Add saving of pushrules action changes

This commit is contained in:
miruka
2020-11-01 00:55:29 -04:00
parent 2480603ee2
commit d5bcaca874
5 changed files with 135 additions and 20 deletions

View File

@@ -4,9 +4,39 @@ import QtQuick 2.12
import "../../Base"
HButton {
property bool on: true
property string toggles: ""
readonly property string key: JSON.stringify([model.kind, model.id])
readonly property bool on:
toggles && page.pendingEdits[key] && toggles in page.pendingEdits[key]?
page.pendingEdits[key][toggles] :
toggles ?
model[toggles] :
true
opacity: on ? 1 : theme.disabledElementsOpacity
hoverEnabled: true
backgroundColor: "transparent"
onClicked: {
if (! toggles) return
if (! (key in page.pendingEdits)) page.pendingEdits[key] = {}
if ((! on) === model[toggles])
delete page.pendingEdits[key][toggles]
else
page.pendingEdits[key][toggles] = ! on
if (! Object.keys(page.pendingEdits[key]).length)
delete page.pendingEdits[key]
page.pendingEditsChanged()
}
Behavior on opacity { HNumberAnimation {} }
}

View File

@@ -1,24 +1,20 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import "../.."
import "../../Base"
import "../../Base/Buttons"
import "../../Base/HTile"
import "../../MainPane"
import "../../PythonBridge"
import "../../ShortcutBundles"
HTile {
id: root
property string userId
property Item page
readonly property QtObject matchingRoom:
model.kind === "Room" ?
ModelStore.get(userId, "rooms").find(model.id) :
ModelStore.get(page.userId, "rooms").find(model.id) :
null
@@ -69,7 +65,7 @@ HTile {
model.id === ".m.rule.contains_user_name" ?
qsTr("Contains %1").arg(utils.coloredNameHtml(
"", userId, userId.split(":")[0].substring(1),
"", page.userId, page.userId.split(":")[0].substring(1),
)):
model.id === ".m.rule.call" ?
@@ -103,7 +99,7 @@ HTile {
HRowLayout {
NotificationRuleButton {
on: model.notify
toggles: "notify"
contentItem: MessageIndicator {
indicatorTheme:
@@ -117,7 +113,7 @@ HTile {
}
NotificationRuleButton {
on: model.highlight
toggles: "highlight"
contentItem: MessageIndicator {
indicatorTheme:
@@ -134,17 +130,17 @@ HTile {
NotificationRuleButton {
icon.name: "pushrule-action-bubble"
on: model.bubble
toggles: "bubble"
}
NotificationRuleButton {
icon.name: "pushrule-action-sound"
on: model.sound
toggles: "sound"
}
NotificationRuleButton {
icon.name: "pushrule-action-urgency-hint"
on: model.urgency_hint
toggles: "urgency_hint"
}
HSpacer {}

View File

@@ -6,7 +6,6 @@ import QtQuick.Layouts 1.12
import "../.."
import "../../Base"
import "../../Base/Buttons"
import "../../PythonBridge"
import "../../ShortcutBundles"
HListView {
@@ -17,14 +16,38 @@ HListView {
property bool enableFlickShortcuts:
SwipeView ? SwipeView.isCurrentItem : true
// The object's array keys are run through `JSON.stringify(key)`.
// {[kind, rule_id]: {notify, highlight, bubble, sound, urgency_hint}}
property var pendingEdits: ({})
property string saveFutureId: ""
function takeFocus() {
// deviceList.headerItem.exportButton.forceActiveFocus()
// deviceList.headerItem.exportButton.forceActiveFocus() TODO
}
function save() {
const args = []
for (const [kindRuleId, kwargs] of Object.entries(pendingEdits)) {
const [kind, rule_id] = JSON.parse(kindRuleId)
args.push(Object.assign({}, {kind, rule_id}, kwargs))
}
saveFutureId = py.callClientCoro(
userId,
"mass_tweak_pushrules",
args,
() => {
if (! root) return
saveFutureId = ""
pendingEdits = {}
}
)
}
clip: true
model: ModelStore.get(userId, "pushrules")
bottomMargin: theme.spacing
implicitHeight: Math.min(window.height, contentHeight + bottomMargin)
section.property: "kind"
@@ -42,10 +65,25 @@ HListView {
}
delegate: NotificationRuleDelegate {
userId: root.userId
page: root
width: root.width
}
footer: AutoDirectionLayout {
z: 100
width: root.width
enabled: Object.keys(root.pendingEdits).length !== 0
ApplyButton {
onClicked: root.save()
loading: root.saveFutureId !== ""
}
CancelButton {
onClicked: pendingEdits = {}
}
}
Layout.fillWidth: true
Layout.fillHeight: true