diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/manifests.ts index 1d9abbe1ee..c31c88b94d 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/manifests.ts @@ -1,5 +1,6 @@ import { UMB_PARTIAL_VIEW_ENTITY_TYPE } from '../entity.js'; import { UMB_PARTIAL_VIEW_DETAIL_REPOSITORY_ALIAS } from '../repository/index.js'; +import { UMB_PARTIAL_VIEW_ITEM_REPOSITORY_ALIAS } from '../repository/item/index.js'; import { manifests as createManifests } from './create/manifests.js'; import { manifests as renameManifests } from './rename/manifests.js'; import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry'; @@ -12,7 +13,7 @@ const partialViewActions: Array = [ kind: 'delete', meta: { detailRepositoryAlias: UMB_PARTIAL_VIEW_DETAIL_REPOSITORY_ALIAS, - itemRepositoryAlias: UMB_PARTIAL_VIEW_ITEM_REPOSITORY_ALIAS, // TODO: implement partial view item repo + itemRepositoryAlias: UMB_PARTIAL_VIEW_ITEM_REPOSITORY_ALIAS, entityTypes: [UMB_PARTIAL_VIEW_ENTITY_TYPE], }, }, diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/index.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/index.ts new file mode 100644 index 0000000000..d25f95a60a --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/index.ts @@ -0,0 +1,3 @@ +export { UmbPartialViewItemRepository } from './partial-view-item.repository.js'; +export { UMB_PARTIAL_VIEW_ITEM_REPOSITORY_ALIAS, UMB_PARTIAL_VIEW_ITEM_STORE_ALIAS } from './manifests.js'; +export { UMB_PARTIAL_VIEW_ITEM_STORE_CONTEXT } from './partial-view-item.store.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/manifests.ts new file mode 100644 index 0000000000..5440d488b0 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/manifests.ts @@ -0,0 +1,20 @@ +import type { ManifestRepository, ManifestItemStore } from '@umbraco-cms/backoffice/extension-registry'; + +export const UMB_PARTIAL_VIEW_ITEM_REPOSITORY_ALIAS = 'Umb.Repository.PartialView.Item'; +export const UMB_PARTIAL_VIEW_ITEM_STORE_ALIAS = 'Umb.ItemStore.PartialView'; + +const repository: ManifestRepository = { + type: 'repository', + alias: UMB_PARTIAL_VIEW_ITEM_REPOSITORY_ALIAS, + name: 'Partial View Item Repository', + api: () => import('./partial-view-item.repository.js'), +}; + +const itemStore: ManifestItemStore = { + type: 'itemStore', + alias: 'Umb.ItemStore.PartialView', + name: 'Partial View Item Store', + api: () => import('./partial-view-item.store.js'), +}; + +export const manifests = [repository, itemStore]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/partial-view-item.repository.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/partial-view-item.repository.ts new file mode 100644 index 0000000000..0779f52811 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/partial-view-item.repository.ts @@ -0,0 +1,13 @@ +import type { UmbPartialViewItemModel } from '../../types.js'; +import { UmbPartialViewItemServerDataSource } from './partial-view-item.server.data-source.js'; +import { UMB_PARTIAL_VIEW_ITEM_STORE_CONTEXT } from './partial-view-item.store.js'; +import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; +import { UmbItemRepositoryBase } from '@umbraco-cms/backoffice/repository'; + +export class UmbPartialViewItemRepository extends UmbItemRepositoryBase { + constructor(host: UmbControllerHost) { + super(host, UmbPartialViewItemServerDataSource, UMB_PARTIAL_VIEW_ITEM_STORE_CONTEXT); + } +} + +export default UmbPartialViewItemRepository; diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/partial-view-item.server.data-source.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/partial-view-item.server.data-source.ts new file mode 100644 index 0000000000..2d99226b93 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/partial-view-item.server.data-source.ts @@ -0,0 +1,68 @@ +import { UMB_PARTIAL_VIEW_ENTITY_TYPE, UMB_PARTIAL_VIEW_FOLDER_ENTITY_TYPE } from '../../entity.js'; +import type { UmbPartialViewItemModel } from '../../types.js'; +import { UmbServerFilePathUniqueSerializer } from '@umbraco-cms/backoffice/server-file-system'; +import type { UmbItemDataSource } from '@umbraco-cms/backoffice/repository'; +import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; +import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources'; +import { PartialViewResource } from '@umbraco-cms/backoffice/external/backend-api'; + +/** + * A data source for script items that fetches data from the server + * @export + * @class UmbPartialViewItemServerDataSource + * @implements {UmbItemDataSource} + */ +export class UmbPartialViewItemServerDataSource implements UmbItemDataSource { + #host: UmbControllerHost; + #serverFilePathUniqueSerializer = new UmbServerFilePathUniqueSerializer(); + + /** + * Creates an instance of UmbPartialViewItemServerDataSource. + * @param {UmbControllerHost} host + * @memberof UmbPartialViewItemServerDataSource + */ + constructor(host: UmbControllerHost) { + this.#host = host; + } + + /** + * Fetches the items for the given uniques from the server + * @param {Array} uniques + * @return {*} + * @memberof UmbPartialViewItemServerDataSource + */ + async getItems(uniques: Array) { + if (!uniques) throw new Error('Uniques are missing'); + + const paths = uniques + .map((unique) => { + const serverPath = this.#serverFilePathUniqueSerializer.toServerPath(unique); + return serverPath ? encodeURI(serverPath) : null; + }) + .filter((x) => x !== null) as string[]; + + const { data, error } = await tryExecuteAndNotify( + this.#host, + PartialViewResource.getItemPartialView({ + path: paths, + }), + ); + + if (data) { + const items: Array = data.map((item) => { + return { + entityType: item.isFolder ? UMB_PARTIAL_VIEW_FOLDER_ENTITY_TYPE : UMB_PARTIAL_VIEW_ENTITY_TYPE, + unique: this.#serverFilePathUniqueSerializer.toUnique(item.path), + parentUnique: item.parent ? this.#serverFilePathUniqueSerializer.toUnique(item.parent.path) : null, + name: item.name, + isFolder: item.isFolder, + path: item.path, + }; + }); + + return { data: items }; + } + + return { error }; + } +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/partial-view-item.store.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/partial-view-item.store.ts new file mode 100644 index 0000000000..6c5792e62e --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/item/partial-view-item.store.ts @@ -0,0 +1,28 @@ +import type { UmbPartialViewItemModel } from '../../types.js'; +import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; +import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; +import { UmbItemStoreBase } from '@umbraco-cms/backoffice/store'; + +/** + * @export + * @class UmbPartialViewItemStore + * @extends {UmbItemStoreBase} + * @description - Data Store for PartialView items + */ + +export class UmbPartialViewItemStore extends UmbItemStoreBase { + /** + * Creates an instance of UmbPartialViewItemStore. + * @param {UmbControllerHostElement} host + * @memberof UmbPartialViewItemStore + */ + constructor(host: UmbControllerHostElement) { + super(host, UMB_PARTIAL_VIEW_ITEM_STORE_CONTEXT.toString()); + } +} + +export default UmbPartialViewItemStore; + +export const UMB_PARTIAL_VIEW_ITEM_STORE_CONTEXT = new UmbContextToken( + 'UmbPartialViewItemStore', +); diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/manifests.ts index 545fa91468..60a9c1fe24 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/manifests.ts @@ -1,3 +1,4 @@ +import { manifests as itemManifests } from './item/manifests.js'; import type { ManifestRepository, ManifestStore } from '@umbraco-cms/backoffice/extension-registry'; export const UMB_PARTIAL_VIEW_DETAIL_REPOSITORY_ALIAS = 'Umb.Repository.PartialView.Detail'; @@ -17,4 +18,4 @@ const store: ManifestStore = { api: () => import('./partial-view-detail.store.js'), }; -export const manifests = [repository, store]; +export const manifests = [repository, store, ...itemManifests]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/types.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/types.ts index 27d428a73c..a67e7730c7 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/types.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/types.ts @@ -1,4 +1,4 @@ -import type { UmbPartialViewEntityType } from './entity.js'; +import type { UmbPartialViewEntityType, UmbPartialViewFolderEntityType } from './entity.js'; export interface UmbPartialViewDetailModel { entityType: UmbPartialViewEntityType; @@ -8,3 +8,11 @@ export interface UmbPartialViewDetailModel { name: string; content: string; } + +export interface UmbPartialViewItemModel { + entityType: UmbPartialViewEntityType | UmbPartialViewFolderEntityType; + unique: string; + parentUnique: string | null; + path: string; + name: string; +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/rename/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/rename/manifests.ts index 50185cfa3e..df761b261a 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/rename/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/rename/manifests.ts @@ -1,4 +1,5 @@ import { UMB_SCRIPT_ENTITY_TYPE } from '../../entity.js'; +import { UMB_SCRIPT_ITEM_REPOSITORY_ALIAS } from '../../repository/item/index.js'; import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry'; export const UMB_RENAME_SCRIPT_REPOSITORY_ALIAS = 'Umb.Repository.Script.Rename';