split stylesheet handlers
This commit is contained in:
@@ -28,7 +28,7 @@ import { handlers as logViewerHandlers } from './handlers/log-viewer.handlers.js
|
||||
import { handlers as packageHandlers } from './handlers/package.handlers.js';
|
||||
import { handlers as rteEmbedHandlers } from './handlers/rte-embed.handlers.js';
|
||||
import { handlers as staticFileHandlers } from './handlers/static-file.handlers.js';
|
||||
import { handlers as stylesheetHandlers } from './handlers/stylesheet.handlers.js';
|
||||
import { handlers as stylesheetHandlers } from './handlers/stylesheet/index.js';
|
||||
import { handlers as partialViewsHandlers } from './handlers/partial-views.handlers.js';
|
||||
import { handlers as tagHandlers } from './handlers/tag-handlers.js';
|
||||
import { handlers as configHandlers } from './handlers/config.handlers.js';
|
||||
|
||||
@@ -37,8 +37,24 @@ export class UmbMockFileSystemDetailManager<MockItemType extends ScriptResponseM
|
||||
return mappedItem;
|
||||
}
|
||||
|
||||
update(item: UpdateTextFileViewModelBaseModel) {
|
||||
const mockItem = this.#db.read(item.existingPath);
|
||||
update(path: string, item: UpdateTextFileViewModelBaseModel) {
|
||||
const mockItem = this.#db.read(path);
|
||||
|
||||
const updatedMockItem = {
|
||||
...mockItem,
|
||||
content: item.content,
|
||||
} as MockItemType;
|
||||
|
||||
this.#db.update(path, updatedMockItem);
|
||||
}
|
||||
|
||||
delete(path: string) {
|
||||
this.#db.delete(path);
|
||||
}
|
||||
|
||||
/* TODO: implement as rename
|
||||
update(path, item: UpdateTextFileViewModelBaseModel) {
|
||||
const mockItem = this.#db.read(path);
|
||||
|
||||
const parentPath = getParentPathFromServerPath(item.existingPath);
|
||||
const newPath = parentPath ? parentPath + '/' + item.name : item.name;
|
||||
@@ -52,8 +68,5 @@ export class UmbMockFileSystemDetailManager<MockItemType extends ScriptResponseM
|
||||
|
||||
this.#db.update(item.existingPath, updatedMockItem);
|
||||
}
|
||||
|
||||
delete(path: string) {
|
||||
this.#db.delete(path);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class UmbScriptMockDB extends UmbFileSystemMockDbBase<UmbMockScriptModel> {
|
||||
return {
|
||||
name: item.name,
|
||||
path: item.path,
|
||||
parentPath: item.parentPath,
|
||||
parentPath: item.parentPath,
|
||||
content: item.content,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
const { rest } = window.MockServiceWorker;
|
||||
import { umbStylesheetData } from '../data/stylesheet/stylesheet.db.js';
|
||||
import {
|
||||
CreatePathFolderRequestModel,
|
||||
CreateStylesheetRequestModel,
|
||||
UpdateStylesheetRequestModel,
|
||||
} from '@umbraco-cms/backoffice/backend-api';
|
||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||
|
||||
const treeHandlers = [
|
||||
rest.get(umbracoPath('/tree/stylesheet/root'), (req, res, ctx) => {
|
||||
const response = umbStylesheetData.tree.getRoot();
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
|
||||
rest.get(umbracoPath('/tree/stylesheet/children'), (req, res, ctx) => {
|
||||
const path = req.url.searchParams.get('path');
|
||||
if (!path) return res(ctx.status(400));
|
||||
const response = umbStylesheetData.tree.getChildrenOf(path);
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
];
|
||||
|
||||
const detailHandlers = [
|
||||
rest.get(umbracoPath('/stylesheet'), (req, res, ctx) => {
|
||||
const path = req.url.searchParams.get('path');
|
||||
if (!path) return res(ctx.status(400));
|
||||
const response = umbStylesheetData.file.read(path);
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
|
||||
rest.post(umbracoPath('/stylesheet'), async (req, res, ctx) => {
|
||||
const requestBody = (await req.json()) as CreateStylesheetRequestModel;
|
||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||
const path = umbStylesheetData.file.create(requestBody);
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.set({
|
||||
Location: path,
|
||||
}),
|
||||
);
|
||||
}),
|
||||
|
||||
rest.delete(umbracoPath('/stylesheet'), (req, res, ctx) => {
|
||||
const path = req.url.searchParams.get('path');
|
||||
if (!path) return res(ctx.status(400));
|
||||
umbStylesheetData.file.delete(path);
|
||||
return res(ctx.status(200));
|
||||
}),
|
||||
|
||||
rest.put(umbracoPath('/stylesheet'), async (req, res, ctx) => {
|
||||
const requestBody = (await req.json()) as UpdateStylesheetRequestModel;
|
||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||
umbStylesheetData.file.update(requestBody);
|
||||
return res(ctx.status(200));
|
||||
}),
|
||||
];
|
||||
|
||||
const itemHandlers = [
|
||||
rest.get(umbracoPath('/stylesheet/item'), (req, res, ctx) => {
|
||||
const paths = req.url.searchParams.getAll('paths');
|
||||
if (!paths) return res(ctx.status(400, 'no body found'));
|
||||
const items = umbStylesheetData.item.getItems(paths);
|
||||
return res(ctx.status(200), ctx.json(items));
|
||||
}),
|
||||
];
|
||||
|
||||
const collectionHandlers = [
|
||||
rest.get(umbracoPath('/stylesheet/all'), (req, res, ctx) => {
|
||||
const path = req.url.searchParams.get('path');
|
||||
if (!path) return;
|
||||
const response = umbStylesheetData.getAllStylesheets();
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
];
|
||||
|
||||
const folderHandlers = [
|
||||
rest.get(umbracoPath('/stylesheet/folder'), (req, res, ctx) => {
|
||||
const path = req.url.searchParams.get('path');
|
||||
if (!path) return res(ctx.status(400));
|
||||
const response = umbStylesheetData.folder.read(path);
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
|
||||
rest.post(umbracoPath('/stylesheet/folder'), async (req, res, ctx) => {
|
||||
const requestBody = (await req.json()) as CreatePathFolderRequestModel;
|
||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||
umbStylesheetData.folder.create(requestBody);
|
||||
return res(ctx.status(200));
|
||||
}),
|
||||
|
||||
rest.delete(umbracoPath('/stylesheet/folder'), (req, res, ctx) => {
|
||||
const path = req.url.searchParams.get('path');
|
||||
if (!path) return res(ctx.status(400));
|
||||
umbStylesheetData.folder.delete(path);
|
||||
return res(ctx.status(200));
|
||||
}),
|
||||
];
|
||||
|
||||
export const handlers = [...treeHandlers, ...detailHandlers, ...itemHandlers, ...collectionHandlers, ...folderHandlers];
|
||||
@@ -0,0 +1,42 @@
|
||||
const { rest } = window.MockServiceWorker;
|
||||
import { umbStylesheetData } from '../../data/stylesheet/stylesheet.db.js';
|
||||
import { UMB_SLUG } from './slug.js';
|
||||
import { CreateStylesheetRequestModel, UpdateStylesheetRequestModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||
|
||||
export const detailHandlers = [
|
||||
rest.post(umbracoPath(UMB_SLUG), async (req, res, ctx) => {
|
||||
const requestBody = (await req.json()) as CreateStylesheetRequestModel;
|
||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||
const path = umbStylesheetData.file.create(requestBody);
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.set({
|
||||
Location: path,
|
||||
}),
|
||||
);
|
||||
}),
|
||||
|
||||
rest.get(umbracoPath(`${UMB_SLUG}/:path`), (req, res, ctx) => {
|
||||
const path = req.params.path as string;
|
||||
if (!path) return res(ctx.status(400));
|
||||
const response = umbStylesheetData.file.read(path);
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
|
||||
rest.delete(umbracoPath(`${UMB_SLUG}/:path`), (req, res, ctx) => {
|
||||
const path = req.params.path as string;
|
||||
if (!path) return res(ctx.status(400));
|
||||
umbStylesheetData.file.delete(path);
|
||||
return res(ctx.status(200));
|
||||
}),
|
||||
|
||||
rest.put(umbracoPath(`${UMB_SLUG}/:path`), async (req, res, ctx) => {
|
||||
const path = req.params.path as string;
|
||||
if (!path) return res(ctx.status(400));
|
||||
const requestBody = (await req.json()) as UpdateStylesheetRequestModel;
|
||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||
umbStylesheetData.file.update(path, requestBody);
|
||||
return res(ctx.status(200));
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1,28 @@
|
||||
const { rest } = window.MockServiceWorker;
|
||||
import { umbStylesheetData } from '../../data/stylesheet/stylesheet.db.js';
|
||||
import { UMB_SLUG } from './slug.js';
|
||||
import { CreatePathFolderRequestModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||
|
||||
export const folderHandlers = [
|
||||
rest.get(umbracoPath(`${UMB_SLUG}/folder`), (req, res, ctx) => {
|
||||
const path = req.url.searchParams.get('path');
|
||||
if (!path) return res(ctx.status(400));
|
||||
const response = umbStylesheetData.folder.read(path);
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
|
||||
rest.post(umbracoPath(`${UMB_SLUG}/folder`), async (req, res, ctx) => {
|
||||
const requestBody = (await req.json()) as CreatePathFolderRequestModel;
|
||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||
umbStylesheetData.folder.create(requestBody);
|
||||
return res(ctx.status(200));
|
||||
}),
|
||||
|
||||
rest.delete(umbracoPath(`${UMB_SLUG}/folder`), (req, res, ctx) => {
|
||||
const path = req.url.searchParams.get('path');
|
||||
if (!path) return res(ctx.status(400));
|
||||
umbStylesheetData.folder.delete(path);
|
||||
return res(ctx.status(200));
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1,7 @@
|
||||
import { folderHandlers } from './folder.handlers.js';
|
||||
import { treeHandlers } from './tree.handlers.js';
|
||||
import { detailHandlers } from './detail.handlers.js';
|
||||
import { itemHandlers } from './item.handlers.js';
|
||||
import { overviewHandlers } from './overview.handlers.js';
|
||||
|
||||
export const handlers = [...treeHandlers, ...itemHandlers, ...folderHandlers, ...overviewHandlers, ...detailHandlers];
|
||||
@@ -0,0 +1,12 @@
|
||||
const { rest } = window.MockServiceWorker;
|
||||
import { umbStylesheetData } from '../../data/stylesheet/stylesheet.db.js';
|
||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||
|
||||
export const itemHandlers = [
|
||||
rest.get(umbracoPath('/stylesheet/item'), (req, res, ctx) => {
|
||||
const paths = req.url.searchParams.getAll('paths');
|
||||
if (!paths) return res(ctx.status(400, 'no body found'));
|
||||
const items = umbStylesheetData.item.getItems(paths);
|
||||
return res(ctx.status(200), ctx.json(items));
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1,13 @@
|
||||
const { rest } = window.MockServiceWorker;
|
||||
import { umbStylesheetData } from '../../data/stylesheet/stylesheet.db.js';
|
||||
import { UMB_SLUG } from './slug.js';
|
||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||
|
||||
export const overviewHandlers = [
|
||||
rest.get(umbracoPath(`${UMB_SLUG}/overview`), (req, res, ctx) => {
|
||||
const path = req.url.searchParams.get('path');
|
||||
if (!path) return;
|
||||
const response = umbStylesheetData.getAllStylesheets();
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
];
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_SLUG = '/stylesheet';
|
||||
@@ -0,0 +1,18 @@
|
||||
const { rest } = window.MockServiceWorker;
|
||||
import { umbStylesheetData } from '../../data/stylesheet/stylesheet.db.js';
|
||||
import { UMB_SLUG } from './slug.js';
|
||||
import { umbracoPath } from '@umbraco-cms/backoffice/utils';
|
||||
|
||||
export const treeHandlers = [
|
||||
rest.get(umbracoPath(`/tree${UMB_SLUG}/root`), (req, res, ctx) => {
|
||||
const response = umbStylesheetData.tree.getRoot();
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
|
||||
rest.get(umbracoPath(`/tree${UMB_SLUG}/children`), (req, res, ctx) => {
|
||||
const path = req.url.searchParams.get('path');
|
||||
if (!path) return res(ctx.status(400));
|
||||
const response = umbStylesheetData.tree.getChildrenOf(path);
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
}),
|
||||
];
|
||||
@@ -10,7 +10,7 @@ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbDetailDataSource } from '@umbraco-cms/backoffice/repository';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
|
||||
export class UmbStylesheetDetailServerDataSource implements UmbDetailDataSource<UmbScriptDetailModel> {
|
||||
export class UmbStylesheetDetailServerDataSource implements UmbDetailDataSource<UmbStylesheetDetailModel> {
|
||||
#host: UmbControllerHost;
|
||||
#serverPathUniqueSerializer = new UmbServerPathUniqueSerializer();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user