improved indicator view and monitoring view

This commit is contained in:
anhefti 2019-11-28 11:57:24 +01:00
parent a1a9c482e3
commit 646cc51d3e
15 changed files with 170 additions and 54 deletions

View file

@ -18,6 +18,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.EntityType; import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.api.POSTMapper; import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
import ch.ethz.seb.sebserver.gbl.model.Domain; import ch.ethz.seb.sebserver.gbl.model.Domain;
@ -162,6 +163,17 @@ public final class Indicator implements Entity {
return new Indicator(null, exam.id, null, null, null, null); return new Indicator(null, exam.id, null, null, null, null);
} }
public static String getDisplayValue(final Indicator indicator, final Double value) {
if (value == null) {
return Constants.EMPTY_NOTE;
}
if (indicator.getType().integerValue) {
return String.valueOf(value.intValue());
} else {
return String.valueOf(value.floatValue());
}
}
public static final class Threshold { public static final class Threshold {
@JsonProperty(THRESHOLD.ATTR_VALUE) @JsonProperty(THRESHOLD.ATTR_VALUE)

View file

@ -740,7 +740,10 @@ public class ExamForm implements TemplateComposer {
? "color: #4a4a4a; " ? "color: #4a4a4a; "
: "color: #FFFFFF;") : "color: #FFFFFF;")
.append("'>") .append("'>")
.append(threshold.value).append(" (").append(threshold.color).append(")") .append(Indicator.getDisplayValue(indicator, threshold.value))
.append(" (")
.append(threshold.color)
.append(")")
.append("</span>") .append("</span>")
.append(" | "), .append(" | "),
(sb1, sb2) -> sb1.append(sb2)); (sb1, sb2) -> sb1.append(sb2));

View file

