chore(ProfileShowcaseDirtyState): integration with Constants.ShowcaseVisibility enum
This commit is contained in:
parent
29c15a5bff
commit
94f250d671
|
@ -9,6 +9,8 @@ import Storybook 1.0
|
|||
|
||||
import AppLayouts.Profile.helpers 1.0
|
||||
|
||||
import utils 1.0
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
|
@ -24,8 +26,33 @@ Item {
|
|||
ListModel {
|
||||
id: communitiesShowcaseModel
|
||||
|
||||
ListElement { key: "1"; visibility: 1; position: 0 }
|
||||
ListElement { key: "3"; visibility: 2; position: 9 }
|
||||
ListElement {
|
||||
key: "1"
|
||||
visibility: Constants.ShowcaseVisibility.IdVerifiedContacts
|
||||
position: 0
|
||||
}
|
||||
ListElement {
|
||||
key: "3"
|
||||
visibility: Constants.ShowcaseVisibility.Contacts
|
||||
position: 9
|
||||
}
|
||||
}
|
||||
|
||||
ListModel {
|
||||
id: comboBoxModel
|
||||
|
||||
ListElement {
|
||||
text: "verified"
|
||||
value: Constants.ShowcaseVisibility.IdVerifiedContacts
|
||||
}
|
||||
ListElement {
|
||||
text: "contacts"
|
||||
value: Constants.ShowcaseVisibility.Contacts
|
||||
}
|
||||
ListElement {
|
||||
text: "all"
|
||||
value: Constants.ShowcaseVisibility.Everyone
|
||||
}
|
||||
}
|
||||
|
||||
ProfileShowcaseDirtyState {
|
||||
|
@ -130,17 +157,13 @@ Item {
|
|||
|
||||
RoundButton {
|
||||
text: "❌"
|
||||
onClicked: dirtyState.setVisibility(model.key, 0)
|
||||
onClicked: dirtyState.setVisibility(
|
||||
model.key,
|
||||
Constants.ShowcaseVisibility.NoOne)
|
||||
}
|
||||
|
||||
ComboBox {
|
||||
id: combo
|
||||
|
||||
model: ListModel {
|
||||
ListElement { text: "contacts"; value: 1 }
|
||||
ListElement { text: "verified"; value: 2 }
|
||||
ListElement { text: "all"; value: 3 }
|
||||
}
|
||||
model: comboBoxModel
|
||||
|
||||
onCurrentValueChanged: {
|
||||
if (!completed || topModel.index < 0)
|
||||
|
@ -174,7 +197,9 @@ Item {
|
|||
insetComponent: Button {
|
||||
text: "unhide"
|
||||
|
||||
onClicked: dirtyState.setVisibility(model.key, 1)
|
||||
onClicked: dirtyState.setVisibility(
|
||||
model.key,
|
||||
Constants.ShowcaseVisibility.IdVerifiedContacts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,16 @@ ColumnLayout {
|
|||
ListModel {
|
||||
id: accountsShowcaseModel
|
||||
|
||||
ListElement { key: "1"; visibility: 1; position: 0 }
|
||||
ListElement { key: "3"; visibility: 2; position: 9 }
|
||||
ListElement {
|
||||
key: "1"
|
||||
visibility: Constants.ShowcaseVisibility.IdVerifiedContacts
|
||||
position: 0
|
||||
}
|
||||
ListElement {
|
||||
key: "3"
|
||||
visibility: Constants.ShowcaseVisibility.Contacts
|
||||
position: 9
|
||||
}
|
||||
}
|
||||
|
||||
ListModel {
|
||||
|
@ -41,9 +49,21 @@ ColumnLayout {
|
|||
ListModel {
|
||||
id: collectiblesShowcaseModel
|
||||
|
||||
ListElement { key: "1"; visibility: 1; position: 0 }
|
||||
ListElement { key: "2"; visibility: 2; position: 2 }
|
||||
ListElement { key: "3"; visibility: 2; position: 1 }
|
||||
ListElement {
|
||||
key: "1"
|
||||
visibility: Constants.ShowcaseVisibility.IdVerifiedContacts
|
||||
position: 0
|
||||
}
|
||||
ListElement {
|
||||
key: "2"
|
||||
visibility: Constants.ShowcaseVisibility.Contacts
|
||||
position: 2
|
||||
}
|
||||
ListElement {
|
||||
key: "3"
|
||||
visibility: Constants.ShowcaseVisibility.Contacts
|
||||
position: 1
|
||||
}
|
||||
}
|
||||
|
||||
ProfileShowcaseModels {
|
||||
|
@ -68,12 +88,25 @@ ColumnLayout {
|
|||
sourceModel: showcaseModels.collectiblesVisibleModel
|
||||
}
|
||||
|
||||
component VisibilityComboBox: ComboBox {
|
||||
model: ListModel {
|
||||
ListElement { text: "contacts"; value: 1 }
|
||||
ListElement { text: "verified"; value: 2 }
|
||||
ListElement { text: "all"; value: 3 }
|
||||
ListModel {
|
||||
id: comboBoxModel
|
||||
|
||||
ListElement {
|
||||
text: "verified"
|
||||
value: Constants.ShowcaseVisibility.IdVerifiedContacts
|
||||
}
|
||||
ListElement {
|
||||
text: "contacts"
|
||||
value: Constants.ShowcaseVisibility.Contacts
|
||||
}
|
||||
ListElement {
|
||||
text: "all"
|
||||
value: Constants.ShowcaseVisibility.Everyone
|
||||
}
|
||||
}
|
||||
|
||||
component VisibilityComboBox: ComboBox {
|
||||
model: comboBoxModel
|
||||
|
||||
textRole: "text"
|
||||
valueRole: "value"
|
||||
|
@ -150,7 +183,8 @@ ColumnLayout {
|
|||
RoundButton {
|
||||
text: "❌"
|
||||
onClicked: showcaseModels.setAccountVisibility(
|
||||
model.key, 0)
|
||||
model.key,
|
||||
Constants.ShowcaseVisibility.NoOne)
|
||||
}
|
||||
|
||||
VisibilityComboBox {
|
||||
|
@ -185,8 +219,10 @@ ColumnLayout {
|
|||
insetComponent: Button {
|
||||
text: "unhide"
|
||||
|
||||
onClicked: showcaseModels.setAccountVisibility(
|
||||
model.key, 1)
|
||||
onClicked:
|
||||
showcaseModels.setAccountVisibility(
|
||||
model.key,
|
||||
Constants.ShowcaseVisibility.IdVerifiedContacts)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,7 +279,8 @@ ColumnLayout {
|
|||
RoundButton {
|
||||
text: "❌"
|
||||
onClicked: showcaseModels.setCollectibleVisibility(
|
||||
model.key, 0)
|
||||
model.key,
|
||||
Constants.ShowcaseVisibility.NoOne)
|
||||
}
|
||||
|
||||
VisibilityComboBox {
|
||||
|
@ -279,8 +316,10 @@ ColumnLayout {
|
|||
insetComponent: Button {
|
||||
text: "unhide"
|
||||
|
||||
onClicked: showcaseModels.setCollectibleVisibility(
|
||||
model.key, 1)
|
||||
onClicked:
|
||||
showcaseModels.setCollectibleVisibility(
|
||||
model.key,
|
||||
Constants.ShowcaseVisibility.IdVerifiedContacts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import StatusQ.Core.Utils 0.1
|
|||
|
||||
import SortFilterProxyModel 0.2
|
||||
|
||||
import utils 1.0
|
||||
|
||||
/**
|
||||
* Building block for managing temporary state in the "Profile Showcase"
|
||||
* functionality. Provides combining raw source model (like e.g. communities
|
||||
|
@ -45,9 +47,15 @@ QObject {
|
|||
readonly property alias writable_: writable
|
||||
readonly property alias joined_: joined
|
||||
|
||||
component VisibilityFilter: RangeFilter {
|
||||
component HiddenFilter: AnyOf {
|
||||
UndefinedFilter {
|
||||
roleName: "visibility"
|
||||
minimumValue: 1
|
||||
}
|
||||
|
||||
ValueFilter {
|
||||
roleName: "visibility"
|
||||
value: Constants.ShowcaseVisibility.NoOne
|
||||
}
|
||||
}
|
||||
|
||||
LeftJoinModel {
|
||||
|
@ -60,6 +68,7 @@ QObject {
|
|||
id: writable
|
||||
|
||||
sourceModel: joined
|
||||
visibilityHidden: Constants.ShowcaseVisibility.NoOne
|
||||
}
|
||||
|
||||
SortFilterProxyModel {
|
||||
|
@ -68,7 +77,7 @@ QObject {
|
|||
sourceModel: writable
|
||||
delayed: true
|
||||
|
||||
filters: VisibilityFilter {}
|
||||
filters: HiddenFilter { inverted: true }
|
||||
sorters: RoleSorter { roleName: "position" }
|
||||
}
|
||||
|
||||
|
@ -78,6 +87,6 @@ QObject {
|
|||
sourceModel: writable
|
||||
delayed: true
|
||||
|
||||
filters: VisibilityFilter { inverted: true}
|
||||
filters: HiddenFilter {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import StatusQ.Core.Utils 0.1
|
|||
|
||||
import SortFilterProxyModel 0.2
|
||||
|
||||
import utils 1.0
|
||||
|
||||
QObject {
|
||||
id: root
|
||||
|
||||
|
@ -106,20 +108,25 @@ QObject {
|
|||
proxyRoles: FastExpressionRole {
|
||||
name: "maxVisibility"
|
||||
|
||||
expression: {
|
||||
const m = root.accountsVisibilityMap
|
||||
const accounts = model.accounts.split(":")
|
||||
const visibilities = accounts.map(e => m[e]).filter(e => e)
|
||||
// singletons cannot be used in expressions
|
||||
readonly property int hidden: Constants.ShowcaseVisibility.NoOne
|
||||
|
||||
return visibilities.length ? Math.min(...visibilities) : 0
|
||||
expression: {
|
||||
const visibilityMap = root.accountsVisibilityMap
|
||||
const accounts = model.accounts.split(":")
|
||||
const visibilities = accounts.map(a => visibilityMap[a]).filter(
|
||||
v => v !== undefined)
|
||||
|
||||
return visibilities.length ? Math.min(...visibilities) : hidden
|
||||
}
|
||||
|
||||
expectedRoles: ["accounts"]
|
||||
}
|
||||
|
||||
filters: RangeFilter {
|
||||
filters: ValueFilter {
|
||||
roleName: "maxVisibility"
|
||||
minimumValue: 1
|
||||
value: Constants.ShowcaseVisibility.NoOne
|
||||
inverted: true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,14 @@ import StatusQ.Core.Utils 0.1
|
|||
WritableProxyModel {
|
||||
id: root
|
||||
|
||||
/**
|
||||
* "Hidden" is a special type of visibility that requires special
|
||||
* treatment. When the visibility is changed from hidden to other type
|
||||
* of visibility, in addition to changing the visibility, the appropriate
|
||||
* position is also set.
|
||||
*/
|
||||
property int visibilityHidden: 0
|
||||
|
||||
/* Provides the list of objects representing the current state in the
|
||||
* in the following format:
|
||||
* [ {
|
||||
|
@ -41,7 +49,8 @@ WritableProxyModel {
|
|||
return
|
||||
|
||||
// hiding, changing visibility level
|
||||
if (visibility === 0 || (visibility > 0 && oldVisibility > 0)) {
|
||||
if (visibility === visibilityHidden
|
||||
|| oldVisibility !== visibilityHidden) {
|
||||
set(sourceIdx, { visibility: visibility })
|
||||
return
|
||||
}
|
||||
|
@ -96,11 +105,13 @@ WritableProxyModel {
|
|||
const roles = ["key", "position", "visibility"]
|
||||
const keysAndPos = ModelUtils.modelToArray(root, roles)
|
||||
|
||||
return keysAndPos.filter(p => p.visibility)
|
||||
return keysAndPos.filter(p => p.visibility
|
||||
&& p.visibility !== root.visibilityHidden)
|
||||
}
|
||||
|
||||
function getVisibility(idx) {
|
||||
return ModelUtils.get(root, idx, "visibility") || 0
|
||||
return ModelUtils.get(root, idx, "visibility")
|
||||
|| root.visibilityHidden
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue