add repo on success

This commit is contained in:
Radek Stepan 2014-09-12 21:03:52 -07:00
parent ec0864f3d2
commit a17bd05a58
7 changed files with 47 additions and 28 deletions

View File

@ -28,6 +28,7 @@ GitHub Burndown Chart as a service. Public repos are free, for private access au
- [ ] Check location.hash is supported - [ ] Check location.hash is supported
- [ ] Have an app wide of triggering a URL and have named routes too - [ ] Have an app wide of triggering a URL and have named routes too
- [ ] Check that we have not run out of requests to make - [ ] Check that we have not run out of requests to make
- [ ] Deal with running out of GH API requests
### Extras ### Extras

View File

@ -24617,20 +24617,19 @@ requireModule('promise/polyfill').polyfill();
'adapt': [Ractive.adaptors.Ractive], 'adapt': [Ractive.adaptors.Ractive],
init: function() { init: function() {
var autocomplete; var autocomplete;
autocomplete = function(value) { autocomplete = function(value) {};
return console.log('Autocomplete', value);
};
this.observe('value', _.debounce(autocomplete, 200), { this.observe('value', _.debounce(autocomplete, 200), {
'init': false 'init': false
}); });
return this.on('submit', function() { return this.on('submit', function() {
var repo, reponame, username, _ref; var name, owner, repo, _ref;
_ref = this.get('value').split('/'), username = _ref[0], reponame = _ref[1]; _ref = this.get('value').split('/'), owner = _ref[0], name = _ref[1];
repo = github.getRepo(username, reponame); repo = github.getRepo(owner, name);
return repo.show(function(err, repo, xhr) { return repo.show(function(err, repo, xhr) {
if (err) { if (err) {
throw err; throw err;
} }
mediator.fire('!projects/add', repo);
return window.location.hash = '#'; return window.location.hash = '#';
}); });
}); });
@ -24812,7 +24811,7 @@ requireModule('promise/polyfill').polyfill();
}, },
init: function() { init: function() {
var _this = this; var _this = this;
return mediator.on('!projects/get', function(provider) { mediator.on('!projects/get', function(provider) {
switch (provider) { switch (provider) {
case 'local': case 'local':
return localforage.getItem('projects', function(items) { return localforage.getItem('projects', function(items) {
@ -24825,6 +24824,12 @@ requireModule('promise/polyfill').polyfill();
throw 'Not implemented yet'; throw 'Not implemented yet';
} }
}); });
return mediator.on('!projects/add', function(repo) {
return _this.push('items', {
'owner': repo.owner.login,
'name': repo.name
});
});
} }
}); });
@ -24941,7 +24946,7 @@ requireModule('promise/polyfill').polyfill();
// projects.mustache // projects.mustache
root.require.register('burnchart/src/templates/projects.js', function(exports, require, module) { root.require.register('burnchart/src/templates/projects.js', function(exports, require, module) {
module.exports = ["{{#projects.items}}"," <div id=\"projects\">"," <div class=\"header\">"," <a href=\"#\" class=\"sort\"><span class=\"icon sort-alphabet\"></span> Sorted by priority</a>"," <h2>Projects</h2>"," </div>",""," <table>"," {{#projects.items}}"," <tr>"," <td><a class=\"repo\" href=\"#\">demo/demo</a></td>"," <td><span class=\"milestone\">Milestone 1.0 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">40%</span>"," <span class=\"due\">due on Friday</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:40%\"></div>"," </div>"," </div>"," </td>"," </tr>"," {{/projects.items}}",""," <tr>"," <td><a class=\"repo\" href=\"#\">radekstepan/disposable</a></td>"," <td><span class=\"milestone\">Milestone 1.0 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">40%</span>"," <span class=\"due\">due on Friday</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:40%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr class=\"done\">"," <td><a class=\"repo\" href=\"#\">radekstepan/burnchart</a></td>"," <td><span class=\"milestone\">Beta Milestone <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">100%</span>"," <span class=\"due\">due tomorrow</span>"," <div class=\"outer bar\">"," <div class=\"inner bar green\" style=\"width:100%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr>"," <td><a class=\"repo\" href=\"#\">intermine/intermine</a></td>"," <td><span class=\"milestone\">Emma Release 96 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">27%</span>"," <span class=\"due\">due in 2 weeks</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:27%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr>"," <td><a class=\"repo\" href=\"#\">microsoft/windows</a></td>"," <td><span class=\"milestone\">RC 9 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">90%</span>"," <span class=\"due red\">overdue by a month</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:90%\"></div>"," </div>"," </div>"," </td>"," </tr>"," </table>",""," <div class=\"footer\">"," <a href=\"#\"><span class=\"icon cog\"></span> Edit</a>"," </div>"," </div>","{{/projects.items}}"].join("\n"); module.exports = ["{{#projects.items}}"," <div id=\"projects\">"," <div class=\"header\">"," <a href=\"#\" class=\"sort\"><span class=\"icon sort-alphabet\"></span> Sorted by priority</a>"," <h2>Projects</h2>"," </div>",""," <table>"," {{#projects.items}}"," <tr>"," <td><a class=\"repo\" href=\"#\">{{owner}}/{{name}}</a></td>"," <td><span class=\"milestone\">??? <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">10%</span>"," <span class=\"due\">???</span>"," <div class=\"outer bar\">"," <div class=\"inner bar green\" style=\"width:10%\"></div>"," </div>"," </div>"," </td>"," </tr>"," {{/projects.items}}",""," <tr>"," <td><a class=\"repo\" href=\"#\">radekstepan/disposable</a></td>"," <td><span class=\"milestone\">Milestone 1.0 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">40%</span>"," <span class=\"due\">due on Friday</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:40%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr class=\"done\">"," <td><a class=\"repo\" href=\"#\">radekstepan/burnchart</a></td>"," <td><span class=\"milestone\">Beta Milestone <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">100%</span>"," <span class=\"due\">due tomorrow</span>"," <div class=\"outer bar\">"," <div class=\"inner bar green\" style=\"width:100%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr>"," <td><a class=\"repo\" href=\"#\">intermine/intermine</a></td>"," <td><span class=\"milestone\">Emma Release 96 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">27%</span>"," <span class=\"due\">due in 2 weeks</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:27%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr>"," <td><a class=\"repo\" href=\"#\">microsoft/windows</a></td>"," <td><span class=\"milestone\">RC 9 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">90%</span>"," <span class=\"due red\">overdue by a month</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:90%\"></div>"," </div>"," </div>"," </td>"," </tr>"," </table>",""," <div class=\"footer\">"," <a href=\"#\"><span class=\"icon cog\"></span> Edit</a>"," </div>"," </div>","{{/projects.items}}"].join("\n");
}); });
})(); })();