@ -12,6 +12,7 @@ import org.eclipse.swt.widgets.Composite;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.API; import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.api.EntityType; import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.Domain; import ch.ethz.seb.sebserver.gbl.model.Domain;
@ -21,9 +22,11 @@ import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
import ch.ethz.seb.sebserver.gbl.model.exam.QuizData; import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition;
import ch.ethz.seb.sebserver.gui.form.Form;
import ch.ethz.seb.sebserver.gui.form.FormBuilder; import ch.ethz.seb.sebserver.gui.form.FormBuilder;
import ch.ethz.seb.sebserver.gui.form.FormHandle; import ch.ethz.seb.sebserver.gui.form.FormHandle;
import ch.ethz.seb.sebserver.gui.service.ResourceService; import ch.ethz.seb.sebserver.gui.service.ResourceService;
import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.service.page.PageContext; import ch.ethz.seb.sebserver.gui.service.page.PageContext;
import ch.ethz.seb.sebserver.gui.service.page.PageService; import ch.ethz.seb.sebserver.gui.service.page.PageService;
@ -34,6 +37,7 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetIndicator
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.NewIndicator; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.NewIndicator;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.SaveIndicator; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.SaveIndicator;
import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; import ch.ethz.seb.sebserver.gui.widget.WidgetFactory;
import io.micrometer.core.instrument.util.StringUtils;
@Lazy @Lazy
@Component @Component
@ -54,9 +58,17 @@ public class IndicatorForm implements TemplateComposer {
new LocTextKey("sebserver.exam.indicator.form.name"); new LocTextKey("sebserver.exam.indicator.form.name");
private static final LocTextKey FORM_EXAM_TEXT_KEY = private static final LocTextKey FORM_EXAM_TEXT_KEY =
new LocTextKey("sebserver.exam.indicator.form.exam"); new LocTextKey("sebserver.exam.indicator.form.exam");
private static final LocTextKey FORM_DESC_TEXT_KEY =
new LocTextKey("sebserver.exam.indicator.form.description");
private static final String INDICATOR_TYPE_DESC_PREFIX =
"sebserver.exam.indicator.type.description.";
private static final String TYPE_DESCRIPTION_FIELD_NAME =
"typeDescription";
private final PageService pageService; private final PageService pageService;
private final ResourceService resourceService; private final ResourceService resourceService;
private final I18nSupport i18nSupport;
protected IndicatorForm( protected IndicatorForm(
final PageService pageService, final PageService pageService,
@ -64,6 +76,7 @@ public class IndicatorForm implements TemplateComposer {
this.pageService = pageService; this.pageService = pageService;
this.resourceService = resourceService; this.resourceService = resourceService;
this.i18nSupport = pageService.getI18nSupport();
} }
@Override @Override
@ -92,6 +105,11 @@ public class IndicatorForm implements TemplateComposer {
.onError(error -> pageContext.notifyLoadError(EntityType.INDICATOR, error)) .onError(error -> pageContext.notifyLoadError(EntityType.INDICATOR, error))
.getOrThrow(); .getOrThrow();
final boolean typeSet = indicator.type != null;
final String typeDescription = (typeSet)
? this.i18nSupport.getText(INDICATOR_TYPE_DESC_PREFIX + indicator.type.name)
: Constants.EMPTY_NOTE;
// new PageContext with actual EntityKey // new PageContext with actual EntityKey
final PageContext formContext = pageContext.withEntityKey(indicator.getEntityKey()); final PageContext formContext = pageContext.withEntityKey(indicator.getEntityKey());
@ -124,19 +142,32 @@ public class IndicatorForm implements TemplateComposer {
Domain.INDICATOR.ATTR_NAME, Domain.INDICATOR.ATTR_NAME,
FORM_NAME_TEXT_KEY, FORM_NAME_TEXT_KEY,
indicator.name)) indicator.name))
.addField(FormBuilder.singleSelection( .addField(FormBuilder.singleSelection(
Domain.INDICATOR.ATTR_TYPE, Domain.INDICATOR.ATTR_TYPE,
FORM_TYPE_TEXT_KEY, FORM_TYPE_TEXT_KEY,
(indicator.type != null) ? indicator.type.name() : null, (indicator.type != null) ? indicator.type.name() : null,
this.resourceService::indicatorTypeResources)) this.resourceService::indicatorTypeResources)
.withSelectionListener(this::updateForm))
.addField(FormBuilder.text(
TYPE_DESCRIPTION_FIELD_NAME,
FORM_DESC_TEXT_KEY,
typeDescription)
.asArea()
.readonly(true)
.withInputSpan(3))
.addField(FormBuilder.colorSelection( .addField(FormBuilder.colorSelection(
Domain.INDICATOR.ATTR_COLOR, Domain.INDICATOR.ATTR_COLOR,
FORM_COLOR_TEXT_KEY, FORM_COLOR_TEXT_KEY,
indicator.defaultColor)) indicator.defaultColor)
.withEmptyCellSeparation(false))
.addField(FormBuilder.thresholdList( .addField(FormBuilder.thresholdList(
Domain.THRESHOLD.REFERENCE_NAME, Domain.THRESHOLD.REFERENCE_NAME,
FORM_THRESHOLDS_TEXT_KEY, FORM_THRESHOLDS_TEXT_KEY,
indicator.getThresholds())) indicator))
.buildFor((isNew) .buildFor((isNew)
? restService.getRestCall(NewIndicator.class) ? restService.getRestCall(NewIndicator.class)
: restService.getRestCall(SaveIndicator.class)); : restService.getRestCall(SaveIndicator.class));
@ -157,4 +188,15 @@ public class IndicatorForm implements TemplateComposer {
} }
private final void updateForm(final Form form) {
final String typeValue = form.getFieldValue(Domain.INDICATOR.ATTR_TYPE);
if (StringUtils.isNotBlank(typeValue)) {
form.setFieldValue(
TYPE_DESCRIPTION_FIELD_NAME,
this.i18nSupport.getText(INDICATOR_TYPE_DESC_PREFIX + typeValue));
} else {
form.setFieldValue(TYPE_DESCRIPTION_FIELD_NAME, Constants.EMPTY_NOTE);
}
}
} }

