Clean-up rendering and support the /:user or /:user/:reponame URL structure

This commit is contained in:
R. Tyler Croy 2012-04-12 22:21:23 -07:00
parent 2d154d411d
commit aa508d1180
6 changed files with 80 additions and 35 deletions

View File

@ -1,5 +1,5 @@
smalltalk.addPackage('Despair-UI', {});
smalltalk.addClass('PullRequestTile', smalltalk.Widget, ['pull', 'minutesOld'], 'Despair-UI');
smalltalk.addClass('PullRequestTile', smalltalk.Widget, ['pull', 'minutesOld', 'lastUpdatedText'], 'Despair-UI');
smalltalk.addMethod(
unescape('_withPull_'),
smalltalk.method({
@ -17,7 +17,8 @@ smalltalk.method({
selector: unescape('renderOn%3A'),
fn: function (html){
var self=this;
(function($rec){smalltalk.send($rec, "_class_", [smalltalk.send("pull_request_tile sadness_", "__comma", [smalltalk.send(smalltalk.send(self, "_sadness", []), "_asString", [])])]);return smalltalk.send($rec, "_with_", [(function(){smalltalk.send(smalltalk.send(html, "_strong", []), "_with_", [smalltalk.send(self['@pull'], "_title", [])]);smalltalk.send(html, "_br", []);smalltalk.send(html, "_with_", [smalltalk.send("Last updated: ", "__comma", [smalltalk.send(self, "_lastUpdated", [])])]);smalltalk.send(html, "_br", []);return smalltalk.send(html, "_with_", [smalltalk.send(self, "_sadness", [])]);})]);})(smalltalk.send(html, "_div", []));
(self['@lastUpdatedText']=smalltalk.send(self, "_lastUpdated", []));
(function($rec){smalltalk.send($rec, "_class_", [smalltalk.send("pull_request_tile sadness_", "__comma", [smalltalk.send(smalltalk.send(self, "_sadness", []), "_asString", [])])]);return smalltalk.send($rec, "_with_", [(function(){smalltalk.send(smalltalk.send(html, "_strong", []), "_with_", [(function(){return (function($rec){smalltalk.send($rec, "_href_", [smalltalk.send(self['@pull'], "_url", [])]);smalltalk.send($rec, "_target_", ["_blank"]);return smalltalk.send($rec, "_with_", [smalltalk.send(self['@pull'], "_title", [])]);})(smalltalk.send(html, "_a", []));})]);smalltalk.send(html, "_br", []);return smalltalk.send(html, "_with_", [smalltalk.send("Last updated: ", "__comma", [self['@lastUpdatedText']])]);})]);})(smalltalk.send(html, "_div", []));
return self;}
}),
smalltalk.PullRequestTile);
@ -103,8 +104,7 @@ smalltalk.method({
selector: unescape('renderOn%3A'),
fn: function (html){
var self=this;
smalltalk.send(html, "_with_", [self['@repo']]);
(function($rec){smalltalk.send($rec, "_id_", [self['@repo']]);smalltalk.send($rec, "_class_", ["project_tile"]);return smalltalk.send($rec, "_with_", [(function(){return smalltalk.send(self['@pulls'], "_do_", [(function(pull){return (function($rec){smalltalk.send($rec, "_withPull_", [pull]);return smalltalk.send($rec, "_renderOn_", [html]);})(smalltalk.send((smalltalk.PullRequestTile || PullRequestTile), "_new", []));})]);})]);})(smalltalk.send(html, "_div", []));
(function($rec){smalltalk.send($rec, "_id_", [self['@repo']]);smalltalk.send($rec, "_class_", ["project_tile"]);return smalltalk.send($rec, "_with_", [(function(){smalltalk.send(smalltalk.send(html, "_h2", []), "_with_", [self['@repo']]);return (function($rec){smalltalk.send($rec, "_class_", ["pull_requests"]);return smalltalk.send($rec, "_with_", [(function(){return smalltalk.send(self['@pulls'], "_do_", [(function(pull){return (function($rec){smalltalk.send($rec, "_withPull_", [pull]);return smalltalk.send($rec, "_renderOn_", [html]);})(smalltalk.send((smalltalk.PullRequestTile || PullRequestTile), "_new", []));})]);})]);})(smalltalk.send(html, "_div", []));})]);})(smalltalk.send(html, "_div", []));
smalltalk.send(html, "_br", []);
return self;}
}),

View File

@ -1,5 +1,5 @@
smalltalk.addPackage('Despair-UI', {});
smalltalk.addClass('PullRequestTile', smalltalk.Widget, ['pull', 'minutesOld'], 'Despair-UI');
smalltalk.addClass('PullRequestTile', smalltalk.Widget, ['pull', 'minutesOld', 'lastUpdatedText'], 'Despair-UI');
smalltalk.addMethod(
unescape('_withPull_'),
smalltalk.method({
@ -23,11 +23,12 @@ selector: unescape('renderOn%3A'),
category: 'rendering',
fn: function (html){
var self=this;
(function($rec){smalltalk.send($rec, "_class_", [smalltalk.send("pull_request_tile sadness_", "__comma", [smalltalk.send(smalltalk.send(self, "_sadness", []), "_asString", [])])]);return smalltalk.send($rec, "_with_", [(function(){smalltalk.send(smalltalk.send(html, "_strong", []), "_with_", [smalltalk.send(self['@pull'], "_title", [])]);smalltalk.send(html, "_br", []);smalltalk.send(html, "_with_", [smalltalk.send("Last updated: ", "__comma", [smalltalk.send(self, "_lastUpdated", [])])]);smalltalk.send(html, "_br", []);return smalltalk.send(html, "_with_", [smalltalk.send(self, "_sadness", [])]);})]);})(smalltalk.send(html, "_div", []));
(self['@lastUpdatedText']=smalltalk.send(self, "_lastUpdated", []));
(function($rec){smalltalk.send($rec, "_class_", [smalltalk.send("pull_request_tile sadness_", "__comma", [smalltalk.send(smalltalk.send(self, "_sadness", []), "_asString", [])])]);return smalltalk.send($rec, "_with_", [(function(){smalltalk.send(smalltalk.send(html, "_strong", []), "_with_", [(function(){return (function($rec){smalltalk.send($rec, "_href_", [smalltalk.send(self['@pull'], "_url", [])]);smalltalk.send($rec, "_target_", ["_blank"]);return smalltalk.send($rec, "_with_", [smalltalk.send(self['@pull'], "_title", [])]);})(smalltalk.send(html, "_a", []));})]);smalltalk.send(html, "_br", []);return smalltalk.send(html, "_with_", [smalltalk.send("Last updated: ", "__comma", [self['@lastUpdatedText']])]);})]);})(smalltalk.send(html, "_div", []));
return self;},
args: ["html"],
source: unescape('renderOn%3A%20html%0A%09html%20div%0A%09%09class%3A%20%27pull_request_tile%20sadness_%27%2C%20%28self%20sadness%20asString%29%3B%0A%09%09with%3A%20%5B%0A%09%09%09html%20strong%20with%3A%20%28pull%20title%29.%0A%09%09%09html%20br.%0A%09%09%09html%20with%3A%20%27Last%20updated%3A%20%27%2C%20self%20lastUpdated.%0A%09%09%09html%20br.%0A%09%09%09html%20with%3A%20%28self%20sadness%29.%0A%09%5D.'),
messageSends: ["class:", unescape("%2C"), "asString", "sadness", "with:", "strong", "title", "br", "lastUpdated", "div"],
source: unescape('renderOn%3A%20html%0A%09lastUpdatedText%20%3A%3D%20self%20lastUpdated.%0A%09html%20div%0A%09%09class%3A%20%27pull_request_tile%20sadness_%27%2C%20%28self%20sadness%20asString%29%3B%0A%09%09with%3A%20%5B%0A%09%09%09html%20strong%20with%3A%20%5B%20html%20a%20href%3A%20%28pull%20url%29%3B%20target%3A%20%27_blank%27%3B%20with%3A%20%28pull%20title%29%20%5D.%0A%09%09%09html%20br.%0A%09%09%09html%20with%3A%20%27Last%20updated%3A%20%27%2C%20lastUpdatedText.%0A%09%5D.'),
messageSends: ["lastUpdated", "class:", unescape("%2C"), "asString", "sadness", "with:", "strong", "href:", "url", "target:", "title", "a", "br", "div"],
referencedClasses: []
}),
smalltalk.PullRequestTile);
@ -139,13 +140,12 @@ selector: unescape('renderOn%3A'),
category: 'rendering',
fn: function (html){
var self=this;
smalltalk.send(html, "_with_", [self['@repo']]);
(function($rec){smalltalk.send($rec, "_id_", [self['@repo']]);smalltalk.send($rec, "_class_", ["project_tile"]);return smalltalk.send($rec, "_with_", [(function(){return smalltalk.send(self['@pulls'], "_do_", [(function(pull){return (function($rec){smalltalk.send($rec, "_withPull_", [pull]);return smalltalk.send($rec, "_renderOn_", [html]);})(smalltalk.send((smalltalk.PullRequestTile || PullRequestTile), "_new", []));})]);})]);})(smalltalk.send(html, "_div", []));
(function($rec){smalltalk.send($rec, "_id_", [self['@repo']]);smalltalk.send($rec, "_class_", ["project_tile"]);return smalltalk.send($rec, "_with_", [(function(){smalltalk.send(smalltalk.send(html, "_h2", []), "_with_", [self['@repo']]);return (function($rec){smalltalk.send($rec, "_class_", ["pull_requests"]);return smalltalk.send($rec, "_with_", [(function(){return smalltalk.send(self['@pulls'], "_do_", [(function(pull){return (function($rec){smalltalk.send($rec, "_withPull_", [pull]);return smalltalk.send($rec, "_renderOn_", [html]);})(smalltalk.send((smalltalk.PullRequestTile || PullRequestTile), "_new", []));})]);})]);})(smalltalk.send(html, "_div", []));})]);})(smalltalk.send(html, "_div", []));
smalltalk.send(html, "_br", []);
return self;},
args: ["html"],
source: unescape('renderOn%3A%20html%0A%09html%20with%3A%20repo.%0A%09html%20div%0A%09%09id%3A%20repo%3B%0A%09%09class%3A%20%27project_tile%27%3B%0A%09%09with%3A%20%5B%0A%09%09%09pulls%20do%3A%20%5B%20%3Apull%20%7C%0A%09%09%09%09PullRequestTile%20new%20withPull%3A%20pull%3B%20renderOn%3A%20html.%0A%09%09%5D%0A%09%5D.%0A%09html%20br.'),
messageSends: ["with:", "id:", "class:", "do:", "withPull:", "renderOn:", "new", "div", "br"],
source: unescape('renderOn%3A%20html%0A%09html%20div%0A%09%09id%3A%20repo%3B%0A%09%09class%3A%20%27project_tile%27%3B%0A%09%09with%3A%20%5B%0A%09%09%09html%20h2%20with%3A%20repo.%0A%09%09%09html%20div%0A%09%09%09%09class%3A%20%27pull_requests%27%3B%0A%09%09%09%09with%3A%20%5B%0A%09%09%09%09%09pulls%20do%3A%20%5B%20%3Apull%20%7C%20PullRequestTile%20new%20withPull%3A%20pull%3B%20renderOn%3A%20html%20%5D%0A%09%09%09%09%5D.%0A%09%09%5D.%0A%09html%20br.'),
messageSends: ["id:", "class:", "with:", "h2", "do:", "withPull:", "renderOn:", "new", "div", "br"],
referencedClasses: ["PullRequestTile"]
}),
smalltalk.Project);

