public async Task <IActionResult> Index(ContentOptions options, PagerParameters pagerParameters) { if (!options.AdminTemplates && !await _authorizationService.AuthorizeAsync(User, Permissions.ManageTemplates)) { return(Forbid()); } if (options.AdminTemplates && !await _authorizationService.AuthorizeAsync(User, AdminTemplatesPermissions.ManageAdminTemplates)) { return(Forbid()); } var siteSettings = await _siteService.GetSiteSettingsAsync(); var pager = new Pager(pagerParameters, siteSettings.PageSize); var templatesDocument = options.AdminTemplates ? await _adminTemplatesManager.GetTemplatesDocumentAsync() : await _templatesManager.GetTemplatesDocumentAsync() ; var templates = templatesDocument.Templates.ToList(); if (!string.IsNullOrWhiteSpace(options.Search)) { templates = templates.Where(x => x.Key.Contains(options.Search, StringComparison.OrdinalIgnoreCase)).ToList(); } var count = templates.Count; templates = templates.OrderBy(x => x.Key) .Skip(pager.GetStartIndex()) .Take(pager.PageSize).ToList(); var pagerShape = (await New.Pager(pager)).TotalItemCount(count); var model = new TemplateIndexViewModel { Templates = templates.Select(x => new TemplateEntry { Name = x.Key, Template = x.Value }).ToList(), Options = options, Pager = pagerShape }; model.Options.ContentsBulkAction = new List <SelectListItem>() { new SelectListItem() { Text = S["Delete"], Value = nameof(ContentsBulkAction.Remove) } }; return(View("Index", model)); }
public async Task <IActionResult> Index(PagerParameters pagerParameters, bool adminTemplates = false) { if (!adminTemplates && !await _authorizationService.AuthorizeAsync(User, Permissions.ManageTemplates)) { return(Forbid()); } if (adminTemplates && !await _authorizationService.AuthorizeAsync(User, AdminTemplatesPermissions.ManageAdminTemplates)) { return(Forbid()); } var siteSettings = await _siteService.GetSiteSettingsAsync(); var pager = new Pager(pagerParameters, siteSettings.PageSize); var templatesDocument = adminTemplates ? await _adminTemplatesManager.GetTemplatesDocumentAsync() : await _templatesManager.GetTemplatesDocumentAsync() ; var count = templatesDocument.Templates.Count; var templates = templatesDocument.Templates.OrderBy(x => x.Key) .Skip(pager.GetStartIndex()) .Take(pager.PageSize); var pagerShape = (await New.Pager(pager)).TotalItemCount(count); var model = new TemplateIndexViewModel { AdminTemplates = adminTemplates, Templates = templates.Select(x => new TemplateEntry { Name = x.Key, Template = x.Value }).ToList(), Pager = pagerShape }; return(View("Index", model)); }
public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) { var allTemplatesStep = step as AllAdminTemplatesDeploymentStep; if (allTemplatesStep == null) { return; } var templateObjects = new JObject(); var templates = await _templatesManager.GetTemplatesDocumentAsync(); foreach (var template in templates.Templates) { templateObjects[template.Key] = JObject.FromObject(template.Value); } result.Steps.Add(new JObject( new JProperty("name", "AdminTemplates"), new JProperty("AdminTemplates", templateObjects) )); }
public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) { var allTemplatesStep = step as AllAdminTemplatesDeploymentStep; if (allTemplatesStep == null) { return; } var templateObjects = new JObject(); var templates = await _templatesManager.GetTemplatesDocumentAsync(); if (allTemplatesStep.ExportAsFiles) { foreach (var template in templates.Templates) { var fileName = "AdminTemplates/" + template.Key.Replace("__", "-").Replace("_", ".") + ".liquid"; var templateValue = new Template { Description = template.Value.Description, Content = $"[file:text('{fileName}')]" }; await result.FileBuilder.SetFileAsync(fileName, Encoding.UTF8.GetBytes(template.Value.Content)); templateObjects[template.Key] = JObject.FromObject(templateValue); } } else { foreach (var template in templates.Templates) { templateObjects[template.Key] = JObject.FromObject(template.Value); } } result.Steps.Add(new JObject( new JProperty("name", "AdminTemplates"), new JProperty("AdminTemplates", templateObjects) )); }