1 line
21 KiB
JavaScript
1 line
21 KiB
JavaScript
"use strict";const MAX_INPUT_SIZE=1048576;'serviceWorker'in navigator&&(console.log("Registering service worker"),navigator.serviceWorker.register('/sw.js'));class QaPage{lang;tls;domWrapper;domUploaderWrapper;domUploaderCurrentWrapper;domMainWrapper;parser;selectedActivity;selectedApi;constructor(d,e){this.lang=d,this.tls=Object.freeze(e);let b=document.createElement("div");b.id="contentWrapper",this.domWrapper=b;let a=document.createElement("div");a.id="uploader",a.classList.add("uploader"),this.domUploaderWrapper=a;let c=document.createElement("div");c.id="uploaderMenu",this.domUploaderCurrentWrapper=c;let f=document.createElement("main");this.domMainWrapper=f}goForwardInMenuPages(b){const a=this;switch(b){case"parserSelection":a.drawUpActivitySelection();break;case"activityTypeSelection":a.drawUpApiTypeSelection();break;case"apiTypeSelection":a.drawUpUploadTypeSelection();break;default:console.log("Invalid page to go forward from selected.")}}generateDialogueCloseButton(){const a=document.createElement("a");return a.classList.add("icons"),a.classList.add("iconsClose"),a.classList.add("dialogueCloseX"),a.id="dialogueClose",a.textContent="X",a.title=this.tls.close,a.href="#"+location.href,a.addEventListener('click',QaDialogue.closeDialogue),a}setSelectedActivity(a){['evaluate','convert_to_xml'].includes(a)?this.selectedActivity=a:window.alert("Invalid activity selected")}setSelectedApi(b){let a;switch(this.selectedActivity){case"evaluate":a=['object','count_vocabulary_entries_to_be_added','minimaldatensatz'];break;case"convert_to_xml":const b=document.documentElement.getAttribute("data-allowed-xml-conversion-targets").split(',');a=b;break;default:window.alert("Invalid activity set: "+this.selectedActivity)}a.includes(b)?this.selectedApi=b:window.alert("Invalid activity selected")}downloadFromString(b,c){const d=new Blob([c],{type:"text/plain"}),a=document.createElement("a");a.download=b,a.href=window.URL.createObjectURL(d),a.dataset.downloadurl=["text/plain",a.download,a.href].join(":");const e=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0});a.dispatchEvent(e),a.remove()}generateValidationOutputsForCountNewToVocabs(c){const b=document.getElementById("validation_overlay_intro");b!==void 0&&b!==null&&b.parentElement.removeChild(b);const a=document.createElement("div"),d=document.createElement("h5");d.textContent=this.tls.count_new_to_vocabs,a.appendChild(d);const e=document.createElement("table");function f(d,e){const a=document.createElement("tr"),b=document.createElement("th");b.textContent=d,a.appendChild(b);const c=document.createElement("td");return c.textContent=e,a.appendChild(c),a}for(let a of c.count)e.appendChild(f(a.category_name,a.count));a.appendChild(e);const g=document.createElement("h6");g.textContent=this.tls.samples,a.appendChild(g);const h=document.createElement("table");for(let a of c.samples)h.appendChild(f(a.category_name,a.entries.join(", ")));return a.appendChild(h),a}generateValidationOutputsForMinimaldatensatz(b){const a=document.createElement("div");for(let d of b){const c=document.createElement("div"),e=document.createElement("h5");e.textContent=this.tls.inventory_number+': '+d.invno,c.appendChild(e);const f=document.createElement("table");for(let c of d.evaluations){const b=document.createElement("tr"),a=document.createElement("td");a.style.width="40px",c.passed===!0?a.style.background="var(--color-green)":a.style.background="var(--color-red)",b.appendChild(a);const e=document.createElement("td");e.textContent=c.text,b.appendChild(e),f.appendChild(b)}c.appendChild(f),a.appendChild(c)}return a}generateRegularValidationOutputs(c){const b=document.createElement("div");function a(d,e){const a=document.createElement("tr"),b=document.createElement("th");b.textContent=d,a.appendChild(b);const c=document.createElement("td");return c.appendChild(e),a.appendChild(c),a}for(let d of c){const g=document.createElement("div"),j=document.createElement("h5");j.textContent=this.tls.inventory_number+': '+d.invno,g.appendChild(j);const e=document.createElement("div"),f=document.createElement("table"),k=document.createElement("span");k.textContent=d.puqi.score,f.appendChild(a(this.tls.puqi_score,k));const h=document.createElement("span");d.plausi.warn===!1?h.textContent=this.tls.check_passed:h.textContent=this.tls.warning,f.appendChild(a(this.tls.plausi+': '+this.tls.status,h));const i=document.createElement("span");if(d.plausi_legal.warn===!1?i.textContent=this.tls.check_passed:i.textContent=this.tls.warning,f.appendChild(a(this.tls.plausi_legal+': '+this.tls.status,i)),e.appendChild(f),d.plausi.msg.length!==0){const a=document.createElement("h6");a.textContent=this.tls.plausibility_warnings,e.appendChild(a);const b=document.createElement("ul");for(let c of d.plausi.msg){const a=document.createElement("li");a.textContent=c,b.appendChild(a)}e.appendChild(b)}if(d.plausi_legal.warn===!0){const a=document.createElement("h6");a.textContent=this.tls.plausibility_warnings_licenses,e.appendChild(a);const b=document.createElement("ul");for(let a of d.plausi_legal.msg){const c=document.createElement("li");if(a.link!==''){const b=document.createElement("a");b.href=a.link,b.textContent=a.text,c.appendChild(b)}else c.textContent=a.text;b.appendChild(c)}e.appendChild(b)}const l=document.createElement("h6");l.textContent=this.tls.puqi_notices,e.appendChild(l);const m=document.createElement("ul");for(let b of d.puqi.msg){const a=document.createElement("li");a.textContent=b.message,m.appendChild(a)}e.appendChild(m),g.appendChild(e),b.appendChild(g)}return b}listValidationOutputs(b){console.log("Listing validation errors");const c=document.createElement("div"),d=document.createElement("h3");d.textContent=this.tls.validation_errors,d.appendChild(this.generateDialogueCloseButton()),c.appendChild(d);const e=document.createElement("p");e.id="validation_overlay_intro",e.textContent=this.tls.objects_identified.replace("[placeholder_for_count]",b.results.length),c.appendChild(e);const a=document.createElement("section");c.appendChild(a);const f=document.createElement("h4");switch(f.textContent=this.tls.results,a.appendChild(f),this.selectedApi){case"count_vocabulary_entries_to_be_added":a.appendChild(this.generateValidationOutputsForCountNewToVocabs(b.results));break;case"minimaldatensatz":a.appendChild(this.generateValidationOutputsForMinimaldatensatz(b.results));break;default:a.appendChild(this.generateRegularValidationOutputs(b.results));break}dialogue=QaDialogue.drawDialogue(c)}async runApiQuery(c){if(navigator.onLine===!1)return window.alert(this.tls.currently_offline_msg),document.body.classList.remove("loading"),!1;let a=this;(async function(){const a=c;a.includes('<27>')&&window.alert('The file encoding appears to not be UTF-8-encoded!')})();let b={parser:a.parser,lang:a.lang,data:c};a.selectedActivity==='convert_to_xml'&&(b.institution_name=window.prompt("The institution's name cannot automatically be reused from what may be stated in the uploaded data. If you would like to have one in the output data, please enter it here."),b.institution_identifier=window.prompt("The institution's identifier (e.g. an ISIL ID) cannot automatically be reused from what may be stated in the uploaded data. If you would like to have one in the output data, please enter it here."));try{let d=[];for(let a in b)d.push(a+'='+encodeURIComponent(b[a]));const c=await window.fetch('/api/'+a.selectedActivity+'/'+a.selectedApi,{method:'POST',cache:'no-cache',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:d.join("&")});if(document.body.classList.remove("loading"),c.status===200)switch(a.selectedActivity){case"evaluate":try{const b=await c.json();a.listValidationOutputs(b)}catch(a){console.log(a)}break;case"convert_to_xml":const b=await c.text();a.downloadFromString('converted-'+a.selectedActivity+'.xml',b);break;default:window.alert("Invalid activity selected")}else{const a=await c.text();window.alert(a)}}catch(a){console.log(a)}a.drawUpParserSelection()}uploadFileForValidation(b){let c=this;if(b.size>=MAX_INPUT_SIZE)return window.alert(this.tls.filesize_too_big.replace("[placeholder]",MAX_INPUT_SIZE)),!1;const a=new FileReader;a.readAsText(b,'UTF-8'),document.body.classList.add("loading"),a.onload=function(){function b(){c.runApiQuery(a.result)}b()},a.onerror=function(){alert(a.error)}}renderGenHeader(){const b=document.createElement("header");b.id="mainHeader";const a=document.createElement("a");a.id="logoArea",a.href="https://www.museum-digital.org/";const d=document.createElement("img");d.src="/static/img/mdlogo-code.svg",d.alt="Logo of museum-digital",a.appendChild(d);const l=document.createElement("h2");l.textContent="museum-digital",a.appendChild(l),b.appendChild(a);const c=document.createElement("nav"),f=document.createElement("a");f.href="https://en.about.museum-digital.org/about",f.textContent=this.tls.about,c.appendChild(f);const g=document.createElement("div"),h=document.createElement("a");h.textContent=this.tls.contact,h.href="https://en.about.museum-digital.org/contact/",g.appendChild(h);const i=document.createElement("div"),e=document.createElement("a");e.textContent=this.tls.imprint,e.href="https://en.about.museum-digital.org/impressum",i.appendChild(e);const j=document.createElement("a");j.textContent=this.tls.privacy_policy,j.href="https://en.about.museum-digital.org/privacy/",i.appendChild(j),g.appendChild(i),c.appendChild(g);const k=document.createElement("a");k.textContent=this.tls.news,k.href="https://blog.museum-digital.org/",c.appendChild(k),b.appendChild(c),document.body.appendChild(b)}renderHeader(){const b=document.createElement("header");b.id="appHeader";const c=document.createElement("h1"),a=document.createElement("img");a.width="70",a.height="70",a.src="/static/img/mdlogo-code.svg",a.alt="",c.appendChild(a);const d=document.createElement("span");d.textContent="museum-digital:qa",c.appendChild(d),b.appendChild(c),document.body.appendChild(b)}createP(b){const a=document.createElement("p");return a.textContent=b,a}createPlainTextElem(b,c){const a=document.createElement(b);return a.textContent=c,a}renderText(){const a=document.createElement("h2");a.textContent=this.tls.quality_assessment_tools,this.domMainWrapper.appendChild(a),this.domMainWrapper.appendChild(this.createP(this.tls.intro_text)),this.domWrapper.appendChild(this.domMainWrapper)}renderUploader(){const a=document.createElement("textarea");this.domUploaderWrapper.appendChild(a);const b=document.createElement("button");this.domUploaderWrapper.appendChild(b),this.domWrapper.appendChild(this.domUploaderWrapper)}renderStartpageSectionTechBackground(){const a=this;function b(b){b.classList.toggle("active");const a=b;a.style.maxHeight?a.style.maxHeight=null:a.style.maxHeight=a.scrollHeight+"px"}function f(d){d.appendChild(a.createPlainTextElem("h3",a.tls.types_of_evaluations));const c=document.createElement("div");c.classList.add("threeCol");function e(){const c=document.createElement("div");c.id="puqi_ex",c.appendChild(a.createPlainTextElem("h4",a.tls.puqi)),c.appendChild(a.createP(a.tls.puqi_explica)),c.appendChild(a.createPlainTextElem("h5",a.tls.see));const d=document.createElement("ul"),e=document.createElement("li");e.innerHTML='Rohde-Enslin, S. (2014). "PuQi - Eine Versuchung." Paper presented at the Autumn Seminar of the Working Group Documentation of the German Museum Association, 2014 (Herbsttagung der FG Dokumentation des Deutschen Museumsbunds). <a href="https://files.museum-digital.org/de/Praesentationen/2014-10-06_PuQI-Eine-Versuchung_SRE.pdf">https://files.museum-digital.org/de/Praesentationen/2014-10-06_PuQI-Eine-Versuchung_SRE.pdf</a>',d.appendChild(e);const f=document.createElement("li");f.innerHTML='Rohde-Enslin, S. (2015). "PuQI – A Smart Way to Create Better Data." <i>Uncommon Culture</i>, 6 (2), 122-129. <a href="https://uncommonculture.org/ojs/index.php/UC/article/view/6218">https://uncommonculture.org/ojs/index.php/UC/article/view/6218</a>',d.appendChild(f);const g=document.createElement("li");return g.innerHTML='Rohde-Enslin, S. (2021). "PuQi – Verführung zu Qualität." <i>museum-digital:blog</i>, <a href="https://blog.museum-digital.org/de/2021/01/22/ein-publikations-qualitaets-index-fuer-museumsobjektinformationen/">https://blog.museum-digital.org/de/2021/01/22/ein-publikations-qualitaets-index-fuer-museumsobjektinformationen/</a>',d.appendChild(g),c.appendChild(d),c.addEventListener('click',function(){b(c)},{passive:!0}),c}function f(){const c=document.createElement("div");c.id="plausi_ex",c.appendChild(a.createPlainTextElem("h4",a.tls.plausi)),c.appendChild(a.createP(a.tls.plausi_explica)),c.appendChild(a.createP(a.tls.plausi_explica_2)),c.appendChild(a.createPlainTextElem("h5",a.tls.see));const d=document.createElement("ul"),e=document.createElement("li");return e.innerHTML='Rohde-Enslin, S. (2017). "Plausi - PuQI hat einen Freund bekommen." Paper presented at the Autumn Seminar of the Working Group Documentation of the German Museum Association, 2017 (Herbsttagung der FG Dokumentation des Deutschen Museumsbunds). <a href="https://files.museum-digital.org/de/Praesentationen/2017-11_Plausi-FG-Doku-Berlin_SRE.pdf">https://files.museum-digital.org/de/Praesentationen/2017-11_Plausi-FG-Doku-Berlin_SRE.pdf</a>',d.appendChild(e),c.appendChild(d),c.addEventListener('click',function(){b(c)},{passive:!0}),c}function g(){const c=document.createElement("div");return c.id="plausi_legal_ex",c.appendChild(a.createPlainTextElem("h4",a.tls.plausi_legal)),c.appendChild(a.createP(a.tls.plausi_legal_explica)),c.appendChild(a.createP(a.tls.plausi_legal_explica_2)),c.addEventListener('click',function(){b(c)},{passive:!0}),c}function h(){const c=document.createElement("div");return c.id="minimaldatensatz_ex",c.appendChild(a.createPlainTextElem("h4",a.tls.count_new_to_vocabs)),c.appendChild(a.createP(a.tls.count_new_to_vocabs_explica_1)),c.addEventListener('click',function(){b(c)},{passive:!0}),c}function i(){const c=document.createElement("div");c.id="minimaldatensatz_ex",c.appendChild(a.createPlainTextElem("h4","AG Minimaldatensatz")),c.appendChild(a.createP(a.tls.minimaldatensatz_explica_1)),c.appendChild(a.createP(a.tls.minimaldatensatz_explica_2)),c.appendChild(a.createPlainTextElem("h5",a.tls.see));const d=document.createElement("ul"),e=document.createElement("li");e.innerHTML='AG Minimaldatensatz. (2023). "Minimaldatensatz-Empfehlung." <a href="http://minimaldatensatz.de">http://minimaldatensatz.de</a>',d.appendChild(e);const f=document.createElement("li");return f.innerHTML='Marchini C. & Greisinger S. (2023). "Ein Fuß in der Tür: Die Minimaldatensatz-Empfehlung für Museen und Sammlungen." Paper presented at the Autumn Seminar of the Working Group Documentation of the German Museum Association, 2023 (Herbsttagung der FG Dokumentation des Deutschen Museumsbunds).',d.appendChild(f),c.appendChild(d),c.addEventListener('click',function(){b(c)},{passive:!0}),c}c.appendChild(e()),c.appendChild(f()),c.appendChild(g()),c.appendChild(h()),c.appendChild(i()),d.appendChild(c)}function g(d){d.appendChild(a.createPlainTextElem("h3",a.tls.other_features));const c=document.createElement("div");c.classList.add("threeCol");function e(){const c=document.createElement("div");c.id="xmlC_ex",c.appendChild(a.createPlainTextElem("h4",a.tls.convert_to_xml)),c.appendChild(a.createP(a.tls.convert_to_xml_explica)),c.appendChild(a.createPlainTextElem("h5",a.tls.see));const e=document.createElement("ul"),f=document.createElement("li"),d=document.createElement("a");return d.textContent="EODEM",d.href="https://cidoc.mini.icom.museum/working-groups/documentation-standards/eodem-home/",f.appendChild(d),e.appendChild(f),c.appendChild(e),c.addEventListener('click',function(){b(c)},{passive:!0}),c}c.appendChild(e()),d.appendChild(c)}const c=document.createElement("div");c.appendChild(this.createPlainTextElem("h2",this.tls.tech_background_hl));const d=document.createElement("div");d.classList.add("summary"),d.appendChild(this.createPlainTextElem("h3",this.tls.summary)),d.appendChild(this.createP(this.tls.tech_background_summary)),d.appendChild(this.createP(this.tls.click_read_more)),c.appendChild(d);const e=this.createP(this.tls.tech_background_text);return e.classList.add("accordion"),c.appendChild(e),d.addEventListener('click',function(){b(e)},{passive:!0}),f(c),g(c),c}renderStartpageSectionFuture(){const a=document.createElement("div");return a.appendChild(this.createPlainTextElem("h2",this.tls.outlook)),a.appendChild(this.createP(this.tls.outlook_text)),a}renderStartpageSectionFaq(){function c(b){b.classList.toggle("active");const a=b;a.style.maxHeight?a.style.maxHeight=null:a.style.maxHeight=a.scrollHeight+"px"}function b(e,f){const a=document.createElement("div");a.id="faqEntry";const b=document.createElement("p");b.classList.add("faq_question"),b.textContent=e,a.appendChild(b);const d=document.createElement("div");return d.classList.add("faq_answer","accordion"),d.textContent=f,a.appendChild(d),b.addEventListener('click',function(){c(d)},{passive:!0}),a}const a=document.createElement("div");return a.id="faq",a.appendChild(this.createPlainTextElem("h2","FAQ")),a.appendChild(b(this.tls.faq_q_1,this.tls.faq_a_1)),a.appendChild(b(this.tls.faq_q_2,this.tls.faq_a_2)),a}renderStartpageSectionMore(){const a=document.createElement("div");a.id="more",a.appendChild(this.createPlainTextElem("h2",this.tls.more));const b=document.createElement("div");b.classList.add("moreTiles"),b.setAttribute("property","itemListElement"),b.setAttribute("typeof","http://schema.org/ListItem");let d=1;function f(o,n,m,l,j,k){const b=document.createElement("a");b.href=o,b.setAttribute("property","position"),b.setAttribute("content",d),d++;const c=document.createElement("picture");c.loading="lazy";const h=document.createElement("source");h.type="image/webp",h.srcset=l,c.appendChild(h);const g=document.createElement("source");g.type="image/png",g.srcset=j,c.appendChild(g);const a=document.createElement("img");a.loading="lazy",a.src=j,a.alt=k,a.width="400",a.height="225",a.setAttribute("property","image"),c.appendChild(a),b.appendChild(c);const f=document.createElement("div");f.classList.add("moreTilesMeta");const e=document.createElement("p");e.textContent=n,e.setAttribute("property","name"),e.classList.add("moreTilesTitle"),f.appendChild(e);const i=document.createElement("p");return i.textContent=m,i.classList.add("moreTilesSubtitle"),f.appendChild(i),b.appendChild(f),b}b.appendChild(f("https://files.museum-digital.org/","Vortragsfolien","Vortrag auf der Herbsttagung der Fachgruppe Dokumentation des DMB, 10.10.2023.","CC BY 4.0 @ Joshua Ramon Enslin, Freies Deutsches Hochstift","/static/img/more/20231010-Presentation.webp","/static/img/more/20231010-Presentation.png","Folie zur Nachnutzbarkeit von vorliegendem Code im Vortrag auf der Herbsttagung der FG Doku.")),a.appendChild(b),a.appendChild(this.createPlainTextElem("h3",this.tls.log));const c=document.createElement("ul"),g=this;function e(b,c){const a=document.createElement("li");return a.textContent=new Intl.DateTimeFormat([g.lang,'de']).format(b)+': '+c,a}c.appendChild(e(new Date(Date.UTC(2023,11,16,3,45,0,738)),"Add options to convert input data to XML formats")),c.appendChild(e(new Date(Date.UTC(2023,9,10,3,45,0,738)),this.tls.launch)),a.appendChild(c),a.appendChild(this.createPlainTextElem("h3",this.tls.thanks));const h=document.createElement("p");return a.appendChild(h),a}renderFooter(){const d=document.createElement("footer"),b=document.createElement("div"),e=document.createElement("a");if(e.textContent="API",e.href="/swagger",b.appendChild(e),'serviceWorker'in navigator){const a=document.createElement("span");a.textContent=this.tls.reload_application,a.setAttribute("tabindex",1),a.addEventListener('click',function(a){Promise.all(['qa-cache-v1'].map(function(a){caches.has(a).then(function(b){b===!0&&caches.delete(a).then(function(a){})})})),location.reload()},{passive:!0,once:!0}),b.appendChild(a)}const i=document.documentElement.getAttribute("data-allowed-langs").split(','),g=document.createElement("div");for(let b of i){const a=document.createElement("a");a.href="#"+b,a.textContent=b,a.style.textTranform="uppercase",a.addEventListener('click',function(a){a.preventDefault(),sessionStorage.setItem("lang",b),location.reload()}),g.appendChild(a)}b.appendChild(g),d.appendChild(b);const a=document.createElement("p"),f=document.createElement("a");f.textContent="CC BY 4.0",f.href="https://creativecommons.org/licenses/by/4.0/",a.appendChild(f),a.appendChild(this.createPlainTextElem("span"," @ "));const c=document.createElement("a");c.textContent="Joshua Ramon Enslin",c.href="https://www.jrenslin.de",c.setAttribute("rel","author"),a.appendChild(c),a.appendChild(this.createPlainTextElem("span",", "));const h=document.createElement("span");h.textContent="2023",a.appendChild(h),d.appendChild(a),document.body.appendChild(d)}}(async function(){function c(){const c=document.documentElement.getAttribute("data-allowed-langs").split(','),a=sessionStorage.getItem("lang");if(a!==void 0&&c.includes(a))return a;if(navigator.language===void 0)return'en';const b=navigator.language.toLowerCase().substr(0,2);return console.log(b),c.includes(b)?b:'en'}const a=c();document.documentElement.setAttribute("lang",a),document.body.classList.add("loading");let e=0,b;function d(){document.body.classList.remove("loading");const c=new QaPage(a,b);c.renderGenHeader(),c.renderHeader(),c.renderUploader(),c.renderText(),document.body.appendChild(c.domWrapper),c.renderFooter()}window.fetch('/static/json/tls.'+a+'.json',{method:'GET',cache:'no-cache',credentials:'same-origin'}).then(function(a){return a.json()}).then(function(a){b=a,d()})})() |