diff --git a/devdocs/specs/core-customize-form-fields.txt b/devdocs/specs/core-customize-form-fields.txt index a65a7371..c765c69b 100644 --- a/devdocs/specs/core-customize-form-fields.txt +++ b/devdocs/specs/core-customize-form-fields.txt @@ -36,11 +36,12 @@ UI FEATURE - The ability to customize forms: - #DONE# Need a FormCustom table and model to hold the user's form customization data - Like DataFilter, holds a JSON fragment in one field and the form key in another field - - JSON FRAGMENT holds items that differ from stock, no "core" fields allowed - - FieldKey - - Hide - - Required - - Type (checkbox, date, date time, decimal, number, picklist(FUTURE), and text) + - JSON FRAGMENT holds items that differ from stock, Hide not valid for non hideable core fields + - FieldKey "fld" + - Hide "hide" + - Required "required" + - Type One of values from AyDataType but not tags or enum (bool, date, date time, decimal, number, picklist(FUTURE), and text) + - e.g.: {fields:[{fld:"ltkeyoffieldname",hide:"true/false",required:"true/false", type:"bool"},{fld:"dollarAmount",lt:"WidgetDollarAmount",type:"currency"}]} - #DONE# Need a FormAvailableFields static collection class that contains the fields available to each form - This should be independent from any other class tied to a particular route or controller or db table as it could be some or none of all of those things diff --git a/server/AyaNova/Controllers/FormCustomController.cs b/server/AyaNova/Controllers/FormCustomController.cs index 873715c3..393ca8de 100644 --- a/server/AyaNova/Controllers/FormCustomController.cs +++ b/server/AyaNova/Controllers/FormCustomController.cs @@ -127,30 +127,6 @@ namespace AyaNova.Api.Controllers - // /// - // /// Get FormCustom pick list - // /// - // /// Required roles: Any - // /// - // /// - // /// List of public or owned data filters for listKey provided - // [HttpGet("PickList", Name = nameof(FormCustomPickList))] - // public async Task FormCustomPickList([FromQuery] string ListKey) - // { - // if (serverState.IsClosed) - // return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); - - // if (!ModelState.IsValid) - // return BadRequest(new ApiErrorResponse(ModelState)); - - // //Instantiate the business object handler - // FormCustomBiz biz = FormCustomBiz.GetBiz(ct, HttpContext); - - // var l = await biz.GetPickListAsync(ListKey); - // return Ok(new ApiOkResponse(l)); - - // } - // /// // /// Put (update) FormCustom @@ -197,75 +173,40 @@ namespace AyaNova.Api.Controllers // } - // /// - // /// Post FormCustom - // /// - // /// Required roles: - // /// BizAdminFull, InventoryFull, TechFull - // /// - // /// - // /// - // [HttpPost] - // public async Task PostFormCustom([FromBody] FormCustom inObj) - // { - // if (!serverState.IsOpen) - // return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); + /// + /// Post FormCustom + /// + /// Required roles: BizAdminFull + /// + /// + /// + [HttpPost] + public async Task PostFormCustom([FromBody] FormCustom inObj) + { + if (!serverState.IsOpen) + return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); - // //Instantiate the business object handler - // FormCustomBiz biz = FormCustomBiz.GetBiz(ct, HttpContext); + //Instantiate the business object handler + FormCustomBiz biz = FormCustomBiz.GetBiz(ct, HttpContext); - // //If a user has change roles, or editOwnRoles then they can create, true is passed for isOwner since they are creating so by definition the owner - // if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, biz.BizType)) - // return StatusCode(401, new ApiNotAuthorizedResponse()); + //check rights + if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, biz.BizType)) + return StatusCode(401, new ApiNotAuthorizedResponse()); - // if (!ModelState.IsValid) - // return BadRequest(new ApiErrorResponse(ModelState)); + if (!ModelState.IsValid) + return BadRequest(new ApiErrorResponse(ModelState)); - // //Create and validate - // FormCustom o = await biz.CreateAsync(inObj); - // if (o == null) - // return BadRequest(new ApiErrorResponse(biz.Errors)); - // else - // return CreatedAtAction("GetFormCustom", new { id = o.Id }, new ApiCreatedResponse(o)); + //Create and validate + FormCustom o = await biz.CreateAsync(inObj); + if (o == null) + return BadRequest(new ApiErrorResponse(biz.Errors)); + else + return CreatedAtAction("GetFormCustom", new { id = o.Id }, new ApiCreatedResponse(o)); - // } + } - // /// - // /// Delete FormCustom - // /// - // /// Required roles: - // /// Any if public otherwise creator only - // /// - // /// - // /// - // /// Ok - // [HttpDelete("{id}")] - // public async Task DeleteFormCustom([FromRoute] long id) - // { - // if (!serverState.IsOpen) - // return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); - - // if (!ModelState.IsValid) - // return BadRequest(new ApiErrorResponse(ModelState)); - - // //Instantiate the business object handler - // FormCustomBiz biz = FormCustomBiz.GetBiz(ct, HttpContext); - - // var o = await biz.GetNoLogAsync(id); - // if (o == null) - // return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); - - // if (!Authorized.IsAuthorizedToDelete(HttpContext.Items, biz.BizType, o.OwnerId)) - // return StatusCode(401, new ApiNotAuthorizedResponse()); - - // if (!biz.Delete(o)) - // return BadRequest(new ApiErrorResponse(biz.Errors)); - - // return NoContent(); - // } - //------------ diff --git a/server/AyaNova/biz/FormCustomBiz.cs b/server/AyaNova/biz/FormCustomBiz.cs index 2ae9f0df..883b140b 100644 --- a/server/AyaNova/biz/FormCustomBiz.cs +++ b/server/AyaNova/biz/FormCustomBiz.cs @@ -80,35 +80,7 @@ namespace AyaNova.Biz } } - //////////////////////////////////////////////////////////////////////////////////////////////// - //CREATE - internal FormCustom Create(AyContext TempContext, FormCustom inObj) - { - Validate(inObj, true); - if (HasErrors) - return null; - else - { - //do stuff with datafilter - FormCustom outObj = inObj; - outObj.OwnerId = UserId; - - - TempContext.FormCustom.Add(outObj); - TempContext.SaveChanges(); - - //Handle child and associated items: - - //EVENT LOG - EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext); - - //SEARCH INDEXING - // Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Name); - - return outObj; - - } - } + //////////////////////////////////////////////////////////////////////////////////////////////// /// GET @@ -203,7 +175,28 @@ namespace AyaNova.Biz try { var v = JArray.Parse(inObj.Template); + + //Validate the following: + //FormKey is valid value + //All fields specified are valid values + //Field is allowed to be hidden if hidden + //Type is one of the valid types: + /* + public const string Date = "date"; + public const string Text = "text"; + public const string Integer = "int"; + public const string Bool = "bool"; + public const string Decimal = "decimal"; + */ + //TODO: validate the json + /* + - JSON FRAGMENT holds items that differ from stock, no "core" fields allowed + - FieldKey + - Hide + - Required + - Type (checkbox, date, date time, decimal, number, picklist(FUTURE), and text) + */ // for (int i = 0; i < v.Count; i++) // { // var filterItem = v[i];