Skip to content

Commit

Permalink
Ability to view a summary of a user
Browse files Browse the repository at this point in the history
  • Loading branch information
rxdps93 committed Apr 11, 2019
1 parent 5e32d29 commit e5459e3
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,27 +49,30 @@ private void configureContent() {
public void run() {

List<String> 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());
}
})
.addAction("Edit User Permissions", new Runnable() {
@Override
public void run() {
System.out.println("edit permissions");
// TODO: Future task
}
})
.addAction("Remove User", new Runnable() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> permissions = new Table<String>("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));
}
}
46 changes: 28 additions & 18 deletions src/main/java/com/dom/freeman/obj/UserPermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/main/resources/users.csv
Original file line number Diff line number Diff line change
@@ -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,

0 comments on commit e5459e3

Please sign in to comment.