From 9c2e1a25e4120504295f2ed974657a98f3a4548d Mon Sep 17 00:00:00 2001 From: Simon Briere Date: Thu, 28 Mar 2024 14:26:55 -0400 Subject: [PATCH] Refs #2. Work in progress on Timeline widget --- .../DashboardsViewer.qmlproject.qtds | 2 +- .../DashboardsViewer.qmlproject.qtds.1df10fa | 116 ------------------ .../DashboardsViewer/content/CMakeLists.txt | 3 +- .../content/dataSources/BaseDataSource.qml | 3 + .../ParticipantSessionListDataSource.qml | 5 + .../content/widgets/BaseWidget.qml | 2 +- .../content/widgets/TimeLineWidget.qml | 73 +++++++++++ .../config_parser/src/ConfigParser.cpp | 2 +- .../resources/json/TestDashboardv2.json | 11 +- 9 files changed, 93 insertions(+), 124 deletions(-) delete mode 100644 Frontend/DashboardsViewer/DashboardsViewer.qmlproject.qtds.1df10fa create mode 100644 Frontend/DashboardsViewer/content/widgets/TimeLineWidget.qml diff --git a/Frontend/DashboardsViewer/DashboardsViewer.qmlproject.qtds b/Frontend/DashboardsViewer/DashboardsViewer.qmlproject.qtds index 3b688df..94d235b 100644 --- a/Frontend/DashboardsViewer/DashboardsViewer.qmlproject.qtds +++ b/Frontend/DashboardsViewer/DashboardsViewer.qmlproject.qtds @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/Frontend/DashboardsViewer/DashboardsViewer.qmlproject.qtds.1df10fa b/Frontend/DashboardsViewer/DashboardsViewer.qmlproject.qtds.1df10fa deleted file mode 100644 index faa04a8..0000000 --- a/Frontend/DashboardsViewer/DashboardsViewer.qmlproject.qtds.1df10fa +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - EnvironmentId - {1df10fae-5b43-49d7-b010-da6a54749797} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - 0 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - true - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop Qt 6.6.0 - Desktop Qt 6.6.0 - {63f87550-2541-4163-9631-08b7fea781da} - -1 - 0 - 0 - 0 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - - 0 - - false - QML Runtime - QmlProjectManager.QmlRunConfiguration.Qml - - false - en - CurrentFile - true - true - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/Frontend/DashboardsViewer/content/CMakeLists.txt b/Frontend/DashboardsViewer/content/CMakeLists.txt index 299d37b..c73efcd 100644 --- a/Frontend/DashboardsViewer/content/CMakeLists.txt +++ b/Frontend/DashboardsViewer/content/CMakeLists.txt @@ -16,10 +16,11 @@ qt6_add_qml_module(content ui/FlickableScrollBar.qml # Widgets widgets/BaseWidget.qml - widgets/ClockWidget.qml widgets/ButtonWidget.qml + widgets/ClockWidget.qml widgets/ListViewWidget.qml widgets/SessionViewerWidget.qml + widgets/TimeLineWidget.qml # Layouts layouts/BaseLayout.qml diff --git a/Frontend/DashboardsViewer/content/dataSources/BaseDataSource.qml b/Frontend/DashboardsViewer/content/dataSources/BaseDataSource.qml index e9461e9..c2223a2 100644 --- a/Frontend/DashboardsViewer/content/dataSources/BaseDataSource.qml +++ b/Frontend/DashboardsViewer/content/dataSources/BaseDataSource.qml @@ -28,6 +28,7 @@ Item { //Make sure model is empty myModel.clear(); + modelChanged(); //Print number of elements //console.log("Number of elements: ", response.length); @@ -82,12 +83,14 @@ Item { response.dataSource = baseDataSource; myModel.append(response); } + modelChanged(); }); reply.requestFailed.connect(function(response, statusCode) { error(response); console.log("Failed", response, statusCode); }); + } function update() { diff --git a/Frontend/DashboardsViewer/content/dataSources/ParticipantSessionListDataSource.qml b/Frontend/DashboardsViewer/content/dataSources/ParticipantSessionListDataSource.qml index f6d2ea0..6c1f0d0 100644 --- a/Frontend/DashboardsViewer/content/dataSources/ParticipantSessionListDataSource.qml +++ b/Frontend/DashboardsViewer/content/dataSources/ParticipantSessionListDataSource.qml @@ -5,6 +5,7 @@ import OpenTeraLibs.UserClient 1.0 BaseDataSource { id: fetch property int id_participant: 0 // Empty Project + property bool withSessionTypes: false params: {"id_participant": id_participant} url: "/api/user/sessions" @@ -14,6 +15,10 @@ BaseDataSource { function setParticipant(id_participant) { fetch.id_participant = id_participant; + params = {"id_participant": id_participant}; + if (withSessionTypes){ + params["with_session_type"] = true; + } getAll(); } diff --git a/Frontend/DashboardsViewer/content/widgets/BaseWidget.qml b/Frontend/DashboardsViewer/content/widgets/BaseWidget.qml index bb99b9b..5f52dc9 100644 --- a/Frontend/DashboardsViewer/content/widgets/BaseWidget.qml +++ b/Frontend/DashboardsViewer/content/widgets/BaseWidget.qml @@ -10,6 +10,6 @@ Item { property Item stackView: dashboardStackView ? dashboardStackView : null Component.onCompleted: { - console.log("Using StackView: ", stackView) + // console.log("Using StackView: ", stackView) } } diff --git a/Frontend/DashboardsViewer/content/widgets/TimeLineWidget.qml b/Frontend/DashboardsViewer/content/widgets/TimeLineWidget.qml new file mode 100644 index 0000000..caee9ab --- /dev/null +++ b/Frontend/DashboardsViewer/content/widgets/TimeLineWidget.qml @@ -0,0 +1,73 @@ +import QtQuick 2.15 +import QtQuick.Controls 2.15 +import DashboardsViewer 1.0 +import "../dataSources" + + +BaseWidget { + + property ParticipantSessionListDataSource dataSource: null + + visible: dataSource !== null && dataSource.model && dataSource.model.count > 0 + + property real totalDuration: 0 + property real startTimestamp: 0 + + Connections{ + ignoreUnknownSignals: true + target: dataSource + onModelChanged: function() { + repeaterSessions.model = []; + if (dataSource.model.count < 1){ + startTimestamp = 0; + totalDuration = 0; + return; + } + let end_timestamp = Math.ceil((Date.parse(dataSource.model.get(0).session_start_datetime) + dataSource.model.get(0).session_duration * 1000) / 1000); + startTimestamp = Math.ceil((Date.parse(dataSource.model.get(dataSource.model.count-1).session_start_datetime)) / 1000); + totalDuration = end_timestamp - startTimestamp; + //console.log(dataSource.model.get(0).id_session + " * " +dataSource.model.get(dataSource.model.count-1).id_session + " / start: " + startTimestamp + ", total: " + totalDuration); + //console.log(dataSource.model.get(0).session_start_datetime + " - " + dataSource.model.get(dataSource.model.count-1).session_start_datetime + " : " + totalDuration); + + // Force and set session repeater, as we want to have variables set beforehand + repeaterSessions.model = dataSource.model; + } + } + + function updateTimeline(){ + + } + + Rectangle{ + anchors.fill: parent + color: "black" + + Rectangle{ + id: recBase + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: 20 + anchors.rightMargin: 20 + anchors.verticalCenter: parent.verticalCenter + height: 2* parent.height / 3 + color: "darkred" + radius: 2 + + Repeater{ + id: repeaterSessions + model: [] + + Rectangle{ + property real relativeStartTimestamp: Math.ceil(Date.parse(model.session_start_datetime) / 1000) - startTimestamp + color: model.session_type_color ? model.session_type_color : "cyan" + border.color: "black" + border.width: 1 + height: recBase.height + x: Math.ceil((relativeStartTimestamp / totalDuration) * recBase.width) + width: Math.max(5, (model.session_duration*1000 / totalDuration) * recBase.width) + opacity: model.session_status === 2 ? 1.0 : (model.session_status === 1 ? 0.75 : 0.5) + } + } + } + } +} diff --git a/Frontend/DashboardsViewer/qml_cpp_modules/config_parser/src/ConfigParser.cpp b/Frontend/DashboardsViewer/qml_cpp_modules/config_parser/src/ConfigParser.cpp index 5f00c70..c0fe48e 100644 --- a/Frontend/DashboardsViewer/qml_cpp_modules/config_parser/src/ConfigParser.cpp +++ b/Frontend/DashboardsViewer/qml_cpp_modules/config_parser/src/ConfigParser.cpp @@ -25,7 +25,7 @@ ConfigParser::~ConfigParser() bool ConfigParser::isValidString(const QString &input) { - QRegularExpression regex("^[a-zA-Z0-9. |]+$"); + QRegularExpression regex("^[a-zA-Z0-9. //|]+$"); return regex.match(input).hasMatch(); } diff --git a/Frontend/DashboardsViewer/resources/json/TestDashboardv2.json b/Frontend/DashboardsViewer/resources/json/TestDashboardv2.json index 0ca81b1..046e087 100644 --- a/Frontend/DashboardsViewer/resources/json/TestDashboardv2.json +++ b/Frontend/DashboardsViewer/resources/json/TestDashboardv2.json @@ -17,11 +17,12 @@ "properties": { "dataSource": {"type": "raw", "value": "participantListData"}, "delegate": {"type": "delegate", "value": "ParticipantDelegate"}, - "Layout.fillWidth": {"type": "bool", "value": "true"}, + "Layout.maximumWidth": {"type": "raw", "value": "Screen.width/5"}, "Layout.fillHeight": {"type": "bool", "value": "true"} } } ], + "layouts":[ { "type": "CenteredColumnLayout", @@ -31,11 +32,12 @@ }, "widgets": [ { - "type": "Rectangle", + "type": "TimeLineWidget", "id": "wdgTimeline", "properties": { + "dataSource": {"type": "raw", "value": "participantSessionListData"}, "Layout.fillWidth": {"type": "bool", "value": "true"}, - "height": {"type": "int", "value": 100} + "implicitHeight": {"type": "int", "value": 100} } } ], @@ -80,7 +82,8 @@ "type": "ParticipantSessionListDataSource", "id": "participantSessionListData", "properties": { - "id_participant": {"type": "int", "value": -1} + "id_participant": {"type": "int", "value": -1}, + "withSessionTypes": {"type": "bool", "value": "true"} } } ],