Browse Source

Added content property to page & update ui

pull/7911/head
Ahmet 5 years ago
parent
commit
e6ffc14c2b
  1. 2020
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20210302091451_Added_Content_To_Page.Designer.cs
  2. 24
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20210302091451_Added_Content_To_Page.cs
  3. 4
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs
  4. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/CreatePageInputDto.cs
  5. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/PageDto.cs
  6. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/UpdatePageInputDto.cs
  7. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Pages/PageAdminAppService.cs
  8. 44
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/Create.cshtml
  9. 11
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/Create.cshtml.cs
  10. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/Index.cshtml
  11. 1
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/Update.cshtml
  12. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/Update.cshtml.cs
  13. 116
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/create.js
  14. 2
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Pages/PageConsts.cs
  15. 22
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs
  16. 1
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs
  17. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/PageDto.cs
  18. 10
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml
  19. 7
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs
  20. 3
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml
  21. 9
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Pages/PageAdminAppService_Tests.cs
  22. 10
      modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs

2020
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20210302091451_Added_Content_To_Page.Designer.cs

File diff suppressed because it is too large

24
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20210302091451_Added_Content_To_Page.cs

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Volo.CmsKit.Migrations
{
public partial class Added_Content_To_Page : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Content",
table: "CmsPages",
type: "nvarchar(max)",
maxLength: 2147483647,
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Content",
table: "CmsPages");
}
}
}

4
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs

@ -1537,6 +1537,10 @@ namespace Volo.CmsKit.Migrations
.HasColumnType("nvarchar(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<string>("Content")
.HasMaxLength(2147483647)
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime2")
.HasColumnName("CreationTime");

3
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/CreatePageInputDto.cs

@ -16,5 +16,8 @@ namespace Volo.CmsKit.Admin.Pages
[Required]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Slug { get; set; }
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxContentLength))]
public string Content { get; set; }
}
}

2
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/PageDto.cs

@ -9,5 +9,7 @@ namespace Volo.CmsKit.Admin.Pages
public string Title { get; set; }
public string Slug { get; set; }
public string Content { get; set; }
}
}

3
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/UpdatePageInputDto.cs

@ -16,5 +16,8 @@ namespace Volo.CmsKit.Admin.Pages
[Required]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Slug { get; set; }
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxContentLength))]
public string Content { get; set; }
}
}

3
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Pages/PageAdminAppService.cs

@ -50,7 +50,7 @@ namespace Volo.CmsKit.Admin.Pages
{
await CheckPageSlugAsync(input.Slug);
var page = new Page(GuidGenerator.Create(), input.Title, input.Slug, CurrentTenant.Id);
var page = new Page(GuidGenerator.Create(), input.Title, input.Slug, input.Content, CurrentTenant.Id);
await PageRepository.InsertAsync(page);
@ -69,6 +69,7 @@ namespace Volo.CmsKit.Admin.Pages
page.SetTitle(input.Title);
page.SetSlug(input.Slug);
page.SetContent(input.Content);
await PageRepository.UpdateAsync(page);

44
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/Create.cshtml

@ -1,9 +1,10 @@
@page
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents.Components.EntityContentEditor
@using System.Globalization
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.TuiEditor
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Uppy
@using Volo.CmsKit.Admin.Web.Pages
@using Volo.CmsKit.Admin.Web.Menus
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Pages
@using Volo.CmsKit.Admin.Web.Bundles
@inherits CmsKitAdminPageBase
@ -17,27 +18,36 @@
}
@section scripts {
<abp-script-bundle>
<abp-script src="/Pages/CmsKit/Pages/create.js" />
<abp-script type="typeof(SlugifyScriptContributor)" />
</abp-script-bundle>
<abp-script-bundle>
<abp-script type="typeof(TuiEditorScriptContributor)"/>
<abp-script type="typeof(UppyScriptContributor)"/>
<abp-script type="typeof(SlugifyScriptContributor)"/>
<abp-script src="/Pages/CmsKit/Pages/create.js" />
</abp-script-bundle>
}
@section styles {
<abp-style-bundle>
<abp-style type="typeof(TuiEditorStyleContributor)"/>
</abp-style-bundle>
}
<abp-card>
<abp-card-header title="@L["New"].Value"></abp-card-header>
<abp-card-body>
<abp-dynamic-form abp-model="ViewModel" asp-page="/CmsKit/Pages/Create" id="form-page-create">
<abp-form-content />
<form asp-page="/CmsKit/Pages/Create" id="form-page-create">
<abp-input asp-for="@Model.ViewModel.Title" />
<abp-input asp-for="ViewModel.Slug" title="@L["PageSlugInformation"]" data-toggle="tooltip"/>
</abp-dynamic-form>
@await Component.InvokeAsync(typeof(EntityContentEditorViewComponent), new
{
entityType = "Page",
displaySubmitButton = false
})
<abp-input asp-for="@Model.ViewModel.Content" />
<div class="content-editor"
id="ContentEditor"
data-input-id="@Html.IdFor(x => x.ViewModel.Content)"
data-language="@(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName)">
</div>
</form>
</abp-card-body>
<abp-card-footer>
<abp-button button-type="Primary" type="submit" text="@L["Submit"].Value" id="button-page-create" />

