|
30 | 30 |
|
31 | 31 | import static org.jboss.elemento.Elements.div; |
32 | 32 | import static org.jboss.elemento.Elements.span; |
33 | | -import static org.jboss.hal.resources.CSS.*; |
| 33 | +import static org.jboss.hal.resources.CSS.progress; |
| 34 | +import static org.jboss.hal.resources.CSS.progressBar; |
| 35 | +import static org.jboss.hal.resources.CSS.progressBarDanger; |
| 36 | +import static org.jboss.hal.resources.CSS.progressBarRemaining; |
| 37 | +import static org.jboss.hal.resources.CSS.progressBarSuccess; |
| 38 | +import static org.jboss.hal.resources.CSS.progressBarWarning; |
| 39 | +import static org.jboss.hal.resources.CSS.progressContainer; |
| 40 | +import static org.jboss.hal.resources.CSS.progressDescription; |
| 41 | +import static org.jboss.hal.resources.CSS.progressDescriptionLeft; |
| 42 | +import static org.jboss.hal.resources.CSS.progressLabelRight; |
| 43 | +import static org.jboss.hal.resources.CSS.progressLabelTopRight; |
| 44 | +import static org.jboss.hal.resources.CSS.srOnly; |
| 45 | +import static org.jboss.hal.resources.CSS.width; |
34 | 46 | import static org.jboss.hal.resources.UIConstants.PROGRESSBAR; |
35 | 47 | import static org.jboss.hal.resources.UIConstants.ROLE; |
36 | 48 | import static org.jboss.hal.resources.UIConstants.TOGGLE; |
@@ -106,46 +118,44 @@ public void update(long current) { |
106 | 118 | } |
107 | 119 |
|
108 | 120 | public void update(long current, long total) { |
109 | | - if (current <= total) { |
110 | | - this.total = total; |
111 | | - double currentPercent = Math.round(((double) current) / ((double) total) * 100.0); |
112 | | - long remaining = total - current; |
113 | | - double remainingPercent = 100.0 - currentPercent; |
114 | | - |
115 | | - valueBar.setAttribute(aria(VALUE_NOW), String.valueOf(current)); |
116 | | - valueBar.setAttribute(aria(VALUE_MAX), String.valueOf(total)); |
117 | | - valueBar.style.width = width(currentPercent + "%"); |
118 | | - Tooltip.element(valueBar).setTitle(MESSAGES.used(currentPercent)); |
119 | | - // noinspection HardCodedStringLiteral |
120 | | - valueElement.innerHTML = new SafeHtmlBuilder() |
121 | | - .appendHtmlConstant("<strong>") |
122 | | - .appendEscaped(MESSAGES.currentOfTotal(current, total)) |
123 | | - .appendHtmlConstant("</strong>") |
124 | | - .appendEscaped(" " + unit) |
125 | | - .toSafeHtml().asString(); |
126 | | - |
127 | | - remainingBar.setAttribute(aria(VALUE_NOW), String.valueOf(remaining)); |
128 | | - remainingBar.setAttribute(aria(VALUE_MAX), String.valueOf(total)); |
129 | | - remainingBar.style.width = width(remainingPercent + "%"); |
130 | | - Tooltip.element(remainingBar).setTitle(MESSAGES.available(remainingPercent)); |
131 | | - remainingElement.textContent = MESSAGES.available(remainingPercent); |
132 | | - |
133 | | - if (thresholds) { |
134 | | - valueBar.classList.remove(progressBarDanger); |
135 | | - valueBar.classList.remove(progressBarWarning); |
136 | | - valueBar.classList.remove(progressBarSuccess); |
137 | | - if (currentPercent > 90) { |
138 | | - valueBar.classList.add(progressBarDanger); |
139 | | - } else if (currentPercent > 75) { |
140 | | - valueBar.classList.add(progressBarWarning); |
141 | | - } else { |
142 | | - valueBar.classList.add(progressBarSuccess); |
143 | | - } |
144 | | - } |
145 | | - |
146 | | - } else { |
| 121 | + if (current > total) { |
147 | 122 | logger.error("Invalid values for utilization bar chart: current > total ({} > {})", current, total); |
148 | 123 | } |
| 124 | + this.total = total; |
| 125 | + double currentPercent = Math.round(((double) current) / ((double) total) * 100.0); |
| 126 | + long remaining = total - current; |
| 127 | + double remainingPercent = 100.0 - currentPercent; |
| 128 | + |
| 129 | + valueBar.setAttribute(aria(VALUE_NOW), String.valueOf(current)); |
| 130 | + valueBar.setAttribute(aria(VALUE_MAX), String.valueOf(total)); |
| 131 | + valueBar.style.width = width(currentPercent + "%"); |
| 132 | + Tooltip.element(valueBar).setTitle(MESSAGES.used(currentPercent)); |
| 133 | + // noinspection HardCodedStringLiteral |
| 134 | + valueElement.innerHTML = new SafeHtmlBuilder() |
| 135 | + .appendHtmlConstant("<strong>") |
| 136 | + .appendEscaped(MESSAGES.currentOfTotal(current, total)) |
| 137 | + .appendHtmlConstant("</strong>") |
| 138 | + .appendEscaped(" " + unit) |
| 139 | + .toSafeHtml().asString(); |
| 140 | + |
| 141 | + remainingBar.setAttribute(aria(VALUE_NOW), String.valueOf(remaining)); |
| 142 | + remainingBar.setAttribute(aria(VALUE_MAX), String.valueOf(total)); |
| 143 | + remainingBar.style.width = width(remainingPercent + "%"); |
| 144 | + Tooltip.element(remainingBar).setTitle(MESSAGES.available(remainingPercent)); |
| 145 | + remainingElement.textContent = MESSAGES.available(remainingPercent); |
| 146 | + |
| 147 | + if (thresholds) { |
| 148 | + valueBar.classList.remove(progressBarDanger); |
| 149 | + valueBar.classList.remove(progressBarWarning); |
| 150 | + valueBar.classList.remove(progressBarSuccess); |
| 151 | + if (currentPercent > 90) { |
| 152 | + valueBar.classList.add(progressBarDanger); |
| 153 | + } else if (currentPercent > 75) { |
| 154 | + valueBar.classList.add(progressBarWarning); |
| 155 | + } else { |
| 156 | + valueBar.classList.add(progressBarSuccess); |
| 157 | + } |
| 158 | + } |
149 | 159 | } |
150 | 160 |
|
151 | 161 | private String aria(String name) { |
|
0 commit comments