From e82c83f3ab7ffdcf8a5821de3b698ac939dcede3 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 8 Feb 2024 15:12:43 +0000 Subject: [PATCH] [WIP] Adds Document Collection Grid View Largely copied from "src\packages\user\user\collection\views\grid\user-grid-collection-view.element.ts" --- .../document-grid-collection-view.element.ts | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/Umbraco.Web.UI.Client/src/packages/documents/documents/collection/views/grid/document-grid-collection-view.element.ts diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/collection/views/grid/document-grid-collection-view.element.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/collection/views/grid/document-grid-collection-view.element.ts new file mode 100644 index 0000000000..8189c2ab6a --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/collection/views/grid/document-grid-collection-view.element.ts @@ -0,0 +1,106 @@ +import type { UmbDocumentCollectionFilterModel } from '../../types.js'; +import type { UmbDocumentTreeItemModel } from '../../../tree/types.js'; +import { css, html, nothing, customElement, state, repeat } from '@umbraco-cms/backoffice/external/lit'; +import { UmbLitElement } from '@umbraco-cms/internal/lit-element'; +import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; +import { UMB_DEFAULT_COLLECTION_CONTEXT } from '@umbraco-cms/backoffice/collection'; +import type { UmbDefaultCollectionContext } from '@umbraco-cms/backoffice/collection'; + +@customElement('umb-document-grid-collection-view') +export class UmbDocumentGridCollectionViewElement extends UmbLitElement { + @state() + private _items: Array = []; + + @state() + private _selection: Array = []; + + @state() + private _loading = false; + + #collectionContext?: UmbDefaultCollectionContext; + + constructor() { + super(); + + this.consumeContext(UMB_DEFAULT_COLLECTION_CONTEXT, (instance) => { + this.#collectionContext = instance; + this.observe( + this.#collectionContext.selection.selection, + (selection) => (this._selection = selection), + 'umbCollectionSelectionObserver', + ); + this.observe(this.#collectionContext.items, (items) => (this._items = items), 'umbCollectionItemsObserver'); + }); + } + + //TODO How should we handle url stuff? + private _handleOpenCard(id: string) { + //TODO this will not be needed when cards works as links with href + history.pushState(null, '', 'section/content/workspace/document/edit/' + id); + } + + #onSelect(item: UmbDocumentTreeItemModel) { + this.#collectionContext?.selection.select(item.unique ?? ''); + } + + #onDeselect(item: UmbDocumentTreeItemModel) { + this.#collectionContext?.selection.deselect(item.unique ?? ''); + } + + render() { + if (this._loading) nothing; + return html` +
+ ${repeat( + this._items, + (item) => item.unique, + (item) => this.#renderCard(item), + )} +
+ `; + } + + #renderCard(item: UmbDocumentTreeItemModel) { + return html` + 0} + ?selected=${this.#collectionContext?.selection.isSelected(item.unique ?? '')} + @open=${() => this._handleOpenCard(item.unique ?? '')} + @selected=${() => this.#onSelect(item)} + @deselected=${() => this.#onDeselect(item)}> + + + `; + } + + static styles = [ + UmbTextStyles, + css` + :host { + display: flex; + flex-direction: column; + } + + #document-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); + gap: var(--uui-size-space-4); + } + + uui-card-content-node { + width: 100%; + height: 180px; + } + `, + ]; +} + +export default UmbDocumentGridCollectionViewElement; + +declare global { + interface HTMLElementTagNameMap { + 'umb-document-grid-collection-view': UmbDocumentGridCollectionViewElement; + } +}