Skip to content

Commit ccad575

Browse files
building Cache xml
1 parent e755df8 commit ccad575

File tree

5 files changed

+204
-7
lines changed

5 files changed

+204
-7
lines changed

example/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
<a onclick="rSoon(this)">7</a>,
3737
<a onclick="rSoon(this)">8</a>,
3838
<a onclick="rSoon(this)">9</a>,
39-
<a onclick="rSoon(this)">10</a>
39+
<a onclick="rSoon(this)">10</a>,
40+
<a onclick="rSoon(this)">11</a>
4041
</div>
4142
<div id="mdx"></div>
4243
<form id="mdxForm" onsubmit="return false;">
@@ -69,6 +70,11 @@
6970
{
7071
basicMDX: "SELECT NON EMPTY [Product].[P1].[Product Category].Members ON 0,NON EMPTY [DateOfSale].[Actual].[YearSold].Members ON 1 FROM [HoleFoods]",
7172
DrillDownExpression: "NONEMPTYCROSSJOIN([Outlet].[H1].[Region].Members,[Outlet].[H1].[Country].Members)"
73+
},
74+
{
75+
basicMDX: "SELECT NON EMPTY [Outlet]" +
76+
".[H1].[Region].Members ON 0,NON EMPTY [DateOfSale].[Actual].[YearSold].Members ON 1 FROM [HoleFoods]",
77+
DrillDownExpression: "NONEMPTYCROSSJOIN([DateOfSale].[Actual].[YearSold].Members,[Product].[P1].[Product Category].Members)"
7278
}
7379
][v],
7480
setup;
@@ -106,6 +112,8 @@
106112
mdxTo.innerHTML = "<b>Basic MDX:</b> <i>" + (typeof req === "object" ? req.basicMDX : req)
107113
+ "</i>";
108114

115+
console.log(setup);
116+
109117
var lp = new LightPivotTable(setup); // create widget
110118

111119
</script>

export/LightPivotTable.xml

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="Cache" version="25">
3+
4+
<CSP name="DeepSeeLightPivotTable.css" application="">
5+
<![CDATA[{{replace:css}}]]>
6+
</CSP>
7+
8+
9+
<CSP name="DeepSeeLightPivotTable.js" application="">
10+
<![CDATA[{{replace:js}}]]>
11+
</CSP>
12+
13+
<Class name="DeepSee.LightPivotTable">
14+
<Super>%DeepSee.Component.Portlet.abstractPortlet</Super>
15+
<TimeChanged>63515,72475.367191</TimeChanged>
16+
<TimeCreated>63515,61322.546099</TimeCreated>
17+
18+
<Parameter name="INCLUDEFILES">
19+
<Default>style:DeepSeeLightPivotTable.css,script:DeepSeeLightPivotTable.js</Default>
20+
</Parameter>
21+
22+
<Method name="%OnGetPortletName">
23+
<ClassMethod>1</ClassMethod>
24+
<ReturnType>%String</ReturnType>
25+
<Implementation><![CDATA[ quit "Light pivot table"
26+
]]></Implementation>
27+
</Method>
28+
29+
<Method name="%OnGetPortletIcon">
30+
<ClassMethod>1</ClassMethod>
31+
<ReturnType>%String</ReturnType>
32+
<Implementation><![CDATA[ quit "deepsee/ds2_dialpad_44.png"
33+
]]></Implementation>
34+
</Method>
35+
36+
<Method name="%OnGetPortletSettings">
37+
<ClassMethod>1</ClassMethod>
38+
<FormalSpec>*pInfo:%List</FormalSpec>
39+
<ReturnType>%Status</ReturnType>
40+
<Implementation><![CDATA[
41+
kill pInfo // $LB(name,value,type,caption,title)
42+
43+
set pInfo($I(pInfo)) = $LB("dataSource","/SAMPLES","%String",$$$Text("MDX2JSON source","%DeepSee"),"THIS IS TITLE")
44+
45+
quit $$$OK
46+
]]></Implementation>
47+
</Method>
48+
49+
<Method name="getConnectedController">
50+
<Language>javascript</Language>
51+
<ClientMethod>1</ClientMethod>
52+
<Implementation><![CDATA[
53+
var controller = this.getController();
54+
55+
if (null === controller) {
56+
this.connectToController();
57+
controller = this.getController();
58+
}
59+
60+
return controller;
61+
]]></Implementation>
62+
</Method>
63+
64+
<Method name="onCreate">
65+
<Language>javascript</Language>
66+
<ClientMethod>1</ClientMethod>
67+
<Implementation><![CDATA[
68+
var container = document.getElementById(this.id),
69+
source,
70+
setup,
71+
_ = this,
72+
widget = this, // It's lie. It changes later.
73+
widgetKey,
74+
i, info = {};
75+
76+
var post = function (url, data, callback) {
77+
78+
var xhr = new XMLHttpRequest();
79+
xhr.open("POST", url);
80+
xhr.onreadystatechange = function () {
81+
if (xhr.readyState === 4 && xhr.status === 200) {
82+
callback((function () {
83+
try {
84+
return JSON.parse(xhr.responseText) || {}
85+
} catch (e) {
86+
return {
87+
error: "<h1>Unable to parse server response</h1><p>" + xhr.responseText
88+
+ "</p>"
89+
};
90+
}
91+
})());
92+
} else if (xhr.readyState === 4 && xhr.status !== 200) {
93+
callback({ error: xhr.responseText
94+
|| "Error while trying to retrieve data from server." });
95+
}
96+
};
97+
xhr.send(JSON.stringify(data));
98+
99+
};
100+
101+
if (!container) {
102+
console.error("Light pivot table: Unable to get widget with ID=" + this.id);
103+
return;
104+
}
105+
106+
for (i in container.childNodes) {
107+
if (container.childNodes[i].className === "lpt-container") {
108+
container = container.childNodes[i];
109+
break;
110+
}
111+
}
112+
113+
var _ = this;
114+
115+
setTimeout(function() { // onCreate fired when scripts are ready, but this.parent is missed.
116+
117+
// !ultra-bydlocode (get the widget object)
118+
while (widget["parent"]) {
119+
widget = widget["parent"];
120+
}
121+
// !ultra-bydlocode (possible you will have better suggestions to get widget key)
122+
widgetKey = parseInt(_.parent.parent.onwindowgrab.match(/[0-9]+/)[0]);
123+
124+
post((source = location.origin + container.getAttribute("data-source")) + "/Widgets", {
125+
Dashboard: widget["dashboardName"]
126+
}, function (data) {
127+
if (data.error) {
128+
container.innerHTML = "<br/><br/><h3>Unable to get data from server.</h3><p>Check if data source is configured and accessible: " + source + "/Widgets" + "</p>"
129+
} else {
130+
for (i in data.children) {
131+
if (data.children[i].key === widgetKey) {
132+
info = data.children[i];
133+
break;
134+
}
135+
}
136+
setup = {
137+
container: container,
138+
dataSource: {
139+
MDX2JSONSource: source,
140+
basicMDX: info["mdx"]
141+
}
142+
}
143+
post(source + "/DataSource", { DataSource: info["dataSource"] }, function (data) {
144+
145+
if (data["rowAxisOptions"] && data["rowAxisOptions"]["drilldownSpec"]) {
146+
console.log(data["rowAxisOptions"]["drilldownSpec"]);
147+
setup.DrillDownExpression = data["rowAxisOptions"]["drilldownSpec"];
148+
}
149+
150+
new LightPivotTable(setup);
151+
152+
});
153+
}
154+
});
155+
156+
}, 0);
157+
]]></Implementation>
158+
</Method>
159+
160+
<Method name="%DrawHTML">
161+
<Implementation><![CDATA[
162+
set ..renderFlag = ..renderFlag + 1
163+
164+
&html<
165+
<div data-source="#(..settings("dataSource"))#" class="lpt-container" style="position: absolute; left: 0; top: 0; width: 100%; height: 100%;">
166+
167+
</div>
168+
>
169+
]]></Implementation>
170+
</Method>
171+
</Class>
172+
173+
</Export>

