From a0cd5b2f53d0e439756047da0bdd78fcf49f596e Mon Sep 17 00:00:00 2001 From: "Barrett K. Harber" Date: Tue, 25 Oct 2016 13:56:12 -0400 Subject: [PATCH 001/147] Move npm script, `check-style`, into test (avoids failing CI tests) --- .travis.yml | 2 +- package.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 383160a89..02533c978 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,4 +20,4 @@ install: - bower install script: - - npm run check-style && npm test + - npm test diff --git a/package.json b/package.json index a7471104e..27df95876 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,7 @@ "docs": "yuidoc", "docs-deploy": "yuidoc && ghp-import -r origin -p -b gh-pages docs/", "start": "ember server", - "test": "ember test", - "check-style": "./node_modules/jscs/bin/jscs ." + "test": "./node_modules/jscs/bin/jscs . && ember test" }, "repository": "", "engines": { From bf08462cebfc38c414b68ebc3d1d952d37f9a395 Mon Sep 17 00:00:00 2001 From: "Barrett K. Harber" Date: Tue, 25 Oct 2016 13:57:51 -0400 Subject: [PATCH 002/147] Move auth/user dropdown to its own component (needed for Preprints) --- .../navbar-auth-dropdown/component.js | 67 +++++++++++++++++++ .../navbar-auth-dropdown/style.scss | 5 ++ .../navbar-auth-dropdown/template.hbs | 37 ++++++++++ addon/components/osf-navbar/component.js | 37 +--------- addon/components/osf-navbar/style.scss | 6 -- addon/components/osf-navbar/template.hbs | 55 ++------------- addon/styles/addon.scss | 1 + .../navbar-auth-dropdown/component.js | 1 + .../navbar-auth-dropdown/component-test.js | 16 +++++ 9 files changed, 135 insertions(+), 90 deletions(-) create mode 100644 addon/components/navbar-auth-dropdown/component.js create mode 100644 addon/components/navbar-auth-dropdown/style.scss create mode 100644 addon/components/navbar-auth-dropdown/template.hbs create mode 100644 app/components/navbar-auth-dropdown/component.js create mode 100644 tests/integration/components/navbar-auth-dropdown/component-test.js diff --git a/addon/components/navbar-auth-dropdown/component.js b/addon/components/navbar-auth-dropdown/component.js new file mode 100644 index 000000000..96634e42f --- /dev/null +++ b/addon/components/navbar-auth-dropdown/component.js @@ -0,0 +1,67 @@ +import Ember from 'ember'; +import layout from './template'; +import config from 'ember-get-config'; + +/** + * @module ember-osf + * @submodule components + */ + +/** + * Display the login dropdown on the navbar + * + * Sample usage: + * ```handlebars + * {{navbar-auth-dropdown + * loginAction=loginAction}} + * ``` + * + * @class osf-navbar + */ +export default Ember.Component.extend({ + layout, + session: Ember.inject.service(), + currentUser: Ember.inject.service(), + + tagName: 'li', + classNames: ['dropdown'], + classNameBindings: ['notAuthenticated:sign-in'], + notAuthenticated: Ember.computed.not('session.isAuthenticated'), + + /** + * The URL to use for signup. May be overridden, eg for special campaign pages + * + * @property signupUrl + * @type {String} + */ + signupUrl: config.OSF.url + 'register', + + gravatarUrl: Ember.computed('user', function() { + let imgLink = this.get('user.links.profile_image'); + + return imgLink ? `${imgLink}&s=25` : ''; + }), + host: config.OSF.url, + user: null, + _loadCurrentUser() { + this.get('currentUser') + .load() + .then(user => this.set('user', user)); + }, + init() { + this._super(...arguments); + // TODO: React to changes in service/ event? + if (this.get('session.isAuthenticated')) { + this._loadCurrentUser(); + } + }, + // TODO: These parameters are defined in osf settings.py; make sure ember config matches. + allowLogin: true, + enableInstitutions: true, + actions: { + logout() { + // TODO: May not work well if logging out from page that requires login- check? + this.get('session').invalidate(); + }, + } +}); diff --git a/addon/components/navbar-auth-dropdown/style.scss b/addon/components/navbar-auth-dropdown/style.scss new file mode 100644 index 000000000..cc0da01ec --- /dev/null +++ b/addon/components/navbar-auth-dropdown/style.scss @@ -0,0 +1,5 @@ +.osf-gravatar > img { + border: 1px solid #CDCDCD; + border-radius: 13px; + margin-right: 5px; +} diff --git a/addon/components/navbar-auth-dropdown/template.hbs b/addon/components/navbar-auth-dropdown/template.hbs new file mode 100644 index 000000000..beb2dc2e3 --- /dev/null +++ b/addon/components/navbar-auth-dropdown/template.hbs @@ -0,0 +1,37 @@ +{{# if session.isAuthenticated }} + {{! TODO: Replace display name functionality if possible- for now truncate via CSS at end of label }} + + +{{else if allowLogin}} + {{#if institution}} {{! TODO: How does the page know whether this is an institution view? Implement in the future }} + + {{else}} + + {{/if}} +{{/if}} \ No newline at end of file diff --git a/addon/components/osf-navbar/component.js b/addon/components/osf-navbar/component.js index e0be33e8c..8a8300087 100644 --- a/addon/components/osf-navbar/component.js +++ b/addon/components/osf-navbar/component.js @@ -22,7 +22,6 @@ import config from 'ember-get-config'; export default Ember.Component.extend({ layout, session: Ember.inject.service(), - currentUser: Ember.inject.service(), onSearchPage: false, /** * Whether search icons and functionality show up @@ -31,45 +30,13 @@ export default Ember.Component.extend({ */ hideSearch: false, - /** - * The URL to use for signup. May be overridden, eg for special campaign pages - * - * @property signupUrl - * @type {String} - */ - signupUrl: config.OSF.url + 'register', - - gravatarUrl: Ember.computed('user', function() { - let imgLink = this.get('user.links.profile_image'); - if (imgLink) { - imgLink += '&s=25'; - } - return imgLink; - }), - fullName: null, host: config.OSF.url, - user: null, + showSearch: false, - _loadCurrentUser() { - this.get('currentUser').load().then((user) => this.set('user', user)); - }, - init() { - this._super(...arguments); - // TODO: React to changes in service/ event? - if (this.get('session.isAuthenticated')) { - this._loadCurrentUser(); - } - }, - // TODO: These parameters are defined in osf settings.py; make sure ember config matches. - allowLogin: true, - enableInstitutions: true, + actions: { toggleSearch() { this.toggleProperty('showSearch'); }, - logout() { - // TODO: May not work well if logging out from page that requires login- check? - this.get('session').invalidate(); - }, } }); diff --git a/addon/components/osf-navbar/style.scss b/addon/components/osf-navbar/style.scss index 981f51246..6c2670b0e 100644 --- a/addon/components/osf-navbar/style.scss +++ b/addon/components/osf-navbar/style.scss @@ -1,9 +1,3 @@ -.osf-gravatar>img { - border: 1px solid #CDCDCD; - border-radius: 13px; - margin-right: 5px; -} - a.navbar-service::before { content: "/"; padding-right: 8px; diff --git a/addon/components/osf-navbar/template.hbs b/addon/components/osf-navbar/template.hbs index 651b72f6f..2ad6fb990 100644 --- a/addon/components/osf-navbar/template.hbs +++ b/addon/components/osf-navbar/template.hbs @@ -8,8 +8,8 @@ - {{# unless hideSearch}} - {{# unless onSearchPage}} + {{#unless hideSearch}} + {{#unless onSearchPage}} {{!-- TODO: Replace usage of knockout--}} @@ -39,13 +39,13 @@
  • Preprints
  • - {{# unless session.isAuthenticated}} + {{#unless session.isAuthenticated}} {{/unless}} - {{# unless hideSearch}} - {{# unless onSearchPage}} + {{#unless hideSearch}} + {{#unless onSearchPage}} {{/unless}} {{/unless}} - {{# if session.isAuthenticated }} - {{!-- TODO: Replace display name functionality if possible- for now truncate via CSS at end of label --}} - - {{else if allowLogin}} - {{#if institution}} {{!-- TODO: How does the page know whether this is an institution view? Implement in the future --}} - - {{else}} - - {{/if}} - {{/if}} + {{navbar-auth-dropdown loginAction=loginAction}} {{!--/.navbar-collapse --}} diff --git a/addon/styles/addon.scss b/addon/styles/addon.scss index 71c6c4141..ba9e1ecae 100644 --- a/addon/styles/addon.scss +++ b/addon/styles/addon.scss @@ -1,6 +1,7 @@ @import 'components/eosf-project-nav/style'; @import 'components/file-browser/style'; @import 'components/file-widget/style'; +@import 'components/navbar-auth-dropdown/style'; @import 'components/osf-navbar/style'; @import 'components/osf-mode-footer/style'; @import 'components/search-dropdown/style'; diff --git a/app/components/navbar-auth-dropdown/component.js b/app/components/navbar-auth-dropdown/component.js new file mode 100644 index 000000000..d760176a3 --- /dev/null +++ b/app/components/navbar-auth-dropdown/component.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/components/navbar-auth-dropdown/component'; diff --git a/tests/integration/components/navbar-auth-dropdown/component-test.js b/tests/integration/components/navbar-auth-dropdown/component-test.js new file mode 100644 index 000000000..d24161d62 --- /dev/null +++ b/tests/integration/components/navbar-auth-dropdown/component-test.js @@ -0,0 +1,16 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('navbar-auth-dropdown', 'Integration | Component | navbar auth dropdown', { + integration: true +}); + +test('it renders', function (assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + + this.set('loginAction', ()=>{}); + this.render(hbs`{{navbar-auth-dropdown loginAction=loginAction}}`); + + assert.notEqual(this.$().text().trim(), ''); +}); From 7331215d4e0603e4dc4caf4c0f7dd4d5e89c166f Mon Sep 17 00:00:00 2001 From: "Barrett K. Harber" Date: Tue, 25 Oct 2016 15:36:53 -0400 Subject: [PATCH 003/147] Add headline for navbar-auth-dropdown --- addon/components/navbar-auth-dropdown/template.hbs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addon/components/navbar-auth-dropdown/template.hbs b/addon/components/navbar-auth-dropdown/template.hbs index beb2dc2e3..18cc22ce1 100644 --- a/addon/components/navbar-auth-dropdown/template.hbs +++ b/addon/components/navbar-auth-dropdown/template.hbs @@ -7,6 +7,9 @@ {{!--/.navbar-collapse --}} From a8714dae617e16ce43ca12cbe19d4fd549ddc5c8 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 14 Nov 2016 14:47:37 -0500 Subject: [PATCH 023/147] Modify test. --- tests/unit/adapters/osf-adapter-test.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/unit/adapters/osf-adapter-test.js b/tests/unit/adapters/osf-adapter-test.js index 8d45cb6a7..202d9affe 100644 --- a/tests/unit/adapters/osf-adapter-test.js +++ b/tests/unit/adapters/osf-adapter-test.js @@ -530,13 +530,23 @@ test('#findRecord can embed(via include) data with findRecord', function(assert) let store = this.store; let node = FactoryGuy.make('node'); - let child = FactoryGuy.make('node'); + var children; + Ember.run(() => { + children = [ + store.createRecord('node', { + title: 'Foo' + }), + store.createRecord('node', { + title: 'Bar' + }) + ]; + }); + node.get('children').pushObjects(children); + Ember.run(() => { node.set('title', 'Parent'); - child.set('title', 'Child'); - node.set('children', [child]); store.findRecord('node', node.id, { include: 'children' }).then(res => { - assert.equal(res.get('children').toArray()[0].get('title'), child.get('title')); + assert.equal(res.get('children').toArray()[0].get('title'), children[0].get('title')); }); }); From 73ff96e9b940d4f90d80ceeed7c52b5796f4f57b Mon Sep 17 00:00:00 2001 From: "Barrett K. Harber" Date: Mon, 14 Nov 2016 15:30:15 -0500 Subject: [PATCH 024/147] Update link for PREP-244 --- addon/components/osf-copyright/template.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/components/osf-copyright/template.hbs b/addon/components/osf-copyright/template.hbs index a4786c206..f4dc1c197 100644 --- a/addon/components/osf-copyright/template.hbs +++ b/addon/components/osf-copyright/template.hbs @@ -3,7 +3,7 @@

    Copyright © 2011-2016 - Center for Open Science | + Center for Open Science | Terms of Use | Privacy Policy

    From 50753b69bda0ecd7d96b572be7c21abc9e112f01 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Tue, 15 Nov 2016 11:12:07 -0500 Subject: [PATCH 025/147] Add embedding-records route to dummy app for isolating demonstration of embeds feature. --- .../app/controllers/embedding-records.js | 22 +++++++++ tests/dummy/app/router.js | 1 + tests/dummy/app/routes/embedding-records.js | 5 ++ .../dummy/app/templates/embedding-records.hbs | 46 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 tests/dummy/app/controllers/embedding-records.js create mode 100644 tests/dummy/app/routes/embedding-records.js create mode 100644 tests/dummy/app/templates/embedding-records.hbs diff --git a/tests/dummy/app/controllers/embedding-records.js b/tests/dummy/app/controllers/embedding-records.js new file mode 100644 index 000000000..f68487295 --- /dev/null +++ b/tests/dummy/app/controllers/embedding-records.js @@ -0,0 +1,22 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + preprintNode: null, + preprint: null, + nodePreprintsQueried: false, + actions: { + loadNodeEmbedPreprint() { + this.store.findAll('node', { include: 'preprints' }).then((nodes) => { + this.toggleProperty('nodePreprintsQueried'); + for (var node of nodes.toArray()) { + let preprints = node.get('preprints').toArray(); + if (preprints.length > 0 && preprints[0].get('isPublished')) { + this.set('preprintNode', node); + this.set('preprint', preprints[0]); + break; + } + } + }); + } + } +}); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index b1b702605..69543b922 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -63,6 +63,7 @@ Router.map(function() { this.route('prereg'); this.route('allnodes'); this.route('usernodes'); + this.route('embedding-records'); }); export default Router; diff --git a/tests/dummy/app/routes/embedding-records.js b/tests/dummy/app/routes/embedding-records.js new file mode 100644 index 000000000..cdd575783 --- /dev/null +++ b/tests/dummy/app/routes/embedding-records.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + +}); diff --git a/tests/dummy/app/templates/embedding-records.hbs b/tests/dummy/app/templates/embedding-records.hbs new file mode 100644 index 000000000..a56291ce4 --- /dev/null +++ b/tests/dummy/app/templates/embedding-records.hbs @@ -0,0 +1,46 @@ +
    +
    +
    +

    Demonstration of Embedded Records

    + +

    + + {{#if nodePreprintsQueried}} + {{#if preprintNode}} +

    + : {{preprintNode.title}} + : {{preprintNode.id}} +

    +

    + + : {{preprint.id}} + {{#if preprint.doi}} + {{preprint.doi}} + {{/if}} +

    +

    {{preprintNode.description}}

    +

    + + +

      + {{#each preprint.subjects as |subjectBlock|}} + {{#each subjectBlock as |subject|}} +
    • <{{subject.text}}/li> + {{/each}} + {{/each}} +
    + +

    + {{else}} +

    No nodes with published preprints on them (that you can access at least)!

    + {{/if}} + + {{/if}} + +
    +
    +
    + + + + From f5b1c3370cac8b4d1485bcf77a8fa26d73ca2cf5 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Tue, 15 Nov 2016 14:42:33 -0500 Subject: [PATCH 026/147] Query example with embed. --- .../app/controllers/embedding-records.js | 13 +++++++++ .../dummy/app/templates/embedding-records.hbs | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/tests/dummy/app/controllers/embedding-records.js b/tests/dummy/app/controllers/embedding-records.js index f68487295..851dc2482 100644 --- a/tests/dummy/app/controllers/embedding-records.js +++ b/tests/dummy/app/controllers/embedding-records.js @@ -4,6 +4,8 @@ export default Ember.Controller.extend({ preprintNode: null, preprint: null, nodePreprintsQueried: false, + usersQueried: false, + matchingUsers: Ember.A(), actions: { loadNodeEmbedPreprint() { this.store.findAll('node', { include: 'preprints' }).then((nodes) => { @@ -17,6 +19,17 @@ export default Ember.Controller.extend({ } } }); + }, + searchUsers(userQuery) { + this.set('usersQueried', false); + this.store.query('user', { + filter: {full_name: userQuery}, + embed: 'nodes' + }).then((users) => { + this.set('usersQueried', true); + this.set('matchingUsers', users); + }); + } } }); diff --git a/tests/dummy/app/templates/embedding-records.hbs b/tests/dummy/app/templates/embedding-records.hbs index a56291ce4..37c65f721 100644 --- a/tests/dummy/app/templates/embedding-records.hbs +++ b/tests/dummy/app/templates/embedding-records.hbs @@ -3,6 +3,8 @@

    Demonstration of Embedded Records

    +
    +

    {{#if nodePreprintsQueried}} @@ -37,6 +39,31 @@ {{/if}} +
    + + {{input value=userQuery placeholder='Enter user name'}} + + {{#if matchingUsers}} +

    +
      + {{#each matchingUsers as |user|}} +
    • {{user.fullName}}
    • + {{#if user.nodes}} +

      User Nodes:

      +
        + {{#each user.nodes as |node|}} +
      • {{node.title}}
      • + {{/each}} +
      + {{/if}} + {{/each}} +
    + {{else}} + {{#if usersQueried}} +

    No users matching this query!

    + {{/if}} + {{/if}} +
    From 8f8409d3bbbb22d6f9a41e72a665ee3979b465bc Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Tue, 15 Nov 2016 14:56:04 -0500 Subject: [PATCH 027/147] Add message to dummy app. --- tests/dummy/app/templates/embedding-records.hbs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/dummy/app/templates/embedding-records.hbs b/tests/dummy/app/templates/embedding-records.hbs index 37c65f721..3240fdaa2 100644 --- a/tests/dummy/app/templates/embedding-records.hbs +++ b/tests/dummy/app/templates/embedding-records.hbs @@ -13,8 +13,8 @@ : {{preprintNode.title}} : {{preprintNode.id}}

    +

    This preprint was embedded on this node, so a separate request wasn't required to fetch it!

    - : {{preprint.id}} {{#if preprint.doi}} {{preprint.doi}} @@ -49,6 +49,7 @@ {{#each matchingUsers as |user|}}

  • {{user.fullName}}
  • {{#if user.nodes}} +

    These nodes were embedded in the user response so a separate request was not required!

    User Nodes:

    diff --git a/addon/components/license-picker/component.js b/addon/components/license-picker/component.js index 7823d7df8..544fce3f8 100644 --- a/addon/components/license-picker/component.js +++ b/addon/components/license-picker/component.js @@ -10,6 +10,16 @@ export default Ember.Component.extend({ this.set('licensesAvailable', ret); }); }, + nodeLicenseText: Ember.computed('nodeLicense.text', 'year', 'copyrightHolders', function() { + let text = this.get('nodeLicense.text'); + if (!text) { + return ''; + } + text = text.replace(/({{year}})/g, this.get('year') || ''); + text = text.replace(/({{copyrightHolders}})/g, this.get('copyrightHolders') || ''); + return text; + }), + // nodeLicense: Ember.computed('licensesAvailable', function() { // return this.get('currentValues.licenseType') || this.get('licensesAvailable')[0]; // //return this.get('store').findRecord('license', '57a8c6b752386caf6a68df1e');//this.get('licenseId')); @@ -33,8 +43,8 @@ export default Ember.Component.extend({ year: null, copyrightHolders: null, actions: { - selectLicense() { - console.log('oks') + selectLicense(license) { + this.set('nodeLicense', license); }, save() { let values = { diff --git a/addon/components/license-picker/template.hbs b/addon/components/license-picker/template.hbs index 1fcd283fa..4a7264f6c 100644 --- a/addon/components/license-picker/template.hbs +++ b/addon/components/license-picker/template.hbs @@ -1,14 +1,15 @@

    {{license-list licenses=licensesAvailable showCategories=true select=(action 'selectLicense')}} - -{{!input value=nodeLicense.name}}

    {{input value=year}}

    {{input value=copyrightHolders}} -

    {{nodeLicense.text}}

    + +

    {{nodeLicenseText}}

    + {{#if allowDismiss}} - + {{/if}} + From 4e746ffb8677fcd111fa10787413a46d48d6e93c Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Wed, 16 Nov 2016 16:55:52 -0500 Subject: [PATCH 040/147] working on styling --- addon/components/license-picker/template.hbs | 27 ++++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/addon/components/license-picker/template.hbs b/addon/components/license-picker/template.hbs index 4a7264f6c..1cfa929b9 100644 --- a/addon/components/license-picker/template.hbs +++ b/addon/components/license-picker/template.hbs @@ -1,15 +1,20 @@ -

    -{{license-list licenses=licensesAvailable showCategories=true select=(action 'selectLicense')}} +
    +
    +

    + {{license-list licenses=licensesAvailable showCategories=true select=(action 'selectLicense')}} -

    -{{input value=year}} -

    -{{input value=copyrightHolders}} +
    +

    + {{input value=year}} +

    + {{input value=copyrightHolders}} -

    {{nodeLicenseText}}

    +
    {{nodeLicenseText}}
    -{{#if allowDismiss}} - -{{/if}} + {{#if allowDismiss}} + + {{/if}} - + +
    +
    From 03d51ca1d4342d4d7f589bdb50a88880dd5cbdef Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 16 Nov 2016 17:33:43 -0500 Subject: [PATCH 041/147] Add the linkedNodes relationship to the node model. --- addon/models/node.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addon/models/node.js b/addon/models/node.js index 3dbc14f04..f3bab05e2 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -66,6 +66,10 @@ export default OsfModel.extend(FileItemMixin, { nodeLinks: DS.hasMany('node-links', { inverse: null }), + linkedNodes: DS.hasMany('nodes', { + inverse: null, + serializerType: 'linked-node' + }), registrations: DS.hasMany('registrations', { inverse: 'registeredFrom' }), From 3a71574ad719f1ce464a4ebe4e7298c18c6b5aec Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 16 Nov 2016 17:34:17 -0500 Subject: [PATCH 042/147] Modify the addNodeLink and removeNodeLink methods to be using linkedNodes structure. --- addon/mixins/node-actions.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/addon/mixins/node-actions.js b/addon/mixins/node-actions.js index 5cfdaf4e7..8c6f5fcac 100644 --- a/addon/mixins/node-actions.js +++ b/addon/mixins/node-actions.js @@ -197,30 +197,32 @@ export default Ember.Mixin.create({ return this.get('_node').addChild(title, description, category); }, /** - * Add a node link (pointer) to another node + * Adds a relationship to another node, called a linkedNode. * * @method addNodeLink - * @param {String} targetNodeId ID of the node for which you wish to create a pointer - * @return {Promise} Returns a promise that resolves to model for the newly created NodeLink + * @param {String} targetNodeId ID of the node for which you wish to create a link + * @return {Promise} Returns a promise that resolves to the newly updated node */ addNodeLink(targetNodeId) { var node = this.get('_node'); - var nodeLink = this.store.createRecord('node-link', { - target: targetNodeId + return this.store.findRecord('node', targetNodeId).then(linkedNode => { + node.get('linkedNodes').pushObject(linkedNode); + return node.save(); }); - node.get('nodeLinks').pushObject(nodeLink); - return node.save().then(() => nodeLink); + }, /** - * Remove a node link (pointer) to another node + * Removes the linkedNode relationship to another node. Does not remove the linked node itself. * * @method removeNodeLink - * @param {Object} nodeLink nodeLink record to be destroyed. - * @return {Promise} Returns a promise that resolves after the node link has been removed. This does not delete - * the target node itself. + * @param {Object} linkedNode linkedNode relationship to be destroyed. + * @return {Promise} Returns a promise that resolves to the newly updated node */ - removeNodeLink(nodeLink) { - return nodeLink.destroyRecord(); + removeNodeLink(linkedNode) { + var node = this.get('_node'); + node.get('linkedNodes').removeObject(linkedNode); + return node.save(); } + } }); From d1ebedc091e32f64a953892fce3ab83164afadab Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 16 Nov 2016 17:34:46 -0500 Subject: [PATCH 043/147] Modify dummy app to demonstrate use of linkedNodes instead of node links. --- tests/dummy/app/templates/nodes/detail/index.hbs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index 62c36dda5..a529b88a8 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -116,25 +116,25 @@
    -

    Node links

    +

    Linked Nodes (formerly node links. After API v2.1, node links have been deprecated).

    - {{#if model.nodeLinks}} + {{#if model.linkedNodes}} - {{#each model.nodeLinks as |nodelink|}} + {{#each model.linkedNodes as |node|}} - - - + + + {{/each}} {{/if}}
    Id Name
    {{nodelink.targetNode.id}} {{link-to nodelink.targetNode.title 'nodes.detail' nodelink.targetNode.id}} {{node.id}} {{link-to node.title 'nodes.detail' node.id}}

    -

    Add link

    +

    Add linked node relationship

    {{input value=targetNodeId}} From e0a305d7b1272a866a1d83c26d9244100f89bd20 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 16 Nov 2016 17:35:19 -0500 Subject: [PATCH 044/147] Fix bug where canonicalRecords are not getting cleaned up when deleting relationships. --- addon/adapters/osf-adapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index d98c35ea9..b8210e8a1 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -223,7 +223,7 @@ export default DS.JSONAPIAdapter.extend(HasManyQuery.RESTAdapterMixin, GenericDa data: data, isBulk: isBulk }).then(res => { - if (!Ember.$.isArray(res.data)) { + if (res && !Ember.$.isArray(res.data)) { res.data = [res.data]; } return res; From f278a89bd3d3492eb41ca60b5a7c9a1776efc69f Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Thu, 17 Nov 2016 10:54:18 -0500 Subject: [PATCH 045/147] work on passing defaults --- addon/components/license-list/component.js | 4 +- addon/components/license-picker/component.js | 61 +++++++++++-------- addon/components/license-picker/template.hbs | 27 ++++---- .../app/templates/nodes/detail/index.hbs | 2 +- 4 files changed, 55 insertions(+), 39 deletions(-) diff --git a/addon/components/license-list/component.js b/addon/components/license-list/component.js index b3f43bb25..7e304bf1a 100644 --- a/addon/components/license-list/component.js +++ b/addon/components/license-list/component.js @@ -10,11 +10,11 @@ const defaultCategories = { export default Ember.Component.extend({ layout, _selectedLicense: null, - selectedLicense: Ember.computed('attrs.currentLicense', 'licenses', '_selectedLicense', function() { + selectedLicense: Ember.computed('currentLicense', 'licenses', '_selectedLicense', function() { if (this.get('_selectedLicense') !== null) { return this.get('_selectedLicense'); } - return this.get('attrs.currentLicense'); + return this.get('currentLicense'); }), categories: Ember.A(), categoriesSeparator: Ember.observer('licenses', function() { diff --git a/addon/components/license-picker/component.js b/addon/components/license-picker/component.js index 544fce3f8..aa7e8e483 100644 --- a/addon/components/license-picker/component.js +++ b/addon/components/license-picker/component.js @@ -4,12 +4,44 @@ import layout from './template'; export default Ember.Component.extend({ layout, store: Ember.inject.service(), - init: function() { - this._super(...arguments); - this.get('store').query('license', {'page[size]': 20}).then(ret => { - this.set('licensesAvailable', ret); + licensesAvailable: Ember.A(), + showYear: true, + showCopyrightHolders: true, + showOtherFields: Ember.observer('nodeLicense', 'nodeLicense.text', function() { + let text = this.get('nodeLicense.text'); + if (!text) { + return; + } + this.set('showYear', text.indexOf('{{year}}') !== -1); + this.set('showCopyrightHolders', text.indexOf('{{copyrightHolders}}') !== -1); + }), + didReceiveAttrs() { + Ember.run.once(this, function() { + if (!this.get('licenses')) { + this.get('store').query('license', {'page[size]': 20}).then(ret => { + this.set('licensesAvailable', ret); + }); + } else { + this.set('licensesAvailable', this.get('licenses')); + } + if (!this.get('currentValues.year')) { + let date = new Date(); + this.set('year', String(date.getUTCFullYear())); + } else { + this.set('year', this.get('currentValues.year')); + } + if (this.get('currentValues.copyrightHolders')) { + this.set('copyrightHolders', this.get('currentValues.copyrightHolders')); + } }); }, + _setNodeLicense: Ember.observer('licensesAvailable', function() { + if (!this.get('currentValues.licenseType')) { + this.set('nodeLicense', this.get('licensesAvailable.firstObject')); + } else { + this.set('nodeLicense', this.get('currentValues.licenseType')); + } + }), nodeLicenseText: Ember.computed('nodeLicense.text', 'year', 'copyrightHolders', function() { let text = this.get('nodeLicense.text'); if (!text) { @@ -19,27 +51,6 @@ export default Ember.Component.extend({ text = text.replace(/({{copyrightHolders}})/g, this.get('copyrightHolders') || ''); return text; }), - - // nodeLicense: Ember.computed('licensesAvailable', function() { - // return this.get('currentValues.licenseType') || this.get('licensesAvailable')[0]; - // //return this.get('store').findRecord('license', '57a8c6b752386caf6a68df1e');//this.get('licenseId')); - // }), - // licensesAvailable: Ember.computed('currentValues', 'attrs.licenses', function() { - // //if (!this.get('attrs.licenses.value') || this.get('attrs.licenses').length === 0) { - // return this.get('store').query('license', {'page[size]': 20}).then(ret => { - // ret.forEach(each => { - // console.log(each.get('name')); - // if (each.get('name') === "No license") { - // - // this.set('nodeLicense', each); - // } - // }) - // // this.set('nodeLicense', ret[0]); - // return ret; - // }); - // //} - // //return this.get('licenses'); - // }), year: null, copyrightHolders: null, actions: { diff --git a/addon/components/license-picker/template.hbs b/addon/components/license-picker/template.hbs index 1cfa929b9..adca0d726 100644 --- a/addon/components/license-picker/template.hbs +++ b/addon/components/license-picker/template.hbs @@ -1,19 +1,24 @@
    + {{#if allowDismiss}} + {{fa-icon 'times'}} + {{/if}}

    - {{license-list licenses=licensesAvailable showCategories=true select=(action 'selectLicense')}} - + {{license-list licenses=licensesAvailable currentLicense=currentValues.licenseType showCategories=showCategories select=(action 'selectLicense')}}
    -

    - {{input value=year}} -

    - {{input value=copyrightHolders}} - -
    {{nodeLicenseText}}
    - - {{#if allowDismiss}} - + {{#if showYear}} +

    + {{input class='form-control' value=year}} {{/if}} + {{#if showCopyrightHolders}} +

    + {{input value=copyrightHolders}} + {{/if}} +
    +
    +            {{nodeLicenseText}}
    +        
    +
    diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index 60f440394..ed046822e 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -19,7 +19,7 @@

    {{#if licenseToggle}} - {{license-picker licenses=[] currentValues=serializedLicense editLicense=(action 'editLicense') allowDismiss=true dismiss=(action 'toggleLicense')}} + {{license-picker showCategories=true currentValues=serializedLicense editLicense=(action 'editLicense') allowDismiss=true dismiss=(action 'toggleLicense')}} {{/if}}

    From 6af07401debefcb36b7a7de908da59b39cc3424b Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 17 Nov 2016 11:39:11 -0500 Subject: [PATCH 046/147] Remove deprecated nodeLinks from model. --- addon/models/collection.js | 3 --- addon/models/node.js | 3 --- 2 files changed, 6 deletions(-) diff --git a/addon/models/collection.js b/addon/models/collection.js index dabb47be2..39891cd35 100644 --- a/addon/models/collection.js +++ b/addon/models/collection.js @@ -19,9 +19,6 @@ export default OsfModel.extend({ dateCreated: DS.attr('date'), dateModified: DS.attr('date'), bookmarks: DS.attr('boolean'), - // nodeLinks: DS.hasMany('node-links', { - // inverse:null - // }), linkedNodes: DS.hasMany('nodes', { inverse: null, serializerType: 'linked-node' diff --git a/addon/models/node.js b/addon/models/node.js index f3bab05e2..e1b8dfb16 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -63,9 +63,6 @@ export default OsfModel.extend(FileItemMixin, { files: DS.hasMany('file-provider'), //forkedFrom: DS.belongsTo('node'), - nodeLinks: DS.hasMany('node-links', { - inverse: null - }), linkedNodes: DS.hasMany('nodes', { inverse: null, serializerType: 'linked-node' From 9f9150ddc66ce50feb2ae1d3e58d1153fb46746c Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Thu, 17 Nov 2016 11:43:26 -0500 Subject: [PATCH 047/147] work on styling --- addon/components/license-list/component.js | 6 +-- addon/components/license-list/template.hbs | 40 ++++++++++---------- addon/components/license-picker/component.js | 2 + addon/components/license-picker/template.hbs | 10 ++--- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/addon/components/license-list/component.js b/addon/components/license-list/component.js index 7e304bf1a..9e838821f 100644 --- a/addon/components/license-list/component.js +++ b/addon/components/license-list/component.js @@ -9,7 +9,7 @@ const defaultCategories = { export default Ember.Component.extend({ layout, - _selectedLicense: null, + store: Ember.inject.service(), selectedLicense: Ember.computed('currentLicense', 'licenses', '_selectedLicense', function() { if (this.get('_selectedLicense') !== null) { return this.get('_selectedLicense'); @@ -67,8 +67,8 @@ export default Ember.Component.extend({ this.set('categories', categories); }), actions: { - select(license) { - this.set('_selectedLicense', license); + select() { + let license = this.get('store').peekRecord('license', this.$('select')[0].value); this.sendAction('select', license); } } diff --git a/addon/components/license-list/template.hbs b/addon/components/license-list/template.hbs index efdb40064..3574a0c1a 100644 --- a/addon/components/license-list/template.hbs +++ b/addon/components/license-list/template.hbs @@ -1,22 +1,22 @@ -