function isIdInResultArray(resultArray, id) { for (var i in resultArray) { if (resultArray[i].id === id) { return true; } } return false; } function find(searchParams, selectedId, selectedFirst) { var backendParams = convertParamsForBackend(searchParams); return sendRequestPromise(backendParams, "find", "sendQuery", activeTab) .then(function(res) { var resultArray = res.resultArray; return generateSearchResult(searchParams, resultArray, selectedId, selectedFirst); }); } function generateSearchResult(searchParams, resultArray, selectedId, selectFirst) { if (isJsonCall) { $("body").empty(); $("body").append(JSON.stringify(resultArray)); document.location = url + "Server/sendQuerySub/output.php"; return; } if (resultArray === undefined || resultArray.length === 0) { $("#resultList").empty(); $("#resultContent").empty(); $("#numberOfResults").html('Treffer: 0'); return Promise.resolve(); } else { clearAndBuildResultList(searchParams, resultArray); $("#resultContent").empty(); if (selectedId !== undefined && isIdInResultArray(resultArray, selectedId)) { return buildDetailContent(searchParams, activeTab, selectedId); } else if (selectFirst === true && resultArray.length === 1) { return buildDetailContent(searchParams, activeTab, resultArray[0]["id"]); } else { //timeline only for musici, baccae and eventa if (activeTab == 0 || activeTab == 2 || activeTab == 5) { $("#resultContent").append("
"); $("#resultContent").append("
"); } //no map for res and catalogus if (activeTab !== 6 && activeTab !== 7){ $("#resultContent").append("
"); $("#resultContent").append("
"); } $("#resultContent").append("
"); $("#resultContent").append("
"); //Pies $("#visSunBursts").append('
'); toolTip = new ToolTip("#resultContent"); buildOverviewPage(resultArray); return Promise.resolve(); } } } function asyncRequestTimeLine(ids, count, customContent) { return sendRequestPromise(ids, "asyncLoadTimeLineData", "sendQuery", activeTab) .then(function(res) { var resultArray = res.resultArray; toolTipTimeline = new ToolTipTimeline("#visTimeLine"); //TREFFERLISTEN VIS //TIMELINE var timelineData = []; var timelineId = "timeline"; var needLegend = false; for (var key in resultArray) { for (var key2 in resultArray[key]["timelineDates"]) { timelineData.push(resultArray[key]["timelineDates"][key2]); } } if (customContent) { for (var key in customContent) { for (var date in timelineData) { if (customContent[key]["mXp-ID"] === timelineData[date]["F41"]) { timelineData[date]["Art"] = customContent[key]["key"]; } } } } if (activeTab == 2 || activeTab == 5) { needLegend = true; var events = []; typesOfPlaces[activeTab] = []; for (var entry in count) { events[count[entry]["type"]] = entry; if (typesOfPlaces[activeTab].indexOf(count[entry]["type"]) === -1) { typesOfPlaces[activeTab].push(count[entry]["type"]); } } timelineData.sort(function(a, b) { return events[b["Art"]] + events[a["Art"]]; }); } if (timelineData.length > 0) { makeTimeline(timelineData, timelineId, needLegend, count, false); } else { $("#" + timelineId).remove(); } }); } function asyncRequestMap(ids, count) { return sendRequestPromise(ids, "asyncLoadMapData", "sendQuery", activeTab) .then(function(res) { var resultArray = res.resultArray; var array = []; for (var key in resultArray) { var tmpEntity = resultArray[key]; if (tmpEntity["mapPlaces"]) { for (var key in tmpEntity["mapPlaces"]) { var tmp = tmpEntity["mapPlaces"][key]; if (!tmp[1] || !tmp[2]) continue; //Skip it, is logged on serverside and inserted into db as missing entry array.push([tmp[0], tmp[1], tmp[2], tmp[3], tmpEntity["F41"]]); } } } if (activeTab == 2 || activeTab == 5) { var events = []; typesOfPlaces[activeTab] = []; for (var entry in count) { events[count[entry]["type"]] = entry; if (typesOfPlaces[activeTab].indexOf(count[entry]["type"]) === -1) { typesOfPlaces[activeTab].push(count[entry]["type"]); } } array.sort(function(a, b) { return events[b[3]] + events[a[3]]; }); } appendMap(array, false, false, count); }); } function asyncRequestNetwork(id, ids) { return sendRequestPromise(ids, "asyncNetworkData", "sendQuery", activeTab) .then(function(res) { for(var key in res.resultArray) { var keyUse = replaceSpecialCharacters(key); $("#visNetworkGraph").append('
'); $("#"+id+keyUse).append(''); appendNetwork('networkgraph'+keyUse, res.resultArray[key]); } }); } function asyncRequestSunBurst(ids, attribute, label) { $(".pieChart").append('
'); appendSunburstDummy(attribute, label); return sendRequestPromise([ids, attribute, label], "asyncLoadSunBurstData", "sendQuery", activeTab) .then(function(res) { var resultArray = res.resultArray; var headline = resultArray["headline"]; var data = resultArray["data"]; var crit = resultArray["crit"]; var typesSizes = resultArray["typesCacheSizes"]; if (activeTab === 3 && typesSizes) { var levelIndex; for (levelIndex = 1; levelIndex < typesSizes.length - 2; levelIndex++) //Index which level is the highest shown (0 world, 1 continent,...) and 0 is not set(started at 1) //...-3 because we want to show at least 2 levels. Even if they are not that suitable, use the last two { if (typesSizes[levelIndex] > 1) break; } for (var key in data) { var oldEntry = data[key]["topology"]; data[key]["topology"] = ["" + (oldEntry[levelIndex] ? oldEntry[levelIndex] : "X") + ";" + (oldEntry[levelIndex + 1] ? oldEntry[levelIndex + 1] : "X") + ";" + (oldEntry[levelIndex + 2] ? oldEntry[levelIndex + 2] : "X")]; } } appendSunburst(crit, headline, data); }); } function buildOverviewPage(resultArray) { $("#resultContent").css("display", "block"); $("#resultContent").css("width", "95%"); paginationArray = [] var ids = []; for(var i = 0; i < resultArray.length; i++) { ids.push(resultArray[i].F41); } if(activeTab === 0) { $("#resultContent").append("
"); $("#visMap").append('
'); $("#mapContainer").append('
'); appendMapDummy(["dummy"], false); asyncRequestMap(ids); $("#visTimeLine").append('
'); makeTimelineDummy([], "timeline"); asyncRequestTimeLine(ids); asyncRequestNetwork("networkgraphwrapper", ids); asyncRequestSunBurst(ids, "gender", "Geschlecht"); asyncRequestSunBurst(ids, "mj", "Musikalische Tätigkeiten"); asyncRequestSunBurst(ids, "oj", "Nichtmusikalische Tätigkeiten"); asyncRequestSunBurst(ids, "spa", "Träger/Sparten"); asyncRequestSunBurst(ids, "kon", "Konfessionen"); asyncRequestSunBurst(ids, "name", "Nachnamen"); asyncRequestSunBurst(ids, "preName", "Vornamen"); asyncRequestSunBurst(ids, "hj", "Zeitgenössische Angaben"); asyncRequestSunBurst(ids, "institution", "Institutionen"); asyncRequestSunBurst(ids, "nation", "Nationalitäten"); } else if (activeTab === 1) { $("#visMap").append('
'); $("#mapContainer").append('
'); appendMapDummy(["dummy"], false); asyncRequestMap(ids); asyncRequestSunBurst(ids, "mjC", "Musikalische Einteilungen"); asyncRequestSunBurst(ids, "ojC", "Weitere Einteilungen"); } else if (activeTab === 2) { $("#visTimeLine").append('
'); makeTimelineDummy([], "timeline"); $("#resultContent").append("
"); $("#visMap").append('
'); $("#mapContainer").append('
'); appendMapDummy(["dummy"], false); sendRequestPromise(ids, "count", "sendQuery", activeTab) .then(function(res) { asyncRequestTimeLine(ids, res.resultArray); asyncRequestMap(ids, res.resultArray); asyncRequestSunBurst(ids, "names", "Bezeichnungen"); asyncRequestSunBurst(ids, "types", "Arten"); asyncRequestSunBurst(ids, "category", "Werkformen"); }); } else if (activeTab === 3) { $("#visMap").append('
'); $("#mapContainer").append('
'); appendMapDummy(["dummy"], false); asyncRequestMap(ids); asyncRequestSunBurst(ids, "topology", "Topologie"); asyncRequestSunBurst(ids, "types", "Ortsart"); } else if (activeTab === 5) { $("#visTimeLine").append('
'); makeTimelineDummy([], "timeline"); var customResultArray = [] for (var entry in resultArray) { customResultArray.push({ "key": resultArray[entry]["Art"], "mXp-ID": resultArray[entry]["F41"] }) } $("#resultContent").append("
"); $("#visMap").append('
'); $("#mapContainer").append('
'); appendMapDummy(["dummy"], false); sendRequestPromise(ids, "count", "sendQuery", activeTab) .then(function(res) { asyncRequestTimeLine(ids, res.resultArray, customResultArray); asyncRequestMap(ids, res.resultArray); asyncRequestSunBurst(ids, "types", "Ereignistypen"); }); } else if(activeTab === 6) { var names = []; for(var i = 0; i < resultArray.length; i++) { names.push(resultArray[i].F41); } asyncRequestSunBurst(names, "numberOfObjects", "Anzahl an Objekten"); } else if(activeTab === 7) { asyncRequestSunBurst(ids, "format", "Medienformat"); asyncRequestSunBurst(ids, "types", "Metadaten"); } } function clearAndBuildResultList(searchParams, iresultArray) { var resultListDom = $("#resultList"); resultListDom.empty(); var resultListDomCopy = resultListDom.clone(); resultListDomCopy.empty(); $("#resultList").scrollTop(0); $("#numberOfResults").html(iresultArray.length + ' Treffer'); for (var result in iresultArray) { var $resultEntry = createResultListEntry(result, searchParams, iresultArray); resultListDomCopy.append($resultEntry); } resultListDom.replaceWith(resultListDomCopy); setSizeOfSearchAndResult(); var maxStringLength = Math.max(...$("#resultList").find(".resultListEntryID").map(function() { return $(this).text().length; }).get()); $("#resultList").find(".resultListEntryID").css("width", maxStringLength + 1 + "ch"); $("#resultList").on("keyup", function(event) { if (event.keyCode == 38) { if ($(event.target)[0].previousSibling !== null) { stopRunningRequests(); var selectedId = $($(event.target)[0].previousSibling).attr("key"); var url = buildSelectedURLPath(searchParams, activeTab, selectedId) // in this case we set the url before the page loaded, so that we get all history entries // if a user clicks on results in fast succesion, not just the ones which were fully loaded setURL(new URL(url, window.location.href)); buildDetailContent(searchParams, activeTab, selectedId) .then(function(url) {}); event.preventDefault(); $(event.target)[0].previousSibling.focus(); } } if (event.keyCode == 40) { if ($(event.target)[0].nextSibling !== null) { stopRunningRequests(); var selectedId = $($(event.target)[0].nextSibling).attr("key"); var url = buildSelectedURLPath(searchParams, activeTab, selectedId) // in this case we set the url before the page loaded, so that we get all history entries // if a user clicks on results in fast succesion, not just the ones which were fully loaded setURL(new URL(url, window.location.href)); buildDetailContent(searchParams, activeTab, selectedId) .then(function(url) {}); event.preventDefault(); $(event.target)[0].nextSibling.focus(); } } }); var maxIdWidth = Math.max(...$("#resultList").find(".resultListEntryID").map(function() { return parseInt($(this).css("width").replace("px", "")); }).get()); var maxIdMargin = 2 * Math.max(...$("#resultList").find(".resultListEntryID").map(function() { return parseInt($(this).css("margin-right").replace("px", "")); }).get()); $("#resultListHeaderID").css("width", maxIdWidth + maxIdMargin + "px"); } function createResultListEntry(result, searchParams, results) { result = Number(result); var selectedId = results[result]["id"]; var linkUrl = buildSelectedURLPath(searchParams, activeTab, selectedId); // here we do not generate an internalink with the data-link-internal property, as we do not want the click behaviour to be overwritten by the router // instead we define a separate click handler below /* var $resultEntry = $("
\
" + selectedId +"
\
" + results[result][resultOutputArray[activeTab]] + "
\
");*/ var $resultEntry = $("
\
" + selectedId + "
\ " + results[result][resultOutputArray[activeTab]] + " \
"); $resultEntry.on("click", function(e) { // before we do any new requests we stop all pending ones // -> see sendRequest.js // This is not safe, however and still can cause problems (in the future) // E.g: // A user starts some internal routing through resolveURL, // this process has build only half a page (not interesting here ist the detailContent which will be deleted anyway in this handler) // If in this intermediate state the user clicks on this link, we might get a corrupt result // However at the moment this can not happen, as a search is the only possibility for this, and it will clear the resultlist // after the initial request is sent. stopRunningRequests(); var selectedId = $(this).attr("key"); var url = buildSelectedURLPath(searchParams, activeTab, selectedId) // in this case we set the url before the page loaded, so that we get all history entries // if a user clicks on results in fast succesion, not just the ones which were fully loaded setURL(new URL(url, window.location.href)); buildDetailContent(searchParams, activeTab, selectedId) .then(function(url) {}); e.preventDefault(); }); $resultEntry.on("mouseover", function() { if (activeTab === 0) { $("#path" + this.attributes.key.nodeValue).attr({ "stroke-width": 4, "stroke-opacity": 0.6 }); } else { $(".newPath" + this.attributes.key.nodeValue).attr({ "stroke-width": 4, "stroke-opacity": 0.6 }); } highlightMap(this.attributes.key.nodeValue); highlightSunBurst(this.attributes.key.nodeValue); highlightNetworkGraph(this.attributes.key.nodeValue, null); }); $resultEntry.on("mouseout", function() { if (activeTab === 0) { $("#path" + this.attributes.key.nodeValue).attr({ "stroke-width": 0.5, "stroke-opacity": 1 }); } else { $(".newPath" + this.attributes.key.nodeValue).attr({ "stroke-width": 1, "stroke-opacity": 1 }); } highlightMap(null); highlightSunBurst(null); highlightNetworkGraph(null, null); }); return $resultEntry; } function buildDetailContent(searchParams, activeTab, selectedId) { $(".resultListEntry").removeClass("highlight"); $("div[key='" + selectedId + "']").addClass("highlight"); $("#resultContent").empty().append("


"); $(".loader").css("border-top-color", thisTabColor); $(".loadingMoreAsync").css("border", "none"); $("body").css("cursor", "progress"); return sendRequestPromise(selectedId, requestCommandResult[activeTab], "sendQuery", activeTab) .then(function(res) { $("body").css("cursor", "default"); switch (activeTab) { case 0: result_Sub_person(res.resultArray); break; case 1: result_Sub_casae(res.resultArray); break; case 2: result_Sub_baccae(res.resultArray); break; case 3: result_Sub_loci(res.resultArray); break; case 4: result_Sub_syllabus(res.resultArray); break; case 5: result_Sub_eventa(res.resultArray); break; case 6: result_Sub_res(res.resultArray); break; case 7: result_Sub_catalogus(res.resultArray); break; default: console.log("ERROR. tab not available: " + activeTab); } setTabFontColor(); setWidthOfIdLabels(); return buildSelectedURLPath(searchParams, activeTab, selectedId); }); } function setWidthOfIdLabels() { $("#resultContent").find("ul").each(function() { var maxStringLength = Math.max(...$(this).find(".resultListEntryID").map(function() { return $(this).text().length; }).get()); if (parseInt(maxStringLength)) { maxStringLength = parseInt(maxStringLength) + 1; $(this).find(".resultListEntryID").css("width", maxStringLength + "ch"); $(this).find(".resultListEntryID").css("margin-right", "6px"); } }); }