Browse Source

Completed adding widget config

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

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

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

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

@ -1,4 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Volo.Abp.Application.Dtos;
@ -20,7 +21,10 @@ public class ContentAdminAppService : CmsKitAdminAppServiceBase, IContentAdminAp
//TODO remove
if (!_options.WidgetConfigs.Any())
{
_options.AddWidget("Poll", "CmsPollByCode");
_options.AddWidget("Poll", "CmsPollByCode", new List<PropertyDto>()
{
new PropertyDto() { Key = "Code", Name = "Code" }
});
}
return Task.FromResult(new ListResultDto<ContentWidgetDto>()
{

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

@ -5,7 +5,6 @@
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Contents;
@inject IHtmlLocalizer<CmsKitResource> L
@model AddWidgetModal;
@{
Layout = null;
@ -23,12 +22,21 @@
<abp-modal-body>
<div class="container row">
<abp-select asp-for="ViewModel.Widget" />
<div id="PropertySideId">
@foreach (var item in Model.ViewModel.Properties.FirstOrDefault(p=>p.Key == "Poll").Properties)
<div id="PropertySideIdPoll">
@foreach (var item in Model.ViewModel.ContentWidgets.FirstOrDefault(p=>p.Key == "Poll").Properties)
{
<div class="form-group">
<label for="@(item.Key)">@item.Name</label>
<input class="properties form-control" id="@(item.Key)" type="text" />
</div>
}
</div>
<div id="PropertySideIdComment">
@foreach (var item in Model.ViewModel.ContentWidgets.FirstOrDefault(p=>p.Key == "Comment").Properties)
{
<div class="form-group">
<label for="@(item)">@item</label>
<input class="properties form-control" id="@(item)" type="text" />
<label for="@(item.Key)">@item.Name</label>
<input class="properties form-control" id="@(item.Key)" type="text" />
</div>
}
</div>

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

@ -17,7 +17,6 @@ public class AddWidgetModal : AbpPageModel
[BindProperty]
public ContentViewModel ViewModel { get; set; }
public List<SelectListItem> Widgets { get; set; } = new();
public AddWidgetModal(IContentAdminAppService contentAdminAppService)
@ -30,8 +29,7 @@ public class AddWidgetModal : AbpPageModel
ViewModel = new ContentViewModel();
var widgets = await ContentAdminAppService.GetWidgetsAsync();
ViewModel.Properties = widgets.Items.ToArray();
ViewModel.ContentWidgets = widgets.Items.ToArray();
Widgets = new List<SelectListItem>() { new("", "") };
Widgets.AddRange(widgets
@ -45,7 +43,7 @@ public class AddWidgetModal : AbpPageModel
[SelectItems(nameof(Widgets))]
public string Widget { get; set; }
public ContentWidgetDto[] Properties { get; set; } = Array.Empty<ContentWidgetDto>();
public ContentWidgetDto[] ContentWidgets { get; set; } = Array.Empty<ContentWidgetDto>();
}
}

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

@ -4,10 +4,45 @@ $(function () {
var initModal = function () {
$('#PropertySideId').hide();
$('#PropertySideIdPoll').hide();
$('#PropertySideIdComment').hide();
//var getRelatedProperties = function () {
// var html = "";
// for (var i = 0; i < 2; i++) {
// html += "<div class=\"form-group\"> " +
// " <label for=\"" + i + "\">" + i + "</label>" +
// " <input class=\"properties form-control\" id=\"" + i + " type=\"text\" />" +
// " </div>";
// }
// $("#ye").each(function () {
// debugger
// alert("a");
// });
// return html;
//}
let widgetType;
$("#ViewModel_Widget").change(function () {
$('#PropertySideId').show();
widgetType = this.value;
debugger
if (widgetType == "Poll") {
$('#PropertySideIdPoll').show();
$('#PropertySideIdComment').hide();
}
else {
$('#PropertySideIdPoll').hide();
$('#PropertySideIdComment').show();
}
//var newHtml = getRelatedProperties();
//$("#PropertySideId").append(newHtml);
});
$("#save-changes").click(function () {
@ -20,9 +55,9 @@ $(function () {
}
});
var contentEditorText = $("#ContentEditor")[0].innerText.split("\n")[2];
var contentEditorText = $("#ContentEditor")[0].innerText.split("\n")[1];
var updatedText = "[Widget ";
var updatedText = "[Widget Type=\"" + widgetType + "\" ";
for (var i = 0; i < keys.length; i++) {
updatedText += keys[i] + "=\"" + values[i] + "\" ";

10
modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/PropertyDto.cs

@ -0,0 +1,10 @@
using System;
namespace Volo.CmsKit.Contents;
[Serializable]
public class PropertyDto
{
public string Key { get; set; }
public string Name { get; set; }
}

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

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

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

@ -5,11 +5,17 @@ namespace Volo.CmsKit.Contents;
public class ContentWidgetConfig
{
public string Name { get; }
//TODO remove - just for example
public List<string> Properties { get; } = new() { "Type", "Code" };
public List<PropertyDto> Properties { get; }
public ContentWidgetConfig(string widgetName)
{
Properties = new();
Name = widgetName;
}
public void AddProperty(string key, string name)
{
Properties.Add(new PropertyDto() { Key = key, Name = name });
}
}
Loading…
Cancel
Save