Commit 2d9fa8a3 authored by Iker Hurtado's avatar Iker Hurtado
Browse files

Open source code release (step 2)

parent 4e99910c
Pipeline #30115 passed with stages
in 6 seconds
This diff is collapsed.
const Conf = {};
Conf.GuestUserToken =
'eyJhbGciOiJIUzI1NiIsImlhdCI6MTUyMzg4MDE1OSwiZXhwIjoxNjgxNTYwMTU5fQ.ey'+
'JpZCI6ImVuY2d1aSJ9.MsMWQa3IklH7cQTxRaIRSF9q8D_2LD5Fs2-irpWPTp4';
// EXPORTS
module.exports = Conf;
let util = require('./util.js');
class FilterComponent {
constructor(className) {
this.element = document.createElement('div');
this.element.className = className;
this.filtersOn = [];
this.folded = true;
this.element.innerHTML+=`
<div style="float: left; width: 97%;" >
<div class="filter-c-folded" >
<span style="vertical-align: top;">Filtering</span>
</div>
<div class="filter-c-unfolded" style="display: none">
</div>
</div>
<div class="filter-c-btn" style="float: right; width: 3%;">
<img src="${util.IMAGE_DIR}folded.png" />
<!--<button class="on">filter</button> -->
</div>
<div style="clear: both;"></div>
`;
this.foldedPanel = this.element.querySelector('.filter-c-folded');
this.unfoldedPanel = this.element.querySelector('.filter-c-unfolded');
this.foldBtn = this.element.querySelector('img');
this.foldBtn.addEventListener('click', e => {
this.folded = !this.folded;
this.foldBtn.src = (this.folded ? util.IMAGE_DIR+'folded.png' :
util.IMAGE_DIR+'unfolded.png');
//this.foldBtn.className = (this.folded ? 'on' : 'off');
this.foldedPanel.style.display = (this.folded ? 'block' : 'none');
this.unfoldedPanel.style.display = (this.folded ? 'none' : 'block');
});
}
addItems(items){
let html = '';
items.forEach( item => {
this.filtersOn.push(item);
html += '<input type="checkbox" value="'+item+'" checked>'+item+' &nbsp;&nbsp; ';
});
this.unfoldedPanel.innerHTML += html;
this.element.addEventListener('click', (e) => {
if (e.target.tagName === 'INPUT'){
let index = this.filtersOn.indexOf(e.target.value);
if (index >= 0) this.filtersOn.splice( index, 1 );
else this.filtersOn.push(e.target.value);
this.itemListener(this.filtersOn);
}
});
}
addItemsMap(itemsMap){
let html = '';
itemsMap.forEach( (itemId, itemName) => {
this.filtersOn.push(itemId);
html += '<input type="checkbox" value="'+itemId+'" checked>'+
'<span style="vertical-align: 20%">'+itemName+'</span> &nbsp;&nbsp; ';
});
this.unfoldedPanel.innerHTML += html;
this.element.addEventListener('click', (e) => {
if (e.target.tagName === 'INPUT'){
let index = this.filtersOn.indexOf(e.target.value);
if (index >= 0) this.filtersOn.splice( index, 1 );
else this.filtersOn.push(e.target.value);
this.itemListener(this.filtersOn);
}
});
}
setItemListener(listener){
this.itemListener = listener;
}
}
// EXPORTS
module.exports = FilterComponent;
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
This component is the popup window (and the darkened background) with a form
inside used for users to report (flagging) errors on the calculations
*/
"use strict";
let util = require('./util.js');
let DataStore = require('../material-mod/DataStore.js');
// main DOM elements
let flaggingPopupBackground = document.querySelector('#flagging-form-popup-bg');
let flaggingFormPopup = document.querySelector('#flagging-form-popup');
flaggingFormPopup.innerHTML =`
<div> <img src="img/cross.svg" height="12px"
style="float: right; cursor: pointer" />
</div>
......@@ -40,7 +63,7 @@ flaggingFormPopup.innerHTML =`
</div>
`;
// Form elements
let categoryField = flaggingFormPopup.querySelector('#flagging-category');
let eStructOption = categoryField.querySelector('option[value="electronicstruct"]');
let thermalOption = categoryField.querySelector('option[value="thermalprops"]');
......@@ -54,7 +77,6 @@ let overviewEStructCalcs = null;
function _setCurrentPage(pageId){
//if (view === util.MAT_VIEW.structure){
subcategoryField.innerHTML = '';
......@@ -102,8 +124,7 @@ function _setCurrentPage(pageId){
}
}
}
} // function _setCurrentPage
function show(pageStatus){
......@@ -125,8 +146,6 @@ function show(pageStatus){
flaggingFormPopup.style.visibility = 'visible';
flaggingPopupBackground.style.visibility = 'visible';
//console.log('flaggingFormPopup: ',ttRect, windowHeight, topPos);
//console.log('FFF Hash: ',pageId, document.location.hash);
}
......@@ -140,6 +159,7 @@ function hide(){
validationMsg.innerHTML = '';
}
function createOption(text, value){
let opt = document.createElement('option');
opt.value = (value === undefined ? text : value);
......@@ -197,8 +217,6 @@ sendButton.addEventListener('click', e => {
descriptionText += '\\n\\n**User text:** '+textareaText;
//titleText = 'FAKE ISSUE! @ : TESTING GUI user flagging';
//descriptionText = 'Text ';
let queryJson =`{
"title": "${titleText}",
"description": "${descriptionText}"}`;
......@@ -210,7 +228,6 @@ sendButton.addEventListener('click', e => {
if (e.target.status === 200) hide();
});
}
});
......
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
This file implements an information system for the user that provides info
related to the concepts or quantities shown on the UI
The literals are read form the file infosys.json
*/
"use strict";
let util = require('./util.js');
let SwitchComponent = require('./SwitchComponent.js');
const INFOSYS_FILE_PATH = 'infosys.json';
let tooltip= document.querySelector('#info-tooltip');
let tooltipContent= document.querySelector('#tooltip-content');
let tooltip = document.querySelector('#info-tooltip');
let tooltipContent = document.querySelector('#tooltip-content');
let elements = [];
let timerSet = null;
let on = false;
......@@ -59,6 +85,7 @@ function addToInfoSystem(baseElement){
enableTooltip(infosysLabels[i]);
}
function addElementToInfoSystem(element, value){
elements.push(element);
element.setAttribute('info-sys-data',value);
......
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
This component is the loading popup window
*/
"use strict";
let util = require('./util.js');
let loadingPopup= document.querySelector('#loading-popup');
let loadingPopup = document.querySelector('#loading-popup');
function show(){
let ttRect = loadingPopup.getBoundingClientRect();
......
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
This file implements the design pattern pub/sub, which allows one module
to broadcast messages to other modules.
*/
"use strict";
var messages = new Map(); // = {};
var messages = new Map();
var lastUid = -1;
/**
* subscribe( message, func ) -> String
* - message (String): The message to subscribe to
* - func (Function): The function to call when a new message is published
* Subscribes the passed function to the passed message. Every returned token is unique and should be stored if
* you need to unsubscribe
* Subscribes the passed function to the passed message. Every returned token
* is unique and should be stored if you need to unsubscribe
**/
function subscribe( message, func ){
//console.log('SUBSCRIBING Message '+message);
......
"use strict";
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
let routes = new Map();
/*
This file implements the app Routing system: the feature that allows
the page navigation in a single-page environment.
*/
function print(){
console.log('Router data: ');
routes.forEach(function(func, url) {
console.log(url + ': ' + func);
});
}
"use strict";
let routes = new Map();
function add(route, func){
......@@ -35,7 +51,7 @@ function route(){
}
else command= hashPath;
console.log("hashPath: " + hashPath+' command: '+command+' param: '+param+' subparam: '+subparam);
//console.log("hashPath: " + hashPath+' command: '+command+' param: '+param+' subparam: '+subparam);
if (routes.has(command)) {
routes.get(command)(param, subparam);
......@@ -43,5 +59,13 @@ function route(){
};
function print(){
console.log('Router data: ');
routes.forEach(function(func, url) {
console.log(url + ': ' + func);
});
}
// EXPORTS
module.exports = { add: add, route: route };
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
SVG drawing util library
*/
"use strict";
const xmlns="http://www.w3.org/2000/svg";
......
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
This component implements a generic switch/toggle button
*/
let util = require('./util.js');
class SwitchComponent {
......
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
This file implements the user guidance system. This complex system for
showing tips to the user is specified in the project documentation
*/
"use strict";
//let util = require('util.js');
......@@ -21,6 +46,7 @@ function createUserMsg(i, width){
return element;
}
function showTip(tipNumber){
if (tipNumber === 8 && !searchBarShowing) return; // Do nothing
if (tipNumber === 4 && !searchBarShowing) return; // Do nothing
......@@ -113,7 +139,7 @@ function closeIndependentTip( tipNumber){
function closeAndShowNext(e){
e.preventDefault();
console.log("closeAndShowNext",currentTip);
//console.log("closeAndShowNext",currentTip);
e.target.style.display = 'none';
switch (currentTip) {
......@@ -155,7 +181,7 @@ function show(value, tip3, tip7){ // Global show - the UserGuidance is shown or
function updateCurrentTip(value){
currentTip = value;
localStorage.setItem('currentTip', value);
console.log('localStorage.currentTip:',localStorage.getItem('currentTip'));
//console.log('localStorage.currentTip:',localStorage.getItem('currentTip'));
}
......
/**
* Copyright 2016-2018 Iker Hurtado
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
This is an app-level utility JavaScript file. It holds:
- Environments conf (API URL and user cookie domain configuration)
* Maybe this conf info can be removed from here to a better place
- global state variables and app-level constants
- miscellaneous app-level function
- local vars
- app-level util functions
* Maybe this file should be rethought
*/
"use strict";
let DataStore = require('../material-mod/DataStore.js');
//let LoadingPopup = require('./LoadingPopup.js');
let Conf = require('../Conf.js');
// global state vars
let materialId = null;
let searchResults = false;
const IMAGE_DIR= 'img/';
// app-level constants
const IMAGE_DIR = 'img/';
const AUTH_REQUEST_HEADER_GUEST_USER = 'Basic '+ btoa(Conf.GuestUserToken+':');
const MAT_VIEW = {
'structure' : 'structure',
'electronicstruct': 'electronicstruct',
'methodology': 'methodology',
'thermalprops': 'thermalprops',
'elasticconst': 'elasticconst'
};
let ELEMENTS = [
'H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', // Si = 14
'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', // Nin = 28
'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', // Nb = 41
'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Xe', // Xe = 54
'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', // Ho= 67
'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', // Hg = 80
'Tl', 'Pb', 'Bi', 'Po', 'At', 'Rn', 'Fr', 'Ra', 'Ac', 'Th', 'Pa', 'U', 'Np', // Np = 93
'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm', 'Md', 'No', 'Lr', 'Rf', 'Ha', 'Sg', // sg = 106
'Ns', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og' // Mt = 109
];
// API URL and user cookie domain configuration
......@@ -19,7 +78,7 @@ let path = 'v1.0/';
// Case 2: production environment
if (document.location.href.indexOf('nomad-coe.eu') > 0){//
API_HOST='https://encyclopedia.nomad-coe.eu/';// old host -> API_HOST= 'https://encyclopedia-api.nomad-coe.eu/'; //***
API_HOST='https://encyclopedia.nomad-coe.eu/';
USER_COOKIE_DOMAIN = '.nomad-coe.eu';
path = 'api/v1.0/';
}
......@@ -30,53 +89,32 @@ else if (document.location.href.indexOf('gui') > 0){
USER_COOKIE_DOMAIN = '.mpg.de';
}
let API_BASE_URL = API_HOST + path;// for the old host -> API_HOST+'v1.0/';
console.log('API host: ',API_HOST,' USER_COOKIE_DOMAIN: ',USER_COOKIE_DOMAIN);
let API_BASE_URL = API_HOST + path;
//console.log('API host: ',API_HOST,' USER_COOKIE_DOMAIN: ',USER_COOKIE_DOMAIN);
document.querySelector('#guest-user a').href = API_BASE_URL+'saml/?sso2';
const AUTH_REQUEST_HEADER_GUEST_USER = 'Basic '+
btoa('eyJhbGciOiJIUzI1NiIsImlhdCI6MTUyMzg4MDE1OSwiZXhwIjoxNjgxNTYwMTU5fQ.ey'+
'JpZCI6ImVuY2d1aSJ9.MsMWQa3IklH7cQTxRaIRSF9q8D_2LD5Fs2-irpWPTp4:');
// Mockup URLs
//const FERMI_SURFACE_URL= HOST+'files/fermi/'+
//'fed3fa9fbc68aa6c5e51845396889666ca37bb2e626e1da53.x3d';
const BAND_STRUCT_EXAMPLE_URL= API_BASE_URL+'materials/108541/calculations/290737';
const MAT_VIEW = {
'structure' : 'structure',
'electronicstruct': 'electronicstruct',
'methodology': 'methodology',
'thermalprops': 'thermalprops',
'elasticconst': 'elasticconst'
};
let ELEMENTS = [
<