Commit 46401a39 authored by Iker Hurtado's avatar Iker Hurtado
Browse files

User flagging feature: set the definitive content, text and format in the generated issues

parent 8f721f36
Pipeline #23910 passed with stages
in 14 seconds
......@@ -127,7 +127,7 @@ var BAND_STRUCT_EXAMPLE_URL=API_BASE_URL+'materials/108541/calculations/290737';
'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
];var authRequestHeaderValue=AUTH_REQUEST_HEADER_GUEST_USER;//console.log('user: ANONYMOUS authRequestHeader: ',authRequestHeaderValue);
var userData=null;function getUserData(){return userData;}function authServerReq(url,callback){var oReq=new XMLHttpRequest();oReq.addEventListener("load",callback);console.log('util.authServerReq: ',API_BASE_URL+url);oReq.open("GET",API_BASE_URL+url);//console.log('util.authServerReq oReq: ', oReq);
var userData=null;function getUserData(){return userData;}function getServerLocation(){return document.location.hostname;}function authServerReq(url,callback){var oReq=new XMLHttpRequest();oReq.addEventListener("load",callback);console.log('util.authServerReq: ',API_BASE_URL+url);oReq.open("GET",API_BASE_URL+url);//console.log('util.authServerReq oReq: ', oReq);
oReq.send();return oReq;}function setAuthRequestHeader(userDataP,value){if(value===undefined){// default value
authRequestHeaderValue=AUTH_REQUEST_HEADER_GUEST_USER;userData=null;//console.log('user: ANONYMOUS authRequestHeader: ',authRequestHeaderValue);
}else{authRequestHeaderValue='Basic '+btoa(value+':');userData=userDataP;//console.log('user',user,'authRequestHeader: ',authRequestHeaderValue);
......@@ -186,7 +186,7 @@ exp=exp<0?0:exp;return[stepArray,exp];}/*
//console.log('TEMPORARY PATCH is2DSystem:', DataStore.getMaterialData());
return DataStore.getMaterialData().system_type === '2D';
}
*/module.exports={searchResults:searchResults,materialId:materialId,MAT_VIEW:MAT_VIEW,IMAGE_DIR:IMAGE_DIR,USER_COOKIE_DOMAIN:USER_COOKIE_DOMAIN,ELEMENTS:ELEMENTS,setAuthRequestHeader:setAuthRequestHeader,getUserData:getUserData,authServerReq:authServerReq,serverReq:serverReq,serverReqPOST:serverReqPOST,getSearchURL:getSearchURL,getSuggestionURL:getSuggestionURL,getMaterialURL:getMaterialURL,getMaterialCalcURL:getMaterialCalcURL,getMaterialXsURL:getMaterialXsURL,getCalcEnergiesURL:getCalcEnergiesURL,getFlaggingURL:getFlaggingURL,setBrowserHashPath:setBrowserHashPath,loadLib:loadLib,getNumberArray:getNumberArray,getCellDataForViewer:getCellDataForViewer,//FERMI_SURFACE_URL: FERMI_SURFACE_URL,
*/module.exports={searchResults:searchResults,materialId:materialId,MAT_VIEW:MAT_VIEW,IMAGE_DIR:IMAGE_DIR,USER_COOKIE_DOMAIN:USER_COOKIE_DOMAIN,ELEMENTS:ELEMENTS,setAuthRequestHeader:setAuthRequestHeader,getUserData:getUserData,getServerLocation:getServerLocation,authServerReq:authServerReq,serverReq:serverReq,serverReqPOST:serverReqPOST,getSearchURL:getSearchURL,getSuggestionURL:getSuggestionURL,getMaterialURL:getMaterialURL,getMaterialCalcURL:getMaterialCalcURL,getMaterialXsURL:getMaterialXsURL,getCalcEnergiesURL:getCalcEnergiesURL,getFlaggingURL:getFlaggingURL,setBrowserHashPath:setBrowserHashPath,loadLib:loadLib,getNumberArray:getNumberArray,getCellDataForViewer:getCellDataForViewer,//FERMI_SURFACE_URL: FERMI_SURFACE_URL,
BAND_STRUCT_EXAMPLE_URL:BAND_STRUCT_EXAMPLE_URL,J2eV:J2eV,eV2J:eV2J,//getBandGapStatsValue: getBandGapStatsValue,
m2Angstrom:m2Angstrom,getLatticeAnglesValues:getLatticeAnglesValues,rad2degree:rad2degree,m3ToAngstrom3:m3ToAngstrom3,getQuantityStatsMap:getQuantityStatsMap,toAngstromMinus3:toAngstromMinus3,getMaterialTitle:getMaterialTitle,getMinMaxHTML:getMinMaxHTML,getSubscriptedFormula:getSubscriptedFormula,getAverage:getAverage,generateDiagramSteps:generateDiagramSteps};},/* 2 *//***/function(module,exports){var materialData=void 0;function setMaterialData(dataFromAPI){materialData=dataFromAPI;}function getMaterialData(){return materialData;}var calcs=void 0;var calcMap=new Map();function setCalculations(calcsFromAPI){calcs=calcsFromAPI;for(var i=0;i<calcs.length;i++){calcMap.set(calcs[i].id,calcs[i]);}}function getCalculations(){return calcs;}function getCalc(calcId){return calcMap.get(calcId);}var groups=void 0;function processCalcGroups(groupsFromAPI){var methodCalcsMap=new Map();groupsFromAPI.forEach(function(group,i){if(group.group_type!=='method'){var calcsMins=void 0;if(methodCalcsMap.has(group.method_hash)){calcsMins=methodCalcsMap.get(group.method_hash);}else{calcsMins={'ids':[],'minEnergies':[]};methodCalcsMap.set(group.method_hash,calcsMins);}calcsMins.ids.push(group.representative_calculation_id);calcsMins.minEnergies.push(group.energy_minimum);}});//console.log('methodCalcsMap', methodCalcsMap);
var methodRepresentativeMap=new Map();methodCalcsMap.forEach(function(calcsData,methodHash){var minVal=Math.min.apply(null,calcsData.minEnergies);var index=calcsData.minEnergies.indexOf(minVal);methodRepresentativeMap.set(methodHash,calcsData.ids[index]);});//console.log('methodRepresentativeMap', methodRepresentativeMap);
......@@ -225,9 +225,9 @@ eStructOption.style.display=DataStore.hasElecStructureData?'block':'none';therma
}function hide(){flaggingPopupBackground.style.visibility='hidden';flaggingFormPopup.style.visibility='hidden';// reset UI
categoryField.selectedIndex=0;subcategoryField.selectedIndex=0;flaggingFormPopup.querySelector('textarea').value='';validationMsg.innerHTML='';}function createOption(text,value){var opt=document.createElement('option');opt.value=value===undefined?text:value;opt.innerHTML=text;return opt;}closeButton.addEventListener('click',function(e){hide();});sendButton.addEventListener('click',function(e){var categoryChosen=categoryField.options[categoryField.selectedIndex];if(!categoryField.disabled&&categoryChosen.value===''){// Overview case
validationMsg.innerHTML='The category fields must be set';}else if(categoryField.disabled&&subcategoryField.value===''// Detaisl pages case
&&categoryChosen.value!==util.MAT_VIEW.methodology){validationMsg.innerHTML='The subcategory fields must be set';}else{validationMsg.innerHTML='Sending report...';var textareaText=flaggingFormPopup.querySelector('textarea').value;var materialId=DataStore.getMaterialData().id;var userdata=util.getUserData();var titleText='FAKE ISSUE!! TESTING GUI user flagging. User: '+userdata.username+' | Material id: '+materialId;var descriptionText='User email: '+userdata.email;// Overview page
if(!categoryField.disabled){titleText+=' | Category: Overview - '+categoryChosen.text;if(categoryChosen.value===util.MAT_VIEW.electronicstruct&&overviewEStructCalcs!==null)descriptionText+=' | Chosen calculations: '+(overviewEStructCalcs.bs===null?'':'BS calc:'+overviewEStructCalcs.bs)+(overviewEStructCalcs.dos===null?'':'DOS calc:'+overviewEStructCalcs.dos);}else{// Details pages
titleText+=' | Category: '+categoryChosen.text;if(categoryChosen.value!==util.MAT_VIEW.methodology){descriptionText+=' | Subcategory: '+subcategoryField.options[subcategoryField.selectedIndex].text;descriptionText+=' | Calc tree leaf marked: '+treeLeaf;}}descriptionText+=' | Text: '+textareaText;//titleText = 'FAKE ISSUE! @ : TESTING GUI user flagging';
&&categoryChosen.value!==util.MAT_VIEW.methodology){validationMsg.innerHTML='The subcategory fields must be set';}else{validationMsg.innerHTML='Sending report...';var textareaText=flaggingFormPopup.querySelector('textarea').value;var materialId=DataStore.getMaterialData().id;var userdata=util.getUserData();var titleText='User issue | Material '+materialId;var descriptionText='**Server:** '+util.getServerLocation()+'\\n\\n**User:** '+userdata.username+', '+userdata.email;// Overview page
if(!categoryField.disabled){descriptionText+='\\n\\n**Category:** Overview / '+categoryChosen.text;if(categoryChosen.value===util.MAT_VIEW.electronicstruct&&overviewEStructCalcs!==null)descriptionText+='\\n\\n**Chosen calculations:** '+(overviewEStructCalcs.bs===null?'':'BS calculation '+overviewEStructCalcs.bs)+(overviewEStructCalcs.dos===null?'':' DOS calculation '+overviewEStructCalcs.dos);}else{// Details pages
descriptionText+='\\n\\n**Category:** '+categoryChosen.text;if(categoryChosen.value!==util.MAT_VIEW.methodology){descriptionText+='\\n\\n**Subcategory:** '+subcategoryField.options[subcategoryField.selectedIndex].text+'\\n\\n**Calculation/group marked on the tree:** '+treeLeaf;}}descriptionText+='\\n\\n**User text:** '+textareaText;//titleText = 'FAKE ISSUE! @ : TESTING GUI user flagging';
//descriptionText = 'Text ';
var queryJson="{\n\t \"title\": \""+titleText+"\",\n\t \"description\": \""+descriptionText+"\"}";console.log('Flagging POST request Json: ',queryJson);//, util.getFlaggingURL());
util.serverReqPOST(util.getFlaggingURL(),queryJson,function(e){console.log('response',e);if(e.target.status===200)hide();});}});// EXPORTS
......
......@@ -480,6 +480,10 @@
return userData;
}
function getServerLocation(){
return document.location.hostname;
}
function authServerReq(url, callback){
var oReq = new XMLHttpRequest();
......@@ -819,6 +823,7 @@
ELEMENTS: ELEMENTS,
setAuthRequestHeader,
getUserData,
getServerLocation,
authServerReq,
serverReq,
serverReqPOST,
......@@ -1225,28 +1230,32 @@
let materialId = DataStore.getMaterialData().id;
let userdata = util.getUserData();
let titleText = 'FAKE ISSUE!! TESTING GUI user flagging. User: '+
userdata.username+' | Material id: '+materialId;
let descriptionText = 'User email: '+userdata.email;
let titleText = 'User issue | Material '+materialId;
let descriptionText = '**Server:** '+util.getServerLocation()+
'\\n\\n**User:** '+userdata.username+', '+userdata.email;
// Overview page
if ( !categoryField.disabled){
titleText += ' | Category: Overview - '+categoryChosen.text;
descriptionText += '\\n\\n**Category:** Overview / '+categoryChosen.text;
if (categoryChosen.value === util.MAT_VIEW.electronicstruct
&& overviewEStructCalcs !== null)
descriptionText += ' | Chosen calculations: '+
(overviewEStructCalcs.bs === null ? '' : 'BS calc:'+overviewEStructCalcs.bs)+
(overviewEStructCalcs.dos === null ? '' : 'DOS calc:'+overviewEStructCalcs.dos);
descriptionText += '\\n\\n**Chosen calculations:** '+
(overviewEStructCalcs.bs === null ? '' : 'BS calculation '+overviewEStructCalcs.bs)+
(overviewEStructCalcs.dos === null ? '' : ' DOS calculation '+overviewEStructCalcs.dos);
}else{ // Details pages
titleText += ' | Category: '+categoryChosen.text;
descriptionText += '\\n\\n**Category:** '+categoryChosen.text;
if (categoryChosen.value !== util.MAT_VIEW.methodology){
descriptionText += ' | Subcategory: '+
subcategoryField.options[subcategoryField.selectedIndex].text;
descriptionText += ' | Calc tree leaf marked: '+treeLeaf;
descriptionText += '\\n\\n**Subcategory:** '+
subcategoryField.options[subcategoryField.selectedIndex].text+
'\\n\\n**Calculation/group marked on the tree:** '+treeLeaf;
}
}
descriptionText += ' | Text: '+textareaText;
descriptionText += '\\n\\n**User text:** '+textareaText;
//titleText = 'FAKE ISSUE! @ : TESTING GUI user flagging';
//descriptionText = 'Text ';
......@@ -1255,11 +1264,13 @@
"description": "${descriptionText}"}`;
console.log('Flagging POST request Json: ',queryJson);//, util.getFlaggingURL());
util.serverReqPOST(util.getFlaggingURL(), queryJson, e => {
console.log('response',e);
if (e.target.status === 200) hide();
});
}
});
......
......@@ -170,28 +170,32 @@ sendButton.addEventListener('click', e => {
let materialId = DataStore.getMaterialData().id;
let userdata = util.getUserData();
let titleText = 'FAKE ISSUE!! TESTING GUI user flagging. User: '+
userdata.username+' | Material id: '+materialId;
let descriptionText = 'User email: '+userdata.email;
let titleText = 'User issue | Material '+materialId;
let descriptionText = '**Server:** '+util.getServerLocation()+
'\\n\\n**User:** '+userdata.username+', '+userdata.email;
// Overview page
if ( !categoryField.disabled){
titleText += ' | Category: Overview - '+categoryChosen.text;
descriptionText += '\\n\\n**Category:** Overview / '+categoryChosen.text;
if (categoryChosen.value === util.MAT_VIEW.electronicstruct
&& overviewEStructCalcs !== null)
descriptionText += ' | Chosen calculations: '+
(overviewEStructCalcs.bs === null ? '' : 'BS calc:'+overviewEStructCalcs.bs)+
(overviewEStructCalcs.dos === null ? '' : 'DOS calc:'+overviewEStructCalcs.dos);
descriptionText += '\\n\\n**Chosen calculations:** '+
(overviewEStructCalcs.bs === null ? '' : 'BS calculation '+overviewEStructCalcs.bs)+
(overviewEStructCalcs.dos === null ? '' : ' DOS calculation '+overviewEStructCalcs.dos);
}else{ // Details pages
titleText += ' | Category: '+categoryChosen.text;
descriptionText += '\\n\\n**Category:** '+categoryChosen.text;
if (categoryChosen.value !== util.MAT_VIEW.methodology){
descriptionText += ' | Subcategory: '+
subcategoryField.options[subcategoryField.selectedIndex].text;
descriptionText += ' | Calc tree leaf marked: '+treeLeaf;
descriptionText += '\\n\\n**Subcategory:** '+
subcategoryField.options[subcategoryField.selectedIndex].text+
'\\n\\n**Calculation/group marked on the tree:** '+treeLeaf;
}
}
descriptionText += ' | Text: '+textareaText;
descriptionText += '\\n\\n**User text:** '+textareaText;
//titleText = 'FAKE ISSUE! @ : TESTING GUI user flagging';
//descriptionText = 'Text ';
......@@ -200,11 +204,13 @@ sendButton.addEventListener('click', e => {
"description": "${descriptionText}"}`;
console.log('Flagging POST request Json: ',queryJson);//, util.getFlaggingURL());
util.serverReqPOST(util.getFlaggingURL(), queryJson, e => {
console.log('response',e);
if (e.target.status === 200) hide();
});
}
});
......
......@@ -69,6 +69,10 @@ function getUserData(){
return userData;
}
function getServerLocation(){
return document.location.hostname;
}
function authServerReq(url, callback){
var oReq = new XMLHttpRequest();
......@@ -408,6 +412,7 @@ module.exports = {
ELEMENTS: ELEMENTS,
setAuthRequestHeader,
getUserData,
getServerLocation,
authServerReq,
serverReq,
serverReqPOST,
......
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