diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java index 280a949e..33fabfef 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 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.POSTMapper; 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); } + 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 { @JsonProperty(THRESHOLD.ATTR_VALUE) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java index d44db572..54949dc7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java @@ -740,7 +740,10 @@ public class ExamForm implements TemplateComposer { ? "color: #4a4a4a; " : "color: #FFFFFF;") .append("'>") - .append(threshold.value).append(" (").append(threshold.color).append(")") + .append(Indicator.getDisplayValue(indicator, threshold.value)) + .append(" (") + .append(threshold.color) + .append(")") .append("") .append(" | "), (sb1, sb2) -> sb1.append(sb2)); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java index 9e5c2683..4fd8dc67 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java @@ -12,6 +12,7 @@ import org.eclipse.swt.widgets.Composite; import org.springframework.context.annotation.Lazy; 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.EntityType; 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.profile.GuiProfile; 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.FormHandle; 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.page.PageContext; 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.SaveIndicator; import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; +import io.micrometer.core.instrument.util.StringUtils; @Lazy @Component @@ -54,9 +58,17 @@ public class IndicatorForm implements TemplateComposer { new LocTextKey("sebserver.exam.indicator.form.name"); private static final LocTextKey FORM_EXAM_TEXT_KEY = 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 ResourceService resourceService; + private final I18nSupport i18nSupport; protected IndicatorForm( final PageService pageService, @@ -64,6 +76,7 @@ public class IndicatorForm implements TemplateComposer { this.pageService = pageService; this.resourceService = resourceService; + this.i18nSupport = pageService.getI18nSupport(); } @Override @@ -92,6 +105,11 @@ public class IndicatorForm implements TemplateComposer { .onError(error -> pageContext.notifyLoadError(EntityType.INDICATOR, error)) .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 final PageContext formContext = pageContext.withEntityKey(indicator.getEntityKey()); @@ -124,19 +142,32 @@ public class IndicatorForm implements TemplateComposer { Domain.INDICATOR.ATTR_NAME, FORM_NAME_TEXT_KEY, indicator.name)) + .addField(FormBuilder.singleSelection( Domain.INDICATOR.ATTR_TYPE, FORM_TYPE_TEXT_KEY, (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( Domain.INDICATOR.ATTR_COLOR, FORM_COLOR_TEXT_KEY, - indicator.defaultColor)) + indicator.defaultColor) + .withEmptyCellSeparation(false)) .addField(FormBuilder.thresholdList( Domain.THRESHOLD.REFERENCE_NAME, FORM_THRESHOLDS_TEXT_KEY, - indicator.getThresholds())) + indicator)) + .buildFor((isNew) ? restService.getRestCall(NewIndicator.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); + } + } + } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/Form.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/Form.java index 9169c23a..86489ebc 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/Form.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/Form.java @@ -122,6 +122,10 @@ public final class Form implements FormBinding { 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) { this.formFields.add(name, createReadonlyAccessor(label, field)); return this; @@ -293,7 +297,7 @@ public final class Form implements FormBinding { case MULTI: case MULTI_COMBO: return createAccessor(label, selection, Form::adaptCommaSeparatedStringToJsonArray, errorLabel); - default : return createAccessor(label, selection, null, null); + default : return createAccessor(label, selection, null, errorLabel); } } private FormFieldAccessor createAccessor( diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/FormBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormBuilder.java index 30921290..def47fc7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/FormBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormBuilder.java @@ -9,7 +9,6 @@ package ch.ethz.seb.sebserver.gui.form; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.List; 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.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.gui.service.i18n.I18nSupport; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; @@ -259,9 +258,9 @@ public class FormBuilder { public static ThresholdListBuilder thresholdList( final String name, final LocTextKey label, - final Collection 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) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/ThresholdListBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/ThresholdListBuilder.java index 3cbadb23..f5b973a0 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/ThresholdListBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/ThresholdListBuilder.java @@ -19,18 +19,22 @@ import org.eclipse.swt.widgets.Label; import ch.ethz.seb.sebserver.gbl.Constants; 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.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.widget.ThresholdList; public class ThresholdListBuilder extends FieldBuilder> { + private final Indicator indicator; + protected ThresholdListBuilder( final String name, final LocTextKey label, - final Collection value) { + final Indicator indicator) { - super(name, label, value); + super(name, label, indicator.getThresholds()); + this.indicator = indicator; } @Override @@ -50,7 +54,7 @@ public class ThresholdListBuilder extends FieldBuilder> { final ThresholdList thresholdList = builder.widgetFactory.thresholdList( fieldGrid, fieldGrid.getParent().getParent(), - this.value); + this.indicator); final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); thresholdList.setLayoutData(gridData); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java index 4f30f52b..6772d2ce 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java @@ -22,6 +22,7 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; 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.IndicatorValue; 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.page.PageService; import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction; @@ -83,6 +85,9 @@ public final class ClientConnectionTable { private LinkedHashMap tableMapping; private final MultiValueMap sessionIds; + private final Color darkFontColor; + private final Color lightFontColor; + public ClientConnectionTable( final PageService pageService, final Composite tableRoot, @@ -98,6 +103,9 @@ public final class ClientConnectionTable { final Display display = tableRoot.getDisplay(); 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( indicators, display, @@ -105,9 +113,11 @@ public final class ClientConnectionTable { this.table = this.widgetFactory.tableLocalized(tableRoot, SWT.SINGLE | SWT.V_SCROLL); final GridLayout gridLayout = new GridLayout(3 + indicators.size(), true); + gridLayout.horizontalSpacing = 100; + gridLayout.marginWidth = 100; + gridLayout.marginRight = 100; this.table.setLayout(gridLayout); final GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false); - //gridData.heightHint = 200; this.table.setLayoutData(gridData); this.table.setHeaderVisible(true); this.table.setLinesVisible(true); @@ -260,7 +270,8 @@ public final class ClientConnectionTable { final Long connectionId; private boolean changed = false; private ClientConnectionData connectionData; - private int indicatorWeight; + private int thresholdsWeight; + private int[] indicatorWeights = null; private boolean duplicateChecked = false; UpdatableTableItem(final Long connectionId) { @@ -290,9 +301,11 @@ public final class ClientConnectionTable { } void updateConnectionStatusColor(final TableItem tableItem) { - tableItem.setBackground( - 2, - ClientConnectionTable.this.statusData.getStatusColor(this.connectionData)); + final Color statusColor = ClientConnectionTable.this.statusData.getStatusColor(this.connectionData); + tableItem.setBackground(2, statusColor); + tableItem.setForeground(2, Utils.darkColor(statusColor.getRGB()) + ? ClientConnectionTable.this.darkFontColor + : ClientConnectionTable.this.lightFontColor); } void updateDuplicateColor(final TableItem tableItem) { @@ -313,7 +326,7 @@ public final class ClientConnectionTable { } void updateIndicatorValues(final TableItem tableItem) { - if (this.connectionData == null) { + if (this.connectionData == null || this.indicatorWeights == null) { return; } @@ -325,17 +338,23 @@ public final class ClientConnectionTable { ClientConnectionTable.this.indicatorMapping.get(indicatorValue.getType()); if (fillEmpty) { - tableItem.setText(indicatorData.index, Constants.EMPTY_NOTE); + tableItem.setText(indicatorData.tableIndex, Constants.EMPTY_NOTE); tableItem.setBackground( - indicatorData.index, + indicatorData.tableIndex, indicatorData.defaultColor); } else { - tableItem.setText(indicatorData.index, getDisplayValue(indicatorValue)); + tableItem.setText(indicatorData.tableIndex, getDisplayValue(indicatorValue)); + final int weight = this.indicatorWeights[indicatorData.index]; final Color color = - (this.indicatorWeight >= 0 && this.indicatorWeight < indicatorData.thresholdColor.length) - ? indicatorData.thresholdColor[this.indicatorWeight].color + (weight >= 0 && weight < indicatorData.thresholdColor.length) + ? indicatorData.thresholdColor[weight].color : 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() { - return this.indicatorWeight; + return -this.thresholdsWeight; } String getStatusName() { @@ -412,6 +431,10 @@ public final class ClientConnectionTable { 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++) { final IndicatorValue indicatorValue = connectionData.indicatorValues.get(i); final IndicatorData indicatorData = @@ -419,10 +442,13 @@ public final class ClientConnectionTable { final double value = indicatorValue.getValue(); 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; + this.thresholdsWeight -= this.indicatorWeights[indicatorData.index]; + this.indicatorWeights[indicatorData.index] = indicatorWeight; + this.thresholdsWeight += this.indicatorWeights[indicatorData.index]; } - this.indicatorWeight = indicatorWeight; } this.connectionData = connectionData; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/IndicatorData.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/IndicatorData.java index 6aa32d0f..1ef5bd53 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/IndicatorData.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/IndicatorData.java @@ -8,7 +8,9 @@ package ch.ethz.seb.sebserver.gui.service.session; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.EnumMap; import org.eclipse.swt.graphics.Color; @@ -22,29 +24,42 @@ import ch.ethz.seb.sebserver.gbl.util.Utils; final class IndicatorData { final int index; + final int tableIndex; final Indicator indicator; final Color defaultColor; 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.index = index; + this.tableIndex = tableIndex; this.defaultColor = new Color(display, Utils.toRGB(indicator.defaultColor), 255); this.thresholdColor = new ThresholdColor[indicator.thresholds.size()]; + final ArrayList sortedThresholds = new ArrayList<>(indicator.thresholds); + Collections.sort(sortedThresholds, (t1, t2) -> t1.value.compareTo(t2.value)); 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 createFormIndicators( final Collection indicators, final Display display, - final int indexOffset) { + final int tableIndexOffset) { final EnumMap indicatorMapping = new EnumMap<>(IndicatorType.class); - int i = indexOffset; + int i = 0; 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++; } return indicatorMapping; @@ -53,11 +68,7 @@ final class IndicatorData { static final int getWeight(final IndicatorData indicatorData, final double value) { for (int j = 0; j < indicatorData.thresholdColor.length; j++) { if (value < indicatorData.thresholdColor[j].value) { - if (j == 0) { - return -1; - } else { - return j - 1; - } + return (j == 0) ? -1 : j - 1; } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/StatusData.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/StatusData.java index d0e3f9e9..d4bbc03e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/StatusData.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/StatusData.java @@ -23,9 +23,9 @@ public class StatusData { public StatusData(final Display display) { this.defaultColor = new Color(display, new RGB(255, 255, 255), 255); - this.color1 = new Color(display, new RGB(0, 255, 0), 255); - this.color2 = new Color(display, new RGB(249, 166, 2), 255); - this.color3 = new Color(display, new RGB(255, 0, 0), 255); + this.color1 = new Color(display, new RGB(34, 177, 76), 255); + this.color2 = new Color(display, new RGB(255, 194, 14), 255); + this.color3 = new Color(display, new RGB(237, 28, 36), 255); } Color getStatusColor(final ClientConnectionData connectionData) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java index a5231588..1a13c5dd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/ColorSelection.java @@ -74,7 +74,9 @@ public final class ColorSelection extends Composite implements Selection { colorCallLayout.marginTop = 2; this.colorField.setLayout(colorCallLayout); 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); final Label imageButton = widgetFactory.imageButton( diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/ThresholdList.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/ThresholdList.java index 63ee7ee5..e3905bea 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/ThresholdList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/ThresholdList.java @@ -24,6 +24,7 @@ import org.eclipse.swt.widgets.Text; import org.slf4j.Logger; 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.gui.service.i18n.LocTextKey; 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 final WidgetFactory widgetFactory; + private final Indicator indicator; private final List thresholds = new ArrayList<>(); private final GridData valueCell; @@ -51,16 +53,14 @@ public final class ThresholdList extends Composite { private final GridData actionCell; private final Composite updateAnchor; - ThresholdList(final Composite parent, final WidgetFactory widgetFactory) { - this(parent, parent, widgetFactory); - } - ThresholdList( + final Indicator indicator, final Composite parent, final Composite updateAnchor, final WidgetFactory widgetFactory) { super(parent, SWT.NONE); + this.indicator = indicator; this.updateAnchor = updateAnchor; this.widgetFactory = widgetFactory; 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) { - 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); valueInput.setLayoutData(valueCell); @@ -156,7 +163,7 @@ public final class ThresholdList extends Composite { if (threshold != null) { if (threshold.value != null) { - valueInput.setText(threshold.value.toString()); + valueInput.setText(Indicator.getDisplayValue(this.indicator, threshold.value)); } if (threshold.color != null) { selector.select(threshold.color); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java index 9541a308..d86a0fbc 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java @@ -40,7 +40,7 @@ import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Lazy; 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.util.Tuple; import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; @@ -605,11 +605,11 @@ public class WidgetFactory { public ThresholdList thresholdList( final Composite parent, final Composite updateAnchor, - final Collection values) { + final Indicator indicator) { - final ThresholdList thresholdList = new ThresholdList(parent, updateAnchor, this); - if (values != null) { - thresholdList.setThresholds(values); + final ThresholdList thresholdList = new ThresholdList(indicator, parent, updateAnchor, this); + if (indicator.thresholds != null) { + thresholdList.setThresholds(indicator.thresholds); } return thresholdList; } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index a77df066..14d613be 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -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.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 @@ -387,6 +390,7 @@ sebserver.exam.indicator.form.title.new=Add Indicator sebserver.exam.indicator.form.exam=Exam sebserver.exam.indicator.form.name=Name 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.action=Please select a color sebserver.exam.indicator.form.thresholds=Thresholds diff --git a/src/main/resources/static/css/sebserver.css b/src/main/resources/static/css/sebserver.css index 48dac24c..d1eac110 100644 --- a/src/main/resources/static/css/sebserver.css +++ b/src/main/resources/static/css/sebserver.css @@ -111,11 +111,13 @@ Label-SeparatorLine { Label.colordark { font: 12px "Courier New", Courier, monospace; color: #4a4a4a; + padding: 2px 5px 2px 5px; } Label.colorlight { font: 12px "Courier New", Courier, monospace; color: #FFFFFF; + padding: 2px 5px 2px 5px; } Composite.bordered { diff --git a/src/test/java/ch/ethz/seb/sebserver/HTTPClientBot.java b/src/test/java/ch/ethz/seb/sebserver/HTTPClientBot.java index 84e2aa24..c7ac0bee 100644 --- a/src/test/java/ch/ethz/seb/sebserver/HTTPClientBot.java +++ b/src/test/java/ch/ethz/seb/sebserver/HTTPClientBot.java @@ -78,8 +78,8 @@ public class HTTPClientBot { public HTTPClientBot(final Map args) { - this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://ralph.ethz.ch:8080"); - //this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://localhost:8080"); + //this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://ralph.ethz.ch:8080"); + this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://localhost:8080"); //this.webserviceAddress = args.getOrDefault("webserviceAddress", "https://seb.test-swissmooc.ch"); this.accessTokenEndpoint = args.getOrDefault("accessTokenEndpoint", "/oauth/token");