gulpfile.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
var gulp = require("gulp"),
2+
fs = require("fs"),
23
clean = require("gulp-clean"),
34
concat = require("gulp-concat"),
45
uglify = require("gulp-uglify"),
56
wrap = require("gulp-wrap"),
67
minifyCSS = require("gulp-minify-css"),
7-
htmlReplace = require("gulp-html-replace");
8+
htmlReplace = require("gulp-html-replace"),
9+
replace = require('gulp-replace');
810

911
gulp.task("clean", function () {
1012
return gulp.src("build", {read: false})
@@ -35,6 +37,13 @@ gulp.task("addExample", ["clean"], function () {
3537
.pipe(gulp.dest("build/example/"));
3638
});
3739

40+
gulp.task("exportCacheXML", ["clean", "gatherScripts", "gatherCSS"], function () {
41+
gulp.src("export/LightPivotTable.xml")
42+
.pipe(replace(/\{\{replace:css}}/, fs.readFileSync("build/css/lightPivotTable.css")))
43+
.pipe(replace(/\{\{replace:js}}/, fs.readFileSync("build/js/lightPivotTable.js")))
44+
.pipe(gulp.dest("build/"));
45+
});
46+
3847
gulp.task("copyLICENSE", ["clean"], function (){
3948
gulp.src("LICENSE")
4049
.pipe(gulp.dest("build/"));
@@ -46,5 +55,6 @@ gulp.task("copyREADME", ["clean"], function (){
4655
});
4756

4857
gulp.task("default", [
49-
"clean", "gatherScripts", "gatherCSS", "addExample", "copyLICENSE", "copyREADME"
58+
"clean", "gatherScripts", "gatherCSS", "addExample", "copyLICENSE", "copyREADME",
59+
"exportCacheXML"
5060
]);

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "LightPivotTable",
3-
"version": "0.0.1",
3+
"author": "ZitRo",
4+
"version": "0.2.0",
45
"description": "Light pivot table for MDX2JSON source for InterSystems Cache",
56
"main": "test/testServer.js",
67
"directories": {
@@ -14,7 +15,8 @@
1415
"gulp-html-replace": "^1.4.1",
1516
"gulp-minify-css": "^0.3.11",
1617
"gulp-uglify": "^1.0.1",
17-
"gulp-wrap": "^0.5.0"
18+
"gulp-wrap": "^0.5.0",
19+
"gulp-replace": "^0.5.0"
1820
},
1921
"scripts": {
2022
"test": "node test/testServer.js"
@@ -25,6 +27,5 @@
2527
"data",
2628
"collection",
2729
"visualization"
28-
],
29-
"author": "ZitRo"
30+
]
3031
}

readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ Build the project, and then include <code>build/css/lightPivotTable.css</code> a
2929
<code>build/js/lightPivotTable.js</code> files into your project. Usage is shown in
3030
<code>build/example/index.html</code> example.
3131

32+
To integrate light pivot widget into DeepSee, just perform build and then import <code>
33+
build/LightPivotTable.xml</code> into namespace you want. Make sure that MDX2JSON source is
34+
installed and configured. Also you may need to change the widget property "MDX2JSON source" to make
35+
it work with another MDX2JSON source.
36+
3237
## Build
3338

3439
You need [NodeJS](http://nodejs.org/) to perform any build tasks.

0 commit comments

Comments
 (0)