-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from SorinPopteanu/add-factories
Add Organization roles
- Loading branch information
Showing
23 changed files
with
1,060 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...rg/chainoptim/desktop/core/organization/controller/ConfirmCustomRoleDeleteController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Integer> { | ||
|
||
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<List<User>> handleUsersResponse(Optional<List<User>> users) { | ||
if (users.isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
Platform.runLater(() -> { | ||
List<User> 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<List<User>> handleUsersException(Throwable ex) { | ||
ex.printStackTrace(); | ||
return Optional.empty(); | ||
} | ||
|
||
@FXML | ||
private void onConfirmButtonClicked() { | ||
actionListener.onConfirmCustomRoleDelete(customRoleId); | ||
} | ||
|
||
@FXML | ||
private void onCancelButtonClicked() { | ||
actionListener.onCancelCustomRoleDelete(); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...rg/chainoptim/desktop/core/organization/controller/ConfirmCustomRoleUpdateController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CustomRole> { | ||
|
||
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<List<User>> handleUsersResponse(Optional<List<User>> users) { | ||
if (users.isEmpty()) { | ||
System.out.println("No users found for custom role: " + customRole.getName()); | ||
return Optional.empty(); | ||
} | ||
Platform.runLater(() -> { | ||
List<User> 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<List<User>> handleUsersException(Throwable ex) { | ||
ex.printStackTrace(); | ||
return Optional.empty(); | ||
} | ||
|
||
@FXML | ||
private void onConfirmButtonClicked() { | ||
confirmUpdateDialogActionListener.onConfirmCustomRoleUpdate(customRole); | ||
} | ||
|
||
@FXML | ||
private void onCancelButtonClicked() { | ||
confirmUpdateDialogActionListener.onCancelCustomRoleUpdate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.