Добавил сервисную страницу, небольшой рефакторинг
This commit is contained in:
12
HomeForm.qml
12
HomeForm.qml
@@ -4,18 +4,6 @@ import QtQuick.Controls 2.0
|
||||
Page {
|
||||
title: qsTr("nooLight")
|
||||
|
||||
function showError(text) {
|
||||
ToolTip.show(text, 1000)
|
||||
}
|
||||
|
||||
LightsModel {
|
||||
id: lightsModel
|
||||
|
||||
serviceUrl: settings.serviceUrl
|
||||
|
||||
onError: showError(text)
|
||||
}
|
||||
|
||||
ListView {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 5
|
||||
|
||||
@@ -20,6 +20,8 @@ ListModel {
|
||||
property alias serviceUrl: nooLiteClient.serviceUrl
|
||||
property bool isLoading: false
|
||||
|
||||
property int channelsCount: 0
|
||||
|
||||
signal error(string text)
|
||||
|
||||
onServiceUrlChanged: reload()
|
||||
@@ -30,12 +32,25 @@ ListModel {
|
||||
}
|
||||
|
||||
function populateModel(data) {
|
||||
root.clear()
|
||||
root.channelsCount = 0
|
||||
|
||||
data.groups.forEach(function (group) {
|
||||
root.append(group)
|
||||
|
||||
root.channelsCount += group.channels.length
|
||||
})
|
||||
}
|
||||
|
||||
function switchChannel(channelId) {
|
||||
root.client.switchChannel(channelId)
|
||||
root.client.sendCommand("switch", channelId)
|
||||
}
|
||||
|
||||
function bindChannel(channelId) {
|
||||
root.client.sendCommand("bind", channelId)
|
||||
}
|
||||
|
||||
function unbindChannel(channelId) {
|
||||
root.client.sendCommand("unbind", channelId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ QtObject {
|
||||
_get(root.serviceUrl + '/static/channels.js', root.modelLoad)
|
||||
}
|
||||
|
||||
function switchChannel(channelId) {
|
||||
_get(root.serviceUrl + '/noolite/switch/%1'.arg(channelId), function (data) {
|
||||
function sendCommand(command, channelId) {
|
||||
_get(root.serviceUrl + '/noolite/%1/%2'.arg(command).arg(channelId), function (data) {
|
||||
if (data.error) {
|
||||
root.error(qsTr("Server error: %1").arg(data.error))
|
||||
return
|
||||
|
||||
40
ServiceForm.qml
Normal file
40
ServiceForm.qml
Normal file
@@ -0,0 +1,40 @@
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 2.2
|
||||
|
||||
Page {
|
||||
id: root
|
||||
|
||||
title: qsTr("Service")
|
||||
|
||||
ListView {
|
||||
model: lightsModel.channelsCount
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
delegate: Row {
|
||||
spacing: 4
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
Button {
|
||||
width: 160
|
||||
|
||||
text: qsTr("Bind channel %1").arg(index)
|
||||
|
||||
onClicked: {
|
||||
lightsModel.bindChannel(index)
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
width: 160
|
||||
|
||||
text: qsTr("Unbind channel %1").arg(index)
|
||||
|
||||
onClicked: {
|
||||
lightsModel.unbindChannel(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
main.qml
36
main.qml
@@ -16,6 +16,14 @@ ApplicationWindow {
|
||||
property string serviceUrl: ""
|
||||
}
|
||||
|
||||
LightsModel {
|
||||
id: lightsModel
|
||||
|
||||
serviceUrl: settings.serviceUrl
|
||||
|
||||
onError: stackView.showError(text)
|
||||
}
|
||||
|
||||
header: ToolBar {
|
||||
contentHeight: 36
|
||||
|
||||
@@ -72,16 +80,19 @@ ApplicationWindow {
|
||||
}
|
||||
}
|
||||
|
||||
ItemDelegate {
|
||||
text: qsTr("Service")
|
||||
width: parent.width
|
||||
onClicked: {
|
||||
stackView.openPage("ServiceForm.qml")
|
||||
}
|
||||
}
|
||||
|
||||
ItemDelegate {
|
||||
text: qsTr("Settings")
|
||||
width: parent.width
|
||||
onClicked: {
|
||||
if (stackView.depth > 1) {
|
||||
stackView.pop()
|
||||
}
|
||||
|
||||
stackView.push("SettingsForm.qml")
|
||||
drawer.close()
|
||||
stackView.openPage("SettingsForm.qml")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,6 +102,19 @@ ApplicationWindow {
|
||||
id: stackView
|
||||
initialItem: "HomeForm.qml"
|
||||
anchors.fill: parent
|
||||
|
||||
function openPage(page) {
|
||||
if (depth > 1) {
|
||||
pop()
|
||||
}
|
||||
|
||||
push(page)
|
||||
drawer.close()
|
||||
}
|
||||
|
||||
function showError(text) {
|
||||
ToolTip.show(text, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
onClosing: {
|
||||
|
||||
Reference in New Issue
Block a user