This commit is contained in:
@@ -95,37 +95,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get available fields for form specified
|
|
||||||
/// Used to build UI for customizing a form
|
|
||||||
///
|
|
||||||
/// Required roles:
|
|
||||||
/// BizAdminFull only has rights to customize forms
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="formkey"></param>
|
|
||||||
/// <returns>A single FormCustom</returns>
|
|
||||||
[HttpGet("AvailableFields/{formkey}")]
|
|
||||||
public ActionResult GetAvailableFields([FromRoute] string formkey)
|
|
||||||
{
|
|
||||||
if (serverState.IsClosed)
|
|
||||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
|
||||||
|
|
||||||
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.FormCustom))
|
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
|
||||||
|
|
||||||
if (ObjectFields.IsValidObjectKey(formkey))
|
|
||||||
{
|
|
||||||
return Ok(ApiOkResponse.Response(ObjectFields.ObjectFields(formkey), true));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
76
server/AyaNova/Controllers/ObjectFieldsController.cs
Normal file
76
server/AyaNova/Controllers/ObjectFieldsController.cs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using AyaNova.Models;
|
||||||
|
using AyaNova.Api.ControllerHelpers;
|
||||||
|
using AyaNova.Biz;
|
||||||
|
|
||||||
|
|
||||||
|
namespace AyaNova.Api.Controllers
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enum pick list controller
|
||||||
|
/// </summary>
|
||||||
|
[ApiController]
|
||||||
|
[ApiVersion("8.0")]
|
||||||
|
[Route("api/v{version:apiVersion}/[controller]")]
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Authorize]
|
||||||
|
public class ObjectFieldsController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly AyContext ct;
|
||||||
|
private readonly ILogger<AyaTypeController> log;
|
||||||
|
private readonly ApiServerState serverState;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ctor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dbcontext"></param>
|
||||||
|
/// <param name="logger"></param>
|
||||||
|
/// <param name="apiServerState"></param>
|
||||||
|
public ObjectFieldsController(AyContext dbcontext, ILogger<AyaTypeController> logger, ApiServerState apiServerState)
|
||||||
|
{
|
||||||
|
ct = dbcontext;
|
||||||
|
log = logger;
|
||||||
|
serverState = apiServerState;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get available fields for object specified
|
||||||
|
/// Used to build UI for customizing forms, lists etc
|
||||||
|
///
|
||||||
|
/// Required roles: Any
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="objectKey"></param>
|
||||||
|
/// <returns>List of fields and their properties</returns>
|
||||||
|
[HttpGet("ObjectFields/{objectKey}")]
|
||||||
|
public ActionResult GetObjectFields([FromRoute] string objectKey)
|
||||||
|
{
|
||||||
|
if (!serverState.IsOpen)
|
||||||
|
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
|
if (ObjectFields.IsValidObjectKey(objectKey))
|
||||||
|
{
|
||||||
|
return Ok(ApiOkResponse.Response(ObjectFields.ObjectFieldsList(objectKey), true));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}//eoc
|
||||||
|
}//ens
|
||||||
@@ -16,7 +16,7 @@ namespace AyaNova.Biz
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var FormTemplate = JArray.Parse(formCustom.Template);
|
var FormTemplate = JArray.Parse(formCustom.Template);
|
||||||
var ThisFormCustomFieldsList = ObjectFields.ObjectFields(formCustom.FormKey).Where(x => x.Custom == true).Select(x => x.Key).ToList();
|
var ThisFormCustomFieldsList = ObjectFields.ObjectFieldsList(formCustom.FormKey).Where(x => x.Custom == true).Select(x => x.Key).ToList();
|
||||||
|
|
||||||
//If the customFields string is empty then only validation is if any of the fields are required to be filled in
|
//If the customFields string is empty then only validation is if any of the fields are required to be filled in
|
||||||
if (!hasCustomData)
|
if (!hasCustomData)
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ namespace AyaNova.Biz
|
|||||||
if ((!PropertyHasErrors("FormKey") && !string.IsNullOrWhiteSpace(inObj.Template)))
|
if ((!PropertyHasErrors("FormKey") && !string.IsNullOrWhiteSpace(inObj.Template)))
|
||||||
{
|
{
|
||||||
var ValidCustomFieldTypes = CustomFieldType.ValidCustomFieldTypes;
|
var ValidCustomFieldTypes = CustomFieldType.ValidCustomFieldTypes;
|
||||||
var ValidFormFields = ObjectFields.ObjectFields(inObj.FormKey);
|
var ValidFormFields = ObjectFields.ObjectFieldsList(inObj.FormKey);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Parse the json, expecting something like this:
|
//Parse the json, expecting something like this:
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new System.ArgumentOutOfRangeException($"FormAvailableFields: {key} is not a valid form key");
|
throw new System.ArgumentOutOfRangeException($"ObjectFields: {key} is not a valid form key");
|
||||||
}
|
}
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
}//eoc FormAvailableFields
|
}//eoc ObjectFields
|
||||||
|
|
||||||
public class ObjectField
|
public class ObjectField
|
||||||
{
|
{
|
||||||
@@ -158,24 +158,24 @@ namespace AyaNova.Biz
|
|||||||
MiniAvailable = true;
|
MiniAvailable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectField(string key, string propertyName, bool sharedLTKey = false, bool hideable = true, bool custom = false)
|
// public ObjectField(string key, string propertyName, bool sharedLTKey = false, bool hideable = true, bool custom = false)
|
||||||
{
|
// {
|
||||||
Key = key;
|
// Key = key;
|
||||||
Hideable = hideable;
|
// Hideable = hideable;
|
||||||
Custom = custom;
|
// Custom = custom;
|
||||||
SharedLTKey = sharedLTKey;
|
// SharedLTKey = sharedLTKey;
|
||||||
PropertyName = propertyName;//Only if hideable do they require this as non-hideable ones are automatically validated anyway and this is only required for validation
|
// PropertyName = propertyName;//Only if hideable do they require this as non-hideable ones are automatically validated anyway and this is only required for validation
|
||||||
}
|
// }
|
||||||
|
|
||||||
public ObjectField(string key, bool sharedLTKey = false, bool hideable = true, bool custom = false)
|
// public ObjectField(string key, bool sharedLTKey = false, bool hideable = true, bool custom = false)
|
||||||
{
|
// {
|
||||||
Key = key;
|
// Key = key;
|
||||||
Hideable = hideable;
|
// Hideable = hideable;
|
||||||
Custom = custom;
|
// Custom = custom;
|
||||||
SharedLTKey = sharedLTKey;
|
// SharedLTKey = sharedLTKey;
|
||||||
PropertyName = null;
|
// PropertyName = null;
|
||||||
|
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace AyaNova.Biz
|
|||||||
//var OuterJson=JObject.Parse(formCustom.Template);
|
//var OuterJson=JObject.Parse(formCustom.Template);
|
||||||
var FormTemplate = JArray.Parse(formCustom.Template);
|
var FormTemplate = JArray.Parse(formCustom.Template);
|
||||||
// var FormTemplate=(JArray)OuterJson["template"];
|
// var FormTemplate=(JArray)OuterJson["template"];
|
||||||
var FormFields = ObjectFields.ObjectFields(formCustom.FormKey);
|
var FormFields = ObjectFields.ObjectFieldsList(formCustom.FormKey);
|
||||||
// var ThisFormNormalFieldsList = FormFields.Where(x => x.Custom == false).Select(x => x.Key).ToList();
|
// var ThisFormNormalFieldsList = FormFields.Where(x => x.Custom == false).Select(x => x.Key).ToList();
|
||||||
|
|
||||||
foreach (JObject jo in FormTemplate)
|
foreach (JObject jo in FormTemplate)
|
||||||
|
|||||||
Reference in New Issue
Block a user