Skip to content

Commit

Permalink
Merge pull request #422 from adlius/feature/chronos
Browse files Browse the repository at this point in the history
[EMB-535][EOSF][Chronos][NPD]Merge NPD changes to Chronos branch.
  • Loading branch information
jamescdavis committed Jan 3, 2019
2 parents f61e588 + ce37e25 commit c47e54a
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 175 deletions.
21 changes: 17 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,29 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased]

## [Unreleased]

### Added
- Added `dateWithdrawn` and `withdrawalJustification` to `preprint` model
- 'My Preprints' link to the Preprint navbar
- Contributor mixin to share contributor-related methods between nodes and preprints
- New fields added to `preprint` model for node-preprint divorce
- Default message in `old-file-browser` if no files found

### Changed
- Normalize "Add a Preprint" language across screen sizes
- Node-preprint divorce changes
- `contributor` model now shared between nodes and preprints. `preprint` relationship added to `contributor` model
- Modify `contributor` adapter to talk to both node/preprint contributor endpoints
- `Preprint` adapter has an option to unset a supplemental project from a preprint
- Fix for building mfrURLs

## [0.21.0] - 2018-09-20
### Added
- Added `dateWithdrawn` and `withdrawalJustification` to `preprint` model
- 'My Preprints' link to the Preprint navbar

### Changed
- `users` model to use urlForQuery to allow searching via `/search/users/`
- Normalize "Add a Preprint" language across screen sizes

