2024-02-16 12:08:45 +00:00
|
|
|
import QtQml 2.15
|
|
|
|
|
|
|
|
import StatusQ 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
2024-02-16 12:08:45 +00:00
|
|
|
QObject {
|
|
|
|
id: root
|
|
|
|
|
2024-02-28 12:01:31 +00:00
|
|
|
// GENERAL
|
2024-03-08 09:27:45 +00:00
|
|
|
readonly property bool dirty: communities.dirty || accounts.dirty || collectibles.dirty || socialLinks.dirty
|
2024-02-28 12:01:31 +00:00
|
|
|
|
|
|
|
function revert() {
|
|
|
|
communities.revert()
|
|
|
|
accounts.revert()
|
|
|
|
collectibles.revert()
|
2024-03-08 09:27:45 +00:00
|
|
|
socialLinks.revert()
|
2024-02-28 12:01:31 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 12:08:45 +00:00
|
|
|
// COMMUNITIES
|
|
|
|
|
|
|
|
// Input models
|
2024-03-29 11:43:49 +00:00
|
|
|
property alias communitiesSourceModel: communities.sourceModel
|
2024-02-16 12:08:45 +00:00
|
|
|
|
|
|
|
// Output models
|
|
|
|
readonly property alias communitiesVisibleModel: communities.visibleModel
|
|
|
|
readonly property alias communitiesHiddenModel: communities.hiddenModel
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
function communitiesCurrentState() {
|
|
|
|
return communities.currentState()
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCommunityVisibility(key, visibility) {
|
|
|
|
communities.setVisibility(key, visibility)
|
|
|
|
}
|
|
|
|
|
2024-04-19 09:46:23 +00:00
|
|
|
function changeCommunityPosition(from, to) {
|
|
|
|
communities.changePosition(from, to)
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ACCOUNTS
|
|
|
|
|
|
|
|
// Input models
|
2024-03-29 11:43:49 +00:00
|
|
|
property alias accountsSourceModel: accounts.sourceModel
|
2024-02-16 12:08:45 +00:00
|
|
|
|
|
|
|
// Output models
|
|
|
|
readonly property alias accountsVisibleModel: accounts.visibleModel
|
|
|
|
readonly property alias accountsHiddenModel: accounts.hiddenModel
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
function accountsCurrentState() {
|
|
|
|
return accounts.currentState()
|
|
|
|
}
|
|
|
|
|
|
|
|
function setAccountVisibility(key, visibility) {
|
|
|
|
accounts.setVisibility(key, visibility)
|
|
|
|
}
|
|
|
|
|
2024-04-19 09:46:23 +00:00
|
|
|
function changeAccountPosition(from, to) {
|
|
|
|
accounts.changePosition(from, to)
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Other
|
|
|
|
readonly property alias visibleAccountsList:
|
|
|
|
visibleAccountsConnections.visibleAccountsList
|
|
|
|
|
|
|
|
readonly property alias accountsVisibilityMap:
|
|
|
|
visibleAccountsConnections.accountsVisibilityMap
|
|
|
|
|
|
|
|
// COLLECTIBLES
|
|
|
|
|
|
|
|
// Input models
|
2024-03-29 11:43:49 +00:00
|
|
|
property alias collectiblesSourceModel: collectiblesFilter.sourceModel
|
2024-02-16 12:08:45 +00:00
|
|
|
|
|
|
|
// Output models
|
|
|
|
readonly property alias collectiblesVisibleModel: collectibles.visibleModel
|
|
|
|
readonly property alias collectiblesHiddenModel: collectibles.hiddenModel
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
function collectiblesCurrentState() {
|
|
|
|
return collectibles.currentState()
|
|
|
|
}
|
|
|
|
|
|
|
|
function setCollectibleVisibility(key, visibility) {
|
|
|
|
collectibles.setVisibility(key, visibility)
|
|
|
|
}
|
|
|
|
|
2024-02-29 07:43:38 +00:00
|
|
|
function changeCollectiblePosition(from, to) {
|
|
|
|
collectibles.changePosition(from, to)
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
2024-03-08 09:27:45 +00:00
|
|
|
// SOCIAL LINKS
|
|
|
|
|
|
|
|
// Input models
|
2024-03-29 11:43:49 +00:00
|
|
|
property alias socialLinksSourceModel: socialLinks.sourceModel
|
2024-03-08 09:27:45 +00:00
|
|
|
|
|
|
|
// Output models
|
|
|
|
readonly property alias socialLinksVisibleModel: socialLinks.visibleModel
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
function appendSocialLink(obj) {
|
|
|
|
socialLinks.append(obj)
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateSocialLink(index, obj) {
|
|
|
|
socialLinks.update(index, obj)
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeSocialLink(index) {
|
|
|
|
socialLinks.remove(index)
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeSocialLinkPosition(from, to) {
|
|
|
|
socialLinks.changePosition(from, to)
|
|
|
|
}
|
|
|
|
|
|
|
|
function socialLinksCurrentState(roleNames) {
|
|
|
|
return socialLinks.currentState(roleNames)
|
|
|
|
}
|
|
|
|
|
2024-03-08 20:11:48 +00:00
|
|
|
// The complete preferences models json current state:
|
|
|
|
function buildJSONModelsCurrentState() {
|
|
|
|
return JSON.stringify({
|
|
|
|
"communities": communitiesCurrentState(),
|
|
|
|
"accounts": accountsCurrentState(),
|
2024-03-08 09:27:45 +00:00
|
|
|
"collectibles": collectiblesCurrentState(),
|
|
|
|
"socialLinks": socialLinksCurrentState(["url", "text", "showcaseVisibility", "showcasePosition"])
|
2024-03-08 20:11:48 +00:00
|
|
|
// TODO: Assets --> Issue #13492
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-02-16 12:08:45 +00:00
|
|
|
ProfileShowcaseDirtyState {
|
|
|
|
id: communities
|
|
|
|
}
|
|
|
|
|
|
|
|
ProfileShowcaseDirtyState {
|
|
|
|
id: accounts
|
|
|
|
}
|
|
|
|
|
|
|
|
ProfileShowcaseDirtyState {
|
|
|
|
id: collectibles
|
|
|
|
|
|
|
|
sourceModel: collectiblesFilter
|
|
|
|
}
|
|
|
|
|
2024-03-08 09:27:45 +00:00
|
|
|
ProfileShowcaseDirtyState {
|
|
|
|
id: socialLinks
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-16 12:08:45 +00:00
|
|
|
SortFilterProxyModel {
|
|
|
|
id: collectiblesFilter
|
|
|
|
|
|
|
|
delayed: true
|
|
|
|
proxyRoles: FastExpressionRole {
|
|
|
|
name: "maxVisibility"
|
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
// singletons cannot be used in expressions
|
|
|
|
readonly property int hidden: Constants.ShowcaseVisibility.NoOne
|
|
|
|
|
2024-03-04 22:07:09 +00:00
|
|
|
function getMaxVisibility(ownershipModel) {
|
2024-02-20 13:26:56 +00:00
|
|
|
const visibilityMap = root.accountsVisibilityMap
|
2024-03-04 22:07:09 +00:00
|
|
|
const accounts = ModelUtils.modelToFlatArray(ownershipModel, "accountAddress")
|
|
|
|
const visibilities = accounts.map(a => visibilityMap[a.toLowerCase()]).filter(
|
2024-02-20 13:26:56 +00:00
|
|
|
v => v !== undefined)
|
2024-02-16 12:08:45 +00:00
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
return visibilities.length ? Math.min(...visibilities) : hidden
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
2024-03-04 22:07:09 +00:00
|
|
|
expression: {
|
|
|
|
return getMaxVisibility(model.ownership)
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedRoles: ["ownership"]
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
2024-02-20 13:26:56 +00:00
|
|
|
filters: ValueFilter {
|
2024-02-16 12:08:45 +00:00
|
|
|
roleName: "maxVisibility"
|
2024-02-20 13:26:56 +00:00
|
|
|
value: Constants.ShowcaseVisibility.NoOne
|
|
|
|
inverted: true
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
id: visibleAccountsConnections
|
|
|
|
|
|
|
|
target: accounts.visibleModel
|
|
|
|
|
|
|
|
property var visibleAccountsList: []
|
|
|
|
property var accountsVisibilityMap: ({})
|
|
|
|
|
|
|
|
function updateAccountsList() {
|
|
|
|
const keysAndVisibility = ModelUtils.modelToArray(
|
2024-03-04 22:07:09 +00:00
|
|
|
accounts.visibleModel, ["showcaseKey", "showcaseVisibility"])
|
2024-02-16 12:08:45 +00:00
|
|
|
|
2024-03-04 22:07:09 +00:00
|
|
|
visibleAccountsList = keysAndVisibility.map(e => e.showcaseKey)
|
2024-02-16 12:08:45 +00:00
|
|
|
|
|
|
|
accountsVisibilityMap = keysAndVisibility.reduce(
|
|
|
|
(acc, val) => Object.assign(
|
2024-03-04 22:07:09 +00:00
|
|
|
acc, {[val.showcaseKey]: val.showcaseVisibility}), {})
|
2024-02-16 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onDataChanged() {
|
|
|
|
updateAccountsList()
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRowsInserted() {
|
|
|
|
updateAccountsList()
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRowsRemoved() {
|
|
|
|
updateAccountsList()
|
|
|
|
}
|
|
|
|
|
|
|
|
function onModelReset() {
|
|
|
|
updateAccountsList()
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: updateAccountsList()
|
|
|
|
}
|
|
|
|
}
|