Skip to content

Commit

Permalink
https://github.com/StephaneCouturier/Katalog/issues/534
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneCouturier committed Jul 7, 2024
1 parent 03a545c commit 9d94af6
Showing 1 changed file with 93 additions and 46 deletions.
139 changes: 93 additions & 46 deletions src/mainwindow_tab_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,29 +1448,8 @@ void MainWindow::loadDevicesTreeToModel(QString targetTreeModel)
QSqlQuery query;
QString querySQL;

//For the complete Device tree
querySQL = QLatin1String(R"(
SELECT device_id,
device_parent_id,
device_name,
device_type,
device_external_id,
device_path,
device_total_file_size,
device_total_file_count,
device_total_space,
device_free_space,
device_active,
device_group_id,
device_date_updated,
device_order
FROM device
)");

if (ui->Devices_checkBox_DisplayPhysicalGroup->isChecked() == true and
ui->Devices_checkBox_DisplayVirtualGroups->isChecked() == false) {

querySQL = QLatin1String(R"(
WITH RECURSIVE device_tree AS (
SELECT
device_id,
Expand All @@ -1485,9 +1464,10 @@ void MainWindow::loadDevicesTreeToModel(QString targetTreeModel)
device_free_space,
device_active,
device_group_id,
device_date_updated
device_date_updated,
0 AS level
FROM device
WHERE device_id = 1
WHERE device_parent_id =0
UNION ALL
Expand All @@ -1504,11 +1484,35 @@ void MainWindow::loadDevicesTreeToModel(QString targetTreeModel)
child.device_free_space,
child.device_active,
child.device_group_id,
child.device_date_updated
child.device_date_updated,
parent.level + 1 AS level
FROM device_tree parent
JOIN device child ON child.device_parent_id = parent.device_id
)
SELECT
device_id,
device_parent_id,
device_name,
device_type,
device_external_id,
device_path,
device_total_file_size,
device_total_file_count,
device_total_space,
device_free_space,
device_active,
device_group_id,
device_date_updated,
level
FROM device_tree
)");

if (ui->Devices_checkBox_DisplayPhysicalGroup->isChecked() == true and
ui->Devices_checkBox_DisplayVirtualGroups->isChecked() == false) {
//For the Physical Group only
querySQL = QLatin1String(R"(
WITH RECURSIVE device_tree AS (
SELECT
device_id,
device_parent_id,
device_name,
Expand All @@ -1521,13 +1525,53 @@ void MainWindow::loadDevicesTreeToModel(QString targetTreeModel)
device_free_space,
device_active,
device_group_id,
device_date_updated
device_date_updated,
0 AS level
FROM device
WHERE device_parent_id =0
AND device_group_id=0
UNION ALL
SELECT
child.device_id,
child.device_parent_id,
child.device_name,
child.device_type,
child.device_external_id,
child.device_path,
child.device_total_file_size,
child.device_total_file_count,
child.device_total_space,
child.device_free_space,
child.device_active,
child.device_group_id,
child.device_date_updated,
parent.level + 1 AS level
FROM device_tree parent
JOIN device child ON child.device_parent_id = parent.device_id
)
SELECT
device_id,
device_parent_id,
device_name,
device_type,
device_external_id,
device_path,
device_total_file_size,
device_total_file_count,
device_total_space,
device_free_space,
device_active,
device_group_id,
device_date_updated,
level
FROM device_tree
)");
}
else if (ui->Devices_checkBox_DisplayPhysicalGroup->isChecked() == false and
ui->Devices_checkBox_DisplayVirtualGroups->isChecked() == true) {

//For the Virtual Groups only
querySQL = QLatin1String(R"(
WITH RECURSIVE device_tree AS (
SELECT
Expand All @@ -1543,9 +1587,11 @@ void MainWindow::loadDevicesTreeToModel(QString targetTreeModel)
device_free_space,
device_active,
device_group_id,
device_date_updated
device_date_updated,
0 AS level
FROM device
WHERE device_id <> 1
WHERE device_parent_id <>1
AND device_group_id !=0
UNION ALL
Expand All @@ -1562,25 +1608,26 @@ void MainWindow::loadDevicesTreeToModel(QString targetTreeModel)
child.device_free_space,
child.device_active,
child.device_group_id,
child.device_date_updated
child.device_date_updated,
parent.level + 1 AS level
FROM device_tree parent
JOIN device child ON child.device_parent_id = parent.device_id
WHERE parent.device_id <> 1
)
SELECT DISTINCT
device_id,
device_parent_id,
device_name,
device_type,
device_external_id,
device_path,
device_total_file_size,
device_total_file_count,
device_total_space,
device_free_space,
device_active,
device_group_id,
device_date_updated
SELECT
device_id,
device_parent_id,
device_name,
device_type,
device_external_id,
device_path,
device_total_file_size,
device_total_file_count,
device_total_space,
device_free_space,
device_active,
device_group_id,
device_date_updated,
level
FROM device_tree
)");
}
Expand All @@ -1603,7 +1650,7 @@ void MainWindow::loadDevicesTreeToModel(QString targetTreeModel)
)");
}

querySQL +=" ORDER BY device_type DESC, device_parent_id ASC, device_id ASC ";
querySQL +=" ORDER BY level ASC, device_type DESC, device_parent_id ASC, device_id ASC ";
query.prepare(querySQL);
query.exec();

Expand Down

0 comments on commit 9d94af6

Please sign in to comment.