View File

@ -6,10 +6,12 @@ smalltalk.method({
selector: unescape('bootstrap%3A'),
fn: function (aUsername){
var self=this;
var presetRepoName=nil;
(self['@username']=aUsername);
smalltalk.send((smalltalk.Repo || Repo), "_fetchReposFor_withEachDo_finally_", [aUsername, (function(repo){var reponame=nil;
(presetRepoName=smalltalk.send((typeof window == 'undefined' ? nil : window), "_at_", ["despair_repo"]));
(($receiver = presetRepoName) == nil || $receiver == undefined) ? (function(){return smalltalk.send((smalltalk.Repo || Repo), "_fetchReposFor_withEachDo_finally_", [aUsername, (function(repo){var reponame=nil;
var forks=nil;
(reponame=smalltalk.send(repo, "_at_", ["name"]));(forks=smalltalk.send(repo, "_at_", ["forks"]));return ((($receiver = ((($receiver = forks).klass === smalltalk.Number) ? $receiver <(2) : smalltalk.send($receiver, "__lt", [(2)]))).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (($receiver = reponame) != nil && $receiver != undefined) ? (function(){return smalltalk.send(self['@repos'], "_at_put_", [reponame, smalltalk.send((smalltalk.Array || Array), "_new", [])]);})() : nil;})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (($receiver = reponame) != nil && $receiver != undefined) ? (function(){return smalltalk.send(self['@repos'], "_at_put_", [reponame, smalltalk.send((smalltalk.Array || Array), "_new", [])]);})() : nil;})]));}), (function(){return smalltalk.send(self, "_loadPullRequests", []);})]);
(reponame=smalltalk.send(repo, "_at_", ["name"]));(forks=smalltalk.send(repo, "_at_", ["forks"]));return ((($receiver = ((($receiver = forks).klass === smalltalk.Number) ? $receiver <(2) : smalltalk.send($receiver, "__lt", [(2)]))).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (($receiver = reponame) != nil && $receiver != undefined) ? (function(){return smalltalk.send(self['@repos'], "_at_put_", [reponame, smalltalk.send((smalltalk.Array || Array), "_new", [])]);})() : nil;})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (($receiver = reponame) != nil && $receiver != undefined) ? (function(){return smalltalk.send(self['@repos'], "_at_put_", [reponame, smalltalk.send((smalltalk.Array || Array), "_new", [])]);})() : nil;})]));}), (function(){return smalltalk.send(self, "_loadPullRequests", []);})]);})() : (function(){smalltalk.send(self['@repos'], "_at_put_", [presetRepoName, smalltalk.send((smalltalk.Array || Array), "_new", [])]);return smalltalk.send(self, "_loadPullRequests", []);})();
return self;}
}),
smalltalk.DespairApp);
@ -65,6 +67,17 @@ return self;}
}),
smalltalk.DespairApp);
smalltalk.addMethod(
unescape('_repos'),
smalltalk.method({
selector: unescape('repos'),
fn: function (){
var self=this;
return self['@repos'];
return self;}
}),
smalltalk.DespairApp);
smalltalk.DespairApp.klass.iVarNames = ['current'];
smalltalk.addMethod(

View File

@ -7,14 +7,16 @@ selector: unescape('bootstrap%3A'),
category: 'initializers',
fn: function (aUsername){
var self=this;
var presetRepoName=nil;
(self['@username']=aUsername);
smalltalk.send((smalltalk.Repo || Repo), "_fetchReposFor_withEachDo_finally_", [aUsername, (function(repo){var reponame=nil;
(presetRepoName=smalltalk.send((typeof window == 'undefined' ? nil : window), "_at_", ["despair_repo"]));
(($receiver = presetRepoName) == nil || $receiver == undefined) ? (function(){return smalltalk.send((smalltalk.Repo || Repo), "_fetchReposFor_withEachDo_finally_", [aUsername, (function(repo){var reponame=nil;
var forks=nil;
(reponame=smalltalk.send(repo, "_at_", ["name"]));(forks=smalltalk.send(repo, "_at_", ["forks"]));return ((($receiver = ((($receiver = forks).klass === smalltalk.Number) ? $receiver <(2) : smalltalk.send($receiver, "__lt", [(2)]))).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (($receiver = reponame) != nil && $receiver != undefined) ? (function(){return smalltalk.send(self['@repos'], "_at_put_", [reponame, smalltalk.send((smalltalk.Array || Array), "_new", [])]);})() : nil;})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (($receiver = reponame) != nil && $receiver != undefined) ? (function(){return smalltalk.send(self['@repos'], "_at_put_", [reponame, smalltalk.send((smalltalk.Array || Array), "_new", [])]);})() : nil;})]));}), (function(){return smalltalk.send(self, "_loadPullRequests", []);})]);
(reponame=smalltalk.send(repo, "_at_", ["name"]));(forks=smalltalk.send(repo, "_at_", ["forks"]));return ((($receiver = ((($receiver = forks).klass === smalltalk.Number) ? $receiver <(2) : smalltalk.send($receiver, "__lt", [(2)]))).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (($receiver = reponame) != nil && $receiver != undefined) ? (function(){return smalltalk.send(self['@repos'], "_at_put_", [reponame, smalltalk.send((smalltalk.Array || Array), "_new", [])]);})() : nil;})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (($receiver = reponame) != nil && $receiver != undefined) ? (function(){return smalltalk.send(self['@repos'], "_at_put_", [reponame, smalltalk.send((smalltalk.Array || Array), "_new", [])]);})() : nil;})]));}), (function(){return smalltalk.send(self, "_loadPullRequests", []);})]);})() : (function(){smalltalk.send(self['@repos'], "_at_put_", [presetRepoName, smalltalk.send((smalltalk.Array || Array), "_new", [])]);return smalltalk.send(self, "_loadPullRequests", []);})();
return self;},
args: ["aUsername"],
source: unescape('bootstrap%3A%20aUsername%0A%09%22%20Start%20the%20application%20loading%20with%20aUsername%20%22%0A%09username%20%3A%3D%20aUsername.%0A%0A%09Repo%20fetchReposFor%3A%20aUsername%0A%09%09withEachDo%3A%20%5B%20%3Arepo%20%7C%0A%09%09%09%7C%20reponame%20forks%20%7C%0A%09%09%09reponame%20%3A%3D%20repo%20at%3A%20%27name%27.%0A%09%09%09forks%20%3A%3D%20repo%20at%3A%20%27forks%27.%0A%09%09%09%28forks%20%3C%202%29%20ifFalse%3A%20%5B%20reponame%20ifNotNil%3A%20%5B%20repos%20at%3A%20reponame%20put%3A%20%28Array%20new%29%20%5D%20%5D%0A%09%09%5D%0A%09%09finally%3A%20%5B%20self%20loadPullRequests%20%5D.'),
messageSends: ["fetchReposFor:withEachDo:finally:", "at:", "ifFalse:", unescape("%3C"), "ifNotNil:", "at:put:", "new", "loadPullRequests"],
source: unescape('bootstrap%3A%20aUsername%0A%09%22%20Start%20the%20application%20loading%20with%20aUsername%20%22%0A%09%7C%20presetRepoName%20%7C%0A%09username%20%3A%3D%20aUsername.%0A%09presetRepoName%20%3A%3D%20%28window%20at%3A%20%27despair_repo%27%29.%0A%0A%09presetRepoName%0A%09%09ifNotNil%3A%20%5B%0A%09%09%09repos%20at%3A%20presetRepoName%20put%3A%20%28Array%20new%29.%0A%09%09%09self%20loadPullRequests.%0A%09%09%5D%0A%09%09ifNil%3A%20%5B%0A%09%09%09Repo%20fetchReposFor%3A%20aUsername%0A%09%09%09%09withEachDo%3A%20%5B%20%3Arepo%20%7C%0A%09%09%09%09%09%7C%20reponame%20forks%20%7C%0A%09%09%09%09%09reponame%20%3A%3D%20repo%20at%3A%20%27name%27.%0A%09%09%09%09%09forks%20%3A%3D%20repo%20at%3A%20%27forks%27.%0A%09%09%09%09%09%28forks%20%3C%202%29%20ifFalse%3A%20%5B%20reponame%20ifNotNil%3A%20%5B%20repos%20at%3A%20reponame%20put%3A%20%28Array%20new%29%20%5D%20%5D%0A%09%09%09%09%5D%0A%09%09%09%09finally%3A%20%5B%20self%20loadPullRequests%20%5D.%0A%09%09%5D.%0A%09%0A'),
messageSends: ["at:", "ifNotNil:ifNil:", "fetchReposFor:withEachDo:finally:", "ifFalse:", unescape("%3C"), "ifNotNil:", "at:put:", "new", "loadPullRequests"],
referencedClasses: ["Repo", "Array"]
}),
smalltalk.DespairApp);
@ -90,6 +92,22 @@ referencedClasses: []
}),
smalltalk.DespairApp);
smalltalk.addMethod(
unescape('_repos'),
smalltalk.method({
selector: unescape('repos'),
category: 'accessors',
fn: function (){
var self=this;
return self['@repos'];
return self;},
args: [],
source: unescape('repos%0A%09%5E%20repos.'),
messageSends: [],
referencedClasses: []
}),
smalltalk.DespairApp);
smalltalk.DespairApp.klass.iVarNames = ['current'];
smalltalk.addMethod(

View File

@ -1,6 +1,6 @@
Smalltalk current createPackage: 'Despair-UI' properties: #{}!
Widget subclass: #PullRequestTile
instanceVariableNames: 'pull minutesOld'
instanceVariableNames: 'pull minutesOld lastUpdatedText'
category: 'Despair-UI'!
!PullRequestTile methodsFor: 'initializers'!
@ -17,14 +17,13 @@ initialize
!PullRequestTile methodsFor: 'rendering'!
renderOn: html
lastUpdatedText := self lastUpdated.
html div
class: 'pull_request_tile sadness_', (self sadness asString);
with: [
html strong with: (pull title).
html strong with: [ html a href: (pull url); target: '_blank'; with: (pull title) ].
html br.
html with: 'Last updated: ', self lastUpdated.
html br.
html with: (self sadness).
html with: 'Last updated: ', lastUpdatedText.
].
!
@ -77,15 +76,17 @@ withRepo: aRepo andPullRequests: anArrayOfRequests
!Project methodsFor: 'rendering'!
renderOn: html
html with: repo.
html div
id: repo;
class: 'project_tile';
with: [
pulls do: [ :pull |
PullRequestTile new withPull: pull; renderOn: html.
]
].
html h2 with: repo.
html div
class: 'pull_requests';
with: [
pulls do: [ :pull | PullRequestTile new withPull: pull; renderOn: html ]
].
].
html br.
! !

View File

@ -7,6 +7,10 @@ Object subclass: #DespairApp
activeRepos
^ activeRepos.
!
repos
^ repos.
! !
!DespairApp methodsFor: 'actions'!
@ -44,16 +48,25 @@ activateRepo: aRepoName
bootstrap: aUsername
" Start the application loading with aUsername "
| presetRepoName |
username := aUsername.
presetRepoName := (window at: 'despair_repo').
Repo fetchReposFor: aUsername
withEachDo: [ :repo |
| reponame forks |
reponame := repo at: 'name'.
forks := repo at: 'forks'.
(forks < 2) ifFalse: [ reponame ifNotNil: [ repos at: reponame put: (Array new) ] ]
presetRepoName
ifNotNil: [
repos at: presetRepoName put: (Array new).
self loadPullRequests.
]
finally: [ self loadPullRequests ].
ifNil: [
Repo fetchReposFor: aUsername
withEachDo: [ :repo |
| reponame forks |
reponame := repo at: 'name'.
forks := repo at: 'forks'.
(forks < 2) ifFalse: [ reponame ifNotNil: [ repos at: reponame put: (Array new) ] ]
]
finally: [ self loadPullRequests ].
].
!
initialize