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 {
|
Button {
|
||||||
Layout.fillWidth: true
|
text: "Reset changes"
|
||||||
|
|
||||||
Button {
|
onClicked: communityNewPermissionView.resetChanges()
|
||||||
text: "Save changes"
|
|
||||||
|
|
||||||
onClicked: communityNewPermissionView.saveChanges()
|
|
||||||
}
|
|
||||||
|
|
||||||
Button {
|
|
||||||
text: "Reset changes"
|
|
||||||
|
|
||||||
onClicked: communityNewPermissionView.resetChanges()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
|
|
|
@ -146,33 +146,47 @@ SettingsPageLayout {
|
||||||
id: newPermissionView
|
id: newPermissionView
|
||||||
|
|
||||||
CommunityNewPermissionView {
|
CommunityNewPermissionView {
|
||||||
id: newPermissionViewItem
|
|
||||||
|
|
||||||
viewWidth: root.viewWidth
|
viewWidth: root.viewWidth
|
||||||
|
|
||||||
rootStore: root.rootStore
|
rootStore: root.rootStore
|
||||||
store: root.store
|
store: root.store
|
||||||
onPermissionCreated: root.state = d.permissionsViewState
|
|
||||||
isEditState: root.state === d.editPermissionViewState
|
isEditState: root.state === d.editPermissionViewState
|
||||||
permissionIndex: d.permissionIndexToEdit
|
|
||||||
holdingsModel: d.holdingsToEditModel
|
holdingsModel: d.holdingsToEditModel
|
||||||
permissionObject: d.permissionsToEditObject
|
permissionObject: d.permissionsToEditObject
|
||||||
channelsModel: d.channelsToEditModel
|
channelsModel: d.channelsToEditModel
|
||||||
isPrivate: d.isPrivateToEditValue
|
isPrivate: d.isPrivateToEditValue
|
||||||
|
|
||||||
|
onCreatePermissionClicked: {
|
||||||
|
root.store.createPermission(dirtyValues.holdingsModel,
|
||||||
|
dirtyValues.permissionObject,
|
||||||
|
dirtyValues.isPrivate,
|
||||||
|
dirtyValues.channelsModel)
|
||||||
|
|
||||||
|
root.state = d.permissionsViewState
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: d
|
target: d
|
||||||
|
|
||||||
function onSaveChanges() {
|
function onSaveChanges() {
|
||||||
newPermissionViewItem.saveChanges()
|
root.store.editPermission(
|
||||||
|
d.permissionIndexToEdit,
|
||||||
|
dirtyValues.holdingsModel,
|
||||||
|
dirtyValues.permissionObject,
|
||||||
|
dirtyValues.channelsModel,
|
||||||
|
dirtyValues.isPrivate)
|
||||||
}
|
}
|
||||||
|
|
||||||
function onResetChanges() {
|
function onResetChanges() {
|
||||||
newPermissionViewItem.resetChanges()
|
resetChanges()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Binding {
|
||||||
root.dirty = Qt.binding(() => newPermissionViewItem.isEditState && newPermissionViewItem.dirty)
|
target: root
|
||||||
|
property: "dirty"
|
||||||
|
value: isEditState && dirty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ QtObject {
|
||||||
permission.permissionsObjectModel.text = permissions.text
|
permission.permissionsObjectModel.text = permissions.text
|
||||||
permission.permissionsObjectModel.imageSource = permissions.imageSource
|
permission.permissionsObjectModel.imageSource = permissions.imageSource
|
||||||
|
|
||||||
// Setting CHANNELS
|
// Setting CHANNELS:
|
||||||
for (let c = 0; c < channels.count; c++) {
|
for (let c = 0; c < channels.count; c++) {
|
||||||
const entry = channels.get(c)
|
const entry = channels.get(c)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ StatusScrollView {
|
||||||
property bool isEditState: false
|
property bool isEditState: false
|
||||||
readonly property bool dirty: {
|
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:
|
// Holdings:
|
||||||
if (d.checkIfHoldingsDirty())
|
if (d.checkIfHoldingsDirty())
|
||||||
|
@ -55,16 +56,6 @@ StatusScrollView {
|
||||||
return dirtyPermissionObj
|
return dirtyPermissionObj
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveChanges() {
|
|
||||||
d.saveChanges()
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetChanges() {
|
|
||||||
d.loadInitValues()
|
|
||||||
}
|
|
||||||
|
|
||||||
property int permissionIndex
|
|
||||||
|
|
||||||
// roles: type, key, name, amount, imageSource
|
// roles: type, key, name, amount, imageSource
|
||||||
property var holdingsModel: ListModel {}
|
property var holdingsModel: ListModel {}
|
||||||
|
|
||||||
|
@ -76,7 +67,13 @@ StatusScrollView {
|
||||||
|
|
||||||
property bool isPrivate: false
|
property bool isPrivate: false
|
||||||
|
|
||||||
signal permissionCreated()
|
readonly property alias dirtyValues: d.dirtyValues
|
||||||
|
|
||||||
|
signal createPermissionClicked
|
||||||
|
|
||||||
|
function resetChanges() {
|
||||||
|
d.loadInitValues()
|
||||||
|
}
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
id: d
|
id: d
|
||||||
|
@ -113,11 +110,11 @@ StatusScrollView {
|
||||||
// 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
|
||||||
property int triggerDirtyTool: 0
|
property int triggerDirtyTool: 0
|
||||||
|
|
||||||
property QtObject dirtyValues: QtObject {
|
readonly property QtObject dirtyValues: QtObject {
|
||||||
property ListModel holdingsModel: ListModel {}
|
readonly property ListModel holdingsModel: ListModel {}
|
||||||
property ListModel channelsModel: ListModel {}
|
readonly property ListModel channelsModel: ListModel {}
|
||||||
|
|
||||||
property QtObject permissionObject: QtObject {
|
readonly property QtObject permissionObject: QtObject {
|
||||||
property var key: null
|
property var key: null
|
||||||
property string text: ""
|
property string text: ""
|
||||||
property string imageSource: ""
|
property string imageSource: ""
|
||||||
|
@ -166,16 +163,6 @@ StatusScrollView {
|
||||||
|
|
||||||
return names
|
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() {
|
function loadInitValues() {
|
||||||
|
@ -693,13 +680,8 @@ StatusScrollView {
|
||||||
Layout.preferredHeight: 44
|
Layout.preferredHeight: 44
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
onClicked: {
|
|
||||||
root.store.createPermission(d.dirtyValues.holdingsModel,
|
onClicked: root.createPermissionClicked()
|
||||||
d.dirtyValues.permissionObject,
|
|
||||||
d.dirtyValues.isPrivate,
|
|
||||||
d.dirtyValues.channelsModel)
|
|
||||||
root.permissionCreated()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue