Skip to content

Commit

Permalink
show logs for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
parhampch committed Jul 23, 2020
1 parent c174b73 commit d2f569a
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 28 deletions.
56 changes: 31 additions & 25 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 93 additions & 3 deletions src/main/java/View/Menu/AdminMenus/AdminMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Model.Account.AdminAccount;
import Model.Account.BuyerAccount;
import Model.Account.SellerAccount;
import Model.Log.BuyLog;
import Model.Product.Category;
import Model.Product.DiscountAndOff.Discount;
import Model.Product.Product;
Expand Down Expand Up @@ -94,6 +95,11 @@ public void show() {
manageDiscounts.getStyleClass().add("dark-blue");
manageDiscounts.setMaxWidth(Double.MAX_VALUE);

Button manageLogs = new Button("Manage Logs");
manageLogs.setOnAction(e -> handleAllLogs());
manageLogs.getStyleClass().add("dark-blue");
manageLogs.setMaxWidth(Double.MAX_VALUE);

Button manageAddAdmin = new Button("Add Manager");
manageAddAdmin.setOnAction(e -> handleAddAdmin());
manageAddAdmin.getStyleClass().add("dark-blue");
Expand All @@ -107,8 +113,9 @@ public void show() {
GridPane.setConstraints(manageProduct, 0, 4);
GridPane.setConstraints(manageCategories, 0, 5);
GridPane.setConstraints(manageDiscounts, 0, 6);
GridPane.setConstraints(manageAddAdmin, 0, 7);
GridPane.setConstraints(logout, 0, 8);
GridPane.setConstraints(manageLogs, 0, 7);
GridPane.setConstraints(manageAddAdmin, 0, 8);
GridPane.setConstraints(logout, 0, 9);
GridPane.setHalignment(editInfoButton, HPos.CENTER);
GridPane.setHalignment(manageUser, HPos.CENTER);
GridPane.setHalignment(onlineUser, HPos.CENTER);
Expand All @@ -117,9 +124,10 @@ public void show() {
GridPane.setHalignment(manageCategories, HPos.CENTER);
GridPane.setHalignment(manageDiscounts, HPos.CENTER);
GridPane.setHalignment(manageAddAdmin, HPos.CENTER);
GridPane.setHalignment(manageLogs, HPos.CENTER);
GridPane.setHalignment(logout, HPos.CENTER);

allButtons.getChildren().addAll(editInfoButton, manageUser, manageRequest, manageProduct, manageCategories, manageDiscounts, manageAddAdmin, logout, onlineUser);
allButtons.getChildren().addAll(editInfoButton, manageUser, manageRequest, manageProduct, manageCategories, manageDiscounts, manageAddAdmin, logout, onlineUser, manageLogs);

try {
dataOutputStream.writeUTF("GetLoggedAccount");
Expand Down Expand Up @@ -406,6 +414,88 @@ public void handleManageProduct()
}
}

private void handleAllLogs()
{
try {
super.setPane();
dataOutputStream.writeUTF("GetAllBuyerAccounts");
dataOutputStream.flush();
ArrayList<BuyerAccount> allBuyers = new Gson().fromJson(dataInputStream.readUTF(), new TypeToken<ArrayList<BuyerAccount>>(){}.getType());
ArrayList<BuyLog> allLogs = new ArrayList<>();
for (BuyerAccount buyer : allBuyers) {
allLogs.addAll(buyer.getBuyLogs());
}
Scene scene = new Scene(super.mainPane, 1000, 600);
scene.getStylesheets().add(new File("Data/Styles/Buttons.css").toURI().toString());
scene.getStylesheets().add(new File("Data/Styles/textfield.css").toURI().toString());
scene.getStylesheets().add(new File("Data/Styles/backgrounds.css").toURI().toString());
scene.getStylesheets().add(new File("Data/Styles/choicebox.css").toURI().toString());
super.mainPane.getStyleClass().add("admin-page");
ScrollPane scrollPane = new ScrollPane();
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);
scrollPane.getStyleClass().add("scroll-pane");
GridPane gridPane = new GridPane();
gridPane.setHgap(20);
gridPane.setVgap(10);
gridPane.setAlignment(Pos.CENTER);
Label info = new Label("All Buy Logs");
info.setFont(Font.font(25));
GridPane.setHalignment(info, HPos.CENTER);
info.setAlignment(Pos.CENTER);
GridPane.setConstraints(info, 1, 0);
gridPane.getChildren().add(info);
int i = 1;
for (BuyLog buyLog : allLogs) {
Label label = new Label(String.valueOf(buyLog.getLogId()));
label.setFont(Font.font(15));
Button button = new Button("show");
button.setMaxWidth(Double.MAX_VALUE);
button.getStyleClass().add("dark-blue");
button.setAlignment(Pos.CENTER);
button.setOnAction(e -> {
handleShowLog(buyLog);
});
GridPane.setConstraints(label, 0, i);
GridPane.setConstraints(button, 2, i);
gridPane.getChildren().addAll(label, button);
i++;
}
Button back = new Button("back");
back.setAlignment(Pos.CENTER);
back.getStyleClass().add("dark-blue");
back.setMaxWidth(Double.MAX_VALUE);
GridPane.setHalignment(back, HPos.CENTER);
back.setOnAction(e -> show());
GridPane.setConstraints(back,1, i);
gridPane.getChildren().add(back);

scrollPane.setContent(gridPane);
super.mainPane.setCenter(scrollPane);

Menu.window.setScene(scene);
}
catch (Exception e)
{
e.printStackTrace();
}
}

private void handleShowLog(BuyLog buyLog) {
Stage newWindow = new Stage();
Pane pane = buyLog.showLogWithGraphic();
((GridPane)pane).setAlignment(Pos.CENTER);
Scene scene = new Scene(pane, 600, 400);
scene.getStylesheets().add(new File("Data/Styles/backgrounds.css").toURI().toString());
pane.getStyleClass().add("admin-popup");

newWindow.setScene(scene);
newWindow.initModality(Modality.APPLICATION_MODAL);
newWindow.setOnCloseRequest(e -> handleAllLogs());
newWindow.showAndWait();
}

public void handleManageUsers()
{
try {
Expand Down

0 comments on commit d2f569a

Please sign in to comment.