diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 356254a4..e9aeba6a 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -48,6 +48,7 @@ opens org.chainoptim.desktop.core.organization.controller to javafx.fxml, com.google.guice; opens org.chainoptim.desktop.core.organization.service to com.google.guice; opens org.chainoptim.desktop.core.organization.model to com.fasterxml.jackson.databind; + opens org.chainoptim.desktop.core.organization.dto to com.fasterxml.jackson.databind; // Features // - Product diff --git a/src/main/java/org/chainoptim/desktop/core/main/controller/OverviewController.java b/src/main/java/org/chainoptim/desktop/core/main/controller/OverviewController.java index b39d1c16..54106db1 100644 --- a/src/main/java/org/chainoptim/desktop/core/main/controller/OverviewController.java +++ b/src/main/java/org/chainoptim/desktop/core/main/controller/OverviewController.java @@ -36,17 +36,13 @@ public void initialize(URL location, ResourceBundle resources) { } private void fetchAndSetUser(String username) { - try { - userService.getUserByUsername(username) - .thenAcceptAsync(userOptional -> userOptional.ifPresentOrElse(this::updateCurrentUser, - () -> Platform.runLater(() -> System.err.println("User not found.")))) - .exceptionally(ex -> { - Platform.runLater(() -> System.err.println("Failed to load user: " + ex.getMessage())); - return null; - }); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException("Error encoding username: " + e.getMessage()); - } + userService.getUserByUsername(username) + .thenAcceptAsync(userOptional -> userOptional.ifPresentOrElse(this::updateCurrentUser, + () -> Platform.runLater(() -> System.err.println("User not found.")))) + .exceptionally(ex -> { + Platform.runLater(() -> System.err.println("Failed to load user: " + ex.getMessage())); + return null; + }); } private void updateCurrentUser(User user) { diff --git a/src/main/java/org/chainoptim/desktop/core/organization/controller/ConfirmCustomRoleDeleteController.java b/src/main/java/org/chainoptim/desktop/core/organization/controller/ConfirmCustomRoleDeleteController.java new file mode 100644 index 00000000..8230e25d --- /dev/null +++ b/src/main/java/org/chainoptim/desktop/core/organization/controller/ConfirmCustomRoleDeleteController.java @@ -0,0 +1,81 @@ +package org.chainoptim.desktop.core.organization.controller; + +import org.chainoptim.desktop.core.organization.model.ConfirmDeleteDialogActionListener; +import org.chainoptim.desktop.core.organization.model.ConfirmUpdateDialogActionListener; +import org.chainoptim.desktop.core.organization.model.CustomRole; +import org.chainoptim.desktop.core.user.model.User; +import org.chainoptim.desktop.core.user.service.UserService; +import org.chainoptim.desktop.shared.util.DataReceiver; +import com.google.inject.Inject; +import javafx.application.Platform; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.VBox; +import lombok.Setter; + +import java.util.List; +import java.util.Optional; + +public class ConfirmCustomRoleDeleteController implements DataReceiver { + + private final UserService userService; + + private Integer customRoleId; + + @Setter + private ConfirmDeleteDialogActionListener actionListener; + + @FXML + private VBox usersVBox; + @FXML + private Button confirmButton; + @FXML + private Button cancelButton; + + @Inject + public ConfirmCustomRoleDeleteController(UserService userService) { + this.userService = userService; + } + + @Override + public void setData(Integer customRoleId) { + this.customRoleId = customRoleId; + + userService.getUsersByCustomRoleId(customRoleId) + .thenApply(this::handleUsersResponse) + .exceptionally(this::handleUsersException); + } + + private Optional> handleUsersResponse(Optional> users) { + if (users.isEmpty()) { + return Optional.empty(); + } + Platform.runLater(() -> { + List userList = users.get(); + usersVBox.getChildren().clear(); + + for (User user : userList) { + // Put names into VBox + Label usernameLabel = new Label(user.getUsername()); + usersVBox.getChildren().add(usernameLabel); + } + }); + return users; + } + + private Optional> handleUsersException(Throwable ex) { + ex.printStackTrace(); + return Optional.empty(); + } + + @FXML + private void onConfirmButtonClicked() { + actionListener.onConfirmCustomRoleDelete(customRoleId); + } + + @FXML + private void onCancelButtonClicked() { + actionListener.onCancelCustomRoleDelete(); + } +} diff --git a/src/main/java/org/chainoptim/desktop/core/organization/controller/ConfirmCustomRoleUpdateController.java b/src/main/java/org/chainoptim/desktop/core/organization/controller/ConfirmCustomRoleUpdateController.java new file mode 100644 index 00000000..e96d30df --- /dev/null +++ b/src/main/java/org/chainoptim/desktop/core/organization/controller/ConfirmCustomRoleUpdateController.java @@ -0,0 +1,80 @@ +package org.chainoptim.desktop.core.organization.controller; + +import org.chainoptim.desktop.core.organization.model.ConfirmUpdateDialogActionListener; +import org.chainoptim.desktop.core.organization.model.CustomRole; +import org.chainoptim.desktop.core.user.model.User; +import org.chainoptim.desktop.core.user.service.UserService; +import org.chainoptim.desktop.shared.util.DataReceiver; +import com.google.inject.Inject; +import javafx.application.Platform; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.VBox; +import lombok.Setter; + +import java.util.List; +import java.util.Optional; + +public class ConfirmCustomRoleUpdateController implements DataReceiver { + + private final UserService userService; + + private CustomRole customRole; + + @Setter + private ConfirmUpdateDialogActionListener confirmUpdateDialogActionListener; + + @FXML + private VBox usersVBox; + @FXML + private Button confirmButton; + @FXML + private Button cancelButton; + + @Inject + public ConfirmCustomRoleUpdateController(UserService userService) { + this.userService = userService; + } + + @Override + public void setData(CustomRole data) { + this.customRole = data; + System.out.println("Custom role: " + customRole.getName()); + + userService.getUsersByCustomRoleId(customRole.getId()) + .thenApply(this::handleUsersResponse) + .exceptionally(this::handleUsersException); + } + + private Optional> handleUsersResponse(Optional> users) { + if (users.isEmpty()) { + System.out.println("No users found for custom role: " + customRole.getName()); + return Optional.empty(); + } + Platform.runLater(() -> { + List userList = users.get(); + for (User user : userList) { + // Put names into VBox + Label usernameLabel = new Label(user.getUsername()); + usersVBox.getChildren().add(usernameLabel); + } + }); + return users; + } + + private Optional> handleUsersException(Throwable ex) { + ex.printStackTrace(); + return Optional.empty(); + } + + @FXML + private void onConfirmButtonClicked() { + confirmUpdateDialogActionListener.onConfirmCustomRoleUpdate(customRole); + } + + @FXML + private void onCancelButtonClicked() { + confirmUpdateDialogActionListener.onCancelCustomRoleUpdate(); + } +} diff --git a/src/main/java/org/chainoptim/desktop/core/organization/controller/OrganizationController.java b/src/main/java/org/chainoptim/desktop/core/organization/controller/OrganizationController.java index b98f7976..27e2df53 100644 --- a/src/main/java/org/chainoptim/desktop/core/organization/controller/OrganizationController.java +++ b/src/main/java/org/chainoptim/desktop/core/organization/controller/OrganizationController.java @@ -167,8 +167,7 @@ private Optional handleOrganizationException(Throwable ex) { } @FXML - private void handleChangePlan() { - - loadTabContent(subscriptionPlanTab, "/org/chainoptim/desktop/core/organization/OrganizationSubscriptionPlanView.fxml", this.organization); + private void handleEditOrganization() { + System.out.println("Edit organization clicked"); } } diff --git a/src/main/java/org/chainoptim/desktop/core/organization/controller/OrganizationCustomRolesController.java b/src/main/java/org/chainoptim/desktop/core/organization/controller/OrganizationCustomRolesController.java index 6b4c26c6..88a81f38 100644 --- a/src/main/java/org/chainoptim/desktop/core/organization/controller/OrganizationCustomRolesController.java +++ b/src/main/java/org/chainoptim/desktop/core/organization/controller/OrganizationCustomRolesController.java @@ -1,87 +1,160 @@ package org.chainoptim.desktop.core.organization.controller; +import org.chainoptim.desktop.core.abstraction.ControllerFactory; +import org.chainoptim.desktop.core.organization.dto.CreateCustomRoleDTO; import org.chainoptim.desktop.core.organization.dto.UpdateCustomRoleDTO; -import org.chainoptim.desktop.core.organization.model.CustomRole; -import org.chainoptim.desktop.core.organization.model.FeaturePermissions; -import org.chainoptim.desktop.core.organization.model.Organization; -import org.chainoptim.desktop.core.organization.model.Permissions; +import org.chainoptim.desktop.core.organization.model.*; import org.chainoptim.desktop.core.organization.service.CustomRoleService; import org.chainoptim.desktop.shared.fallback.FallbackManager; import org.chainoptim.desktop.shared.util.DataReceiver; +import org.chainoptim.desktop.shared.util.resourceloader.FXMLLoaderService; import com.google.inject.Inject; import javafx.application.Platform; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.scene.Node; -import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; -import javafx.scene.control.Control; -import javafx.scene.control.Label; +import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; -import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; -import javafx.scene.layout.Region; -import javafx.scene.layout.RowConstraints; +import javafx.scene.layout.StackPane; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; -public class OrganizationCustomRolesController implements DataReceiver { +public class OrganizationCustomRolesController implements DataReceiver, ConfirmUpdateDialogActionListener, ConfirmDeleteDialogActionListener { + // Injected services and controllers private final CustomRoleService customRoleService; - + private final FXMLLoaderService fxmlLoaderService; + private final ControllerFactory controllerFactory; private final FallbackManager fallbackManager; - private Organization organization; - private List customRoles; + private ConfirmCustomRoleUpdateController confirmCustomRoleUpdateController; + private ConfirmCustomRoleDeleteController confirmCustomRoleDeleteController; + // FXML + @FXML + private Label tabTitle; + @FXML + private Button addNewRoleButton; + @FXML + private Button deleteRoleButton; @FXML private GridPane customRolesPane; @FXML private List