Commit f57df8cd authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Added better handling of missing material information.

parent 6566fba1
Pipeline #97678 skipped with stage
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -1224,6 +1224,14 @@ text.structure-viewer-legend-labels{ ...@@ -1224,6 +1224,14 @@ text.structure-viewer-legend-labels{
font-size: 16px; font-size: 16px;
} }
#missing-prompt{
margin-top: 0.5rem;
background-color: #E56400;
color: white;
padding: 16px;
display: none;
}
/* /*
.tooltip { .tooltip {
visibility: hidden; visibility: hidden;
......
...@@ -33,6 +33,7 @@ let calcMap = new Map(); ...@@ -33,6 +33,7 @@ let calcMap = new Map();
let ready = false; let ready = false;
let hasThermal; let hasThermal;
let hasElecStructure; let hasElecStructure;
let missing = false;
function setMaterialData(dataFromAPI){ function setMaterialData(dataFromAPI){
materialData = dataFromAPI; materialData = dataFromAPI;
...@@ -42,6 +43,14 @@ function getMaterialData(){ ...@@ -42,6 +43,14 @@ function getMaterialData(){
return materialData; return materialData;
} }
function setMissing(value) {
missing = value;
}
function getMissing() {
return missing;
}
function setIdealizedStructure(structure){ function setIdealizedStructure(structure){
idealizedStructure = structure; idealizedStructure = structure;
} }
...@@ -129,6 +138,9 @@ function getGroupId(leafId) { ...@@ -129,6 +138,9 @@ function getGroupId(leafId) {
function isReady(matId) { function isReady(matId) {
if (materialData !== undefined) { if (materialData !== undefined) {
if (missing && matId == materialData.material_id) {
return true;
}
if (idealizedStructure !== undefined) { if (idealizedStructure !== undefined) {
if (calcs !== undefined) { if (calcs !== undefined) {
if (groups !== undefined) { if (groups !== undefined) {
...@@ -147,6 +159,7 @@ function clear() { ...@@ -147,6 +159,7 @@ function clear() {
calcs = undefined; calcs = undefined;
groups = undefined; groups = undefined;
idealizedStructure = undefined; idealizedStructure = undefined;
missing = false;
} }
function isInAnyGroup(calcId){ function isInAnyGroup(calcId){
...@@ -192,6 +205,8 @@ module.exports = { ...@@ -192,6 +205,8 @@ module.exports = {
isInAnyNotDisabledGroup, isInAnyNotDisabledGroup,
getGroupLeafId, getGroupLeafId,
isReady, isReady,
setMissing,
getMissing,
clear, clear,
setIdealizedStructure, setIdealizedStructure,
getIdealizedStructure, getIdealizedStructure,
......
...@@ -48,6 +48,9 @@ class MaterialMod { ...@@ -48,6 +48,9 @@ class MaterialMod {
constructor(){ constructor(){
this.element = document.createElement('div'); this.element = document.createElement('div');
this.element.setAttribute("id",'material-module'); this.element.setAttribute("id",'material-module');
this.missingPrompt = document.createElement('div');
this.missingPrompt.id = "missing-prompt";
this.element.appendChild(this.missingPrompt)
this.overview = new Overview(); this.overview = new Overview();
this.overview.attachAndSetEvents(this.element); this.overview.attachAndSetEvents(this.element);
...@@ -138,30 +141,45 @@ class MaterialMod { ...@@ -138,30 +141,45 @@ class MaterialMod {
* Called upon loading the overview page for a specific material. * Called upon loading the overview page for a specific material.
*/ */
_loadMaterial(matId, view) { _loadMaterial(matId, view) {
// Set to loading mode
this._setView(view);
let show = () => { let show = () => {
let materialData = DataStore.getMaterialData(); // Show error message if resource not found
let idealizedStructure = DataStore.getIdealizedStructure(); const missingPrompt = document.getElementById("missing-prompt");
// Cell viewer needs to be set only after page is visible so that it is if (DataStore.getMissing()) {
// resized correctly. // Hide the current view
if (this.currentDetailView !== null) { if (this.currentDetailView === null) {
this.currentDetailView.load(); this.overview.element.style.display = 'none';
if (view === util.MAT_VIEW.structure) { } else {
this._setCellViewer(this.structureDetails.vizBox); this.currentDetailView.element.style.display = 'none';
}
if (view === util.MAT_VIEW.methodology) {
this.methodologyDetails.updateSelection();
} }
const msg = `
Could not find information for material with identifier ${matId}.
Either the material does not exist or is not yet visible in the Encyclopedia.
`;
missingPrompt.textContent = msg;
missingPrompt.style.display = "block";
} else { } else {
document.querySelector('title').innerHTML = missingPrompt.style.display = "none";
'NOMAD Encyclopedia - '+util.getMaterialTitle(materialData, false); this._setView(view);
this.overview.setMaterialData(); let materialData = DataStore.getMaterialData();
let name = (materialData.material_name === null ? materialData.formula : materialData.material_name); let idealizedStructure = DataStore.getIdealizedStructure();
this.overview.setCalcsData(markedTreeLeafs); // Cell viewer needs to be set only after page is visible so that it is
this._setCellViewer(this.overview.vizBox); // resized correctly.
if (this.currentDetailView !== null) {
this.currentDetailView.load();
if (view === util.MAT_VIEW.structure) {
this._setCellViewer(this.structureDetails.vizBox);
}
if (view === util.MAT_VIEW.methodology) {
this.methodologyDetails.updateSelection();
}
} else {
document.querySelector('title').innerHTML =
'NOMAD Encyclopedia - '+util.getMaterialTitle(materialData, false);
this.overview.setMaterialData();
let name = (materialData.material_name === null ? materialData.formula : materialData.material_name);
this.overview.setCalcsData(markedTreeLeafs);
this._setCellViewer(this.overview.vizBox);
}
} }
}; };
let isReady = () => { let isReady = () => {
...@@ -175,6 +193,7 @@ class MaterialMod { ...@@ -175,6 +193,7 @@ class MaterialMod {
// If material is already loaded, nothing fetched. // If material is already loaded, nothing fetched.
if (!isReady()) { if (!isReady()) {
DataStore.clear(); DataStore.clear();
this.overview.clearCalcsData();
LoadingPopup.reset(); LoadingPopup.reset();
this.structureViewer.axisCheckbox.checked = true; this.structureViewer.axisCheckbox.checked = true;
this.structureViewer.bondsCheckbox.checked = true; this.structureViewer.bondsCheckbox.checked = true;
...@@ -187,9 +206,16 @@ class MaterialMod { ...@@ -187,9 +206,16 @@ class MaterialMod {
// Request basic material data // Request basic material data
LoadingPopup.show("load_basic"); LoadingPopup.show("load_basic");
util.serverReq(util.getMaterialURL(matId), e1 => { util.serverReq(util.getMaterialURL(matId), e1 => {
let materialData = JSON.parse(e1.target.response); // Check for error
DataStore.setMaterialData(materialData); let stat = e1.target.status;
util.materialId = materialData.material_id; if (stat >= 400 && stat < 500) {
DataStore.setMissing(true);
DataStore.setMaterialData({material_id: matId});
} else {
let materialData = JSON.parse(e1.target.response);
DataStore.setMaterialData(materialData);
util.materialId = materialData.material_id;
}
isReady(); isReady();
LoadingPopup.hide("load_basic"); LoadingPopup.hide("load_basic");
}); });
...@@ -197,32 +223,50 @@ class MaterialMod { ...@@ -197,32 +223,50 @@ class MaterialMod {
// Request basic details for all calculations related to this material // Request basic details for all calculations related to this material
LoadingPopup.show("load_calculations"); LoadingPopup.show("load_calculations");
util.serverReq(util.getMaterialXsURL('calculations', matId), e4 => { util.serverReq(util.getMaterialXsURL('calculations', matId), e4 => {
let calculations = JSON.parse(e4.target.response); // Check for error
let representatives = calculations.representatives; let stat = e4.target.status;
let idealId = representatives.idealized_structure; if (stat >= 400 && stat < 500) {
DataStore.setCalculations(calculations); DataStore.setMissing(true);
} else {
// Get the idealized structure let calculations = JSON.parse(e4.target.response);
//util.serverReq(util.getMaterialXsURL('idealized_structure', matId), e2 => { let representatives = calculations.representatives;
let query = JSON.stringify({properties: ["idealized_structure"]}); let idealId = representatives.idealized_structure;
LoadingPopup.show("load_idealized"); DataStore.setCalculations(calculations);
util.serverReqPOST(util.getMaterialCalcURL(matId, idealId), query, e2 => {
let struct = JSON.parse(e2.target.response).idealized_structure; // Get the idealized structure
DataStore.setIdealizedStructure(struct); //util.serverReq(util.getMaterialXsURL('idealized_structure', matId), e2 => {
this.structureViewer.load(struct); let query = JSON.stringify({properties: ["idealized_structure"]});
document.getElementById('structure-ov').style.visibility = 'visible'; LoadingPopup.show("load_idealized");
document.getElementById('methodology-ov').style.visibility = 'visible'; util.serverReqPOST(util.getMaterialCalcURL(matId, idealId), query, e2 => {
isReady(); // Check for error
LoadingPopup.hide("load_idealized"); let stat = e2.target.status;
}); if (stat >= 400 && stat < 500) {
DataStore.setMissing(true);
} else {
let struct = JSON.parse(e2.target.response).idealized_structure;
DataStore.setIdealizedStructure(struct);
this.structureViewer.load(struct);
document.getElementById('structure-ov').style.visibility = 'visible';
document.getElementById('methodology-ov').style.visibility = 'visible';
}
isReady();
LoadingPopup.hide("load_idealized");
});
}
LoadingPopup.hide("load_calculations"); LoadingPopup.hide("load_calculations");
}); });
// Request groups // Request groups
LoadingPopup.show("load_groups"); LoadingPopup.show("load_groups");
util.serverReq(util.getMaterialXsURL('groups', matId), e5 => { util.serverReq(util.getMaterialXsURL('groups', matId), e5 => {
let groups = JSON.parse(e5.target.response); // Check for error
DataStore.setGroups(groups); let stat = e5.target.status;
if (stat >= 400 && stat < 500) {
DataStore.setMissing(true);
} else {
let groups = JSON.parse(e5.target.response);
DataStore.setGroups(groups);
}
isReady(); isReady();
LoadingPopup.hide("load_groups"); LoadingPopup.hide("load_groups");
}); });
......
...@@ -358,6 +358,14 @@ class Overview { ...@@ -358,6 +358,14 @@ class Overview {
return false; return false;
} }
clearCalcsData() {
this.materialId = null;
this.calcMaterialId = null;
let bsLoaded = false;
let phononLoaded = false;
let dosLoaded = false;
}
setCalcsData(markedTreeLeafs) { setCalcsData(markedTreeLeafs) {
let matData = DataStore.getMaterialData(); let matData = DataStore.getMaterialData();
let calcs = DataStore.getCalculations(); let calcs = DataStore.getCalculations();
......
Markdown is supported
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