From e5459e3e02082bcbf2d65312b438c34c734a966e Mon Sep 17 00:00:00 2001 From: rxdps93 <> Date: Thu, 11 Apr 2019 14:37:54 -0400 Subject: [PATCH] Ability to view a summary of a user --- .../dialog/ViewItemSummaryDialog.java | 3 +- .../components/users/UserViewPanel.java | 13 ++- .../users/dialog/ViewUserSummaryDialog.java | 80 +++++++++++++++++++ .../com/dom/freeman/obj/UserPermission.java | 46 ++++++----- src/main/resources/users.csv | 1 + 5 files changed, 119 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/dom/freeman/components/users/dialog/ViewUserSummaryDialog.java diff --git a/src/main/java/com/dom/freeman/components/inventory/dialog/ViewItemSummaryDialog.java b/src/main/java/com/dom/freeman/components/inventory/dialog/ViewItemSummaryDialog.java index 4478a1c..f319098 100644 --- a/src/main/java/com/dom/freeman/components/inventory/dialog/ViewItemSummaryDialog.java +++ b/src/main/java/com/dom/freeman/components/inventory/dialog/ViewItemSummaryDialog.java @@ -24,7 +24,7 @@ public ViewItemSummaryDialog(String title, Item item) { this.configureContent(item); } - public void configureContent(Item item) { + private void configureContent(Item item) { Panel mainPanel = new Panel(new GridLayout(2)); @@ -50,7 +50,6 @@ public void configureContent(Item item) { mainPanel.addComponent(this.dialogSpacer()); mainPanel.addComponent(summary); - // Item Tags TODO: Make this look less bad Panel itemTagPanel = new Panel(new GridLayout(3)).setLayoutData( GridLayout.createHorizontallyFilledLayoutData(2)); diff --git a/src/main/java/com/dom/freeman/components/users/UserViewPanel.java b/src/main/java/com/dom/freeman/components/users/UserViewPanel.java index 4816793..d45ec53 100644 --- a/src/main/java/com/dom/freeman/components/users/UserViewPanel.java +++ b/src/main/java/com/dom/freeman/components/users/UserViewPanel.java @@ -6,7 +6,9 @@ import com.dom.freeman.Global; import com.dom.freeman.Utility; import com.dom.freeman.components.users.dialog.EditUserDialog; +import com.dom.freeman.components.users.dialog.ViewUserSummaryDialog; import com.dom.freeman.components.users.tables.UserViewTable; +import com.dom.freeman.obj.User; import com.googlecode.lanterna.gui2.Borders; import com.googlecode.lanterna.gui2.Interactable; import com.googlecode.lanterna.gui2.LayoutManager; @@ -47,19 +49,22 @@ private void configureContent() { public void run() { List data = userTable.getTableModel().getRow(userTable.getSelectedRow()); + User selectedUser = Utility.METHODS.getUserById(data.get(userTable.getTableModel().getColumnCount() - 1)); new ActionListDialogBuilder().setTitle("SELECT AN ACTION") .addAction("View User Summary", new Runnable() { @Override public void run() { - System.out.println("user summary"); + ViewUserSummaryDialog viewUser = new ViewUserSummaryDialog("USER SUMMARY", + selectedUser); + viewUser.setHints(Arrays.asList(Hint.CENTERED)); + viewUser.showDialog(parent.getTextGUI()); } }) .addAction("Edit User Details", new Runnable() { @Override public void run() { - EditUserDialog editUser = new EditUserDialog("EDIT USER", - Utility.METHODS.getUserById(data.get(userTable.getTableModel().getColumnCount() - 1))); + EditUserDialog editUser = new EditUserDialog("EDIT USER", selectedUser); editUser.setHints(Arrays.asList(Hint.CENTERED)); editUser.showDialog(parent.getTextGUI()); } @@ -67,7 +72,7 @@ public void run() { .addAction("Edit User Permissions", new Runnable() { @Override public void run() { - System.out.println("edit permissions"); + // TODO: Future task } }) .addAction("Remove User", new Runnable() { diff --git a/src/main/java/com/dom/freeman/components/users/dialog/ViewUserSummaryDialog.java b/src/main/java/com/dom/freeman/components/users/dialog/ViewUserSummaryDialog.java new file mode 100644 index 0000000..c3cfb89 --- /dev/null +++ b/src/main/java/com/dom/freeman/components/users/dialog/ViewUserSummaryDialog.java @@ -0,0 +1,80 @@ +package com.dom.freeman.components.users.dialog; + +import com.dom.freeman.obj.User; +import com.dom.freeman.obj.UserPermission; +import com.googlecode.lanterna.SGR; +import com.googlecode.lanterna.TerminalSize; +import com.googlecode.lanterna.gui2.Borders; +import com.googlecode.lanterna.gui2.Button; +import com.googlecode.lanterna.gui2.EmptySpace; +import com.googlecode.lanterna.gui2.GridLayout; +import com.googlecode.lanterna.gui2.Label; +import com.googlecode.lanterna.gui2.LocalizedString; +import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.GridLayout.Alignment; +import com.googlecode.lanterna.gui2.dialogs.DialogWindow; +import com.googlecode.lanterna.gui2.table.Table; + +public class ViewUserSummaryDialog extends DialogWindow { + + public ViewUserSummaryDialog(String title, User user) { + super(title); + this.configureContent(user); + } + + private void configureContent(User user) { + + Panel mainPanel = new Panel(new GridLayout(2)); + + // Description + mainPanel.addComponent(new Label("Summary for selected user").setLayoutData( + GridLayout.createLayoutData(Alignment.BEGINNING, Alignment.CENTER, + false, false, 2, 1))); + + // User details + mainPanel.addComponent(this.dialogSpacer()); + + mainPanel.addComponent(new Label("First Name").addStyle(SGR.BOLD)); + mainPanel.addComponent(new Label(user.getFirstName())); + + mainPanel.addComponent(new Label("Last Name").addStyle(SGR.BOLD)); + mainPanel.addComponent(new Label(user.getLastName())); + + mainPanel.addComponent(new Label("Display Name").addStyle(SGR.BOLD)); + mainPanel.addComponent(new Label(user.getDisplayName())); + + // User Permissions + mainPanel.addComponent(this.dialogSpacer()); + if (user.getUserPermissions().size() == 0) { + mainPanel.addComponent(new Label("This user has no permissions.").setLayoutData( + GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER, + false, false, 2, 1))); + } else { + Table permissions = new Table("PERMISSION", "DESCRIPTION"); + permissions.setEnabled(false); + for (UserPermission permission : user.getUserPermissions()) { + permissions.getTableModel().addRow( + permission.toString(), permission.getDescription()); + } + permissions.setLayoutData(GridLayout.createLayoutData( + Alignment.FILL, Alignment.FILL, true, true, 2, 1)); + mainPanel.addComponent(permissions.withBorder(Borders.singleLine("Permissions"))); + } + + // Buttons + mainPanel.addComponent(this.dialogSpacer()); + mainPanel.addComponent(new EmptySpace(TerminalSize.ONE)); + mainPanel.addComponent(new Button(LocalizedString.OK.toString(), new Runnable() { + @Override + public void run() { + close(); + } + })); + + this.setComponent(mainPanel); + } + + private EmptySpace dialogSpacer() { + return new EmptySpace().setLayoutData(GridLayout.createHorizontallyFilledLayoutData(2)); + } +} diff --git a/src/main/java/com/dom/freeman/obj/UserPermission.java b/src/main/java/com/dom/freeman/obj/UserPermission.java index e3962bc..ccbc5c4 100644 --- a/src/main/java/com/dom/freeman/obj/UserPermission.java +++ b/src/main/java/com/dom/freeman/obj/UserPermission.java @@ -2,28 +2,38 @@ public enum UserPermission { - ADD_ITEM, - EDIT_ITEM, - REMOVE_ITEM, + ADD_ITEM("Ability to add a new item to the inventory"), + EDIT_ITEM("Ability to edit an existing item in the inventory"), + REMOVE_ITEM("Ability to remove an existing item from the inventory"), - ADD_ITEM_TAG, - EDIT_ITEM_TAG, - REMOVE_ITEM_TAG, + ADD_ITEM_TAG("Ability to create a new item tag"), + EDIT_ITEM_TAG("Ability to edit an existing item tag"), + REMOVE_ITEM_TAG("Ability to remove an existing item tag"), - ASSIGN_ITEM_TAG, - UNASSIGN_ITEM_TAG, + ASSIGN_ITEM_TAG("Ability to associate an item and item tag"), + UNASSIGN_ITEM_TAG("Ability to unassociate an item and item tag"), - ADD_PERMANENT_TAG, - EDIT_PERMANENT_TAG, - REMOVE_PERMANENT_TAG, + ADD_PERMANENT_TAG("Ability to create a new permanent tag"), + EDIT_PERMANENT_TAG("Ability to edit an existing permanent tag"), + REMOVE_PERMANENT_TAG("Ability to remove an existing permanent tag"), - ADD_USER, - EDIT_USER, - REMOVE_USER, + ADD_USER("Ability to add a new user to the system"), + EDIT_USER("Ability to edit an existing user"), + REMOVE_USER("Ability to remove an existing user"), - GRANT_USER_PERMISSION, - REVOKE_USER_PERMISSION, + GRANT_USER_PERMISSION("Ability to grant a user permissions"), + REVOKE_USER_PERMISSION("Ability to revoke permissions from a user"), - VIEW_TRANSACTIONS_SELF, - VIEW_TRANSACTIONS_ALL; + VIEW_TRANSACTIONS_SELF("Ability to see a history of your actions in the system"), + VIEW_TRANSACTIONS_ALL("Ability to see a history of all users' actions in the system"); + + private String description; + + private UserPermission(String description) { + this.description = description; + } + + public String getDescription() { + return this.description; + } } diff --git a/src/main/resources/users.csv b/src/main/resources/users.csv index 942ff1b..8e78af2 100644 --- a/src/main/resources/users.csv +++ b/src/main/resources/users.csv @@ -1,3 +1,4 @@ "Donald","Trump","GEOTUS","3d1e48ce-a651-48b6-bd8f-e540fe8db73b","" "Richard","Stallman","rms.sexy","bfff8b19-b48f-41d7-b000-942646135f45","" "Terry","Davis","temple","0a85af4c-18cb-401f-bace-efcc42de11c7","" +Theodore,Roosevelt,teddy,08a53765-46d8-4326-b302-b4d419a4be85,