Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change color for changed tasks (before not different from not-changed) #571

Merged
merged 5 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions saltgui/static/scripts/Character.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ export class Character {
Character.WHITE_RIGHT_POINTING_TRIANGLE = "\u25B7";
Character.BLACK_RIGHT_POINTING_POINTER = "\u25BA";
Character.WHITE_DOWN_POINTING_TRIANGLE = "\u25BD";
Character.BLACK_CIRCLE_WITH_OUTLINE = "\u25C9";
Character.BLACK_DIAMOND = "\u25C6";
Character.BLACK_CIRCLE = "\u25CF";
Character.GEAR = "\u2699";
Character.WARNING_SIGN = "\u26A0" + Character._VARIATION_SELECTOR_16;
Character.HEAVY_CHECK_MARK = "\u2714";
Character.HEAVY_MULTIPLICATION_X = "\u2716" + Character._VARIATION_SELECTOR_15;
Character.HEAVY_BALLOT_X = "\u2718";
Character.BLACK_QUESTION_MARK_ORNAMENT = "\u2753" + Character._VARIATION_SELECTOR_15;
Character._BLACK_MEDIUM_RIGHT_POINTING_TRIANGLE = "\u2BC8";

Expand Down
105 changes: 77 additions & 28 deletions saltgui/static/scripts/output/Output.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,80 @@ export class Output {
return false;
}

static getTaskNrChanges (pTask) {
if (!pTask.changes) {
return 0;
}
if (typeof pTask.changes !== "object") {
return 1;
}
if (Array.isArray(pTask.changes)) {
return pTask.changes.length;
}
if (Object.keys(pTask.changes).length === 0) {
// empty changes object does not count as real change
return 0;
}
return 1;
}

static getTaskCharacter (pTask) {
if (!pTask.changes) {
return Character.BLACK_CIRCLE;
}
if (typeof pTask.changes !== "object") {
return Character.BLACK_DIAMOND;
}
if (Array.isArray(pTask.changes)) {
return pTask.changes.length === 0 ? Character.BLACK_CIRCLE : Character.BLACK_DIAMOND;
}
if (Object.keys(pTask.changes).length === 0) {
// empty changes object does not count as real change
return Character.BLACK_CIRCLE;
}
return Character.BLACK_DIAMOND;
}

static _getTaskChanges (pTask) {
if (!pTask.changes) {
return "";
}
if (typeof pTask.changes !== "object") {
return "\n'changes' has type " + typeof pTask.changes;
}
if (Array.isArray(pTask.changes)) {
const nrChanges = pTask.changes.length;
return Utils.txtZeroOneMany(
nrChanges,
"\n'changes' is an empty array",
"\n'changes' is an array\n" + nrChanges + " change",
"\n'changes' is an array\n" + nrChanges + " changes");
}
if (Object.keys(pTask.changes).length === 0) {
// empty changes object does not count as real change
return "";
}
return "\nchanged";
}

static getTaskClass (pTask) {
let className;

if (pTask.result === null) {
className = "task-skipped";
} else if (pTask.result === false) {
className = "task-failure";
} else {
className = "task-success";
}

if (Output.getTaskNrChanges(pTask) > 0) {
className += "-changes";
}

return className;
}

static _setTaskToolTip (pSpan, pTask) {

if (typeof pTask !== "object") {
Expand All @@ -362,40 +436,15 @@ export class Output {
txt += "\n" + functionName;
}

let nrChanges;
if (!pTask.changes) {
nrChanges = 0;
} else if (typeof pTask.changes !== "object") {
nrChanges = 1;
txt += "\n'changes' has type " + typeof pTask.changes;
} else if (Array.isArray(pTask.changes)) {
nrChanges = pTask.changes.length;
txt += "\n'changes' is an array";
txt += Utils.txtZeroOneMany(nrChanges, "", "\n" + nrChanges + " change", "\n" + nrChanges + " changes");
} else if (typeof pTask.changes === "object" && Object.keys(pTask.changes).length === 0) {
// empty changes object does not count as real change
nrChanges = 0;
} else {
nrChanges = 1;
txt += "\nchanged";
}
txt += Output._getTaskChanges(pTask);

if (Output.isHiddenTask(pTask)) {
txt += "\nhidden";
}

pSpan.className = "taskcircle";
if (pTask.result === null) {
pSpan.classList.add("task-skipped");
} else if (pTask.result) {
pSpan.classList.add("task-success");
} else {
pSpan.classList.add("task-failure");
}
if (nrChanges) {
pSpan.classList.add("task-changes");
pSpan.innerText = Character.BLACK_CIRCLE_WITH_OUTLINE;
}
pSpan.classList.add(Output.getTaskClass(pTask));
pSpan.innerText = Output.getTaskCharacter(pTask);

for (const key in pTask) {
/* eslint-disable curly */
Expand Down
28 changes: 7 additions & 21 deletions saltgui/static/scripts/output/OutputHighstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,8 @@ export class OutputHighstate {

const functionName = components[0] + "." + components[3];

let hasChanges = false;
let chgs = null;
if (task["changes"] !== undefined) {
chgs = task.changes;
const keys = Object.keys(chgs);
if (keys.length === 2 && keys[0] === "out" && keys[1] === "ret") {
chgs = chgs["ret"];
}
const str = JSON.stringify(chgs);
if (str !== "{}") {
hasChanges = true;
}
changesDetail += Object.keys(chgs).length;
}
const nrChanges = Output.getTaskNrChanges(task);
changesDetail += nrChanges;

const taskId = components[1];
let taskName = components[2];
Expand All @@ -156,23 +144,21 @@ export class OutputHighstate {
taskSpan = OutputHighstateTaskTerse.getStateOutput(task, taskName, functionName);
} else if (Output.isStateOutputSelected("mixed") && task.result) {
taskSpan = OutputHighstateTaskTerse.getStateOutput(task, taskName, functionName);
} else if (Output.isStateOutputSelected("changes") && task.result && hasChanges) {
} else if (Output.isStateOutputSelected("changes") && task.result && nrChanges) {
taskSpan = OutputHighstateTaskTerse.getStateOutput(task, taskName, functionName);
} else if (Output.isOutputFormatAllowed("saltguihighstate")) {
taskSpan = OutputHighstateTaskSaltGui.getStateOutput(task, taskId, taskName, functionName, pMinionId, pJobId);
} else {
taskSpan = OutputHighstateTaskFull.getStateOutput(task, taskId, taskName, functionName);
}

taskSpan.classList.add(Output.getTaskClass(task));
if (task.result === null) {
taskSpan.classList.add("task-skipped");
// VOID
} else if (!task.result) {
taskSpan.classList.add("task-failure");
} else if (hasChanges) {
taskSpan.classList.add("task-changes");
// VOID
} else if (nrChanges) {
changesSummary += 1;
} else {
taskSpan.classList.add("task-success");
}
const taskDiv = Utils.createDiv("", "", Utils.getIdFromMinionId(pMinionId + "." + nr));
taskDiv.append(taskSpan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class OutputHighstateSummaryOriginal {
pDiv.append(oSpan);

txt = "changed=" + pChangesSummary;
const changedSpan = Utils.createSpan("task-changes", txt);
const changedSpan = Utils.createSpan("task-success-changes", txt);
pDiv.append(changedSpan);

txt = ")";
Expand Down
13 changes: 2 additions & 11 deletions saltgui/static/scripts/output/OutputHighstateTaskSaltGui.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,8 @@ export class OutputHighstateTaskSaltGui {
const taskDiv = Utils.createDiv();

const span = Utils.createSpan("task-icon");
if (pTask.result === null) {
span.innerText = Character.HEAVY_CHECK_MARK;
span.classList.add("task-skipped");
} else if (pTask.result) {
span.innerText = Character.HEAVY_CHECK_MARK;
span.classList.add("task-success");
} else {
span.innerText = Character.HEAVY_BALLOT_X;
span.classList.add("task-failure");
}
// don't use task-changes here
span.innerText = Output.getTaskCharacter(pTask);
span.classList.add(Output.getTaskClass(pTask));
taskDiv.append(span);

taskDiv.append(document.createTextNode(pTaskName));
Expand Down
63 changes: 34 additions & 29 deletions saltgui/static/scripts/panels/HighState.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export class HighStatePanel extends Panel {
// we may use it for presentation (keys.length <= this._maxHighstateStates); or
// for information (keys.length > this._maxHighstateStates)

const span = Utils.createSpan("task", Character.BLACK_CIRCLE);
const span = Utils.createSpan("task");
span.style.backgroundColor = "black";

// this also sets the span's class(es)
Expand All @@ -438,32 +438,38 @@ export class HighStatePanel extends Panel {
span.classList.add("task");

if (keys.length > this._maxHighstateStates) {
let statKey = "";
let prio = 0;

// statkeys are sortable on their priority
if (span.classList.contains("task-skipped")) {
statKey = "task-skipped";
prio = 31;
} else if (span.classList.contains("task-success")) {
statKey = "task-success";
prio = 41;
} else if (span.classList.contains("task-failure")) {
statKey = "task-failure";
prio = 21;
} else {
statKey = "task-unknown";
prio = 11;
}

if (span.classList.contains("task-changes")) {
prio -= 1;
statKey += " task-changes";
span.innerText = Character.BLACK_CIRCLE_WITH_OUTLINE;
const taskClass = Output.getTaskClass(data);
const taskChar = Output.getTaskCharacter(data);

// priority must always be a 2-digit value (i.e. 10..99)
let priority;

// taskClass is to be sorted on its priority (low to high)
switch (taskClass) {
case "task-success":
priority = 41;
break;
case "task-success-changes":
priority = 40;
break;
case "task-skipped":
priority = 31;
break;
case "task-skipped-changes":
priority = 30;
break;
case "task-failure":
priority = 21;
break;
case "task-failure-changes":
priority = 20;
break;
default:
priority = 11;
}

// allow keys to be sortable
statKey = prio + statKey;
const statKey = priority + taskClass + taskChar;

if (statKey in stats) {
stats[statKey] += 1;
Expand Down Expand Up @@ -491,18 +497,17 @@ export class HighStatePanel extends Panel {

// show the summary when one was build up
for (const statKey of Object.keys(stats).sort()) {
const character = statKey.substring(statKey.length - 1);
const className = statKey.substring(2, statKey.length - 1);
const sepSpan = Utils.createSpan("", sep + stats[statKey] + Character.MULTIPLICATION_SIGN);
summarySpan.append(sepSpan);
sep = " ";

// remove the priority indicator from the key
const itemSpan = Utils.createSpan(["tasksummary", "taskcircle"], Character.BLACK_CIRCLE);
itemSpan.classList.add(...statKey.substring(2).split(" "));
if(itemSpan.classList.contains("task-changes")) {
itemSpan.innerText = Character.BLACK_CIRCLE_WITH_OUTLINE;
}
const itemSpan = Utils.createSpan(["tasksummary", className], character);
itemSpan.style.backgroundColor = "black";
summarySpan.append(itemSpan);
Utils.addToolTip(itemSpan, className.replace("task-", "").replace("-", " with "));
}

// allow similar navigation, but just only to the job level
Expand Down
Loading
Loading