Skip to content

Commit

Permalink
resolve #7 handle duplicate names
Browse files Browse the repository at this point in the history
  • Loading branch information
sheehan committed Jan 10, 2017
1 parent 8850577 commit 84668dd
Show file tree
Hide file tree
Showing 10 changed files with 7,238 additions and 6,496 deletions.
15 changes: 8 additions & 7 deletions grails-app/assets/javascripts/app/App.es6
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ grailsplugins.App = class {
setupRouter() {
page.base(this.baseUrl);
page('/q/:q', (context, next) => {
// ga('send', 'pageview', canonicalPath);
this.showSearch(context.params.q);
});
page('/plugin/:plugin', (context, next) => {
// ga('send', 'pageview', canonicalPath);
this.showPlugin(context.params.plugin);
let plugin = this.plugins.findByName(context.params.plugin);
this.showPlugin(plugin);
});
page('/plugin/:owner/:name', (context, next) => {
let plugin = this.plugins.findByOwnerAndName(context.params.owner, context.params.name);
this.showPlugin(plugin);
});
page('*', (context, next) => {
// ga('send', 'pageview', canonicalPath);
this.showSearch('');
});
}
Expand Down Expand Up @@ -89,13 +91,12 @@ grailsplugins.App = class {
}
}

showPlugin(pluginName) {
showPlugin(plugin) {
this._lastSearchScrollTop = $('body').scrollTop();

document.title = pluginName;
document.title = plugin.name;
$('.search-section').addClass('hide');
$('.plugin-section').removeClass('hide');
let plugin = this.plugins.findByName(pluginName);
this.pluginView.showPlugin(plugin);
}
};
4 changes: 4 additions & 0 deletions grails-app/assets/javascripts/app/Plugins.es6
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ grailsplugins.Plugins = class {
return _.findWhere(this._plugins, {name: name});
}

findByOwnerAndName(owner, name) {
return _.findWhere(this._plugins, {owner: owner, name: name});
}

getLabels() {
return this._allLabels;
}
Expand Down
2 changes: 1 addition & 1 deletion grails-app/assets/javascripts/templates/plugin.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<i class="fa fa-github"></i> <span class="gh-text" id="gh-text">Star</span></a><a class="gh-count" id="gh-count" href="{{githubRepo.html_url}}/stargazers">{{githubRepo.stargazers_count}}</a>
</span>
{{/if}}
<a class="plugin-name" href="{{baseUrl}}/plugin/{{name}}" data-internal>{{name}}</a>
<a class="plugin-name" href="{{baseUrl}}/plugin/{{owner}}/{{name}}" data-internal>{{name}}</a>
</div>
<div class="attributes-bar">
<ul class="attributes-list">
Expand Down
2 changes: 1 addition & 1 deletion grails-app/assets/javascripts/templates/plugins.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{#each plugins}}
<li>
<div>
<a class="plugin-name" href="{{baseUrl}}/plugin/{{name}}" data-internal>{{name}}</a>
<a class="plugin-name" href="{{baseUrl}}/plugin/{{owner}}/{{name}}" data-internal>{{name}}</a>
<span class="external-links">
{{#if githubRepo}}
<a href="{{githubRepo.html_url}}" title="Github repository" target="_top"><img src="{{baseUrl}}/assets/plainicon.com-50224-svg.svg"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ class PluginController {
}

def plugin() {
def plugins = Plugins.get()
Map plugin = plugins.find { it.name == params.plugin }
renderPlugin Plugins.get().find { it.name == params.pluginName }
}

def pluginWithOwner() {
renderPlugin Plugins.get().find { it.name == params.pluginName && it.owner == params.ownerName }
}

private renderPlugin(Map plugin) {
Map json = [
baseUrl: createLink(uri: '/')
]
Expand Down
3 changes: 2 additions & 1 deletion grails-app/controllers/com/github/sheehan/UrlMappings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class UrlMappings {

"/"(controller: 'plugin', action: 'index')
"/plugin/json"(controller: 'plugin', action: 'json')
"/plugin/$plugin"(controller: 'plugin', action: 'plugin')
"/plugin/$pluginName"(controller: 'plugin', action: 'plugin')
"/plugin/$ownerName/$pluginName"(controller: 'plugin', action: 'pluginWithOwner')
"/q/$query"(controller: 'plugin', action: 'index')

"500"(view:'/error')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class SyncPluginsJobService implements SchwartzJob {
Compare compare = pluginService.refreshPlugins()
if (compare) {
compare.newVersions.each { Compare.NewVersion newVersion ->
String owner = newVersion.plugin.owner
String name = newVersion.plugin.name
String version = newVersion.version
twitterService.tweet "$name $version released: http://plugins.grails.org/plugin/$name"
twitterService.tweet "$name $version released: http://plugins.grails.org/plugin/$owner/$name"
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/com/github/sheehan/Compare.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Compare {

Compare(List<Map> oldJson, List<Map> newJson) {
newJson.each { plugin ->
Map match = oldJson.find { it.name == plugin.name }
Map match = oldJson.find { it.name == plugin.name && it.owner == plugin.owner }
if (!match) {
if (plugin.latest_version) {
newVersions << new NewVersion(version: plugin.latest_version, plugin: plugin)
Expand Down
Loading

0 comments on commit 84668dd

Please sign in to comment.