Commit 9804b28b authored by Maxime Chaillet's avatar Maxime Chaillet Committed by Chaillet Maxime
Browse files

use karma to test the app. display the proposal and beamline in a table.

parent 459a58d1
RewriteEngine On RewriteEngine on
RewriteBase / RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
......
...@@ -7,26 +7,29 @@ ...@@ -7,26 +7,29 @@
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<!-- Using grunt-wiredep, the proper js files from bower components are included below -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/dustjs-linkedin/dist/dust-full.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/dustjs-helpers/dist/dust-helpers.min.js"></script>
<script src="bower_components/lodash/lodash.js"></script>
<script src="bower_components/moment/moment.js"></script>
<!-- endbower -->
<!-- Using grunt-include-source, the proper js files created by us (not minified) are included below --> <!-- Using grunt-include-source, the proper js files created by us (not minified) are included below -->
<script src="src/author.js"></script> <script src="src/author.js"></script>
<script src="src/beamlineurl.js"></script> <script src="src/beamlineurl.js"></script>
<script src="src/citation.js"></script> <script src="src/citation.js"></script>
<script src="src/constants.js"></script>
<script src="src/doicontroller.js"></script> <script src="src/doicontroller.js"></script>
<script src="src/doiData.js"></script> <script src="src/doiData.js"></script>
<script src="src/doiview.js"></script> <script src="src/doiview.js"></script>
<script src="src/event.js"></script> <script src="src/event.js"></script>
<script src="src/experimentalreportcontroller.js"></script> <script src="src/experimentalreportcontroller.js"></script>
<script src="src/jsonextractor.js"></script> <script src="src/jsonextractor.js"></script>
<script src="src/metadataTableHelper.js"></script>
<!-- Using grunt-wiredep, the proper js files from bower components are included below -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/dustjs-linkedin/dist/dust-full.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/dustjs-helpers/dist/dust-helpers.min.js"></script>
<script src="bower_components/lodash/lodash.js"></script>
<script src="bower_components/moment/moment.js"></script>
<!-- endbower -->
<!-- bower:css --> <!-- bower:css -->
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" /> <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
......
...@@ -7,12 +7,13 @@ ...@@ -7,12 +7,13 @@
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<!-- Using grunt-include-source, the proper js files created by us (not minified) are included below -->
<!-- include: "type": "js", "files": "src/*.js" -->
<!-- Using grunt-wiredep, the proper js files from bower components are included below --> <!-- Using grunt-wiredep, the proper js files from bower components are included below -->
<!-- bower:js --> <!-- bower:js -->
<!-- endbower --> <!-- endbower -->
<!-- Using grunt-include-source, the proper js files created by us (not minified) are included below -->
<!-- include: "type": "js", "files": "src/*.js" -->
<!-- bower:css --> <!-- bower:css -->
<!-- endbower --> <!-- endbower -->
......
...@@ -72,4 +72,4 @@ ...@@ -72,4 +72,4 @@
</div> </div>
</footer> </footer>
</body> </body>
</html> </html>
\ No newline at end of file
// Karma configuration
// Generated on Thu Oct 11 2018 23:09:22 GMT+0200 (CEST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'browserify'],
// list of files / patterns to load in the browser
files: [
'src/jsonextractor.js',
'src/constants.js',
'tests/jsonExtractor.test.js',
'bower_components/lodash/lodash.js'
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'tests/jsonExtractor.test.js': [ 'browserify' ]
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs',
1 verbose cli '/usr/bin/npm',
1 verbose cli 'install',
1 verbose cli 'grunt-insert',
1 verbose cli '--save' ]
2 info using npm@1.4.21
3 info using node@v0.10.29
4 warn package.json doi-landing-page@0.0.0 No description
5 warn package.json doi-landing-page@0.0.0 No README data
6 verbose readDependencies using package.json deps
7 verbose cache add [ 'grunt-insert', null ]
8 verbose cache add name=undefined spec="grunt-insert" args=["grunt-insert",null]
9 verbose parsed url { protocol: null,
9 verbose parsed url slashes: null,
9 verbose parsed url auth: null,
9 verbose parsed url host: null,
9 verbose parsed url port: null,
9 verbose parsed url hostname: null,
9 verbose parsed url hash: null,
9 verbose parsed url search: null,
9 verbose parsed url query: null,
9 verbose parsed url pathname: 'grunt-insert',
9 verbose parsed url path: 'grunt-insert',
9 verbose parsed url href: 'grunt-insert' }
10 silly lockFile 6a16fb4d-grunt-insert grunt-insert
11 verbose lock grunt-insert /users/demariaa/.npm/6a16fb4d-grunt-insert.lock
12 silly lockFile 6a16fb4d-grunt-insert grunt-insert
13 silly lockFile 6a16fb4d-grunt-insert grunt-insert
14 verbose addNamed [ 'grunt-insert', '' ]
15 verbose addNamed [ null, '*' ]
16 silly lockFile e2629ca7-grunt-insert grunt-insert@
17 verbose lock grunt-insert@ /users/demariaa/.npm/e2629ca7-grunt-insert.lock
18 silly addNameRange { name: 'grunt-insert', range: '*', hasData: false }
19 verbose request where is /grunt-insert
20 verbose request registry https://registry.npmjs.org/
21 verbose request id b08254c7f12aca69
22 verbose url raw /grunt-insert
23 verbose url resolving [ 'https://registry.npmjs.org/', './grunt-insert' ]
24 verbose url resolved https://registry.npmjs.org/grunt-insert
25 verbose request where is https://registry.npmjs.org/grunt-insert
26 info trying registry request attempt 1 at 15:07:13
27 verbose etag "52aa504a-1a9d"
28 http GET https://registry.npmjs.org/grunt-insert
29 http 304 https://registry.npmjs.org/grunt-insert
30 silly registry.get cb [ 304,
30 silly registry.get { date: 'Wed, 13 Dec 2017 14:07:14 GMT',
30 silly registry.get via: '1.1 varnish',
30 silly registry.get 'cache-control': 'max-age=300',
30 silly registry.get etag: '"52aa504a-1a9d"',
30 silly registry.get age: '35',
30 silly registry.get connection: 'keep-alive',
30 silly registry.get 'x-served-by': 'cache-cdg8721-CDG',
30 silly registry.get 'x-cache': 'HIT',
30 silly registry.get 'x-cache-hits': '1',
30 silly registry.get 'x-timer': 'S1513174034.009346,VS0,VE1',
30 silly registry.get vary: 'Accept-Encoding, Accept' } ]
31 verbose etag https://registry.npmjs.org/grunt-insert from cache
32 silly addNameRange number 2 { name: 'grunt-insert', range: '*', hasData: true }
33 silly addNameRange versions [ 'grunt-insert', [ '0.1.0' ] ]
34 verbose addNamed [ 'grunt-insert', '0.1.0' ]
35 verbose addNamed [ '0.1.0', '0.1.0' ]
36 silly lockFile 59aac559-grunt-insert-0-1-0 grunt-insert@0.1.0
37 verbose lock grunt-insert@0.1.0 /users/demariaa/.npm/59aac559-grunt-insert-0-1-0.lock
38 silly lockFile 59aac559-grunt-insert-0-1-0 grunt-insert@0.1.0
39 silly lockFile 59aac559-grunt-insert-0-1-0 grunt-insert@0.1.0
40 silly lockFile e2629ca7-grunt-insert grunt-insert@
41 silly lockFile e2629ca7-grunt-insert grunt-insert@
42 silly resolved [ { name: 'grunt-insert',
42 silly resolved description: 'Insert code from one file into another.',
42 silly resolved version: '0.1.0',
42 silly resolved homepage: 'https://github.com/grunt-insert',
42 silly resolved author:
42 silly resolved { name: 'Jamie Popkin',
42 silly resolved email: 'popkinj@littleearth.ca',
42 silly resolved url: 'http://littleearth.ca' },
42 silly resolved repository: { type: 'git', url: 'git://github.com/grunt-insert' },
42 silly resolved bugs: { url: 'https://github.com/grunt-insert/issues' },
42 silly resolved licenses: [ [Object] ],
42 silly resolved main: 'Gruntfile.js',
42 silly resolved engines: { node: '>= 0.8.0' },
42 silly resolved scripts: { test: 'grunt test' },
42 silly resolved devDependencies:
42 silly resolved { 'grunt-contrib-jshint': '~0.6.0',
42 silly resolved 'grunt-contrib-clean': '~0.4.0',
42 silly resolved 'grunt-contrib-nodeunit': '~0.2.0',
42 silly resolved grunt: '~0.4.1' },
42 silly resolved peerDependencies: { grunt: '~0.4.1' },
42 silly resolved keywords: [ 'gruntplugin', 'insert', 'build', 'merge', 'concatenate' ],
42 silly resolved readme: '# grunt-insert\n\n> Insert code from one file into another.\n\nUseful when you want to build a single file containing everything it needs for initial rendering. Such as on mobile, where the number of requests directly effects user experience.\nAt the moment it only overwrites the destination file. So be careful to consider that in the build process.\n\n## Getting Started\nThis plugin requires Grunt `~0.4.1`\n\nIf you haven\'t used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you\'re familiar with that process, you may install this plugin with this command:\n\n```shell\nnpm install grunt-insert --save-dev\n```\n\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks(\'grunt-insert\');\n```\n\n## The "insert" task\n\n### Overview\nIn your project\'s Gruntfile, add a section named `insert` to the data object passed into `grunt.initConfig()`.\n\n```js\ngrunt.initConfig({\n insert: {\n options: {\n // Task-specific options go here.\n },\n your_target: {\n // Target-specific file lists and/or options go here.\n },\n },\n});\n```\n\n### Options\n\n**This doesn\'t exist yet.**\n#### options.backup\nType: `Boolean`\nDefault value: false\n\nAll for a backup file to be written for each build. It stores the original file before any and all injections.\n\n### Usage Examples\n\n#### Default Options\nIn this example the javascript is contained in a separate file for development purposes. Then stuffed in the *script* tag of the html file.\n\n```js\ngrunt.initConfig({\n insert: {\n options: {},\n\t main: {\n\t\tsrc: "lib/js/stuff.js",\n\t\tdest: "dist/html/index.html",\n\t\tmatch: "//Stuff it here"\n\t},\n },\n});\n```\n\nThen in the destination file ,*index.html*, make sure you place the *match* string wherever you want source code to be placed. It could look something like this\n```html\n<!doctype html>\n<html>\n\t<head>\n\t\t<script>\n\t\t\t//Stuff it here\n\t\t</script>\n\t</head>\n\t<body>\n\t\tBlah blah.\n\t</body>\n</html>\n```\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\n\n## Release History\n_(Nothing yet)_\n',
42 silly resolved readmeFilename: 'README.md',
42 silly resolved _id: 'grunt-insert@0.1.0',
42 silly resolved dist:
42 silly resolved { shasum: '3b2d2b1728db73a3c173f27ae15c0e7034be3221',
42 silly resolved tarball: 'https://registry.npmjs.org/grunt-insert/-/grunt-insert-0.1.0.tgz' },
42 silly resolved _from: 'grunt-insert@',
42 silly resolved _npmVersion: '1.3.1',
42 silly resolved _npmUser: { name: 'popkinj', email: 'popkinj@littleearth.ca' },
42 silly resolved maintainers: [ [Object] ],
42 silly resolved directories: {},
42 silly resolved _shasum: '3b2d2b1728db73a3c173f27ae15c0e7034be3221',
42 silly resolved _resolved: 'https://registry.npmjs.org/grunt-insert/-/grunt-insert-0.1.0.tgz' } ]
43 info install grunt-insert@0.1.0 into /opt2/apache-tomcat-7.0.67/webapps/doi-landing-page
44 info installOne grunt-insert@0.1.0
45 verbose node_modules/grunt-insert unbuild
46 info preuninstall grunt-insert@0.1.0
47 info uninstall grunt-insert@0.1.0
48 verbose true,/opt2/apache-tomcat-7.0.67/webapps/doi-landing-page/node_modules,/opt2/apache-tomcat-7.0.67/webapps/doi-landing-page/node_modules unbuild grunt-insert@0.1.0
49 info postuninstall grunt-insert@0.1.0
50 verbose tar unpack /users/demariaa/.npm/grunt-insert/0.1.0/package.tgz
51 silly lockFile 5e01aa29-g-page-node-modules-grunt-insert tar:///opt2/apache-tomcat-7.0.67/webapps/doi-landing-page/node_modules/grunt-insert
52 verbose lock tar:///opt2/apache-tomcat-7.0.67/webapps/doi-landing-page/node_modules/grunt-insert /users/demariaa/.npm/5e01aa29-g-page-node-modules-grunt-insert.lock
53 silly lockFile ae01df02-m-grunt-insert-0-1-0-package-tgz tar:///users/demariaa/.npm/grunt-insert/0.1.0/package.tgz
54 verbose lock tar:///users/demariaa/.npm/grunt-insert/0.1.0/package.tgz /users/demariaa/.npm/ae01df02-m-grunt-insert-0-1-0-package-tgz.lock
55 silly gunzTarPerm modes [ '755', '644' ]
56 silly gunzTarPerm extractEntry package.json
57 silly gunzTarPerm extractEntry .npmignore
58 silly gunzTarPerm extractEntry README.md
59 silly gunzTarPerm extractEntry Gruntfile.js
60 silly gunzTarPerm extractEntry .jshintrc
61 silly gunzTarPerm extractEntry LICENSE-MIT
62 silly gunzTarPerm extractEntry tasks/insert.js
63 silly gunzTarPerm extractEntry test/injector_test.js
64 silly gunzTarPerm extractEntry test/expected/custom_options
65 silly gunzTarPerm extractEntry test/expected/default_options
66 silly gunzTarPerm extractEntry test/fixtures/123
67 silly gunzTarPerm extractEntry test/fixtures/testing
68 silly lockFile 5e01aa29-g-page-node-modules-grunt-insert tar:///opt2/apache-tomcat-7.0.67/webapps/doi-landing-page/node_modules/grunt-insert
69 silly lockFile 5e01aa29-g-page-node-modules-grunt-insert tar:///opt2/apache-tomcat-7.0.67/webapps/doi-landing-page/node_modules/grunt-insert
70 silly lockFile ae01df02-m-grunt-insert-0-1-0-package-tgz tar:///users/demariaa/.npm/grunt-insert/0.1.0/package.tgz
71 silly lockFile ae01df02-m-grunt-insert-0-1-0-package-tgz tar:///users/demariaa/.npm/grunt-insert/0.1.0/package.tgz
72 info preinstall grunt-insert@0.1.0
73 verbose readDependencies using package.json deps
74 verbose readDependencies using package.json deps
75 silly resolved []
76 verbose about to build /opt2/apache-tomcat-7.0.67/webapps/doi-landing-page/node_modules/grunt-insert
77 info build /opt2/apache-tomcat-7.0.67/webapps/doi-landing-page/node_modules/grunt-insert
78 verbose linkStuff [ false,
78 verbose linkStuff false,
78 verbose linkStuff false,
78 verbose linkStuff '/opt2/apache-tomcat-7.0.67/webapps/doi-landing-page/node_modules' ]
79 info linkStuff grunt-insert@0.1.0
80 verbose linkBins grunt-insert@0.1.0
81 verbose linkMans grunt-insert@0.1.0
82 verbose rebuildBundles grunt-insert@0.1.0
83 info install grunt-insert@0.1.0
84 info postinstall grunt-insert@0.1.0
85 verbose readDependencies using package.json deps
86 verbose already installed skipping grunt@~0.4.1 /opt2/apache-tomcat-7.0.67/webapps/doi-landing-page
87 silly resolved []
88 error peerinvalid The package grunt does not satisfy its siblings' peerDependencies requirements!
88 error peerinvalid Peer grunt-contrib-jshint@1.1.0 wants grunt@>=0.4.0
88 error peerinvalid Peer grunt-dustjs@1.4.0 wants grunt@>=0.4.0
88 error peerinvalid Peer grunt-wiredep@3.0.1 wants grunt@>=0.4.0
88 error peerinvalid Peer grunt-insert@0.1.0 wants grunt@~0.4.1
89 error System Linux 4.8.0-0.bpo.2-amd64
90 error command "/usr/bin/nodejs" "/usr/bin/npm" "install" "grunt-insert" "--save"
91 error cwd /opt2/apache-tomcat-7.0.67/webapps/doi-landing-page
92 error node -v v0.10.29
93 error npm -v 1.4.21
94 error code EPEERINVALID
95 verbose exit [ 1, true ]
{ {
"name": "doi-landing-page", "name": "doi-landing-page",
"jest": { "version": "0.0.0",
"rootDir": "tests" "description": "",
}, "main": "Gruntfile.js",
"version": "0.0.0", "dependencies": {
"description": "", "grunt": "^1.0.1",
"main": "Gruntfile.js", "grunt-contrib-jshint": "^1.1.0",
"dependencies": { "grunt-contrib-uglify": "^3.2.1",
"grunt": "^1.0.1", "grunt-contrib-watch": "^1.0.0",
"grunt-contrib-jshint": "^1.1.0", "grunt-dust": "^0.9.4",
"grunt-contrib-uglify": "^3.2.1", "grunt-dustjs": "^1.4.0",
"grunt-contrib-watch": "^1.0.0", "grunt-wiredep": "^3.0.1"
"grunt-dust": "^0.9.4", },
"grunt-dustjs": "^1.4.0", "devDependencies": {
"grunt-wiredep": "^3.0.1" "browserify": "^16.2.3",
}, "grunt": "^1.0.1",
"devDependencies": { "grunt-contrib-cssmin": "^2.2.1",
"grunt": "^1.0.1", "grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-cssmin": "^2.2.1", "grunt-include-source": "^1.1.0",
"grunt-contrib-jshint": "^1.1.0", "grunt-plato": "^1.4.0",
"grunt-include-source": "^1.1.0", "jasmine-core": "^3.2.1",
"grunt-plato": "^1.4.0", "karma": "^3.0.0",
"jest": "^23.6.0" "karma-browserify": "^5.3.0",
}, "karma-chrome-launcher": "^2.2.0",
"scripts": { "karma-firefox-launcher": "^1.1.0",
"test": "jest --watchAll" "karma-jasmine": "^1.1.2",
}, "watchify": "^3.11.0"
"repository": { },
"type": "git", "scripts": {
"url": "git@gitlab.esrf.fr:icat/doi-landing-page.git" "test": "./node_modules/jest/bin/jest.js"
}, },
"author": "", "repository": {
"license": "ISC" "type": "git",
} "url": "git@gitlab.esrf.fr:icat/doi-landing-page.git"
\ No newline at end of file },
"author": "",
"license": "ISC"
}
var CONSTANTS = {
ES_RESOURCE_TYPE : "experimental session resource type",
DC_RESOURCE_TYPE : "dataset collection resource type"
};
//module.exports = CONSTANTS;
...@@ -3,6 +3,7 @@ function DoiData() { ...@@ -3,6 +3,7 @@ function DoiData() {
} }
/** /**
* Get the accessibility status * Get the accessibility status
* @param {string} resourceType the resource type for this DOI
* @param {string} sessionDate The timeStamp the experiment was started * @param {string} sessionDate The timeStamp the experiment was started
* @param {string} publiclyAccessibleYear The year the data will be publicly accesssible. * @param {string} publiclyAccessibleYear The year the data will be publicly accesssible.
* @return {string} * @return {string}
...@@ -10,19 +11,24 @@ function DoiData() { ...@@ -10,19 +11,24 @@ function DoiData() {
* "Restricted access" : the data is still under embargo. Only accessible to experimental team members * "Restricted access" : the data is still under embargo. Only accessible to experimental team members
* *
* */ * */
DoiData.prototype.getAccessibilityStatus = function( sessionDate, publiclyAccessibleYear ) { DoiData.prototype.getAccessibilityStatus = function (resourceType, sessionDate, publiclyAccessibleYear) {
if (resourceType) {
if (resourceType === CONSTANTS.ES_RESOURCE_TYPE) {
if (publiclyAccessibleYear && sessionDate) {
var publiclyAvailableDate = moment(publiclyAccessibleYear, "YYYY");
var now = moment();
if ( publiclyAccessibleYear && sessionDate ) { if (now > publiclyAvailableDate) {
var publiclyAvailableDate = moment( publiclyAccessibleYear, "YYYY" ); return "Open access";
var now = moment(); } else if (now <= publiclyAvailableDate) {
return "Restricted access";
if ( now > publiclyAvailableDate ) { }
}
} else if (resourceType === CONSTANTS.DC_RESOURCE_TYPE){
return "Open access"; return "Open access";
} else if ( now <= publiclyAvailableDate ) {
return "Restricted access";
} }
} }
console.log( "Failed to determine whether the accessibility of the DOI." ); console.log("Failed to determine whether the accessibility of the DOI.");
return "Accessibility status could not be determined"; return "Accessibility status could not be determined";
}; };
function DOIController(view) { function DOIController(view) {
var _this = this; var _this = this;
// doiServer = the server which provides doi details from a given doi name. // doiServer = the server which provides doi details from a given doi name.
//this.doiServer = "https://data.datacite.org/"; //this.doiServer = "https://data.datacite.org/";
this.doiServer = "https://api.test.datacite.org/" this.doiServer = "https://api.test.datacite.org/";
// 10.5072 is the test esrf doi prefix; // 10.5072 is the test esrf doi prefix;
// 10.15151 is the production esrf doi prefix; // 10.15151 is the production esrf doi prefix;
this.acceptedPrefix = [ "10.5072", "10.15151" ]; this.acceptedPrefix = ["10.5072", "10.15151"];
this.view = view; this.view = view;
this.experimentalReportController = new ExperimentalReportController(); this.experimentalReportController = new ExperimentalReportController();
this.experimentalReportController.onSuccess.attach(function(sender, data) { this.experimentalReportController.onSuccess.attach(function (sender, data) {
_this.view.renderExperimentalReportData(data); _this.view.renderExperimentalReportData(data);
}); });
this.experimentalReportController.onError.attach(function(sender, data) { this.experimentalReportController.onError.attach(function (sender, data) {
console.log("Error when retrieving fileList from SMIS."); console.log("Error when retrieving fileList from SMIS.");
_this.view.renderErrorForExperimentalReport(); _this.view.renderErrorForExperimentalReport();
}); });
} }
...@@ -28,91 +28,94 @@ function DOIController(view) { ...@@ -28,91 +28,94 @@ function DOIController(view) {
* fields when the doi does not exist. In this case the following code is * fields when the doi does not exist. In this case the following code is
* executed. Reloading the page is treated by .fail as it should be. * executed. Reloading the page is treated by .fail as it should be.
*/ */
DOIController.prototype.isValidDOIData = function(doiData) { DOIController.prototype.isValidDOIData = function (doiData) {
if (_.keysIn(doiData).length > 3) { if (_.keysIn(doiData).length > 3) {
return _.find(_.keysIn(doiData), function(value) { return _.find(_.keysIn(doiData), function (value) {
return value === "title"; return value === "title";
}).length > 0; }).length > 0;
} }
return false; return false;
}; };
DOIController.prototype.getData = function(doi) { DOIController.prototype.getData = function (doi) {
var _this = this; var _this = this;
this.view.setDOIInTopBanner(doi); this.view.setDOIInTopBanner(doi);
if (this.hasAcceptedPrefix(doi)) { if (this.hasAcceptedPrefix(doi)) {
$.ajax({ $.ajax({
headers : { headers: {
Accept : "application/vnd.datacite.datacite+json" Accept: "application/vnd.datacite.datacite+json"
}, },
type : "GET", type: "GET",
timeout : 15000, // triggers timeout when request pends longer than timeout: 15000, // triggers timeout when request pends longer than
// 5000ms // 5000ms
url : this.doiServer + doi, url: this.doiServer + doi,
beforeSend : function(xhr) { beforeSend: function (xhr) {
_this.view.setLoading("Retrieving data from Server"); _this.view.setLoading("Retrieving data from Server");
xhr.setRequestHeader ("Authorization", "Basic " + btoa("DATACITE.ESRF" + ":" + "datacyte1")); // to be removed as well as the parameter xhr.setRequestHeader("Authorization", "Basic " + btoa("DATACITE.ESRF" + ":" + "datacyte1")); // to be removed as well as the parameter
}, },
complete : function() { complete: function () {
_this.view.setLoading(false); _this.view.setLoading(false);
} }
}) })
.done(function(data) { .done(function (data) {
if (data) { if (data) {
// Test abnormal length of the json object // Test abnormal length of the json object
if (!_this.isValidDOIData(data)) { if (!_this.isValidDOIData(data)) {
_this.view.renderError("Not Found", _this.origin); _this.view.renderError("Not Found", _this.origin);
} else { } else {
var doiData = new DoiData(); var doiData = new DoiData();
doiData.title = data.title; doiData.title = data.title;
doiData.doi = data.doi.toUpperCase(); doiData.doi = data.doi.toUpperCase();
doiData.dataciteLink = _this.doiServer + doi; doiData.dataciteLink = _this.doiServer + doi;
doiData.publisher = data.publisher; doiData.publisher = data.publisher;
doiData.creator = data.creator; doiData.creator = data.creator;
var jsonExtractor = new JsonExtractor(); var jsonExtractor = new JsonExtractor();
doiData.mintingYear = jsonExtractor.getMintingYear(data); doiData.mintingYear = jsonExtractor.getMintingYear(data);
doiData.sessionDate = jsonExtractor.getSessionDate(data); doiData.sessionDate = jsonExtractor.getSessionDate(data);
doiData.publiclyAccessibleYear = data.publication_year; doiData.publiclyAccessibleYear = data.publication_year;
doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description"); doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subject, "Proposal Type Description");
doiData.proposalNumber = jsonExtractor.getFieldFromSubject(data.subject, "Proposal"); doiData.proposalName = jsonExtractor.getFieldFromSubject(data.subject, "Proposal");
_this.experimentalReportController.requestFilenameList(doiData.proposalNumber); _this.experimentalReportController.requestFilenameList(doiData.proposalName);
doiData.beamline = jsonExtractor.getFieldFromSubject(data.subject, "instrument"); doiData.beamline = jsonExtractor.getFieldFromSubject(data.