diff --git a/Frontend/DashboardsViewer/CMakeLists.txt b/Frontend/DashboardsViewer/CMakeLists.txt index f3d32c3..31a4fff 100644 --- a/Frontend/DashboardsViewer/CMakeLists.txt +++ b/Frontend/DashboardsViewer/CMakeLists.txt @@ -84,4 +84,7 @@ else() add_custom_command(TARGET DashboardsViewerApp POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/qml/OpenTeraLibs ${CMAKE_CURRENT_SOURCE_DIR}/imports/generated/OpenTeraLibs) + add_custom_command(TARGET DashboardsViewerApp POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_BINARY_DIR}/qml/DashboardsViewer ${CMAKE_CURRENT_SOURCE_DIR}/imports/generated/DashboardsViewer) endif() diff --git a/Frontend/DashboardsViewer/content/CMakeLists.txt b/Frontend/DashboardsViewer/content/CMakeLists.txt index 977e5a6..789c5ef 100644 --- a/Frontend/DashboardsViewer/content/CMakeLists.txt +++ b/Frontend/DashboardsViewer/content/CMakeLists.txt @@ -8,9 +8,7 @@ qt6_add_qml_module(content App.qml # Screens screens/Dashboard.qml - screens/DashboardForm.ui.qml screens/DashboardSelector.qml - screens/DashboardSelectorForm.ui.qml screens/Login.qml # Uis ui/BasicButton.ui.qml diff --git a/Frontend/DashboardsViewer/content/screens/Dashboard.qml b/Frontend/DashboardsViewer/content/screens/Dashboard.qml index df22a82..a967c58 100644 --- a/Frontend/DashboardsViewer/content/screens/Dashboard.qml +++ b/Frontend/DashboardsViewer/content/screens/Dashboard.qml @@ -1,14 +1,18 @@ import QtQuick 2.15 +import QtQuick.Controls 2.15 import OpenTeraLibs.UserClient 1.0 import DashboardsViewer.ConfigParser 1.0 -DashboardForm { +import DashboardsViewer - id: dashboard - property string definition : "" +Item { + width: 1024 + height: 768 + anchors.fill: parent + property string definition: "" - signal buttonClicked() + signal buttonClicked ConfigParser { id: parser @@ -17,35 +21,56 @@ DashboardForm { function loadDocument() { console.log("should load document", definition) - var dynamicQML = parser.parseConfigString(definition); + var dynamicQML = parser.parseConfigString(definition) console.log("dynamicQML", dynamicQML) - if (dynamicQML.length > 0) - { - for (var i = 0; i < dynamicQML.length; i++) - { + if (dynamicQML.length > 0) { + for (var i = 0; i < dynamicQML.length; i++) { - try { + try { //Create object from dynamicQML - var dynamicObject = Qt.createQmlObject(dynamicQML[i], dashboardStackView); + var dynamicObject = Qt.createQmlObject(dynamicQML[i], + dashboardStackView) console.log("dynamicObject", dynamicObject) // Push to stackView - if (dynamicObject) - { - dashboardStackView.push(dynamicObject); + if (dynamicObject) { + dashboardStackView.push(dynamicObject) } + } catch (e) { + console.log("Error", e) + } + } + } + } + + Text { + id: dashboardText + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: parent.top + text: qsTr("DASHBOARD") + font.pixelSize: 60 + height: 60 + horizontalAlignment: Text.AlignHCenter + } - } - catch(e) { - console.log("Error", e) - } - } + Button { + id: closeButton + anchors.left: loadButton.right + anchors.top: parent.top + width: 150 + height: 60 + text: qsTr("Close") + onClicked: function () { + stackview.pop() } } - closeButton.onClicked: function() { - stackview.pop(); + StackView { + id: dashboardStackView + anchors.top: dashboardText.bottom + anchors.bottom: parent.bottom + width: parent.width } } diff --git a/Frontend/DashboardsViewer/content/screens/DashboardForm.ui.qml b/Frontend/DashboardsViewer/content/screens/DashboardForm.ui.qml deleted file mode 100644 index 120f717..0000000 --- a/Frontend/DashboardsViewer/content/screens/DashboardForm.ui.qml +++ /dev/null @@ -1,47 +0,0 @@ - - -/* -This is a UI file (.ui.qml) that is intended to be edited in Qt Design Studio only. -It is supposed to be strictly declarative and only uses a subset of QML. If you edit -this file manually, you might introduce QML code that is not supported by Qt Design Studio. -Check out https://doc.qt.io/qtcreator/creator-quick-ui-forms.html for details on .ui.qml files. -*/ -import QtQuick 2.15 -import QtQuick.Controls 2.15 -import DashboardsViewer - -Item { - width: 1024 - height: 768 - anchors.fill: parent - - property alias closeButton: closeButton - property alias mainView: dashboardStackView - property alias dashboardStackView: dashboardStackView - - Text { - id: dashboardText - anchors.horizontalCenter: parent.horizontalCenter - anchors.top: parent.top - text: qsTr("DASHBOARD") - font.pixelSize: 60 - height: 60 - horizontalAlignment: Text.AlignHCenter - } - - Button { - id: closeButton - anchors.left: loadButton.right - anchors.top: parent.top - width: 150 - height: 60 - text: qsTr("Close") - } - - StackView { - id: dashboardStackView - anchors.top: dashboardText.bottom - anchors.bottom: parent.bottom - width: parent.width - } -} diff --git a/Frontend/DashboardsViewer/content/screens/DashboardSelector.qml b/Frontend/DashboardsViewer/content/screens/DashboardSelector.qml index 10253cd..45561b2 100644 --- a/Frontend/DashboardsViewer/content/screens/DashboardSelector.qml +++ b/Frontend/DashboardsViewer/content/screens/DashboardSelector.qml @@ -1,84 +1,41 @@ import QtQuick 2.15 -import OpenTeraLibs.UserClient -import "../dataSources" - -DashboardSelectorForm { - id:selectorForm - - cmbSites.onCurrentIndexChanged: function() { - - console.log("cmbSites.onCurrentIndexChanged", cmbSites.currentIndex); - var index = cmbSites.currentIndex; - - if (index >= 0) { - //Get element at index - var selectedSite = sitesDataSource.model.get(index); - - console.log(selectedSite); - if (selectedSite && selectedSite.id_site) - { - projectsDataSource.setSiteID(selectedSite.id_site); - sitesDashboardDataSource.setSiteID(selectedSite.id_site); - } - } - else - { - siteGridView.model.clear(); - } - } - - cmbProjects.onCurrentIndexChanged: function() { - console.log("cmbProjects.onCurrentIndexChanged", cmbProjects.currentIndex); - var index = cmbProjects.currentIndex; - - if (index >=0) { - // Get Selected project - var selectedProject = projectsDataSource.model.get(index); - console.log(selectedProject); - if (selectedProject && selectedProject.id_project) - { - projectsDashboardDataSource.setProjectID(selectedProject.id_project); - } - } - else - { - projectGridView.model.clear(); - } - } - - onItemClicked: function(id, definition){ - stackview.push("Dashboard.qml") +import QtQuick.Controls 2.15 +import QtQuick.Layouts +import QtQuick.Effects - // Get the current pushed element (the Dashboard) - var currentElement = stackview.currentItem; - - // Set the Actual definition - currentElement.definition = definition; - currentElement.loadDocument(); - } +import "../ui" +import "../delegates" +import "../dataSources" +import DashboardsViewer 1.0 +import OpenTeraLibs.UserClient +Item { + id: rootItem BaseDataSource { id: sitesDataSource url: "/api/user/sites" - params: {"list": true} + params: { + "list": true + } autoFetch: true // Look for change in the model - model.onCountChanged: function() { + model.onCountChanged: function () { console.log("Sites model updated.") - cmbSites.model.clear(); + cmbSites.model.clear() for (var i = 0; i < model.count; ++i) { - var site = model.get(i); - cmbSites.model.append({"text": site.site_name}); + var site = model.get(i) + cmbSites.model.append({ + "text": site.site_name + }) } // Select first element in combo ? - if (model.count > 0) - { - cmbSites.currentIndex = 0; + if (model.count > 0) { + cmbSites.currentIndex = 0 } } } // sitesDataSource @@ -87,28 +44,31 @@ DashboardSelectorForm { id: projectsDataSource url: "/api/user/projects" property int id_site: -1 - params: {"id_site": id_site} + params: { + "id_site": id_site + } autoFetch: false function setSiteID(id) { - projectsDataSource.id_site = id; + projectsDataSource.id_site = id //Get all information - getAll(); + getAll() } - model.onCountChanged: function() { - cmbProjects.model.clear(); + model.onCountChanged: function () { + cmbProjects.model.clear() for (var i = 0; i < model.count; ++i) { - var project = model.get(i); - cmbProjects.model.append({"text": project.project_name}); + var project = model.get(i) + cmbProjects.model.append({ + "text": project.project_name + }) } // Select first element in combo? - if(model.count > 0) { - cmbProjects.currentIndex = 0; + if (model.count > 0) { + cmbProjects.currentIndex = 0 } - } } // projectsDataSource @@ -116,73 +76,252 @@ DashboardSelectorForm { id: sitesDashboardDataSource url: "/dashboards/api/user/dashboards" property int id_site: -1 - params: {"id_site": id_site} + params: { + "id_site": id_site + } autoFetch: false function setSiteID(id) { - sitesDashboardDataSource.id_site = id; + sitesDashboardDataSource.id_site = id //Get all information - getAll(); + getAll() } - model.onCountChanged: function() { + model.onCountChanged: function () { - selectorForm.siteGridView.model.clear(); + siteGridView.model.clear() for (var i = 0; i < model.count; ++i) { - var dashboard = model.get(i); - console.log(dashboard); - - var description = dashboard.dashboard_description; - var enabled = dashboard.dashboard_enabled; - var name = dashboard.dashboard_name; - var definition = dashboard.versions.dashboard_definition; - - console.log(description, enabled, name, definition); - - - selectorForm.siteGridView.model.append({"id": dashboard.id_dashboard, - "name": name, - "definition": definition, - "color": "Blue"}) + var dashboard = model.get(i) + console.log(dashboard) + + var description = dashboard.dashboard_description + var enabled = dashboard.dashboard_enabled + var name = dashboard.dashboard_name + var definition = dashboard.versions.dashboard_definition + + console.log(description, enabled, name, definition) + + siteGridView.model.append({ + "id": dashboard.id_dashboard, + "name": name, + "definition": definition, + "color": "Blue" + }) } } } // projectsDashboardDataSource - BaseDataSource { id: projectsDashboardDataSource url: "/dashboards/api/user/dashboards" property int id_project: -1 - params: {"id_project": id_project} + params: { + "id_project": id_project + } autoFetch: false function setProjectID(id) { - projectsDashboardDataSource.id_project = id; + projectsDashboardDataSource.id_project = id //Get all information - getAll(); + getAll() } - model.onCountChanged: function() { - - selectorForm.projectGridView.model.clear(); + model.onCountChanged: function () { + projectGridView.model.clear() for (var i = 0; i < model.count; ++i) { - var dashboard = model.get(i); - console.log(dashboard); - - var description = dashboard.dashboard_description; - var enabled = dashboard.dashboard_enabled; - var name = dashboard.dashboard_name; - var definition = dashboard.versions.dashboard_definition; - - selectorForm.projectGridView.model.append({"id": dashboard.id_dashboard, - "name": name, - "definition": definition, - "color": "Red"}) - + var dashboard = model.get(i) + console.log(dashboard) + + var description = dashboard.dashboard_description + var enabled = dashboard.dashboard_enabled + var name = dashboard.dashboard_name + var definition = dashboard.versions.dashboard_definition + + projectGridView.model.append({ + "id": dashboard.id_dashboard, + "name": name, + "definition": definition, + "color": "Red" + }) } } } // projectsDashboardDataSource -} + anchors.centerIn: parent + width: parent? 0.8 * parent.width : 400 + height: parent ? 0.9 * parent.height : 200 + + BasicDialog { + id: dlgMain + title: qsTr("Select dashboard to display") + anchors.fill: parent + ColumnLayout { + id: layoutMain + anchors.fill: parent + anchors.margins: 10 + + Rectangle { + Layout.fillWidth: true + + implicitHeight: rowFilters.implicitHeight + lblFilters.implicitHeight + + rowFilters.anchors.margins * 2 + + radius: 10 + Layout.alignment: Qt.AlignLeft | Qt.AlignTop + color: "#77000000" + + Text { + id: lblFilters + anchors.left: parent.left + anchors.top: parent.top + anchors.leftMargin: 10 + text: qsTr("Filters") + color: "lightyellow" + font.pixelSize: Constants.smallFontSize + font.italic: true + } + + RowLayout { + id: rowFilters + anchors.top: lblFilters.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: 5 + implicitHeight: 200 + + Text { + text: qsTr("Site") + Layout.leftMargin: 20 + color: Constants.textColor + font.pixelSize: Constants.smallFontSize + font.bold: true + style: Text.Outline + } + + ComboBox { + id: cmbSites + Layout.fillWidth: true + Layout.fillHeight: true + model: ListModel {} + onCurrentIndexChanged: function () { + + var index = cmbSites.currentIndex + + if (index >= 0) { + //Get element at index + var selectedSite = sitesDataSource.model.get( + index) + + if (selectedSite && selectedSite.id_site) { + projectsDataSource.setSiteID( + selectedSite.id_site) + sitesDashboardDataSource.setSiteID( + selectedSite.id_site) + } + } else { + siteGridView.model.clear() + } + } + } + Text { + text: qsTr("Project") + color: Constants.textColor + font.pixelSize: Constants.smallFontSize + style: Text.Outline + font.bold: true + } + + ComboBox { + id: cmbProjects + Layout.fillWidth: true + Layout.fillHeight: true + model: ListModel {} + onCurrentIndexChanged: function () { + var index = cmbProjects.currentIndex + + if (index >= 0) { + // Get Selected project + var selectedProject = projectsDataSource.model.get( + index) + if (selectedProject + && selectedProject.id_project) { + projectsDashboardDataSource.setProjectID( + selectedProject.id_project) + } + } else { + projectGridView.model.clear() + } + } + } + } //RowLayout + } // First Rect + Rectangle { + id: siteProjectGrids + color: "#77000000" + Layout.fillWidth: true + Layout.fillHeight: true + radius: 10 + Layout.alignment: Qt.AlignLeft | Qt.AlignTop + + RowLayout { + //Fill the rest + id: siteProjectRowLayout + anchors.fill: parent + + GridView { + id: siteGridView + Layout.fillWidth: true + Layout.fillHeight: true + cellWidth: 100 + cellHeight: 100 + clip: true + ScrollBar.vertical: FlickableScrollBar {} + model: ListModel {} + delegate: SiteProjectDelegate { + id: siteProjectDelegateSite + + onItemClicked: function (id, definition) { + stackview.push("Dashboard.qml") + + // Get the current pushed element (the Dashboard) + var currentElement = stackview.currentItem + + // Set the Actual definition + currentElement.definition = definition + currentElement.loadDocument() + } + } + } // GridView 1 + + GridView { + id: projectGridView + Layout.fillWidth: true + Layout.fillHeight: true + model: ListModel {} + cellWidth: 100 + cellHeight: 100 + clip: true + + ScrollBar.vertical: FlickableScrollBar {} + delegate: SiteProjectDelegate { + id: siteProjectDelegateProject + + onItemClicked: function (id, definition) { + stackview.push("Dashboard.qml") + + // Get the current pushed element (the Dashboard) + var currentElement = stackview.currentItem + + // Set the Actual definition + currentElement.definition = definition + currentElement.loadDocument() + } + } + } // GridView 2 + } //RowLayout (2) + } // Rectangle 2 + } // ColumnLayout + } // BasicDialog +} // Item diff --git a/Frontend/DashboardsViewer/content/screens/DashboardSelectorForm.ui.qml b/Frontend/DashboardsViewer/content/screens/DashboardSelectorForm.ui.qml deleted file mode 100644 index fc1c81c..0000000 --- a/Frontend/DashboardsViewer/content/screens/DashboardSelectorForm.ui.qml +++ /dev/null @@ -1,152 +0,0 @@ -import QtQuick 2.15 -import QtQuick.Controls 2.15 -import QtQuick.Layouts -import QtQuick.Effects - -import "../ui" -import "../delegates" -import DashboardsViewer 1.0 - -Item { - id: rootItem - property alias cmbSites: cmbSites - property alias cmbProjects: cmbProjects - property alias siteGridView: siteGridView - property alias projectGridView: projectGridView - - signal itemClicked(var id, var definition) - - - Item { - anchors.centerIn: parent - width: 0.8 * parent.width - height: 0.9 * parent.height - - BasicDialog { - id: dlgMain - title: qsTr("Select dashboard to display") - anchors.fill: parent - ColumnLayout { - id: layoutMain - anchors.fill: parent - anchors.margins: 10 - - Rectangle { - Layout.fillWidth: true - - implicitHeight: rowFilters.implicitHeight + lblFilters.implicitHeight - + rowFilters.anchors.margins * 2 - - radius: 10 - Layout.alignment: Qt.AlignLeft | Qt.AlignTop - color: "#77000000" - - Text { - id: lblFilters - anchors.left: parent.left - anchors.top: parent.top - anchors.leftMargin: 10 - text: qsTr("Filters") - color: "lightyellow" - font.pixelSize: Constants.smallFontSize - font.italic: true - } - - RowLayout { - id: rowFilters - anchors.top: lblFilters.bottom - anchors.left: parent.left - anchors.right: parent.right - anchors.margins: 5 - implicitHeight: 200 - - Text { - text: qsTr("Site") - Layout.leftMargin: 20 - color: Constants.textColor - font.pixelSize: Constants.smallFontSize - font.bold: true - style: Text.Outline - } - - ComboBox { - id: cmbSites - Layout.fillWidth: true - Layout.fillHeight: true - model: ListModel {} - } - Text { - text: qsTr("Project") - color: Constants.textColor - font.pixelSize: Constants.smallFontSize - style: Text.Outline - font.bold: true - } - - ComboBox { - id: cmbProjects - Layout.fillWidth: true - Layout.fillHeight: true - model: ListModel {} - } - } //RowLayout - } // First Rect - Rectangle { - id: siteProjectGrids - color: "#77000000" - Layout.fillWidth: true - Layout.fillHeight: true - radius: 10 - Layout.alignment: Qt.AlignLeft | Qt.AlignTop - - RowLayout { - //Fill the rest - id: siteProjectRowLayout - anchors.fill: parent - - GridView { - id: siteGridView - Layout.fillWidth: true - Layout.fillHeight: true - cellWidth: 100 - cellHeight: 100 - clip: true - ScrollBar.vertical: FlickableScrollBar {} - model: ListModel {} - delegate: SiteProjectDelegate { - id: siteProjectDelegateSite - - Connections { - target: siteProjectDelegateSite - onItemClicked: function (id, definition){rootItem.itemClicked(id, definition);} - } - - } - } // GridView 1 - - GridView { - id: projectGridView - Layout.fillWidth: true - Layout.fillHeight: true - model: ListModel {} - cellWidth: 100 - cellHeight: 100 - clip: true - - ScrollBar.vertical: FlickableScrollBar {} - delegate: SiteProjectDelegate { - id: siteProjectDelegateProject - - Connections { - target: siteProjectDelegateProject - onItemClicked: function (id, definition){rootItem.itemClicked(id, definition);} - } - - } - } // GridView 2 - } //RowLayout (2) - } // Rectangle 2 - } // ColumnLayout - } // BasicDialog - } // Item -} // Item