2022-06-09 15:27:14 +00:00
|
|
|
import QtQuick 2.14
|
|
|
|
|
2023-06-23 06:17:04 +00:00
|
|
|
import AppLayouts.Communities.controls 1.0
|
|
|
|
import AppLayouts.Communities.layouts 1.0
|
2022-11-25 17:35:30 +00:00
|
|
|
import AppLayouts.Chat.stores 1.0
|
2023-06-23 06:17:04 +00:00
|
|
|
import AppLayouts.Communities.views 1.0
|
2022-06-09 15:27:14 +00:00
|
|
|
|
2023-02-14 20:39:18 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
2023-02-17 11:53:18 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
SettingsPageLayout {
|
|
|
|
id: root
|
|
|
|
|
2023-03-07 08:47:04 +00:00
|
|
|
required property var permissionsModel
|
|
|
|
required property var assetsModel
|
|
|
|
required property var collectiblesModel
|
|
|
|
required property var channelsModel
|
|
|
|
|
2023-06-21 14:20:39 +00:00
|
|
|
// id, name, image, color, owner properties expected
|
2023-03-07 08:47:04 +00:00
|
|
|
required property var communityDetails
|
|
|
|
|
2022-11-25 17:35:30 +00:00
|
|
|
property int viewWidth: 560 // by design
|
|
|
|
|
2023-03-07 08:47:04 +00:00
|
|
|
signal createPermissionRequested(
|
|
|
|
int permissionType, var holdings, var channels, bool isPrivate)
|
|
|
|
|
|
|
|
signal updatePermissionRequested(
|
|
|
|
string key, int permissionType, var holdings, var channels, bool isPrivate)
|
|
|
|
|
|
|
|
signal removePermissionRequested(string key)
|
|
|
|
|
2023-03-24 12:41:46 +00:00
|
|
|
signal navigateToMintTokenSettings
|
|
|
|
|
2022-12-07 16:14:36 +00:00
|
|
|
function navigateBack() {
|
2022-09-13 16:17:54 +00:00
|
|
|
if (root.state === d.newPermissionViewState) {
|
2023-02-10 22:40:07 +00:00
|
|
|
root.state = d.initialState
|
2023-02-20 08:31:39 +00:00
|
|
|
} else if (root.state === d.permissionsViewState) {
|
2022-11-24 16:23:54 +00:00
|
|
|
root.state = d.newPermissionViewState
|
2023-02-20 08:31:39 +00:00
|
|
|
} else if (root.state === d.editPermissionViewState) {
|
2022-11-24 16:23:54 +00:00
|
|
|
if (root.dirty) {
|
|
|
|
root.notifyDirty()
|
|
|
|
} else {
|
2023-02-10 22:40:07 +00:00
|
|
|
root.state = d.initialState
|
2022-11-24 16:23:54 +00:00
|
|
|
}
|
2022-12-07 16:14:36 +00:00
|
|
|
}
|
2022-09-13 16:17:54 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
readonly property string welcomeViewState: "WELCOME"
|
2022-11-24 16:23:54 +00:00
|
|
|
readonly property string newPermissionViewState: "NEW_PERMISSION"
|
2022-11-25 17:35:30 +00:00
|
|
|
readonly property string permissionsViewState: "PERMISSIONS"
|
2022-11-24 16:23:54 +00:00
|
|
|
readonly property string editPermissionViewState: "EDIT_PERMISSION"
|
2023-03-07 15:50:23 +00:00
|
|
|
readonly property bool permissionsExist: root.permissionsModel.count > 0
|
2023-02-08 10:13:16 +00:00
|
|
|
|
|
|
|
signal saveChanges
|
|
|
|
signal resetChanges
|
2022-11-24 16:23:54 +00:00
|
|
|
|
2023-02-20 08:31:39 +00:00
|
|
|
property string permissionKeyToEdit
|
|
|
|
|
2023-02-28 15:23:09 +00:00
|
|
|
property var holdingsToEditModel
|
2023-02-11 19:03:57 +00:00
|
|
|
property int permissionTypeToEdit: PermissionTypes.Type.None
|
2023-02-28 15:23:09 +00:00
|
|
|
property var channelsToEditModel
|
2022-11-24 16:23:54 +00:00
|
|
|
property bool isPrivateToEditValue: false
|
|
|
|
|
|
|
|
onPermissionsExistChanged: {
|
|
|
|
// Navigate back to welcome permissions view if all existing permissions are removed.
|
|
|
|
if(root.state === d.permissionsViewState && !permissionsExist) {
|
2023-02-20 08:31:39 +00:00
|
|
|
root.state = d.welcomeViewState;
|
2022-11-24 16:23:54 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-07 16:14:36 +00:00
|
|
|
|
2023-02-28 15:00:10 +00:00
|
|
|
readonly property string initialState: d.permissionsExist ? d.permissionsViewState : d.welcomeViewState
|
2022-11-24 16:23:54 +00:00
|
|
|
|
|
|
|
function initializeData() {
|
2023-02-14 20:39:18 +00:00
|
|
|
holdingsToEditModel = emptyModel
|
|
|
|
channelsToEditModel = emptyModel
|
2023-02-11 19:03:57 +00:00
|
|
|
permissionTypeToEdit = PermissionTypes.Type.None
|
2022-11-24 16:23:54 +00:00
|
|
|
isPrivateToEditValue = false
|
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 16:23:54 +00:00
|
|
|
saveChangesButtonEnabled: true
|
2023-01-11 13:57:50 +00:00
|
|
|
saveChangesText: qsTr("Update permission")
|
|
|
|
cancelChangesText: qsTr("Revert changes")
|
2023-02-10 22:40:07 +00:00
|
|
|
state: d.initialState
|
2022-06-09 15:27:14 +00:00
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: d.welcomeViewState
|
|
|
|
PropertyChanges {target: root; title: qsTr("Permissions")}
|
2022-09-13 16:17:54 +00:00
|
|
|
PropertyChanges {target: root; previousPageName: ""}
|
2022-06-09 15:27:14 +00:00
|
|
|
PropertyChanges {target: root; content: welcomeView}
|
2023-05-30 15:18:45 +00:00
|
|
|
PropertyChanges {target: root; primaryHeaderButton.visible: true}
|
|
|
|
PropertyChanges {target: root; primaryHeaderButton.text: qsTr("Add new permission")}
|
2022-06-09 15:27:14 +00:00
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: d.newPermissionViewState
|
|
|
|
PropertyChanges {target: root; title: qsTr("New permission")}
|
2022-09-13 16:17:54 +00:00
|
|
|
PropertyChanges {target: root; previousPageName: qsTr("Permissions")}
|
2022-06-09 15:27:14 +00:00
|
|
|
PropertyChanges {target: root; content: newPermissionView}
|
2023-05-30 15:18:45 +00:00
|
|
|
PropertyChanges {target: root; primaryHeaderButton.visible: false}
|
2022-11-25 17:35:30 +00:00
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: d.permissionsViewState
|
|
|
|
PropertyChanges {target: root; title: qsTr("Permissions")}
|
|
|
|
PropertyChanges {target: root; previousPageName: ""}
|
|
|
|
PropertyChanges {target: root; content: permissionsView}
|
2023-05-30 15:18:45 +00:00
|
|
|
PropertyChanges {target: root; primaryHeaderButton.visible: true}
|
|
|
|
PropertyChanges {target: root; primaryHeaderButton.text: qsTr("Add new permission")}
|
2022-11-24 16:23:54 +00:00
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: d.editPermissionViewState
|
|
|
|
PropertyChanges {target: root; title: qsTr("Edit permission")}
|
|
|
|
PropertyChanges {target: root; previousPageName: qsTr("Permissions")}
|
|
|
|
PropertyChanges {target: root; content: newPermissionView}
|
2023-05-30 15:18:45 +00:00
|
|
|
PropertyChanges {target: root; primaryHeaderButton.visible: false}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2023-05-30 15:18:45 +00:00
|
|
|
onPrimaryHeaderButtonClicked: {
|
2022-11-24 16:23:54 +00:00
|
|
|
if(root.state === d.welcomeViewState || root.state === d.permissionsViewState) {
|
|
|
|
d.initializeData()
|
2022-11-25 17:35:30 +00:00
|
|
|
root.state = d.newPermissionViewState
|
2022-11-24 16:23:54 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-25 17:35:30 +00:00
|
|
|
|
2022-11-24 16:23:54 +00:00
|
|
|
onSaveChangesClicked: {
|
2023-02-08 10:13:16 +00:00
|
|
|
d.saveChanges()
|
|
|
|
d.resetChanges()
|
|
|
|
|
2022-11-24 16:23:54 +00:00
|
|
|
root.navigateBack()
|
|
|
|
}
|
|
|
|
|
|
|
|
onResetChangesClicked: {
|
2023-02-08 10:13:16 +00:00
|
|
|
d.resetChanges()
|
|
|
|
|
2022-11-24 16:23:54 +00:00
|
|
|
root.navigateBack()
|
2022-11-25 17:35:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
// Community Permissions possible view contents:
|
|
|
|
Component {
|
|
|
|
id: welcomeView
|
2023-02-17 11:53:18 +00:00
|
|
|
|
2023-06-26 11:48:45 +00:00
|
|
|
WelcomeSettingsView {
|
2022-11-25 17:35:30 +00:00
|
|
|
viewWidth: root.viewWidth
|
2023-02-20 09:00:40 +00:00
|
|
|
image: Style.png("community/permissions2_3")
|
2023-02-17 11:53:18 +00:00
|
|
|
title: qsTr("Permissions")
|
|
|
|
subtitle: qsTr("You can manage your community by creating and issuing membership and access permissions")
|
|
|
|
checkersModel: [
|
|
|
|
qsTr("Give individual members access to private channels"),
|
|
|
|
qsTr("Monetise your community with subscriptions and fees"),
|
|
|
|
qsTr("Require holding a token or NFT to obtain exclusive membership rights")
|
|
|
|
]
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: newPermissionView
|
2023-02-17 11:53:18 +00:00
|
|
|
|
2023-06-26 11:48:45 +00:00
|
|
|
EditPermissionView {
|
|
|
|
id: editPermissionView
|
2023-02-14 20:39:18 +00:00
|
|
|
|
2022-11-25 17:35:30 +00:00
|
|
|
viewWidth: root.viewWidth
|
2023-02-08 23:22:57 +00:00
|
|
|
|
2023-03-07 08:47:04 +00:00
|
|
|
assetsModel: root.assetsModel
|
|
|
|
collectiblesModel: root.collectiblesModel
|
|
|
|
channelsModel: root.channelsModel
|
|
|
|
communityDetails: root.communityDetails
|
2023-02-08 23:22:57 +00:00
|
|
|
|
2022-11-24 16:23:54 +00:00
|
|
|
isEditState: root.state === d.editPermissionViewState
|
2023-02-11 19:03:57 +00:00
|
|
|
|
2023-03-07 08:47:04 +00:00
|
|
|
selectedHoldingsModel: d.holdingsToEditModel
|
|
|
|
selectedChannelsModel: d.channelsToEditModel
|
2023-02-11 19:03:57 +00:00
|
|
|
|
|
|
|
permissionType: d.permissionTypeToEdit
|
2022-11-24 16:23:54 +00:00
|
|
|
isPrivate: d.isPrivateToEditValue
|
2023-04-04 14:10:37 +00:00
|
|
|
holdingsRequired: selectedHoldingsModel ? selectedHoldingsModel.count > 0
|
|
|
|
: false
|
|
|
|
|
2023-03-02 15:58:26 +00:00
|
|
|
permissionDuplicated: {
|
2023-02-14 23:53:01 +00:00
|
|
|
// dependencies
|
|
|
|
holdingsTracker.revision
|
|
|
|
channelsTracker.revision
|
2023-06-26 11:48:45 +00:00
|
|
|
editPermissionView.dirtyValues.permissionType
|
|
|
|
editPermissionView.dirtyValues.isPrivate
|
2023-03-07 08:47:04 +00:00
|
|
|
const model = root.permissionsModel
|
2023-02-17 13:36:58 +00:00
|
|
|
const count = model.rowCount()
|
2023-02-14 23:53:01 +00:00
|
|
|
|
2023-02-17 13:36:58 +00:00
|
|
|
for (let i = 0; i < count; i++) {
|
2023-02-20 08:31:39 +00:00
|
|
|
const item = ModelUtils.get(model, i)
|
|
|
|
|
2023-02-14 23:53:01 +00:00
|
|
|
if (root.state === d.editPermissionViewState
|
2023-02-20 08:31:39 +00:00
|
|
|
&& d.permissionKeyToEdit === item.key)
|
2023-02-14 23:53:01 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
const holdings = item.holdingsListModel
|
|
|
|
const channels = item.channelsListModel
|
|
|
|
const permissionType = item.permissionType
|
|
|
|
|
|
|
|
const same = (a, b) => ModelUtils.checkEqualitySet(a, b, ["key"])
|
|
|
|
|
2023-04-05 11:15:57 +00:00
|
|
|
if (holdings.rowCount() === 0)
|
|
|
|
if (dirtyValues.holdingsRequired)
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
return true
|
2023-04-04 14:10:37 +00:00
|
|
|
|
|
|
|
if (holdings.rowCount() !== 0 && !dirtyValues.holdingsRequired)
|
|
|
|
continue
|
|
|
|
|
2023-03-07 08:47:04 +00:00
|
|
|
if (same(dirtyValues.selectedHoldingsModel, holdings)
|
|
|
|
&& same(dirtyValues.selectedChannelsModel, channels)
|
2023-02-14 23:53:01 +00:00
|
|
|
&& dirtyValues.permissionType === permissionType)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-03-02 15:58:26 +00:00
|
|
|
permissionTypeLimitReached: {
|
|
|
|
const type = dirtyValues.permissionType
|
|
|
|
const limit = PermissionTypes.getPermissionsCountLimit(type)
|
|
|
|
|
|
|
|
if (limit === -1)
|
|
|
|
return false
|
|
|
|
|
|
|
|
const model = root.permissionsModel
|
|
|
|
const count = model.rowCount()
|
|
|
|
let sameTypeCount = 0
|
|
|
|
|
|
|
|
for (let i = 0; i < count; i++)
|
|
|
|
if (type === ModelUtils.get(model, i, "permissionType"))
|
|
|
|
sameTypeCount++
|
|
|
|
|
|
|
|
return limit <= sameTypeCount
|
|
|
|
}
|
|
|
|
|
2023-02-08 23:22:57 +00:00
|
|
|
onCreatePermissionClicked: {
|
2023-04-04 14:10:37 +00:00
|
|
|
const holdings = dirtyValues.holdingsRequired ?
|
|
|
|
ModelUtils.modelToArray(
|
|
|
|
dirtyValues.selectedHoldingsModel,
|
|
|
|
["key", "type", "amount"])
|
|
|
|
: []
|
2023-02-22 12:26:02 +00:00
|
|
|
|
|
|
|
const channels = ModelUtils.modelToArray(
|
2023-03-07 08:47:04 +00:00
|
|
|
dirtyValues.selectedChannelsModel, ["key"])
|
2023-02-22 12:26:02 +00:00
|
|
|
|
2023-03-07 08:47:04 +00:00
|
|
|
root.createPermissionRequested(
|
|
|
|
dirtyValues.permissionType, holdings, channels,
|
|
|
|
dirtyValues.isPrivate)
|
2023-02-08 23:22:57 +00:00
|
|
|
|
|
|
|
root.state = d.permissionsViewState
|
|
|
|
}
|
|
|
|
|
2023-03-24 12:41:46 +00:00
|
|
|
onNavigateToMintTokenSettings: root.navigateToMintTokenSettings()
|
|
|
|
|
2023-02-08 10:13:16 +00:00
|
|
|
Connections {
|
|
|
|
target: d
|
|
|
|
|
|
|
|
function onSaveChanges() {
|
2023-04-05 11:15:57 +00:00
|
|
|
const holdings = dirtyValues.holdingsRequired ?
|
|
|
|
ModelUtils.modelToArray(
|
|
|
|
dirtyValues.selectedHoldingsModel,
|
|
|
|
["key", "type", "amount"])
|
|
|
|
: []
|
2023-02-22 12:26:02 +00:00
|
|
|
|
|
|
|
const channels = ModelUtils.modelToArray(
|
2023-03-07 08:47:04 +00:00
|
|
|
dirtyValues.selectedChannelsModel, ["key"])
|
|
|
|
|
|
|
|
root.updatePermissionRequested(
|
|
|
|
d.permissionKeyToEdit, dirtyValues.permissionType,
|
|
|
|
holdings, channels, dirtyValues.isPrivate)
|
2023-02-08 10:13:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onResetChanges() {
|
2023-02-08 23:22:57 +00:00
|
|
|
resetChanges()
|
2023-02-08 10:13:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-08 23:22:57 +00:00
|
|
|
Binding {
|
|
|
|
target: root
|
|
|
|
property: "dirty"
|
|
|
|
value: isEditState && dirty
|
2023-02-08 10:13:16 +00:00
|
|
|
}
|
2023-02-14 20:39:18 +00:00
|
|
|
|
|
|
|
ModelChangeTracker {
|
|
|
|
id: holdingsTracker
|
|
|
|
|
2023-06-26 11:48:45 +00:00
|
|
|
model: editPermissionView.dirtyValues.selectedHoldingsModel
|
2023-02-14 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ModelChangeTracker {
|
|
|
|
id: channelsTracker
|
|
|
|
|
2023-06-26 11:48:45 +00:00
|
|
|
model: editPermissionView.dirtyValues.selectedChannelsModel
|
2023-02-14 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Binding {
|
|
|
|
target: root
|
|
|
|
property: "saveChangesButtonEnabled"
|
2023-06-26 11:48:45 +00:00
|
|
|
value: !editPermissionView.permissionDuplicated
|
|
|
|
&& !editPermissionView.permissionTypeLimitReached
|
|
|
|
&& editPermissionView.isFullyFilled
|
2023-02-14 20:39:18 +00:00
|
|
|
}
|
2022-11-25 17:35:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: permissionsView
|
2023-02-10 22:40:07 +00:00
|
|
|
|
2023-06-26 11:48:45 +00:00
|
|
|
PermissionsView {
|
2023-03-07 08:47:04 +00:00
|
|
|
permissionsModel: root.permissionsModel
|
|
|
|
assetsModel: root.assetsModel
|
|
|
|
collectiblesModel: root.collectiblesModel
|
|
|
|
channelsModel: root.channelsModel
|
|
|
|
communityDetails: root.communityDetails
|
|
|
|
|
2022-11-25 17:35:30 +00:00
|
|
|
viewWidth: root.viewWidth
|
2023-02-10 22:40:07 +00:00
|
|
|
|
2023-02-14 20:39:18 +00:00
|
|
|
function setInitialValuesFromIndex(index) {
|
2023-03-07 08:47:04 +00:00
|
|
|
const item = ModelUtils.get(root.permissionsModel, index)
|
2023-02-10 22:40:07 +00:00
|
|
|
|
|
|
|
d.holdingsToEditModel = item.holdingsListModel
|
|
|
|
d.channelsToEditModel = item.channelsListModel
|
2023-02-11 19:03:57 +00:00
|
|
|
d.permissionTypeToEdit = item.permissionType
|
2023-02-10 22:40:07 +00:00
|
|
|
d.isPrivateToEditValue = item.isPrivate
|
2023-02-14 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onEditPermissionRequested: {
|
|
|
|
setInitialValuesFromIndex(index)
|
2023-02-20 08:31:39 +00:00
|
|
|
d.permissionKeyToEdit = ModelUtils.get(
|
2023-03-07 08:47:04 +00:00
|
|
|
root.permissionsModel, index, "key")
|
2022-11-24 16:23:54 +00:00
|
|
|
root.state = d.editPermissionViewState
|
|
|
|
}
|
2023-02-10 22:40:07 +00:00
|
|
|
|
|
|
|
onDuplicatePermissionRequested: {
|
2023-02-14 20:39:18 +00:00
|
|
|
setInitialValuesFromIndex(index)
|
|
|
|
root.state = d.newPermissionViewState
|
2023-02-10 22:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onRemovePermissionRequested: {
|
2023-03-07 08:47:04 +00:00
|
|
|
const key = ModelUtils.get(root.permissionsModel, index, "key")
|
|
|
|
root.removePermissionRequested(key)
|
2023-02-10 22:40:07 +00:00
|
|
|
}
|
2022-11-25 17:35:30 +00:00
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
2022-11-24 16:23:54 +00:00
|
|
|
|
2023-02-14 20:39:18 +00:00
|
|
|
ListModel {
|
|
|
|
id: emptyModel
|
2022-11-24 16:23:54 +00:00
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|