Commit 4e99910c authored by Iker Hurtado's avatar Iker Hurtado
Browse files

Open source code release (step 1)

parent 5ff0784d
Pipeline #30039 passed with stages
in 7 seconds
......@@ -45,8 +45,33 @@
/***/ function(module, exports, __webpack_require__) {
/**
* 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 is the application entry point.
It defines some app level components (Breadcrumb) and
initializes several more (app level events, app routing, authentication)
*/
"use strict";
// main.js
let util = __webpack_require__(1);
let LoadingPopup = __webpack_require__(3);
let FlaggingFormPopup = __webpack_require__(4);
......@@ -57,15 +82,19 @@
let UserGuidance = __webpack_require__(32);
let DataStore = __webpack_require__(2);
let contentElement= document.getElementById("content");
let titleElement= document.querySelector('title');
// main DOM elements
let contentElement = document.getElementById('content');
let titleElement = document.querySelector('title');
/********* User flagging side tab ****************/
/* This side vertical tab is hidden initially
but it has to be set up when the app starts */
let flaggingTab = document.getElementById('calc-flagging-tab');
//let top = (window.innerHeight - flaggingTab.getBoundingClientRect().height)/2;
flaggingTab.style.top = (window.innerHeight/2)+'px';
flaggingTab.addEventListener('click',e => {
......@@ -74,8 +103,7 @@
/**************************/
/*********** App Breadcrumb component definition ***************/
class Breadcrumb {
......@@ -121,7 +149,6 @@
let self = this;
function adjustDropdownOptions() {
//console.log('FAOCUS');
let esOption = self.detailsDropDown.querySelector('option[value="electronicstruct"]');
if (!DataStore.hasElecStructureData) self.detailsDropDown.removeChild(esOption);
......@@ -144,7 +171,7 @@
if (appModule === 'search'){
this.overviewSel.style.display = 'none';
this.detailsSel.style.display = 'none';
//this.resultsSel.style.display = 'inline';
if (param === 'results'){
this.resultsSel.style.display = 'inline';
this.resultsSel.querySelector('span').style.fontWeight = 'bold';
......@@ -169,7 +196,10 @@
} // class Breadcrumb
/*****************************/
/***************************
App setup
***************************/
let breadcrumb = new Breadcrumb();
......@@ -186,7 +216,7 @@
}
/****** App level events *************/
/****** App level events setup ********/
PubSub.subscribe('show-material', data => {
console.log('Handling event show-material: '+data.id+' view: '+data.view);
......@@ -251,7 +281,6 @@
let userNameElement = document.querySelector('#user-name');
let logoutButton = document.querySelector('#logout-button');
function setAppAuthenticated(data){
if (data.status === 'Authenticated'){
userNameElement.innerHTML = data.user.username;
......@@ -273,60 +302,6 @@
flaggingTab.style.visibility = 'hidden';
}
//************* NORMAL WAY
/*
// When the app loads, it checks if the user is authenticated
let oReq = util.authServerReq('saml/user/', e => {
console.log('Response ',oReq.responseText);
let jsonData;
try {
jsonData = JSON.parse(oReq.responseText); //JSON.parse(response); //
console.log('Response jsonData out ',jsonData);
} catch(e) { console.log('../saml/user/ json response bad format', e); }
*/
/* Trick in order to test this feature in my local dev environment
let ddd= `{"status": "Authenticated",
"token": {
"data": "eyJhbGciOiJIUzI1NiIsImlhdCI6MTQ5MjA3MDI5MCwiZXhwIjoxNTIzNjI3ODkwfQ.eyJpZCI6ImVuY2d1aSJ9.oXYwGrLHRxdvKRal1NaAJJ5tCVTDupB5SjAGTtJVDKU",
"expires_in": 86400
},
"user": {
"email": "fakeuser@gmail.com",
"username": "fakeuser"
}
}`;
jsonData = JSON.parse(ddd);
*/
/*
setAppAuthenticated(jsonData);
});
// Logout
logoutButton.addEventListener( "click", e => {
util.authServerReq('saml/logout/', e => {});
//console.log('Logging out ',userNameElement.innerHTML);
userNameElement.innerHTML = '';
document.querySelector('#guest-user').style.display = 'inline';
document.querySelector('#auth-user').style.display = 'none';
util.setAuthRequestHeader();
if (flaggingTab.style.visibility !== 'hidden')
flaggingTab.style.visibility = 'hidden';
});
*/
//*********** COOKIES WAY
function getCookie(name) {
let value = "; " + document.cookie;
......@@ -341,68 +316,25 @@
let userInfoCookie = getCookie('user_info');
console.log('Cookies: ', document.cookie, userInfoCookie);
//console.log('Cookies: ', document.cookie, userInfoCookie);
if (userInfoCookie !== undefined){
let userInfoData = JSON.parse(parseCookie(userInfoCookie));
console.log('userInfoData: ', userInfoData);
//console.log('userInfoData: ', userInfoData);
setAppAuthenticated(userInfoData);
}
/*
let ddd= `{"status": "Authenticated",
"token": {
"data": "eyJhbGciOiJIUzI1NiIsImlhdCI6MTQ5MjA3MDI5MCwiZXhwIjoxNTIzNjI3ODkwfQ.eyJpZCI6ImVuY2d1aSJ9.oXYwGrLHRxdvKRal1NaAJJ5tCVTDupB5SjAGTtJVDKU",
"expires_in": 86400
},
"user": {
"email": "fakeuser@gmail.com",
"username": "fakeuser"
}
}`;
let jsonData = JSON.parse(ddd);
setAppAuthenticated(userInfoData);
*/
// Logout
logoutButton.addEventListener( "click", e => {
document.cookie='user_info=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain='+
util.USER_COOKIE_DOMAIN+'; path=/';
console.log('Logging out document.cookie ',document.cookie);
//console.log('Logging out document.cookie ',document.cookie);
setAppLoggedOut();
//console.log('Logging out ',userNameElement.innerHTML);
});
/*** Popup code
let loginButton = document.querySelector('#login-button');
let params = `width=400,height=600,left=600,top=100`;
loginButton.addEventListener( "click", e => {
let loginWindow;
// I think it's a blocking call
loginWindow = window.open('http://enc-testing-nomad.esc.rzg.mpg.de/v1.0/saml/', 'Login', params);
console.log("loginWindow", loginWindow);
loginWindow.addEventListener("focus", function(event) {
console.log("focus", loginWindow, loginWindow.document);
});
loginWindow.addEventListener("unload", function(event) {
console.log("unload", loginWindow, loginWindow.document.firstChild);
//loginWindow.close();
});
//location.reload(true);
});
*/
/***/ },
......
/**
* 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 is the application entry point.
It defines some app level components (Breadcrumb) and
initializes several more (app level events, app routing, authentication)
*/
"use strict";
// main.js
let util = require('./common/util.js');
let LoadingPopup = require('./common/LoadingPopup.js');
let FlaggingFormPopup = require('./common/FlaggingFormPopup.js');
......@@ -11,15 +36,19 @@ let SearchModule = require('./search-mod/SearchMod.js');
let UserGuidance = require('./common/UserGuidance.js');
let DataStore = require('./material-mod/DataStore.js');
let contentElement= document.getElementById("content");
let titleElement= document.querySelector('title');
// main DOM elements
let contentElement = document.getElementById('content');
let titleElement = document.querySelector('title');
/********* User flagging side tab ****************/
/* This side vertical tab is hidden initially
but it has to be set up when the app starts */
let flaggingTab = document.getElementById('calc-flagging-tab');
//let top = (window.innerHeight - flaggingTab.getBoundingClientRect().height)/2;
flaggingTab.style.top = (window.innerHeight/2)+'px';
flaggingTab.addEventListener('click',e => {
......@@ -28,8 +57,7 @@ flaggingTab.addEventListener('click',e => {
/**************************/
/*********** App Breadcrumb component definition ***************/
class Breadcrumb {
......@@ -75,7 +103,6 @@ class Breadcrumb {
let self = this;
function adjustDropdownOptions() {
//console.log('FAOCUS');
let esOption = self.detailsDropDown.querySelector('option[value="electronicstruct"]');
if (!DataStore.hasElecStructureData) self.detailsDropDown.removeChild(esOption);
......@@ -98,7 +125,7 @@ class Breadcrumb {
if (appModule === 'search'){
this.overviewSel.style.display = 'none';
this.detailsSel.style.display = 'none';
//this.resultsSel.style.display = 'inline';
if (param === 'results'){
this.resultsSel.style.display = 'inline';
this.resultsSel.querySelector('span').style.fontWeight = 'bold';
......@@ -123,7 +150,10 @@ class Breadcrumb {
} // class Breadcrumb
/*****************************/
/***************************
App setup
***************************/
let breadcrumb = new Breadcrumb();
......@@ -140,7 +170,7 @@ function showModuleDOM(module){
}
/****** App level events *************/
/****** App level events setup ********/
PubSub.subscribe('show-material', data => {
console.log('Handling event show-material: '+data.id+' view: '+data.view);
......@@ -205,7 +235,6 @@ Router.route();
let userNameElement = document.querySelector('#user-name');
let logoutButton = document.querySelector('#logout-button');
function setAppAuthenticated(data){
if (data.status === 'Authenticated'){
userNameElement.innerHTML = data.user.username;
......@@ -227,60 +256,6 @@ function setAppLoggedOut(){
flaggingTab.style.visibility = 'hidden';
}
//************* NORMAL WAY
/*
// When the app loads, it checks if the user is authenticated
let oReq = util.authServerReq('saml/user/', e => {
console.log('Response ',oReq.responseText);
let jsonData;
try {
jsonData = JSON.parse(oReq.responseText); //JSON.parse(response); //
console.log('Response jsonData out ',jsonData);
} catch(e) { console.log('../saml/user/ json response bad format', e); }
*/
/* Trick in order to test this feature in my local dev environment
let ddd= `{"status": "Authenticated",
"token": {
"data": "eyJhbGciOiJIUzI1NiIsImlhdCI6MTQ5MjA3MDI5MCwiZXhwIjoxNTIzNjI3ODkwfQ.eyJpZCI6ImVuY2d1aSJ9.oXYwGrLHRxdvKRal1NaAJJ5tCVTDupB5SjAGTtJVDKU",
"expires_in": 86400
},
"user": {
"email": "fakeuser@gmail.com",
"username": "fakeuser"
}
}`;
jsonData = JSON.parse(ddd);
*/
/*
setAppAuthenticated(jsonData);
});
// Logout
logoutButton.addEventListener( "click", e => {
util.authServerReq('saml/logout/', e => {});
//console.log('Logging out ',userNameElement.innerHTML);
userNameElement.innerHTML = '';
document.querySelector('#guest-user').style.display = 'inline';
document.querySelector('#auth-user').style.display = 'none';
util.setAuthRequestHeader();
if (flaggingTab.style.visibility !== 'hidden')
flaggingTab.style.visibility = 'hidden';
});
*/
//*********** COOKIES WAY
function getCookie(name) {
let value = "; " + document.cookie;
......@@ -295,65 +270,22 @@ function parseCookie(userData) {
let userInfoCookie = getCookie('user_info');
console.log('Cookies: ', document.cookie, userInfoCookie);
//console.log('Cookies: ', document.cookie, userInfoCookie);
if (userInfoCookie !== undefined){
let userInfoData = JSON.parse(parseCookie(userInfoCookie));
console.log('userInfoData: ', userInfoData);
//console.log('userInfoData: ', userInfoData);
setAppAuthenticated(userInfoData);
}
/*
let ddd= `{"status": "Authenticated",
"token": {
"data": "eyJhbGciOiJIUzI1NiIsImlhdCI6MTQ5MjA3MDI5MCwiZXhwIjoxNTIzNjI3ODkwfQ.eyJpZCI6ImVuY2d1aSJ9.oXYwGrLHRxdvKRal1NaAJJ5tCVTDupB5SjAGTtJVDKU",
"expires_in": 86400
},
"user": {
"email": "fakeuser@gmail.com",
"username": "fakeuser"
}
}`;
let jsonData = JSON.parse(ddd);
setAppAuthenticated(userInfoData);
*/
// Logout
logoutButton.addEventListener( "click", e => {
document.cookie='user_info=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain='+
util.USER_COOKIE_DOMAIN+'; path=/';
console.log('Logging out document.cookie ',document.cookie);
//console.log('Logging out document.cookie ',document.cookie);
setAppLoggedOut();
//console.log('Logging out ',userNameElement.innerHTML);
});
/*** Popup code
let loginButton = document.querySelector('#login-button');
let params = `width=400,height=600,left=600,top=100`;
loginButton.addEventListener( "click", e => {
let loginWindow;
// I think it's a blocking call
loginWindow = window.open('http://enc-testing-nomad.esc.rzg.mpg.de/v1.0/saml/', 'Login', params);
console.log("loginWindow", loginWindow);
loginWindow.addEventListener("focus", function(event) {
console.log("focus", loginWindow, loginWindow.document);
});
loginWindow.addEventListener("unload", function(event) {
console.log("unload", loginWindow, loginWindow.document.firstChild);
//loginWindow.close();
});
//location.reload(true);
});
*/
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment