Skip to content

Commit

Permalink
linting and tests for routes. #280
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 1, 2020
1 parent 8e9fea2 commit 4948b82
Show file tree
Hide file tree
Showing 53 changed files with 486 additions and 412 deletions.
4 changes: 0 additions & 4 deletions app/controllers/periodicals.js

This file was deleted.

55 changes: 22 additions & 33 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import GoogleAnalyticsRoute from 'ember-tracker/mixins/google-analytics-route';

const Router = EmberRouter.extend(GoogleAnalyticsRoute, {
location: config.locationType,
rootURL: config.rootURL
rootURL: config.rootURL,
});

Router.map(function () {
this.route('providers', function () {
this.route('show', { path: '/:provider_id' }, function () {
Router.map(function() {
this.route('providers', function() {
this.route('show', { path: '/:provider_id' }, function() {
this.route('settings');
this.route('dois');
this.route('prefixes', function () {
this.route('show', { path: '/:prefix_id' }, function () {
this.route('prefixes', function() {
this.route('show', { path: '/:prefix_id' }, function() {
this.route('delete');
});
this.route('new');
Expand All @@ -22,58 +22,47 @@ Router.map(function () {
this.route('repositories');
});
});
this.route('repositories', function () {
this.route('show', { path: '/:repository_id' }, function () {
this.route('repositories', function() {
this.route('show', { path: '/:repository_id' }, function() {
this.route('settings');
this.route('dois', function () {
this.route('new');
this.route('upload');
this.route('show', { path: '/:doi_id' }, function () {
this.route('edit');
this.route('modify');
this.route('delete');
this.route('transfer');
});
});
this.route('dois');
this.route('transfer');
this.route('prefixes', function () {
this.route('show', { path: '/:prefix_id' }, function () {
this.route('prefixes', function() {
this.route('show', { path: '/:prefix_id' }, function() {
this.route('delete');
});
this.route('new');
});
});
});
this.route('dois', function () {
this.route('dois', function() {
this.route('new');
this.route('upload');
this.route('show', { path: '/:doi_id' }, function () {
this.route('show', { path: '/:doi_id' }, function() {
this.route('edit');
this.route('modify');
this.route('delete');
this.route('transfer');
});
});
this.route('settings', function () {
this.route('index', { path: '/' });
});
this.route('prefixes', function () {
this.route('prefixes', function() {
this.route('new');
});
this.route('users', function () {
this.route('show', { path: '/:user_id' }, function () {
this.route('users', function() {
this.route('show', { path: '/:user_id' }, function() {
this.route('settings');
this.route('dois');
});
});

this.route("sign-in");
this.route('settings');
this.route('sign-in');
this.route('authorize');
this.route("reset");
this.route("password");
this.route('reset');
this.route('password');

//set up all of your known routes, and then...
this.route("404", { path: "*path" });
// set up all of your known routes, and then...
this.route('404', { path: '*path' });
});

export default Router;
6 changes: 3 additions & 3 deletions app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default Route.extend(ApplicationRouteMixin, {
isTokenAuthenticating: null,

beforeModel() {
this.intl.setLocale(['en-us']);
this.intl.setLocale([ 'en-us' ]);
set(this, 'headData.siteName', ENV.SITE_TITLE);
return this._loadCurrentUser();
},
Expand All @@ -34,7 +34,7 @@ export default Route.extend(ApplicationRouteMixin, {
if (!this.isTokenAuthenticating) {
this._super(...arguments);
this._loadCurrentUser();
this.transitionTo('settings')
this.transitionTo('settings');
} else {
this.set('isTokenAuthenticating', false);
}
Expand All @@ -46,5 +46,5 @@ export default Route.extend(ApplicationRouteMixin, {
},
_loadCurrentUser() {
return this.currentUser.load().catch(() => this.session.invalidate());
}
},
});
8 changes: 4 additions & 4 deletions app/routes/authorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export default Route.extend({
model() {
let self = this;
let url = ENV.FABRICA_URL + '/authorize';
fetch(url).then(function (response) {
fetch(url).then(function(response) {
let jwt = response.headers.get('x-amzn-oidc-data');

if (jwt) {
console.log(jwt)
console.log(jwt);
self.session.authenticate('authenticator:globus', jwt).catch((reason) => {
self.set('errorMessage', reason.errors && reason.errors[0].title || reason);
self.transitionTo('/');
Expand All @@ -22,9 +22,9 @@ export default Route.extend({
console.log(response);
self.transitionTo('/sign-in?globus');
}
}).catch(function (error) {
}).catch(function(error) {
console.log(error);
this.transitionTo('/sign-in?globus');
});
}
},
});
34 changes: 17 additions & 17 deletions app/routes/dois/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export default Route.extend({
can: service(),

model(params) {
params = assign(params, {
params = assign(params, {
page: {
number: params.page,
size: params.size
}
size: params.size,
},
});

return this.store.query('doi', params);
Expand All @@ -24,40 +24,40 @@ export default Route.extend({

queryParams: {
page: {
refreshModel: true
refreshModel: true,
},
size: {
refreshModel: true
refreshModel: true,
},
state: {
refreshModel: true
refreshModel: true,
},
'resource-type-id': {
refreshModel: true
refreshModel: true,
},
year: {
refreshModel: true
refreshModel: true,
},
registered: {
refreshModel: true
refreshModel: true,
},
'client-id': {
refreshModel: true
refreshModel: true,
},
'affiliation-id': {
refreshModel: true
refreshModel: true,
},
prefix: {
refreshModel: true
refreshModel: true,
},
'schema-version': {
refreshModel: true
refreshModel: true,
},
source: {
refreshModel: true
refreshModel: true,
},
'link-check-status': {
refreshModel: true
}
}
refreshModel: true,
},
},
});
8 changes: 2 additions & 6 deletions app/routes/dois/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ export default Route.extend({
set(self, 'headData.description', doi.description);

return doi;
}).catch(function(reason){
if (console.debug) {
console.debug(reason);
} else {
console.log(reason);
}
}).catch(function(reason) {
console.debug(reason);

self.get('flashMessages').warning('Fabrica is currently unavailable due to a DataCite API problem. We apologize for the inconvenience and are working hard to restore the service. Please check back later or contact DataCite Support if you have a question.');
self.transitionTo('/');
Expand Down
10 changes: 3 additions & 7 deletions app/routes/dois/show/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ export default Route.extend({
let self = this;
return this.store.findRecord('doi', this.modelFor('dois/show').get('id'), { include: 'client' }).then(function(doi) {
return doi;
}).catch(function(reason){
if (console.debug) {
console.debug(reason);
} else {
console.log(reason);
}
}).catch(function(reason) {
console.debug(reason);

self.get('flashMessages').warning('Fabrica is currently unavailable due to a DataCite API problem. We apologize for the inconvenience and are working hard to restore the service. Please check back later or contact DataCite Support if you have a question.');
self.transitionTo('/');
Expand All @@ -26,5 +22,5 @@ export default Route.extend({
} else {
this.modelFor('dois/show').set('mode', 'delete');
}
}
},
});
12 changes: 4 additions & 8 deletions app/routes/dois/show/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ export default Route.extend({

model() {
let self = this;
return this.store.findRecord('doi', this.modelFor('dois/show').get('id'), { include: 'provider,client,resource-type' }).then(function (doi) {
return this.store.findRecord('doi', this.modelFor('dois/show').get('id'), { include: 'provider,client,resource-type' }).then(function(doi) {
return doi;
}).catch(function (reason) {
if (console.debug) {
console.debug(reason);
} else {
console.log(reason);
}
}).catch(function(reason) {
console.debug(reason);

self.get('flashMessages').warning('Fabrica is currently unavailable due to a DataCite API problem. We apologize for the inconvenience and are working hard to restore the service. Please check back later or contact DataCite Support if you have a question.');
self.transitionTo('/');
Expand All @@ -26,5 +22,5 @@ export default Route.extend({
} else {
this.modelFor('dois/show').set('mode', 'edit');
}
}
},
});
8 changes: 2 additions & 6 deletions app/routes/dois/show/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ export default Route.extend({
let self = this;
return this.store.findRecord('doi', this.modelFor('dois/show').get('id'), { include: 'client' }).then(function(doi) {
return doi;
}).catch(function(reason){
if (console.debug) {
console.debug(reason);
} else {
console.log(reason);
}
}).catch(function(reason) {
console.debug(reason);

self.get('flashMessages').warning('Fabrica is currently unavailable due to a DataCite API problem. We apologize for the inconvenience and are working hard to restore the service. Please check back later or contact DataCite Support if you have a question.');
self.transitionTo('/');
Expand Down
10 changes: 3 additions & 7 deletions app/routes/dois/show/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ export default Route.extend({
let self = this;
return this.store.findRecord('doi', this.modelFor('dois/show').get('id'), { include: 'provider,client,resource-type' }).then(function(doi) {
return doi;
}).catch(function(reason){
if (console.debug) {
console.debug(reason);
} else {
console.log(reason);
}
}).catch(function(reason) {
console.debug(reason);

self.get('flashMessages').warning('Fabrica is currently unavailable due to a DataCite API problem. We apologize for the inconvenience and are working hard to restore the service. Please check back later or contact DataCite Support if you have a question.');
self.transitionTo('/');
Expand All @@ -26,5 +22,5 @@ export default Route.extend({
} else {
this.modelFor('dois/show').set('mode', 'modify');
}
}
},
});
6 changes: 3 additions & 3 deletions app/routes/dois/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export default Route.extend({

model() {
let repository = this.modelFor('repositories/show');
let doi = this.store.createRecord('doi', { repository: repository, mode: 'upload', state: 'draft' });
let doi = this.store.createRecord('doi', { repository, mode: 'upload', state: 'draft' });

return hash({
repository: repository,
doi: doi
repository,
doi,
});
},

Expand Down
12 changes: 4 additions & 8 deletions app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ export default Route.extend({
let self = this;
return this.store.findRecord('provider', 'admin').then(function(admin) {
return admin;
}).catch(function(reason){
if (console.debug) {
console.debug(reason);
} else {
console.log(reason);
}
}).catch(function(reason) {
console.debug(reason);

self.get('flashMessages').warning('Fabrica is currently unavailable due to a DataCite API problem. We apologize for the inconvenience and are working hard to restore the service. Please check back later or contact DataCite Support if you have a question.');
self.transitionTo('index');
Expand All @@ -38,6 +34,6 @@ export default Route.extend({
actions: {
queryParamsDidChange() {
this.refresh();
}
}
},
},
});
18 changes: 9 additions & 9 deletions app/routes/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import Route from '@ember/routing/route';

export default Route.extend(AuthenticatedRouteMixin, {
currentUser: service(),
authenticationRoute: "sign-in",

authenticationRoute: 'sign-in',

model() {
if (this.currentUser.get("client_id")) {
return this.store.findRecord('repository', this.currentUser.get("uid")).then(function(repository) {
if (this.currentUser.get('client_id')) {
return this.store.findRecord('repository', this.currentUser.get('uid')).then(function(repository) {
repository.set('confirmSymbol', repository.get('symbol'));
return repository;
});
} else if (this.currentUser.get("provider_id")) {
return this.store.findRecord('provider', this.currentUser.get("uid")).then(function(provider) {
} else if (this.currentUser.get('provider_id')) {
return this.store.findRecord('provider', this.currentUser.get('uid')).then(function(provider) {
provider.set('confirmSymbol', provider.get('symbol'));
return provider;
});
} else if (this.currentUser.get("uid") === "admin") {
return this.store.findRecord('provider', "admin").then(function(provider) {
} else if (this.currentUser.get('uid') === 'admin') {
return this.store.findRecord('provider', 'admin').then(function(provider) {
provider.set('confirmSymbol', provider.get('symbol'));
return provider;
});
}
}
},
});
Loading

0 comments on commit 4948b82

Please sign in to comment.