Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IEQEFCR
halo
提交
514ccdb2
H
halo
项目概览
IEQEFCR
/
halo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
halo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
514ccdb2
编写于
12月 09, 2021
作者:
G
guqing
提交者:
GitHub
12月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add some APIs for group obtaining theme configurations and setting items (#1582)
上级
dbf954e2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
87 addition
and
6 deletion
+87
-6
src/main/java/run/halo/app/controller/admin/api/ThemeController.java
...va/run/halo/app/controller/admin/api/ThemeController.java
+24
-0
src/main/java/run/halo/app/service/ThemeService.java
src/main/java/run/halo/app/service/ThemeService.java
+15
-3
src/main/java/run/halo/app/service/ThemeSettingService.java
src/main/java/run/halo/app/service/ThemeSettingService.java
+12
-0
src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java
...main/java/run/halo/app/service/impl/ThemeServiceImpl.java
+14
-1
src/main/java/run/halo/app/service/impl/ThemeSettingServiceImpl.java
...va/run/halo/app/service/impl/ThemeSettingServiceImpl.java
+22
-2
未找到文件。
src/main/java/run/halo/app/controller/admin/api/ThemeController.java
浏览文件 @
514ccdb2
...
...
@@ -3,6 +3,7 @@ package run.halo.app.controller.admin.api;
import
io.swagger.annotations.ApiOperation
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
...
...
@@ -18,17 +19,20 @@ import org.springframework.web.multipart.MultipartFile;
import
run.halo.app.annotation.DisableOnCondition
;
import
run.halo.app.cache.lock.CacheLock
;
import
run.halo.app.handler.theme.config.support.Group
;
import
run.halo.app.handler.theme.config.support.Item
;
import
run.halo.app.handler.theme.config.support.ThemeProperty
;
import
run.halo.app.model.params.ThemeContentParam
;
import
run.halo.app.model.support.BaseResponse
;
import
run.halo.app.model.support.ThemeFile
;
import
run.halo.app.service.ThemeService
;
import
run.halo.app.service.ThemeSettingService
;
import
run.halo.app.utils.ServiceUtils
;
/**
* Theme controller.
*
* @author ryanwang
* @author guqing
* @date 2019-03-20
*/
@RestController
...
...
@@ -137,6 +141,19 @@ public class ThemeController {
return
themeService
.
fetchConfig
(
themeId
);
}
@GetMapping
(
"{themeId:.+}/configurations/groups/{group}"
)
@ApiOperation
(
"Fetches theme configuration by theme id and group name"
)
public
Set
<
Item
>
fetchConfigByGroup
(
@PathVariable
(
"themeId"
)
String
themeId
,
@PathVariable
String
group
)
{
return
themeService
.
fetchConfigItemsBy
(
themeId
,
group
);
}
@GetMapping
(
"{themeId:.+}/configurations/groups"
)
@ApiOperation
(
"Fetches theme configuration group names by theme id"
)
public
Set
<
String
>
fetchConfigGroups
(
@PathVariable
(
"themeId"
)
String
themeId
)
{
return
ServiceUtils
.
fetchProperty
(
themeService
.
fetchConfig
(
themeId
),
Group:
:
getName
);
}
@GetMapping
(
"activation/settings"
)
@ApiOperation
(
"Lists activated theme settings"
)
public
Map
<
String
,
Object
>
listSettingsBy
()
{
...
...
@@ -149,6 +166,13 @@ public class ThemeController {
return
themeSettingService
.
listAsMapBy
(
themeId
);
}
@GetMapping
(
"{themeId:.+}/groups/{group}/settings"
)
@ApiOperation
(
"Lists theme settings by theme id and group name"
)
public
Map
<
String
,
Object
>
listSettingsBy
(
@PathVariable
(
"themeId"
)
String
themeId
,
@PathVariable
String
group
)
{
return
themeSettingService
.
listAsMapBy
(
themeId
,
group
);
}
@PostMapping
(
"activation/settings"
)
@ApiOperation
(
"Saves theme settings"
)
public
void
saveSettingsBy
(
@RequestBody
Map
<
String
,
Object
>
settings
)
{
...
...
src/main/java/run/halo/app/service/ThemeService.java
浏览文件 @
514ccdb2
...
...
@@ -3,10 +3,12 @@ package run.halo.app.service;
import
java.nio.file.Path
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Set
;
import
org.springframework.lang.NonNull
;
import
org.springframework.lang.Nullable
;
import
org.springframework.web.multipart.MultipartFile
;
import
run.halo.app.handler.theme.config.support.Group
;
import
run.halo.app.handler.theme.config.support.Item
;
import
run.halo.app.handler.theme.config.support.ThemeProperty
;
import
run.halo.app.model.support.ThemeFile
;
...
...
@@ -14,6 +16,7 @@ import run.halo.app.model.support.ThemeFile;
* Theme service interface.
*
* @author ryanwang
* @author guqing
* @date 2019-03-26
*/
public
interface
ThemeService
{
...
...
@@ -67,7 +70,7 @@ public interface ThemeService {
Optional
<
ThemeProperty
>
fetchThemePropertyBy
(
@Nullable
String
themeId
);
/**
* Gets all themes
* Gets all themes
.
*
* @return set of themes
*/
...
...
@@ -95,7 +98,7 @@ public interface ThemeService {
List
<
String
>
listCustomTemplates
(
@NonNull
String
themeId
,
@NonNull
String
prefix
);
/**
* Judging whether template exists under the specified theme
* Judging whether template exists under the specified theme
.
*
* @param template template must not be blank
* @return boolean
...
...
@@ -103,7 +106,7 @@ public interface ThemeService {
boolean
templateExists
(
@Nullable
String
template
);
/**
* Checks whether theme exists under template path
* Checks whether theme exists under template path
.
*
* @param themeId theme id
* @return boolean
...
...
@@ -169,6 +172,15 @@ public interface ThemeService {
@NonNull
List
<
Group
>
fetchConfig
(
@NonNull
String
themeId
);
/**
* Fetch config items by <code>themeId</code> and <code>group</code>.
*
* @param themeId theme id must not be blank
* @param group group name must not be blank
* @return config items
*/
Set
<
Item
>
fetchConfigItemsBy
(
@NonNull
String
themeId
,
String
group
);
/**
* Renders a theme page.
*
...
...
src/main/java/run/halo/app/service/ThemeSettingService.java
浏览文件 @
514ccdb2
...
...
@@ -2,9 +2,11 @@ package run.halo.app.service;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.springframework.lang.NonNull
;
import
org.springframework.lang.Nullable
;
import
org.springframework.transaction.annotation.Transactional
;
import
run.halo.app.handler.theme.config.support.Item
;
import
run.halo.app.model.entity.ThemeSetting
;
import
run.halo.app.service.base.CrudService
;
...
...
@@ -55,6 +57,16 @@ public interface ThemeSettingService extends CrudService<ThemeSetting, Integer>
@NonNull
Map
<
String
,
Object
>
listAsMapBy
(
@NonNull
String
themeId
);
/**
* Lists theme settings as map by <code>themeId</code> and <code>group</code> name.
*
* @param themeId theme id must not be blank.
* @param group theme group name must not be blank.
* @return theme setting map(key: item name, value: item)
*/
@NonNull
Map
<
String
,
Object
>
listAsMapBy
(
String
themeId
,
String
group
);
/**
* Delete unused theme setting.
*/
...
...
src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java
浏览文件 @
514ccdb2
...
...
@@ -6,8 +6,10 @@ import java.nio.file.Files;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.Collections
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -33,7 +35,7 @@ import run.halo.app.exception.ThemePropertyMissingException;
import
run.halo.app.exception.ThemeUpdateException
;
import
run.halo.app.handler.theme.config.ThemeConfigResolver
;
import
run.halo.app.handler.theme.config.support.Group
;
import
run.halo.app.handler.theme.config.support.
Option
;
import
run.halo.app.handler.theme.config.support.
Item
;
import
run.halo.app.handler.theme.config.support.ThemeProperty
;
import
run.halo.app.model.support.HaloConst
;
import
run.halo.app.model.support.ThemeFile
;
...
...
@@ -54,6 +56,7 @@ import run.halo.app.utils.FileUtils;
* Theme service implementation.
*
* @author ryanwang
* @author guqing
* @date 2019-03-26
*/
@Slf4j
...
...
@@ -296,6 +299,16 @@ public class ThemeServiceImpl implements ThemeService {
}
}
@Override
public
Set
<
Item
>
fetchConfigItemsBy
(
@NonNull
String
themeId
,
@NonNull
String
group
)
{
return
fetchConfig
(
themeId
).
stream
()
.
filter
(
g
->
StringUtils
.
equals
(
g
.
getName
(),
group
))
.
findFirst
()
.
map
(
Group:
:
getItems
)
.
map
(
items
->
(
Set
<
Item
>)
new
LinkedHashSet
<>(
items
))
.
orElseGet
(
Collections:
:
emptySet
);
}
@Override
public
String
render
(
String
pageName
)
{
var
folderName
=
getActivatedTheme
().
getFolderName
();
...
...
src/main/java/run/halo/app/service/impl/ThemeSettingServiceImpl.java
浏览文件 @
514ccdb2
...
...
@@ -10,6 +10,7 @@ import java.util.Optional;
import
java.util.Set
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.jetbrains.annotations.NotNull
;
import
org.springframework.data.domain.Example
;
import
org.springframework.lang.NonNull
;
import
org.springframework.stereotype.Service
;
...
...
@@ -121,6 +122,7 @@ public class ThemeSettingServiceImpl extends AbstractCrudService<ThemeSetting, I
}
}
@NonNull
@Override
public
List
<
ThemeSetting
>
listBy
(
String
themeId
)
{
assertThemeIdHasText
(
themeId
);
...
...
@@ -128,11 +130,30 @@ public class ThemeSettingServiceImpl extends AbstractCrudService<ThemeSetting, I
return
themeSettingRepository
.
findAllByThemeId
(
themeId
);
}
@NonNull
@Override
public
Map
<
String
,
Object
>
listAsMapBy
(
String
themeId
)
{
public
Map
<
String
,
Object
>
listAsMapBy
(
@NonNull
String
themeId
)
{
// Convert to item map(key: item name, value: item)
Map
<
String
,
Item
>
itemMap
=
getConfigItemMap
(
themeId
);
return
listAsMapBy
(
themeId
,
itemMap
);
}
@NonNull
@Override
public
Map
<
String
,
Object
>
listAsMapBy
(
String
themeId
,
String
group
)
{
// Convert to item map(key: item name, value: item)
Set
<
Item
>
items
=
themeService
.
fetchConfigItemsBy
(
themeId
,
group
);
Map
<
String
,
Item
>
itemMap
=
ServiceUtils
.
convertToMap
(
items
,
Item:
:
getName
);
return
listAsMapBy
(
themeId
,
itemMap
);
}
@NotNull
private
Map
<
String
,
Object
>
listAsMapBy
(
String
themeId
,
Map
<
String
,
Item
>
itemMap
)
{
Assert
.
notNull
(
themeId
,
"The themeId must not be null."
);
Assert
.
notNull
(
itemMap
,
"The itemMap must not be null."
);
// Get theme setting
List
<
ThemeSetting
>
themeSettings
=
listBy
(
themeId
);
...
...
@@ -170,7 +191,6 @@ public class ThemeSettingServiceImpl extends AbstractCrudService<ThemeSetting, I
result
.
put
(
name
,
convertedDefaultValue
);
});
return
result
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录