|
| 1 | +/* |
| 2 | + This file contains the code samples which will appear live in the web-page. |
| 3 | + Each sample method name starts with _Report_ or _Page or _Embed depends on which section it appears. |
| 4 | + Please keep this. |
| 5 | +*/ |
| 6 | + |
| 7 | +// ---- Embed Code ---------------------------------------------------- |
| 8 | + |
| 9 | +function _Embed_BasicEmbed() { |
| 10 | + var txtAccessToken = $('#txtAccessToken').val(); |
| 11 | + var txtEmbedUrl = $('#txtReportEmbed').val(); |
| 12 | + var txtEmbedReportId = $('#txtEmbedReportId').val(); |
| 13 | + |
| 14 | + var embedConfiguration = { |
| 15 | + type: 'report', |
| 16 | + accessToken: txtAccessToken, |
| 17 | + embedUrl: txtEmbedUrl, |
| 18 | + id: txtEmbedReportId, |
| 19 | + settings: { |
| 20 | + filterPaneEnabled: true, |
| 21 | + navContentPaneEnabled: true |
| 22 | + } |
| 23 | + }; |
| 24 | + |
| 25 | + var reportContainer = document.getElementById('reportContainer'); |
| 26 | + powerbi.embed(reportContainer, embedConfiguration); |
| 27 | +} |
| 28 | + |
| 29 | +function _Embed_EmbedWithDefaultFilter() { |
| 30 | + var txtAccessToken = $('#txtAccessToken').val(); |
| 31 | + var txtEmbedUrl = $('#txtReportEmbed').val(); |
| 32 | + var txtEmbedReportId = $('#txtEmbedReportId').val(); |
| 33 | + |
| 34 | + const filter = { |
| 35 | + $schema: "http://powerbi.com/product/schema#basic", |
| 36 | + target: { |
| 37 | + table: "Store", |
| 38 | + column: "Chain" |
| 39 | + }, |
| 40 | + operator: "In", |
| 41 | + values: ["Lindseys"] |
| 42 | + }; |
| 43 | + |
| 44 | + var embedConfiguration = { |
| 45 | + type: 'report', |
| 46 | + accessToken: txtAccessToken, |
| 47 | + embedUrl: txtEmbedUrl, |
| 48 | + id: txtEmbedReportId, |
| 49 | + settings: { |
| 50 | + filterPaneEnabled: false, |
| 51 | + navContentPaneEnabled: false |
| 52 | + }, |
| 53 | + filters: [filter] |
| 54 | + }; |
| 55 | + |
| 56 | + var reportContainer = document.getElementById('reportContainer'); |
| 57 | + powerbi.embed(reportContainer, embedConfiguration); |
| 58 | +} |
| 59 | + |
| 60 | +// ---- Report Operations ---------------------------------------------------- |
| 61 | + |
| 62 | + function _Report_GetId() { |
| 63 | + report = powerbi.embeds[0]; |
| 64 | + $('#result').html(report.getId()); |
| 65 | +} |
| 66 | + |
| 67 | +function _Report_UpdateSettings() { |
| 68 | + const newSettings = { |
| 69 | + navContentPaneEnabled: true, |
| 70 | + filterPaneEnabled: false |
| 71 | + }; |
| 72 | + |
| 73 | + report = powerbi.embeds[0]; |
| 74 | + report.updateSettings(newSettings) |
| 75 | + .then(function (result) { |
| 76 | + $("#result").html(result); |
| 77 | + }) |
| 78 | + .catch(function (error) { |
| 79 | + $("#result").html(error); |
| 80 | + }); |
| 81 | +} |
| 82 | + |
| 83 | +function _Report_GetPages() { |
| 84 | + report = powerbi.embeds[0]; |
| 85 | + |
| 86 | + report.getPages() |
| 87 | + .then(function (pages) { |
| 88 | + var result = ""; |
| 89 | + var index = 1; |
| 90 | + pages.forEach(function(page) { |
| 91 | + result = result + index + ") " + page.name + "(displayName: " + page.displayName + ")" + "<br/>"; |
| 92 | + index++; |
| 93 | + }); |
| 94 | + |
| 95 | + $("#result").html("Done. <br/>" + result); |
| 96 | + }) |
| 97 | + .catch(function (errors) { |
| 98 | + $("#result").html("Error. <br/>" + JSON.stringify(errors)); |
| 99 | + }); |
| 100 | +} |
| 101 | + |
| 102 | +function _Report_SetPage() { |
| 103 | + report = powerbi.embeds[0]; |
| 104 | + report.setPage("ReportSection2") |
| 105 | + .then(function (result) { |
| 106 | + $("#result").html("Done. <br/>" + JSON.stringify(result)); |
| 107 | + }) |
| 108 | + .catch(function (errors) { |
| 109 | + $("#result").html("Error. <br/>" + JSON.stringify(errors)); |
| 110 | + }); |
| 111 | +} |
| 112 | + |
| 113 | +function _Report_GetFilters() { |
| 114 | + report = powerbi.embeds[0]; |
| 115 | + |
| 116 | + report.getFilters() |
| 117 | + .then(function (filters) { |
| 118 | + $("#result").html("Done. <br/>" + JSON.stringify(filters, null, " ")); |
| 119 | + }) |
| 120 | + .catch(function (errors) { |
| 121 | + $("#result").html("Error. <br/>" + JSON.stringify(errors)); |
| 122 | + }); |
| 123 | +} |
| 124 | + |
| 125 | +function _Report_SetFilters() { |
| 126 | + const filter = { |
| 127 | + $schema: "http://powerbi.com/product/schema#basic", |
| 128 | + target: { |
| 129 | + table: "Store", |
| 130 | + column: "Chain" |
| 131 | + }, |
| 132 | + operator: "In", |
| 133 | + values: ["Lindseys"] |
| 134 | + }; |
| 135 | + |
| 136 | + report = powerbi.embeds[0]; |
| 137 | + report.setFilters([filter]) |
| 138 | + .then(function (result) { |
| 139 | + $("#result").html("Done. <br/>" + JSON.stringify(result)); |
| 140 | + }) |
| 141 | + .catch(function (errors) { |
| 142 | + $("#result").html("Error. <br/>" + JSON.stringify(errors)); |
| 143 | + }); |
| 144 | +} |
| 145 | + |
| 146 | +function _Report_RemoveFilters() { |
| 147 | + report = powerbi.embeds[0]; |
| 148 | + report.removeFilters() |
| 149 | + .then(function (result) { |
| 150 | + $("#result").html("Done. <br/>" + JSON.stringify(result)); |
| 151 | + }) |
| 152 | + .catch(function (errors) { |
| 153 | + $("#result").html("Error. <br/>" + JSON.stringify(errors)); |
| 154 | + }); |
| 155 | +} |
| 156 | + |
| 157 | +function _Report_PrintCurrentReport() { |
| 158 | + report = powerbi.embeds[0]; |
| 159 | + report.print() |
| 160 | + .then(function (result) { |
| 161 | + $("#result").html("Done. <br/>" + JSON.stringify(result)); |
| 162 | + }) |
| 163 | + .catch(function (errors) { |
| 164 | + $("#result").html("Error. <br/>" + JSON.stringify(errors)); |
| 165 | + }); |
| 166 | +} |
| 167 | + |
| 168 | +function _Report_Reload() { |
| 169 | + report = powerbi.embeds[0]; |
| 170 | + report.reload() |
| 171 | + .then(function (result) { |
| 172 | + $("#result").html("Done. <br/>" + JSON.stringify(result)); |
| 173 | + }) |
| 174 | + .catch(function (errors) { |
| 175 | + $("#result").html("Error. <br/>" + JSON.stringify(errors)); |
| 176 | + }); |
| 177 | +} |
| 178 | + |
| 179 | +function _Report_FullScreen() { |
| 180 | + report = powerbi.embeds[0]; |
| 181 | + report.fullscreen(); |
| 182 | + |
| 183 | + $("#result").html("Done!"); |
| 184 | +} |
| 185 | + |
| 186 | +function _Report_ExitFullScreen() { |
| 187 | + report = powerbi.embeds[0]; |
| 188 | + report.exitFullscreen(); |
| 189 | + |
| 190 | + $("#result").html("Done!"); |
| 191 | +} |
| 192 | + |
| 193 | +// ---- Page Operations ---------------------------------------------------- |
| 194 | + |
| 195 | +function _Page_SetActive() { |
| 196 | + report = powerbi.embeds[0]; |
| 197 | + |
| 198 | + // Set the second page active |
| 199 | + report.getPages() |
| 200 | + .then(function (pages) { |
| 201 | + pages[1].setActive().then(function (result) { |
| 202 | + $("#result").html("Done. <br/>" + result) |
| 203 | + }); |
| 204 | + }) |
| 205 | + .catch(function (errors) { |
| 206 | + $("#result").html("getPages Error. " + errors); |
| 207 | + }); |
| 208 | +} |
| 209 | + |
| 210 | +function _Page_GetFilters() { |
| 211 | + report = powerbi.embeds[0]; |
| 212 | + |
| 213 | + // Get Filters of first page |
| 214 | + report.getPages() |
| 215 | + .then(function (pages) { |
| 216 | + pages[1].getFilters() |
| 217 | + .then(function (filters) { |
| 218 | + $("#result").html("Done. <br/>" + JSON.stringify(filters, null, " ")) |
| 219 | + }) |
| 220 | + .catch(function (errors) { |
| 221 | + $("#result").html("Error. <br/>" + JSON.stringify(errors)); |
| 222 | + }); |
| 223 | + }) |
| 224 | + .catch(function (errors) { |
| 225 | + $("#result").html("getPages Error. " + errors); |
| 226 | + }); |
| 227 | +} |
| 228 | + |
| 229 | +function _Page_SetFilters() { |
| 230 | + const filter = { |
| 231 | + $schema: "http://powerbi.com/product/schema#basic", |
| 232 | + target: { |
| 233 | + table: "Store", |
| 234 | + column: "Chain" |
| 235 | + }, |
| 236 | + operator: "In", |
| 237 | + values: ["Lindseys"] |
| 238 | + }; |
| 239 | + |
| 240 | + report = powerbi.embeds[0]; |
| 241 | + report.getPages() |
| 242 | + .then(function (pages) { |
| 243 | + pages[1].setFilters([filter]) |
| 244 | + .then(function (result) { |
| 245 | + $("#result").html("Done. <br/>" + JSON.stringify(result)); |
| 246 | + }) |
| 247 | + .catch(function (errors) { |
| 248 | + $("#result").html("Error. <br/>" + JSON.stringify(errors)); |
| 249 | + }); |
| 250 | + }) |
| 251 | + .catch(function (errors) { |
| 252 | + $("#result").html("Error. <br/>" + JSON.stringify(errors)); |
| 253 | + }); |
| 254 | +} |
| 255 | + |
| 256 | +function _Page_RemoveFilters() { |
| 257 | + report = powerbi.embeds[0]; |
| 258 | + |
| 259 | + // Get Filters of first page |
| 260 | + report.getPages() |
| 261 | + .then(function (pages) { |
| 262 | + pages[1].removeFilters() |
| 263 | + .then(function (result) { |
| 264 | + $("#result").html("Done. <br/>" + JSON.stringify(result)); |
| 265 | + }) |
| 266 | + .catch(function (errors) { |
| 267 | + $("#result").html("Error. <br/>" + JSON.stringify(errors)); |
| 268 | + }); |
| 269 | + }) |
| 270 | + .catch(function (errors) { |
| 271 | + $("#result").html("getPages Error. " + errors); |
| 272 | + }); |
| 273 | +} |
0 commit comments