From 97d53df3be7c789ac98dc7224a1270f14ed60fb7 Mon Sep 17 00:00:00 2001 From: Josep Llort Date: Sat, 29 Oct 2016 20:01:19 +0200 Subject: [PATCH 1/2] Make compatible with older ws 1.0 --- js/options.js | 6 +++++- js/popup.js | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/js/options.js b/js/options.js index e9898cb..4da88e3 100644 --- a/js/options.js +++ b/js/options.js @@ -40,7 +40,7 @@ function checkConnection(url, userName, password) { var requestUrl = url + "services/rest/repository/getAppVersion"; var xhr = new XMLHttpRequest(); xhr.open("GET", requestUrl, false); - //xhr.setRequestHeader("Authorization", "Basic " + btoa("okmAdmin" + ":" + "OpenKMi3visio15?")); + xhr.setRequestHeader("Authorization", "Basic " + btoa(userName + ":" + password)); xhr.setRequestHeader("Accept", "application/json; indent=4"); @@ -50,6 +50,10 @@ function checkConnection(url, userName, password) { if ((status >= 200 && status < 300) || status === 304) { var ver = JSON.parse(xhr.responseText); + // workaround for older ws version what shows root variable + if (typeof ver.appVersion !== 'undefined') { + ver = ver.appVersion; + } var okmVersion = "OpenKM version " + ver.major + "." + ver.minor + "." + ver.maintenance + " " + ver.extension + " build:" + ver.build; document.getElementById('optMessage').innerHTML = "
" + "Connected to " + okmVersion + "
"; console.log("Connected to " + okmVersion); diff --git a/js/popup.js b/js/popup.js index 7e9605e..34b24ad 100644 --- a/js/popup.js +++ b/js/popup.js @@ -45,6 +45,10 @@ function getFileIconCode (mimeType) { function generateHtmlResultsWS1(jsonDict, baseUrl) { // Grabbing the results var results = jsonDict["queryResult"]; + // workaround for older ws version what shows root variable + if (typeof jsonDict["queryResults"] !== 'undefined') { + results = jsonDict["queryResults"]["queryResult"] + } var html = "
"; html += "
Resultados: " + results.length.toString() + "
"; From 43aaebf94018d528f705073fa4dbca8013b095ee Mon Sep 17 00:00:00 2001 From: Josep Llort Date: Sat, 29 Oct 2016 20:58:21 +0200 Subject: [PATCH 2/2] solves issue when results are empty or equals to 1 --- js/popup.js | 108 +++++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/js/popup.js b/js/popup.js index 34b24ad..93442a2 100644 --- a/js/popup.js +++ b/js/popup.js @@ -47,42 +47,33 @@ function generateHtmlResultsWS1(jsonDict, baseUrl) { var results = jsonDict["queryResult"]; // workaround for older ws version what shows root variable if (typeof jsonDict["queryResults"] !== 'undefined') { - results = jsonDict["queryResults"]["queryResult"] + results = jsonDict["queryResults"]["queryResult"]; + } + + // Check case results <=1 ( in case 0,1 results.length is undefined, and in case 0 result is undefined ) + var length = 0; + if (typeof results !== 'undefined' && typeof results.length !== 'undefined') { + length = results.length; + } else if (typeof results !== 'undefined') { + length = 1; } var html = "
"; - html += "
Resultados: " + results.length.toString() + "
"; + html += "
Resultados: " + length + "
"; html += "
"; html += "
"; //Body html += '
'; - - for (var k = 0; k < results.length; k++) { - var res = results[k]; - - var newRow = ""; - // Setting the file name and the Download link - newRow += "" + getFileIconCode (res["document"]["mimeType"] ) + " " + res["document"]["path"].substring(res["document"]["path"].lastIndexOf('/')+1)+ ""; - newRow += "Date: " + res["document"]["actualVersion"]["created"].toString()+ "

"; - - // Adding the excerpt if it exists - try { - if (res["excerpt"].toString() == "undefined") { - newRow += "[N/F]"; - } - else { - newRow += "[...] " +res["excerpt"] + "[...]"; - } - } - catch (e) { - newRow += "--"; + + if (length>1) { + for (var k = 0; k < length; k++) { + var res = results[k]; + html += generateRowWS(res, "document", baseUrl); } - - newRow+="

"; - - html += newRow; - } + } else if (length==1) { + html += generateRowWS(results, "document", baseUrl); + } // Closing the results html += "
"; @@ -96,10 +87,18 @@ function generateHtmlResultsWS1(jsonDict, baseUrl) { function generateHtmlResultsWS2(jsonDict, baseUrl) { // Grabbing the results var results = jsonDict["queryResult"]; + + // Check case results <=1 ( in case 0,1 results.length is undefined, and in case 0 result is undefined ) + var length = 0; + if (typeof results !== 'undefined' && typeof results.length !== 'undefined') { + length = results.length; + } else if (typeof results !== 'undefined') { + length = 1; + } var html = "
"; - html += "
Resultados: " + results.length.toString()+ "
"; + html += "
Resultados: " + length+ "
"; html += "

"; html += "
"; @@ -107,31 +106,14 @@ function generateHtmlResultsWS2(jsonDict, baseUrl) { //Body html += '
'; - for (var k = 0; k < results.length; k++) { - var res = results[k]; - - var newRow = ""; - // Setting the file name and the Download link - newRow += "" + getFileIconCode (res["node"]["mimeType"] ) + " " + res["node"]["path"].substring(res["node"]["path"].lastIndexOf('/')+1)+ ""; - newRow += "Date: " + res["node"]["actualVersion"]["created"].toString()+ "

"; - - // Adding the excerpt if it exists - try { - if (res["excerpt"].toString() == "undefined") { - newRow += "[N/F]"; - } - else { - newRow += "[...] " +res["excerpt"] + "[...]"; - } - } - catch (e) { - newRow += "--"; + if (length>1) { + for (var k = 0; k < length; k++) { + var res = results[k]; + html += generateRowWS(res, "node", baseUrl); } - - newRow+="

"; - - html += newRow; - } + } else if (length==1) { + html += generateRowWS(results, "node", baseUrl); + } // Closing the results html += "
"; @@ -142,6 +124,28 @@ function generateHtmlResultsWS2(jsonDict, baseUrl) { return html; } +function generateRowWS(res, rootNodeName, baseUrl) { + var newRow = ""; + // Setting the file name and the Download link + newRow += "" + getFileIconCode(res[rootNodeName]["mimeType"]) + " " + res[rootNodeName]["path"].substring(res[rootNodeName]["path"].lastIndexOf('/')+1)+ ""; + newRow += "Date: " + res[rootNodeName]["actualVersion"]["created"].toString()+ "

"; + + // Adding the excerpt if it exists + try { + if (res["excerpt"].toString() == "undefined") { + newRow += "[N/F]"; + } + else { + newRow += "[...] " +res["excerpt"] + "[...]"; + } + } + catch (e) { + newRow += "--"; + } + + newRow+="

"; + return newRow; +} // Executing the Query towards OpenKM function runQuery() {