chore(CommunityNewPermissionView): Operations on models excluded to ModelUtils singleton
This commit is contained in:
parent
fb19385438
commit
9f884605cb
|
@ -0,0 +1,39 @@
|
||||||
|
pragma Singleton
|
||||||
|
|
||||||
|
import QtQuick 2.14
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
function modelToArray(model, roles) {
|
||||||
|
if (!model)
|
||||||
|
return []
|
||||||
|
|
||||||
|
const count = model.count
|
||||||
|
const array = []
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const modelItem = model.get(i)
|
||||||
|
const arrayItem = {}
|
||||||
|
|
||||||
|
roles.forEach(role => {
|
||||||
|
const entry = modelItem[role]
|
||||||
|
|
||||||
|
if (entry !== undefined)
|
||||||
|
arrayItem[role] = entry
|
||||||
|
})
|
||||||
|
|
||||||
|
array.push(arrayItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
return array
|
||||||
|
}
|
||||||
|
|
||||||
|
function indexOf(model, role, key) {
|
||||||
|
const count = model.count
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i++)
|
||||||
|
if (model.get(i)[role] === key)
|
||||||
|
return i
|
||||||
|
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
module StatusQ.Core.Utils
|
module StatusQ.Core.Utils
|
||||||
|
|
||||||
EmojiJSON 1.0 emojiList.js
|
EmojiJSON 1.0 emojiList.js
|
||||||
XSS 1.0 xss.js
|
|
||||||
singleton Utils 0.1 Utils.qml
|
|
||||||
singleton Emoji 0.1 Emoji.qml
|
|
||||||
JSONListModel 0.1 JSONListModel.qml
|
JSONListModel 0.1 JSONListModel.qml
|
||||||
|
XSS 1.0 xss.js
|
||||||
|
singleton Emoji 0.1 Emoji.qml
|
||||||
|
singleton ModelUtils 0.1 ModelUtils.qml
|
||||||
singleton OperatorsUtils 0.1 OperatorsUtils.qml
|
singleton OperatorsUtils 0.1 OperatorsUtils.qml
|
||||||
|
singleton Utils 0.1 Utils.qml
|
||||||
|
|
|
@ -193,5 +193,6 @@
|
||||||
<file>StatusQ/Core/Utils/OperatorsUtils.qml</file>
|
<file>StatusQ/Core/Utils/OperatorsUtils.qml</file>
|
||||||
<file>StatusQ/Controls/StatusTextWithLoadingState.qml</file>
|
<file>StatusQ/Controls/StatusTextWithLoadingState.qml</file>
|
||||||
<file>StatusQ/Components/LoadingComponent.qml</file>
|
<file>StatusQ/Components/LoadingComponent.qml</file>
|
||||||
|
<file>StatusQ/Core/Utils/ModelUtils.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -8,12 +8,12 @@ import StatusQ.Components 0.1
|
||||||
import StatusQ.Controls 0.1
|
import StatusQ.Controls 0.1
|
||||||
import StatusQ.Core.Utils 0.1
|
import StatusQ.Core.Utils 0.1
|
||||||
|
|
||||||
import AppLayouts.Chat.helpers 1.0
|
|
||||||
import utils 1.0
|
import utils 1.0
|
||||||
import shared.panels 1.0
|
import shared.panels 1.0
|
||||||
|
|
||||||
import SortFilterProxyModel 0.2
|
import SortFilterProxyModel 0.2
|
||||||
|
|
||||||
|
import AppLayouts.Chat.helpers 1.0
|
||||||
import AppLayouts.Chat.panels.communities 1.0
|
import AppLayouts.Chat.panels.communities 1.0
|
||||||
|
|
||||||
import "../../../Chat/controls/community"
|
import "../../../Chat/controls/community"
|
||||||
|
@ -122,46 +122,20 @@ StatusScrollView {
|
||||||
|
|
||||||
property bool isPrivate: false
|
property bool isPrivate: false
|
||||||
|
|
||||||
function getIndexOfKey(key) {
|
function getHoldingIndex(key) {
|
||||||
const count = holdingsModel.count
|
return ModelUtils.indexOf(holdingsModel, "key", key)
|
||||||
|
|
||||||
for (let i = 0; i < count; i++)
|
|
||||||
if (holdingsModel.get(i).key === key)
|
|
||||||
return i
|
|
||||||
|
|
||||||
return -1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTokenKeysAndAmounts() {
|
function getTokenKeysAndAmounts() {
|
||||||
const keysAndAmounts = []
|
return ModelUtils.modelToArray(holdingsModel, ["type", "key", "amount"])
|
||||||
const count = holdingsModel.count
|
.filter(item => item.type !== HoldingTypes.Type.Ens)
|
||||||
|
.map(item => ({ key: item.key, amount: item.amount }))
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
const item = holdingsModel.get(i)
|
|
||||||
|
|
||||||
if (item.type === HoldingTypes.Type.Ens)
|
|
||||||
continue
|
|
||||||
|
|
||||||
keysAndAmounts.push({ key: item.key, amount: item.amount })
|
|
||||||
}
|
|
||||||
|
|
||||||
return keysAndAmounts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEnsNames() {
|
function getEnsNames() {
|
||||||
const names = []
|
return ModelUtils.modelToArray(holdingsModel, ["type", "name"])
|
||||||
const count = holdingsModel.count
|
.filter(item => item.type === HoldingTypes.Type.Ens)
|
||||||
|
.map(item => item.name)
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
const item = holdingsModel.get(i)
|
|
||||||
|
|
||||||
if (item.type !== HoldingTypes.Type.Ens)
|
|
||||||
continue
|
|
||||||
|
|
||||||
names.push(item.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return names
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,24 +143,9 @@ StatusScrollView {
|
||||||
// Holdings:
|
// Holdings:
|
||||||
d.dirtyValues.holdingsModel.clear()
|
d.dirtyValues.holdingsModel.clear()
|
||||||
|
|
||||||
if (root.holdingsModel) {
|
d.dirtyValues.holdingsModel.append(
|
||||||
for (let i = 0; i < root.holdingsModel.count; i++) {
|
ModelUtils.modelToArray(root.holdingsModel,
|
||||||
const item = root.holdingsModel.get(i)
|
["type", "key", "name", "amount", "imageSource", "shortName"]))
|
||||||
|
|
||||||
const initItem = {
|
|
||||||
type: item.type,
|
|
||||||
key: item.key,
|
|
||||||
name: item.name,
|
|
||||||
amount: item.amount,
|
|
||||||
imageSource: item.imageSource
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.shortName)
|
|
||||||
initItem.shortName = item.shortName
|
|
||||||
|
|
||||||
d.dirtyValues.holdingsModel.append(initItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Permissions:
|
// Permissions:
|
||||||
d.dirtyValues.permissionObject.key = root.permissionObject ? root.permissionObject.key : null
|
d.dirtyValues.permissionObject.key = root.permissionObject ? root.permissionObject.key : null
|
||||||
|
@ -198,21 +157,9 @@ StatusScrollView {
|
||||||
// Channels
|
// Channels
|
||||||
d.dirtyValues.channelsModel.clear()
|
d.dirtyValues.channelsModel.clear()
|
||||||
|
|
||||||
if (root.channelsModel) {
|
d.dirtyValues.channelsModel.append(
|
||||||
for (let c = 0; c < root.channelsModel.count; c++) {
|
ModelUtils.modelToArray(root.channelsModel,
|
||||||
const item = root.channelsModel.get(c)
|
["itemId", "text", "emoji", "color", "operator"]))
|
||||||
|
|
||||||
const initItem = {
|
|
||||||
itemId: item.itemId,
|
|
||||||
text: item.text,
|
|
||||||
emoji: item.emoji,
|
|
||||||
color: item.color,
|
|
||||||
operator: OperatorsUtils.Operators.None
|
|
||||||
}
|
|
||||||
|
|
||||||
d.dirtyValues.channelsModel.append(initItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root.channelsModel && (root.channelsModel.count || d.dirtyValues.permissionObject.key === null)) {
|
if (root.channelsModel && (root.channelsModel.count || d.dirtyValues.permissionObject.key === null)) {
|
||||||
inSelector.wholeCommunitySelected = false
|
inSelector.wholeCommunitySelected = false
|
||||||
|
@ -352,12 +299,12 @@ StatusScrollView {
|
||||||
|
|
||||||
function prepareUpdateIndex(key) {
|
function prepareUpdateIndex(key) {
|
||||||
const itemIndex = tokensSelector.editedIndex
|
const itemIndex = tokensSelector.editedIndex
|
||||||
const existingIndex = d.dirtyValues.getIndexOfKey(key)
|
const existingIndex = d.dirtyValues.getHoldingIndex(key)
|
||||||
|
|
||||||
if (itemIndex !== -1 && existingIndex !== -1 && itemIndex !== existingIndex) {
|
if (itemIndex !== -1 && existingIndex !== -1 && itemIndex !== existingIndex) {
|
||||||
const previousKey = d.dirtyValues.holdingsModel.get(itemIndex).key
|
const previousKey = d.dirtyValues.holdingsModel.get(itemIndex).key
|
||||||
d.dirtyValues.holdingsModel.remove(existingIndex)
|
d.dirtyValues.holdingsModel.remove(existingIndex)
|
||||||
return d.dirtyValues.getIndexOfKey(previousKey)
|
return d.dirtyValues.getHoldingIndex(previousKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemIndex === -1) {
|
if (itemIndex === -1) {
|
||||||
|
|
Loading…
Reference in New Issue