## [0.20.1] - 2018-08-16
### Remove unwanted lineage code
Expand Down
19 changes: 15 additions & 4 deletions addon/adapters/contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ import OsfAdapter from './osf-adapter';
export default OsfAdapter.extend({
buildURL(modelName, id, snapshot, requestType) { // jshint ignore:line
if (requestType === 'createRecord' || requestType === 'findRecord') {
var nodeId;
var sendEmail = true;
let nodeId;
let sendEmail = true;
let requestUrl;

if (snapshot) {
nodeId = snapshot.record.get('nodeId');
sendEmail = snapshot.record.get('sendEmail');
} else {
nodeId = id.split('-').shift();
}

let type = 'node';
let node = this.store.peekRecord('node', nodeId);
if (!node) {
node = this.store.peekRecord('preprint', nodeId);
type = 'preprint';
}

if (node) {
let base = this._buildRelationshipURL(
node._internalModel.createSnapshot(),
Expand All @@ -24,7 +31,11 @@ export default OsfAdapter.extend({
}

// Needed for Ember Data to update the inverse record's (the node's) relationship
var requestUrl = `${base}?embed=node`;
if (type == 'preprint') {
requestUrl = `${base}?embed=preprint`;
} else {
requestUrl = `${base}?embed=node`;
}

if (!sendEmail) {
requestUrl += `&send_email=false`;
Expand Down
26 changes: 19 additions & 7 deletions addon/adapters/preprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@ import OsfAdapter from './osf-adapter';

export default OsfAdapter.extend({
// Overrides updateRecord on OsfAdapter. Is identical to JSONAPIAdapter > Update Record (parent's parent method).
// Updates to preprints do not need special handling.
// NOTE: With this implementation,
// the app cannot remove a `node` relationship and update other attributes/relationship with one .save() call.
updateRecord(store, type, snapshot) {
var data = {};
var serializer = store.serializerFor(type.modelName);
let data = {};
let url = null;

serializer.serializeIntoHash(data, type, snapshot, { includeId: true });

var id = snapshot.id;
var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord');
if (snapshot.record.get('_dirtyRelationships')['node'] && snapshot.record.get('_dirtyRelationships')['node']['remove'].length && !snapshot.record.get('_dirtyRelationships')['node']['add'].length) {
// Supplemental project has been selected for removal.
// Send request to relationship link to remove node
url = this._buildRelationshipURL(snapshot, 'node');
data = {
'data': null
};
} else {
// Preprint attributes and/or relationships have been modified.
// Send patch request to preprint detail link
const serializer = store.serializerFor(type.modelName);
serializer.serializeIntoHash(data, type, snapshot, { includeId: true });
const id = snapshot.id;
url = this.buildURL(type.modelName, id, snapshot, 'updateRecord');
}

return this.ajax(url, 'PATCH', { data: data });
}
Expand Down
7 changes: 6 additions & 1 deletion addon/components/file-renderer/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export default Ember.Component.extend({
allowfullscreen: true,
version: null,
mfrUrl: Ember.computed('download', 'version', function() {
let download = this.get('download') + '?direct&mode=render';
let download = this.get('download');
if (download.includes('?')) {
download = download + '&mode=render';
} else {
download = download + '?direct&mode=render';
}
if (this.get('version')) {
download += '&version=' + this.get('version');
}
Expand Down
35 changes: 20 additions & 15 deletions addon/components/old-file-browser/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,24 @@
{{/if}}

<div class='old-file-browser-list file-browser-list'>
{{#ember-collection
items=items
cell-layout=(fixed-grid-layout itemWidth itemHeight)
as |item|
}}
{{old-file-browser-item
item=item
navigateToItem=(action 'navigateToItem')
selectItem=(action 'selectItem')
openItem=(action 'openItem')
}}
{{/ember-collection}}
{{#unless itemsLoaded}}
{{fa-icon 'spinner' size=3 pulse=true}}
{{/unless}}
{{#if itemsLoaded}}
{{#if items}}
{{#ember-collection
items=items
cell-layout=(fixed-grid-layout itemWidth itemHeight)
as |item|
}}
{{old-file-browser-item
item=item
navigateToItem=(action 'navigateToItem')
selectItem=(action 'selectItem')
openItem=(action 'openItem')
}}
{{/ember-collection}}
{{else}}
<p class='p-l-md p-t-xs text-muted'><em> No files found </em></p>
{{/if}}
{{else}}
<p class='p-l-md p-t-xs'> {{fa-icon 'spinner' size=3 pulse=true}} </p>
{{/if}}
</div>
6 changes: 6 additions & 0 deletions addon/locales/en/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export default {
singular: 'thesis',
singularCapitalized: 'Thesis',
},
supplementalProject: {
plural: 'supplemental projects',
pluralCapitalized: 'Supplemental Projects',
singular: 'supplemental project',
singularCapitalized: 'Supplemental Project',
}
},
eosf: {
authDropdown: {
Expand Down
146 changes: 146 additions & 0 deletions addon/mixins/contributor-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import Ember from 'ember';

export default Ember.Mixin.create({
/**
* Determine whether the specified user ID is a contributor on this node
* @method isContributor
* @param {String} userId
* @return {boolean} Whether the specified user is a contributor on this node
*/
isContributor(userId) {
// Return true if there is at least one matching contributor for this user ID
if (!userId) {
return new Ember.RSVP.Promise((resolve) => resolve(false));
}
const contribId = `${this.get('id')}-${userId}`;
return this.store.findRecord('contributor', contribId).then(() => true, () => false);
},

save() {
// Some duplicate logic from osf-model#save needed to support
// contributor edits being saved through the node
// Note: order is important here so _dirtyRelationships gets set by the _super call
const promise = this._super(...arguments);
if (!this.get('_dirtyRelationships.contributors')) {
this.set('_dirtyRelationships.contributors', {});
}

const contributors = this.hasMany('contributors').hasManyRelationship;
this.set(
'_dirtyRelationships.contributors.update',
contributors.members.list.filter(m => !m.getRecord().get('isNew') && Object.keys(m.getRecord().changedAttributes()).length > 0)
);
// Need to included created contributors even in relationship
// hasLoaded is false
this.set(
'_dirtyRelationships.contributors.create',
contributors.members.list.filter(m => m.getRecord().get('isNew'))
);
// Contributors are a 'real' delete, not just a de-reference
this.set(
'_dirtyRelationships.contributors.delete',
this.get('_dirtyRelationships.contributors.remove') || []
);
this.set('_dirtyRelationships.contributors.remove', []);
return promise;
},
addContributor(userId, permission, isBibliographic, sendEmail, fullName, email) {
const contrib = this.store.createRecord('contributor', {
permission: permission,
bibliographic: isBibliographic,
sendEmail: sendEmail,
nodeId: this.get('id'),
userId: userId,
fullName: fullName,
email: email
});

return contrib.save();
},

addContributors(contributors, sendEmail) {
const payload = contributors.map(contrib => {
const contribData = {
permission: contrib.permission,
bibliographic: contrib.bibliographic,
nodeId: this.get('id'),
userId: contrib.userId,
id: this.get('id') + '-' + contrib.userId,
};
if (contrib.unregisteredContributor) {
contribData.fullName = contrib.unregisteredContributor;
}
const c = this.store.createRecord('contributor', contribData);

return c.serialize({
includeId: true,
includeUser: true
}).data;
});

let emailQuery = '';
if (!sendEmail) {
emailQuery = '?send_email=false';
} else if (sendEmail === 'preprint') {
emailQuery = '?send_email=preprint';
}

// TODO Get this working properly - should not be an ajax request in the future.
return this.store.adapterFor('contributor').ajax(this.get('links.relationships.contributors.links.related.href') + emailQuery, 'POST', {
data: {
data: payload
},
isBulk: true
}).then(resp => {
this.store.pushPayload(resp);
const createdContribs = Ember.A();
resp.data.map((contrib) => {
createdContribs.push(this.store.peekRecord('contributor', contrib.id));
});
return createdContribs;
});
},

removeContributor(contributor) {
return contributor.destroyRecord().then(rec => {
this.get('store')._removeFromIdMap(rec._internalModel);
});
},

updateContributor(contributor, permissions, bibliographic) {
if (!Ember.isEmpty(permissions))
contributor.set('permission', permissions);
if (!Ember.isEmpty(bibliographic))
contributor.set('bibliographic', bibliographic);
return contributor.save();
},

updateContributors(contributors, permissionsChanges, bibliographicChanges) {
let payload = contributors
.filter(contrib => contrib.id in permissionsChanges || contrib.id in bibliographicChanges)
.map(contrib => {
if (contrib.id in permissionsChanges) {
contrib.set('permission', permissionsChanges[contrib.id]);
}

if (contrib.id in bibliographicChanges) {
contrib.set('bibliographic', bibliographicChanges[contrib.id]);
}

return contrib.serialize({
includeId: true,
includeUser: false
}).data;
});

return this.store.adapterFor('contributor').ajax(this.get('links.relationships.contributors.links.related.href'), 'PATCH', {
data: {
data: payload
},
isBulk: true
}).then(resp => {
this.store.pushPayload(resp);
return contributors;
});
}
});
3 changes: 3 additions & 0 deletions addon/models/contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ export default OsfModel.extend({

node: DS.belongsTo('node', {
inverse: 'contributors'
}),
preprint: DS.belongsTo('preprint', {
inverse: 'contributors'
})
});
Loading

0 comments on commit c47e54a

Please sign in to comment.