saving of space content in lists

This commit is contained in:
2020-05-03 16:21:37 +02:00
parent 3bbe19f407
commit 881bb20f22
8 changed files with 87 additions and 9 deletions
+4 -1
View File
@@ -1,4 +1,7 @@
namespace zero.Core.Entities
using Newtonsoft.Json;
using System;
namespace zero.Core.Entities
{
/// <summary>
/// A list item can consist of unlimited properties and be rendered as you wish
+9 -2
View File
@@ -27,7 +27,8 @@
disabled: false,
renderer: {},
actions: [],
model: null
model: null,
fullModel: null
}),
computed: {
@@ -58,13 +59,19 @@
{
this.renderer = response.config;
this.model = response.model;
this.fullModel = response;
});
},
onSubmit(form)
{
console.table(JSON.parse(JSON.stringify(this.model)));
this.fullModel.model = this.model;
form.handle(SpacesApi.save(this.fullModel)).then(response =>
{
console.info(response);
});
},
}
+10 -4
View File
@@ -1,4 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using zero.Core;
using zero.Core.Api;
@@ -61,22 +64,25 @@ namespace zero.Web.Controllers
model = await Api.GetItem<TeamMember>(alias, contentId);
}
JsonSerializerSettings settings = JsonConvert.DefaultSettings();
settings.TypeNameHandling = TypeNameHandling.Objects;
return Json(new SpaceContentEditModel()
{
Id = model.Id,
Alias = alias,
Model = model,
Config = Api.GetEditorConfig(alias)
});
}, settings);
}
/// <summary>
/// Save content item
/// </summary>
public async Task<IActionResult> Save([FromBody] TeamMember model)
public async Task<IActionResult> Save([FromBody] SpaceContentEditModel model)
{
TeamMember member = await Mapper.Map(model, await Api.GetItem<TeamMember>(model.Id));
return Json(await Api.Save(model.SpaceAlias, model));
return Json(await Api.Save(model.Alias, model.Model));
}
@@ -59,7 +59,6 @@ namespace zero.Web.Controllers
[ZeroAuthorize(Permissions.Settings.Users, PermissionsValue.Write)]
public async Task<IActionResult> Save([FromBody] UserRoleEditModel model)
{
var state = ModelState;
UserRole role = await Mapper.Map(model, await Api.GetById(model.Id));
return await As<UserRole, UserRoleEditModel>(await Api.Save(role));
}
@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Mvc.Formatters;
using System;
using System.IO;
using System.Threading.Tasks;
namespace zero.Web.Formatters
{
public class RawJsonBodyInputFormatter : InputFormatter
{
public RawJsonBodyInputFormatter()
{
this.SupportedMediaTypes.Add("application/json");
}
public override async Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context)
{
var request = context.HttpContext.Request;
using (var reader = new StreamReader(request.Body))
{
var content = await reader.ReadToEndAsync();
return await InputFormatterResult.SuccessAsync(content);
}
}
protected override bool CanReadType(Type type)
{
return type == typeof(string);
}
}
}
+26
View File
@@ -0,0 +1,26 @@
using System;
using System.Linq;
using zero.Core.Entities;
using zero.Core.Identity;
using zero.Core.Extensions;
using zero.Web.Models;
using Raven.Client.Documents;
namespace zero.Web.Mapper
{
public class SpaceMapperConfig : IMapperConfig
{
/// <inheritdoc />
public void Configure(IMapper config)
{
//config.CreateMap<SpaceContentEditModel, SpaceContent>((source, target) =>
//{
// target.Id = source.Id;
// target.Name = source.Name;
// target.IsActive = source.IsActive;
// target.CreatedDate = source.CreatedDate;
// target.
//});
}
}
}
+4 -1
View File
@@ -1,4 +1,7 @@
namespace zero.Web.Models
using Newtonsoft.Json;
using System;
namespace zero.Web.Models
{
public abstract class EditModel
{
+4
View File
@@ -18,6 +18,7 @@ using zero.Core.Entities;
using zero.Core.Extensions;
using zero.TestData;
using zero.TestData.Lists;
using zero.Web.Formatters;
namespace zero.Web
{
@@ -122,6 +123,7 @@ namespace zero.Web
IMvcBuilder mvc = services.AddMvc(opts =>
{
opts.Filters.Add<Core.Attributes.OperationCancelledExceptionFilterAttribute>();
opts.InputFormatters.Insert(0, new RawJsonBodyInputFormatter());
})
//.ExtendWithCore()
.AddNewtonsoftJson(opts =>
@@ -129,6 +131,8 @@ namespace zero.Web
opts.SerializerSettings.Converters.Add(new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" });
opts.SerializerSettings.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy()));
opts.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
JsonConvert.DefaultSettings = () => opts.SerializerSettings;
});
if (Environment.GetEnvironmentVariable("DOTNET_WATCH") == "1")