Skip to content

Commit

Permalink
Merge pull request #4 from darkman97i/issueWS1.0
Browse files Browse the repository at this point in the history
Issue ws1.0
  • Loading branch information
darkman97i authored Oct 29, 2016
2 parents 722e274 + 43aaebf commit 16084a7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 52 deletions.
6 changes: 5 additions & 1 deletion js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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 = "<div class='notice success'><i class='icon-ok icon-large'></i> " + "Connected to " + okmVersion + "<a href='#close' class='icon-remove'></a></div>";
console.log("Connected to " + okmVersion);
Expand Down
110 changes: 59 additions & 51 deletions js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,40 +45,35 @@ 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"];
}

// 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 = "<div class='callout callout-top clearfix'>";
html += "<h6><i class='fa fa-list-alt fa-lg'></i> Resultados: " + results.length.toString() + "</h6>";
html += "<h6><i class='fa fa-list-alt fa-lg'></i> Resultados: " + length + "</h6>";
html += "<table class='tight' cellspacing='0' cellpadding='0'><br>";
html += "<thead></thead><br>";

//Body
html += '<tbody><br>';

for (var k = 0; k < results.length; k++) {
var res = results[k];

var newRow = "<tr class='result'>";
// Setting the file name and the Download link
newRow += "<docname>" + getFileIconCode (res["document"]["mimeType"] ) + " <a target='_blank' href='" + baseUrl + "Download?uuid=" + res["document"]["uuid"] + "'>" + res["document"]["path"].substring(res["document"]["path"].lastIndexOf('/')+1)+ "</a></docname>";
newRow += "<date>Date: " + res["document"]["actualVersion"]["created"].toString()+ "</date><br><br>";

// Adding the excerpt if it exists
try {
if (res["excerpt"].toString() == "undefined") {
newRow += "<i>[N/F]</i>";
}
else {
newRow += "<i class='fa fa-quote-left'></i><excerpt>[...] " +res["excerpt"] + "[...]</excerpt><i class='fa fa-quote-right'></i>";
}
}
catch (e) {
newRow += "<i>--</i>";

if (length>1) {
for (var k = 0; k < length; k++) {
var res = results[k];
html += generateRowWS(res, "document", baseUrl);
}

newRow+="</tr><hr><br>";

html += newRow;
}
} else if (length==1) {
html += generateRowWS(results, "document", baseUrl);
}

// Closing the results
html += "</tbody><br>";
Expand All @@ -92,42 +87,33 @@ 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 = "<div class='callout callout-top clearfix'>";

html += "<h6><i class='fa fa-list-alt fa-lg'></i> Resultados: " + results.length.toString()+ "</h6>";
html += "<h6><i class='fa fa-list-alt fa-lg'></i> Resultados: " + length+ "</h6>";

html += "<table class='tight' cellspacing='0' cellpadding='0'><br>";
html += "<thead></thead><br>";

//Body
html += '<tbody><br>';

for (var k = 0; k < results.length; k++) {
var res = results[k];

var newRow = "<tr class='result'>";
// Setting the file name and the Download link
newRow += "<docname>" + getFileIconCode (res["node"]["mimeType"] ) + " <a target='_blank' href='" + baseUrl + "Download?uuid=" + res["node"]["uuid"] + "'>" + res["node"]["path"].substring(res["node"]["path"].lastIndexOf('/')+1)+ "</a></docname>";
newRow += "<date>Date: " + res["node"]["actualVersion"]["created"].toString()+ "</date><br><br>";

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

newRow+="</tr><hr><br>";

html += newRow;
}
} else if (length==1) {
html += generateRowWS(results, "node", baseUrl);
}

// Closing the results
html += "</tbody><br>";
Expand All @@ -138,6 +124,28 @@ function generateHtmlResultsWS2(jsonDict, baseUrl) {
return html;
}

function generateRowWS(res, rootNodeName, baseUrl) {
var newRow = "<tr class='result'>";
// Setting the file name and the Download link
newRow += "<docname>" + getFileIconCode(res[rootNodeName]["mimeType"]) + " <a target='_blank' href='" + baseUrl + "Download?uuid=" + res[rootNodeName]["uuid"] + "'>" + res[rootNodeName]["path"].substring(res[rootNodeName]["path"].lastIndexOf('/')+1)+ "</a></docname>";
newRow += "<date>Date: " + res[rootNodeName]["actualVersion"]["created"].toString()+ "</date><br><br>";

// Adding the excerpt if it exists
try {
if (res["excerpt"].toString() == "undefined") {
newRow += "<i>[N/F]</i>";
}
else {
newRow += "<i class='fa fa-quote-left'></i><excerpt>[...] " +res["excerpt"] + "[...]</excerpt><i class='fa fa-quote-right'></i>";
}
}
catch (e) {
newRow += "<i>--</i>";
}

newRow+="</tr><hr><br>";
return newRow;
}

// Executing the Query towards OpenKM
function runQuery() {
Expand Down

0 comments on commit 16084a7

Please sign in to comment.