11
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/Create.cshtml.cs

@ -2,10 +2,8 @@
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form;
using Volo.Abp.Validation;
using Volo.CmsKit.Admin.Pages;
using Volo.CmsKit.Admin.Web.Pages;
using Volo.CmsKit.Pages;
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Pages
@ -34,14 +32,17 @@ namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Pages
[AutoMap(typeof(CreatePageInputDto), ReverseMap = true)]
public class CreatePageViewModel
{
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxTitleLength))]
[Required]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxTitleLength))]
public string Title { get; set; }
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
[Required]
[DynamicFormIgnore]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Slug { get; set; }
[HiddenInput]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Content { get; set; }
}
}
}

2
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/Index.cshtml

@ -1,6 +1,4 @@
@page
@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Pages.Shared.Components.AbpPageToolbar
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Pages.Shared.Components.AbpPageSearchBox
@using Volo.CmsKit.Admin.Web.Pages

1
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/Update.cshtml

@ -2,7 +2,6 @@
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents.Components.EntityContentEditor
@using Volo.CmsKit.Admin.Web.Menus
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Pages
@using Volo.CmsKit.Admin.Web.Pages
@inherits CmsKitAdminPageBase

3
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/Update.cshtml.cs

@ -1,10 +1,7 @@
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form;
using Volo.Abp.Validation;

116
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/create.js

