Skip to content

Commit

Permalink
Added the feature: #3
Browse files Browse the repository at this point in the history
  • Loading branch information
fcorti committed Jan 29, 2018
1 parent 3c30ed9 commit 3a7f423
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ <h1>
Update the filter below to update the dashboard.
<div>
<select id="externalHtmlElementId">
<option value="Classic Cars">Classic Cars</option>
<option value="Motorcycles">Motorcycles</option>
<option value="Classic Cars">Classic Cars</option>
<option value="Planes">Planes</option>
<option value="Ships">Ships</option>
<option value="Trains">Trains</option>
Expand All @@ -39,7 +39,8 @@ <h1>
id = "dashboard2"
pentahoPath = "/public/sample2.wcdf"
[params] = "['param2']"
[masterHtmlElementIds] = "['externalHtmlElementId']">
[masterHtmlElementIds] = "['externalHtmlElementId']"
[setDefaults]="true">
</pentaho-dashboard>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/app/pentaho-dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pentaho-dashboard",
"version": "1.0.3",
"version": "1.0.4",
"description": "Pentaho dashboards library for Angular.",
"main": "index.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class PentahoDashboardComponent implements AfterViewInit {
@Input('masterHtmlElementIds')
private masterHtmlElementIds : string[] = [];

@Input('setDefaults')
private setDefaults : boolean = true;

constructor(private pentahoDashboardService: PentahoDashboardService) {
}

Expand All @@ -40,7 +43,7 @@ export class PentahoDashboardComponent implements AfterViewInit {
this.pentahoDashboardService.renderDashboardDependingOnDashboard(this.pentahoPath, this.id, this.params, this.masterDashboardId, this.masterDashboardParams);
}
else if (this.masterHtmlElementIds != []) {
this.pentahoDashboardService.renderDashboardDependingOnHtmlElement(this.pentahoPath, this.id, this.params, this.masterHtmlElementIds);
this.pentahoDashboardService.renderDashboardDependingOnHtmlElement(this.pentahoPath, this.id, this.params, this.masterHtmlElementIds, this.setDefaults);
}
else {
this.pentahoDashboardService.renderDashboard(this.pentahoPath, this.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ export class PentahoDashboardService {
path: string,
htmlId:string,
params: string[],
masterHtmlElementIds: string[]) {
masterHtmlElementIds: string[],
setDefaults: boolean) {

var dashboardScriptElement = this.createDashboardScriptElement();

var jsCode = "";
jsCode += this.getJsCodeRequireStart([path]);
jsCode += this.getJsCodeForDashboardDependingOnHtmlElement(htmlId, params, masterHtmlElementIds);
jsCode += this.getJsCodeForDashboardDependingOnHtmlElement(htmlId, params, masterHtmlElementIds, setDefaults);
jsCode += this.getJsCodeRequireEnd();

dashboardScriptElement.innerHTML = jsCode;
Expand Down Expand Up @@ -176,13 +177,17 @@ export class PentahoDashboardService {
masterParams: string[]):string {

var jsCode = ", function(MasterDashboard, Dashboard) { ";

jsCode += "var currentDashboard = new Dashboard(\"" + htmlId + "\"); ";
jsCode += "currentDashboard.render(); ";

jsCode += "var masterDashboard = new MasterDashboard(\"" + masterDashboardHtmlId + "\"); ";
jsCode += "masterDashboard.render(); ";

for (let i in masterParams) {
jsCode += "masterDashboard.on(\"cdf " + masterParams[i] + ":fireChange\", function (evt) { currentDashboard.fireChange(\"" + params[i] + "\", evt.value); }); ";
}

jsCode += "} ";

return jsCode;
Expand All @@ -191,15 +196,22 @@ export class PentahoDashboardService {
private getJsCodeForDashboardDependingOnHtmlElement(
htmlId:string,
params: string[],
masterHtmlElementIds: string[]):string {
masterHtmlElementIds: string[],
setDefaults: boolean):string {

var jsCode = ", function(Dashboard) { ";

jsCode += "var currentDashboard = new Dashboard(\"" + htmlId + "\"); ";
jsCode += "currentDashboard.render(); ";

for (let i in masterHtmlElementIds) {
jsCode += "var htmlElement" + i + " = document.getElementById(\"" + masterHtmlElementIds[i] + "\"); ";
jsCode += "htmlElement" + i + ".addEventListener(\"change\", function() { currentDashboard.fireChange(\"" + params[i] + "\", this.value); }); ";
if (setDefaults) {
jsCode += "currentDashboard.setParameter(\"" + params[i] + "\", htmlElement"+ i +".value); ";
}
}

jsCode += "} ";

return jsCode;
Expand Down

0 comments on commit 3a7f423

Please sign in to comment.