From 0d0d1f053145cf32f4ed4b6bb607e0a940fb0fef Mon Sep 17 00:00:00 2001 From: Ahmet Date: Thu, 11 Feb 2021 13:14:57 +0300 Subject: [PATCH] Added tui-editor with media upload to index page --- .../Pages/Index.cshtml | 35 +++++++++++ .../Volo.CmsKit.Web.Unified/Pages/index.js | 58 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/index.js diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml index 9f92acb27b..885034b055 100644 --- a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml @@ -1,7 +1,10 @@ @page @using Localization.Resources.AbpUi @using Microsoft.Extensions.Localization +@using Volo.Abp.AspNetCore.Mvc.UI.Packages.TuiEditor +@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Uppy @using Volo.Abp.GlobalFeatures +@using Volo.Abp.Users @using Volo.CmsKit.GlobalFeatures @using Volo.CmsKit.Pages @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting @@ -11,6 +14,18 @@ @using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Tags @model IndexModel @inject IStringLocalizer Localizer +@inject ICurrentUser CurrentUser + +@section styles{ + +} + +@section scripts{ + + + +} +

CMS Kit DEMO

@@ -33,6 +48,26 @@ +
+

Media added content editor

+ + + @if (CurrentUser.Id != null) + { + @if (GlobalFeatureManager.Instance.IsEnabled()) + { + +
+ + } + } + else + { + Please Login + } +
+
+ @if (GlobalFeatureManager.Instance.IsEnabled()) diff --git a/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/index.js b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/index.js new file mode 100644 index 0000000000..ad8fac0e00 --- /dev/null +++ b/modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/index.js @@ -0,0 +1,58 @@ +$(function(){ + var fileUploadUri = "/api/cms-kit-admin/media"; + var fileUriPrefix = "/api/cms-kit/media/" + + var editor = $('#content-editor'); + + function getUppyHeaders() { + var headers = {}; + headers[abp.security.antiForgery.tokenHeaderName] = abp.security.antiForgery.getToken(); + + return headers; + } + + var uploadImage = function (blob, callback, source) { + var UPPY_OPTIONS = { + endpoint: fileUploadUri, + formData: true, + fieldName: "file", + method: "post", + headers: getUppyHeaders() + }; + + var UPPY = Uppy.Core().use(Uppy.XHRUpload, UPPY_OPTIONS); + + UPPY.reset(); + + UPPY.addFile({ + id: "content-file", + name: blob.name, + type: blob.type, + data: blob, + }); + + UPPY.upload().then((result) => { + if (result.failed.length > 0) { + abp.message.error("File upload failed"); + } else { + var mediaDto = result.successful[0].response.body; + var fileUrl = (fileUriPrefix + mediaDto.id); + + callback(fileUrl, mediaDto.name); + } + }); + }; + + editor.tuiEditor({ + usageStatistics: false, + useCommandShortcut: true, + initialEditType: 'wysiwyg', + previewStyle: 'tab', + height: "25em", + minHeight: "25em", + language: abp.localization.currentCulture.cultureName, + hooks: { + addImageBlobHook: uploadImage, + }, + }); +}); \ No newline at end of file