Changed structure of CmsKitContentWidgetOptions

pull/13242/head
malik masis 3 years ago
parent 34dca9a45c
commit 9243b5128c

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

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

@ -10,8 +10,7 @@
Layout = null;
}
@section scripts
{
@section scripts {
<abp-script src="/Pages/CmsKit/Contents/addWidgetModal.js" />
}
@ -22,7 +21,10 @@
@if (Model.Widgets.Count() > 1)
{
<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>
<button class="btn btn-primary float-end" type="submit" id="save-changes">@L["Add"]</button>

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

@ -6,15 +6,15 @@ $(function () {
let widgetType;
$("#ViewModel_Widget").change(function () {
widgetType = this.value;
widgetType = $("#ViewModel_Widget").find(":selected").text();
$("#PropertySideId").html('');
$("#WidgetCodeDiv").hide();
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];
if (firstWidgetType.key == "Poll") {
if (firstWidgetType.key == "CmsPollByCode") {
$("#polls").removeAttr("hidden");
$("#WidgetCodeDiv").show();
}

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

@ -11,10 +11,9 @@ public class CmsKitContentWidgetOptions
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);
conf.Properties.AddRange(properties);
WidgetConfigs.Add(widgetName, conf);
var config = new ContentWidgetConfig(widgetName, internalWidgetName);
WidgetConfigs.Add(widgetKey, config);
}
}

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