chore(CommunityNewPermissionView): refactor to improve separation of concerns, create/save actions moved up
This commit is contained in:
parent
3a3d1657f0
commit
fb19385438
|
@ -113,20 +113,10 @@ SplitView {
|
|||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
Button {
|
||||
text: "Reset changes"
|
||||
|
||||
Button {
|
||||
text: "Save changes"
|
||||
|
||||
onClicked: communityNewPermissionView.saveChanges()
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Reset changes"
|
||||
|
||||
onClicked: communityNewPermissionView.resetChanges()
|
||||
}
|
||||
onClicked: communityNewPermissionView.resetChanges()
|
||||
}
|
||||
|
||||
Label {
|
||||
|
|
|
@ -146,33 +146,47 @@ SettingsPageLayout {
|
|||
id: newPermissionView
|
||||
|
||||
CommunityNewPermissionView {
|
||||
id: newPermissionViewItem
|
||||
|
||||
viewWidth: root.viewWidth
|
||||
|
||||
rootStore: root.rootStore
|
||||
store: root.store
|
||||
onPermissionCreated: root.state = d.permissionsViewState
|
||||
|
||||
isEditState: root.state === d.editPermissionViewState
|
||||
permissionIndex: d.permissionIndexToEdit
|
||||
holdingsModel: d.holdingsToEditModel
|
||||
permissionObject: d.permissionsToEditObject
|
||||
channelsModel: d.channelsToEditModel
|
||||
isPrivate: d.isPrivateToEditValue
|
||||
|
||||
onCreatePermissionClicked: {
|
||||
root.store.createPermission(dirtyValues.holdingsModel,
|
||||
dirtyValues.permissionObject,
|
||||
dirtyValues.isPrivate,
|
||||
dirtyValues.channelsModel)
|
||||
|
||||
root.state = d.permissionsViewState
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: d
|
||||
|
||||
function onSaveChanges() {
|
||||
newPermissionViewItem.saveChanges()
|
||||
root.store.editPermission(
|
||||
d.permissionIndexToEdit,
|
||||
dirtyValues.holdingsModel,
|
||||
dirtyValues.permissionObject,
|
||||
dirtyValues.channelsModel,
|
||||
dirtyValues.isPrivate)
|
||||
}
|
||||
|
||||
function onResetChanges() {
|
||||
newPermissionViewItem.resetChanges()
|
||||
resetChanges()
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
root.dirty = Qt.binding(() => newPermissionViewItem.isEditState && newPermissionViewItem.dirty)
|
||||
Binding {
|
||||
target: root
|
||||
property: "dirty"
|
||||
value: isEditState && dirty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ QtObject {
|
|||
permission.permissionsObjectModel.text = permissions.text
|
||||
permission.permissionsObjectModel.imageSource = permissions.imageSource
|
||||
|
||||
// Setting CHANNELS
|
||||
// Setting CHANNELS:
|
||||
for (let c = 0; c < channels.count; c++) {
|
||||
const entry = channels.get(c)
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@ StatusScrollView {
|
|||
property bool isEditState: false
|
||||
readonly property bool dirty: {
|
||||
|
||||
const trick = d.triggerDirtyTool // Trick: Used to force the reevaluation of dirty when an item of the list is updated
|
||||
// Trick: Used to force the reevaluation of dirty when an item of the list is updated
|
||||
const trick = d.triggerDirtyTool
|
||||
|
||||
// Holdings:
|
||||
if (d.checkIfHoldingsDirty())
|
||||
|
@ -55,16 +56,6 @@ StatusScrollView {
|
|||
return dirtyPermissionObj
|
||||
}
|
||||
|
||||
function saveChanges() {
|
||||
d.saveChanges()
|
||||
}
|
||||
|
||||
function resetChanges() {
|
||||
d.loadInitValues()
|
||||
}
|
||||
|
||||
property int permissionIndex
|
||||
|
||||
// roles: type, key, name, amount, imageSource
|
||||
property var holdingsModel: ListModel {}
|
||||
|
||||
|
@ -76,7 +67,13 @@ StatusScrollView {
|
|||
|
||||
property bool isPrivate: false
|
||||
|
||||
signal permissionCreated()
|
||||
readonly property alias dirtyValues: d.dirtyValues
|
||||
|
||||
signal createPermissionClicked
|
||||
|
||||
function resetChanges() {
|
||||
d.loadInitValues()
|
||||
}
|
||||
|
||||
QtObject {
|
||||
id: d
|
||||
|
@ -113,11 +110,11 @@ StatusScrollView {
|
|||
// Trick: Used to force the reevaluation of dirty when an item of the list is updated
|
||||
property int triggerDirtyTool: 0
|
||||
|
||||
property QtObject dirtyValues: QtObject {
|
||||
property ListModel holdingsModel: ListModel {}
|
||||
property ListModel channelsModel: ListModel {}
|
||||
readonly property QtObject dirtyValues: QtObject {
|
||||
readonly property ListModel holdingsModel: ListModel {}
|
||||
readonly property ListModel channelsModel: ListModel {}
|
||||
|
||||
property QtObject permissionObject: QtObject {
|
||||
readonly property QtObject permissionObject: QtObject {
|
||||
property var key: null
|
||||
property string text: ""
|
||||
property string imageSource: ""
|
||||
|
@ -166,16 +163,6 @@ StatusScrollView {
|
|||
|
||||
return names
|
||||
}
|
||||
|
||||
// TODO: Channels
|
||||
}
|
||||
|
||||
function saveChanges() {
|
||||
root.store.editPermission(root.permissionIndex,
|
||||
d.dirtyValues.holdingsModel,
|
||||
d.dirtyValues.permissionObject,
|
||||
d.dirtyValues.channelsModel,
|
||||
d.dirtyValues.isPrivate)
|
||||
}
|
||||
|
||||
function loadInitValues() {
|
||||
|
@ -693,13 +680,8 @@ StatusScrollView {
|
|||
Layout.preferredHeight: 44
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
Layout.fillWidth: true
|
||||
onClicked: {
|
||||
root.store.createPermission(d.dirtyValues.holdingsModel,
|
||||
d.dirtyValues.permissionObject,
|
||||
d.dirtyValues.isPrivate,
|
||||
d.dirtyValues.channelsModel)
|
||||
root.permissionCreated()
|
||||
}
|
||||
|
||||
onClicked: root.createPermissionClicked()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue