public static string Parse(IParseContext context) { var type = string.Empty; foreach (var name in context.StlAttributes.AllKeys) { var value = context.StlAttributes[name]; if (ApplicationUtils.EqualsIgnoreCase(name, AttributeType)) { type = Context.ParseApi.ParseAttributeValue(value, context); } } if (string.IsNullOrEmpty(context.StlInnerHtml)) { var elementId = $"iframe_{StringUtils.GetShortGuid(false)}"; var libUrl = Context.PluginApi.GetPluginUrl(ApplicationUtils.PluginId, "assets/lib/iframe-resizer-3.6.3/iframeResizer.min.js"); var pageUrl = Context.PluginApi.GetPluginUrl(ApplicationUtils.PluginId, $"templates/{type}/index.html?siteId={context.SiteId}&apiUrl={HttpUtility.UrlEncode(Context.Environment.ApiUrl)}"); return($@" <iframe id=""{elementId}"" frameborder=""0"" scrolling=""no"" src=""{pageUrl}"" style=""width: 1px;min-width: 100%;""></iframe> <script type=""text/javascript"" src=""{libUrl}""></script> <script type=""text/javascript"">iFrameResize({{log: false}}, '#{elementId}')</script> "); } return($@" <script> var $apiUrl = '{Context.Environment.ApiUrl}'; var $siteId = {context.SiteId}; </script> {context.StlInnerHtml} "); }
public IHttpActionResult Get() { try { var request = Context.AuthenticatedRequest; var siteId = request.GetQueryInt("siteId"); if (!request.IsAdminLoggin) { return(Unauthorized()); } var name = request.GetQueryString("name"); var templateInfoList = TemplateManager.GetTemplateInfoList(); var templateInfo = templateInfoList.FirstOrDefault(x => ApplicationUtils.EqualsIgnoreCase(name, x.Name)); return(Ok(new { Value = templateInfo })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Submit() { try { var request = Context.AuthenticatedRequest; var siteId = request.GetQueryInt("siteId"); if (!request.IsAdminLoggin) { return(Unauthorized()); } var settings = ApplicationUtils.GetSettings(siteId); var type = request.GetPostString("type"); if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.IsClosed))) { settings.IsClosed = request.GetPostBool(nameof(Settings.IsClosed).ToCamelCase()); Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings); } else if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.DaysWarning))) { settings.DaysWarning = request.GetPostInt(nameof(Settings.DaysWarning).ToCamelCase()); Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings); } else if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.DaysDeadline))) { settings.DaysDeadline = request.GetPostInt(nameof(Settings.DaysDeadline).ToCamelCase()); Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings); } else if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.IsDeleteAllowed))) { settings.IsDeleteAllowed = request.GetPostBool(nameof(Settings.IsDeleteAllowed).ToCamelCase()); Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings); } else if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.IsSelectCategory))) { settings.IsSelectCategory = request.GetPostBool(nameof(Settings.IsSelectCategory).ToCamelCase()); Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings); } else if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.IsSelectDepartment))) { settings.IsSelectDepartment = request.GetPostBool(nameof(Settings.IsSelectDepartment).ToCamelCase()); Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings); } return(Ok(new { })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Clone() { try { var request = Context.AuthenticatedRequest; var siteId = request.GetQueryInt("siteId"); if (!request.IsAdminLoggin) { return(Unauthorized()); } var nameToClone = request.GetPostString("nameToClone"); var name = request.GetPostString("name"); var description = request.GetPostString("description"); var templateInfoList = TemplateManager.GetTemplateInfoList(); var templateInfoToClone = templateInfoList.FirstOrDefault(x => ApplicationUtils.EqualsIgnoreCase(nameToClone, x.Name)); if (templateInfoToClone == null) { return(NotFound()); } if (templateInfoList.Any(x => ApplicationUtils.EqualsIgnoreCase(name, x.Name))) { return(BadRequest($"标识为 {name} 的模板已存在,请更换模板标识!")); } var templateInfo = new TemplateInfo { Name = name, Main = templateInfoToClone.Main, Publisher = string.Empty, Description = description, Icon = templateInfoToClone.Icon }; templateInfoList.Add(templateInfo); TemplateManager.Clone(nameToClone, templateInfo, templateInfoList); return(Ok(new { Value = templateInfo })); } catch (Exception ex) { return(InternalServerError(ex)); } }