2022-08-23 08:46:37 +00:00
import QtQuick 2.0
QtObject {
2022-11-25 17:35:30 +00:00
id: root
2023-01-20 11:04:12 +00:00
readonly property bool isOwner: false
2023-01-23 15:50:34 +00:00
property var permissionsModel: ListModel { } // Backend permissions list object model assignment. Please check the current expected data in qml defined in `createPermissions` method
property var permissionConflict: QtObject { // Backend conflicts object model assignment. Now mocked data.
property bool exists: false
property string holdings: qsTr ( "1 ETH" )
property string permissions: qsTr ( "View and Post" )
property string channels: qsTr ( "#general" )
}
2022-08-23 08:46:37 +00:00
// TODO: Replace to real data, now dummy model
2023-01-12 13:18:52 +00:00
property var assetsModel: ListModel {
ListElement { key: "socks" ; iconSource: "qrc:imports/assets/png/tokens/SOCKS.png" ; name: "Unisocks" ; shortName: "SOCKS" ; category: "Community assets" }
ListElement { key: "zrx" ; iconSource: "qrc:imports/assets/png/tokens/ZRX.png" ; name: "Ox" ; shortName: "ZRX" ; category: "Listed assets" }
ListElement { key: "1inch" ; iconSource: "qrc:imports/assets/png/tokens/CUSTOM-TOKEN.png" ; name: "1inch" ; shortName: "ZRX" ; category: "Listed assets" }
ListElement { key: "Aave" ; iconSource: "qrc:imports/assets/png/tokens/CUSTOM-TOKEN.png" ; name: "Aave" ; shortName: "AAVE" ; category: "Listed assets" }
ListElement { key: "Amp" ; iconSource: "qrc:imports/assets/png/tokens/CUSTOM-TOKEN.png" ; name: "Amp" ; shortName: "AMP" ; category: "Listed assets" }
2022-08-23 08:46:37 +00:00
}
// TODO: Replace to real data, now dummy model
property var collectiblesModel: ListModel {
ListElement {
key: "Anniversary"
iconSource: "qrc:imports/assets/png/collectibles/Anniversary.png"
name: "Anniversary"
category: "Community collectibles"
}
ListElement {
key: "CryptoKitties"
iconSource: "qrc:imports/assets/png/collectibles/CryptoKitties.png"
name: "CryptoKitties"
category: "Your collectibles"
subItems: [
ListElement {
key: "Kitty1"
iconSource: "qrc:imports/assets/png/collectibles/Furbeard.png"
imageSource: "qrc:imports/assets/png/collectibles/FurbeardBig.png"
name: "Furbeard"
} ,
ListElement {
key: "Kitty2"
iconSource: "qrc:imports/assets/png/collectibles/Magicat.png"
imageSource: "qrc:imports/assets/png/collectibles/MagicatBig.png"
name: "Magicat"
} ,
ListElement {
key: "Kitty3"
iconSource: "qrc:imports/assets/png/collectibles/HappyMeow.png"
imageSource: "qrc:imports/assets/png/collectibles/HappyMeowBig.png"
name: "Happy Meow"
} ,
ListElement {
key: "Kitty4"
iconSource: "qrc:imports/assets/png/collectibles/Furbeard.png"
imageSource: "qrc:imports/assets/png/collectibles/FurbeardBig.png"
name: "Furbeard-2"
} ,
ListElement {
key: "Kitty5"
iconSource: "qrc:imports/assets/png/collectibles/Magicat.png"
imageSource: "qrc:imports/assets/png/collectibles/MagicatBig.png"
name: "Magicat-3"
}
]
}
ListElement {
key: "SuperRare"
iconSource: "qrc:imports/assets/png/collectibles/SuperRare.png" ;
name: "SuperRare"
category: "Your collectibles"
}
ListElement {
key: "Custom"
iconSource: "qrc:imports/assets/png/collectibles/SNT.png"
name: "Custom Collectible"
category: "All collectibles"
}
}
2022-11-25 17:35:30 +00:00
// TODO: Replace to real data, now dummy model
property var channelsModel: ListModel {
2022-12-01 16:31:03 +00:00
ListElement { key: "welcome" ; iconSource: "qrc:imports/assets/png/tokens/CUSTOM-TOKEN.png" ; name: "#welcome" }
2022-11-25 17:35:30 +00:00
ListElement { key: "general" ; iconSource: "qrc:imports/assets/png/tokens/CUSTOM-TOKEN.png" ; name: "#general" }
}
2022-11-24 16:23:54 +00:00
function createPermission ( holdings , permissions , isPrivate , channels , index = null ) {
// TO BE REPLACED: It shold just be a call to the backend sharing `holdings`, `permissions`, `channels` and `isPrivate` properties.
2023-01-27 09:22:04 +00:00
const permission = {
2022-11-25 17:35:30 +00:00
isPrivate: true ,
holdingsListModel: [ ] ,
permissionsObjectModel: {
key: "" ,
text: "" ,
imageSource: ""
} ,
2023-01-27 09:22:04 +00:00
channelsListModel: [ ] ,
}
2022-11-25 17:35:30 +00:00
// Setting HOLDINGS:
2023-01-27 09:22:04 +00:00
for ( let i = 0 ; i < holdings . count ; i ++ ) {
const entry = holdings . get ( i )
2022-11-25 17:35:30 +00:00
permission . holdingsListModel . push ( {
2023-01-27 09:22:04 +00:00
type: entry . type ,
key: entry . key ,
name: entry . name ,
amount: entry . amount ,
imageSource: entry . imageSource
} )
2022-11-25 17:35:30 +00:00
}
// Setting PERMISSIONS:
permission . permissionsObjectModel . key = permissions . key
permission . permissionsObjectModel . text = permissions . text
permission . permissionsObjectModel . imageSource = permissions . imageSource
2023-01-27 09:22:04 +00:00
// Setting CHANNELS
for ( let c = 0 ; c < channels . count ; c ++ ) {
const entry = channels . get ( c )
permission . channelsListModel . push ( {
itemId: entry . itemId ,
text: entry . text ,
emoji: entry . emoji ,
color: entry . color
} )
}
2022-11-25 17:35:30 +00:00
// Setting PRIVATE permission property:
permission . isPrivate = isPrivate
2023-01-27 09:22:04 +00:00
if ( index !== null ) {
2022-11-24 16:23:54 +00:00
// Edit permission model:
console . log ( "TODO: Edit permissions - backend call" )
root . permissionsModel . set ( index , permission )
2023-01-27 09:22:04 +00:00
} else {
2022-11-24 16:23:54 +00:00
// Add into permission model:
console . log ( "TODO: Create permissions - backend call - Now dummy data shown" )
root . permissionsModel . append ( permission )
}
2022-11-25 17:35:30 +00:00
}
2022-11-24 16:23:54 +00:00
function editPermission ( index , holdings , permissions , channels , isPrivate ) {
// TO BE REPLACED: Call to backend
createPermission ( holdings , permissions , isPrivate , channels , index )
2022-11-25 17:35:30 +00:00
}
function duplicatePermission ( index ) {
2022-11-24 16:23:54 +00:00
// TO BE REPLACED: Call to backend
2022-11-25 17:35:30 +00:00
console . log ( "TODO: Duplicate permissions - backend call" )
2022-11-24 16:23:54 +00:00
const permission = root . permissionsModel . get ( index )
2023-01-27 09:22:04 +00:00
createPermission ( permission . holdingsListModel , permission . permissionsObjectModel ,
permission . isPrivate , permission . channelsListModel )
2022-11-25 17:35:30 +00:00
}
function removePermission ( index ) {
console . log ( "TODO: Remove permissions - backend call" )
2022-11-24 16:23:54 +00:00
root . permissionsModel . remove ( index )
2022-08-23 08:46:37 +00:00
}
}