From cd33b48b0956681f6478f2f94cb12671fc8d4486 Mon Sep 17 00:00:00 2001 From: Julia Gru <56249914+julczka@users.noreply.github.com> Date: Tue, 18 Jul 2023 13:42:49 +0200 Subject: [PATCH] update server data source --- .../partial-views.detail.server.data.ts | 66 ++++++++++++++----- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/sources/partial-views.detail.server.data.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/sources/partial-views.detail.server.data.ts index 19f9f52d09..9741d34bc9 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/sources/partial-views.detail.server.data.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/repository/sources/partial-views.detail.server.data.ts @@ -1,10 +1,23 @@ import { PartialViewDetails } from '../../config.js'; +import { + CreatePartialViewRequestModel, + PartialViewResource, + PartialViewResponseModel, + UpdatePartialViewRequestModel, +} from '@umbraco-cms/backoffice/backend-api'; import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; import { DataSourceResponse, UmbDataSource } from '@umbraco-cms/backoffice/repository'; +import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources'; -//TODO Pass proper models export class UmbPartialViewDetailServerDataSource - implements UmbDataSource + implements + UmbDataSource< + CreatePartialViewRequestModel, + string, + UpdatePartialViewRequestModel, + PartialViewResponseModel, + string + > { #host: UmbControllerHostElement; @@ -17,29 +30,52 @@ export class UmbPartialViewDetailServerDataSource this.#host = host; } - createScaffold(parentKey: string | null): Promise> { - throw new Error('Method not implemented.'); + //TODO check if this is correct + createScaffold(parentid: string | null = null, preset: string): Promise> { + return tryExecuteAndNotify(this.#host, PartialViewResource.getPartialViewSnippetByName({ name: preset })); } /** - * Fetches a Stylesheet with the given path from the server + * Fetches a partial view with the given path from the server * @param {string} path * @return {*} * @memberof UmbStylesheetServerDataSource */ - async get(path: string) { + get(path: string) { if (!path) throw new Error('Path is missing'); - console.log('GET PATRIAL WITH PATH', path); - return { data: undefined, error: undefined }; + return tryExecuteAndNotify(this.#host, PartialViewResource.getPartialView({ path })); + } + /** + * Creates a new partial view + * + * @param {CreatePartialViewRequestModel} requestBody + * @return {*} {Promise>} + * @memberof UmbPartialViewDetailServerDataSource + */ + insert(requestBody: CreatePartialViewRequestModel): Promise> { + return tryExecuteAndNotify(this.#host, PartialViewResource.postPartialViewFolder({ requestBody })); } - insert(data: any): Promise> { - throw new Error('Method not implemented.'); + //TODO the parameters here are bit ugly, since unique is already in the request body parameter, but it has to be done to marry the UmbDataSource interface an backend API together... maybe come up with some nicer solution + /** + * Updates a partial view + * + * @param {string} [unique=''] + * @param {UpdatePartialViewRequestModel} requestBody + * @return {*} {Promise>} + * @memberof UmbPartialViewDetailServerDataSource + */ + update(unique = '', requestBody: UpdatePartialViewRequestModel): Promise> { + return tryExecuteAndNotify(this.#host, PartialViewResource.putPartialView({ requestBody })); } - update(unique: string, data: PartialViewDetails): Promise> { - throw new Error('Method not implemented.'); - } - delete(unique: string): Promise { - throw new Error('Method not implemented.'); + /** + * Deletes a partial view + * + * @param {string} path + * @return {*} {Promise} + * @memberof UmbPartialViewDetailServerDataSource + */ + delete(path: string): Promise { + return tryExecuteAndNotify(this.#host, PartialViewResource.deletePartialView({ path })); } }