Skip to content

Commit 2a07c05

Browse files
authored
Merge pull request #583 from erwindon/timers-off
timers are not always stopped when leaving a page
2 parents 3f3571a + 32587a9 commit 2a07c05

File tree

14 files changed

+103
-32
lines changed

14 files changed

+103
-32
lines changed

saltgui/static/scripts/issues/State.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,39 +65,41 @@ export class StateIssues extends Issues {
6565
jobs = jobs.slice(0, MAX_HIGHSTATE_JOBS);
6666
}
6767

68-
this.jobs = jobs;
68+
pPanel.jobs = jobs;
6969
// this is good only while "State" is the only issue-provider that uses play/pause
7070
pPanel.setPlayPauseButton(jobs.length === 0 ? "none" : "play");
7171

7272
this._updateNextJob(pPanel, pMsg, pKeys);
7373
}
7474

7575
_updateNextJob (pPanel, pMsg, pKeys) {
76-
if (!this.jobs) {
76+
if (!pPanel.jobs) {
7777
return;
7878
}
79-
if (!this.jobs.length) {
79+
if (!pPanel.jobs.length) {
8080
// this is good only while "State" is the only issue-provider
8181
pPanel.setPlayPauseButton("none");
82-
this.jobs = null;
82+
pPanel.jobs = null;
8383
Issues.readyCategory(pPanel, pMsg);
8484
return;
8585
}
8686

8787
if (pPanel.playOrPause !== "play") {
88-
window.setTimeout(() => {
88+
pPanel.issuesStateTimeout = window.setTimeout(() => {
89+
pPanel.issuesStateTimeout = null;
8990
this._updateNextJob(pPanel, pMsg, pKeys);
9091
}, 1000);
9192
return;
9293
}
9394

94-
const job = this.jobs.pop();
95+
const job = pPanel.jobs.pop();
9596

9697
const runnerJobsListJobPromise = this.api.getRunnerJobsListJob(job.id);
9798

9899
runnerJobsListJobPromise.then((pRunnerJobsListJobData) => {
99100
StateIssues._handleJobRunnerJobsListJob(pPanel, pRunnerJobsListJobData, pKeys);
100-
window.setTimeout(() => {
101+
pPanel.issuesStateTimeout = window.setTimeout(() => {
102+
pPanel.issuesStateTimeout = null;
101103
this._updateNextJob(pPanel, pMsg, pKeys);
102104
}, 100);
103105
return true;

saltgui/static/scripts/pages/HighState.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ export class HighStatePage extends Page {
2323
this.jobs.handleSaltJobRetEvent(pData);
2424
}
2525
}
26+
27+
onHide () {
28+
this.highstate.onHide();
29+
}
2630
}

saltgui/static/scripts/pages/Issues.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ export class IssuesPage extends Page {
2323
this.jobs.handleSaltJobRetEvent(pData);
2424
}
2525
}
26+
27+
onHide () {
28+
this.issues.onHide();
29+
}
2630
}

saltgui/static/scripts/pages/Job.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ export class JobPage extends Page {
1515
handleSaltJobRetEvent (pData) {
1616
this.job.handleSaltJobRetEvent(pData);
1717
}
18+
19+
onHide () {
20+
this.job.onHide();
21+
}
1822
}

saltgui/static/scripts/pages/Jobs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ export class JobsPage extends Page {
1515
handleSaltJobRetEvent (pData) {
1616
this.jobs.handleSaltJobRetEvent(pData);
1717
}
18+
19+
onHide () {
20+
this.jobs.onHide();
21+
}
1822
}

saltgui/static/scripts/pages/Logout.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class LogoutPage extends Page {
1212
onRegister () {
1313
// don't verify for invalid sessions too often
1414
// this happens only when the server was reset
15-
this.logoutTimer = window.setInterval(() => {
15+
this.logoutInterval = window.setInterval(() => {
1616
this._logoutTimer();
1717
}, 60000);
1818

@@ -51,9 +51,9 @@ export class LogoutPage extends Page {
5151
// not to any regular api functions
5252
// may happen due to https://github.com/saltstack/salt/issues/59620
5353
// repeating this is not so useful
54-
if (this.logoutTimer) {
55-
clearInterval(this.logoutTimer);
56-
this.logoutTimer = null;
54+
if (this.logoutInterval) {
55+
clearInterval(this.logoutInterval);
56+
this.logoutInterval = null;
5757
}
5858
return;
5959
}

saltgui/static/scripts/pages/Nodegroups.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ export class NodegroupsPage extends Page {
3131
const nodegroups = Utils.getStorageItemObject("session", "nodegroups");
3232
return Object.keys(nodegroups).length > 0;
3333
}
34+
35+
onHide () {
36+
this.nodegroups.onHide();
37+
}
3438
}

saltgui/static/scripts/panels/HighState.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ export class HighStatePanel extends Panel {
8585
});
8686
}
8787

88+
onHide () {
89+
if (this.nextJobTimeout) {
90+
// stop the timer when nobody is looking
91+
window.clearTimeout(this.nextJobTimeout);
92+
this.nextJobTimeout = null;
93+
}
94+
}
95+
8896
_addMenuItemStateApply (pMenu, pMinionId) {
8997
pMenu.addMenuItem("Apply state...", () => {
9098
const cmdArr = ["state.apply"];
@@ -205,7 +213,8 @@ export class HighStatePanel extends Panel {
205213
this._handleJob(job);
206214
}
207215

208-
window.setTimeout(() => {
216+
this.nextJobTimeout = window.setTimeout(() => {
217+
this.nextJobTimeout = null;
209218
this._updateNextJob();
210219
}, 1000);
211220
}

saltgui/static/scripts/panels/Issues.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,15 @@ export class IssuesPanel extends Panel {
6666
Utils.addToolTip(this.msgDiv, pErrorMsg);
6767
});
6868
}
69+
70+
onHide () {
71+
// from StateIssues
72+
this.jobs = null;
73+
74+
if (this.issuesStateTimeout) {
75+
// stop the timer when nobody is looking
76+
window.clearTimeout(this.issuesStateTimeout);
77+
this.issuesStateTimeout = null;
78+
}
79+
}
6980
}

saltgui/static/scripts/panels/Job.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export class JobPanel extends Panel {
7474
return;
7575
}
7676

77-
window.setTimeout(() => {
77+
this.refreshJobTimeout = window.setTimeout(() => {
78+
this.refreshJobTimeout = null;
7879
if (this.playOrPause === "play") {
7980
this.onShow();
8081
} else {
@@ -118,6 +119,14 @@ export class JobPanel extends Panel {
118119
this.setPlayPauseButton(jobRefresh);
119120
}
120121

122+
onHide () {
123+
if (this.refreshJobTimeout) {
124+
// stop the timer when nobody is looking
125+
window.clearTimeout(this.refreshJobTimeout);
126+
this.refreshJobTimeout = null;
127+
}
128+
}
129+
121130
static _isResultOk (result) {
122131
if (!result.success) {
123132
return false;

0 commit comments

Comments
 (0)