@ -1,22 +1,25 @@
$(function () {
var l = abp.localization.getResource("CmsKit");
var $formCreate = $('#form-page-create');
var $createForm = $('#form-page-create');
var $title = $('#ViewModel_Title');
var $slug = $('#ViewModel_Slug');
var $buttonSubmit = $('#button-page-create');
var $pageContentInput = $('#ViewModel_Value');
$formCreate.on('submit', function (e) {
$createForm.data('validator').settings.ignore = ":hidden, [contenteditable='true']:not([name]), .tui-popup-wrapper";
$createForm.on('submit', function (e) {
e.preventDefault();
if ($formCreate.valid()) {
if ($createForm.valid()) {
abp.ui.setBusy();
$formCreate.ajaxSubmit({
$createForm.ajaxSubmit({
success: function (result) {
submitEntityContent(result.id);
abp.notify.success(l('SuccessfullySaved'));
abp.ui.clearBusy();
location.href = "/CmsKit/Pages/";
}
});
}
@ -24,28 +27,9 @@
$buttonSubmit.click(function (e) {
e.preventDefault();
$formCreate.submit();
$createForm.submit();
});
function submitEntityContent(pageId) {
volo.cmsKit.admin.contents.contentAdmin
.create(
{
entityType: 'Page',
entityId: pageId,
value: $pageContentInput.val()
})
.then(function (result) {
finishSaving();
});
}
function finishSaving() {
abp.notify.success(l('SuccessfullySaved'));
abp.ui.clearBusy();
location.href = "/CmsKit/Pages/";
}
var slugEdited = false;
$title.on('change paste keyup', function () {
@ -69,4 +53,84 @@
$slug.change(function () {
slugEdited = true;
});
// -----------------------------------
function getUppyHeaders() {
var headers = {};
headers[abp.security.antiForgery.tokenHeaderName] = abp.security.antiForgery.getToken();
return headers;
}
var fileUploadUri = "/api/cms-kit-admin/media/page";
var fileUriPrefix = "/api/cms-kit/media/";
var editorDataKey = "tuiEditor";
initAllEditors();
function initAllEditors() {
$('.content-editor').each(function (i, item) {
initEditor(item);
});
}
function initEditor(element) {
var $editorContainer = $(element);
var inputName = $editorContainer.data('input-id');
var $editorInput = $('#' + inputName);
var initialValue = $editorInput.val();
var editor = $editorContainer.tuiEditor({
usageStatistics: false,
useCommandShortcut: true,
initialValue: initialValue,
previewStyle: 'tab',
height: "25em",
minHeight: "25em",
initialEditType: initialValue ? 'wysiwyg' : 'markdown',
language: $editorContainer.data("language"),
hooks: {
addImageBlobHook: uploadFile,
},
events: {
change: function (_val) {
$editorInput.val(editor.getHtml());
$editorInput.trigger("change");
}
}
}).data(editorDataKey);
}
function uploadFile(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);
}
});
}
});

2
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Pages/PageConsts.cs

@ -5,5 +5,7 @@
public static int MaxTitleLength { get; set; } = 256;
public static int MaxSlugLength { get; set; } = 256;
public static int MaxContentLength { get; set; } = int.MaxValue;
}
}

22
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs

@ -8,22 +8,25 @@ namespace Volo.CmsKit.Pages
{
public class Page : FullAuditedAggregateRoot<Guid>, IMultiTenant
{
[CanBeNull] public virtual Guid? TenantId { get; protected set; }
public virtual Guid? TenantId { get; protected set; }
[NotNull] public virtual string Title { get; protected set; }
public virtual string Title { get; protected set; }
[NotNull] public virtual string Slug { get; protected set; }
public virtual string Slug { get; protected set; }
public virtual string Content { get; protected set; }
protected Page()
{
}
public Page(Guid id, [NotNull] string title, [NotNull] string slug, [CanBeNull]Guid? tenantId = null) : base(id)
public Page(Guid id, [NotNull] string title, [NotNull] string slug, string content = null, Guid? tenantId = null) : base(id)
{
Title = Check.NotNullOrEmpty(title, nameof(title), PageConsts.MaxTitleLength);
Slug = Check.NotNullOrEmpty(slug, nameof(slug), PageConsts.MaxSlugLength);
TenantId = tenantId;
SetTitle(title);
SetSlug(slug);
SetContent(content);
}
public virtual void SetTitle(string title)
@ -35,5 +38,10 @@ namespace Volo.CmsKit.Pages
{
Slug = Check.NotNullOrEmpty(slug, nameof(slug), PageConsts.MaxSlugLength);
}
public virtual void SetContent(string content)
{
Content = Check.Length(content, nameof(content), PageConsts.MaxContentLength);
}
}
}

1
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs

@ -179,6 +179,7 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.Property(x => x.Title).IsRequired().HasMaxLength(PageConsts.MaxTitleLength);
b.Property(x => x.Slug).IsRequired().HasMaxLength(PageConsts.MaxSlugLength);
b.Property(x => x.Content).HasMaxLength(PageConsts.MaxContentLength);
b.HasIndex(x => new { x.TenantId, Url = x.Slug });
});

2
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/PageDto.cs

@ -9,5 +9,7 @@ namespace Volo.CmsKit.Public.Pages
public string Title { get; set; }
public string Slug { get; set; }
public string Content { get; set; }
}
}

