From 8de62e30f6489c22237a46ed2ef2ac2c3c0ee82b Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Wed, 22 Dec 2021 15:41:11 +0100 Subject: [PATCH] integration stuff --- .../Integrations/IntegrationsController.cs | 147 ++++++++++++++- .../Integrations/_IntegrationsController.cs | 43 ----- zero.Backoffice.UI/app/components/index.ts | 10 +- zero.Backoffice.UI/app/core/zeroRuntime.ts | 4 +- .../editor/blueprint/property.vue | 2 +- .../editor/blueprint/settings.vue | 2 +- zero.Backoffice.UI/app/editor/compile.ts | 7 +- .../app/editor/legacy/blueprint/property.vue | 2 +- zero.Backoffice.UI/app/editor/plugin.ts | 12 ++ zero.Backoffice.UI/app/editor/register.ts | 9 + .../editor/ui-editor-component.vue | 4 +- .../editor/ui-editor-header.vue | 0 .../editor/ui-editor-infos.vue | 0 .../editor/ui-editor-overlay.vue | 0 .../{components => }/editor/ui-editor.scss | 0 .../app/{components => }/editor/ui-editor.vue | 16 +- .../app/modules/integrations/api.ts | 20 ++- .../app/modules/integrations/integration.vue | 94 ++++++++-- .../integrations/integrations-item.vue | 53 +++--- .../Resources/Localization/zero.en-us.json | 4 +- .../Configuration/ConfigurationModule.cs | 1 + .../Configuration/Integrations/Integration.cs | 6 +- .../Integrations/IntegrationOptions.cs | 9 +- .../Integrations/IntegrationService.cs | 14 -- .../Integrations/IntegrationStore.cs | 170 ++++++++++++++++++ .../Integrations/IntegrationType.cs | 2 +- .../Integrations/IntegrationTypeService.cs | 4 +- zero.Core/Stores/StoreOperations.Read.cs | 8 + zero.Core/Stores/StoreOperations.cs | 5 + zero.Core/Utils/JsonFlavorVariantConverter.cs | 54 ++++++ zero.Demo/FathomAnalyticsIntegration.cs | 2 +- zero.Demo/GoogleAnalyticsIntegration.cs | 2 +- zero.Demo/SetupController.cs | 16 ++ 33 files changed, 587 insertions(+), 135 deletions(-) delete mode 100644 zero.Api/Endpoints/Integrations/_IntegrationsController.cs rename zero.Backoffice.UI/app/{components => }/editor/blueprint/property.vue (99%) rename zero.Backoffice.UI/app/{components => }/editor/blueprint/settings.vue (99%) create mode 100644 zero.Backoffice.UI/app/editor/register.ts rename zero.Backoffice.UI/app/{components => }/editor/ui-editor-component.vue (97%) rename zero.Backoffice.UI/app/{components => }/editor/ui-editor-header.vue (100%) rename zero.Backoffice.UI/app/{components => }/editor/ui-editor-infos.vue (100%) rename zero.Backoffice.UI/app/{components => }/editor/ui-editor-overlay.vue (100%) rename zero.Backoffice.UI/app/{components => }/editor/ui-editor.scss (100%) rename zero.Backoffice.UI/app/{components => }/editor/ui-editor.vue (85%) delete mode 100644 zero.Core/Configuration/Integrations/IntegrationService.cs create mode 100644 zero.Core/Configuration/Integrations/IntegrationStore.cs create mode 100644 zero.Core/Utils/JsonFlavorVariantConverter.cs diff --git a/zero.Api/Endpoints/Integrations/IntegrationsController.cs b/zero.Api/Endpoints/Integrations/IntegrationsController.cs index cc86de71..3a90ce42 100644 --- a/zero.Api/Endpoints/Integrations/IntegrationsController.cs +++ b/zero.Api/Endpoints/Integrations/IntegrationsController.cs @@ -1,31 +1,172 @@ using Microsoft.AspNetCore.Mvc; using System.Collections; +using zero.Mapper; namespace zero.Api.Endpoints.Integrations; public class IntegrationsController : ZeroApiController { readonly IIntegrationTypeService IntegrationTypes; + readonly IIntegrationStore Store; - public IntegrationsController(IIntegrationTypeService integrationTypes) + public IntegrationsController(IIntegrationTypeService integrationTypes, IIntegrationStore store) { IntegrationTypes = integrationTypes; + Store = store; } + [HttpGet("types")] //[ZeroAuthorize(SpacePermissions.Read)] - public virtual ActionResult GetTypes() + public virtual async Task> GetTypes() { IEnumerable result = Mapper.Map(IntegrationTypes.GetAll()); + + foreach (IntegrationTypeDisplay display in result) + { + Integration model = await Store.Load(display.Alias); + + if (model != null) + { + display.IsConfigured = true; + display.IsActivated = model.IsActive; + display.ModelId = model.Id; + } + } + return Ok(result); } + [HttpGet("types/{alias}")] //[ZeroAuthorize(SpacePermissions.Read)] - public virtual ActionResult GetTypes(string alias) + public virtual async Task> GetType(string alias) { IntegrationTypeDisplay result = Mapper.Map(IntegrationTypes.GetByAlias(alias)); + + if (result == null) + { + return NotFound(); + } + + Integration model = await Store.Load(result.Alias); + + if (model != null) + { + result.IsConfigured = true; + result.IsActivated = model.IsActive; + result.ModelId = model.Id; + } + return Ok(result); } + + + [HttpGet("empty/{alias}")] + //[ZeroAuthorize(CountryPermissions.Create)] + public virtual async Task> Empty(string alias) + { + Integration model = await Store.Empty(alias); + + if (model == null) + { + return NotFound(); + } + + return model; + } + + + [HttpGet("{alias}")] + //[ZeroAuthorize(CountryPermissions.Read)] + public virtual async Task> Get(string alias) + { + Integration model = await Store.Load(alias); + + if (model == null) + { + return NotFound(); + } + + HttpContext.Items[ApiConstants.ChangeToken] = Store.GetChangeToken(model); + + return model; + } + + + [HttpPost("")] + //[ZeroAuthorize(CountryPermissions.Create)] + public virtual async Task> Create(Integration saveModel) + { + Result result = await Store.Create(saveModel); + + bool minimalResponse = Hints.ResponsePreference == ApiResponsePreference.Minimal; + + if (result.IsSuccess) + { + return Created("/", minimalResponse ? null : saveModel); + } + + return result.WithoutModel(); + } + + + [HttpPut("{alias}")] + //[ZeroAuthorize(CountryPermissions.Update)] + public virtual async Task> Update(string alias, Integration updateModel, [FromQuery] string changeToken = null) + { + if (alias != updateModel.TypeAlias) + { + return BadRequest(Result.Fail(nameof(alias), "@integration.errors.noaliasmatch")); + } + + Result result = await Store.Update(updateModel); + + if (Hints.ResponsePreference == ApiResponsePreference.Minimal) + { + return result.WithoutModel(); + } + + return result; + } + + + [HttpPut("{alias}/activate")] + //[ZeroAuthorize(CountryPermissions.Update)] + public virtual async Task> Activate(string alias) + { + Result result = await Store.Activate(alias); + + if (Hints.ResponsePreference == ApiResponsePreference.Minimal) + { + return result.WithoutModel(); + } + + return result; + } + + + [HttpPut("{alias}/deactivate")] + //[ZeroAuthorize(CountryPermissions.Update)] + public virtual async Task> Deactivate(string alias) + { + Result result = await Store.Deactivate(alias); + + if (Hints.ResponsePreference == ApiResponsePreference.Minimal) + { + return result.WithoutModel(); + } + + return result; + } + + + [HttpDelete("{alias}")] + //[ZeroAuthorize(CountryPermissions.Delete)] + public virtual async Task> Delete(string alias) + { + Result result = await Store.Delete(alias); + return result.WithoutModel(); + } } \ No newline at end of file diff --git a/zero.Api/Endpoints/Integrations/_IntegrationsController.cs b/zero.Api/Endpoints/Integrations/_IntegrationsController.cs deleted file mode 100644 index ad84a171..00000000 --- a/zero.Api/Endpoints/Integrations/_IntegrationsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -//using Microsoft.AspNetCore.Mvc; -//using System.Collections.Generic; -//using System.Threading.Tasks; -//using zero.Core.Collections; -//using zero.Core.Entities; -//using zero.Core.Integrations; -//using zero.Web.Models; - -//namespace zero.Web.Controllers -//{ -// //[ZeroAuthorize(Permissions.Sections.PREFIX + "commerce", PermissionsValue.Read)] -// public class IntegrationsController : BackofficeController -// { -// IIntegrationsCollection Collection; - -// public IntegrationsController(IIntegrationsCollection collection) -// { -// Collection = collection; -// } - - -// public EditModel GetEmpty([FromQuery] string alias) => Edit(Collection.GetEmpty(alias)); - - -// public async Task> GetByAlias([FromQuery] string alias) => Edit(await Collection.GetByAlias(alias)); - - -// public async Task> Load([FromQuery] ListQuery query) => await Collection.Load(query); - - -// public async Task> GetTypes() => await Collection.GetTypesWithStatus(); - - -// [HttpPost] -// public async Task> Save([FromBody] Integration model) => await Collection.Save(model); - -// [HttpPost] -// public async Task> SaveActiveState([FromBody] Integration model) => model.IsActive ? await Collection.Activate(model.Alias) : await Collection.Deactivate(model.Alias); - -// [HttpDelete] -// public async Task> Delete([FromQuery] string alias) => await Collection.DeleteByAlias(alias); -// } -//} \ No newline at end of file diff --git a/zero.Backoffice.UI/app/components/index.ts b/zero.Backoffice.UI/app/components/index.ts index 280de843..4d6bb3a5 100644 --- a/zero.Backoffice.UI/app/components/index.ts +++ b/zero.Backoffice.UI/app/components/index.ts @@ -28,10 +28,6 @@ import uiDatagrid from './ui-datagrid.vue'; import uiProgress from './ui-progress.vue'; import uiDate from './ui-date.vue'; -import uiEditor from './editor/ui-editor.vue'; -import uiEditorInfos from './editor/ui-editor-infos.vue'; -import uiEditorHeader from './editor/ui-editor-header.vue'; - export { uiIcon, uiLoading, @@ -61,9 +57,5 @@ export { uiPick, uiDatagrid, uiProgress, - uiDate, - - uiEditor, - uiEditorInfos, - uiEditorHeader + uiDate }; \ No newline at end of file diff --git a/zero.Backoffice.UI/app/core/zeroRuntime.ts b/zero.Backoffice.UI/app/core/zeroRuntime.ts index 401bbfb4..0b444c49 100644 --- a/zero.Backoffice.UI/app/core/zeroRuntime.ts +++ b/zero.Backoffice.UI/app/core/zeroRuntime.ts @@ -7,7 +7,7 @@ import { createRouter, RouteRecordRaw, RouterOptions } from 'vue-router'; import registerDirectives from '../directives/register'; import registerComponents from '../components/register'; import registerFormComponents from '../forms/register'; -//import registerEditorComponents from '../editor/register'; +import registerEditorComponents from '../editor/register'; import { getRouterConfig, appendRouterGuards } from './router/routerConfig'; import { @@ -73,7 +73,7 @@ export class ZeroRuntime implements Zero registerDirectives(app); registerComponents(app); registerFormComponents(app); - //registerEditorComponents(app); + registerEditorComponents(app); } diff --git a/zero.Backoffice.UI/app/components/editor/blueprint/property.vue b/zero.Backoffice.UI/app/editor/blueprint/property.vue similarity index 99% rename from zero.Backoffice.UI/app/components/editor/blueprint/property.vue rename to zero.Backoffice.UI/app/editor/blueprint/property.vue index e0bca79d..283dcf32 100644 --- a/zero.Backoffice.UI/app/components/editor/blueprint/property.vue +++ b/zero.Backoffice.UI/app/editor/blueprint/property.vue @@ -28,7 +28,7 @@