Work on front and back integration, correct the expected data format
authorymh <ymh.work@gmail.com>
Tue, 04 Oct 2016 11:58:39 +0200
changeset 319 78990a8a069b
parent 318 5564f5065f81
child 320 0fce13da58af
Work on front and back integration, correct the expected data format
.hgignore
cms/app-client/README.md
cms/app-client/app/adapters/application.js
cms/app-client/app/components/discourses-component.js
cms/app-client/app/components/visu-langues.js
cms/app-client/app/serializers/geostat.js
cms/app-client/app/serializers/theme.js
cms/app-client/config/environment.js
cms/app-client/mirage/config.js
cms/app-client/mirage/serializers/datestat.js
cms/app-client/mirage/serializers/discourse.js
cms/app-client/mirage/serializers/geostat.js
cms/app-client/mirage/serializers/language.js
cms/app-client/mirage/serializers/theme.js
server/src/app/Http/Controllers/Api/DocumentController.php
server/src/app/Models/DocumentResult.php
server/src/gulpfile.js
server/src/public/css/app.css
server/src/routes/api.php
server/src/tests/Controllers/DiscourseControllerTest.php
server/src/tests/Controllers/GeoStatsControllerTest.php
--- a/.hgignore	Mon Oct 03 16:32:41 2016 +0200
+++ b/.hgignore	Tue Oct 04 11:58:39 2016 +0200
@@ -35,6 +35,7 @@
 ^server/src/public/css
 ^server/src/public/js/vendor
 ^server/src/public/fonts
+^server/src/public/corpus-app
 ^server/bo_client/.dir-locals.el$
 ^server/bo_client/.projectile$
 ^server/bo_client/node_modules
--- a/cms/app-client/README.md	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/README.md	Tue Oct 04 11:58:39 2016 +0200
@@ -7,16 +7,11 @@
 
 You will need the following things properly installed on your computer.
 
