Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions app/routes/project-version.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from 'ember';
import _ from 'lodash/lodash';

export default Ember.Route.extend({
titleToken: function(model) {
Expand All @@ -8,23 +9,20 @@ export default Ember.Route.extend({
model(params) {
const id = `${params.project}-${params.project_version}`;
return this.store.find('project', params.project).then(() => {
return this.store.find('project-version', id);
return this.store.findRecord('project-version', id, { includes: 'project' });
});
},

afterModel(model, transition) {
// Using redirect instead of afterModel so transition succeeds and returns 30
redirect(model, transition) {
let classParams = transition.params['project-version.class'];
let moduleParams = transition.params['project-version.module'];
let namespaceParams = transition.params['project-version.namespace'];
return model.get('project').then(() => {
if (!classParams && !moduleParams && !namespaceParams) {
const namespaces = model.hasMany('namespaces').ids().sort();
const namespace = namespaces[0];
return this.store.find('namespace', namespace).then(namespace => {
return this.transitionTo('project-version.namespace', model, namespace);
});
}
});
if (!classParams && !moduleParams && !namespaceParams) {
const namespaces = model.hasMany('namespaces').ids().sort();
const namespace = _.last(namespaces[0].split("-"));
return this.transitionTo('project-version.namespace', model.get('project.id'), model.get('version'), namespace);
}
},

serialize(model) {
Expand Down
24 changes: 14 additions & 10 deletions app/routes/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ export default Ember.Route.extend({
scrollPositionReset: inject.service(),

model(params) {
return this.store.find('project', params.project);
return this.store.findRecord('project', params.project, { includes: 'project-version' });
},

afterModel(project /*, transition */) {
return project.get('projectVersions').then(versions => {
const last = versions.toArray().sort((a, b) => {
const a_ver = _.last(a.get('id').split("-"));
const b_ver = _.last(b.get('id').split("-"));
return semverCompare(a_ver, b_ver);
})[versions.length - 1];
return this.transitionTo('project-version', last);
});
// Using redirect instead of afterModel so transition succeeds and returns 307 in fastboot
redirect(project /*, transition */) {
const versions = project.get('projectVersions').toArray();
const last = versions.sort((a, b) => {
const a_ver = this.getVersionString(a);
const b_ver = this.getVersionString(b);
return semverCompare(a_ver, b_ver);
})[versions.length - 1];
return this.transitionTo('project-version', project.get('id'), this.getVersionString(last));
},

getVersionString(version) {
return _.last(version.get('id').split("-"));
},

actions: {
Expand Down