View file

@ -122,6 +122,10 @@ public final class Form implements FormBinding {
return !this.formFields.isEmpty(); return !this.formFields.isEmpty();
} }
public boolean hasField(final String fieldName) {
return this.formFields.containsKey(fieldName);
}
Form putReadonlyField(final String name, final Label label, final Text field) { Form putReadonlyField(final String name, final Label label, final Text field) {
this.formFields.add(name, createReadonlyAccessor(label, field)); this.formFields.add(name, createReadonlyAccessor(label, field));
return this; return this;
@ -293,7 +297,7 @@ public final class Form implements FormBinding {
case MULTI: case MULTI:
case MULTI_COMBO: case MULTI_COMBO:
return createAccessor(label, selection, Form::adaptCommaSeparatedStringToJsonArray, errorLabel); return createAccessor(label, selection, Form::adaptCommaSeparatedStringToJsonArray, errorLabel);
default : return createAccessor(label, selection, null, null); default : return createAccessor(label, selection, null, errorLabel);
} }
} }
private FormFieldAccessor createAccessor( private FormFieldAccessor createAccessor(

View file

@ -9,7 +9,6 @@
package ch.ethz.seb.sebserver.gui.form; package ch.ethz.seb.sebserver.gui.form;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
@ -27,7 +26,7 @@ import org.slf4j.LoggerFactory;
import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.model.Entity; import ch.ethz.seb.sebserver.gbl.model.Entity;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold; import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
import ch.ethz.seb.sebserver.gbl.util.Tuple; import ch.ethz.seb.sebserver.gbl.util.Tuple;
import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport; import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
@ -259,9 +258,9 @@ public class FormBuilder {
public static ThresholdListBuilder thresholdList( public static ThresholdListBuilder thresholdList(
final String name, final String name,
final LocTextKey label, final LocTextKey label,
final Collection<Threshold> value) { final Indicator indicator) {
return new ThresholdListBuilder(name, label, value); return new ThresholdListBuilder(name, label, indicator);
} }
public static ImageUploadFieldBuilder imageUpload(final String name, final LocTextKey label, final String value) { public static ImageUploadFieldBuilder imageUpload(final String name, final LocTextKey label, final String value) {

View file

@ -19,18 +19,22 @@ import org.eclipse.swt.widgets.Label;
import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.model.Domain; import ch.ethz.seb.sebserver.gbl.model.Domain;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold; import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.widget.ThresholdList; import ch.ethz.seb.sebserver.gui.widget.ThresholdList;
public class ThresholdListBuilder extends FieldBuilder<Collection<Threshold>> { public class ThresholdListBuilder extends FieldBuilder<Collection<Threshold>> {
private final Indicator indicator;
protected ThresholdListBuilder( protected ThresholdListBuilder(
final String name, final String name,
final LocTextKey label, final LocTextKey label,
final Collection<Threshold> value) { final Indicator indicator) {
super(name, label, value); super(name, label, indicator.getThresholds());
this.indicator = indicator;
} }
@Override @Override
@ -50,7 +54,7 @@ public class ThresholdListBuilder extends FieldBuilder<Collection<Threshold>> {
final ThresholdList thresholdList = builder.widgetFactory.thresholdList( final ThresholdList thresholdList = builder.widgetFactory.thresholdList(
fieldGrid, fieldGrid,
fieldGrid.getParent().getParent(), fieldGrid.getParent().getParent(),
this.value); this.indicator);
final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
thresholdList.setLayoutData(gridData); thresholdList.setLayoutData(gridData);

View file

@ -22,6 +22,7 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
@ -46,6 +47,7 @@ import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection.ConnectionStatus
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData;
import ch.ethz.seb.sebserver.gbl.model.session.IndicatorValue; import ch.ethz.seb.sebserver.gbl.model.session.IndicatorValue;
import ch.ethz.seb.sebserver.gbl.util.Tuple; import ch.ethz.seb.sebserver.gbl.util.Tuple;
import ch.ethz.seb.sebserver.gbl.util.Utils;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.service.page.PageService; import ch.ethz.seb.sebserver.gui.service.page.PageService;
import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction; import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction;
@ -83,6 +85,9 @@ public final class ClientConnectionTable {
private LinkedHashMap<Long, UpdatableTableItem> tableMapping; private LinkedHashMap<Long, UpdatableTableItem> tableMapping;
private final MultiValueMap<String, Long> sessionIds; private final MultiValueMap<String, Long> sessionIds;
private final Color darkFontColor;
private final Color lightFontColor;
public ClientConnectionTable( public ClientConnectionTable(
final PageService pageService, final PageService pageService,
final Composite tableRoot, final Composite tableRoot,
@ -98,6 +103,9 @@ public final class ClientConnectionTable {
final Display display = tableRoot.getDisplay(); final Display display = tableRoot.getDisplay();
this.statusData = new StatusData(display); this.statusData = new StatusData(display);
this.darkFontColor = new Color(display, new RGB(0, 0, 0));
this.lightFontColor = new Color(display, new RGB(255, 255, 255));
this.indicatorMapping = IndicatorData.createFormIndicators( this.indicatorMapping = IndicatorData.createFormIndicators(
indicators, indicators,
display, display,
@ -105,9 +113,11 @@ public final class ClientConnectionTable {
this.table = this.widgetFactory.tableLocalized(tableRoot, SWT.SINGLE | SWT.V_SCROLL); this.table = this.widgetFactory.tableLocalized(tableRoot, SWT.SINGLE | SWT.V_SCROLL);
final GridLayout gridLayout = new GridLayout(3 + indicators.size(), true); final GridLayout gridLayout = new GridLayout(3 + indicators.size(), true);
gridLayout.horizontalSpacing = 100;
gridLayout.marginWidth = 100;
gridLayout.marginRight = 100;
this.table.setLayout(gridLayout); this.table.setLayout(gridLayout);
final GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); final GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false);
//gridData.heightHint = 200;
this.table.setLayoutData(gridData); this.table.setLayoutData(gridData);
this.table.setHeaderVisible(true); this.table.setHeaderVisible(true);
this.table.setLinesVisible(true); this.table.setLinesVisible(true);
@ -260,7 +270,8 @@ public final class ClientConnectionTable {
final Long connectionId; final Long connectionId;
private boolean changed = false; private boolean changed = false;
private ClientConnectionData connectionData; private ClientConnectionData connectionData;
private int indicatorWeight; private int thresholdsWeight;
private int[] indicatorWeights = null;
private boolean duplicateChecked = false; private boolean duplicateChecked = false;
UpdatableTableItem(final Long connectionId) { UpdatableTableItem(final Long connectionId) {
@ -290,9 +301,11 @@ public final class ClientConnectionTable {
} }
void updateConnectionStatusColor(final TableItem tableItem) { void updateConnectionStatusColor(final TableItem tableItem) {
tableItem.setBackground( final Color statusColor = ClientConnectionTable.this.statusData.getStatusColor(this.connectionData);
2, tableItem.setBackground(2, statusColor);
ClientConnectionTable.this.statusData.getStatusColor(this.connectionData)); tableItem.setForeground(2, Utils.darkColor(statusColor.getRGB())
? ClientConnectionTable.this.darkFontColor
: ClientConnectionTable.this.lightFontColor);
} }
void updateDuplicateColor(final TableItem tableItem) { void updateDuplicateColor(final TableItem tableItem) {
@ -313,7 +326,7 @@ public final class ClientConnectionTable {
} }
void updateIndicatorValues(final TableItem tableItem) { void updateIndicatorValues(final TableItem tableItem) {
if (this.connectionData == null) { if (this.connectionData == null || this.indicatorWeights == null) {
return; return;
} }
@ -325,17 +338,23 @@ public final class ClientConnectionTable {
ClientConnectionTable.this.indicatorMapping.get(indicatorValue.getType()); ClientConnectionTable.this.indicatorMapping.get(indicatorValue.getType());
if (fillEmpty) { if (fillEmpty) {
tableItem.setText(indicatorData.index, Constants.EMPTY_NOTE); tableItem.setText(indicatorData.tableIndex, Constants.EMPTY_NOTE);
tableItem.setBackground( tableItem.setBackground(
indicatorData.index, indicatorData.tableIndex,
indicatorData.defaultColor); indicatorData.defaultColor);
} else { } else {
tableItem.setText(indicatorData.index, getDisplayValue(indicatorValue)); tableItem.setText(indicatorData.tableIndex, getDisplayValue(indicatorValue));
final int weight = this.indicatorWeights[indicatorData.index];
final Color color = final Color color =
(this.indicatorWeight >= 0 && this.indicatorWeight < indicatorData.thresholdColor.length) (weight >= 0 && weight < indicatorData.thresholdColor.length)
? indicatorData.thresholdColor[this.indicatorWeight].color ? indicatorData.thresholdColor[weight].color
: indicatorData.defaultColor; : indicatorData.defaultColor;
tableItem.setBackground(indicatorData.index, color); tableItem.setBackground(indicatorData.tableIndex, color);
tableItem.setForeground(
indicatorData.tableIndex,
Utils.darkColor(color.getRGB())
? ClientConnectionTable.this.darkFontColor
: ClientConnectionTable.this.lightFontColor);
} }
} }
} }
@ -376,7 +395,7 @@ public final class ClientConnectionTable {
} }
int thresholdsWeight() { int thresholdsWeight() {
return this.indicatorWeight; return -this.thresholdsWeight;
} }
String getStatusName() { String getStatusName() {
@ -412,6 +431,10 @@ public final class ClientConnectionTable {
ClientConnectionTable.this.needsSort = true; ClientConnectionTable.this.needsSort = true;
} }
if (this.indicatorWeights == null) {
this.indicatorWeights = new int[ClientConnectionTable.this.indicatorMapping.size()];
}
for (int i = 0; i < connectionData.indicatorValues.size(); i++) { for (int i = 0; i < connectionData.indicatorValues.size(); i++) {
final IndicatorValue indicatorValue = connectionData.indicatorValues.get(i); final IndicatorValue indicatorValue = connectionData.indicatorValues.get(i);
final IndicatorData indicatorData = final IndicatorData indicatorData =
@ -419,10 +442,13 @@ public final class ClientConnectionTable {
final double value = indicatorValue.getValue(); final double value = indicatorValue.getValue();
final int indicatorWeight = IndicatorData.getWeight(indicatorData, value); final int indicatorWeight = IndicatorData.getWeight(indicatorData, value);
if (this.indicatorWeight != indicatorWeight) { if (this.indicatorWeights[indicatorData.index] != indicatorWeight) {
System.out.println("**** index: " + indicatorData.index + " weight: " + indicatorWeight);
ClientConnectionTable.this.needsSort = true; ClientConnectionTable.this.needsSort = true;
this.thresholdsWeight -= this.indicatorWeights[indicatorData.index];
this.indicatorWeights[indicatorData.index] = indicatorWeight;
this.thresholdsWeight += this.indicatorWeights[indicatorData.index];
} }
this.indicatorWeight = indicatorWeight;
} }
this.connectionData = connectionData; this.connectionData = connectionData;

View file

@ -8,7 +8,9 @@
package ch.ethz.seb.sebserver.gui.service.session; package ch.ethz.seb.sebserver.gui.service.session;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap; import java.util.EnumMap;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
@ -22,29 +24,42 @@ import ch.ethz.seb.sebserver.gbl.util.Utils;
final class IndicatorData { final class IndicatorData {
final int index; final int index;
final int tableIndex;
final Indicator indicator; final Indicator indicator;
final Color defaultColor; final Color defaultColor;
final ThresholdColor[] thresholdColor; final ThresholdColor[] thresholdColor;
protected IndicatorData(final Indicator indicator, final int index, final Display display) { protected IndicatorData(
final Indicator indicator,
final int index,
final int tableIndex,
final Display display) {
this.indicator = indicator; this.indicator = indicator;
this.index = index; this.index = index;
this.tableIndex = tableIndex;
this.defaultColor = new Color(display, Utils.toRGB(indicator.defaultColor), 255); this.defaultColor = new Color(display, Utils.toRGB(indicator.defaultColor), 255);
this.thresholdColor = new ThresholdColor[indicator.thresholds.size()]; this.thresholdColor = new ThresholdColor[indicator.thresholds.size()];
final ArrayList<Threshold> sortedThresholds = new ArrayList<>(indicator.thresholds);
Collections.sort(sortedThresholds, (t1, t2) -> t1.value.compareTo(t2.value));
for (int i = 0; i < indicator.thresholds.size(); i++) { for (int i = 0; i < indicator.thresholds.size(); i++) {
this.thresholdColor[i] = new ThresholdColor(indicator.thresholds.get(i), display); this.thresholdColor[i] = new ThresholdColor(sortedThresholds.get(i), display);
} }
} }
static final EnumMap<IndicatorType, IndicatorData> createFormIndicators( static final EnumMap<IndicatorType, IndicatorData> createFormIndicators(
final Collection<Indicator> indicators, final Collection<Indicator> indicators,
final Display display, final Display display,
final int indexOffset) { final int tableIndexOffset) {
final EnumMap<IndicatorType, IndicatorData> indicatorMapping = new EnumMap<>(IndicatorType.class); final EnumMap<IndicatorType, IndicatorData> indicatorMapping = new EnumMap<>(IndicatorType.class);
int i = indexOffset; int i = 0;
for (final Indicator indicator : indicators) { for (final Indicator indicator : indicators) {
indicatorMapping.put(indicator.type, new IndicatorData(indicator, i, display)); indicatorMapping.put(indicator.type, new IndicatorData(
indicator,
i,
i + tableIndexOffset,
display));
i++; i++;
} }
return indicatorMapping; return indicatorMapping;
@ -53,11 +68,7 @@ final class IndicatorData {
static final int getWeight(final IndicatorData indicatorData, final double value) { static final int getWeight(final IndicatorData indicatorData, final double value) {
for (int j = 0; j < indicatorData.thresholdColor.length; j++) { for (int j = 0; j < indicatorData.thresholdColor.length; j++) {
if (value < indicatorData.thresholdColor[j].value) { if (value < indicatorData.thresholdColor[j].value) {
if (j == 0) { return (j == 0) ? -1 : j - 1;
return -1;
} else {
return j - 1;
}
} }
} }

View file

@ -23,9 +23,9 @@ public class StatusData {
public StatusData(final Display display) { public StatusData(final Display display) {
this.defaultColor = new Color(display, new RGB(255, 255, 255), 255); this.defaultColor = new Color(display, new RGB(255, 255, 255), 255);
this.color1 = new Color(display, new RGB(0, 255, 0), 255); this.color1 = new Color(display, new RGB(34, 177, 76), 255);
this.color2 = new Color(display, new RGB(249, 166, 2), 255); this.color2 = new Color(display, new RGB(255, 194, 14), 255);
this.color3 = new Color(display, new RGB(255, 0, 0), 255); this.color3 = new Color(display, new RGB(237, 28, 36), 255);
} }
Color getStatusColor(final ClientConnectionData connectionData) { Color getStatusColor(final ClientConnectionData connectionData) {

View file

@ -74,7 +74,9 @@ public final class ColorSelection extends Composite implements Selection {
colorCallLayout.marginTop = 2; colorCallLayout.marginTop = 2;
this.colorField.setLayout(colorCallLayout); this.colorField.setLayout(colorCallLayout);
this.colorLabel = new Label(this.colorField, SWT.NONE); this.colorLabel = new Label(this.colorField, SWT.NONE);
this.colorLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, false)); final GridData gridData = new GridData(SWT.RIGHT, SWT.TOP, true, false);
gridData.minimumWidth = 50;
this.colorLabel.setLayoutData(gridData);
this.colorLabel.setData(RWT.CUSTOM_VARIANT, CustomVariant.LIGHT_COLOR_LABEL.key); this.colorLabel.setData(RWT.CUSTOM_VARIANT, CustomVariant.LIGHT_COLOR_LABEL.key);
final Label imageButton = widgetFactory.imageButton( final Label imageButton = widgetFactory.imageButton(

View file

@ -24,6 +24,7 @@ import org.eclipse.swt.widgets.Text;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold; import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.service.page.PageService; import ch.ethz.seb.sebserver.gui.service.page.PageService;
@ -44,6 +45,7 @@ public final class ThresholdList extends Composite {
private static final LocTextKey REMOVE_TEXT_KEY = new LocTextKey("sebserver.exam.indicator.thresholds.list.remove"); private static final LocTextKey REMOVE_TEXT_KEY = new LocTextKey("sebserver.exam.indicator.thresholds.list.remove");
private final WidgetFactory widgetFactory; private final WidgetFactory widgetFactory;
private final Indicator indicator;
private final List<Entry> thresholds = new ArrayList<>(); private final List<Entry> thresholds = new ArrayList<>();
private final GridData valueCell; private final GridData valueCell;
@ -51,16 +53,14 @@ public final class ThresholdList extends Composite {
private final GridData actionCell; private final GridData actionCell;
private final Composite updateAnchor; private final Composite updateAnchor;
ThresholdList(final Composite parent, final WidgetFactory widgetFactory) {
this(parent, parent, widgetFactory);
}
ThresholdList( ThresholdList(
final Indicator indicator,
final Composite parent, final Composite parent,
final Composite updateAnchor, final Composite updateAnchor,
final WidgetFactory widgetFactory) { final WidgetFactory widgetFactory) {
super(parent, SWT.NONE); super(parent, SWT.NONE);
this.indicator = indicator;
this.updateAnchor = updateAnchor; this.updateAnchor = updateAnchor;
this.widgetFactory = widgetFactory; this.widgetFactory = widgetFactory;
super.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); super.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
@ -135,7 +135,14 @@ public final class ThresholdList extends Composite {
} }
private void addThreshold(final Threshold threshold) { private void addThreshold(final Threshold threshold) {
final Text valueInput = this.widgetFactory.numberInput(this, s -> Double.parseDouble(s)); final Text valueInput = this.widgetFactory.numberInput(
this, s -> {
if (this.indicator.getType().integerValue) {
Integer.parseInt(s);
} else {
Double.parseDouble(s);
}
});
final GridData valueCell = new GridData(SWT.FILL, SWT.CENTER, true, false); final GridData valueCell = new GridData(SWT.FILL, SWT.CENTER, true, false);
valueInput.setLayoutData(valueCell); valueInput.setLayoutData(valueCell);
@ -156,7 +163,7 @@ public final class ThresholdList extends Composite {
if (threshold != null) { if (threshold != null) {
if (threshold.value != null) { if (threshold.value != null) {
valueInput.setText(threshold.value.toString()); valueInput.setText(Indicator.getDisplayValue(this.indicator, threshold.value));
} }
if (threshold.color != null) { if (threshold.color != null) {
selector.select(threshold.color); selector.select(threshold.color);

View file

@ -40,7 +40,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold; import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gbl.util.Tuple; import ch.ethz.seb.sebserver.gbl.util.Tuple;
import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition;
@ -605,11 +605,11 @@ public class WidgetFactory {
public ThresholdList thresholdList( public ThresholdList thresholdList(
final Composite parent, final Composite parent,
final Composite updateAnchor, final Composite updateAnchor,
final Collection<Threshold> values) { final Indicator indicator) {
final ThresholdList thresholdList = new ThresholdList(parent, updateAnchor, this); final ThresholdList thresholdList = new ThresholdList(indicator, parent, updateAnchor, this);
if (values != null) { if (indicator.thresholds != null) {
thresholdList.setThresholds(values); thresholdList.setThresholds(indicator.thresholds);
} }
return thresholdList; return thresholdList;
} }

View file

@ -374,6 +374,9 @@ sebserver.exam.indicator.list.pleaseSelect=Please select an indicator first
sebserver.exam.indicator.type.LAST_PING=Last Ping sebserver.exam.indicator.type.LAST_PING=Last Ping
sebserver.exam.indicator.type.ERROR_COUNT=Error Count sebserver.exam.indicator.type.ERROR_COUNT=Error Count
sebserver.exam.indicator.type.description.LAST_PING=This indicator shows the time in milliseconds since the last ping has been received from a SEB Client.\nThis indicator can be used to track a SEB Client connection and indicate connection losse.\n\nThresholds are defined in milliseconds.
sebserver.exam.indicator.type.description.ERROR_COUNT=This indicator shows the number of error log messages that has been received from a SEB Client.\nThis indicator can be used to track errors of connected SEB Clients\n\nThresholds are defined by natural numbers.
sebserver.exam.indicator.info.pleaseSelect=Please select an indicator first sebserver.exam.indicator.info.pleaseSelect=Please select an indicator first
@ -387,6 +390,7 @@ sebserver.exam.indicator.form.title.new=Add Indicator
sebserver.exam.indicator.form.exam=Exam sebserver.exam.indicator.form.exam=Exam
sebserver.exam.indicator.form.name=Name sebserver.exam.indicator.form.name=Name
sebserver.exam.indicator.form.type=Type sebserver.exam.indicator.form.type=Type
sebserver.exam.indicator.form.description=Type Description
sebserver.exam.indicator.form.color=Default Color sebserver.exam.indicator.form.color=Default Color
sebserver.exam.indicator.form.color.action=Please select a color sebserver.exam.indicator.form.color.action=Please select a color
sebserver.exam.indicator.form.thresholds=Thresholds sebserver.exam.indicator.form.thresholds=Thresholds

View file

@ -111,11 +111,13 @@ Label-SeparatorLine {
Label.colordark { Label.colordark {
font: 12px "Courier New", Courier, monospace; font: 12px "Courier New", Courier, monospace;
color: #4a4a4a; color: #4a4a4a;
padding: 2px 5px 2px 5px;
} }
Label.colorlight { Label.colorlight {
font: 12px "Courier New", Courier, monospace; font: 12px "Courier New", Courier, monospace;
color: #FFFFFF; color: #FFFFFF;
padding: 2px 5px 2px 5px;
} }
Composite.bordered { Composite.bordered {

View file

@ -78,8 +78,8 @@ public class HTTPClientBot {
public HTTPClientBot(final Map<String, String> args) { public HTTPClientBot(final Map<String, String> args) {
this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://ralph.ethz.ch:8080"); //this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://ralph.ethz.ch:8080");
//this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://localhost:8080"); this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://localhost:8080");
//this.webserviceAddress = args.getOrDefault("webserviceAddress", "https://seb.test-swissmooc.ch"); //this.webserviceAddress = args.getOrDefault("webserviceAddress", "https://seb.test-swissmooc.ch");
this.accessTokenEndpoint = args.getOrDefault("accessTokenEndpoint", "/oauth/token"); this.accessTokenEndpoint = args.getOrDefault("accessTokenEndpoint", "/oauth/token");