diff --git a/app/controllers/user.js b/app/controllers/user.js new file mode 100644 index 00000000000..bfc99c8d576 --- /dev/null +++ b/app/controllers/user.js @@ -0,0 +1,19 @@ +import Ember from 'ember'; +import PaginationMixin from '../mixins/pagination'; + +const { computed } = Ember; + +// TODO: reduce duplication with controllers/crates + +export default Ember.Controller.extend(PaginationMixin, { + queryParams: ['page', 'per_page', 'sort'], + page: '1', + per_page: 10, + sort: 'alpha', + + totalItems: computed.readOnly('model.crates.meta.total'), + + currentSortBy: computed('sort', function() { + return (this.get('sort') === 'downloads') ? 'Downloads' : 'Alphabetical'; + }), +}); diff --git a/app/router.js b/app/router.js index d858f0d5c9a..8e48c6c8ca7 100644 --- a/app/router.js +++ b/app/router.js @@ -27,6 +27,7 @@ Router.map(function() { this.route('crates'); this.route('following'); }); + this.route('user', { path: '/users/:user_id' }); this.route('install'); this.route('search'); this.route('dashboard'); diff --git a/app/routes/user.js b/app/routes/user.js new file mode 100644 index 00000000000..a8a0f79d850 --- /dev/null +++ b/app/routes/user.js @@ -0,0 +1,37 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + queryParams: { + page: { refreshModel: true }, + sort: { refreshModel: true }, + }, + data: {}, + + setupController(controller, model) { + this._super(controller, model); + + controller.set('fetchingFeed', true); + controller.set('crates', this.get('data.crates')); + }, + + model(params) { + const { user_id } = params; + return this.store.find('user', user_id).then( + (user) => { + params.user_id = user.get('id'); + return Ember.RSVP.hash({ + crates: this.store.query('crate', params), + user + }); + }, + (e) => { + if (e.errors.any(e => e.detail === 'Not Found')) { + this + .controllerFor('application') + .set('nextFlashError', `User '${params.user_id}' does not exist`); + return this.replaceWith('index'); + } + } + ); + }, +}); diff --git a/app/styles/crate.scss b/app/styles/crate.scss index 81aa6b3de9d..9e9d22d1192 100644 --- a/app/styles/crate.scss +++ b/app/styles/crate.scss @@ -11,7 +11,10 @@ @include display-flex; @include align-items(center); } - h1 { padding-left: 10px; } + h1 { + padding-left: 10px; + padding-right: 10px; + } h2 { color: $main-color-light; padding-left: 10px; } .right { @include flex(2); diff --git a/app/templates/crate/version.hbs b/app/templates/crate/version.hbs index a39c698cd13..42356ec38ec 100644 --- a/app/templates/crate/version.hbs +++ b/app/templates/crate/version.hbs @@ -109,9 +109,9 @@
+ {{/user-link}}
+
+ {{ currentSortBy }}
+
+ {{/rl-dropdown-toggle}}
+
+ {{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
+
+ {{/link-to}}
+ {{#each pages as |page|}}
+ {{#link-to (query-params page=page)}}{{ page }}{{/link-to}}
+ {{/each}}
+ {{#link-to (query-params page=nextPage) class="next" rel="next" title="next page"}}
+
+ {{/link-to}}
+