Skip to content

Commit c3b9ccb

Browse files
author
Erwin Dondorp
committed
made play/pause more generic
1 parent 499557e commit c3b9ccb

10 files changed

Lines changed: 96 additions & 66 deletions

File tree

saltgui/static/scripts/Utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,13 @@ export class Utils {
446446
} else {
447447
txt = pManyText;
448448
}
449-
txt = txt.replace("{0}", pCnt.toLocaleString());
449+
if (pCnt === undefined) {
450+
// just in case
451+
txt = txt.replace("{0}", pCnt);
452+
console.log(pCnt, pZeroText, pOneText, pManyText);
453+
} else {
454+
txt = txt.replace("{0}", pCnt.toLocaleString());
455+
}
450456
return txt;
451457
}
452458

saltgui/static/scripts/issues/State.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export class StateIssues extends Issues {
3838
}
3939

4040
this.jobs = jobs;
41-
pPanel.setPlayPauseButton("play");
41+
// this is good only while "State" is the only issue-provider
42+
pPanel.setPlayPauseButton(jobs.length === 0 ? "none" : "play");
4243

4344
this._updateNextJob(pPanel, pMsg);
4445
}
@@ -48,11 +49,20 @@ export class StateIssues extends Issues {
4849
return;
4950
}
5051
if (!this.jobs.length) {
52+
// this is good only while "State" is the only issue-provider
5153
pPanel.setPlayPauseButton("none");
5254
this.jobs = null;
5355
Issues.readyCategory(pPanel, pMsg);
5456
return;
5557
}
58+
59+
if (pPanel.playOrPause !== "play") {
60+
window.setTimeout(() => {
61+
this._updateNextJob(pPanel, pMsg);
62+
}, 1000);
63+
return;
64+
}
65+
5666
const job = this.jobs.pop();
5767

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

