Skip to content

Commit

Permalink
Refs #2, Simplify data sources, make id external to properties
Browse files Browse the repository at this point in the history
  • Loading branch information
doumdi committed Mar 7, 2024
1 parent 3db16c7 commit 171e3c8
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 143 deletions.
1 change: 1 addition & 0 deletions Frontend/DashboardsViewer/content/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ qt6_add_qml_module(content
# Delegates
delegates/ParticipantDelegate.qml
delegates/SessionDelegate.qml
delegates/GenericItemDelegate.qml

RESOURCES
fonts/Arimo-VariableFont_wght.ttf
Expand Down
45 changes: 45 additions & 0 deletions Frontend/DashboardsViewer/content/dataSources/BaseDataSource.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
import QtQuick 2.15
import OpenTeraLibs.UserClient 1.0

Item {
id: baseDataSource
property string url: "" // Empty URL
property ListModel model: ListModel {
id: myModel
}
property var params: Object()
property string fieldIdName: "id_"
property string fieldDisplayName: "disp_"
property string iconPath: "qrc:/genericIcon"
property bool autoFetch: false

signal error(var errorMessage);

function getAll() {
var reply = UserClient.get(url, params);

reply.requestSucceeded.connect(function(response, statusCode) {
console.log("Success", response, statusCode);

//Make sure model is empty
myModel.clear();

//Add session
response.forEach(function(item) {
myModel.append(item)
});
});

reply.requestFailed.connect(function(response, statusCode) {
error(response);
console.log("Failed", response, statusCode);
});
}

function update() {
getAll();
}

Component.onCompleted: function() {
//Get data from user client
if (baseDataSource.autoFetch)
{
getAll();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,66 +1,16 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts
import OpenTeraLibs.UserClient 1.0
import "../delegates"

Item {

property string url: "" // Empty URL
property int id_project: 0 // Empty Project
property ListModel model: ListModel {
id: myModel
}

BaseDataSource {
id: fetch
signal dataReady(var data);
signal error(string message);
signal participantClicked(int id_participant);

function getAll() {
var params = {"id_project": id_project};
var reply = UserClient.get(url, params);

reply.requestSucceeded.connect(function(response, statusCode) {
console.log("Success", response, statusCode);

//Make sure model is empty
myModel.clear();

//Add participants to model
//TODO filter fields
response.forEach(function(item) {

var filteredItem = {};

//Filter fields
filteredItem.participant_name = item.participant_name;
filteredItem.id_participant = item.id_participant;
filteredItem.participant_uuid = item.participant_uuid;
filteredItem.participant_enabled = item.participant_enabled;
filteredItem.id_project = item.id_project;

myModel.append(filteredItem);
});

});

reply.requestFailed.connect(function(response, statusCode) {
error(response);
console.log("Failed", response, statusCode);
});

}

function update() {
getAll();
}

Component.onCompleted: function() {
//Get data from user client
getAll();
}
property int id_project: 0 // Empty Project

params: {"id_project": id_project}
url: "/api/user/participants"
fieldIdName: "id_participant"
fieldDisplayName: "participant_name"
iconPath: "qrc:/genericIcon"
}


Original file line number Diff line number Diff line change
@@ -1,58 +1,15 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts
import OpenTeraLibs.UserClient 1.0
import "../delegates"

Item {

property string url: "/api/user/sessions" // Empty URL
property int id_participant: 0 // Empty Participant
property Component delegate: SessionDelegate {
id: myDelegate
}

property ListModel model: ListModel {
id: myModel
}

BaseDataSource {
id: fetch
signal dataReady(var data);
signal error(string message);


function setParticipant(id) {
id_participant = id;
update();
}


function getAll() {
var params = {"id_participant": id_participant};
var reply = UserClient.get(url, params);

reply.requestSucceeded.connect(function(response, statusCode) {
console.log("Success", response, statusCode);

//Make sure model is empty
myModel.clear();

//Add session
response.forEach(function(item) {
myModel.append(item)
});
});

reply.requestFailed.connect(function(response, statusCode) {
error(response);
console.log("Failed", response, statusCode);
});

}

function update() {
getAll();
}
property int id_participant: 0 // Empty Project

params: {"id_participant": id_participant}
url: "/api/user/sessions"
fieldIdName: "id_session"
fieldDisplayName: "session_name"
iconPath: "qrc:/genericIcon"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts

Item {
property string fieldIdName: "id_"
property string fieldDisplayName: "disp_"
property string iconPath: "qrc:/genericIcon"

id: myDelegate

signal itemClicked(int id);

Rectangle {
id: myRectangle
width: 500
height: 80
color: "#cccccc"
border.color: "black"
border.width: 1
radius: 5

ColumnLayout {
id: columnLayout
anchors.fill: parent


// Customize delegate appearance as needed
Text {
height: 20
text: "Name: " + model[fieldDisplayName]
color: "red"
}
/*
Text {
height: 20
text: "Enabled: " + participant_enabled
color: "green"
}
Text {
height: 20
text: "UUID: " + participant_uuid
color: "blue"
}
*/
}
Component.onCompleted: function() {
console.log("GenericItemDelegate");
}


MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
itemClicked(model[fieldIdName]);
}
}
}
}
11 changes: 11 additions & 0 deletions Frontend/DashboardsViewer/content/widgets/ListViewWidget.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ BaseWidget {
anchors.fill: parent
model: myModel
delegate: myDelegate

onModelChanged: function()
{
console.log("ListViewWidget.onModelChanged");
delegate.fieldIdName = model.fieldIdName
delegate.fieldDisplayName = model.fieldDisplayName;
delegate.iconPath = model.iconPath;
}
}




ListModel {
id: myModel
ListElement { name: "Apple" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void ConfigParser::writeLayout(const QJsonObject &layout, QTextStream &stream)

// Start layout
stream << type << " {\n";
stream << " " << "id: " << layout["id"].toString() << "\n";

//Verify if we have properties
if (layout.contains("properties"))
Expand Down Expand Up @@ -175,6 +176,7 @@ void ConfigParser::writeWidget(const QJsonObject &widget, QTextStream &stream)

// Start widget
stream << type << " {\n";
stream << " " << "id: " << widget["id"].toString() << "\n";

// Get Properties
QJsonObject properties = widget["properties"].toObject();
Expand Down Expand Up @@ -306,6 +308,7 @@ void ConfigParser::writeDataSources(const QJsonArray &dataSources, QTextStream &
// Extract data-source information
QJsonObject source = dataSources[i].toObject();
stream << source["type"].toString() <<" {\n";
stream << " " << "id: " << source["id"].toString() << "\n";
QJsonObject properties = source["properties"].toObject();
writeProperties(properties, stream);
stream << "}\n";
Expand Down
Loading

0 comments on commit 171e3c8

Please sign in to comment.