mock data and handlers
This commit is contained in:
@@ -1164,6 +1164,11 @@ class UmbDocumentTypeData extends UmbEntityData<DocumentTypeResponseModel> {
|
||||
const items = this.treeData.filter((item) => allowedTypeKeys.includes(item.id ?? ''));
|
||||
return items.map((item) => item);
|
||||
}
|
||||
|
||||
/** For internal use */
|
||||
getAll() {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
|
||||
export const umbDocumentTypeData = new UmbDocumentTypeData();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { umbDocumentTypeData } from './document-type.data.js';
|
||||
import { UmbEntityData } from './entity.data.js';
|
||||
import { createDocumentTreeItem } from './utils.js';
|
||||
import {
|
||||
@@ -5,6 +6,7 @@ import {
|
||||
DocumentResponseModel,
|
||||
DocumentTreeItemResponseModel,
|
||||
PagedDocumentTreeItemResponseModel,
|
||||
PagedDocumentTypeResponseModel,
|
||||
} from '@umbraco-cms/backoffice/backend-api';
|
||||
|
||||
export const data: Array<DocumentResponseModel> = [
|
||||
@@ -595,6 +597,26 @@ class UmbDocumentData extends UmbEntityData<DocumentResponseModel> {
|
||||
const items = this.treeData.filter((item) => ids.includes(item.id ?? ''));
|
||||
return items.map((item) => item);
|
||||
}
|
||||
|
||||
getDocumentByIdAllowedDocumentTypes(id: string): PagedDocumentTypeResponseModel {
|
||||
const item = this.getById(id);
|
||||
if (item?.contentTypeId) {
|
||||
const docType = umbDocumentTypeData.getById(item.contentTypeId);
|
||||
if (docType) {
|
||||
const items = docType.allowedContentTypes ?? [];
|
||||
const total = items?.length;
|
||||
return { items, total };
|
||||
}
|
||||
}
|
||||
return { items: [], total: 0 };
|
||||
}
|
||||
|
||||
getAllowedDocumentTypesAtRoot(): PagedDocumentTypeResponseModel {
|
||||
const items = umbDocumentTypeData.getAll(); //.filter((docType) => docType.allowedAsRoot);
|
||||
|
||||
const total = items?.length;
|
||||
return { items, total };
|
||||
}
|
||||
}
|
||||
|
||||
export const umbDocumentData = new UmbDocumentData();
|
||||
|
||||
@@ -61,4 +61,19 @@ export const handlers = [
|
||||
|
||||
return res(ctx.status(200), ctx.json(document));
|
||||
}),
|
||||
|
||||
rest.get(umbracoPath('/document/:id/allowed-document-types'), (req, res, ctx) => {
|
||||
const id = req.params.id as string;
|
||||
if (!id) return;
|
||||
|
||||
const response = umbDocumentData.getDocumentByIdAllowedDocumentTypes(id);
|
||||
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
|
||||
rest.get(umbracoPath('/document/root/allowed-document-types'), (req, res, ctx) => {
|
||||
const response = umbDocumentData.getAllowedDocumentTypesAtRoot();
|
||||
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
];
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { UmbDocumentTypeRepository } from '../../repository/document-type.repository.js';
|
||||
import { html, nothing, customElement, state, ifDefined } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { UUITextStyles } from '@umbraco-cms/backoffice/external/uui';
|
||||
import { UmbAllowedDocumentTypesModalData, UmbAllowedDocumentTypesModalResult } from '@umbraco-cms/backoffice/modal';
|
||||
import { UmbModalBaseElement } from '@umbraco-cms/internal/modal';
|
||||
import { DocumentTypeResponseModel, DocumentTypeTreeItemResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { DocumentTypeTreeItemResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { UmbDocumentRepository } from '@umbraco-cms/backoffice/document';
|
||||
|
||||
@customElement('umb-allowed-document-types-modal')
|
||||
export class UmbAllowedDocumentTypesModalElement extends UmbModalBaseElement<
|
||||
UmbAllowedDocumentTypesModalData,
|
||||
UmbAllowedDocumentTypesModalResult
|
||||
> {
|
||||
#documentTypeRepository = new UmbDocumentTypeRepository(this);
|
||||
#documentRepository = new UmbDocumentRepository(this);
|
||||
|
||||
@state()
|
||||
private _allowedDocumentTypes: DocumentTypeTreeItemResponseModel[] = [];
|
||||
@@ -39,34 +39,21 @@ export class UmbAllowedDocumentTypesModalElement extends UmbModalBaseElement<
|
||||
}
|
||||
|
||||
private async _retrieveAllowedChildrenOf(id: string) {
|
||||
const { data } = await this.#documentTypeRepository.requestAllowedChildTypesOf(id);
|
||||
const { data } = await this.#documentRepository.requestAllowedDocumentTypesOf(id);
|
||||
|
||||
if (data) {
|
||||
this._allowedDocumentTypes = data;
|
||||
// TODO: implement pagination, or get 1000?
|
||||
this._allowedDocumentTypes = data.items;
|
||||
}
|
||||
}
|
||||
|
||||
private async _retrieveAllowedChildrenOfRoot() {
|
||||
// TODO: This is a hack until we get the right end points (Which will become a Document end point. meaning this modal should have another name, it should be named so its clear that this is for documents, not document types. ex.: 'create-document-modal')
|
||||
const { data } = await this.#documentTypeRepository.requestRootTreeItems();
|
||||
if (!data) return;
|
||||
const { data } = await this.#documentRepository.requestAllowedDocumentTypesAtRoot();
|
||||
|
||||
const allFullModels: Array<DocumentTypeResponseModel> = [];
|
||||
await Promise.all(
|
||||
data.items.map((item) => {
|
||||
if (item.id) {
|
||||
return this.#documentTypeRepository.requestById(item.id).then((result) => {
|
||||
if (result.data) {
|
||||
allFullModels.push({ ...result.data });
|
||||
}
|
||||
});
|
||||
}
|
||||
return Promise.resolve();
|
||||
})
|
||||
);
|
||||
|
||||
this._allowedDocumentTypes = allFullModels.filter((item) => item.allowedAsRoot) ?? [];
|
||||
// End of hack...^^
|
||||
if (data) {
|
||||
// TODO: implement pagination, or get 1000?
|
||||
this._allowedDocumentTypes = data.items;
|
||||
}
|
||||
}
|
||||
|
||||
private _handleCancel() {
|
||||
|
||||
@@ -56,6 +56,7 @@ export class UmbDocumentRepository
|
||||
// TODO: Move
|
||||
|
||||
// TREE:
|
||||
|
||||
async requestTreeRoot() {
|
||||
await this.#init;
|
||||
|
||||
@@ -95,6 +96,17 @@ export class UmbDocumentRepository
|
||||
return { data, error, asObservable: () => this.#treeStore!.childrenOf(parentId) };
|
||||
}
|
||||
|
||||
// Structure permissions;
|
||||
|
||||
async requestAllowedDocumentTypesAtRoot() {
|
||||
return this.#detailDataSource.getAllowedDocumentTypesAtRoot();
|
||||
}
|
||||
async requestAllowedDocumentTypesOf(id: string) {
|
||||
if (!id) throw new Error('Id is missing');
|
||||
await this.#init;
|
||||
return this.#detailDataSource.getAllowedDocumentTypesOf(id);
|
||||
}
|
||||
|
||||
async requestItemsLegacy(ids: Array<string>) {
|
||||
await this.#init;
|
||||
|
||||
|
||||
@@ -168,4 +168,28 @@ export class UmbDocumentServerDataSource
|
||||
}).then((res) => res.json())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the allowed document types for a given parent id
|
||||
* @param {string} id
|
||||
* @return {*}
|
||||
* @memberof UmbDocumentTypeServerDataSource
|
||||
*/
|
||||
async getAllowedDocumentTypesOf(id: string) {
|
||||
if (!id) throw new Error('Id is missing');
|
||||
|
||||
return tryExecuteAndNotify(this.#host, DocumentResource.getDocumentByIdAllowedDocumentTypes({ id }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the allowed document types for root
|
||||
* @param {string} id
|
||||
* @return {*}
|
||||
* @memberof UmbDocumentTypeServerDataSource
|
||||
*/
|
||||
async getAllowedDocumentTypesAtRoot() {
|
||||
console.log('source requestAllowedDocumentTypesAtRoot');
|
||||
// Notice, here we need to implement pagination.
|
||||
return tryExecuteAndNotify(this.#host, DocumentResource.getDocumentRootAllowedDocumentTypes({ take: 4 }));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user