-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.html
212 lines (195 loc) · 6.36 KB
/
convert.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html>
<head>
<title>DEMO</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script data-main="app/main" src="app/lib/require.js"></script>
<!--<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>-->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
</head>
<body ng-controller="MainCtrl">
<h1>Mashup Converter test</h1>
<table>
<tr>
<td style="width:50%;">
<fieldset>
<legend>Javascript</legend>
<textarea class="javascript" style="width:100%;height:400px;" id="the_code">
/*global require, alert*/
/*
*
*/
/*
* Fill in host and port for Qlik engine
*/
var config = {
host: window.location.hostname,
prefix: "/",
port: window.location.port,
isSecure: window.location.protocol === "https:"
};
require.config( {
baseUrl: ( config.isSecure ? "https://" : "http://" ) + config.host + (config.port ? ":" + config.port: "") + config.prefix + "resources"
} );
require( ["js/qlik"], function ( qlik ) {
qlik.setOnError(function(error) {
$("#error span").html(error.message);
$("#error").show();
$("#closeerror").on("qv-activate", function() {
$("#error").hide();
});
});
//callbacks
//open app and get objects
var app = qlik.openApp("Helpdesk Management.qvf", config);
$(".qvobject").each(function() {
app.getObject(this, $(this).data("qvid"));
});
$( ".qsnapshot" ).each( function () {
app.getSnapshot( this, $( this ).data( "qvid" ) );
} );
/*AUTOGEN START*/
/*AUTOGEN END*/
} );
</textarea>
</fieldset>
</td>
<td style="width:50%;">
<fieldset>
<legend>HTML</legend>
<textarea id="the_html_code" class="javascript" style="width:100%;height:400px;">
<!doctype html>
<html><head>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Helpdesk Grid</title>
<!--Add host to these 3 links if the mashup is on another webserver than qlikview static content-->
<link rel="stylesheet" href="/resources/assets/client/client.css" media="all">
<link rel="stylesheet" href="/resources/autogenerated/qlikui.css">
<script src="/resources/assets/external/requirejs/require.js"></script>
<script src="helpdesk-grid.js"></script>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Custom styles for this template -->
<link href="helpdesk-grid.css" rel="stylesheet">
</head>
<body style="overflow:auto">
<div class="container">
<div class="page-header">
<h1>Helpdesk Grid</h1>
</div>
<div class="alert alert-danger" id="error" style="display:none;position:relative;">
<span></span>
<button type="button" class="btn btn-sm btn-default" id="closeerror" style="position:absolute;right:10px;top:10px;">
OK
</button>
</div>
<div class="row">
<div class="col-md-8">
<div id="QV00" class="qvobject" style="width:100%;height:40px;" data-qvid="CurrentSelections"></div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div id="QV01" class="qvobject" style="width:100%;height:200px;" data-qvid="hRZaKk"></div>
</div>
<div class="col-md-4">
<div id="QV02" class="qvobject" style="width:100%;height:200px;" data-qvid="55fecfc8-6460-4e63-9f32-cb8e8bd52438"></div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div id="QV03" class="qvobject" style="width:100%;height:200px;" data-qvid="a5e0f12c-38f5-4da9-8f3f-0e4566b28398"></div>
</div>
<div class="col-md-4">
<div id="QV04" class="qvobject" style="width:100%;height:200px;" data-qvid="PAppmU"></div>
</div>
</div>
<div class="row">
<div class="col-md-8">
<div id="QV05" class="qvobject" style="width:100%;height:200px;" data-qvid="rJFbvG"></div>
</div>
</div>
</div>
</body></html>
</textarea>
</fieldset>
</td>
</tr>
<tr>
<td>
<fieldset>
<legend>The result js</legend>
<pre>
<code id="the_js_res" class="js" style="height:400px;">
</code>
</pre>
</fieldset>
</td>
<td>
<fieldset>
<legend>The result html</legend>
<textarea id="the_html_res" class="html" style="width:100%;height:480px;">
</textarea>
</fieldset>
</td>
</tr>
</table>
<script type="text/javascript">
var convertOldJsMashup = function ( stringJS, stringHTML ) {
//utils
var extractJqueryLoops = function(stringJs){
var resString = stringJs;
var jqueryLoops = [];
function extract(){
var regExp = /\$\(\s*("|')\.(qvobject|qsnapshot)("|')\s*\)\.each\([\S\s]*\)/g;
var res = resString.match(regExp);
if(res){
var counter = 0;
var start = res[0].indexOf('(',res[0].indexOf('each'));
for( var i=start; i < res[0].length; i++){
console.log(counter);
if ( res[0][i] === '(' ) { counter++; }
if ( res[0][i] === ')' ) { counter--; }
if ( counter === 0 ) {
jqueryLoops.push(res[0].slice(0,i));
resString = resString.replace( res[0].slice( 0, i ), '' );
console.log(resString, jqueryLoops); return true;
}
if(extract()){
return true;
}
return false;
}
}else{ return true;}
}
extract();
return jqueryLoops;
};
//step 1 remove /*AUTOGEN...*/ comments
var regExp = /(\/\*AUTOGEN (START|END)\*\/)/g;
stringJS = stringJS.replace( regExp, '' );
//step 2 change
regExp = /(\/\/open app and get objects)/g;
stringJS = stringJS.replace( regExp, '//open apps' );
//find jqueryloops
console.log(extractJqueryLoops(stringJS));
return {
JS: stringJS,
HTML: stringHTML
}
};
var js = document.getElementById( 'the_code' ).value;
var html = document.getElementById( 'the_html_code' ).value;
var res = convertOldJsMashup( js, html );
document.getElementById( 'the_js_res' ).innerHTML = res.JS;
document.getElementById( 'the_html_res' ).innerHTML = res.HTML;
hljs.initHighlightingOnLoad();
</script>
</body>
</html>