# HG changeset patch # User ymh # Date 1470493773 -25200 # Node ID 02e2396bcbbc1799dc08a77240a739e2c867743e # Parent 64caee7ce38dcc48e0aea051002e9d032140adb6 Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error) diff -r 64caee7ce38d -r 02e2396bcbbc cms/app-client/.jshintrc --- a/cms/app-client/.jshintrc Sat Aug 06 21:27:53 2016 +0700 +++ b/cms/app-client/.jshintrc Sat Aug 06 21:29:33 2016 +0700 @@ -1,33 +1,32 @@ { - "predef": [ - "Popcorn", - "server", - "document", - "window", - "-Promise" - ], - "browser": true, - "boss": true, - "curly": true, - "debug": false, - "devel": true, - "eqeqeq": true, - "evil": true, - "forin": false, - "immed": false, - "laxbreak": false, - "noarg": true, - "noempty": false, - "nonew": false, - "nomen": false, - "onevar": false, - "plusplus": false, - "regexp": false, - "undef": true, - "sub": true, - "strict": false, - "white": false, - "eqnull": true, - "esnext": true, - "unused": true + "predef": [ + "document", + "window", + "-Promise" + ], + "browser": true, + "boss": true, + "curly": true, + "debug": false, + "devel": true, + "eqeqeq": true, + "evil": true, + "forin": false, + "immed": false, + "laxbreak": false, + "newcap": true, + "noarg": true, + "noempty": false, + "nonew": false, + "nomen": false, + "onevar": false, + "plusplus": false, + "regexp": false, + "undef": true, + "sub": true, + "strict": false, + "white": false, + "eqnull": true, + "esversion": 6, + "unused": true } diff -r 64caee7ce38d -r 02e2396bcbbc cms/app-client/.travis.yml --- a/cms/app-client/.travis.yml Sat Aug 06 21:27:53 2016 +0700 +++ b/cms/app-client/.travis.yml Sat Aug 06 21:29:33 2016 +0700 @@ -12,7 +12,9 @@ before_install: - npm config set spin false - npm install -g bower + - bower --version - npm install phantomjs-prebuilt + - phantomjs --version install: - npm install diff -r 64caee7ce38d -r 02e2396bcbbc cms/app-client/app/adapters/application.js --- a/cms/app-client/app/adapters/application.js Sat Aug 06 21:27:53 2016 +0700 +++ b/cms/app-client/app/adapters/application.js Sat Aug 06 21:29:33 2016 +0700 @@ -3,7 +3,7 @@ export default RESTAdapter.extend({ - namespace: ENV.baseURL.replace(/\/$/,"")+'/api/v1', + namespace: ENV.rootURL.replace(/\/$/,"")+'/api/v1', buildURL: function(modelName, id) { if(modelName === 'transcript') { @@ -19,4 +19,4 @@ return this._super(...arguments); } -}); \ No newline at end of file +}); diff -r 64caee7ce38d -r 02e2396bcbbc cms/app-client/app/components/discourses-component.js --- a/cms/app-client/app/components/discourses-component.js Sat Aug 06 21:27:53 2016 +0700 +++ b/cms/app-client/app/components/discourses-component.js Sat Aug 06 21:29:33 2016 +0700 @@ -13,8 +13,8 @@ didRender: function() { var self = this; - var baseURL = env.baseURL.replace(/\/$/,"")+'/api/v1'; - + var baseURL = env.rootURL.replace(/\/$/,"")+'/api/v1'; + d3.json(baseURL + "/discourses", function(discourses) { var width = self.$().parent().width(); var height = self.$().parent().height() - self.$().siblings().height(); @@ -66,7 +66,7 @@ .on('click', function(d) { self.get('filter').set('discourse', d.id); }); - + leaf.append("circle") .attr("r", function(d) { return Math.max(7.5 + d.r * 2, d.r * 2); }) .attr("fill", function(d) { return d.fill; }) @@ -100,5 +100,5 @@ return nodes; } - + }); diff -r 64caee7ce38d -r 02e2396bcbbc cms/app-client/app/components/filtering-component.js --- a/cms/app-client/app/components/filtering-component.js Sat Aug 06 21:27:53 2016 +0700 +++ b/cms/app-client/app/components/filtering-component.js Sat Aug 06 21:29:33 2016 +0700 @@ -19,7 +19,7 @@ }, elementFocusOut: function(event) { - if(!Ember.$.contains(this.get('element'), event.target)) { + if(this.get('element') && !Ember.$.contains(this.get('element'), event.target)) { this.set('isDropdownOpen', false); } }, diff -r 64caee7ce38d -r 02e2396bcbbc cms/app-client/app/components/player-component.js --- a/cms/app-client/app/components/player-component.js Sat Aug 06 21:27:53 2016 +0700 +++ b/cms/app-client/app/components/player-component.js Sat Aug 06 21:29:33 2016 +0700 @@ -1,4 +1,5 @@ import Ember from 'ember'; +import Popcorn from 'popcorn'; export default Ember.Component.extend({ classNames: ['player-component'], diff -r 64caee7ce38d -r 02e2396bcbbc cms/app-client/app/components/visu-langues.js --- a/cms/app-client/app/components/visu-langues.js Sat Aug 06 21:27:53 2016 +0700 +++ b/cms/app-client/app/components/visu-langues.js Sat Aug 06 21:29:33 2016 +0700 @@ -52,7 +52,7 @@ .attr("y", 6 - margin.top) .attr("dy", ".75em"); - var baseurl = ENV.baseURL.replace(/\/$/,"")+'/api/v1'; + var baseurl = ENV.rootURL.replace(/\/$/,"")+'/api/v1'; d3.json(baseurl+"/languages", function(languages) { var root = _.cloneDeep(self.constants.LANGUAGES_TREEMAP); @@ -145,7 +145,7 @@ if (transitioning || !d) { return; } - + selectHandler(d); transitioning = true; diff -r 64caee7ce38d -r 02e2396bcbbc cms/app-client/app/index.html --- a/cms/app-client/app/index.html Sat Aug 06 21:27:53 2016 +0700 +++ b/cms/app-client/app/index.html Sat Aug 06 21:29:33 2016 +0700 @@ -10,9 +10,9 @@ {{content-for "head"}} - - - + + + {{content-for "head-footer"}} @@ -34,9 +34,9 @@
- - - + + + - - - - - + + + + + {{content-for "body-footer"}} {{content-for "test-body-footer"}} diff -r 64caee7ce38d -r 02e2396bcbbc cms/app-client/vendor/shims/popcorn.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/vendor/shims/popcorn.js Sat Aug 06 21:29:33 2016 +0700 @@ -0,0 +1,9 @@ +(function() { + function vendorModule() { + 'use strict'; + + return { 'default': self['Popcorn'] }; + } + + define('popcorn', [], vendorModule); +})(); diff -r 64caee7ce38d -r 02e2396bcbbc common/corpus-common-addon/addon/services/resolver-service.js --- a/common/corpus-common-addon/addon/services/resolver-service.js Sat Aug 06 21:27:53 2016 +0700 +++ b/common/corpus-common-addon/addon/services/resolver-service.js Sat Aug 06 21:29:33 2016 +0700 @@ -42,7 +42,7 @@ } Ember.$.ajax({ //TODO Configuration ? - url: this.env().baseURL.replace(/\/$/,'') + this.apiPath +ids, + url: this.env().rootURL.replace(/\/$/,'') + this.apiPath +ids, success: (itemDoc) => { _.each(queryRegister, (resolve_reject) => { diff -r 64caee7ce38d -r 02e2396bcbbc common/corpus-common-addon/tests/dummy/app/router.js --- a/common/corpus-common-addon/tests/dummy/app/router.js Sat Aug 06 21:27:53 2016 +0700 +++ b/common/corpus-common-addon/tests/dummy/app/router.js Sat Aug 06 21:29:33 2016 +0700 @@ -2,7 +2,8 @@ import config from './config/environment'; const Router = Ember.Router.extend({ - location: config.locationType + location: config.locationType, + rootURL: config.rootURL || '/' }); Router.map(function() { diff -r 64caee7ce38d -r 02e2396bcbbc common/corpus-common-addon/tests/dummy/config/environment.js --- a/common/corpus-common-addon/tests/dummy/config/environment.js Sat Aug 06 21:27:53 2016 +0700 +++ b/common/corpus-common-addon/tests/dummy/config/environment.js Sat Aug 06 21:29:33 2016 +0700 @@ -4,7 +4,7 @@ var ENV = { modulePrefix: 'dummy', environment: environment, - baseURL: '/', + rootURL: '/', locationType: 'auto', EmberENV: { FEATURES: { @@ -29,7 +29,7 @@ if (environment === 'test') { // Testem prefers this... - ENV.baseURL = '/'; + ENV.rootURL = '/'; ENV.locationType = 'none'; // keep test console output quieter diff -r 64caee7ce38d -r 02e2396bcbbc server/src/app/Libraries/Utils.php --- a/server/src/app/Libraries/Utils.php Sat Aug 06 21:27:53 2016 +0700 +++ b/server/src/app/Libraries/Utils.php Sat Aug 06 21:29:33 2016 +0700 @@ -3,6 +3,8 @@ use EasyRdf\Literal; use EasyRdf\Resource; +use EasyRdf\Graph; + /** * Utilities functions @@ -117,5 +119,19 @@ } } + /** + * @param EasyRdf\Graph $graph1 + * @param EasyRdf\Graph $graph2 + * + * @return EasyRdf\Graph + */ + public static function mergeGraphs(Graph $graph1, Graph $graph2) + { + $data1 = $graph1->toRdfPhp(); + $data2 = $graph2->toRdfPhp(); + $merged = array_merge_recursive($data1, $data2); + unset($data1, $data2); + return new Graph($graph1->getUri(), $merged, 'php'); + } } diff -r 64caee7ce38d -r 02e2396bcbbc server/src/app/Repositories/RdfDocumentRepository.php --- a/server/src/app/Repositories/RdfDocumentRepository.php Sat Aug 06 21:27:53 2016 +0700 +++ b/server/src/app/Repositories/RdfDocumentRepository.php Sat Aug 06 21:29:33 2016 +0700 @@ -7,7 +7,10 @@ use CorpusParole\Models\DocumentResult; use CorpusParole\Models\Document; use CorpusParole\Libraries\CorpusParoleException; +use CorpusParole\Libraries\Utils; use CorpusParole\Libraries\Sparql\SparqlClient; + + use CorpusParole\Services\LexvoResolverInterface; use EasyRdf\Graph; @@ -21,6 +24,42 @@ */ class RdfDocumentRepository implements DocumentRepository { + const ALL_QUERIES = [ + "SELECT". + " ?uri". + " ?doc". + " ?title". + " ?issued". + " ?modified". + " ?lang". + " (group_concat(distinct ?publisher;separator=\", \") as ?publishers) ". + "WHERE {". + "GRAPH ?uri { ?doc a .". + " ?doc ?title.". + " OPTIONAL {?doc ?lang.} ". + " OPTIONAL {?doc ?issued.} ". + " OPTIONAL {?doc ?modified.} ". + " OPTIONAL {?doc ?publisher.} }". + "} ". + "GROUP BY ?uri ?doc ?title ?issued ?modified ?lang ". + "ORDER BY ?uri", + + "SELECT". + " ?uri". + " ?doc". + " (sample(distinct ?ext) as ?extent) ". + "WHERE {". + " GRAPH ?uri {". + " ?s a . ". + " ?uri ?s. ". + " ?uri ?doc. ". + " OPTIONAL {?s ?ext.}". + " }". + "} ". + "GROUP BY ?uri ?doc ". + "ORDER BY ?uri" + ]; + private $sparqlClient; private $lexvoResolver; @@ -33,44 +72,56 @@ return $this->sparqlClient; } - private function queryDocs($query) { - $docs = $this->sparqlClient->query($query); - - $data = []; - - foreach ($docs as $doc) { - $newGraph = new Graph($doc->uri->getUri()); - $newGraph->add($doc->uri, "rdf:type", $newGraph->resource("http://www.openarchives.org/ore/terms/Aggregation")); - $newGraph->add($doc->uri, "http://www.europeana.eu/schemas/edm/aggregatedCHO", $doc->doc); - $newGraph->add($doc->doc, "rdf:type", $newGraph->resource("http://www.europeana.eu/schemas/edm/ProvidedCHO")); + private function getResGraph($doc) { + $newGraph = new Graph($doc->uri->getUri()); + $newGraph->add($doc->uri, "rdf:type", $newGraph->resource("http://www.openarchives.org/ore/terms/Aggregation")); + $newGraph->add($doc->uri, "http://www.europeana.eu/schemas/edm/aggregatedCHO", $doc->doc); + $newGraph->add($doc->doc, "rdf:type", $newGraph->resource("http://www.europeana.eu/schemas/edm/ProvidedCHO")); + if(isset($doc->title)) { $newGraph->add($doc->doc, "http://purl.org/dc/elements/1.1/title", $doc->title); - if(isset($doc->lang)) { - $newGraph->add($doc->doc, "http://purl.org/dc/elements/1.1/language", $doc->lang); + } + if(isset($doc->lang)) { + $newGraph->add($doc->doc, "http://purl.org/dc/elements/1.1/language", $doc->lang); + } + if(isset($doc->issued)) { + $newGraph->add($doc->doc, "http://purl.org/dc/terms/issued", $doc->issued); + } + if(isset($doc->modified)) { + $newGraph->add($doc->doc, "http://purl.org/dc/terms/modified", $doc->modified); + } + if(isset($doc->publishers)) { + $newGraph->add($doc->doc, "http://purl.org/dc/elements/1.1/publisher", $doc->publishers); + } + if(isset($doc->extent)) { + $newGraph->add($doc->doc, "http://purl.org/dc/terms/extent", $doc->extent); + } + return $newGraph; + } + + private function queryDocs($queries) { + + $resDocs = []; + + foreach($queries as $query) { + $docs = $this->sparqlClient->query($query); + foreach($docs as $doc) { + $graph = $this->getResGraph($doc); + + $uri = $doc->uri->getUri(); + if(array_key_exists($uri, $resDocs)) { + $resDocs[$uri] = Utils::mergeGraphs($resDocs[$uri], $graph); + } else { + $resDocs[$uri] = $graph; + } + } - if(isset($doc->issued)) { - $newGraph->add($doc->doc, "http://purl.org/dc/terms/issued", $doc->issued); - } - if(isset($doc->modified)) { - $newGraph->add($doc->doc, "http://purl.org/dc/terms/modified", $doc->modified); - } - array_push($data, new DocumentResult($doc->uri->getUri(), $newGraph)); } - return $data; + return array_map(function($g) { return new DocumentResult($g->getUri(), $g); }, array_values($resDocs)); } public function all() { - - return $this->queryDocs( - "SELECT DISTINCT ?uri ?doc ?title ?issued ?modified ?lang". - " WHERE {". - " GRAPH ?uri { ?doc a .". - " ?doc ?title.". - " OPTIONAL {?doc ?lang.} ". - " OPTIONAL {?doc ?issued.} ". - " OPTIONAL {?doc ?modified.} }". - " } ORDER BY ?uri" - ); + return $this->queryDocs(self::ALL_QUERIES); } public function get($id, bool $short=false) { @@ -156,17 +207,7 @@ $offset = max(0,($page - 1) * $perPage); - $query = - "SELECT DISTINCT ?uri ?doc ?title ?issued ?modified ?lang". - " WHERE {". - " GRAPH ?uri { ?doc a .". - " ?doc ?title.". - " OPTIONAL {?doc ?lang.} ". - " OPTIONAL {?doc ?issued.} ". - " OPTIONAL {?doc ?modified.} }". - " } ORDER BY ?uri OFFSET $offset LIMIT $perPage"; - - $results = $this->queryDocs($query); + $results = $this->queryDocs(array_map(function($q) use ($offset, $perPage) { return $q . "\nOFFSET $offset LIMIT $perPage"; }, self::ALL_QUERIES)); return new LengthAwarePaginator($results, $total, $perPage, $page, [ 'path' => Paginator::resolveCurrentPath(), @@ -200,7 +241,4 @@ return $docList; } - - - } diff -r 64caee7ce38d -r 02e2396bcbbc server/src/tests/Libraries/UtilsTest.php --- a/server/src/tests/Libraries/UtilsTest.php Sat Aug 06 21:27:53 2016 +0700 +++ b/server/src/tests/Libraries/UtilsTest.php Sat Aug 06 21:29:33 2016 +0700 @@ -31,4 +31,10 @@ $this->assertNull($ms, "duration must be null"); } + public function testiso8601IntervalToMillisDoubleZero() { + $ms = Utils::iso8601IntervalToMillis("PT47M00S"); + $this->assertEquals(2820000, $ms, "duration must be 2820000"); + } + + }