mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-03 14:19:56 +00:00
Viewlet setting drag and drop fix (#2682)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
2a2ff83924
commit
a01b7e5d6c
@ -84,10 +84,6 @@
|
|||||||
value = !value
|
value = !value
|
||||||
dispatch('change', value)
|
dispatch('change', value)
|
||||||
}}
|
}}
|
||||||
on:focus
|
|
||||||
on:blur
|
|
||||||
on:mousemove
|
|
||||||
on:mouseleave
|
|
||||||
{id}
|
{id}
|
||||||
>
|
>
|
||||||
{#if icon}
|
{#if icon}
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
(res) => {
|
(res) => {
|
||||||
preference = res[0]
|
preference = res[0]
|
||||||
attributes = getConfig(viewlet, preference)
|
attributes = getConfig(viewlet, preference)
|
||||||
|
enabled = attributes.filter((p) => p.enabled)
|
||||||
loading = false
|
loading = false
|
||||||
},
|
},
|
||||||
{ limit: 1 }
|
{ limit: 1 }
|
||||||
@ -58,6 +59,7 @@
|
|||||||
const hierarchy = client.getHierarchy()
|
const hierarchy = client.getHierarchy()
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
let attributes: AttributeConfig[] = []
|
let attributes: AttributeConfig[] = []
|
||||||
|
let enabled: AttributeConfig[] = []
|
||||||
let loading = true
|
let loading = true
|
||||||
|
|
||||||
interface AttributeConfig {
|
interface AttributeConfig {
|
||||||
@ -210,7 +212,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function save (): Promise<void> {
|
async function save (): Promise<void> {
|
||||||
const config = attributes.filter((p) => p.enabled).map((p) => p.value)
|
const config = enabled.map((p) => p.value)
|
||||||
if (preference !== undefined) {
|
if (preference !== undefined) {
|
||||||
await client.update(preference, {
|
await client.update(preference, {
|
||||||
config
|
config
|
||||||
@ -225,6 +227,7 @@
|
|||||||
|
|
||||||
function restoreDefault (): void {
|
function restoreDefault (): void {
|
||||||
attributes = getConfig(viewlet, undefined)
|
attributes = getConfig(viewlet, undefined)
|
||||||
|
enabled = attributes.filter((p) => p.enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setStatus (result: AttributeConfig[], preference: ViewletPreference): AttributeConfig[] {
|
function setStatus (result: AttributeConfig[], preference: ViewletPreference): AttributeConfig[] {
|
||||||
@ -246,8 +249,7 @@
|
|||||||
const elements: HTMLElement[] = []
|
const elements: HTMLElement[] = []
|
||||||
let selected: number | undefined
|
let selected: number | undefined
|
||||||
|
|
||||||
function dragswap (ev: MouseEvent, i: number): boolean {
|
function dragswap (ev: MouseEvent, i: number, s: number): boolean {
|
||||||
const s = selected as number
|
|
||||||
if (i < s) {
|
if (i < s) {
|
||||||
if (elements[i].offsetTop !== elements[s].offsetTop) {
|
if (elements[i].offsetTop !== elements[s].offsetTop) {
|
||||||
return ev.offsetY < elements[i].offsetHeight / 2
|
return ev.offsetY < elements[i].offsetHeight / 2
|
||||||
@ -266,8 +268,8 @@
|
|||||||
|
|
||||||
function dragover (ev: MouseEvent, i: number) {
|
function dragover (ev: MouseEvent, i: number) {
|
||||||
const s = selected as number
|
const s = selected as number
|
||||||
if (dragswap(ev, i)) {
|
if (dragswap(ev, i, s)) {
|
||||||
;[attributes[i], attributes[s]] = [attributes[s], attributes[i]]
|
;[enabled[i], enabled[s]] = [enabled[s], enabled[i]]
|
||||||
selected = i
|
selected = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,7 +295,6 @@
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
$: enabled = attributes.filter((p) => p.enabled)
|
|
||||||
$: classes = groupByClasses(attributes)
|
$: classes = groupByClasses(attributes)
|
||||||
|
|
||||||
function getClassLabel (_class: Ref<Class<Doc>>): IntlString {
|
function getClassLabel (_class: Ref<Class<Doc>>): IntlString {
|
||||||
@ -336,6 +337,10 @@
|
|||||||
icon={attribute.icon}
|
icon={attribute.icon}
|
||||||
label={attribute.label}
|
label={attribute.label}
|
||||||
bind:value={attribute.enabled}
|
bind:value={attribute.enabled}
|
||||||
|
on:change={() => {
|
||||||
|
enabled.splice(i, 1)
|
||||||
|
enabled = enabled
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
@ -357,7 +362,8 @@
|
|||||||
const value = classes.get(_class)?.find((it) => it.value === val)
|
const value = classes.get(_class)?.find((it) => it.value === val)
|
||||||
if (value) {
|
if (value) {
|
||||||
value.enabled = true
|
value.enabled = true
|
||||||
attributes = attributes
|
enabled.push(value)
|
||||||
|
enabled = enabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user