@@ -4,10 +4,22 @@ $(function () {
44 var $reportsList = $ ( '#reportslist' ) ;
55 var $dynamicReport = $ ( '#reportdynamic' ) ;
66 var $customPageNavReport = $ ( '#reportcustompagenav' ) ;
7- var $reportPagesList = $ ( '#reportpageslist' ) ;
7+ var customPageNavReport ;
8+ var customPageNavReportPages ;
9+ var $reportPagesList = $ ( '#reportpagesbuttons' ) ;
810 var $resetButton = $ ( '#resetButton' ) ;
11+ var $prevButton = $ ( '#prevbutton' ) ;
12+ var $nextButton = $ ( '#nextbutton' ) ;
13+ var $cycleButton = $ ( '#cyclebutton' ) ;
14+ var cycleIntervalId ;
915 var apiBaseUrl = 'http://powerbipaasapi.azurewebsites.net/api/reports' ;
1016
17+ var localReportOverride = {
18+ embedUrl : 'https://portal.analysis.windows-int.net/appTokenReportEmbed' ,
19+ id : 'c4d31ef0-7b34-4d80-9bcb-5974d1405572' ,
20+ accessToken : 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2ZXIiOiIwLjEuMCIsImF1ZCI6Imh0dHBzOi8vYW5hbHlzaXMud2luZG93cy5uZXQvcG93ZXJiaS9hcGkiLCJpc3MiOiJQb3dlckJJU0RLIiwidHlwZSI6ImVtYmVkIiwid2NuIjoiV2FsbGFjZSIsIndpZCI6IjUyMWNkYTJhLTRlZDItNDg5Ni1hYzA0LWM5YzM4MWRjMjUyYSIsInJpZCI6ImM0ZDMxZWYwLTdiMzQtNGQ4MC05YmNiLTU5NzRkMTQwNTU3MiIsIm5iZiI6MTQ2NzMxNjQ2MCwiZXhwIjoxNDY3MzIwMDYwfQ.1iKcgmG07m-VLGKmGwKI95ICVYowYkVGnudws02rtow'
21+ } ;
22+
1123 /**
1224 * Basic Embed
1325 */
@@ -19,40 +31,118 @@ $(function () {
1931 return response . json ( ) ;
2032 } )
2133 . then ( function ( report ) {
22- var reportConfig = $ . extend ( { type : 'report' } , report ) ;
34+ var reportConfig = $ . extend ( { type : 'report' } , report , localReportOverride ) ;
2335 var staticReport = powerbi . embed ( $staticReport . get ( 0 ) , reportConfig ) ;
36+
2437 staticReport . on ( 'loaded' , function ( event ) {
2538 console . log ( 'static report loaded' ) ;
2639 } ) ;
40+ staticReport . on ( 'error' , function ( event ) {
41+ console . log ( 'static report error' ) ;
42+ } ) ;
2743
2844 var customPageNavConfig = $ . extend ( {
2945 settings : {
30- navContentPaneEnabled : false ,
3146 filterPaneEnabled : false
3247 }
3348 } , reportConfig ) ;
3449
35- var customPageNavReport = powerbi . embed ( $customPageNavReport . get ( 0 ) , customPageNavConfig ) ;
50+ customPageNavReport = powerbi . embed ( $customPageNavReport . get ( 0 ) , customPageNavConfig ) ;
3651 customPageNavReport . on ( 'loaded' , function ( event ) {
3752 console . log ( 'custom page nav report loaded' ) ;
3853 customPageNavReport . getPages ( )
3954 . then ( pages => {
4055 console . log ( 'pages: ' , pages ) ;
41- return pages
42- . map ( function ( page ) {
43- return generateReportPage ( report , page ) ;
44- } )
45- . forEach ( function ( element ) {
46- $reportPagesList . append ( element ) ;
47- } ) ;
56+ if ( pages . length > 0 ) {
57+ customPageNavReportPages = pages ;
58+ const firstPage = customPageNavReportPages [ 0 ] ;
59+ firstPage . isActive = true ;
60+
61+ pages
62+ . map ( function ( page ) {
63+ return generateReportPage ( page ) ;
64+ } )
65+ . forEach ( function ( element ) {
66+ $reportPagesList . append ( element ) ;
67+ } ) ;
68+ }
4869 } ) ;
4970 } ) ;
71+ customPageNavReport . on ( 'error' , function ( event ) {
72+ console . log ( 'customPageNavReport error' , event ) ;
73+ } ) ;
5074
5175 customPageNavReport . on ( 'pageChanged' , function ( event ) {
52- console . log ( 'pageChanged event received' ) ;
53- } )
76+ console . log ( 'pageChanged event received' , event ) ;
77+ updateActivePage ( event . newPage ) ;
78+ } ) ;
5479 } ) ;
5580
81+ function updateActivePage ( newPage ) {
82+ // Remove active class
83+ var reportButtons = $reportPagesList . children ( 'button' ) ;
84+
85+ reportButtons
86+ . each ( function ( index , element ) {
87+ var $element = $ ( element ) ;
88+ var buttonPage = $element . data ( 'page' ) ;
89+ if ( buttonPage . isActive ) {
90+ buttonPage . isActive = false ;
91+ $element . removeClass ( 'active' ) ;
92+ }
93+ } ) ;
94+
95+ // Set active class
96+ reportButtons
97+ . each ( function ( index , element ) {
98+ var $element = $ ( element ) ;
99+ var buttonPage = $element . data ( 'page' ) ;
100+ if ( buttonPage . name === newPage . name ) {
101+ buttonPage . isActive = true ;
102+ $element . addClass ( 'active' ) ;
103+ }
104+ } ) ;
105+ }
106+
107+ function changePage ( forwards ) {
108+ // Remove active class
109+ var reportButtons = $reportPagesList . children ( 'button' ) ;
110+ var $activeButtonIndex = - 1 ;
111+
112+ reportButtons
113+ . each ( function ( index , element ) {
114+ var $element = $ ( element ) ;
115+ var buttonPage = $element . data ( 'page' ) ;
116+ if ( buttonPage . isActive ) {
117+ $activeButtonIndex = index ;
118+ }
119+ } ) ;
120+
121+ if ( forwards ) {
122+ $activeButtonIndex += 1 ;
123+ }
124+ else {
125+ $activeButtonIndex -= 1 ;
126+ }
127+
128+ if ( $activeButtonIndex > reportButtons . length - 1 ) {
129+ $activeButtonIndex = 0 ;
130+ }
131+ if ( $activeButtonIndex < 0 ) {
132+ $activeButtonIndex = reportButtons . length - 1 ;
133+ }
134+
135+ reportButtons
136+ . each ( function ( index , element ) {
137+ if ( $activeButtonIndex === index ) {
138+ var $element = $ ( element ) ;
139+ var buttonPage = $element . data ( 'page' ) ;
140+
141+ customPageNavReport . setPage ( buttonPage . name ) ;
142+ }
143+ } ) ;
144+ }
145+
56146 /**
57147 * Dynamic Embed
58148 */
@@ -76,15 +166,20 @@ $(function () {
76166 return element ;
77167 }
78168
79- function generateReportPage ( report , page ) {
80- return $ ( '<button>' )
169+ function generateReportPage ( page ) {
170+ var $page = $ ( '<button>' )
81171 . attr ( {
82172 type : 'button'
83173 } )
84174 . addClass ( 'btn btn-success' )
85- . data ( 'report' , report )
86175 . data ( 'page' , page )
87- . text ( page . name ) ;
176+ . text ( page . displayName ) ;
177+
178+ if ( page . isActive ) {
179+ $page . addClass ( 'active' ) ;
180+ }
181+
182+ return $page ;
88183 }
89184
90185 var allReportsUrl = apiBaseUrl ;
@@ -111,15 +206,39 @@ $(function () {
111206 return response . json ( ) ;
112207 } )
113208 . then ( function ( reportWithToken ) {
114- var reportConfig = $ . extend ( { type : 'report' } , reportWithToken ) ;
209+ var reportConfig = $ . extend ( { type : 'report' } , reportWithToken , localReportOverride ) ;
115210 powerbi . embed ( $dynamicReport . get ( 0 ) , reportConfig ) ;
116211 } ) ;
117212 } ) ;
118213
214+ $prevButton . on ( 'click' , function ( event ) {
215+ changePage ( false ) ;
216+ } ) ;
217+
218+ $nextButton . on ( 'click' , function ( event ) {
219+ changePage ( true ) ;
220+ } ) ;
221+
222+ $cycleButton . on ( 'click' , function ( event ) {
223+ $cycleButton . toggleClass ( 'active' ) ;
224+ $cycleButton . data ( 'cycle' , ! $cycleButton . data ( 'cycle' ) ) ;
225+
226+ if ( $cycleButton . data ( 'cycle' ) ) {
227+ cycleIntervalId = setInterval ( function ( ) {
228+ console . log ( 'cycle page: ' ) ;
229+ changePage ( true ) ;
230+ } , 1000 ) ;
231+ }
232+ else {
233+ clearInterval ( cycleIntervalId ) ;
234+ }
235+ } ) ;
236+
119237 $resetButton . on ( 'click' , function ( event ) {
120238 powerbi . reset ( $dynamicReport . get ( 0 ) ) ;
121239 } ) ;
122240
241+
123242 /**
124243 * Custom Page Navigation
125244 */
@@ -129,7 +248,7 @@ $(function () {
129248 var page = $ ( button ) . data ( 'page' ) ;
130249
131250 console . log ( 'Attempting to set page to: ' , page . name ) ;
132- report . setPage ( page . name )
251+ customPageNavReport . setPage ( page . name )
133252 . then ( function ( response ) {
134253 console . log ( 'Page changed request accepted' ) ;
135254 } ) ;
0 commit comments