From 0530171e5ffbb87d768517c98686d0fa981427b9 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Fri, 5 Apr 2019 20:18:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../run/halo/app/model/support/Theme.java | 4 +-- .../app/service/impl/ThemeServiceImpl.java | 25 +++++++++++++------ .../controller/admin/api/AdminController.java | 5 ++++ .../admin/api/CategoryController.java | 12 ++++----- .../controller/admin/api/ThemeController.java | 10 ++++---- 5 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/main/java/run/halo/app/model/support/Theme.java b/src/main/java/run/halo/app/model/support/Theme.java index eef1216ff..f6238ff24 100644 --- a/src/main/java/run/halo/app/model/support/Theme.java +++ b/src/main/java/run/halo/app/model/support/Theme.java @@ -16,9 +16,9 @@ public class Theme implements Serializable { private static final long serialVersionUID = 1L; /** - * Theme dir + * Theme key,is theme folder name. */ - private String themeDir; + private String key; /** * Is support setting options diff --git a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java index f19b9fbca..aa114c6c0 100644 --- a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java @@ -26,7 +26,16 @@ import java.util.List; @Service public class ThemeServiceImpl implements ThemeService { + /** + * The type of file that can be modified. + */ private static String[] CAN_EDIT_SUFFIX = {"ftl", "css", "js"}; + + /** + * These file names cannot be displayed. + */ + private static String[] FILTER_FILES = {".git", ".DS_Store", "theme.properties"}; + private final HaloProperties haloProperties; public ThemeServiceImpl(HaloProperties haloProperties) { @@ -50,13 +59,9 @@ public class ThemeServiceImpl implements ThemeService { continue; } theme = new Theme(); - theme.setThemeDir(file.getName()); - File optionsPath = new File(getThemeBasePath().getAbsolutePath(), file.getName() + "/module/options.ftl"); - if (optionsPath.exists()) { - theme.setHasOptions(true); - } else { - theme.setHasOptions(false); - } + theme.setKey(file.getName()); + File optionsPath = new File(file.getAbsolutePath(), "module/options.ftl"); + theme.setHasOptions(optionsPath.exists()); theme.setProperties(getProperties(new File(getThemeBasePath(), file.getName()))); themes.add(theme); } @@ -80,7 +85,13 @@ public class ThemeServiceImpl implements ThemeService { File absolutePathFile = new File(absolutePath); File[] baseFiles = absolutePathFile.listFiles(); if (null != baseFiles) { + baseFileFor: for (File base : baseFiles) { + for (String filterFile : FILTER_FILES) { + if (filterFile.equals(base.getName())) { + continue baseFileFor; + } + } ThemeFile file = new ThemeFile(); if (base.isDirectory()) { file.setName(base.getName()); diff --git a/src/main/java/run/halo/app/web/controller/admin/api/AdminController.java b/src/main/java/run/halo/app/web/controller/admin/api/AdminController.java index f2a17961f..9dbd3ac33 100644 --- a/src/main/java/run/halo/app/web/controller/admin/api/AdminController.java +++ b/src/main/java/run/halo/app/web/controller/admin/api/AdminController.java @@ -54,6 +54,11 @@ public class AdminController { this.linkService = linkService; } + /** + * Get some statistics about the count of posts, the count of comments, etc. + * + * @return counts + */ @GetMapping("counts") @ApiOperation("Gets count info") public CountOutputDTO getCount() { diff --git a/src/main/java/run/halo/app/web/controller/admin/api/CategoryController.java b/src/main/java/run/halo/app/web/controller/admin/api/CategoryController.java index fa00740c5..513e0a679 100644 --- a/src/main/java/run/halo/app/web/controller/admin/api/CategoryController.java +++ b/src/main/java/run/halo/app/web/controller/admin/api/CategoryController.java @@ -1,11 +1,5 @@ package run.halo.app.web.controller.admin.api; -import run.halo.app.model.dto.CategoryOutputDTO; -import run.halo.app.model.entity.Category; -import run.halo.app.model.params.CategoryParam; -import run.halo.app.model.vo.CategoryVO; -import run.halo.app.service.CategoryService; -import run.halo.app.service.PostCategoryService; import io.swagger.annotations.ApiOperation; import org.springframework.data.domain.Sort; import org.springframework.data.web.SortDefault; @@ -41,6 +35,12 @@ public class CategoryController { this.postCategoryService = postCategoryService; } + @GetMapping + @ApiOperation("List all categories") + public List listAll() { + return categoryService.listAll(); + } + @GetMapping("tree_view") @ApiOperation("List as category tree") public List listAsTree(@SortDefault(sort = "name", direction = ASC) Sort sort) { diff --git a/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java b/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java index 204363c6d..a0a2db873 100644 --- a/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java +++ b/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java @@ -81,18 +81,18 @@ public class ThemeController { /** * Active theme * - * @param themeName theme name + * @param theme theme name * @throws TemplateModelException TemplateModelException */ @GetMapping(value = "active") @ApiOperation("Active theme") - public void active(@RequestParam(name = "themeName", defaultValue = "anatole") String themeName) throws TemplateModelException { + public void active(@RequestParam(name = "theme", defaultValue = "anatole") String theme) throws TemplateModelException { Map properties = new HashMap<>(1); - properties.put(PrimaryProperties.THEME, themeName); + properties.put(PrimaryProperties.THEME, theme); // TODO Refactor: saveProperties => saveProperty optionService.saveProperties(properties, OptionSource.SYSTEM); - HaloConst.ACTIVATED_THEME_NAME = themeName; - configuration.setSharedVariable("themeName", themeName); + HaloConst.ACTIVATED_THEME_NAME = theme; + configuration.setSharedVariable("themeName", theme); configuration.setSharedVariable("options", optionService.listOptions()); } }