fix remove device policy question handling

This commit is contained in:
Michael Zanetti 2018-06-28 13:58:49 +02:00
parent b041db8c81
commit fe80fc3531
4 changed files with 101 additions and 62 deletions

View File

@ -212,5 +212,6 @@
<file>ui/mainviews/DevicesPageDelegate.qml</file>
<file>ui/components/AutoSizeMenu.qml</file>
<file>ui/components/EmptyViewPlaceholder.qml</file>
<file>ui/components/RemoveDeviceMethodDialog.qml</file>
</qresource>
</RCC>

View File

@ -17,6 +17,34 @@ Page {
}
}
QtObject {
id: d
property var deviceToRemove: null
}
Connections {
target: Engine.deviceManager
onRemoveDeviceReply: {
if (!d.deviceToRemove) {
return;
}
switch (params.deviceError) {
case "DeviceErrorNoError":
d.deviceToRemove = null;
return;
case "DeviceErrorDeviceInRule":
var removeMethodComponent = Qt.createComponent(Qt.resolvedUrl("components/RemoveDeviceMethodDialog.qml"))
var popup = removeMethodComponent.createObject(root, {device: d.deviceToRemove, rulesList: params["ruleIds"]});
popup.open();
return;
default:
var popup = errorDialog.createObject(root, {errorCode: params.deviceError})
popup.open();
}
}
}
ListView {
anchors.fill: parent
model: Engine.deviceManager.devices
@ -28,7 +56,8 @@ Page {
pageStack.push(Qt.resolvedUrl("devicepages/ConfigureThingPage.qml"), {device: Engine.deviceManager.devices.get(index)})
}
onDeleteClicked: {
Engine.deviceManager.removeDevice(Engine.deviceManager.devices.get(index).id)
d.deviceToRemove = Engine.deviceManager.devices.get(index);
Engine.deviceManager.removeDevice(d.deviceToRemove.id)
}
}
}

View File

@ -0,0 +1,68 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Nymea 1.0
Dialog {
id: root
width: Math.min(parent.width * .8, contentLabel.implicitWidth + app.margins * 2)
x: (parent.width - width) / 2
y: (parent.height - height) / 2
modal: true
property var device: null
property var rulesList: null
ColumnLayout {
width: parent.width
Label {
id: contentLabel
text: qsTr("This thing is currently used in one or more rules:")
Layout.fillWidth: true
wrapMode: Text.WordWrap
}
ThinDivider {}
ListView {
Layout.fillWidth: true
Layout.preferredHeight: app.iconSize * Math.min(count, 5)
model: rulesList
interactive: contentHeight > height
delegate: Label {
height: app.iconSize
width: parent.width
elide: Text.ElideRight
text: Engine.ruleManager.rules.getRule(modelData).name
verticalAlignment: Text.AlignVCenter
}
}
ThinDivider {}
Button {
text: qsTr("Remove all those rules")
Layout.fillWidth: true
onClicked: {
Engine.deviceManager.removeDevice(root.device.id, DeviceManager.RemovePolicyCascade)
root.close()
root.destroy();
}
}
Button {
text: qsTr("Update rules, removing this thing")
Layout.fillWidth: true
onClicked: {
Engine.deviceManager.removeDevice(root.device.id, DeviceManager.RemovePolicyUpdate)
root.close()
root.destroy();
}
}
Button {
text: qsTr("Don't remove this thing")
Layout.fillWidth: true
onClicked: {
root.close()
root.destroy();
}
}
}
}

View File

@ -47,7 +47,7 @@ Page {
pageStack.pop();
return;
case "DeviceErrorDeviceInRule":
var popup = removeMethodComponent.createObject(root, {rulesList: params["ruleIds"]});
var popup = removeMethodComponent.createObject(root, {device: root.device, rulesList: params["ruleIds"]});
popup.open();
return;
default:
@ -117,67 +117,8 @@ Page {
Component {
id: removeMethodComponent
Dialog {
id: removeMethodDialog
width: Math.min(parent.width * .8, contentLabel.implicitWidth + app.margins * 2)
x: (parent.width - width) / 2
y: (parent.height - height) / 2
modal: true
RemoveDeviceMethodDialog {
property var rulesList: null
ColumnLayout {
width: parent.width
Label {
id: contentLabel
text: qsTr("This thing is currently used in one or more rules:")
Layout.fillWidth: true
wrapMode: Text.WordWrap
}
ThinDivider {}
ListView {
Layout.fillWidth: true
Layout.preferredHeight: app.iconSize * Math.min(count, 5)
model: rulesList
interactive: contentHeight > height
delegate: Label {
height: app.iconSize
width: parent.width
elide: Text.ElideRight
text: Engine.ruleManager.rules.getRule(modelData).name
verticalAlignment: Text.AlignVCenter
}
}
ThinDivider {}
Button {
text: qsTr("Remove all those rules")
Layout.fillWidth: true
onClicked: {
Engine.deviceManager.removeDevice(root.device.id, DeviceManager.RemovePolicyCascade)
removeMethodDialog.close()
removeMethodDialog.destroy();
}
}
Button {
text: qsTr("Update rules, removing this thing")
Layout.fillWidth: true
onClicked: {
Engine.deviceManager.removeDevice(root.device.id, DeviceManager.RemovePolicyUpdate)
removeMethodDialog.close()
removeMethodDialog.destroy();
}
}
Button {
text: qsTr("Don't remove this thing")
Layout.fillWidth: true
onClicked: {
removeMethodDialog.close()
removeMethodDialog.destroy();
}
}
}
}
}
}