Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-05-30 13:41:19 +06:00 committed by GitHub
parent a2d8bfc5e3
commit e97a6cb6f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 39 deletions

View File

@ -15,7 +15,7 @@
<script lang="ts"> <script lang="ts">
import core, { Enum } from '@anticrm/core' import core, { Enum } from '@anticrm/core'
import presentation, { Card, getClient } from '@anticrm/presentation' import presentation, { Card, getClient } from '@anticrm/presentation'
import { ActionIcon, EditBox, IconAdd, IconDelete } from '@anticrm/ui' import { ActionIcon, EditBox, IconCheck, IconDelete } from '@anticrm/ui'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import setting from '../plugin' import setting from '../plugin'
@ -65,12 +65,12 @@
> >
<div class="mb-2"><EditBox bind:value={name} placeholder={core.string.Name} maxWidth="13rem" /></div> <div class="mb-2"><EditBox bind:value={name} placeholder={core.string.Name} maxWidth="13rem" /></div>
<div class="flex-between mb-4"> <div class="flex-between mb-4">
<EditBox placeholder={setting.string.NewValue} bind:value={newValue} maxWidth="13rem" /><ActionIcon <EditBox
icon={IconAdd} placeholder={setting.string.NewValue}
label={presentation.string.Add} kind="large-style"
action={add} bind:value={newValue}
size={'small'} maxWidth="13rem"
/> /><ActionIcon icon={IconCheck} label={presentation.string.Add} action={add} size={'small'} />
</div> </div>
<div class="flex-row"> <div class="flex-row">
{#each values as value} {#each values as value}

View File

@ -14,8 +14,9 @@
--> -->
<script lang="ts"> <script lang="ts">
import core, { Enum } from '@anticrm/core' import core, { Enum } from '@anticrm/core'
import { createQuery } from '@anticrm/presentation' import { createQuery, getClient } from '@anticrm/presentation'
import { CircleButton, Icon, IconAdd, Label, showPopup } from '@anticrm/ui' import { CircleButton, EditBox, Icon, eventToHTMLElement, IconAdd, IconMoreH, Label, showPopup } from '@anticrm/ui'
import { ContextMenu } from '@anticrm/view-resources'
import setting from '../plugin' import setting from '../plugin'
import EnumValues from './EnumValues.svelte' import EnumValues from './EnumValues.svelte'
@ -23,14 +24,25 @@
let enums: Enum[] = [] let enums: Enum[] = []
let selected: Enum | undefined let selected: Enum | undefined
const client = getClient()
query.query(core.class.Enum, {}, (res) => { query.query(core.class.Enum, {}, (res) => {
console.log(res)
enums = res enums = res
if (selected !== undefined) {
selected = enums.find((p) => p._id === selected?._id)
}
}) })
function create () { function create () {
showPopup(setting.component.EditEnum, 'top') showPopup(setting.component.EditEnum, 'top')
} }
async function update (value: Enum): Promise<void> {
await client.update(value, {
name: value.name
})
}
</script> </script>
<div class="antiComponent"> <div class="antiComponent">
@ -53,12 +65,20 @@
selected = value selected = value
}} }}
> >
{value.name} <EditBox maxWidth="15rem" bind:value={value.name} on:change={() => update(value)} />
<div
class="hover-trans"
on:click|stopPropagation={(ev) => {
showPopup(ContextMenu, { object: value }, eventToHTMLElement(ev), () => {})
}}
>
<IconMoreH size={'medium'} />
</div>
</div> </div>
{/each} {/each}
</div> </div>
</div> </div>
<div class="ac-column max"> <div class="ac-column">
{#if selected !== undefined} {#if selected !== undefined}
<EnumValues value={selected} /> <EnumValues value={selected} />
{/if} {/if}

View File

@ -14,48 +14,51 @@
--> -->
<script lang="ts"> <script lang="ts">
import { Enum } from '@anticrm/core' import { Enum } from '@anticrm/core'
import { ActionIcon, Button, EditBox, IconAdd, IconDelete } from '@anticrm/ui' import { ActionIcon, EditBox, IconCheck, IconDelete } from '@anticrm/ui'
import presentation, { getClient } from '@anticrm/presentation' import { getClient } from '@anticrm/presentation'
import setting from '../plugin' import setting from '../plugin'
export let value: Enum export let value: Enum
const client = getClient() const client = getClient()
$: values = value.enumValues
let newValue = '' let newValue = ''
function add () { async function add () {
if (newValue.trim().length === 0) return if (newValue.trim().length === 0) return
values.push(newValue) await client.update(value, {
values = values $push: { enumValues: newValue }
})
newValue = '' newValue = ''
} }
function remove (value: string) { async function remove (target: string) {
values = values.filter((p) => p !== value)
}
async function save () {
await client.update(value, { await client.update(value, {
enumValues: values $pull: { enumValues: target }
}) })
} }
</script> </script>
<div class="flex-grow"> <div class="flex-grow">
<div class="flex-between mb-4"> <div class="flex-between mb-4">
<EditBox placeholder={setting.string.NewValue} bind:value={newValue} maxWidth="20rem" /><ActionIcon <EditBox
label={presentation.string.Add} placeholder={setting.string.NewValue}
icon={IconAdd} on:keydown={(evt) => {
action={add} if (evt.key === 'Enter') {
size={'small'} add()
}
}}
kind="large-style"
bind:value={newValue}
maxWidth="18rem"
/> />
<ActionIcon icon={IconCheck} label={setting.string.Add} action={add} size={'small'} />
</div> </div>
<div class="overflow-y-auto flex-row"> <div class="overflow-y-auto flex-row">
{#each values as value} {#each value.enumValues as value}
<div class="flex-between mb-2"> <div class="flex-between mb-2">
{value}<ActionIcon {value}
<ActionIcon
icon={IconDelete} icon={IconDelete}
label={setting.string.Delete} label={setting.string.Delete}
action={() => { action={() => {
@ -67,12 +70,3 @@
{/each} {/each}
</div> </div>
</div> </div>
<div class="flex-row-reverse">
<Button
label={presentation.string.Save}
kind={'primary'}
on:click={() => {
save()
}}
/>
</div>