-* [Git](http://git-scm.com/)
 * [Node.js](http://nodejs.org/) (with NPM)
-* [Bower](http://bower.io/)
-* [Ember CLI](http://www.ember-cli.com/)
 * [PhantomJS](http://phantomjs.org/)
 
 ## Installation
 
-* `git clone <repository-url>` this repository
-* change into the new directory
 * `npm install`
 * `bower install`
 
--- a/cms/app-client/app/adapters/application.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/app/adapters/application.js	Tue Oct 04 11:58:39 2016 +0200
@@ -9,11 +9,13 @@
 
 export default RESTAdapter.extend({
 
-    namespace: ENV.backRootURL.replace(/\/$/,"")+'/api/v1',
+    namespace: (ENV.APP.backRootURL || ENV.rootURL).replace(/\/$/,"")+'/api/v1',
 
     buildURL: function(modelName, id) {
         if(modelName === 'transcript') {
-            return this.urlPrefix() + '/documents/' + id + '/' + modelName;
+            return this.urlPrefix() + '/documents/' + encodeURIComponent(encodeURIComponent(id)) + '/' + modelName;
+        } else if (modelName === 'document' && id) {
+            return this.urlPrefix() + '/documents/' + encodeURIComponent(encodeURIComponent(id)) ;
         }
         return this._super(...arguments);
     },
--- a/cms/app-client/app/components/discourses-component.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/app/components/discourses-component.js	Tue Oct 04 11:58:39 2016 +0200
@@ -18,9 +18,10 @@
 
     didRender: function() {
         var self = this;
-        var baseURL = ENV.backRootURL.replace(/\/$/,"")+'/api/v1/stats';
+        var baseURL = (ENV.APP.backRootURL || ENV.rootURL).replace(/\/$/,"")+'/api/v1/stats';
 
-        d3.json(baseURL + "/discourses", function(discourses) {
+        d3.json(baseURL + "/discourses", function(data) {
+            var discourses = data['discourses'];
             var array = Object.keys(discourses).map(function (key) { return discourses[key].count; });
             var oldMin = Math.min(...array),
                 oldMax = Math.max(...array);
--- a/cms/app-client/app/components/visu-langues.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/app/components/visu-langues.js	Tue Oct 04 11:58:39 2016 +0200
@@ -15,13 +15,14 @@
 
     didInsertElement: function(){
         var self = this;
-        var baseurl = ENV.backRootURL.replace(/\/$/,"")+'/api/v1';
+        var baseurl = (ENV.APP.backRootURL || ENV.rootURL).replace(/\/$/,"")+'/api/v1';
 
-        d3.json(baseurl+"/stats/languages", function(languages) {
+        d3.json(baseurl+"/stats/languages", function(data) {
             var margin = { top: 30, right: 0, bottom: 0, left: 0 };
             var width = Ember.$('#' + self.get('elementId')).width();
             var height = Ember.$('#' + self.get('elementId')).height() - margin.top - margin.bottom;
 
+            var languages = data['languages'];
             var array = Object.keys(languages).map(function (key) { return languages[key]; });
             var oldMin = Math.min(...array),
                 oldMax = Math.max(...array);
--- a/cms/app-client/app/serializers/geostat.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/app/serializers/geostat.js	Tue Oct 04 11:58:39 2016 +0200
@@ -4,7 +4,7 @@
 
     normalizeResponse: function(store, primaryModelClass, payload) {
         var data = [];
-        Object.keys(payload).forEach(function(key) {
+        Object.keys(payload['geostats']).forEach(function(key) {
             data.push({
                 'id': key,
                 'type': 'geostat',
@@ -18,4 +18,4 @@
         };
     }
 
-});
\ No newline at end of file
+});
--- a/cms/app-client/app/serializers/theme.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/app/serializers/theme.js	Tue Oct 04 11:58:39 2016 +0200
@@ -4,13 +4,14 @@
 
     normalizeResponse: function(store, primaryModelClass, payload) {
         var data = [];
-        Object.keys(payload).forEach(function(key) {
+        var themes = payload['themes'];
+        Object.keys(themes).forEach(function(key) {
             data.push({
                 'id': key,
                 'type': 'theme',
                 'attributes': {
-                    'label': payload[key].label,
-                    'count': payload[key].count
+                    'label': themes[key].label,
+                    'count': themes[key].count
                 }
             });
         });
@@ -19,4 +20,4 @@
         };
     }
 
-});
\ No newline at end of file
+});
--- a/cms/app-client/config/environment.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/config/environment.js	Tue Oct 04 11:58:39 2016 +0200
@@ -6,7 +6,6 @@
         modulePrefix: 'app-client',
         environment: environment,
         rootURL: '/corpus/',
-        backRootURL: '/corpus/',
         locationType: 'hash',
         EmberENV: {
             FEATURES: {
@@ -15,13 +14,12 @@
             }
         },
         APP: {
-            baseStatic: ''
+            backRootURL: '/corpus/',
             // Here you can pass flags/options to your application instance
             // when it is created
         }
     };
     if (environment === 'development') {
-        ENV.APP.baseStatic = '';
         ENV.contentSecurityPolicy = {
             'default-src': "'none'",
             'script-src': "'self' *",
@@ -34,14 +32,17 @@
     }
     if (environment === 'test') {
         ENV.rootURL = '/';
-        ENV.backRootURL = '/';
         ENV.locationType = 'none';
         ENV.APP.LOG_ACTIVE_GENERATION = false;
         ENV.APP.LOG_VIEW_LOOKUPS = false;
         ENV.APP.rootElement = '#ember-testing';
+        ENV.APP.backRootURL = '/';
     }
+
     if (environment === 'production') {
-        ENV.APP.baseStatic = '/modules/corpus/app-client/';
+        ENV.rootURL = '/corpus-app/';
+        ENV.APP.backRootURL = '/corpus-back/';
     }
+
     return ENV;
 };
--- a/cms/app-client/mirage/config.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/mirage/config.js	Tue Oct 04 11:58:39 2016 +0200
@@ -13,7 +13,7 @@
     */
     // this.urlPrefix = '';    // make this `http://localhost:8080`, for example, if your API is on a different server
     // this.namespace = '';    // make this `api`, for example, if your API is namespaced
-    this.namespace = ENV.backRootURL.replace(/\/$/,'')+'/api/v1';
+    this.namespace = (ENV.APP.backRootURL || ENV.rootURL).replace(/\/$/,'')+'/api/v1';
     // this.timing = 400;      // delay for each request, automatically set to 0 during testing
 
     this.get('/documents', function({ documents }) {
@@ -21,12 +21,12 @@
     });
 
     this.get('/documents/:id', ({documents}, request) => {
-        let id = decodeURIComponent(request.params.id);
+        let id = decodeURIComponent(decodeURIComponent(request.params.id));
         return documents.find(id);
     });
 
     this.get('/documents/:id/transcript',  ({transcripts}, request) => {
-        let id = decodeURIComponent(request.params.id);
+        let id = decodeURIComponent(decodeURIComponent(request.params.id));
         return transcripts.find(id).transcript;
     });
 
--- a/cms/app-client/mirage/serializers/datestat.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/mirage/serializers/datestat.js	Tue Oct 04 11:58:39 2016 +0200
@@ -4,6 +4,6 @@
 
 export default JSONAPISerializer.extend({
     serialize(response) {
-        return _(response.models).map((dateinfo) => { return [dateinfo.id, dateinfo.count];}).object().value();
+        return {'datestats': _(response.models).map((dateinfo) => { return [dateinfo.id, dateinfo.count];}).object().value()};
     }
 });
--- a/cms/app-client/mirage/serializers/discourse.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/mirage/serializers/discourse.js	Tue Oct 04 11:58:39 2016 +0200
@@ -4,6 +4,6 @@
 
 export default JSONAPISerializer.extend({
     serialize(response) {
-        return _(response.models).map((discourse) => { return [discourse.id, {count: discourse.count, label: discourse.label}];}).object().value();
+        return { 'discourses' : _(response.models).map((discourse) => { return [discourse.id, {count: discourse.count, label: discourse.label}];}).object().value()};
     }
 });
--- a/cms/app-client/mirage/serializers/geostat.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/mirage/serializers/geostat.js	Tue Oct 04 11:58:39 2016 +0200
@@ -5,6 +5,6 @@
 export default JSONAPISerializer.extend({
     serialize(response, request) {
     	var map = response.models.find(map => map.id === request.queryParams['area']);
-        return _(map && map.areas || {}).map((geostat) => { return [geostat.id, geostat.count];}).object().value();
+        return {'geostats': _(map && map.areas || {}).map((geostat) => { return [geostat.id, geostat.count];}).object().value()};
     }
 });
--- a/cms/app-client/mirage/serializers/language.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/mirage/serializers/language.js	Tue Oct 04 11:58:39 2016 +0200
@@ -4,6 +4,6 @@
 
 export default JSONAPISerializer.extend({
     serialize(response) {
-        return _(response.models).map((lang) => { return [lang.id, lang.count];}).object().value();
+        return {'languages' : _(response.models).map((lang) => { return [lang.id, lang.count];}).object().value()};
     }
 });
--- a/cms/app-client/mirage/serializers/theme.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/cms/app-client/mirage/serializers/theme.js	Tue Oct 04 11:58:39 2016 +0200
@@ -30,7 +30,7 @@
         } else {
             array = response.models;
         }
-        return _(array).map((theme) => { return [theme.id, {count: theme.count, label: theme.label}];}).object().value();
+        return { 'themes': _(array).map((theme) => { return [theme.id, {count: theme.count, label: theme.label}];}).object().value() };
     }
 
 });
--- a/server/src/app/Http/Controllers/Api/DocumentController.php	Mon Oct 03 16:32:41 2016 +0200
+++ b/server/src/app/Http/Controllers/Api/DocumentController.php	Tue Oct 04 11:58:39 2016 +0200
@@ -67,7 +67,7 @@
      */
     public function show(Request $request, $id)
     {
-        $id= urldecode($id);
+        $id = urldecode($id);
         $short = filter_var($request->input('short', false), FILTER_VALIDATE_BOOLEAN);
         $doc = $this->documentRepository->get($id, $short);
         if(is_null($doc)) {
--- a/server/src/app/Models/DocumentResult.php	Mon Oct 03 16:32:41 2016 +0200
+++ b/server/src/app/Models/DocumentResult.php	Tue Oct 04 11:58:39 2016 +0200
@@ -85,8 +85,8 @@
 
         if($this->graph) {
             $res = array_merge($res, [
-                'publishers' => $this->getPublishersValue(),
-                'duration' => $this->getDurationValue(),
+                'publisher' => $this->getPublishersValue(),
+                'duration_ms' => $this->getDurationValue(),
                 'transcript_url' => $this->getTranscriptUrl()
             ]);
         }
--- a/server/src/gulpfile.js	Mon Oct 03 16:32:41 2016 +0200
+++ b/server/src/gulpfile.js	Tue Oct 04 11:58:39 2016 +0200
@@ -45,8 +45,8 @@
         if(err) {
             return;
         }
-        gulp.src(['**/*','!vendor', '!vendor/**', '!node_modules', '!node_modules/**', '!.env', '!.git*'])
-            .pipe(gulp.dest('../../build/root/var/www/corpusdelaparole/corpus/'))
+        gulp.src(['**/*','!vendor', '!vendor/**', '!node_modules', '!public/corpus-app', '!public/corpus-app/**','!node_modules/**', '!.env', '!.git*'])
+            .pipe(gulp.dest('../../build/root/var/www/corpusdelaparole/corpus-back/'))
     });
 });
 
--- a/server/src/public/css/app.css	Mon Oct 03 16:32:41 2016 +0200
+++ b/server/src/public/css/app.css	Tue Oct 04 11:58:39 2016 +0200
@@ -1,7 +1,7 @@
 @charset "UTF-8";
 /*!
- * Bootstrap v3.3.6 (http://getbootstrap.com)
- * Copyright 2011-2015 Twitter, Inc.
+ * Bootstrap v3.3.7 (http://getbootstrap.com)
+ * Copyright 2011-2016 Twitter, Inc.
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  */
 /*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
@@ -1072,7 +1072,6 @@
     color: #23527c;
     text-decoration: underline; }
   a:focus {
-    outline: thin dotted;
     outline: 5px auto -webkit-focus-ring-color;
     outline-offset: -2px; }
 
@@ -2284,7 +2283,6 @@
 input[type="file"]:focus,
 input[type="radio"]:focus,
 input[type="checkbox"]:focus {
-  outline: thin dotted;
   outline: 5px auto -webkit-focus-ring-color;
   outline-offset: -2px; }
 
@@ -2789,7 +2787,6 @@
   -ms-user-select: none;
   user-select: none; }
   .btn:focus, .btn.focus, .btn:active:focus, .btn:active.focus, .btn.active:focus, .btn.active.focus {
-    outline: thin dotted;
     outline: 5px auto -webkit-focus-ring-color;
     outline-offset: -2px; }
   .btn:hover, .btn:focus, .btn.focus {
@@ -4374,12 +4371,6 @@
   .alert-danger .alert-link {
     color: #843534; }
 
-@-webkit-keyframes progress-bar-stripes {
-  from {
-    background-position: 40px 0; }
-  to {
-    background-position: 0 0; } }
-
 @keyframes progress-bar-stripes {
   from {
     background-position: 40px 0; }
@@ -4413,7 +4404,6 @@
 
 .progress.active .progress-bar,
 .progress-bar.active {
-  -webkit-animation: progress-bar-stripes 2s linear infinite;
   animation: progress-bar-stripes 2s linear infinite; }
 
 .progress-bar-success {
@@ -5027,12 +5017,9 @@
   -webkit-overflow-scrolling: touch;
   outline: 0; }
   .modal.fade .modal-dialog {
-    -webkit-transform: translate(0, -25%);
     transform: translate(0, -25%);
-    transition: -webkit-transform 0.3s ease-out;
     transition: transform 0.3s ease-out; }
   .modal.in .modal-dialog {
-    -webkit-transform: translate(0, 0);
     transform: translate(0, 0); }
 
 .modal-open .modal {
@@ -5375,22 +5362,16 @@
       line-height: 1; }
     @media all and (transform-3d), (-webkit-transform-3d) {
       .carousel-inner > .item {
-        transition: -webkit-transform 0.6s ease-in-out;
         transition: transform 0.6s ease-in-out;
-        -webkit-backface-visibility: hidden;
         backface-visibility: hidden;
-        -webkit-perspective: 1000px;
         perspective: 1000px; }
         .carousel-inner > .item.next, .carousel-inner > .item.active.right {
-          -webkit-transform: translate3d(100%, 0, 0);
           transform: translate3d(100%, 0, 0);
           left: 0; }
         .carousel-inner > .item.prev, .carousel-inner > .item.active.left {
-          -webkit-transform: translate3d(-100%, 0, 0);
           transform: translate3d(-100%, 0, 0);
           left: 0; }
         .carousel-inner > .item.next.left, .carousel-inner > .item.prev.right, .carousel-inner > .item.active {
-          -webkit-transform: translate3d(0, 0, 0);
           transform: translate3d(0, 0, 0);
           left: 0; } }
   .carousel-inner > .active,
--- a/server/src/routes/api.php	Mon Oct 03 16:32:41 2016 +0200
+++ b/server/src/routes/api.php	Tue Oct 04 11:58:39 2016 +0200
@@ -11,36 +11,26 @@
 */
 Route::group(['prefix' => 'v1'] , function() {
 
-    Route::group(['prefix' => 'documents'], function() {
-        Route::pattern('id', ".*");
-        Route::get('{id}/transcript', 'Api\DocumentController@transcript');
-        Route::resource('', 'Api\DocumentController',
-                        ['only' => ['index', 'show', 'update']]);
-    });
+    Route::pattern('id', ".*");
+    Route::get('documents/{id}/transcript', 'Api\DocumentController@transcript');
+    Route::resource('documents', 'Api\DocumentController', [
+            'only' => ['index', 'show', 'update']
+    ]);
 
 
     Route::group(['prefix' => 'resolvers'], function() {
-        Route::resource('viaf', 'Api\ViafController',
-                        ['only' => ['show']]);
-        Route::resource('lexvo', 'Api\LexvoController',
-                        ['only' => ['show']]);
-        Route::resource('bnf', 'Api\BnfController',
-                        ['only' => ['index','show']]);
-        Route::resource('geonames', 'Api\GeonamesController',
-                        ['only' => ['index','show']]);
+        Route::get('viaf/{id}', 'Api\ViafController@show');
+        Route::get('lexvo/{id}', 'Api\LexvoController@show');
+        Route::get('bnf/{id}', 'Api\BnfController@show');
+        Route::get('geonames/{id}', 'Api\GeonamesController@show');
     });
 
 
     Route::group(['prefix' => 'stats'], function() {
-        Route::resource('languages', 'Api\LanguageController',
-                        ['only' => ['index']]);
-        Route::resource('themes', 'Api\ThemeController',
-                        ['only' => ['index']]);
-        Route::resource('discourses', 'Api\DiscourseController',
-                        ['only' => ['index']]);
-        Route::resource('datestats', 'Api\DateStatsController',
-                        ['only' => ['index']]);
-        Route::resource('geostats', 'Api\GeoStatsController',
-                        ['only' => ['index']]);
+        Route::get('languages', 'Api\LanguageController@index');
+        Route::get('themes', 'Api\ThemeController@index');
+        Route::get('discourses', 'Api\DiscourseController@index');
+        Route::get('datestats', 'Api\DateStatsController@index');
+        Route::get('geostats', 'Api\GeoStatsController@index');
     });
 });
--- a/server/src/tests/Controllers/DiscourseControllerTest.php	Mon Oct 03 16:32:41 2016 +0200
+++ b/server/src/tests/Controllers/DiscourseControllerTest.php	Tue Oct 04 11:58:39 2016 +0200
@@ -29,10 +29,10 @@
 
     public function testIndexQuery() {
 
-        $query = preg_replace('/\s+/', ' ', "select (?o as ?res) (COUNT(?s) as ?count) where {
+        $query = preg_replace('/\s+/', ' ', "SELECT (?o AS ?res) (COUNT(?s) AS ?count) WHERE {
             ?s a <http://www.europeana.eu/schemas/edm/ProvidedCHO>.
             ?s <http://purl.org/dc/elements/1.1/type> ?o.
-            filter(uri(?o) in (<".implode('>,<', array_keys(config('corpusparole.corpus_discourse_type'))).">))
+            FILTER(uri(?o) in (<".implode('>,<', array_keys(config('corpusparole.corpus_discourse_type'))).">))
         }
         GROUP BY ?o
         ORDER BY DESC(?count)");
--- a/server/src/tests/Controllers/GeoStatsControllerTest.php	Mon Oct 03 16:32:41 2016 +0200
+++ b/server/src/tests/Controllers/GeoStatsControllerTest.php	Tue Oct 04 11:58:39 2016 +0200
@@ -1,7 +1,5 @@
 <?php
 
-use Es;
-
 class GeoStatsControllerTest extends TestCase
 {
    public function testGetIndex()