Skip to content

Commit c867661

Browse files
committed
Merged PR 3708: Add ApplyCustomLayout method.
1) Add ApplyCustomLayout method. 2) Remove logs like: Json Object { "statusCode": 202, "headers": { "id": "1rjzv" } }
1 parent 3acf0f1 commit c867661

File tree

4 files changed

+88
-42
lines changed

4 files changed

+88
-42
lines changed

demo/v2-demo/scripts/codesamples.js

Lines changed: 81 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,8 @@ function _Report_UpdateSettings() {
596596

597597
// Update the settings by passing in the new settings you have configured.
598598
report.updateSettings(newSettings)
599-
.then(function (result) {
600-
$("#result").html(result);
601-
})
602599
.catch(function (error) {
603-
$("#result").html(error);
600+
Log.log(errors);
604601
});
605602
}
606603

@@ -632,16 +629,6 @@ function _Report_SetPage() {
632629
// Get a reference to the embedded report.
633630
report = powerbi.get(embedContainer);
634631

635-
// setPage will change the selected view to the page you indicate.
636-
// This is the actual page name not the display name.
637-
report.setPage("ReportSection2")
638-
.then(function (result) {
639-
Log.log(result);
640-
})
641-
.catch(function (errors) {
642-
Log.log(errors);
643-
});
644-
645632
// Report.off removes a given event handler if it exists.
646633
report.off("pageChanged");
647634

@@ -651,6 +638,13 @@ function _Report_SetPage() {
651638
var page = event.detail.newPage;
652639
Log.logText(page.name + " - " + page.displayName);
653640
});
641+
642+
// setPage will change the selected view to the page you indicate.
643+
// This is the actual page name not the display name.
644+
report.setPage("ReportSection2")
645+
.catch(function (errors) {
646+
Log.log(errors);
647+
});
654648
}
655649