saltgui/static/scripts/panels/BeaconsMinion.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class BeaconsMinionPanel extends Panel {
2020
this._addPanelMenuItemBeaconsReset();
2121
this._addPanelMenuItemBeaconsSave();
2222
this.addSearchButton();
23-
this.addPlayPauseButton("play");
23+
this.addPlayPauseButton();
2424
this.addCloseButton();
2525
this.addHelpButton([
2626
"The content of column 'Value' is automatically refreshed.",
@@ -93,19 +93,15 @@ export class BeaconsMinionPanel extends Panel {
9393
updateFooter () {
9494
// update the footer
9595
const tbody = this.table.tBodies[0];
96-
let txt = Utils.txtZeroOneMany(tbody.rows.length,
96+
const txt = Utils.txtZeroOneMany(tbody.rows.length,
9797
"No beacons", "{0} beacon", "{0} beacons");
98-
99-
if (this.playOrPause === "pause") {
100-
txt += ", press " + Character.buttonInText(Character.CH_PLAY) + " to continue";
101-
}
102-
103-
this.setMsg(txt, true);
98+
this.setMsg(txt);
10499
}
105100

106101
_handleLocalBeaconsList (pLocalBeaconsListData, pMinionId) {
107102
if (this.showErrorRowInstead(pLocalBeaconsListData)) {
108103
this.setPlayPauseButton("none");
104+
this.updateFooter();
109105
return;
110106
}
111107

@@ -194,6 +190,8 @@ export class BeaconsMinionPanel extends Panel {
194190
tr.appendChild(helpButtonTd);
195191
}
196192

193+
this.setPlayPauseButton(keys.length === 0 ? "none" : "play");
194+
197195
this.updateFooter();
198196
}
199197

saltgui/static/scripts/panels/Events.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* global document */
22

3-
import {Character} from "../Character.js";
43
import {Output} from "../output/Output.js";
54
import {Panel} from "./Panel.js";
65
import {Utils} from "../Utils.js";
@@ -14,14 +13,16 @@ export class EventsPanel extends Panel {
1413

1514
this.addTitle("Recent Events");
1615
this.addSearchButton();
17-
this.addPlayPauseButton("pause");
16+
this.addPlayPauseButton();
1817
this.addHelpButton([
1918
"The content of this page is",
2019
"automatically refreshed.",
2120
"Display is limited to " + MAX_EVENTS_IN_VIEW + " events."
2221
]);
2322
this.addTable(["Timestamp", "Tag", "Data"]);
2423
this.addMsg();
24+
25+
this.setPlayPauseButton("pause");
2526
}
2627

2728
onShow () {
@@ -32,26 +33,18 @@ export class EventsPanel extends Panel {
3233
// update the footer
3334
const tbody = this.table.tBodies[0];
3435
// when there are more than a screen-ful of events, the user
35-
// will not see the "press play" message. but ths user already
36-
// knows that because that cause the events to be shown...
36+
// will not see the "press play" message. but the user already
37+
// knows that because that caused the events to be shown...
3738
let txt = Utils.txtZeroOneMany(tbody.rows.length,
3839
"No events", "{0} event", "{0} events");
39-
/* eslint-disable no-lonely-if */
4040
if (this.playOrPause === "play") {
4141
if (tbody.rows.length) {
4242
txt += ", waiting for more events";
4343
} else {
4444
txt += ", waiting for events";
4545
}
46-
} else {
47-
if (tbody.rows.length) {
48-
txt += ", press " + Character.buttonInText(Character.CH_PLAY) + " to continue";
49-
} else {
50-
txt += ", press " + Character.buttonInText(Character.CH_PLAY) + " to begin";
51-
}
5246
}
53-
/* eslint-enable no-lonely-if */
54-
this.setMsg(txt, true);
47+
this.setMsg(txt);
5548
}
5649

5750
handleAnyEvent (pTag, pData) {

saltgui/static/scripts/panels/HighState.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class HighStatePanel extends Panel {
2121
this._addMenuItemStateApply(this.panelMenu, "*");
2222
this._addMenuItemStateApplyTest(this.panelMenu, "*");
2323
this.addSearchButton();
24-
this.addPlayPauseButton("none");
24+
this.addPlayPauseButton();
2525
this.addHelpButton([
2626
"This panel shows the latest state.highstate or state.apply job for each minion.",
2727
"Only the latest " + MAX_HIGHSTATE_JOBS + " jobs are verified.",
@@ -104,13 +104,9 @@ export class HighStatePanel extends Panel {
104104

105105
updateFooter () {
106106
const tbody = this.table.tBodies[0];
107-
let txt = Utils.txtZeroOneMany(tbody.rows.length,
107+
const txt = Utils.txtZeroOneMany(tbody.rows.length,
108108
"No minions", "{0} minion", "{0} minions");
109-
110-
if (this.playOrPause === "pause") {
111-
txt += ", press " + Character.buttonInText(Character.CH_PLAY) + " to continue";
112-
}
113-
this.setMsg(txt, true);
109+
this.setMsg(txt);
114110
}
115111

116112
_handleHighstateRunnerJobsListJobs (pData) {
@@ -134,7 +130,7 @@ export class HighStatePanel extends Panel {
134130

135131
this.jobs = jobs;
136132

137-
this.setPlayPauseButton("play");
133+
this.setPlayPauseButton(jobs.length === 0 ? "none" : "play");
138134

139135
this._updateNextJob();
140136
}

saltgui/static/scripts/panels/Issues.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class IssuesPanel extends Panel {
1616

1717
this.addTitle("Issues (beta)");
1818
this.addSearchButton();
19-
this.addPlayPauseButton("none");
19+
this.addPlayPauseButton();
2020
this.addHelpButton([
2121
"This page contains an overview of problems",
2222
"that are observed in various categories.",
@@ -44,6 +44,10 @@ export class IssuesPanel extends Panel {
4444
this.lowStateIssues = new StateIssues();
4545
}
4646

47+
updateFooter () {
48+
this.setMsg("(loading)");
49+
}
50+
4751
onShow () {
4852
const p1 = this.keysIssues.onGetIssues(this);
4953
const p2 = this.jobsIssues.onGetIssues(this);
@@ -60,7 +64,7 @@ export class IssuesPanel extends Panel {
6064
this.setMsg("");
6165
}, (pErrorMsg) => {
6266
this.setMsg("(error)");
63-
Utils.addToolTip(this.msg, pErrorMsg);
67+
Utils.addToolTip(this.msgDiv, pErrorMsg);
6468
});
6569
}
6670
}

saltgui/static/scripts/panels/Jobs.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* global */
22

3-
import {Character} from "../Character.js";
43
import {Panel} from "./Panel.js";
54
import {Utils} from "../Utils.js";
65

@@ -210,9 +209,7 @@ export class JobsPanel extends Panel {
210209
this.numberOfJobsEligible = numberOfJobsEligible;
211210
this.numberOfJobsPresent = numberOfJobsPresent;
212211

213-
// an intermediate timer event may have caused
214-
// the button to be hidden
215-
this.setPlayPauseButton("play");
212+
this.setPlayPauseButton(numberOfJobsShown === 0 ? "none" : "play");
216213

217214
this.updateFooter();
218215

@@ -228,12 +225,7 @@ export class JobsPanel extends Panel {
228225
}
229226
txt += Utils.txtZeroOneMany(this.numberOfJobsPresent,
230227
"", ", {0} job present", ", {0} jobs present");
231-
232-
if (this.playOrPause === "pause") {
233-
txt += ", press " + Character.buttonInText(Character.CH_PLAY) + " to continue";
234-
}
235-
236-
this.setMsg(txt, true);
228+
this.setMsg(txt);
237229
}
238230

239231
static _jobsToArray (jobs) {

saltgui/static/scripts/panels/JobsDetails.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class JobsDetailsPanel extends JobsPanel {
1919
this._addPanelMenuItemShowEligible();
2020
this._addPanelMenuItemShowAll();
2121
this.addSearchButton();
22-
this.addPlayPauseButton("play");
22+
this.addPlayPauseButton();
2323
this.addHelpButton([
2424
"Entries for jobs that are primarily used by SaltGUI are normally hidden.",
2525
"It is possible to define exceptions on that, and also to define additions to that.",

saltgui/static/scripts/panels/Keys.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* global window */
22

3-
import {Character} from "../Character.js";
43
import {DropDownMenu} from "../DropDown.js";
54
import {Panel} from "./Panel.js";
65
import {Utils} from "../Utils.js";
@@ -22,7 +21,7 @@ export class KeysPanel extends Panel {
2221
this._addPanelMenuItemWheelKeyRejectAllUnacceptedAcceptedDenied();
2322
this._addPanelMenuItemWheelKeyDeleteAll();
2423
this.addSearchButton();
25-
this.addPlayPauseButton("play");
24+
this.addPlayPauseButton();
2625
this.addHelpButton([
2726
"The content of this page is",
2827
"automatically refreshed."
@@ -32,6 +31,8 @@ export class KeysPanel extends Panel {
3231
this.addMsg();
3332

3433
this.fingerprintPattern = /^[0-9a-f:]+$/i;
34+
35+
this.setPlayPauseButton("play");
3536
}
3637

3738
onShow () {
@@ -173,16 +174,12 @@ export class KeysPanel extends Panel {
173174
// capitalize the first word (can only be "no")
174175
txt = txt.replace(/^no/, "No");
175176

176-
if (this.playOrPause === "pause") {
177-
txt += ", press " + Character.buttonInText(Character.CH_PLAY) + " to continue";
178-
}
179-
180177
KeysPanel.cntUnaccepted = cnt["unaccepted"];
181178
KeysPanel.cntAccepted = cnt["accepted"];
182179
KeysPanel.cntDenied = cnt["denied"];
183180
KeysPanel.cntRejected = cnt["rejected"];
184181

185-
this.setMsg(txt, true);
182+
this.setMsg(txt);
186183
}
187184

188185
static _flagMinion (pMinionId, pMinionTr, pMinionsDict) {

saltgui/static/scripts/panels/Panel.js

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class Panel {
6767
this.searchButton = span;
6868
}
6969

70-
addPlayPauseButton (pInitialStatus) {
70+
addPlayPauseButton () {
7171
const playButton = document.createElement("span");
7272
playButton.innerText = Character.CH_PLAY;
7373
playButton.classList.add("small-button");
@@ -102,7 +102,7 @@ export class Panel {
102102
pClickEvent.stopPropagation();
103103
});
104104

105-
this.setPlayPauseButton(pInitialStatus);
105+
this.setPlayPauseButton("none");
106106
}
107107

108108
setPlayPauseButton (pStatus) {
@@ -113,6 +113,7 @@ export class Panel {
113113
if (this.pauseButton) {
114114
this.pauseButton.style.display = pStatus === "play" ? "" : "none";
115115
}
116+
this._updateMsg();
116117
}
117118

118119
addHelpButton (pHelpTextArr, pUrl) {
@@ -238,19 +239,52 @@ export class Panel {
238239
}
239240

240241
addMsg () {
241-
const msg = document.createElement("div");
242-
msg.id = this.key + "-msg";
243-
msg.classList.add("msg");
244-
msg.innerText = "(loading)";
245-
this.div.appendChild(msg);
246-
this.msg = msg;
242+
const msgDiv = document.createElement("div");
243+
msgDiv.id = this.key + "-msg";
244+
msgDiv.classList.add("msg");
245+
this.div.appendChild(msgDiv);
246+
this.msgDiv = msgDiv;
247+
this.setMsg("(loading)");
247248
}
248249

249-
setMsg (pText, isHTML = false) {
250+
setMsg (pText) {
251+
this.msgTxt = pText;
252+
this._updateMsg();
253+
}
254+
255+
_updateMsg () {
256+
if (!this.msgDiv) {
257+
// the div is not created yet
258+
return;
259+
}
260+
261+
let txt = this.msgTxt;
262+
let isHTML = false;
263+
264+
if (this.playOrPause === "pause" && this.pauseButton) {
265+
if (txt) {
266+
txt += ", ";
267+
}
268+
if (this.table && this.table.tBodies[0].rows.length) {
269+
txt += "press " + Character.buttonInText(Character.CH_PLAY) + " to continue";
270+
} else {
271+
txt += "press " + Character.buttonInText(Character.CH_PLAY) + " to begin";
272+
}
273+
isHTML = true;
274+
}
275+
276+
if (this.playOrPause === "play" && this.playButton) {
277+
if (txt) {
278+
txt += ", ";
279+
}
280+
txt += "press " + Character.buttonInText(Character.CH_PAUSE) + " to pause";
281+
isHTML = true;
282+
}
283+
250284
if (isHTML) {
251-
this.msg.innerHTML = pText;
285+
this.msgDiv.innerHTML = txt;
252286
} else {
253-
this.msg.innerText = pText;
287+
this.msgDiv.innerText = txt;
254288
}
255289
}
256290

@@ -315,8 +349,8 @@ export class Panel {
315349
this.table.tFoot.appendChild(tr);
316350

317351
// hide the "(loading)" message
318-
if (this.msg !== null) {
319-
this.msg.style.display = "none";
352+
if (this.msgDiv) {
353+
this.msgDiv.style.display = "none";
320354
}
321355

322356
return true;
@@ -725,8 +759,8 @@ export class Panel {
725759
if (this.table) {
726760
this.clearTable();
727761
}
728-
if (this.msg) {
729-
this.msg.innerText = "(loading)";
762+
if (this.msgDiv) {
763+
this.setMsg("(loading)");
730764
}
731765
if (this.timeField) {
732766
this.timeField.innerHTML = " ";

0 commit comments

Comments
 (0)