# HG changeset patch # User ymh # Date 1456871733 -3600 # Node ID 66c1d31e2f97c7f0a4072facca467c30a16cae4e # Parent c06d08c8a1b82b8deb8eba4beb3cb5bdbc0dcd6c first steps to add subject editing diff -r c06d08c8a1b8 -r 66c1d31e2f97 common/corpus-common-addon/addon/utils/utils.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/corpus-common-addon/addon/utils/utils.js Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,5 @@ +import * as constants from 'corpus-common-addon/utils/constants'; + +export function isBnfLink(s) { + return s.startsWith(constants.BNF_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_URL) || s.startsWith(constants.BNF_ARK_BASE_ID); +}; diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/locales/en/translations.js --- a/server/bo_client/app/locales/en/translations.js Sun Feb 28 09:30:23 2016 +0100 +++ b/server/bo_client/app/locales/en/translations.js Tue Mar 01 23:35:33 2016 +0100 @@ -20,6 +20,9 @@ "contributors_th_url": "URL", "contributors_th_role": "Role", "contributors_th_actions": "Actions", + "subjects_th_label": "Label", + "subjects_th_url": "URL", + "subjects_th_actions": "Actions", "olac_role_annotator": "annotator", "olac_role_author": "author", "olac_role_compiler": "compiler", diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/locales/fr/translations.js --- a/server/bo_client/app/locales/fr/translations.js Sun Feb 28 09:30:23 2016 +0100 +++ b/server/bo_client/app/locales/fr/translations.js Tue Mar 01 23:35:33 2016 +0100 @@ -19,6 +19,9 @@ "contributors_th_url": "URL", "contributors_th_role": "Role", "contributors_th_actions": "Actions", + "subjects_th_label": "Label", + "subjects_th_url": "URL", + "subjects_th_actions": "Actions", "olac_role_annotator": "annotateur", "olac_role_author": "auteur", "olac_role_compiler": "compilateur", diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/pods/components/bo-doc-bnf-autocomplete/component.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/app/pods/components/bo-doc-bnf-autocomplete/component.js Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,96 @@ +import Ember from 'ember'; +import URI from 'urijs'; +import suggestionTemplate from 'bo-client/templates/components/bo-doc-bnf-autocomplete/suggestion'; +import _ from 'lodash/lodash'; + +export default Ember.Component.extend({ + env: function() { + return Ember.getOwner(this).resolveRegistration('config:environment'); + }, + actions: { + setBnfId: function(value) { + if(_.isString(value)) { + this.set('bnfId', { + label: value, + value: value, + id: "", + url: "", + nametype: "" } + ); + } + else { + this.set('bnfId', value); + } + }, + }, + + limit: 15, + + display(selection) { + return selection.value; + }, + + setValue(selection) { + let typeahead = Ember.$(this.$(), ".aupac-typeahead"); + if(selection) { + if(_.isString(selection)) { + typeahead.typeahead('val', selection); + } else { + typeahead.typeahead('val', selection.value); + } + + } else { + typeahead.typeahead('val', ''); + } + }, + + keyDown(event) { + if(event.which === this.get('constants').KEY_CODES.RETURN) { + Ember.$(this.$(), ".aupac-typeahead").typeahead('close'); + } + }, + + suggestionTemplate: suggestionTemplate, + + _registerAfterRender: function() { + Ember.run.schedule('afterRender', this, function () { + this.set('registerAs', this); + }); + }.on('init'), + + + bnfSource : function(query, syncResults, asyncResults) { + var url = URI(this.env().APP['bo-doc-bnf-autocomplete'].bnfQueryUrl).query({term: query}).toString(); + Ember.$.ajax({ + url: url, + dataType: "jsonp", + success: function(data) { + var queryTextRes = { + label: query, + value: query, + id: "", + url: "", + nametype: "" + }; + if (data.result) { + var results = Ember.$.map( data.result, function(item) { + var retLbl = item.term + " [" + item.nametype + "]", + bnfurl = this.env().APP['bo-doc-viaf-autocomplete'].viafBaseUrl + item.bnfid; + return { + label: retLbl, + value: item.term, + id: item.bnfid, + url: bnfurl, + nametype: item.nametype + }; + }); + results.unshift(queryTextRes); + asyncResults( results ); + } else { + asyncResults([queryTextRes]); + } + }, + }); + } + +}); diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/pods/components/bo-doc-bnf-autocomplete/template.hbs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/app/pods/components/bo-doc-bnf-autocomplete/template.hbs Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,13 @@ +{{aupac-typeahead action=(action 'setBnfId') + class=(if inputclass inputclass) + source=bnfSource + placeholder=(if placeholder placeholder) + display=display + async=true + hint=false + suggestionTemplate=suggestionTemplate + selection=(readonly initialBnfId) + allowFreeInput=false + limit=15 + setValue=setValue +}} diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/pods/components/bo-doc-new-subject/component.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/app/pods/components/bo-doc-new-subject/component.js Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,46 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + tagName: "tr", + bnfId: null, + initialBnfId: null, + actions: { + addNewContributor: function() { + if(!this.get('valuesNotSet')) { + this.get('onAdd')(this.getProperties('label','url')); + this.clearProperties(); + } + } + }, + clearProperties: function() { + var subjectDef = { + bnfId: null, + }; + this.setProperties(subjectDef); + //clear typeahead + this.$('.aupac-typeahead').typeahead('val',''); + }, + + _clearAfterRender: function() { + Ember.run.schedule('afterRender', this, function () { + this.clearProperties(); + }); + }.on('init'), + + valuesNotSet: Ember.computed('url', function() { + return !( this.get('url') ); + }), + + label: Ember.computed('bnfId', function() { + var bnfId = this.get('bnfId'); + return (bnfId == null)?"":bnfId.value; + }), + + url: Ember.computed('bnfId', function() { + var bnfId = this.get('bnfId'); + return (bnfId == null)?"":bnfId.url; + }), + + urlPresent: Ember.computed.bool('url'), + +}); diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/pods/components/bo-doc-new-subject/template.hbs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/app/pods/components/bo-doc-new-subject/template.hbs Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,12 @@ +  + +
+ {{bo-doc-viaf-autocomplete inputclass="form-control" placeholder=(t 'bo.contributors_th_name') viafId=viafId initialViafId=initialViafId class='col-md-11'}} + {{#if urlPresent }} +   + {{ else }} +
 
+ {{/if}} +
+ +{{fa-icon "plus" class=(if valuesNotSet "bo-doc-no-edit-icons" "bo-doc-edit-icons") click=(action "addNewContributor")}} diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/pods/components/bo-doc-subject-row/component.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/app/pods/components/bo-doc-subject-row/component.js Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,11 @@ +import Ember from 'ember'; +import * as utils from 'corpus-common-addon/utils/utils'; + +export default Ember.Component.extend({ + tagName: "tr", + isSubjectLink: Ember.computed.match('subject', /^http\:\/\//), + isBnfLink: Ember.computed('subject', function() { + return utils.isBnfLink(this.get('subject')); + }), + isNotBnfLink: Ember.computed.not("isBnfLink") +}); diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/pods/components/bo-doc-subject-row/styles.scss --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/app/pods/components/bo-doc-subject-row/styles.scss Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,3 @@ +.bo-doc-subject-not-bnf { + color: $gray; +} diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/pods/components/bo-doc-subject-row/template.hbs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/app/pods/components/bo-doc-subject-row/template.hbs Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,6 @@ +{{add-one index}} +{{component (get-link-type subject) url=subject}} +{{#if isSubjectLink}}{{subject}}{{/if}} + + {{#if isBnfLink }}{{fa-icon "trash-o" class="bo-doc-edit-icons" }}{{/if}} + diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/pods/components/bo-doc-subjects/component.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/app/pods/components/bo-doc-subjects/component.js Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,21 @@ +import Ember from 'ember'; +import _ from 'lodash/lodash'; +import * as utils from 'corpus-common-addon/utils/utils'; + +export default Ember.Component.extend({ + isEditing: false, + subjectsList: Ember.computed("document.subjects[]", function() { + return _.union( + _.filter(this.get("document").get("subjects"), utils.isBnfLink), + _.filter(this.get("document").get("subjects"), function(s) { return !utils.isBnfLink(s); }) + ); + }), + actions: { + toggleEditSubjects: function() { + this.set('isEditing', !this.get('isEditing')); + this.$('#doc-subjects-table-pane').slideToggle(); + this.$('#doc-subjects-list-pane').slideToggle(); + }, + } + +}); diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/pods/components/bo-doc-subjects/styles.scss --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/app/pods/components/bo-doc-subjects/styles.scss Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,5 @@ + +#doc-subjects-table-pane { + display: none; + margin-top: 20px; +} diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/pods/components/bo-doc-subjects/template.hbs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/app/pods/components/bo-doc-subjects/template.hbs Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,36 @@ +
+ {{ fa-icon "pencil" class='bo-doc-edit-icons' click=(action "toggleEditSubjects")}} +
+
+
{{#each model.subjects as |subject index|}}{{if index ", "}}{{component (get-link-type subject) url=subject}}{{/each}}
+
+ +
+
+
{{t 'bo.document_subjects'}}
+
+
+
{{#each document.subjects as |subject index|}}{{if index ", "}}{{component (get-link-type subject) url=subject}}{{/each}}
+
+
+
+ {{#if isEditing}} + + + + + + + + + + + {{#each subjectsList as |subject index|}} + {{bo-doc-subject-row subject=subject index=index}} + {{/each}} + +
#{{t 'bo.subjects_th_label'}}{{t 'bo.subjects_th_url'}}{{t 'bo.subjects_th_actions'}}
+ {{/if}} +
+
+
diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/pods/components/bo-doc-viaf-autocomplete/component.js --- a/server/bo_client/app/pods/components/bo-doc-viaf-autocomplete/component.js Sun Feb 28 09:30:23 2016 +0100 +++ b/server/bo_client/app/pods/components/bo-doc-viaf-autocomplete/component.js Tue Mar 01 23:35:33 2016 +0100 @@ -11,7 +11,6 @@ actions: { setViafId: function(value) { - console.log('setViafId',value); if(_.isString(value)) { this.set('viafId', { label: value, @@ -30,12 +29,10 @@ limit: 15, display(selection) { - console.log('DISPLAY',selection); return selection.value; }, setValue(selection) { - console.log('setValue',selection); let typeahead = Ember.$(this.$(), ".aupac-typeahead"); if(selection) { if(_.isString(selection)) { diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/templates/components/bo-doc-bnf-autocomplete/suggestion.hbs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/app/templates/components/bo-doc-bnf-autocomplete/suggestion.hbs Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,1 @@ +
{{#if model}}{{model.label}} - {{model.url}}{{/if}}
diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/app/templates/doc.hbs --- a/server/bo_client/app/templates/doc.hbs Sun Feb 28 09:30:23 2016 +0100 +++ b/server/bo_client/app/templates/doc.hbs Tue Mar 01 23:35:33 2016 +0100 @@ -38,13 +38,7 @@
-
-   -
-
-
{{t 'bo.document_subjects'}}
-
{{#each model.subjects as |subject index|}}{{if index ", "}}{{component (get-link-type subject) url=subject}}{{/each}}
-
+ {{bo-doc-subjects document=model}}
diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/config/environment.js --- a/server/bo_client/config/environment.js Sun Feb 28 09:30:23 2016 +0100 +++ b/server/bo_client/config/environment.js Tue Mar 01 23:35:33 2016 +0100 @@ -24,6 +24,10 @@ 'bo-doc-viaf-autocomplete' : { viafQueryUrl: "http://viaf.org/viaf/AutoSuggest?query=", viafBaseUrl: "http://viaf.org/viaf/", + }, + 'bo-doc-bnf-autocomplete' : { + bnfQueryUrl: "http://data.bnf.fr/search-letter/?term=", + bnfBaseUrl: "http://data.bnf.fr/", } }, }; diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/tests/integration/pods/components/bo-doc-bnf-autocomplete/component-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/tests/integration/pods/components/bo-doc-bnf-autocomplete/component-test.js Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('bo-doc-bnf-autocomplete', 'Integration | Component | bo doc bnf autocomplete', { + 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.render(hbs`{{bo-doc-bnf-autocomplete}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage:" + this.render(hbs` + {{#bo-doc-bnf-autocomplete}} + template block text + {{/bo-doc-bnf-autocomplete}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/tests/integration/pods/components/bo-doc-new-subject/component-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/tests/integration/pods/components/bo-doc-new-subject/component-test.js Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('bo-doc-new-subject', 'Integration | Component | bo doc new subject', { + 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.render(hbs`{{bo-doc-new-subject}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage:" + this.render(hbs` + {{#bo-doc-new-subject}} + template block text + {{/bo-doc-new-subject}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/tests/integration/pods/components/bo-doc-subject-row/component-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/tests/integration/pods/components/bo-doc-subject-row/component-test.js Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('bo-doc-subject-row', 'Integration | Component | bo doc subject row', { + 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.render(hbs`{{bo-doc-subject-row}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage:" + this.render(hbs` + {{#bo-doc-subject-row}} + template block text + {{/bo-doc-subject-row}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); diff -r c06d08c8a1b8 -r 66c1d31e2f97 server/bo_client/tests/integration/pods/components/bo-doc-subjects/component-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/bo_client/tests/integration/pods/components/bo-doc-subjects/component-test.js Tue Mar 01 23:35:33 2016 +0100 @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('bo-doc-subjects', 'Integration | Component | bo doc subjects', { + 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.render(hbs`{{bo-doc-subjects}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage:" + this.render(hbs` + {{#bo-doc-subjects}} + template block text + {{/bo-doc-subjects}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +});