public SiteMenu([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public RelationCreateModel([FromServices] ErpRequestContext reqCtx) { ErpRequestContext = reqCtx; }
public PcFieldPassword([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcFieldMultiSelect([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcFieldCurrency([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcProjectWidgetTaskDistribution([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcFieldDate([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcFieldMultiFileUpload([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcButton([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public ApplicationHomePageModel([FromServices] ErpRequestContext reqCtx) { ErpRequestContext = reqCtx; }
public PcLazyLoad([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcProjectWidgetTimesheet([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcGridFilterField([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcChart([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public LoginModel([FromServices] ErpRequestContext reqCtx) { ErpRequestContext = reqCtx; }
public string RenderHtmlWithTemplate(string template, EntityRecord record = null, ErpRequestContext requestContext = null, ErpAppContext appContext = null) { var foundTags = Regex.Matches(template, @"(?<=\{\{)[^}]*(?=\}\})").Cast <Match>().Select(match => match.Value).Distinct().ToList(); foreach (var tag in foundTags) { var processedTag = tag.Replace("{{", "").Replace("}}", "").Trim(); var defaultValue = ""; if (processedTag.Contains("??")) { //this is a tag with a default value int questionMarksLocation = processedTag.IndexOf("??"); var tagValue = processedTag.Substring(0, questionMarksLocation).Trim(); var tagDefault = processedTag.Substring(questionMarksLocation + 2).Trim().Replace("\"", "").Replace("'", ""); processedTag = tagValue; defaultValue = tagDefault; } if (processedTag.StartsWith("Record[") && record != null) { //{{Record["fieldName"]}} var fieldName = processedTag.Replace("Record[\"", "").Replace("\"]", "").ToLowerInvariant(); if (record.Properties.ContainsKey(fieldName) && record[fieldName] != null) { template = template.Replace("{{" + tag + "}}", record[fieldName].ToString()); } else { template = template.Replace("{{" + tag + "}}", defaultValue); } } else if (processedTag.StartsWith("ErpRequestContext.") && requestContext != null) { var propertyPath = processedTag.Replace("ErpRequestContext.", ""); var propertyValue = requestContext.GetPropValue(propertyPath); if (propertyValue != null) { template = template.Replace("{{" + tag + "}}", propertyValue.ToString()); } else { template = template.Replace("{{" + tag + "}}", defaultValue); } } else if (processedTag.StartsWith("ErpAppContext.") && requestContext != null) { var propertyPath = processedTag.Replace("ErpAppContext.", ""); var propertyValue = requestContext.GetPropValue(propertyPath); if (propertyValue != null) { template = template.Replace("{{" + tag + "}}", propertyValue.ToString()); } else { template = template.Replace("{{" + tag + "}}", defaultValue); } } else if (processedTag.StartsWith("ListMeta.") && requestContext != null) { var propertyPath = processedTag.Replace("ListMeta.", ""); var propertyValue = requestContext.GetPropValue(propertyPath); if (propertyValue != null) { template = template.Replace("{{" + tag + "}}", propertyValue.ToString()); } else { template = template.Replace("{{" + tag + "}}", defaultValue); } } else if (processedTag.StartsWith("ViewMeta.") && requestContext != null) { var propertyPath = processedTag.Replace("ViewMeta.", ""); var propertyValue = requestContext.GetPropValue(propertyPath); if (propertyValue != null) { template = template.Replace("{{" + tag + "}}", propertyValue.ToString()); } else { template = template.Replace("{{" + tag + "}}", defaultValue); } } else if (processedTag.StartsWith("erp-allow-roles") && processedTag.Contains("=")) { //Check if "erp-authorize" is present var authoriseTag = foundTags.FirstOrDefault(x => x.Contains("erp-authorize")); if (authoriseTag != null) { var tagArray = processedTag.Split('='); var rolesCsv = tagArray[1].Replace("\"", "").Replace("\"", "").ToLowerInvariant(); var rolesList = rolesCsv.Split(',').ToList(); var currentUser = SecurityContext.CurrentUser; if (currentUser == null && !rolesList.Any(x => x == "guest")) { return(""); } var authorized = false; foreach (var askedRole in rolesList) { if (currentUser.Roles.Any(x => x.Name == askedRole)) { authorized = true; break; } } if (!authorized) { return(""); } } } else if (processedTag.StartsWith("erp-block-roles") && processedTag.Contains("=")) { //Check if "erp-authorize" is present var authoriseTag = foundTags.FirstOrDefault(x => x.Contains("erp-authorize")); if (authoriseTag != null) { var tagArray = processedTag.Split('='); var rolesCsv = tagArray[1].Replace("\"", "").Replace("\"", "").ToLowerInvariant(); var rolesList = rolesCsv.Split(',').ToList(); var currentUser = SecurityContext.CurrentUser; if (currentUser == null && rolesList.Any(x => x == "guest")) { return(""); } var authorized = true; foreach (var askedRole in rolesList) { if (currentUser.Roles.Any(x => x.Name == askedRole)) { authorized = false; break; } } if (!authorized) { return(""); } } } else if (processedTag == "CurrentUrlEncoded" && requestContext != null && requestContext.PageContext != null && requestContext.PageContext.HttpContext != null && requestContext.PageContext.HttpContext.Request != null) { var currentUrl = requestContext.PageContext.HttpContext.Request.Path + requestContext.PageContext.HttpContext.Request.QueryString; var propertyValue = HttpUtility.UrlEncode(currentUrl); if (!String.IsNullOrWhiteSpace(propertyValue)) { template = template.Replace("{{" + tag + "}}", propertyValue); } else { template = template.Replace("{{" + tag + "}}", defaultValue); } } } //Tags that depend on others to be already applied foreach (var tag in foundTags) { var processedTag = tag.Replace("{{", "").Replace("}}", "").Trim(); if (processedTag == "erp-active-page-equals") { //erp-active-page-equals var tagComplete = "{{" + processedTag + "}}"; HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument(); htmlDocument.LoadHtml(template); var links = htmlDocument.DocumentNode.SelectNodes("//a[@href]"); foreach (var link in links) { var hrefString = link.GetAttributeValue("href", ""); var erpTag = link.Attributes.FirstOrDefault(x => x.Name == tagComplete); var emptyTag = link.Attributes.FirstOrDefault(x => x.Name == "dasdasd"); if (erpTag != null) { if (!String.IsNullOrWhiteSpace(hrefString) && requestContext != null && requestContext.PageContext != null) { string currentUrl = requestContext.PageContext.HttpContext.Request.Path.ToString().ToLowerInvariant(); if (currentUrl == hrefString) { var classes = link.GetClasses().ToList(); if (classes.FirstOrDefault(x => x == "active") == null) { classes.Add("active"); link.SetAttributeValue("class", String.Join(" ", classes)); } } } link.Attributes.Remove(tagComplete); } } template = htmlDocument.DocumentNode.InnerHtml; } else if (processedTag == "erp-active-page-starts") { //erp-active-page-equals var tagComplete = "{{" + processedTag + "}}"; HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument(); htmlDocument.LoadHtml(template); var links = htmlDocument.DocumentNode.SelectNodes("//a[@href]"); foreach (var link in links) { var hrefString = link.GetAttributeValue("href", ""); var erpTag = link.Attributes.FirstOrDefault(x => x.Name == tagComplete); var emptyTag = link.Attributes.FirstOrDefault(x => x.Name == "dasdasd"); if (erpTag != null) { if (!String.IsNullOrWhiteSpace(hrefString) && requestContext != null && requestContext.PageContext != null) { string currentUrl = requestContext.PageContext.HttpContext.Request.Path.ToString().ToLowerInvariant(); if (currentUrl.StartsWith(hrefString)) { var classes = link.GetClasses().ToList(); if (classes.FirstOrDefault(x => x == "active") == null) { classes.Add("active"); link.SetAttributeValue("class", String.Join(" ", classes)); } } } link.Attributes.Remove(tagComplete); } } template = htmlDocument.DocumentNode.InnerHtml; } } return(template); }
public PcProjectWidgetTasksQueue([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcTaskRepeatRecurrenceSet([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public EntityDataModel([FromServices] ErpRequestContext reqCtx) { ErpRequestContext = reqCtx; }
public PcRepeater([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public ManageModel([FromServices] ErpRequestContext reqCtx) { ErpRequestContext = reqCtx; }
public PcPageHeader([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public RecordRelatedRecordDetailsPageModel([FromServices] ErpRequestContext reqCtx) { ErpRequestContext = reqCtx; }
public PcFieldTextarea([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public RecordListPageModel([FromServices] ErpRequestContext reqCtx) { ErpRequestContext = reqCtx; }
public FieldDetailsModel([FromServices] ErpRequestContext reqCtx) { ErpRequestContext = reqCtx; }
public PcFieldCheckboxGrid([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcBtnGroup([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public PcValidation([FromServices] ErpRequestContext coreReqCtx) { ErpRequestContext = coreReqCtx; }
public void Init(string appName = "", string areaName = "", string nodeName = "", string pageName = "", Guid?recordId = null, Guid?relationId = null, Guid?parentRecordId = null) { //Stopwatch sw = new Stopwatch(); //sw.Start(); if (String.IsNullOrWhiteSpace(appName)) { appName = AppName; } if (String.IsNullOrWhiteSpace(areaName)) { areaName = AreaName; } if (String.IsNullOrWhiteSpace(nodeName)) { nodeName = NodeName; } if (String.IsNullOrWhiteSpace(pageName)) { pageName = PageName; } if (recordId == null) { recordId = RecordId; } if (relationId == null) { relationId = RelationId; } if (parentRecordId == null) { parentRecordId = ParentRecordId; } var urlInfo = new PageService().GetInfoFromPath(HttpContext.Request.Path); if (String.IsNullOrWhiteSpace(appName)) { appName = urlInfo.AppName; if (AppName != appName) { AppName = appName; //When dealing with non standard routing in pages } } if (String.IsNullOrWhiteSpace(areaName)) { areaName = urlInfo.AreaName; if (AreaName != areaName) { AreaName = areaName; //When dealing with non standard routing in pages } } if (String.IsNullOrWhiteSpace(nodeName)) { nodeName = urlInfo.NodeName; if (NodeName != nodeName) { NodeName = nodeName; //When dealing with non standard routing in pages } } if (String.IsNullOrWhiteSpace(pageName)) { pageName = urlInfo.PageName; if (PageName != pageName) { PageName = pageName; //When dealing with non standard routing in pages } } if (recordId == null) { recordId = urlInfo.RecordId; if (RecordId != recordId) { RecordId = recordId; //When dealing with non standard routing in pages } } if (relationId == null) { relationId = urlInfo.RelationId; if (RelationId != relationId) { RelationId = relationId; //When dealing with non standard routing in pages } } if (parentRecordId == null) { parentRecordId = urlInfo.ParentRecordId; if (ParentRecordId != parentRecordId) { ParentRecordId = parentRecordId; //When dealing with non standard routing in pages } } ErpRequestContext.SetCurrentApp(appName, areaName, nodeName); ErpRequestContext.SetCurrentPage(PageContext, pageName, appName, areaName, nodeName, recordId, relationId, parentRecordId); ErpRequestContext.RecordId = recordId; ErpRequestContext.RelationId = relationId; ErpRequestContext.ParentRecordId = parentRecordId; ErpRequestContext.PageContext = PageContext; if (PageContext.HttpContext.Request.Query.ContainsKey("returnUrl")) { ReturnUrl = HttpUtility.UrlDecode(PageContext.HttpContext.Request.Query["returnUrl"].ToString()); } ErpAppContext = ErpAppContext.Current; CurrentUrl = PageUtils.GetCurrentUrl(PageContext.HttpContext); #region << Init Navigation >> //Application navigation if (ErpRequestContext.App != null) { var sitemap = ErpRequestContext.App.Sitemap; var appPages = new PageService().GetAppPages(ErpRequestContext.App.Id); //Calculate node Urls foreach (var area in sitemap.Areas) { if (area.Nodes.Count > 0) { var currentNode = area.Nodes[0]; switch (currentNode.Type) { case SitemapNodeType.ApplicationPage: var nodePages = appPages.FindAll(x => x.NodeId == currentNode.Id).ToList(); //Case 1: Node has attached pages if (nodePages.Count > 0) { nodePages = nodePages.OrderBy(x => x.Weight).ToList(); currentNode.Url = $"/{ErpRequestContext.App.Name}/{area.Name}/{currentNode.Name}/a/{nodePages[0].Name}"; } else { var firstAppPage = appPages.FindAll(x => x.Type == PageType.Application).OrderBy(x => x.Weight).FirstOrDefault(); if (firstAppPage == null) { currentNode.Url = $"/{ErpRequestContext.App.Name}/{area.Name}/{currentNode.Name}/a/"; } else { currentNode.Url = $"/{ErpRequestContext.App.Name}/{area.Name}/{currentNode.Name}/a/{firstAppPage.Name}"; } } break; case SitemapNodeType.EntityList: var firstListPage = appPages.FindAll(x => x.Type == PageType.RecordList).OrderBy(x => x.Weight).FirstOrDefault(); if (firstListPage == null) { currentNode.Url = $"/{ErpRequestContext.App.Name}/{area.Name}/{currentNode.Name}/l/"; } else { currentNode.Url = $"/{ErpRequestContext.App.Name}/{area.Name}/{currentNode.Name}/l/{firstListPage.Name}"; } break; case SitemapNodeType.Url: //Do nothing break; default: throw new Exception("Type not found"); } continue; } } //Convert to MenuItem foreach (var area in sitemap.Areas) { if (area.Nodes.Count == 0) { continue; } var areaMenuItem = new MenuItem(); if (area.Nodes.Count > 1) { var areaLink = $"<a href=\"javascript: void(0)\" title=\"{area.Label}\" data-navclick-handler>"; areaLink += $"<span class=\"menu-label\">{area.Label}</span>"; areaLink += $"<span class=\"menu-nav-icon ti-angle-down nav-caret\"></span>"; areaLink += $"</a>"; areaMenuItem = new MenuItem() { Content = areaLink }; foreach (var node in area.Nodes) { var nodeLink = $"<a class=\"dropdown-item\" href=\"{node.Url}\" title=\"{node.Label}\"><span class=\"{node.IconClass} icon\"></span> {node.Label}</a>"; areaMenuItem.Nodes.Add(new MenuItem() { Content = nodeLink }); } } else if (area.Nodes.Count == 1) { var areaLink = $"<a href=\"{area.Nodes[0].Url}\" title=\"{area.Label}\">"; areaLink += $"<span class=\"menu-label\">{area.Label}</span>"; areaLink += $"</a>"; areaMenuItem = new MenuItem() { Content = areaLink }; } ApplicationMenu.Add(areaMenuItem); } } //Site menu var pageSrv = new PageService(); var sitePages = pageSrv.GetSitePages(); foreach (var sitePage in sitePages) { SiteMenu.Add(new MenuItem() { Content = $"<a class=\"dropdown-item\" href=\"/s/{sitePage.Name}\">{sitePage.Label}</a>" }); } #endregion DataModel = new PageDataModel(this); //Debug.WriteLine(">>>>>>>>>>>>>>>>>>>>>>>>>> Base page init: " + sw.ElapsedMilliseconds); }