View File

@ -69,20 +69,19 @@
'adapt': [Ractive.adaptors.Ractive], 'adapt': [Ractive.adaptors.Ractive],
init: function() { init: function() {
var autocomplete; var autocomplete;
autocomplete = function(value) { autocomplete = function(value) {};
return console.log('Autocomplete', value);
};
this.observe('value', _.debounce(autocomplete, 200), { this.observe('value', _.debounce(autocomplete, 200), {
'init': false 'init': false
}); });
return this.on('submit', function() { return this.on('submit', function() {
var repo, reponame, username, _ref; var name, owner, repo, _ref;
_ref = this.get('value').split('/'), username = _ref[0], reponame = _ref[1]; _ref = this.get('value').split('/'), owner = _ref[0], name = _ref[1];
repo = github.getRepo(username, reponame); repo = github.getRepo(owner, name);
return repo.show(function(err, repo, xhr) { return repo.show(function(err, repo, xhr) {
if (err) { if (err) {
throw err; throw err;
} }
mediator.fire('!projects/add', repo);
return window.location.hash = '#'; return window.location.hash = '#';
}); });
}); });
@ -264,7 +263,7 @@
}, },
init: function() { init: function() {
var _this = this; var _this = this;
return mediator.on('!projects/get', function(provider) { mediator.on('!projects/get', function(provider) {
switch (provider) { switch (provider) {
case 'local': case 'local':
return localforage.getItem('projects', function(items) { return localforage.getItem('projects', function(items) {
@ -277,6 +276,12 @@
throw 'Not implemented yet'; throw 'Not implemented yet';
} }
}); });
return mediator.on('!projects/add', function(repo) {
return _this.push('items', {
'owner': repo.owner.login,
'name': repo.name
});
});
} }
}); });
@ -393,7 +398,7 @@
// projects.mustache // projects.mustache
root.require.register('burnchart/src/templates/projects.js', function(exports, require, module) { root.require.register('burnchart/src/templates/projects.js', function(exports, require, module) {
module.exports = ["{{#projects.items}}"," <div id=\"projects\">"," <div class=\"header\">"," <a href=\"#\" class=\"sort\"><span class=\"icon sort-alphabet\"></span> Sorted by priority</a>"," <h2>Projects</h2>"," </div>",""," <table>"," {{#projects.items}}"," <tr>"," <td><a class=\"repo\" href=\"#\">demo/demo</a></td>"," <td><span class=\"milestone\">Milestone 1.0 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">40%</span>"," <span class=\"due\">due on Friday</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:40%\"></div>"," </div>"," </div>"," </td>"," </tr>"," {{/projects.items}}",""," <tr>"," <td><a class=\"repo\" href=\"#\">radekstepan/disposable</a></td>"," <td><span class=\"milestone\">Milestone 1.0 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">40%</span>"," <span class=\"due\">due on Friday</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:40%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr class=\"done\">"," <td><a class=\"repo\" href=\"#\">radekstepan/burnchart</a></td>"," <td><span class=\"milestone\">Beta Milestone <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">100%</span>"," <span class=\"due\">due tomorrow</span>"," <div class=\"outer bar\">"," <div class=\"inner bar green\" style=\"width:100%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr>"," <td><a class=\"repo\" href=\"#\">intermine/intermine</a></td>"," <td><span class=\"milestone\">Emma Release 96 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">27%</span>"," <span class=\"due\">due in 2 weeks</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:27%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr>"," <td><a class=\"repo\" href=\"#\">microsoft/windows</a></td>"," <td><span class=\"milestone\">RC 9 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">90%</span>"," <span class=\"due red\">overdue by a month</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:90%\"></div>"," </div>"," </div>"," </td>"," </tr>"," </table>",""," <div class=\"footer\">"," <a href=\"#\"><span class=\"icon cog\"></span> Edit</a>"," </div>"," </div>","{{/projects.items}}"].join("\n"); module.exports = ["{{#projects.items}}"," <div id=\"projects\">"," <div class=\"header\">"," <a href=\"#\" class=\"sort\"><span class=\"icon sort-alphabet\"></span> Sorted by priority</a>"," <h2>Projects</h2>"," </div>",""," <table>"," {{#projects.items}}"," <tr>"," <td><a class=\"repo\" href=\"#\">{{owner}}/{{name}}</a></td>"," <td><span class=\"milestone\">??? <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">10%</span>"," <span class=\"due\">???</span>"," <div class=\"outer bar\">"," <div class=\"inner bar green\" style=\"width:10%\"></div>"," </div>"," </div>"," </td>"," </tr>"," {{/projects.items}}",""," <tr>"," <td><a class=\"repo\" href=\"#\">radekstepan/disposable</a></td>"," <td><span class=\"milestone\">Milestone 1.0 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">40%</span>"," <span class=\"due\">due on Friday</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:40%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr class=\"done\">"," <td><a class=\"repo\" href=\"#\">radekstepan/burnchart</a></td>"," <td><span class=\"milestone\">Beta Milestone <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">100%</span>"," <span class=\"due\">due tomorrow</span>"," <div class=\"outer bar\">"," <div class=\"inner bar green\" style=\"width:100%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr>"," <td><a class=\"repo\" href=\"#\">intermine/intermine</a></td>"," <td><span class=\"milestone\">Emma Release 96 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">27%</span>"," <span class=\"due\">due in 2 weeks</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:27%\"></div>"," </div>"," </div>"," </td>"," </tr>"," <tr>"," <td><a class=\"repo\" href=\"#\">microsoft/windows</a></td>"," <td><span class=\"milestone\">RC 9 <span class=\"icon down-open\"></span></a></td>"," <td>"," <div class=\"progress\">"," <span class=\"percent\">90%</span>"," <span class=\"due red\">overdue by a month</span>"," <div class=\"outer bar\">"," <div class=\"inner bar red\" style=\"width:90%\"></div>"," </div>"," </div>"," </td>"," </tr>"," </table>",""," <div class=\"footer\">"," <a href=\"#\"><span class=\"icon cog\"></span> Edit</a>"," </div>"," </div>","{{/projects.items}}"].join("\n");
}); });
})(); })();

