示例#1
0
        public async Task <IActionResult> Index(PagerParameters pagerParameters)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageTemplates))
            {
                return(Unauthorized());
            }

            var siteSettings = await _siteService.GetSiteSettingsAsync();

            var pager             = new Pager(pagerParameters, siteSettings.PageSize);
            var templatesDocument = await _templatesManager.GetTemplatesDocumentAsync();

            var count = templatesDocument.Templates.Count;

            var templates = templatesDocument.Templates.OrderBy(x => x.Key)
                            .Skip(pager.GetStartIndex())
                            .Take(pager.PageSize);

            var pagerShape = New.Pager(pager).TotalItemCount(count);

            var model = new TemplateIndexViewModel
            {
                Templates = templates.Select(x => new TemplateEntry {
                    Name = x.Key, Template = x.Value
                }).ToList(),
                Pager = pagerShape
            };

            return(View(model));
        }
示例#2
0
        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 ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
        {
            var allTemplatesStep = step as AllTemplatesDeploymentStep;

            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", "Templates"),
                                 new JProperty("Templates", templateObjects)
                                 ));
        }
        public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
        {
            var allTemplatesStep = step as AllTemplatesDeploymentStep;

            if (allTemplatesStep == null)
            {
                return;
            }

            var templateObjects = new JObject();
            var templates       = await _templatesManager.GetTemplatesDocumentAsync();

            if (allTemplatesStep.ExportAsFiles)
            {
                foreach (var template in templates.Templates)
                {
                    var fileName      = "Templates/" + 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", "Templates"),
                                 new JProperty("Templates", templateObjects)
                                 ));
        }