2016-01-18 06:21:48 -06:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
import coreModule from "../../core/core_module";
|
|
|
|
import kbn from "app/core/utils/kbn";
|
|
|
|
import appEvents from "app/core/app_events";
|
2016-01-18 06:21:48 -06:00
|
|
|
|
|
|
|
class PlaylistSrv {
|
2016-01-18 07:05:48 -06:00
|
|
|
private cancelPromise: any;
|
|
|
|
private dashboards: any;
|
|
|
|
private index: number;
|
|
|
|
private interval: any;
|
2016-12-05 04:43:51 -06:00
|
|
|
private startUrl: string;
|
2017-06-02 07:00:42 -05:00
|
|
|
public isPlaying: boolean;
|
2016-01-18 06:21:48 -06:00
|
|
|
|
|
|
|
/** @ngInject */
|
2017-06-28 09:29:46 -05:00
|
|
|
constructor(
|
|
|
|
private $location: any,
|
|
|
|
private $timeout: any,
|
|
|
|
private backendSrv: any,
|
|
|
|
private $routeParams: any
|
2017-12-19 09:06:54 -06:00
|
|
|
) {}
|
2016-01-18 06:21:48 -06:00
|
|
|
|
|
|
|
next() {
|
|
|
|
this.$timeout.cancel(this.cancelPromise);
|
|
|
|
|
2016-01-18 07:58:46 -06:00
|
|
|
var playedAllDashboards = this.index > this.dashboards.length - 1;
|
|
|
|
|
|
|
|
if (playedAllDashboards) {
|
2017-06-28 09:29:46 -05:00
|
|
|
window.location.href = this.getUrlWithKioskMode();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var dash = this.dashboards[this.index];
|
2017-12-19 09:06:54 -06:00
|
|
|
this.$location.url("dashboard/" + dash.uri);
|
2017-06-28 09:29:46 -05:00
|
|
|
|
|
|
|
this.index++;
|
|
|
|
this.cancelPromise = this.$timeout(() => this.next(), this.interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
getUrlWithKioskMode() {
|
2017-12-19 09:06:54 -06:00
|
|
|
const inKioskMode = document.body.classList.contains("page-kiosk-mode");
|
2016-01-18 06:54:32 -06:00
|
|
|
|
2017-06-28 09:29:46 -05:00
|
|
|
// check if should add kiosk query param
|
2017-12-19 09:06:54 -06:00
|
|
|
if (inKioskMode && this.startUrl.indexOf("kiosk") === -1) {
|
|
|
|
return this.startUrl + "?kiosk=true";
|
2016-01-18 06:54:32 -06:00
|
|
|
}
|
2017-06-28 09:29:46 -05:00
|
|
|
|
|
|
|
// check if should remove kiosk query param
|
|
|
|
if (!inKioskMode) {
|
|
|
|
return this.startUrl.split("?")[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// already has kiosk query param, just return startUrl
|
|
|
|
return this.startUrl;
|
2016-01-18 06:21:48 -06:00
|
|
|
}
|
|
|
|
|
2016-01-18 09:00:11 -06:00
|
|
|
prev() {
|
2016-01-18 06:21:48 -06:00
|
|
|
this.index = Math.max(this.index - 2, 0);
|
|
|
|
this.next();
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:40:51 -06:00
|
|
|
start(playlistId) {
|
2016-01-18 06:21:48 -06:00
|
|
|
this.stop();
|
|
|
|
|
2016-12-05 04:43:51 -06:00
|
|
|
this.startUrl = window.location.href;
|
2016-01-18 06:21:48 -06:00
|
|
|
this.index = 0;
|
2017-06-02 07:00:42 -05:00
|
|
|
this.isPlaying = true;
|
2016-01-18 06:21:48 -06:00
|
|
|
|
2017-06-28 09:29:46 -05:00
|
|
|
if (this.$routeParams.kiosk) {
|
2017-12-19 09:06:54 -06:00
|
|
|
appEvents.emit("toggle-kiosk-mode");
|
2017-06-28 09:29:46 -05:00
|
|
|
}
|
|
|
|
|
2016-01-18 09:00:11 -06:00
|
|
|
this.backendSrv.get(`/api/playlists/${playlistId}`).then(playlist => {
|
2017-12-19 09:06:54 -06:00
|
|
|
this.backendSrv
|
|
|
|
.get(`/api/playlists/${playlistId}/dashboards`)
|
|
|
|
.then(dashboards => {
|
|
|
|
this.dashboards = dashboards;
|
|
|
|
this.interval = kbn.interval_to_ms(playlist.interval);
|
|
|
|
this.next();
|
|
|
|
});
|
2016-01-18 09:00:11 -06:00
|
|
|
});
|
2016-01-18 06:21:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
this.index = 0;
|
2017-06-02 07:00:42 -05:00
|
|
|
this.isPlaying = false;
|
2016-01-18 06:21:48 -06:00
|
|
|
|
|
|
|
if (this.cancelPromise) {
|
2016-01-18 09:00:11 -06:00
|
|
|
this.$timeout.cancel(this.cancelPromise);
|
2016-01-18 06:21:48 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
coreModule.service("playlistSrv", PlaylistSrv);
|