10
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/Default.cshtml

@ -1,8 +1,5 @@
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
@using Microsoft.AspNetCore.Mvc.RazorPages
@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Contents
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages.PageViewModel
@inject IPageLayout PageLayout
@ -12,11 +9,6 @@
<abp-card>
<abp-card-body>
@await Component.InvokeAsync(typeof(ContentViewComponent),
new
{
entityType = nameof(Page),
entityId = Model.Id.ToString()
})
@Html.Raw(Model.Content)
</abp-card-body>
</abp-card>

7
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs

@ -16,12 +16,13 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
PagePublicAppService = pagePublicAppService;
}
public virtual async Task<IViewComponentResult> InvokeAsync(Guid pageId, string title, string description)
public virtual async Task<IViewComponentResult> InvokeAsync(Guid pageId, string title, string content)
{
var model = new PageViewModel
{
Id = pageId,
Title = title
Title = title,
Content = content
};
return View("~/Pages/CmsKit/Shared/Components/Pages/Default.cshtml", model);
@ -33,5 +34,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
public Guid Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
}
}

3
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Pages/Index.cshtml

@ -9,5 +9,6 @@
new
{
pageId = Model.Page.Id,
title = Model.Page.Title
title = Model.Page.Title,
content = Model.Page.Content
})

9
modules/cms-kit/test/Volo.CmsKit.Application.Tests/Pages/PageAdminAppService_Tests.cs

@ -64,7 +64,8 @@ namespace Volo.CmsKit.Pages
var dto = new CreatePageInputDto
{
Title = "test",
Slug = "test-url"
Slug = "test-url",
Content = "test*content"
};
await Should.NotThrowAsync(async () => await _pageAdminAppService.CreateAsync(dto));
@ -94,7 +95,8 @@ namespace Volo.CmsKit.Pages
var dto = new UpdatePageInputDto
{
Title = _data.Page_1_Title + "++",
Slug = _data.Page_1_Slug+ "test"
Slug = _data.Page_1_Slug+ "test",
Content = "changed"
};
await Should.NotThrowAsync(async () => await _pageAdminAppService.UpdateAsync(_data.Page_1_Id, dto));
@ -106,6 +108,9 @@ namespace Volo.CmsKit.Pages
updatedPage.Slug.ShouldNotBe(_data.Page_1_Slug);
updatedPage.Slug.ShouldBe(dto.Slug);
updatedPage.Content.ShouldNotBe(_data.Content_1);
updatedPage.Content.ShouldBe(dto.Content);
}
[Fact]

10
modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs

@ -338,17 +338,11 @@ namespace Volo.CmsKit
private async Task SeedPagesAsync()
{
var page1 = new Page(_cmsKitTestData.Page_1_Id, _cmsKitTestData.Page_1_Title, _cmsKitTestData.Page_1_Slug);
var page1Content = new Content(_guidGenerator.Create(), nameof(Page), page1.Id.ToString(), _cmsKitTestData.Page_1_Content);
var page1 = new Page(_cmsKitTestData.Page_1_Id, _cmsKitTestData.Page_1_Title, _cmsKitTestData.Page_1_Slug, _cmsKitTestData.Content_1);
await _pageRepository.InsertAsync(page1);
await _contentRepository.InsertAsync(page1Content);
var page2 = new Page(_cmsKitTestData.Page_2_Id, _cmsKitTestData.Page_2_Title, _cmsKitTestData.Page_2_Slug);
var page2Content = new Content(_guidGenerator.Create(), nameof(Page), page2.Id.ToString(), _cmsKitTestData.Page_2_Content);
var page2 = new Page(_cmsKitTestData.Page_2_Id, _cmsKitTestData.Page_2_Title, _cmsKitTestData.Page_2_Slug, _cmsKitTestData.Content_2);
await _pageRepository.InsertAsync(page2);
await _contentRepository.InsertAsync(page2Content);
}
private async Task SeedBlogsAsync()

Loading…
Cancel
Save