Browse Source

Changed structure of CmsKitContentWidgetOptions

pull/13242/head
malik masis 4 years ago
parent
commit
9243b5128c
  1. 6
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentWidgetDto.cs
  2. 13
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs
  3. 8
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/AddWidgetModal.cshtml
  4. 13
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/AddWidgetModal.cshtml.cs
  5. 6
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/addWidgetModal.js
  6. 4
      modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/WidgetDetailDto.cs
  7. 7
      modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/CmsKitContentWidgetOptions.cs
  8. 15
      modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs

6
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentWidgetDto.cs

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using Volo.CmsKit.Contents; using Volo.CmsKit.Contents;
namespace Volo.CmsKit.Admin.Contents; namespace Volo.CmsKit.Admin.Contents;
@ -8,5 +7,6 @@ namespace Volo.CmsKit.Admin.Contents;
public class ContentWidgetDto public class ContentWidgetDto
{ {
public string Key { get; set; } public string Key { get; set; }
public List<PropertyDto> Properties { get; set; } = new();
} public WidgetDetailDto Details { get; set; }
}

13
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs

@ -21,16 +21,7 @@ public class ContentAdminAppService : CmsKitAdminAppServiceBase, IContentAdminAp
//TODO remove //TODO remove
if (!_options.WidgetConfigs.Any()) if (!_options.WidgetConfigs.Any())
{ {
_options.AddWidget("Poll", "CmsPollByCode", new List<PropertyDto>() _options.AddWidget("CmsPollByCode", "Poll", "CmsPolls");
{
new PropertyDto() { Key = "Code", Name = "Code" }
});
_options.AddWidget("Comment", "CmsCommenting", new List<PropertyDto>()
{
new PropertyDto() { Key = "EntityType", Name = "EntityType" },
new PropertyDto() { Key = "EntityId", Name = "EntityId" }
});
} }
return Task.FromResult(new ListResultDto<ContentWidgetDto>() return Task.FromResult(new ListResultDto<ContentWidgetDto>()
{ {
@ -39,7 +30,7 @@ public class ContentAdminAppService : CmsKitAdminAppServiceBase, IContentAdminAp
new ContentWidgetDto new ContentWidgetDto
{ {
Key = n.Key, Key = n.Key,
Properties = n.Value.Properties Details = new WidgetDetailDto() { InternalName = n.Value.InternalName, Name = n.Value.Name },
}).ToList() }).ToList()
}); });

8
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/AddWidgetModal.cshtml

@ -10,8 +10,7 @@
Layout = null; Layout = null;
} }
@section scripts @section scripts {
{
<abp-script src="/Pages/CmsKit/Contents/addWidgetModal.js" /> <abp-script src="/Pages/CmsKit/Contents/addWidgetModal.js" />
} }
@ -22,7 +21,10 @@
@if (Model.Widgets.Count() > 1) @if (Model.Widgets.Count() > 1)
{ {
<abp-select asp-for="ViewModel.Widget" /> <abp-select asp-for="ViewModel.Widget" />
<div hidden id="polls">@await Component.InvokeAsync("CmsPolls")</div> foreach (var item in Model.ViewModel.Details)
{
<div hidden id="polls">@await Component.InvokeAsync(@item.InternalName)</div>
}
<div class="mb-3" id="PropertySideId"> <div class="mb-3" id="PropertySideId">
</div> </div>
<button class="btn btn-primary float-end" type="submit" id="save-changes">@L["Add"]</button> <button class="btn btn-primary float-end" type="submit" id="save-changes">@L["Add"]</button>

13
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/AddWidgetModal.cshtml.cs

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc.Rendering;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.CmsKit.Admin.Contents; using Volo.CmsKit.Admin.Contents;
using Volo.CmsKit.Contents;
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents; namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents;
@ -25,10 +26,16 @@ public class AddWidgetModal : AbpPageModel
public async Task OnGetAsync() public async Task OnGetAsync()
{ {
var widgets = await ContentAdminAppService.GetWidgetsAsync();
ViewModel = new ContentViewModel()
{
Details = widgets.Items.Select(p => p.Details).ToList()
};
Widgets = new List<SelectListItem>() { new("", "") }; Widgets = new List<SelectListItem>() { new("", "") };
Widgets.AddRange((await ContentAdminAppService.GetWidgetsAsync()) Widgets.AddRange(widgets
.Items .Items
.Select(w => new SelectListItem(w.Key, w.Key)) .Select(w => new SelectListItem(w.Details.Name, w.Key))
.ToList()); .ToList());
} }
@ -36,5 +43,7 @@ public class AddWidgetModal : AbpPageModel
{ {
[SelectItems(nameof(Widgets))] [SelectItems(nameof(Widgets))]
public string Widget { get; set; } public string Widget { get; set; }
public List<WidgetDetailDto> Details { get; set; }
} }
} }

