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