Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add detailed stats on directory view #232

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions owlplug-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@
<groupId>org.jfxtras</groupId>
<artifactId>jmetro</artifactId>
<version>11.6.16</version>
<exclusions>
<exclusion>
<!-- Exclude embedded javafx -->
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
Expand All @@ -41,6 +42,10 @@
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.Tab;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
Expand All @@ -56,9 +61,9 @@ public class DirectoryInfoController extends BaseController {
private FileStatDAO fileStatDAO;

@FXML
private Label directoryPathLabel;
private Label directoryNameLabel;
@FXML
private Label directoryMetricsLabel;
private TextField directoryPathTextField;
@FXML
private ListView<Plugin> pluginDirectoryListView;
@FXML
Expand All @@ -67,7 +72,18 @@ public class DirectoryInfoController extends BaseController {
private Button deleteDirectoryButton;
@FXML
private VBox pieChartContainer;

@FXML
private Tab directoryMetricsTab;
@FXML
private Tab directoryPluginsTab;
@FXML
private Tab directoryFilesTab;
@FXML
private TableView<FileStat> directoryFilesTableView;
@FXML
private TableColumn<FileStat, String> fileNameColumn;
@FXML
private TableColumn<FileStat, String> fileSizeColumn;
private PieChart pieChart;

private PluginDirectory pluginDirectory;
Expand Down Expand Up @@ -132,35 +148,45 @@ protected void layoutChartChildren(double top, double left, double contentWidth,
pieChartContainer.getChildren().add(pieChart);
VBox.setVgrow(pieChart, Priority.ALWAYS);

fileNameColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(cellData.getValue().getName()));

fileSizeColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(
FileUtils.humanReadableByteCount(
cellData.getValue().getLength(), true)));

}

public void setPluginDirectory(PluginDirectory pluginDirectory) {
this.pluginDirectory = pluginDirectory;
directoryPathLabel.setText(pluginDirectory.getPath());
directoryPathTextField.setText(pluginDirectory.getPath());
directoryNameLabel.setText(pluginDirectory.getName());
pluginDirectoryListView.getItems().setAll(pluginDirectory.getPluginList());
directoryMetricsTab.setText("0 KB");


String path = pluginDirectory.getPath();
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}

List<String> directoryMetrics = new ArrayList<>();
Optional<FileStat> directoryStat = fileStatDAO.findByPath(path);
directoryStat.ifPresent(fileStat -> directoryMetrics.add(
directoryStat.ifPresent(fileStat -> directoryMetricsTab.setText(
FileUtils.humanReadableByteCount(fileStat.getLength(), true)));
directoryMetrics.add(pluginDirectory.getPluginList().size() + " plugin(s)");

directoryPluginsTab.setText("Plugins (" + pluginDirectory.getPluginList().size() + ")");

List<FileStat> fileStats = fileStatDAO.findByParentPathOrderByLengthDesc(path);
if (fileStats.size() > 0) {
directoryMetrics.add(fileStats.size() + " file(s)");
}
directoryFilesTab.setText("Files (" + fileStats.size() + ")");

ObservableList<FileStat> obsStats = FXCollections.observableArrayList();
obsStats.addAll(fileStats);
directoryFilesTableView.setItems(obsStats);

pieChart.setData(createStatChartBuckets(fileStats));
pieChart.layout();

directoryMetricsLabel.setText(String.join(" | ", directoryMetrics));

}

private ObservableList<PieChart.Data> createStatChartBuckets(List<FileStat> fileStats) {
Expand Down
122 changes: 71 additions & 51 deletions owlplug-client/src/main/resources/fxml/DirectoryInfoView.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,83 @@
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>

<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.owlplug.core.controllers.DirectoryInfoController">
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.owlplug.core.controllers.DirectoryInfoController">
<children>
<VBox alignment="TOP_CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" spacing="5.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS">
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" spacing="5.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS">
<children>
<Label fx:id="directoryPathLabel" text="DirectoryPath">
<graphic>
<ImageView fitHeight="16.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/folder-grey-16.png" />
</image>
</ImageView>
</graphic>
</Label>
<HBox minHeight="-Infinity" prefHeight="37.0" VBox.vgrow="NEVER">
<HBox alignment="CENTER_RIGHT" spacing="5.0" HBox.hgrow="ALWAYS">
<children>
<HBox alignment="CENTER_LEFT" HBox.hgrow="SOMETIMES">
<children>
<Label fx:id="directoryMetricsLabel" text="METRICS">
<graphic>
<ImageView fitHeight="16.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/chart-white-16.png" />
</image></ImageView>
</graphic></Label>
</children>
</HBox>
<HBox alignment="CENTER_RIGHT" spacing="5.0" HBox.hgrow="ALWAYS">
<children>
<Button fx:id="openDirectoryButton" text="Open directory">
<graphic>
<ImageView fitHeight="16.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/share-white-16.png" />
</image>
</ImageView>
</graphic></Button>
<Button fx:id="deleteDirectoryButton" alignment="CENTER" styleClass="button-danger" text="Delete All">
<graphic>
<ImageView fitHeight="16.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/trash-white-16.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
<Label fx:id="directoryNameLabel" text="DirectoryName">
<graphic>
<ImageView fitHeight="16.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/folder-grey-16.png" />
</image>
</ImageView>
</graphic>
</Label>
<HBox HBox.hgrow="ALWAYS">
</HBox>
<Button fx:id="openDirectoryButton" text="Open directory">
<graphic>
<ImageView fitHeight="16.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/share-white-16.png" />
</image>
</ImageView>
</graphic></Button>
<Button fx:id="deleteDirectoryButton" alignment="CENTER" styleClass="button-danger" text="Delete All">
<graphic>
<ImageView fitHeight="16.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/trash-white-16.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
<VBox.margin>
<Insets top="10.0" />
</VBox.margin>
</HBox>
<ListView fx:id="pluginDirectoryListView" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="SOMETIMES">
<opaqueInsets>
<Insets />
</opaqueInsets>
</ListView>
<TextField fx:id="directoryPathTextField" editable="false" />
<TabPane prefHeight="270.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab fx:id="directoryMetricsTab" disable="true" text="Metrics">
<graphic>
<ImageView fitHeight="16.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/chart-white-16.png" />
</image></ImageView>
</graphic>
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
<Tab fx:id="directoryPluginsTab" text="Plugins">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<ListView fx:id="pluginDirectoryListView" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<opaqueInsets>
<Insets />
</opaqueInsets>
</ListView>
</children>
</AnchorPane>
</content>
</Tab>
<Tab fx:id="directoryFilesTab" text="Files">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0">
<TableView fx:id="directoryFilesTableView" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="fileNameColumn" minWidth="250.0" prefWidth="250.0" text="Name" />
<TableColumn fx:id="fileSizeColumn" editable="false" minWidth="100.0" prefWidth="100.0" sortType="DESCENDING" text="Size" />
</columns>
</TableView>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
<VBox fx:id="pieChartContainer" VBox.vgrow="ALWAYS" />
</children>
<VBox.margin>
Expand Down