Skip to content

Commit

Permalink
🎨 修改主题在线更新的逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Aug 29, 2018
1 parent 918f3f5 commit c5af7bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cc.ryanc.halo.model.dto.LogsRecord;
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
import cc.ryanc.halo.model.enums.ResultCodeEnum;
import cc.ryanc.halo.model.enums.TrueFalseEnum;
import cc.ryanc.halo.service.LogsService;
import cc.ryanc.halo.service.OptionsService;
import cc.ryanc.halo.utils.HaloUtils;
Expand Down Expand Up @@ -224,8 +225,15 @@ public JsonResult pullFromRemote(@RequestParam(value = "themeName") String theme
* @param theme theme名称
*/
@GetMapping(value = "/options")
public String setting(Model model, @RequestParam("theme") String theme) {
public String setting(Model model,
@RequestParam("theme") String theme,
@RequestParam("hasUpdate") String hasUpdate) {
model.addAttribute("themeDir", theme);
if (StringUtils.equals(hasUpdate, TrueFalseEnum.TRUE.getDesc())) {
model.addAttribute("hasUpdate", true);
} else {
model.addAttribute("hasUpdate", false);
}
return "themes/" + theme + "/module/options";
}

Expand Down
58 changes: 3 additions & 55 deletions src/main/resources/templates/admin/admin_theme.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@
<div class="box-footer">
<span class="theme-title">${theme.themeName?if_exists?upper_case}</span>
<#if theme.hasOptions>
<button class="btn btn-primary btn-sm pull-right btn-theme-setting" onclick="openSetting('${theme.themeName?if_exists}')" style="display: none">设置</button>
</#if>
<#if theme.hasUpdate>
<button class="btn btn-warning btn-sm pull-right btn-theme-update" data-loading-text="更新中..." onclick="updateTheme('${theme.themeName?if_exists}',this)" style="display: none;margin-right: 3px">更新</button>
<button class="btn btn-primary btn-sm pull-right btn-theme-setting" onclick="openSetting('${theme.themeName?if_exists}','<#if theme.hasUpdate>true<#else>false</#if>')" style="display: none">设置</button>
</#if>
<#if activeTheme != "${theme.themeName}">
<button class="btn btn-default btn-sm pull-right btn-theme-enable" onclick="setTheme('${theme.themeName?if_exists}')" style="display: none;margin-right: 3px">启用</button>
Expand Down Expand Up @@ -191,69 +188,20 @@
});
}
/**
* 更新主题
*/
function updateTheme(theme,e) {
$(e).button('loading');
$.ajax({
type: 'get',
url: '/admin/themes/pull',
data: {
'themeName': theme
},
success: function (data) {
if(data.code==1){
$.toast({
text: data.msg,
heading: '提示',
icon: 'success',
showHideTransition: 'fade',
allowToastClose: true,
hideAfter: 1000,
stack: 1,
position: 'top-center',
textAlign: 'left',
loader: true,
loaderBg: '#ffffff',
afterHidden: function () {
window.location.href="/admin/themes";
}
});
}else{
$.toast({
text: data.msg,
heading: '提示',
icon: 'error',
showHideTransition: 'fade',
allowToastClose: true,
hideAfter: 2000,
stack: 1,
position: 'top-center',
textAlign: 'left',
loader: true,
loaderBg: '#ffffff'
});
$(e).button('reset');
}
}
});
}
/**
* 打开主题设置
*
* @param theme 主题名
*/
function openSetting(theme) {
function openSetting(theme,hasUpdate) {
layer.open({
type: 2,
title: theme+'主题设置',
shadeClose: true,
shade: 0.5,
maxmin: true,
area: ['90%', '90%'],
content: '/admin/themes/options?theme='+theme,
content: '/admin/themes/options?theme='+theme+'&hasUpdate='+hasUpdate,
scrollbar: false
});
}
Expand Down

0 comments on commit c5af7bf

Please sign in to comment.