View File

@ -14,17 +14,20 @@ module.exports = Ractive.extend
'adapt': [ Ractive.adaptors.Ractive ] 'adapt': [ Ractive.adaptors.Ractive ]
init: -> init: ->
# TODO: autocomplete on our username if we are logged in or based
# on repos we already have.
autocomplete = (value) -> autocomplete = (value) ->
console.log 'Autocomplete', value
@observe 'value', _.debounce(autocomplete, 200), { 'init': no } @observe 'value', _.debounce(autocomplete, 200), { 'init': no }
# TODO: listen to Enter keypress.
@on 'submit', -> @on 'submit', ->
[ username, reponame ] = @get('value').split('/') [ owner, name ] = @get('value').split('/')
repo = github.getRepo username, reponame repo = github.getRepo owner, name
repo.show (err, repo, xhr) -> repo.show (err, repo, xhr) ->
throw err if err throw err if err
# TODO: save repo to us & Firebase. # TODO: save repo to us & Firebase.
mediator.fire '!projects/add', repo
# Redirect to the dashboard. # Redirect to the dashboard.
# TODO: trigger a named route # TODO: trigger a named route
window.location.hash = '#' window.location.hash = '#'

View File

@ -1,4 +1,5 @@
mediator = require './mediator' mediator = require './mediator'
user = require './user'
RactiveModel = require './ractiveModel' RactiveModel = require './ractiveModel'
module.exports = new RactiveModel module.exports = new RactiveModel
@ -7,11 +8,15 @@ module.exports = new RactiveModel
'items': [] 'items': []
init: -> init: ->
mediator.on '!projects/get', (provider) => mediator.on '!projects/get', =>
switch provider switch @get 'provider'
when 'local' when 'local'
localforage.getItem 'projects', (items=[]) => localforage.getItem 'projects', (items=[]) =>
@set 'items', items @set 'items', items
when 'github' when 'github'
throw 'Not implemented yet' throw 'Not implemented yet'
mediator.on '!projects/add', (repo) =>
# TODO: deal with repo.hasIssues and warn if there are none.
@push 'items', { 'owner': repo.owner.login, 'name': repo.name }

View File

@ -13,4 +13,4 @@ module.exports = new RactiveModel
init: -> init: ->
# When we are changed, get our projects. # When we are changed, get our projects.
@observe 'uid', -> @observe 'uid', ->
mediator.fire '!projects/get', @get('provider') mediator.fire '!projects/get'

View File

@ -8,14 +8,14 @@
<table> <table>
{{#projects.items}} {{#projects.items}}
<tr> <tr>
<td><a class="repo" href="#">demo/demo</a></td> <td><a class="repo" href="#">{{owner}}/{{name}}</a></td>
<td><span class="milestone">Milestone 1.0 <span class="icon down-open"></span></a></td> <td><span class="milestone">??? <span class="icon down-open"></span></a></td>
<td> <td>
<div class="progress"> <div class="progress">
<span class="percent">40%</span> <span class="percent">10%</span>
<span class="due">due on Friday</span> <span class="due">???</span>
<div class="outer bar"> <div class="outer bar">
<div class="inner bar red" style="width:40%"></div> <div class="inner bar green" style="width:10%"></div>
</div> </div>
</div> </div>
</td> </td>