6
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Contents/addWidgetModal.js

@ -6,15 +6,15 @@ $(function () {
let widgetType; let widgetType;
$("#ViewModel_Widget").change(function () { $("#ViewModel_Widget").change(function () {
widgetType = this.value; widgetType = $("#ViewModel_Widget").find(":selected").text();
$("#PropertySideId").html(''); $("#PropertySideId").html('');
$("#WidgetCodeDiv").hide(); $("#WidgetCodeDiv").hide();
volo.cmsKit.admin.contents.contentAdmin.getWidgets().then(function (data) { volo.cmsKit.admin.contents.contentAdmin.getWidgets().then(function (data) {
var widgetTypes = data.items.filter(v => v.key === widgetType); var widgetTypes = data.items.filter(v => v.details.name === widgetType);
var firstWidgetType = widgetTypes[0]; var firstWidgetType = widgetTypes[0];
if (firstWidgetType.key == "Poll") { if (firstWidgetType.key == "CmsPollByCode") {
$("#polls").removeAttr("hidden"); $("#polls").removeAttr("hidden");
$("#WidgetCodeDiv").show(); $("#WidgetCodeDiv").show();
} }

4
modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/PropertyDto.cs → modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/WidgetDetailDto.cs

@ -3,8 +3,8 @@
namespace Volo.CmsKit.Contents; namespace Volo.CmsKit.Contents;
[Serializable] [Serializable]
public class PropertyDto public class WidgetDetailDto
{ {
public string Key { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string InternalName { get; set; }
} }

7
modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/CmsKitContentWidgetOptions.cs

@ -11,10 +11,9 @@ public class CmsKitContentWidgetOptions
WidgetConfigs = new(); WidgetConfigs = new();
} }
public void AddWidget(string widgetName, string widgetKey, List<PropertyDto> properties = null) public void AddWidget(string widgetKey, string widgetName, string internalWidgetName = null)
{ {
var conf = new ContentWidgetConfig(widgetKey); var config = new ContentWidgetConfig(widgetName, internalWidgetName);
conf.Properties.AddRange(properties); WidgetConfigs.Add(widgetKey, config);
WidgetConfigs.Add(widgetName, conf);
} }
} }

15
modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentWidgetConfig.cs

@ -1,21 +1,14 @@
using System.Collections.Generic; namespace Volo.CmsKit.Contents;
namespace Volo.CmsKit.Contents;
public class ContentWidgetConfig public class ContentWidgetConfig
{ {
public string Name { get; } public string Name { get; }
public List<PropertyDto> Properties { get; } public string InternalName { get; }
public ContentWidgetConfig(string widgetName) public ContentWidgetConfig(string widgetName, string internalName)
{ {
Properties = new();
Name = widgetName; Name = widgetName;
} InternalName = internalName;
public void AddProperty(string key, string name)
{
Properties.Add(new PropertyDto() { Key = key, Name = name });
} }
} }
Loading…
Cancel
Save