From 33a4445a06d969c11f59784e6685d09dc03e9aa2 Mon Sep 17 00:00:00 2001 From: Sergei Ogorelkov Date: Wed, 30 Nov 2022 22:03:05 +0600 Subject: [PATCH] Add sortable list (#2403) Signed-off-by: Sergei Ogorelkov --- models/view/src/index.ts | 3 +- .../src/components/CreateContact.svelte | 28 ++- .../src/components/list/SortableList.svelte | 219 ++++++++++++++++++ .../components/list/SortableListItem.svelte | 52 +++++ .../list/SortableListItemPresenter.svelte | 106 +++++++++ plugins/view-resources/src/index.ts | 8 +- plugins/view/src/index.ts | 3 +- 7 files changed, 407 insertions(+), 12 deletions(-) create mode 100644 plugins/view-resources/src/components/list/SortableList.svelte create mode 100644 plugins/view-resources/src/components/list/SortableListItem.svelte create mode 100644 plugins/view-resources/src/components/list/SortableListItemPresenter.svelte diff --git a/models/view/src/index.ts b/models/view/src/index.ts index 70d8d8784e..fa6067528d 100644 --- a/models/view/src/index.ts +++ b/models/view/src/index.ts @@ -161,7 +161,8 @@ export class TObjectValidator extends TClass implements ObjectValidator { @Mixin(view.mixin.ObjectFactory, core.class.Class) export class TObjectFactory extends TClass implements ObjectFactory { - component!: AnyComponent + component?: AnyComponent + create?: Resource<() => Promise> } @Mixin(view.mixin.ObjectTitle, core.class.Class) diff --git a/plugins/contact-resources/src/components/CreateContact.svelte b/plugins/contact-resources/src/components/CreateContact.svelte index 64779868e4..cf70e61abf 100644 --- a/plugins/contact-resources/src/components/CreateContact.svelte +++ b/plugins/contact-resources/src/components/CreateContact.svelte @@ -1,5 +1,5 @@ diff --git a/plugins/view-resources/src/components/list/SortableList.svelte b/plugins/view-resources/src/components/list/SortableList.svelte new file mode 100644 index 0000000000..913309e1ce --- /dev/null +++ b/plugins/view-resources/src/components/list/SortableList.svelte @@ -0,0 +1,219 @@ + + + +
+ {#if label} +
+ {#if label} +
+ + +
+ {/if} + {#if objectFactory} +
+
+ {/if} +
+ {/if} + + {#if isLoading} + + {:else if model && items} +
+ {#each items as item, index (item._id)} + {@const isDraggable = isSortable && items.length > 1 && !areItemsSorting} +
draggingIndex} + draggable={isDraggable} + animate:flip={{ duration: flipDuration }} + on:dragstart={(ev) => handleDragStart(ev, index)} + on:dragover={(ev) => handleDragOver(ev, index)} + on:drop={() => handleDrop(index)} + on:dragend={resetDrag} + > + + + +
+ {/each} + + {#if objectFactory?.component && isCreating} + + (isCreating = false)} /> + {/if} +
+ {/if} +
+ + diff --git a/plugins/view-resources/src/components/list/SortableListItem.svelte b/plugins/view-resources/src/components/list/SortableListItem.svelte new file mode 100644 index 0000000000..5cc4c4d1c1 --- /dev/null +++ b/plugins/view-resources/src/components/list/SortableListItem.svelte @@ -0,0 +1,52 @@ + + + +
+
+
+
+ + +
+ + diff --git a/plugins/view-resources/src/components/list/SortableListItemPresenter.svelte b/plugins/view-resources/src/components/list/SortableListItemPresenter.svelte new file mode 100644 index 0000000000..3f9e7c9de4 --- /dev/null +++ b/plugins/view-resources/src/components/list/SortableListItemPresenter.svelte @@ -0,0 +1,106 @@ + + + +
dispatch('edit') : undefined} +> +
+ +
+ + {#if areButtonsVisible} +
+ {#if isEditing} + + {/if} + {#if isDeletable} + + {/if} + {/if} +
+ {/if} +
+ + diff --git a/plugins/view-resources/src/index.ts b/plugins/view-resources/src/index.ts index 74b01d7ba4..8693f2562a 100644 --- a/plugins/view-resources/src/index.ts +++ b/plugins/view-resources/src/index.ts @@ -54,6 +54,9 @@ import UpDownNavigator from './components/UpDownNavigator.svelte' import ViewletSettingButton from './components/ViewletSettingButton.svelte' import ValueSelector from './components/ValueSelector.svelte' import HTMLEditor from './components/HTMLEditor.svelte' +import SortableList from './components/list/SortableList.svelte' +import SortableListItem from './components/list/SortableListItem.svelte' +import SortableListItemPresenter from './components/list/SortableListItemPresenter.svelte' import { afterResult, beforeResult, @@ -110,7 +113,10 @@ export { BooleanPresenter, NumberEditor, NumberPresenter, - TimestampPresenter + TimestampPresenter, + SortableList, + SortableListItem, + SortableListItemPresenter } export default async (): Promise => ({ diff --git a/plugins/view/src/index.ts b/plugins/view/src/index.ts index a9fb44dca3..3823690e6e 100644 --- a/plugins/view/src/index.ts +++ b/plugins/view/src/index.ts @@ -376,7 +376,8 @@ export interface BuildModelOptions { * */ export interface ObjectFactory extends Class { - component: AnyComponent + component?: AnyComponent + create?: Resource<() => Promise> } /**