Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
1ab548f4
Unverified
Commit
1ab548f4
authored
Mar 06, 2019
by
Torkel Ödegaard
Committed by
GitHub
Mar 06, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15832 from grafana/stop-playlist
Alternative fix to detecting when to stop a playlist
parents
2604e9e4
3375c72d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
2 deletions
+62
-2
public/app/features/playlist/playlist_srv.ts
+23
-2
public/app/features/playlist/specs/playlist_srv.test.ts
+39
-0
No files found.
public/app/features/playlist/playlist_srv.ts
View file @
1ab548f4
...
...
@@ -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
);
}
...
...
public/app/features/playlist/specs/playlist_srv.test.ts
View file @
1ab548f4
import
configureMockStore
from
'redux-mock-store'
;
import
{
PlaylistSrv
}
from
'../playlist_srv'
;
import
{
setStore
}
from
'app/store/store'
;
const
mockStore
=
configureMockStore
();
setStore
(
mockStore
({
location
:
{},
})
);
const
dashboards
=
[{
url
:
'dash1'
},
{
url
:
'dash2'
}];
...
...
@@ -19,6 +29,7 @@ const createPlaylistSrv = (): [PlaylistSrv, { url: jest.MockInstance<any, any> }
const
mockLocation
=
{
url
:
jest
.
fn
(),
search
:
()
=>
({}),
path
:
()
=>
'/playlists/1'
,
};
const
mockTimeout
=
jest
.
fn
();
...
...
@@ -96,4 +107,32 @@ describe('PlaylistSrv', () => {
expect
(
hrefMock
).
toHaveBeenCalledTimes
(
3
);
expect
(
hrefMock
).
toHaveBeenLastCalledWith
(
initialUrl
);
});
it
(
'storeUpdated should stop playlist when navigating away'
,
async
()
=>
{
await
srv
.
start
(
1
);
srv
.
storeUpdated
();
expect
(
srv
.
isPlaying
).
toBe
(
false
);
});
it
(
'storeUpdated should not stop playlist when navigating to next dashboard'
,
async
()
=>
{
await
srv
.
start
(
1
);
srv
.
next
();
setStore
(
mockStore
({
location
:
{
path
:
'dash2'
,
},
})
);
expect
((
srv
as
any
).
validPlaylistUrl
).
toBe
(
'dash2'
);
srv
.
storeUpdated
();
expect
(
srv
.
isPlaying
).
toBe
(
true
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment