-
Notifications
You must be signed in to change notification settings - Fork 3
/
saiku-embed.html
executable file
·388 lines (321 loc) · 9.9 KB
/
saiku-embed.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!--
Copyright 2011 - 2017 OSBI Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../polymer/polymer-element.html">
<dom-module id="saiku-embed">
<template>
<!-- Scoped CSS for this element -->
<style>
:host {
display: block;
width: 100%;
}
</style>
<div>
<!-- Any children are rendered here -->
<slot></slot>
<iframe allowtransparency="true" frameborder="0" scrolling="auto"></iframe>
</div>
</template>
<script>
/**
* `saiku-embed`
* A web component to embed Saiku Analytics.
*
* Basic example:
*
* <saiku-embed url="http://localhost:8080/" username="admin" password="admin"></saiku-embed>
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class SaikuEmbed extends Polymer.Element {
static get is() { return 'saiku-embed'; }
constructor() {
super();
this.attachShadow({
mode: 'open'
}).innerHTML = SaikuEmbed.template.innerHTML;
if (!this.url) {
this.textContent = `The url attribute is not included.
Go to https://github.com/OSBI/saiku-embed-element#saiku-embed-element
and see the documentation.`;
}
}
static get properties() {
return {
url: String,
username: String,
password: String,
width: { type: String, value: '800' },
height: { type: String, value: '600' },
schema: String,
cube: String,
default_mdx_filter: String,
default_mdx_filter_rows: String,
default_mdx_filter_columns: String,
lang: String,
mode: String,
path_file_saiku: String,
splash: { type: Boolean, value: true },
plugin: { type: Boolean, value: false },
hide_workspace_icons: { type: Boolean, value: false },
show_help: { type: Boolean, value: false }
};
}
static get observedAttributes() {
return [
'url',
'username',
'password',
'width',
'height',
'schema',
'cube',
'default_mdx_filter',
'default_mdx_filter_rows',
'default_mdx_filter_columns',
'lang',
'mode',
'path_file_saiku',
'splash',
'plugin',
'hide_workspace_icons',
'show_help'
];
}
connectedCallback() {
const iframe = this.shadowRoot.querySelector('iframe');
iframe.width = this.width;
iframe.height = this.height;
iframe.src = this.getInlineFrameSource();
}
attributeChangedCallback(attributeName, oldValue, newValue) {
const iframe = this.shadowRoot.querySelector('iframe');
switch (attributeName) {
case 'width':
case 'height':
this[attributeName] = newValue;
break;
case 'splash':
case 'plugin':
case 'hide_workspace_icons':
case 'show_help':
this[attributeName] = this._isAttributeTrueFromMarkup(newValue);
break;
default:
iframe.src = this.getInlineFrameSource();
break;
}
}
get url() {
return this.getAttribute('url');
}
set url(newValue) {
if (this.url !== newValue) {
this.setAttribute('url', newValue);
}
}
get username() {
return this.getAttribute('username');
}
set username(newValue) {
if (this.username !== newValue) {
this.setAttribute('username', newValue);
}
}
get password() {
return this.getAttribute('password');
}
set password(newValue) {
if (this.password !== newValue) {
this.setAttribute('password', newValue);
}
}
get width() {
return this.getAttribute('width');
}
set width(newValue) {
if (this.width !== newValue) {
this.setAttribute('width', newValue);
}
}
get height() {
return this.getAttribute('height');
}
set height(newValue) {
if (this.height !== newValue) {
this.setAttribute('height', newValue);
}
}
get schema() {
return this.getAttribute('schema') || '';
}
set schema(newValue) {
if (this.schema !== newValue) {
this.setAttribute('schema', newValue);
}
}
get cube() {
return this.getAttribute('cube') || '';
}
set cube(newValue) {
if (this.cube !== newValue) {
this.setAttribute('cube', newValue);
}
}
get default_mdx_filter() {
return this.getAttribute('default_mdx_filter') || '';
}
set default_mdx_filter(newValue) {
if (this.default_mdx_filter !== newValue) {
this.setAttribute('default_mdx_filter', newValue);
}
}
get default_mdx_filter_rows() {
return this.getAttribute('default_mdx_filter_rows') || '';
}
set default_mdx_filter_rows(newValue) {
if (this.default_mdx_filter_rows !== newValue) {
this.setAttribute('default_mdx_filter_rows', newValue);
}
}
get default_mdx_filter_columns() {
return this.getAttribute('default_mdx_filter_columns') || '';
}
set default_mdx_filter_columns(newValue) {
if (this.default_mdx_filter_columns !== newValue) {
this.setAttribute('default_mdx_filter_columns', newValue);
}
}
get lang() {
return this.getAttribute('lang') || '';
}
set lang(newValue) {
if (this.lang !== newValue) {
this.setAttribute('lang', newValue);
}
}
get mode() {
return this.getAttribute('mode') || '';
}
set mode(newValue) {
if (this.mode !== newValue) {
this.setAttribute('mode', newValue);
}
}
get path_file_saiku() {
return this.getAttribute('path_file_saiku') || '';
}
set path_file_saiku(newValue) {
if (this.path_file_saiku !== newValue) {
this.setAttribute('path_file_saiku', newValue);
}
}
get splash() {
return this.getAttribute('splash');
}
set splash(newValue) {
if (this.splash !== newValue.toString()) {
this.setAttribute('splash', newValue);
}
}
get plugin() {
return this.getAttribute('plugin');
}
set plugin(newValue) {
if (this.plugin !== newValue.toString()) {
this.setAttribute('plugin', newValue);
}
}
get hide_workspace_icons() {
return this.getAttribute('hide_workspace_icons');
}
set hide_workspace_icons(newValue) {
if (this.hide_workspace_icons !== newValue.toString()) {
this.setAttribute('hide_workspace_icons', newValue);
}
}
get show_help() {
return this.getAttribute('show_help');
}
set show_help(newValue) {
if (this.show_help !== newValue.toString()) {
this.setAttribute('show_help', newValue);
}
}
getInlineFrameSource() {
const params = this._getAttributesParams();
const src = this._requestUrl(this.url, params);
if (this.path_file_saiku) {
let pathFileSaiku = `#query/open/${this.path_file_saiku}`;
return window.decodeURIComponent(src + pathFileSaiku);
}
return window.decodeURIComponent(src);
}
_isAttributeTrueFromMarkup(obj) {
return obj === true ||
obj === 'true' ||
obj === '' ||
obj.length === 0 ||
toString.call(obj) === '[object Boolean]';
}
_getAttributesParams() {
let params = {};
let attrName;
for (let i = 0; i < this.attributes.length; i++) {
if (SaikuEmbed.properties.hasOwnProperty(this.attributes[i].name) &&
(this.attributes[i].name !== 'url' &&
this.attributes[i].name !== 'path_file_saiku' &&
this.attributes[i].name !== 'width' &&
this.attributes[i].name !== 'height')) {
attrName = this.attributes[i].name;
params[attrName] = this.attributes[i].value;
}
}
return params;
}
_queryString(params) {
const queryParts = [];
let param;
let value;
for (param in params) {
value = params[param];
param = window.encodeURIComponent(param);
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
queryParts.push(`${param}=${window.encodeURIComponent(value[i])}`);
}
}
else if (value !== null) {
queryParts.push(`${param}=${window.encodeURIComponent(value)}`);
}
else {
queryParts.push(param);
}
}
return queryParts.join('&');
}
_requestUrl(url, params) {
const queryString = this._queryString(params);
const newUrl = url || '';
if (queryString) {
const bindingChar = newUrl.indexOf('?') >= 0 ? '&' : '?';
return newUrl + bindingChar + queryString;
}
return newUrl;
}
}
window.customElements.define(SaikuEmbed.is, SaikuEmbed);
</script>
</dom-module>