Skip to content

Commit

Permalink
v3.2.3 dist
Browse files Browse the repository at this point in the history
  • Loading branch information
RobWunderlich committed Nov 23, 2017
1 parent c134375 commit 7a8b69f
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 179 deletions.
Binary file removed dist/DevTool.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/devtool-context-menu.html
@@ -1,4 +1,4 @@
<ul id="devtool-context-menu">
<ul id="devtool-context-menu" class="devtool-context-menu">
<li>Script
<ul>
<li data-devtool-command="ExportScript">Export</li>
Expand Down
2 changes: 1 addition & 1 deletion dist/devtool.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

345 changes: 170 additions & 175 deletions dist/devtool.js
@@ -1,6 +1,3 @@
var engineApp;
var modalsInitialized = false;

define(["qlik",
"./lib/download", // download.js module
"text!./devtool-context-menu.html",
Expand All @@ -14,9 +11,10 @@ define(["qlik",
/**
* @owner Erik Wetterberg (ewg)
*/
function (qlik, download, devtoolContextMenu) {
function (qlik, download, devtoolHtml) {
$('<link href="https://fonts.googleapis.com/icon?family=Material+Icons"rel="stylesheet">').appendTo("head");
engineApp = qlik.currApp(this).model.engineApp;
var modalsInitialized = false;
var engineApp = qlik.currApp(this).model.engineApp;

function toggleId() {
var cnt = $(".devtool-tooltip").remove();
Expand Down Expand Up @@ -62,6 +60,171 @@ define(["qlik",
});
}
}
// Initialize the modal windows
function initModals(qlik, download, devtoolHtml) {
// Remove existing elements
$(".devtool-context-menu").remove();
$(".devtool-properties").remove();
// Add modals to the DOM
$('body').append(devtoolHtml);

// Command router
$("[data-devtool-command]").click(function(event) {
var command = $(event.currentTarget).data("devtool-command");
switch (command) {
case "Copy":
copyToClipboard($('.devtool-properties-content')[0]);
break;
case "ExportScript":
exportScript(qlik, download);
break;
case "ImportScript":
importScript(qlik);
break;
case "ExportVariables":
exportVariables(qlik, download, $(event.target).data("devtool-filetype"));
break;
default:
console.log("unknown option " + command );
}
});
modalsInitialized = true;
}

//==== Display a status message ====
function showMsg(msg) {
$(".devtool-context-msg-content").html(msg);
$('.devtool-context-msg').modal({
showClose: false
});
}

//==== Copy-to-Clipboard function ====
function copyToClipboard(elem) {
if (! window.getSelection().toString()) { // If no user selection, then select everything
var range = document.createRange();
range.selectNodeContents(elem);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
document.execCommand("Copy");
window.getSelection().removeAllRanges();
}

//==== Script Export function ====
function exportScript(qlik, download) {
var filename = qlik.currApp(this).model.layout.qTitle + "-script.txt";
engineApp.getScript().then(function (reply) {
var data = 'data:text/plain;charset=utf-8,' + encodeURIComponent(reply.qScript);
download(data, filename, "text/plain"); // Download in the browser
showMsg("Script exported to " + filename);
});
}

//==== Script Import function ====
function importScript(qlik) {
$("#devtool-input-file").remove();
$('body').append('<input type="file" id="devtool-input-file" style="display:none;">');
$("#devtool-input-file").change(function(){
var input = $("#devtool-input-file")[0];
if (input.files.length > 0) {
var file = input.files[0];
var reader = new FileReader();
reader.onload = function(){ // Callback for read complete
// Ask user to confirm script replace
var r = confirm("Confirm replace of application script with " + file.name + "? The *entire* script will be replaced.");
if (r == true) {
engineApp.setScript(reader.result); // Replace the script in the app
showMsg("Script replaced from " + file.name);
} else {
showMsg("Script replace cancelled");
}
};
reader.readAsText(file); // Read the file contents, onload() will fire when done
} else {
showMsg("No file selected");
}
$("#devtool-input-file").remove();
});
$("#devtool-input-file").click();
}

//==== Variables Export function ====
function exportVariables(qlik, download, filetype) {
if(filetype == "script") {
var str="";
var lastSort="";
getVariables(engineApp).then(function(vars){
vars.map(function(v){
v.devtoolSortGroup = (v.qIsReserved ? '11' : v.qIsScriptCreated ? '21' : '22');
return v;
}).sort(function(a,b){
var av = a.devtoolSortGroup + a.qName;
var bv = b.devtoolSortGroup + b.qName;
return av == bv ? 0 : av < bv ? -1 : 1;
}).forEach(function(v) {
if(v.devtoolSortGroup != lastSort) {
switch (v.devtoolSortGroup) {
case "11":
str += "// ***** Reserved Variables *****\r\n";
break;
case "21":
str += "// ***** Script Defined Variables ***** \r\n";
break;
case "22":
str += "// ***** Non-script Defined Variables ***** \r\n";
break;
default:
break;
}
}
lastSort = v.devtoolSortGroup;
var comment = v.qComment != undefined ? "// " + v.qComment : "";
str += "SET " + v.qName + "='" + v.qDefinition + "';" + comment + "\r\n";
});

var filename = qlik.currApp(this).model.layout.qTitle + "-variables.txt";
var data = 'data:text/plain;charset=utf-8,' + encodeURIComponent(str);
download(data, filename, "text/plain"); // Download in the browser
showMsg("Variables exported to " + filename);
});
}
else {
var str="";
getVariables(engineApp).then(function(vars){
var filename = qlik.currApp(this).model.layout.qTitle + "-variables.json";
var data = 'data:application/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(vars, null, 2));
download(data, filename, "application/json"); // Download in the browser
showMsg("Variables exported to " + filename);
});
}
}

//===== Get all variables in app ====
function getVariables(app) {
return app.createSessionObject({
qVariableListDef: {
qType: 'variable',
qShowReserved: true,
qShowConfig: true,
qMeta: {}
},
qInfo: { qId: "VariableList", qType: "VariableList" }
}).then(function (list) {
return list.getLayout().then(function (layout) {
return Promise.all(layout.qVariableList.qItems.map(function (d) {
return app.getVariableById(d.qInfo.qId).then(function (variable) {
return variable.getProperties().then(function(properties) {
if (d.qIsScriptCreated) properties.qIsScriptCreated = d.qIsScriptCreated;
if (d.qIsReserved) properties.qIsReserved = d.qIsReserved;
if (d.qIsConfig) properties.qIsConfig = d.qIsConfig;
return properties;
});
});
}));
});
});
}

return {
initialProperties: {
Expand All @@ -72,180 +235,12 @@ define(["qlik",
$(document.body).append("<button class='devtool-btn fab'><i class='material-icons'>settings</i></button>");
$(".devtool-btn.fab").on("click", toggleId);
if (!modalsInitialized) {
initModals(qlik, download, devtoolContextMenu)
initModals(qlik, download, devtoolHtml)
}
$(".devtool-btn.fab").contextMenu('menu', $('#devtool-context-menu'), {
'triggerOn' : "contextmenu",
'displayAround' : 'trigger'
});
}
};
});


// Initialize the modal windows
function initModals(qlik, download, devtoolContextMenu) {
// Remove existing elements
$(".devtool-context-menu").remove();
$(".devtool-properties").remove();
// Add modals to the DOM
$('body').append(devtoolContextMenu);

// Command router
$("[data-devtool-command]").click(function(event) {
var command = $(event.currentTarget).data("devtool-command");
switch (command) {
case "Copy":
copyToClipboard($('.devtool-properties-content')[0]);
break;
case "ExportScript":
exportScript(qlik, download);
break;
case "ImportScript":
importScript(qlik);
break;
case "ExportVariables":
exportVariables(qlik, download, $(event.target).data("devtool-filetype"));
break;
default:
console.log("unknown option " + command );
}
});
modalsInitialized = true;
}

function showMsg(msg) {
$(".devtool-context-msg-content").html(msg);
$('.devtool-context-msg').modal({
showClose: false
});
}

//==== Copy-to-Clipboard function ====
function copyToClipboard(elem) {
if (! window.getSelection().toString()) { // If no user selection, then select everything
var range = document.createRange();
range.selectNodeContents(elem);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
document.execCommand("Copy");
window.getSelection().removeAllRanges();
}

//==== Script Export function ====
function exportScript(qlik, download) {
var filename = qlik.currApp(this).model.layout.qTitle + "-script.txt";
engineApp.getScript().then(function (reply) {
var data = 'data:text/plain;charset=utf-8,' + encodeURIComponent(reply.qScript);
download(data, filename, "text/plain"); // Download in the browser
showMsg("Script exported to " + filename);
});
}

//==== Script Import function ====
function importScript(qlik) {
$("#devtool-input-file").remove();
$('body').append('<input type="file" id="devtool-input-file" style="display:none;">');
$("#devtool-input-file").change(function(){
var input = $("#devtool-input-file")[0];
if (input.files.length > 0) {
var file = input.files[0];
var reader = new FileReader();
reader.onload = function(){ // Callback for read complete
// Ask user to confirm script replace
var r = confirm("Confirm replace of application script with " + file.name + "? The *entire* script will be replaced.");
if (r == true) {
engineApp.setScript(reader.result); // Replace the script in the app
showMsg("Script replaced from " + file.name);
} else {
showMsg("Script replace cancelled");
}
};
reader.readAsText(file); // Read the file contents, onload() will fire when done
} else {
showMsg("No file selected");
}
$("#devtool-input-file").remove();
});
showMsg("No file selected");
$("#devtool-input-file").click();

}

//==== Variables Export function ====
function exportVariables(qlik, download, filetype) {
if(filetype == "script") {
var str="";
var lastSort="";
getVariables(engineApp).then(function(vars){
vars.map(function(v){
v.devtoolSortGroup = (v.qIsReserved ? '11' : v.qIsScriptCreated ? '21' : '22');
return v;
}).sort(function(a,b){
var av = a.devtoolSortGroup + a.qName;
var bv = b.devtoolSortGroup + b.qName;
return av == bv ? 0 : av < bv ? -1 : 1;
}).forEach(function(v) {
if(v.devtoolSortGroup != lastSort) {
switch (v.devtoolSortGroup) {
case "11":
str += "// ***** Reserved Variables *****\r\n";
break;
case "21":
str += "// ***** Script Defined Variables ***** \r\n";
break;
case "22":
str += "// ***** Non-script Defined Variables ***** \r\n";
break;
default:
break;
}
}
lastSort = v.devtoolSortGroup;
var comment = v.qComment != undefined ? "// " + v.qComment : "";
str += "SET " + v.qName + "='" + v.qDefinition + "';" + comment + "\r\n";
});

var filename = qlik.currApp(this).model.layout.qTitle + "-variables.txt";
var data = 'data:text/plain;charset=utf-8,' + encodeURIComponent(str);
download(data, filename, "text/plain"); // Download in the browser
showMsg("Variables exported to " + filename);
});
}
else {
var str="";
getVariables(engineApp).then(function(vars){
var filename = qlik.currApp(this).model.layout.qTitle + "-variables.json";
var data = 'data:application/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(vars, null, 2));
download(data, filename, "application/json"); // Download in the browser
showMsg("Variables exported to " + filename);
});
}
}

//===== Get all variables in app ====
function getVariables(app) {
return app.createSessionObject({
qVariableListDef: {
qType: 'variable',
qShowReserved: true,
qShowConfig: true,
qMeta: {}
},
qInfo: { qId: "VariableList", qType: "VariableList" }
}).then(function (list) {
return list.getLayout().then(function (layout) {
return Promise.all(layout.qVariableList.qItems.map(function (d) {
return app.getVariableById(d.qInfo.qId).then(function (variable) {
return variable.getProperties().then(function(properties) {
if (d.qIsScriptCreated) properties.qIsScriptCreated = d.qIsScriptCreated;
if (d.qIsReserved) properties.qIsReserved = d.qIsReserved;
if (d.qIsConfig) properties.qIsConfig = d.qIsConfig;
return properties;
});
});
}));
});
});
}
});
2 changes: 1 addition & 1 deletion dist/devtool.qext
@@ -1,7 +1,7 @@
{
"name": "DevTool",
"description": "Developer Tool extension",
"version": "3.2.2",
"version": "3.2.3",
"type": "visualization",
"author": "Erik Wetterberg",
"icon": "cogwheel"
Expand Down

0 comments on commit 7a8b69f

Please sign in to comment.