public void PageInit() { var entMan = new EntityManager(); var relMan = new EntityRelationManager(); ErpEntity = entMan.ReadEntity(ParentRecordId ?? Guid.Empty).Object; if (ErpEntity == null) { return; } var entityRelations = relMan.Read().Object.Where(x => x.TargetEntityId == ErpEntity.Id || x.OriginEntityId == ErpEntity.Id).ToList(); Relation = entityRelations.SingleOrDefault(x => x.Id == RecordId); if (Relation == null) { return; } if (String.IsNullOrWhiteSpace(ReturnUrl)) { ReturnUrl = $"/sdk/objects/entity/r/{ErpEntity.Id}/rl/relations/r/{Relation.Id}/"; } HeaderActions.AddRange(new List <string>() { PageUtils.GetActionTemplate(PageUtilsActionType.SubmitForm, label: "Save Relation", formId: "ManageRecord"), PageUtils.GetActionTemplate(PageUtilsActionType.Cancel, returnUrl: $"/sdk/objects/entity/r/{ErpEntity.Id}/rl/relations/r/{Relation.Id}/") }); HeaderToolbar.AddRange(AdminPageUtils.GetEntityAdminSubNav(ErpEntity, "relations")); TypeOptions = ModelExtensions.GetEnumAsSelectOptions <EntityRelationType>().FindAll(x => x.Value != "1").ToList(); }
public void PageInit() { Init(); var entMan = new EntityManager(); var recMan = new RecordManager(); ErpEntity = entMan.ReadEntity(ParentRecordId ?? Guid.Empty).Object; if (ErpEntity == null) { return; } if (!SecurityContext.HasEntityPermission(EntityPermission.Update, ErpEntity)) { ErpEntity = null; return; } Fields = ErpEntity.Fields.OrderBy(x => x.Name).ToList(); var idField = Fields.Single(x => x.Name == "id"); Fields.Remove(idField); Fields = Fields.OrderBy(x => x.Name).ToList(); Fields.Insert(0, idField); EntityQuery enQuery = new EntityQuery(ErpEntity.Name, "*", EntityQuery.QueryEQ("id", RecordId)); var response = recMan.Find(enQuery); if (!response.Success) { throw new Exception(response.Message); } if (response.Object.Data.Count == 0) { return; } Record = response.Object.Data[0]; if (String.IsNullOrWhiteSpace(ReturnUrl)) { ReturnUrl = $"/sdk/objects/entity/r/{ErpEntity.Id}/rl/data/l/"; } HeaderActions.AddRange(new List <string>() { PageUtils.GetActionTemplate(PageUtilsActionType.SubmitForm, label: "Save Record", formId: "ManageRecord"), PageUtils.GetActionTemplate(PageUtilsActionType.Cancel, returnUrl: $"/sdk/objects/entity/r/{ErpEntity.Id}/rl/data/l/") }); HeaderToolbar.AddRange(AdminPageUtils.GetEntityAdminSubNav(ErpEntity, "data")); }
public void PageInit() { Init(); if (String.IsNullOrWhiteSpace(ReturnUrl)) { ReturnUrl = $"/sdk/objects/entity/r/{ErpEntity.Id}/rl/relations/l"; } var entMan = new EntityManager(); var relMan = new EntityRelationManager(); var allRelations = relMan.Read().Object; foreach (var entity in entMan.ReadEntities().Object) { foreach (var field in entity.Fields) { if (field is GuidField) { var sfo = new SelectOption($"{entity.Id}${field.Id}", $"{entity.Name}.{field.Name}"); if (field.Unique && field.Required) { OriginOptions.Add(sfo); } if (!allRelations.Any(x => x.TargetFieldId == field.Id && x.RelationType != EntityRelationType.ManyToMany)) { TargetOptions.Add(sfo); } } } } ErpEntity = entMan.ReadEntity(ParentRecordId ?? Guid.Empty).Object; if (ErpEntity == null) { return; } HeaderActions.AddRange(new List <string>() { PageUtils.GetActionTemplate(PageUtilsActionType.SubmitForm, label: "Create Relation", formId: "CreateRecord"), PageUtils.GetActionTemplate(PageUtilsActionType.Cancel, returnUrl: $"/sdk/objects/entity/r/{ErpEntity.Id}/rl/relations/l") }); HeaderToolbar.AddRange(AdminPageUtils.GetEntityAdminSubNav(ErpEntity, "relations")); TypeOptions = ModelExtensions.GetEnumAsSelectOptions <EntityRelationType>().FindAll(x => x.Value != "1").ToList(); }
private void InitPage() { Init(); #region << Init App >> var appServ = new AppService(); App = appServ.GetApplication(RecordId ?? Guid.Empty); if (App != null && PageContext.HttpContext.Request.Method == "GET") { Name = App.Name; Label = App.Label; Description = App.Description; IconClass = App.IconClass; Author = App.Author; Color = App.Color; Weight = App.Weight; if (App.Access != null && App.Access.Count > 0) { Access = App.Access.Select(x => x.ToString()).ToList(); } } #endregion #region << Init Roles >> var roles = new SecurityManager().GetAllRoles().OrderBy(x => x.Name).ToList(); foreach (var role in roles) { RoleOptions.Add(new SelectOption() { Value = role.Id.ToString(), Label = role.Name }); } #endregion #region << Actions >> HeaderActions.AddRange(new List <string>() { $"<button type='button' onclick='ErpEvent.DISPATCH(\"WebVella.Erp.Web.Components.PcForm\",\"submit\")' class='btn btn-blue btn-sm'><span class='fa fa-save go-white'></span> Save App</button>", $"<a href='{ReturnUrl}' class='btn btn-white btn-sm'>Cancel</a>" }); HeaderToolbar.AddRange(AdminPageUtils.GetAppAdminSubNav(App, "manage")); #endregion }
public void PageInit() { Init(); var entMan = new EntityManager(); var recMan = new RecordManager(); ErpEntity = entMan.ReadEntity(ParentRecordId ?? Guid.Empty).Object; if (ErpEntity == null) { return; } if (!SecurityContext.HasEntityPermission(EntityPermission.Create, ErpEntity)) { ErpEntity = null; return; } Fields = ErpEntity.Fields.OrderBy(x => x.Name).ToList(); var idField = Fields.Single(x => x.Name == "id"); Fields.Remove(idField); Fields = Fields.OrderBy(x => x.Name).ToList(); Fields.Insert(0, idField); if (String.IsNullOrWhiteSpace(ReturnUrl)) { ReturnUrl = $"/sdk/objects/entity/r/{ErpEntity.Id}/rl/data/l/"; } HeaderActions.AddRange(new List <string>() { PageUtils.GetActionTemplate(PageUtilsActionType.SubmitForm, label: "Save Record", formId: "CreateRecord"), PageUtils.GetActionTemplate(PageUtilsActionType.Cancel, returnUrl: $"/sdk/objects/entity/r/{ErpEntity.Id}/rl/data/l/") }); HeaderToolbar.AddRange(AdminPageUtils.GetEntityAdminSubNav(ErpEntity, "data")); }
public void InitPage() { Init(); var entMan = new EntityManager(); ErpEntity = entMan.ReadEntity(ParentRecordId ?? Guid.Empty).Object; var allCards = AdminPageUtils.GetFieldCards(); if (FieldTypeId > 19 || FieldTypeId < 1) { FieldTypeId = 18; } FieldCard = allCards.First(x => (string)x["type"] == FieldTypeId.ToString()); if (Enum.TryParse <FieldType>(FieldTypeId.ToString(), out FieldType result)) { Type = result; } #region << Field Type init >> switch (Type) { case FieldType.AutoNumberField: DisplayFormat = "{0}"; break; case FieldType.CurrencyField: CurrencyOptions = Helpers.GetAllCurrency().MapTo <SelectOption>(); break; case FieldType.DateTimeField: Format = "yyyy-MMM-dd HH:mm"; break; default: break; } #endregion #region << Init RecordPermissions >> var valueGrid = new List <KeyStringList>(); PermissionOptions = new List <SelectOption>() { new SelectOption("read", "read"), new SelectOption("update", "update") }; var roles = AdminPageUtils.GetUserRoles(); //Special order is applied foreach (var role in roles) { RoleOptions.Add(new SelectOption(role.Id.ToString(), role.Name)); var keyValuesObj = new KeyStringList() { Key = role.Id.ToString(), Values = new List <string>() }; } #endregion #region << Actions >> HeaderActions.AddRange(new List <string>() { PageUtils.GetActionTemplate(PageUtilsActionType.SubmitForm, label: "Create Field", formId: "CreateRecord", btnClass: "btn btn-green btn-sm", iconClass: "ti-plus"), PageUtils.GetActionTemplate(PageUtilsActionType.Cancel, returnUrl: ReturnUrl) }); #endregion }
public IActionResult OnGet() { Init(); var entMan = new EntityManager(); #region << InitPage >> int pager = 0; string sortBy = ""; QuerySortType sortOrder = QuerySortType.Ascending; PageUtils.GetListQueryParams(PageContext.HttpContext, out pager, out sortBy, out sortOrder); Pager = pager; SortBy = sortBy; SortOrder = sortOrder; ErpEntity = entMan.ReadEntity(ParentRecordId ?? Guid.Empty).Object; if (ErpEntity == null) { return(NotFound()); } if (String.IsNullOrWhiteSpace(ReturnUrl)) { ReturnUrl = $"/sdk/objects/entity/r/{ErpEntity.Id}/"; } var allFields = ErpEntity.Fields; #region << Apply filters >> var submittedFilters = PageUtils.GetPageFiltersFromQuery(PageContext.HttpContext); if (submittedFilters.Count > 0) { foreach (var filter in submittedFilters) { switch (filter.Name) { case "name": if (filter.Type == FilterType.CONTAINS) { allFields = allFields.FindAll(x => x.Name.ToLowerInvariant().Contains(filter.Value.ToLowerInvariant())).ToList(); } break; } } } #endregion allFields = allFields.OrderBy(x => x.Name).ToList(); TotalCount = allFields.Count; ReturnUrlEncoded = HttpUtility.UrlEncode(PageUtils.GetCurrentUrl(PageContext.HttpContext)); PageDescription = PageUtils.GenerateListPageDescription(PageContext.HttpContext, "", TotalCount); #endregion #region << Create Columns >> Columns = new List <GridColumn>() { new GridColumn() { Name = "action", Width = "1%" }, new GridColumn() { Label = "Name", Name = "name", Sortable = true, Searchable = true }, new GridColumn() { Label = "Type", Name = "type", Width = "120px" }, new GridColumn() { Label = "System", Name = "system", Width = "1%" }, new GridColumn() { Label = "Required", Name = "required", Width = "1%" }, new GridColumn() { Label = "Unique", Name = "unique", Width = "80px" }, new GridColumn() { Label = "Searchable", Name = "searchable", Width = "1%" }, }; #endregion #region << Records >> //Apply sort if (!String.IsNullOrWhiteSpace(SortBy)) { switch (SortBy) { case "name": if (SortOrder == QuerySortType.Descending) { allFields = allFields.OrderByDescending(x => x.Name).ToList(); } else { allFields = allFields.OrderBy(x => x.Name).ToList(); } break; default: break; } } //Apply pager var skipPages = (Pager - 1) * PagerSize; allFields = allFields.Skip(skipPages).Take(PagerSize).ToList(); foreach (var field in allFields) { var record = new EntityRecord(); record["action"] = $"<a class='btn btn-sm btn-white' title='App details' href='/sdk/objects/entity/r/{ErpEntity.Id}/rl/fields/r/{field.Id}?returnUrl={ReturnUrlEncoded}'><span class='ti-eye'></span></a>"; record["name"] = field.Name; record["type"] = field.GetFieldType().ToString(); record["system"] = field.System; record["required"] = field.Required; record["unique"] = field.Unique; record["searchable"] = field.Searchable; Records.Add(record); } #endregion #region << Actions >> HeaderActions.AddRange(new List <string>() { $"<a href='/sdk/objects/entity/r/{(ErpEntity != null ? ErpEntity.Id : Guid.Empty)}/rl/fields/c/select?returnUrl={ReturnUrlEncoded}' class='btn btn-white btn-sm'><span class='fa fa-plus go-green'></span> Create Field</a>", $"<button type='button' onclick='ErpEvent.DISPATCH(\"WebVella.Erp.Web.Components.PcDrawer\",\"open\")' class='btn btn-white btn-sm'><span class='fa fa-search'></span> Search</a>" }); HeaderToolbar.AddRange(AdminPageUtils.GetEntityAdminSubNav(ErpEntity, "fields")); #endregion ErpRequestContext.PageContext = PageContext; return(Page()); }
public void PageInit() { #region << Init Entity >> var entMan = new EntityManager(); ErpEntity = entMan.ReadEntity(RecordId ?? Guid.Empty).Object; if (ErpEntity != null && PageContext.HttpContext.Request.Method == "GET") { Name = ErpEntity.Name; Label = ErpEntity.Label; LabelPlural = ErpEntity.LabelPlural; System = ErpEntity.System; IconName = ErpEntity.IconName; Color = ErpEntity.Color; RecordScreenIdField = ErpEntity.RecordScreenIdField; foreach (var field in ErpEntity.Fields) { FieldOptions.Add(new SelectOption() { Value = field.Id.ToString(), Label = field.Name }); } } #endregion if (String.IsNullOrWhiteSpace(ReturnUrl)) { ReturnUrl = $"/sdk/objects/entity/r/{ErpEntity.Id}/"; } #region << Init RecordPermissions >> var valueGrid = new List <KeyStringList>(); PermissionOptions = new List <SelectOption>() { new SelectOption("create", "create"), new SelectOption("read", "read"), new SelectOption("update", "update"), new SelectOption("delete", "delete") }; var roles = AdminPageUtils.GetUserRoles(); //Special order is applied foreach (var role in roles) { RoleOptions.Add(new SelectOption(role.Id.ToString(), role.Name)); var keyValuesObj = new KeyStringList() { Key = role.Id.ToString(), Values = new List <string>() }; if (ErpEntity.RecordPermissions.CanCreate.Contains(role.Id)) { keyValuesObj.Values.Add("create"); } if (ErpEntity.RecordPermissions.CanRead.Contains(role.Id)) { keyValuesObj.Values.Add("read"); } if (ErpEntity.RecordPermissions.CanUpdate.Contains(role.Id)) { keyValuesObj.Values.Add("update"); } if (ErpEntity.RecordPermissions.CanDelete.Contains(role.Id)) { keyValuesObj.Values.Add("delete"); } valueGrid.Add(keyValuesObj); } if (HttpContext.Request.Method == "GET") { RecordPermissions = JsonConvert.SerializeObject(valueGrid); } #endregion #region << Actions >> HeaderActions.AddRange(new List <string>() { PageUtils.GetActionTemplate(PageUtilsActionType.SubmitForm, label: "Save Entity", formId: "ManageRecord"), PageUtils.GetActionTemplate(PageUtilsActionType.Cancel, returnUrl: ReturnUrl, btnClass: "btn btn-sm btn-outline-secondary ml-1") }); HeaderToolbar.AddRange(AdminPageUtils.GetEntityAdminSubNav(ErpEntity, "details")); #endregion }
public void InitPage(bool isGet = true) { IsPostgisInstalled = DbRepository.IsPostgisInstalled(); var entMan = new EntityManager(); ErpEntity = entMan.ReadEntity(ParentRecordId ?? Guid.Empty).Object; var allCards = AdminPageUtils.GetFieldCards(); if (FieldTypeId == 20) //RelationField { throw new Exception("RelationField is unsupported field type"); } FieldCard = allCards.First(x => (string)x["type"] == FieldTypeId.ToString()); if (Enum.TryParse <FieldType>(FieldTypeId.ToString(), out FieldType result)) { Type = result; } if (isGet) { #region << Field Type init >> switch (Type) { case FieldType.AutoNumberField: DisplayFormat = "{0}"; break; case FieldType.CurrencyField: CurrencyOptions = Helpers.GetAllCurrency().MapTo <SelectOption>(); break; case FieldType.DateTimeField: Format = "yyyy-MMM-dd HH:mm"; break; case FieldType.GeographyField: { foreach (int format in Enum.GetValues(typeof(GeographyFieldFormat))) { string value = format.ToString(); string name = ((GeographyFieldFormat)format).ToString(); GeographyFormats.Add(new SelectOption(value, name)); } } break; default: break; } #endregion #region << Init RecordPermissions >> var valueGrid = new List <KeyStringList>(); PermissionOptions = new List <SelectOption>() { new SelectOption("read", "read"), new SelectOption("update", "update") }; var roles = AdminPageUtils.GetUserRoles(); //Special order is applied foreach (var role in roles) { RoleOptions.Add(new SelectOption(role.Id.ToString(), role.Name)); var keyValuesObj = new KeyStringList() { Key = role.Id.ToString(), Values = new List <string>() }; } #endregion } #region << Actions >> if (Type != FieldType.GeographyField) { HeaderActions.AddRange(new List <string>() { PageUtils.GetActionTemplate(PageUtilsActionType.SubmitForm, label: "Create Field", formId: "CreateRecord", btnClass: "btn btn-green btn-sm", iconClass: "fa fa-plus"), PageUtils.GetActionTemplate(PageUtilsActionType.Cancel, returnUrl: ReturnUrl) }); } else if (Type == FieldType.GeographyField) { if (IsPostgisInstalled) { HeaderActions.Add(PageUtils.GetActionTemplate(PageUtilsActionType.SubmitForm, label: "Create Field", formId: "CreateRecord", btnClass: "btn btn-green btn-sm", iconClass: "fa fa-plus")); } HeaderActions.Add(PageUtils.GetActionTemplate(PageUtilsActionType.Cancel, returnUrl: ReturnUrl)); } #endregion }