From daafb7a64bd43665f2a862365275c1f682019112 Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 4 Jul 2019 10:57:14 +0200 Subject: [PATCH] added toggle action buttons for active/inactive on institutions --- .../gui/content/action/ActionDefinition.java | 4 +- .../gui/service/page/impl/PageUtils.java | 21 ++++++--- .../api/useraccount/GetUserDependency.java | 42 ++++++++++++++++++ .../sebserver/gui/widget/WidgetFactory.java | 2 + .../resources/config/application.properties | 2 +- src/main/resources/messages.properties | 4 +- src/main/resources/messages_en.properties | 4 +- .../resources/static/images/toggle_off.png | Bin 0 -> 171 bytes .../resources/static/images/toggle_on.png | Bin 0 -> 172 bytes .../exam/SebExamConfigurationRequestTest.java | 1 - 10 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/useraccount/GetUserDependency.java create mode 100644 src/main/resources/static/images/toggle_off.png create mode 100644 src/main/resources/static/images/toggle_on.png diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java index 27f65c37..aa57ac8c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java @@ -53,12 +53,12 @@ public enum ActionDefinition { ActionCategory.FORM), INSTITUTION_ACTIVATE( new LocTextKey("sebserver.institution.action.activate"), - ImageIcon.INACTIVE, + ImageIcon.TOGGLE_OFF, PageStateDefinition.INSTITUTION_VIEW, ActionCategory.FORM), INSTITUTION_DEACTIVATE( new LocTextKey("sebserver.institution.action.deactivate"), - ImageIcon.ACTIVE, + ImageIcon.TOGGLE_ON, PageStateDefinition.INSTITUTION_VIEW, ActionCategory.FORM), diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageUtils.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageUtils.java index 4a467589..063f8351 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageUtils.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageUtils.java @@ -21,6 +21,7 @@ import ch.ethz.seb.sebserver.gbl.api.API.BulkActionType; import ch.ethz.seb.sebserver.gbl.model.Entity; import ch.ethz.seb.sebserver.gbl.model.EntityKey; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall.CallType; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; @@ -44,13 +45,21 @@ public final class PageUtils { return () -> { try { + final RestCall>.RestCallBuilder builder = + restService.> getBuilder( + entity.entityType(), + CallType.GET_DEPENDENCIES); - final Set dependencies = - restService.> getBuilder(entity.entityType(), CallType.GET_DEPENDENCIES) - .withURIVariable(API.PARAM_MODEL_ID, String.valueOf(entity.getModelId())) - .withQueryParam(API.PARAM_BULK_ACTION_TYPE, BulkActionType.DEACTIVATE.name()) - .call() - .getOrThrow(); + if (builder == null) { + log.error("No RestCall builder found for entity type: {}", entity.entityType()); + return null; + } + + final Set dependencies = builder + .withURIVariable(API.PARAM_MODEL_ID, String.valueOf(entity.getModelId())) + .withQueryParam(API.PARAM_BULK_ACTION_TYPE, BulkActionType.DEACTIVATE.name()) + .call() + .getOrThrow(); final int size = dependencies.size(); if (size > 0) { return new LocTextKey("sebserver.dialog.confirm.deactivation", String.valueOf(size)); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/useraccount/GetUserDependency.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/useraccount/GetUserDependency.java new file mode 100644 index 00000000..a722f05b --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/useraccount/GetUserDependency.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount; + +import java.util.Set; + +import org.springframework.context.annotation.Lazy; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.core.type.TypeReference; + +import ch.ethz.seb.sebserver.gbl.api.API; +import ch.ethz.seb.sebserver.gbl.api.EntityType; +import ch.ethz.seb.sebserver.gbl.model.EntityKey; +import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; + +@Lazy +@Component +@GuiProfile +public class GetUserDependency extends RestCall> { + + public GetUserDependency() { + super(new TypeKey<>( + CallType.GET_DEPENDENCIES, + EntityType.USER, + new TypeReference>() { + }), + HttpMethod.GET, + MediaType.APPLICATION_FORM_URLENCODED, + API.USER_ACCOUNT_ENDPOINT + API.MODEL_ID_VAR_PATH_SEGMENT + API.DEPENDENCY_PATH_SEGMENT); + } + +} 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 95a43791..972dba98 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 @@ -72,6 +72,8 @@ public class WidgetFactory { SHOW("show.png"), ACTIVE("active.png"), INACTIVE("inactive.png"), + TOGGLE_ON("toggle_on.png"), + TOGGLE_OFF("toggle_off.png"), YES("yes.png"), NO("no.png"), SAVE("save.png"), diff --git a/src/main/resources/config/application.properties b/src/main/resources/config/application.properties index 992c0cba..850d0d79 100644 --- a/src/main/resources/config/application.properties +++ b/src/main/resources/config/application.properties @@ -5,6 +5,6 @@ spring.mandatory-file-encoding=UTF-8 spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=true -sebserver.version=0.3.0 pre-beta +sebserver.version=0.3.1 pre-beta sebserver.supported.languages=en,de diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 22a04457..932ac266 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -90,8 +90,8 @@ sebserver.institution.action.list.view=View Institution sebserver.institution.action.list.modify=Edit Institution sebserver.institution.action.modify=Edit sebserver.institution.action.save=Save Institution -sebserver.institution.action.activate=Activate -sebserver.institution.action.deactivate=Deactivate +sebserver.institution.action.activate=Toggle Activity +sebserver.institution.action.deactivate=Toggle Activity sebserver.institution.action.delete=Delete Institution sebserver.institution.info.pleaseSelect=Please Select an Institution first. diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index a0553633..e9ec9653 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -84,8 +84,8 @@ sebserver.institution.action.list.view=View Institution sebserver.institution.action.list.modify=Edit Institution sebserver.institution.action.modify=Edit sebserver.institution.action.save=Save Institution -sebserver.institution.action.activate=Activate -sebserver.institution.action.deactivate=Deactivate +sebserver.institution.action.activate=Toggle Activity +sebserver.institution.action.deactivate=Toggle Activity sebserver.institution.action.delete=Delete Institution sebserver.institution.action.export.sebconfig=SEB Client Config diff --git a/src/main/resources/static/images/toggle_off.png b/src/main/resources/static/images/toggle_off.png new file mode 100644 index 0000000000000000000000000000000000000000..3389f4654289d796ff1e7bc3bed94a9642bbe9ad GIT binary patch literal 171 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+0wn(&ce?|miacE$Ln;`PC0;3XB-$OeYh(5( zkPlE{i1buHT;JBubG<>u>P?GgVET{a8>TgKpD0TG(Y5S_e1I6wrA8Uf6>Tpi(v~`_ z7)=m4dmvy6AOi_nqPW)5b+RF1n{qZ}tj3~{o3}Q+jU+6uto1yV$l6X((Z1I9E WA*-I;jb8(_p25@A&t;ucLK6TO{zHTS literal 0 HcmV?d00001 diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebExamConfigurationRequestTest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebExamConfigurationRequestTest.java index 50a941b3..b34b22e3 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebExamConfigurationRequestTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebExamConfigurationRequestTest.java @@ -249,7 +249,6 @@ public class SebExamConfigurationRequestTest extends ExamAPIIntegrationTester { assertEquals( "{\"messageCode\":\"0\",\"systemMessage\":\"Generic error message\",\"details\":\"Missing exam identider or requested exam is not running\",\"attributes\":[]}", contentAsString); - } }