# HG changeset patch # User ymh # Date 1465293640 -7200 # Node ID 5e93f5e5f8f9e004194b59a06a44b58d94dee1cc # Parent cf7b221238fd8c2ce41d8ff526bea69269b08061# Parent d1baf7ccecc8341154e0a4ae241751e6505a2cce merged change from front dev diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/components/discourses-component.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/components/discourses-component.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,110 @@ +import Ember from 'ember'; +import d3 from 'd3'; +import env from 'app-client/config/environment'; + + + +export default Ember.Component.extend({ + + constants: Ember.inject.service(), + + init: function() { + this._super(...arguments); + }, + + didRender: function() { + var self = this; + var baseURL = env.baseURL.replace(/\/$/,"")+'/api/v1'; + + d3.json(baseURL + "/discourses", function(discourses) { + console.log(discourses); + + var width = self.$().parent().width(); + var height = self.$().parent().height(); + + var bubble = d3.layout.pack() + .sort(null) + .size([width, height]) + .padding(33); + + var element = d3.select('#' + self.get('elementId')); + + var svg = element.append("svg") + .attr("width", width) + .attr("height", height) + .attr("class", "bubble"); + + var nodes = svg.selectAll(".node") + .data(bubble.nodes(self.createNodes(discourses))) + .enter().append("g") + .attr("width", function(d) { return 2.5 * d.r + 'px'; }) + .attr("class", function(d) { return "node" + (!d.children ? " leaf" : ""); }) + .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) + .style("font-size", function(d) { return Math.max(13, d.r / 2) + 'px'; }); + + + var leaf = svg.selectAll(".leaf") + .on('click', function(d) { document.location = self.setQueryString('discours', d.name); }); + + leaf.append("circle") + .attr("r", function(d) { return d.r; }) + .attr("fill", function(d) { return d.fill; }) + .attr("stroke", function(d) { return "#000"; }); + + leaf.append("text") + .attr("dy", ".3em") + .style("text-anchor", "middle") + .text(function(d) { return d.name; }); + + element.style("height", height + "px"); + }); + + this._super(...arguments); + }, + + createNodes: function(json) { + var self = this; + var nodes = {}; + var children = {}; + + Object.keys(json).forEach(function(key) { + var discourse = json[key]; + var index = self.get('constants').DISCOURSES[key]; + var category = self.get('constants').DISCOURSE_CATEGORIES[index]; + + children[index] = children[index] || {}; + children[index]['name'] = index; + children[index]['children'] = children[index]['children'] || []; + children[index]['children'].push({ "name": discourse.label, "value": discourse.count, "fill": category.fill }); + }); + + nodes.children = []; + Object.keys(children).forEach(function(key) { + nodes.children.push(children[key]); + }); + + return nodes; + }, + + setQueryString: function(field, value) { + var hash = document.location.href.split('?'); + var query_parameters = hash.pop(); + + // Unserialize + var parameters = []; + query_parameters.split('&').forEach(function(parameter){ + var object = parameter.split('='); + object[1] && (parameters[object[0]] = object[1]); + }); + + // Serialize + var string = []; + parameters[field] = encodeURI(value); + Object.keys(parameters).forEach(function(key) { + string.push(key + '=' + parameters[key]); + }); + + return hash + '?' + string.join('&'); + } + +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/components/filtering-component.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/components/filtering-component.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,25 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + + filter: '', + + filteredThemes: Ember.computed.filter('themes', function(item) { + return this.get('filter') && (item.get('label') || '').match(this.get('filter')); + }).property('filter'), + + actions: { + + setQueryParameters: function(id) { + this.get('setQueryParameters')(id); + }, + + filterBy: function(input) { + this.set('filter', input && new RegExp('^' + input)); + this.get('filteredThemes'); + } + + } + + +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/components/sorting-component.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/components/sorting-component.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,26 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + + sorting: [], + sortedThemes: Ember.computed.sort('themes', 'sorting'), + + minimum: Ember.computed('themes', function() { return Math.min(...this.themes.mapBy('count')); }), + + maximum: Ember.computed('themes', function() { return Math.max(...this.themes.mapBy('count')); }), + + actions: { + + + setQueryParameters: function(id) { + this.get('setQueryParameters')(id); + }, + + sortBy: function (type) { + this.set('sorting', type === 'popularity' ? ['count:desc'] : ['label']); + this.get('sortedThemes'); + } + + } + +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/controllers/tabs/discours.js --- a/cms/app-client/app/controllers/tabs/discours.js Tue Jun 07 01:16:31 2016 +0200 +++ b/cms/app-client/app/controllers/tabs/discours.js Tue Jun 07 12:00:40 2016 +0200 @@ -1,9 +1,5 @@ import Ember from 'ember'; export default Ember.Controller.extend({ - actions: { - updateUrl: function(selection){ - this.transitionToRoute({queryParams: {discours: selection}}); - } - } + }); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/controllers/tabs/thematiques.js --- a/cms/app-client/app/controllers/tabs/thematiques.js Tue Jun 07 01:16:31 2016 +0200 +++ b/cms/app-client/app/controllers/tabs/thematiques.js Tue Jun 07 12:00:40 2016 +0200 @@ -1,9 +1,12 @@ import Ember from 'ember'; export default Ember.Controller.extend({ - actions: { - updateUrl: function(selection){ - this.transitionToRoute({queryParams: {thematique: selection}}); + + actions: { + + transitionTo: function(id){ + this.transitionToRoute({queryParams: {thematique: id}}); + } + } - } }); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/helpers/popularity.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/helpers/popularity.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,15 @@ +import Ember from 'ember'; + +export function popularity([target, minimum, maximum]) { + var classname = ['not-popular', 'popular', 'very-popular']; + var interval = ( maximum - minimum ) / classname.length; + + var i = 0; + while( target > minimum + ( interval * ( i + 1 ) ) ) { + i ++; + } + + return classname[i]; +} + +export default Ember.Helper.helper(popularity); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/models/discourse.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/models/discourse.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,5 @@ +import Model from 'ember-data/model'; + +export default Model.extend({ + +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/models/theme.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/models/theme.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,9 @@ +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; + +export default Model.extend({ + + label: attr('string'), + count: attr('number') + +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/routes/tabs/discours.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/routes/tabs/discours.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + +}) \ No newline at end of file diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/routes/tabs/thematiques.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/routes/tabs/thematiques.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,9 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + + model: function() { + return this.store.findAll('theme'); + } + +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/serializers/theme.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/serializers/theme.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,22 @@ +import DS from 'ember-data'; + +export default DS.JSONSerializer.extend({ + + normalizeResponse: function(store, primaryModelClass, payload, id, requestType) { + var data = []; + Object.keys(payload).forEach(function(key) { + data.push({ + 'id': key, + 'type': 'theme', + 'attributes': { + 'label': payload[key].label, + 'count': payload[key].count + } + }); + }); + return { + 'data': data + }; + } + +}); \ No newline at end of file diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/services/constants.js --- a/cms/app-client/app/services/constants.js Tue Jun 07 01:16:31 2016 +0200 +++ b/cms/app-client/app/services/constants.js Tue Jun 07 12:00:40 2016 +0200 @@ -27,6 +27,45 @@ 'http://www.language-archives.org/OLAC/1.1/translator': 'bo.olac_role_translator', }; + +const DISCOURSES = { + "http://ark.bnf.fr/ark:/12148/cb12083158d": "cat1", + "http://ark.bnf.fr/ark:/12148/cb119783362": "cat1", + "http://ark.bnf.fr/ark:/12148/cb119317924": "cat1", + "http://ark.bnf.fr/ark:/12148/cb12481481z": "cat1", + "http://ark.bnf.fr/ark:/12148/cb119341539": "cat1", + "http://ark.bnf.fr/ark:/12148/cb11946100d": "cat1", + "http://ark.bnf.fr/ark:/12148/cb11931724n": "cat2", + "http://ark.bnf.fr/ark:/12148/cb11949715t": "cat2", + "http://ark.bnf.fr/ark:/12148/cb13319048g": "cat3", + "http://ark.bnf.fr/ark:/12148/cb11936159v": "cat3", + "http://ark.bnf.fr/ark:/12148/cb11948542x": "cat3", + "http://ark.bnf.fr/ark:/12148/cb11953414d": "cat3", + "http://ark.bnf.fr/ark:/12148/cb11955657q": "cat3", + "http://ark.bnf.fr/ark:/12148/cb11957378b": "cat3", + "http://ark.bnf.fr/ark:/12148/cb11937212q": "cat3", + "http://ark.bnf.fr/ark:/12148/cb119834877": "cat3", + "http://ark.bnf.fr/ark:/12148/cb11976851v": "cat3", + "http://ark.bnf.fr/ark:/12148/cb120502737": "cat4", + "http://ark.bnf.fr/ark:/12148/cb11932135w": "cat4", + "http://ark.bnf.fr/ark:/12148/cb119829234": "cat4" +}; + +const DISCOURSE_CATEGORIES = { + "cat1": { + "fill": "#b6d7a8" + }, + "cat2": { + "fill": "#ea9999" + }, + "cat3": { + "fill": "#a2c4c9" + }, + "cat4":{ + "fill": "#ffe599" + } +}; + const KEY_CODES = { BACKSPACE : 8, DELETE : 46, @@ -255,6 +294,8 @@ export default Ember.Service.extend({ OLAC_ROLES: OLAC_ROLES, + DISCOURSES: DISCOURSES, + DISCOURSE_CATEGORIES: DISCOURSE_CATEGORIES, KEY_CODES: KEY_CODES, VIAF_BASE_URL: "http://viaf.org/viaf/", LEXVO_BASE_URL: "http://lexvo.org/id/iso639-3/", diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/templates/components/discourses-component.hbs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/templates/components/discourses-component.hbs Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,1 @@ +{{yield}} diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/templates/components/filtering-component.hbs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/templates/components/filtering-component.hbs Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,11 @@ +{{yield}} + +{{ input type='text' key-up='filterBy' placeholder='Entrez une thématique'}} + + \ No newline at end of file diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/templates/components/sorting-component.hbs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/templates/components/sorting-component.hbs Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,24 @@ +{{yield}} + +
+ +
Trier par :
+ + + +
+ + \ No newline at end of file diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/templates/tabs/discours.hbs --- a/cms/app-client/app/templates/tabs/discours.hbs Tue Jun 07 01:16:31 2016 +0200 +++ b/cms/app-client/app/templates/tabs/discours.hbs Tue Jun 07 12:00:40 2016 +0200 @@ -1,30 +1,1 @@ -
-
-

