|
|
@@ -7,6 +7,7 @@ import coreModule from '../../core/core_module';
|
|
|
import appEvents from 'app/core/app_events';
|
|
|
import locationUtil from 'app/core/utils/location_util';
|
|
|
import kbn from 'app/core/utils/kbn';
|
|
|
+import { store } from 'app/store/store';
|
|
|
|
|
|
export class PlaylistSrv {
|
|
|
private cancelPromise: any;
|
|
|
@@ -15,6 +16,8 @@ export class PlaylistSrv {
|
|
|
private interval: number;
|
|
|
private startUrl: string;
|
|
|
private numberOfLoops = 0;
|
|
|
+ private storeUnsub: () => void;
|
|
|
+ private validPlaylistUrl: string;
|
|
|
isPlaying: boolean;
|
|
|
|
|
|
/** @ngInject */
|
|
|
@@ -39,15 +42,16 @@ export class PlaylistSrv {
|
|
|
const dash = this.dashboards[this.index];
|
|
|
const queryParams = this.$location.search();
|
|
|
const filteredParams = _.pickBy(queryParams, value => value !== null);
|
|
|
+ const nextDashboardUrl = locationUtil.stripBaseFromUrl(dash.url);
|
|
|
|
|
|
// this is done inside timeout to make sure digest happens after
|
|
|
// as this can be called from react
|
|
|
this.$timeout(() => {
|
|
|
- const stripedUrl = locationUtil.stripBaseFromUrl(dash.url);
|
|
|
- this.$location.url(stripedUrl + '?' + toUrlParams(filteredParams));
|
|
|
+ this.$location.url(nextDashboardUrl + '?' + toUrlParams(filteredParams));
|
|
|
});
|
|
|
|
|
|
this.index++;
|
|
|
+ this.validPlaylistUrl = nextDashboardUrl;
|
|
|
this.cancelPromise = this.$timeout(() => this.next(), this.interval);
|
|
|
}
|
|
|
|
|
|
@@ -56,6 +60,15 @@ export class PlaylistSrv {
|
|
|
this.next();
|
|
|
}
|
|
|
|
|
|
+ // Detect url changes not caused by playlist srv and stop playlist
|
|
|
+ storeUpdated() {
|
|
|
+ const state = store.getState();
|
|
|
+
|
|
|
+ if (state.location.path !== this.validPlaylistUrl) {
|
|
|
+ this.stop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
start(playlistId) {
|
|
|
this.stop();
|
|
|
|
|
|
@@ -63,6 +76,10 @@ export class PlaylistSrv {
|
|
|
this.index = 0;
|
|
|
this.isPlaying = true;
|
|
|
|
|
|
+ // setup location tracking
|
|
|
+ this.storeUnsub = store.subscribe(() => this.storeUpdated());
|
|
|
+ this.validPlaylistUrl = this.$location.path();
|
|
|
+
|
|
|
appEvents.emit('playlist-started');
|
|
|
|
|
|
return this.backendSrv.get(`/api/playlists/${playlistId}`).then(playlist => {
|
|
|
@@ -85,6 +102,10 @@ export class PlaylistSrv {
|
|
|
this.index = 0;
|
|
|
this.isPlaying = false;
|
|
|
|
|
|
+ if (this.storeUnsub) {
|
|
|
+ this.storeUnsub();
|
|
|
+ }
|
|
|
+
|
|
|
if (this.cancelPromise) {
|
|
|
this.$timeout.cancel(this.cancelPromise);
|
|
|
}
|