656650
function _Report_GetFilters() {
@@ -692,9 +686,6 @@ function _Report_SetFilters() {
692686
// Set the filter for the report.
693687
// Pay attention that setFilters receives an array.
694688
report.setFilters([filter])
695-
.then(function (result) {
696-
Log.log(result);
697-
})
698689
.catch(function (errors) {
699690
Log.log(errors);
700691
});
@@ -709,9 +700,6 @@ function _Report_RemoveFilters() {
709700

710701
// Remove the filters currently applied to the report.
711702
report.removeFilters()
712-
.then(function (result) {
713-
Log.log(result);
714-
})
715703
.catch(function (errors) {
716704
Log.log(errors);
717705
});
@@ -726,9 +714,6 @@ function _Report_PrintCurrentReport() {
726714

727715
// Trigger the print dialog for your browser.
728716
report.print()
729-
.then(function (result) {
730-
Log.log(result);
731-
})
732717
.catch(function (errors) {
733718
Log.log(errors);
734719
});
@@ -768,6 +753,73 @@ function _Report_Refresh() {
768753
});
769754
}
770755

756+
function _Report_ApplyCustomLayout() {
757+
// Get a reference to the embedded report HTML element
758+
var embedContainer = $('#embedContainer')[0];
759+
760+
// Get models. models contains enums that can be used.
761+
var models = window['powerbi-client'].models;
762+
763+
// Define default visual layout: visible in 400x300.
764+
let defaultLayout = {
765+
width: 400,
766+
height: 300,
767+
displayState: {
768+
mode: models.VisualContainerDisplayMode.Hidden
769+
}
770+
};
771+
772+
// Define page size as custom size: 1000x580.
773+
let pageSize = {
774+
type: models.PageSizeType.Custom,
775+
width: 1000,
776+
height: 580
777+
};
778+
779+
// Page layout: two visible visuals in fixed position.
780+
let pageLayout = {
781+
defaultLayout: defaultLayout,
782+
visualsLayout: {
783+
"VisualContainer7": {
784+
x: 70,
785+
y: 100,
786+
displayState: {
787+
mode: models.VisualContainerDisplayMode.Visible
788+
}
789+
},
790+
"VisualContainer4": {
791+
x: 540,
792+
y: 100,
793+
displayState: {
794+
mode: models.VisualContainerDisplayMode.Visible
795+
}
796+
}
797+
}
798+
};
799+
800+
let settings = {
801+
filterPaneEnabled: false,
802+
navContentPaneEnabled: false,
803+
layoutType: models.LayoutType.Custom,
804+
customLayout: {
805+
pageSize: pageSize,
806+
displayOption: models.DisplayOption.FitToPage,
807+
pagesLayout: {
808+
"ReportSection3": pageLayout
809+
}
810+
}
811+
}
812+
813+
// Get a reference to the embedded report.
814+
report = powerbi.get(embedContainer);
815+
816+
// Update the settings by passing in the new settings you have configured.
817+
report.updateSettings(settings)
818+
.catch(function (error) {
819+
Log.log(errors);
820+
});
821+
}
822+
771823
function _Report_FullScreen() {
772824
// Get a reference to the embedded report HTML element
773825
var embedContainer = $('#embedContainer')[0];
@@ -874,11 +926,8 @@ function _Report_Extensions_OptionsMenu() {
874926

875927
// Update the settings by passing in the new settings you have configured.
876928
report.updateSettings(newSettings)
877-
.then(function (result) {
878-
$("#result").html(result);
879-
})
880929
.catch(function (error) {
881-
$("#result").html(error);
930+
Log.log(errors);
882931
});
883932

884933
// Report.on will add an event handler to commandTriggered event which prints to console window.
@@ -922,11 +971,8 @@ function _Report_Extensions_ContextMenu() {
922971

923972
// Update the settings by passing in the new settings you have configured.
924973
report.updateSettings(newSettings)
925-
.then(function (result) {
926-
$("#result").html(result);
927-
})
928974
.catch(function (error) {
929-
$("#result").html(error);
975+
Log.log(errors);
930976
});
931977

932978
// Report.on will add an event handler to commandTriggered event which prints to console window.
@@ -953,9 +999,10 @@ function _Page_SetActive() {
953999
// Retrieve the page collection, and then set the second page to be active.
9541000
report.getPages()
9551001
.then(function (pages) {
956-
pages[1].setActive().then(function (result) {
957-
Log.log(result);
958-
});
1002+
pages[1].setActive()
1003+
.catch(function (errors) {
1004+
Log.log(errors);
1005+
});
9591006
})
9601007
.catch(function (errors) {
9611008
Log.log(errors);
@@ -1055,9 +1102,6 @@ function _Page_SetFilters() {
10551102
});
10561103

10571104
activePage.setFilters([filter])
1058-
.then(function (result) {
1059-
Log.log(result);
1060-
})
10611105
.catch(function (errors) {
10621106
Log.log(errors);
10631107
});
@@ -1083,9 +1127,6 @@ function _Page_RemoveFilters() {
10831127
});
10841128

10851129
activePage.removeFilters()
1086-
.then(function (result) {
1087-
Log.log(result);
1088-
})
10891130
.catch(function (errors) {
10901131
Log.log(errors);
10911132
});

demo/v2-demo/scripts/step_embed.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ function Report_Extensions_OptionsMenu() {
5555
SetCode(_Report_Extensions_OptionsMenu);
5656
}
5757

58+
function Report_ApplyCustomLayout() {
59+
SetCode(_Report_ApplyCustomLayout);
60+
}
61+
5862
// ---- Page Operations ----------------------------------------------------
5963

6064
function Page_SetActive() {

demo/v2-demo/settings_embed.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div id="report-embed-table">
1+
<div id="report-embed-table" class="embed-table">
22
<div class="pageTitle">
33
<h4>Embed Report</h4>
44
</div>
@@ -37,7 +37,7 @@ <h4>Embed Report</h4>
3737
<div id="createModeInput">
3838
<h8>Fill in the fields below to get the code to embed your report.</h8>
3939
<div class="spacer" />
40-
40+
4141
<div class="inputLine">
4242
<div class="inputLineTitle">Embed Token</div>
4343
<input type="text" id="txtCreateAccessToken" onchange="UpdateSession(this, SessionKeys.AccessToken);" />

demo/v2-demo/settings_interact.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<li onclick="Report_UpdateSettings()">Update settings</li>
3333
<li onclick="Report_Reload()">Reload</li>
3434
<li onclick="Report_Refresh()">Refresh</li>
35+
<li class="newOperation" onclick="Report_ApplyCustomLayout()">Apply Custom Layout</li>
3536
<li class="newOperation" onclick="Report_Extensions_OptionsMenu()">Extend options menu</li>
3637
<li class="newOperation" onclick="Report_Extensions_ContextMenu()">Extend context menu</li>
3738
<li onclick="Report_FullScreen()">Full screen</li>

0 commit comments

Comments
 (0)