2022-08-23 08:46:37 +00:00
import QtQuick 2.0
QtObject {
2022-11-25 17:35:30 +00:00
id: root
property var permissionsModel: ListModel { } // Backend permissions list object model asignement. Please check the current expected data in qml defined in `createPermissions` method
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.
2022-11-25 17:35:30 +00:00
var permission = {
isPrivate: true ,
holdingsListModel: [ ] ,
permissionsObjectModel: {
key: "" ,
text: "" ,
imageSource: ""
} ,
channelsListModel: [ ]
} ;
// Setting HOLDINGS:
for ( var i = 0 ; i < holdings . count ; i ++ ) {
var entry = holdings . get ( i ) ;
2023-01-12 11:31:08 +00:00
// roles: type, key, name, amount, imageSource
2022-11-25 17:35:30 +00:00
permission . holdingsListModel . push ( {
type: entry . type ,
key: entry . key ,
name: entry . name ,
amount: entry . amount ,
imageSource: entry . imageSource
} ) ;
}
// Setting PERMISSIONS:
permission . permissionsObjectModel . key = permissions . key
permission . permissionsObjectModel . text = permissions . text
permission . permissionsObjectModel . imageSource = permissions . imageSource
// Setting PRIVATE permission property:
permission . isPrivate = isPrivate
// TODO: Set channels list. Now mocked data.
permission . channelsListModel = root . channelsModel
2022-11-24 16:23:54 +00:00
if ( index !== null ) {
// Edit permission model:
console . log ( "TODO: Edit permissions - backend call" )
root . permissionsModel . set ( index , permission )
}
else {
// 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 )
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
}
}