Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cms Kit - Script & Style support for Page #8059

Merged
merged 4 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace Volo.CmsKit.Migrations
{
public partial class Page_StyleScript : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Script",
table: "CmsPages",
type: "nvarchar(max)",
nullable: true);

migrationBuilder.AddColumn<string>(
name: "Style",
table: "CmsPages",
type: "nvarchar(max)",
nullable: true);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Script",
table: "CmsPages");

migrationBuilder.DropColumn(
name: "Style",
table: "CmsPages");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer)
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.3")
.HasAnnotation("ProductVersion", "5.0.4")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

modelBuilder.Entity("Volo.Abp.AuditLogging.AuditLog", b =>
Expand Down Expand Up @@ -1506,11 +1506,17 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("uniqueidentifier")
.HasColumnName("LastModifierId");

b.Property<string>("Script")
.HasColumnType("nvarchar(max)");

b.Property<string>("Slug")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");

b.Property<string>("Style")
.HasColumnType("nvarchar(max)");

b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier")
.HasColumnName("TenantId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ public class CreatePageInputDto

[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxContentLength))]
public string Content { get; set; }

[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxScriptLength))]
public string Script { get; set; }

[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxStyleLength))]
public string Style { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ public class PageDto : AuditedEntityDto<Guid>
public string Slug { get; set; }

public string Content { get; set; }

public string Script { get; set; }

public string Style { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ public class UpdatePageInputDto

[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxContentLength))]
public string Content { get; set; }

[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxScriptLength))]
public string Script { get; set; }