Dialogue

-

Conversation

-

Entretien

-

Discussion

-

Bavardage

-

Argumentation

-

Negociation

-

Reunion

-

Discours

-

Lecture a haute voix

-

Recitation

-

Recit personnel

-

Seminaire

-
-
-

Colloque

-

Conte

-

Fable

-

Narration

-

Chanson

-

Enquete par telephone

-

Questionnaire

-

Enquete

-

Enquetes linguistiques

-

Enquetes de terrain

-

Musique instrumentale

-
-
+{{discourses-component}} \ No newline at end of file diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/app/templates/tabs/thematiques.hbs --- a/cms/app-client/app/templates/tabs/thematiques.hbs Tue Jun 07 01:16:31 2016 +0200 +++ b/cms/app-client/app/templates/tabs/thematiques.hbs Tue Jun 07 12:00:40 2016 +0200 @@ -1,60 +1,5 @@ - +{{outlet}} -
- ipsum - dolor - sit - amet - consectetur - adipiscing - elit - Curabitur - non - ipsum - dolor - sit - amet - consectetur - adipiscing - elit - Curabitur - non - ipsum - dolor - sit - amet - consectetur - adipiscing - elit - Curabitur - non - ipsum - dolor - sit - amet - consectetur - adipiscing - elit - Curabitur - non - ipsum - dolor - sit - amet - consectetur - adipiscing - elit - Curabitur - non - ipsum - dolor - sit - amet - consectetur - adipiscing - elit - Curabitur - non -
+{{ filtering-component themes=model setQueryParameters=( action 'transitionTo' ) }} + +{{ sorting-component themes=model setQueryParameters=( action 'transitionTo' ) }} diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/tests/integration/components/discourses-component-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/tests/integration/components/discourses-component-test.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('discourses-component', 'Integration | Component | discourses component', { + 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`{{discourses-component}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#discourses-component}} + template block text + {{/discourses-component}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/tests/integration/components/filtering-component-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/tests/integration/components/filtering-component-test.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('filtering-component', 'Integration | Component | filtering component', { + 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`{{filtering-component}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#filtering-component}} + template block text + {{/filtering-component}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/tests/integration/components/sorting-component-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/tests/integration/components/sorting-component-test.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('sorting-component', 'Integration | Component | sorting component', { + 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`{{sorting-component}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#sorting-component}} + template block text + {{/sorting-component}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/tests/unit/controllers/tabs/thematiques-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/tests/unit/controllers/tabs/thematiques-test.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('controller:tabs/thematiques', 'Unit | Controller | tabs/thematiques', { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let controller = this.subject(); + assert.ok(controller); +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/tests/unit/helpers/popularity-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/tests/unit/helpers/popularity-test.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,10 @@ +import { popularity } from 'app-client/helpers/popularity'; +import { module, test } from 'qunit'; + +module('Unit | Helper | popularity'); + +// Replace this with your real tests. +test('it works', function(assert) { + let result = popularity([42]); + assert.ok(result); +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/tests/unit/models/discourse-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/tests/unit/models/discourse-test.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('discourse', 'Unit | Model | discourse', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/tests/unit/models/theme-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/tests/unit/models/theme-test.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('theme', 'Unit | Model | theme', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/tests/unit/routes/discours-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/tests/unit/routes/discours-test.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,11 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('route:discours', 'Unit | Route | discours', { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] +}); + +test('it exists', function(assert) { + let route = this.subject(); + assert.ok(route); +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/tests/unit/routes/tabs/thematiques-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/tests/unit/routes/tabs/thematiques-test.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,11 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('route:tabs/thematiques', 'Unit | Route | tabs/thematiques', { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] +}); + +test('it exists', function(assert) { + let route = this.subject(); + assert.ok(route); +}); diff -r cf7b221238fd -r 5e93f5e5f8f9 cms/app-client/tests/unit/serializers/theme-test.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/tests/unit/serializers/theme-test.js Tue Jun 07 12:00:40 2016 +0200 @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('theme', 'Unit | Serializer | theme', { + // Specify the other units that are required for this test. + needs: ['serializer:theme'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +});