Merge branch 'feature/entity-action-kind' of https://github.com/umbraco/Umbraco.CMS.Backoffice into feature/entity-action-kind
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { UMB_SCRIPT_DETAIL_REPOSITORY_ALIAS } from '../repository/index.js';
|
||||
import { UMB_SCRIPT_ENTITY_TYPE } from '../entity.js';
|
||||
import { UMB_SCRIPT_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';
|
||||
@@ -14,7 +15,7 @@ const scriptViewActions: Array<ManifestTypes> = [
|
||||
kind: 'delete',
|
||||
meta: {
|
||||
detailRepositoryAlias: UMB_SCRIPT_DETAIL_REPOSITORY_ALIAS,
|
||||
itemRepositoryAlias: UMB_SCRIPT_DETAIL_ITEM_REPOSITORY_ALIAS, // TODO: implement item repo
|
||||
itemRepositoryAlias: UMB_SCRIPT_ITEM_REPOSITORY_ALIAS,
|
||||
entityTypes: [UMB_SCRIPT_ENTITY_TYPE],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export { UmbScriptItemRepository } from './script-item.repository.js';
|
||||
export { UMB_SCRIPT_ITEM_REPOSITORY_ALIAS, UMB_SCRIPT_ITEM_STORE_ALIAS } from './manifests.js';
|
||||
export { UMB_SCRIPT_ITEM_STORE_CONTEXT } from './script-item.store.js';
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { ManifestRepository, ManifestItemStore } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const UMB_SCRIPT_ITEM_REPOSITORY_ALIAS = 'Umb.Repository.Script.Item';
|
||||
export const UMB_SCRIPT_ITEM_STORE_ALIAS = 'Umb.ItemStore.Script';
|
||||
|
||||
const repository: ManifestRepository = {
|
||||
type: 'repository',
|
||||
alias: UMB_SCRIPT_ITEM_REPOSITORY_ALIAS,
|
||||
name: 'Script Item Repository',
|
||||
api: () => import('./script-item.repository.js'),
|
||||
};
|
||||
|
||||
const itemStore: ManifestItemStore = {
|
||||
type: 'itemStore',
|
||||
alias: 'Umb.ItemStore.Script',
|
||||
name: 'Script Item Store',
|
||||
api: () => import('./script-item.store.js'),
|
||||
};
|
||||
|
||||
export const manifests = [repository, itemStore];
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { UmbScriptItemModel } from '../../types.js';
|
||||
import { UmbScriptItemServerDataSource } from './script-item.server.data-source.js';
|
||||
import { UMB_SCRIPT_ITEM_STORE_CONTEXT } from './script-item.store.js';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbItemRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export class UmbScriptItemRepository extends UmbItemRepositoryBase<UmbScriptItemModel> {
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host, UmbScriptItemServerDataSource, UMB_SCRIPT_ITEM_STORE_CONTEXT);
|
||||
}
|
||||
}
|
||||
|
||||
export default UmbScriptItemRepository;
|
||||
@@ -0,0 +1,68 @@
|
||||
import { UMB_SCRIPT_ENTITY_TYPE, UMB_SCRIPT_FOLDER_ENTITY_TYPE } from '../../entity.js';
|
||||
import type { UmbScriptItemModel } 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 { ScriptResource } from '@umbraco-cms/backoffice/external/backend-api';
|
||||
|
||||
/**
|
||||
* A data source for script items that fetches data from the server
|
||||
* @export
|
||||
* @class UmbScriptItemServerDataSource
|
||||
* @implements {UmbItemDataSource}
|
||||
*/
|
||||
export class UmbScriptItemServerDataSource implements UmbItemDataSource<UmbScriptItemModel> {
|
||||
#host: UmbControllerHost;
|
||||
#serverFilePathUniqueSerializer = new UmbServerFilePathUniqueSerializer();
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbScriptItemServerDataSource.
|
||||
* @param {UmbControllerHost} host
|
||||
* @memberof UmbScriptItemServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHost) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the items for the given uniques from the server
|
||||
* @param {Array<string>} uniques
|
||||
* @return {*}
|
||||
* @memberof UmbScriptItemServerDataSource
|
||||
*/
|
||||
async getItems(uniques: Array<string>) {
|
||||
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,
|
||||
ScriptResource.getItemScript({
|
||||
path: paths,
|
||||
}),
|
||||
);
|
||||
|
||||
if (data) {
|
||||
const items: Array<UmbScriptItemModel> = data.map((item) => {
|
||||
return {
|
||||
entityType: item.isFolder ? UMB_SCRIPT_FOLDER_ENTITY_TYPE : UMB_SCRIPT_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 };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import type { UmbScriptItemModel } 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 UmbScriptItemStore
|
||||
* @extends {UmbItemStoreBase}
|
||||
* @description - Data Store for Script items
|
||||
*/
|
||||
|
||||
export class UmbScriptItemStore extends UmbItemStoreBase<UmbScriptItemModel> {
|
||||
/**
|
||||
* Creates an instance of UmbScriptItemStore.
|
||||
* @param {UmbControllerHostElement} host
|
||||
* @memberof UmbScriptItemStore
|
||||
*/
|
||||
constructor(host: UmbControllerHostElement) {
|
||||
super(host, UMB_SCRIPT_ITEM_STORE_CONTEXT.toString());
|
||||
}
|
||||
}
|
||||
|
||||
export default UmbScriptItemStore;
|
||||
|
||||
export const UMB_SCRIPT_ITEM_STORE_CONTEXT = new UmbContextToken<UmbScriptItemStore>('UmbScriptItemStore');
|
||||
@@ -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_SCRIPT_DETAIL_REPOSITORY_ALIAS = 'Umb.Repository.Script.Detail';
|
||||
@@ -17,4 +18,4 @@ const store: ManifestStore = {
|
||||
api: () => import('./script-detail.store.js'),
|
||||
};
|
||||
|
||||
export const manifests = [repository, store];
|
||||
export const manifests = [repository, store, ...itemManifests];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { UmbScriptEntityType } from './entity.js';
|
||||
import type { UmbScriptEntityType, UmbScriptFolderEntityType } from './entity.js';
|
||||
|
||||
export interface UmbScriptDetailModel {
|
||||
entityType: UmbScriptEntityType;
|
||||
@@ -8,3 +8,12 @@ export interface UmbScriptDetailModel {
|
||||
name: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface UmbScriptItemModel {
|
||||
entityType: UmbScriptEntityType | UmbScriptFolderEntityType;
|
||||
unique: string;
|
||||
parentUnique: string | null;
|
||||
path: string;
|
||||
name: string;
|
||||
isFolder: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user