[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxStyleLength))]
public string Style { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public virtual async Task<PagedResultDto<PageDto>> GetListAsync(GetPagesInputDto
[Authorize(CmsKitAdminPermissions.Pages.Create)]
public virtual async Task<PageDto> CreateAsync(CreatePageInputDto input)
{
var page = await PageManager.CreateAsync(input.Title, input.Slug, input.Content);
var page = await PageManager.CreateAsync(input.Title, input.Slug, input.Content, input.Script, input.Style);

await PageRepository.InsertAsync(page);

Expand All @@ -69,6 +69,8 @@ public virtual async Task<PageDto> UpdateAsync(Guid id, UpdatePageInputDto input

page.SetTitle(input.Title);
page.SetContent(input.Content);
page.SetScript(input.Script);
page.SetStyle(input.Style);

await PageRepository.UpdateAsync(page);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,49 @@
}

@section scripts {
<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>
<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-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>
<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-input asp-for="ViewModel.Slug" title="@L["PageSlugInformation"]" data-toggle="tooltip" />

<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>

<abp-tabs tab-style="Tab">

<abp-tab title="@L["Content"]">
<div class="content-editor"
id="ContentEditor"
data-input-id="@Html.IdFor(x => x.ViewModel.Content)"
data-language="@(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName)">
</div>
</abp-tab>

<abp-tab title="@L["Script"]">
<abp-input asp-for="ViewModel.Script" suppress-label="true" />
</abp-tab>

<abp-tab title="@L["Style"]">
<abp-input asp-for="ViewModel.Style" suppress-label="true"/>
</abp-tab>

</abp-tabs>
</form>
</abp-card-body>
<abp-card-footer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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.Pages;
Expand Down Expand Up @@ -39,10 +40,18 @@ public class CreatePageViewModel
[Required]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Slug { get; set; }

[HiddenInput]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Content { get; set; }

[TextArea(Rows = 6)]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Script { get; set; }

[TextArea(Rows = 6)]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Style { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,53 @@


@section scripts {
<abp-script-bundle>
<abp-script type="typeof(TuiEditorScriptContributor)"/>
<abp-script type="typeof(UppyScriptContributor)"/>
<abp-script type="typeof(SlugifyScriptContributor)"/>
<abp-script src="/Pages/CmsKit/Pages/update.js" />
</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/update.js" />
</abp-script-bundle>
}

@section styles {
<abp-style-bundle>
<abp-style type="typeof(TuiEditorStyleContributor)"/>
</abp-style-bundle>
<abp-style-bundle>
<abp-style type="typeof(TuiEditorStyleContributor)" />
</abp-style-bundle>
}

<abp-card>
<abp-card-header title="@L["Update"].Value"></abp-card-header>
<abp-card-body>
<form asp-page="/CmsKit/Pages/Update" id="form-page-update">
<abp-input asp-for="@Model.Id"/>

<abp-input asp-for="@Model.ViewModel.Title"/>
<abp-input asp-for="@Model.Id" />

<abp-input asp-for="ViewModel.Slug" title="@L["PageSlugInformation"]" data-toggle="tooltip"/>
<abp-input asp-for="@Model.ViewModel.Title" />

<abp-input asp-for="@Model.ViewModel.Content"/>
<abp-input asp-for="ViewModel.Slug" title="@L["PageSlugInformation"]" data-toggle="tooltip" />

<abp-input asp-for="@Model.ViewModel.Content" />


<abp-tabs tab-style="Tab">

<abp-tab title="@L["Content"]">
<div class="content-editor"
id="ContentEditor"
data-input-id="@Html.IdFor(x => x.ViewModel.Content)"
data-language="@(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName)">
</div>
</abp-tab>

<abp-tab title="@L["Script"]">
<abp-input asp-for="ViewModel.Script" suppress-label="true" />
</abp-tab>

<abp-tab title="@L["Style"]">
<abp-input asp-for="ViewModel.Style" suppress-label="true"/>
</abp-tab>

</abp-tabs>

<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public class UpdatePageViewModel
[HiddenInput]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Content { get; set; }

[TextArea(Rows = 6)]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxScriptLength))]
public string Script { get; set; }

[TextArea(Rows = 6)]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxStyleLength))]
public string Style { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"CommentAuthorizationExceptionMessage": "Those comments are not allowed for public display.",
"CommentDeletionConfirmationMessage": "This comment and all replies will be deleted!",
"Comments": "Comments",
"Content": "Content",
"ContentDeletionConfirmationMessage": "Are you sure to delete this content?",
"Contents": "Contents",
"CoverImage": "Cover Image",
Expand Down Expand Up @@ -93,6 +94,7 @@
"ReplyTo": "Reply to",
"SamplePageMessage": "A sample page for the Pro module",
"SaveChanges": "Save Changes",
"Script": "Script",
"SelectAll": "Select All",
"Send": "Send",
"SendMessage": "Send Message",
Expand All @@ -102,6 +104,7 @@
"SourceUrl": "Source Url",
"Star": "Star",
"StartDate": "Start Date",
"Style": "Style",
"Subject": "Subject",
"SubjectPlaceholder": "Please type a subject",
"Submit": "Submit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"Blogs": "Bloglar",
"ChoosePreference": "Tercih seçiniz...",
"Cms": "Cms",
"Content": "İçerik",
"Script": "Script Kodları",
"Style": "Stil Kodları",
"CmsKit.Comments": "Yorumlar",
"CmsKit.Ratings": "Puanlama",
"CmsKit.Reactions": "Tepkiler",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ public class PageConsts
public static int MaxSlugLength { get; set; } = 256;

public static int MaxContentLength { get; set; } = int.MaxValue;

public static int MaxScriptLength { get; set; } = int.MaxValue;

public static int MaxStyleLength { get; set; } = int.MaxValue;
}
}
27 changes: 25 additions & 2 deletions modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,31 @@ public class Page : FullAuditedAggregateRoot<Guid>, IMultiTenant
public virtual string Slug { get; protected set; }

public virtual string Content { get; protected set; }


public virtual string Script { get; protected set; }

public virtual string Style { get; protected set; }

protected Page()
{
}

internal Page(Guid id, [NotNull] string title, [NotNull] string slug, string content = null, Guid? tenantId = null) : base(id)
internal Page(
Guid id,
[NotNull] string title,
[NotNull] string slug,
string content = null,
string script = null,
string style = null,
Guid? tenantId = null) : base(id)
{
TenantId = tenantId;

SetTitle(title);
SetSlug(slug);
SetContent(content);
SetScript(script);
SetStyle(style);
}

public virtual void SetTitle(string title)
Expand All @@ -43,5 +56,15 @@ public virtual void SetContent(string content)
{
Content = Check.Length(content, nameof(content), PageConsts.MaxContentLength);
}

public virtual void SetScript(string script)
{
Script = Check.Length(script, nameof(script), PageConsts.MaxScriptLength);
}

public virtual void SetStyle(string style)
{
Style = Check.Length(style, nameof(style), PageConsts.MaxStyleLength);
}
}
}