From 15037edbded71b3b0d86a1da8895c78b49a37679 Mon Sep 17 00:00:00 2001 From: hide_d Date: Fri, 20 Aug 2021 01:31:18 +0900 Subject: [PATCH] js2ts-fix: install --- hwe/install.php | 26 ++++++------- hwe/ts/install.ts | 89 +++++++++++++++++++++++--------------------- hwe/ts/install_db.ts | 8 ++-- 3 files changed, 62 insertions(+), 61 deletions(-) diff --git a/hwe/install.php b/hwe/install.php index cc1fdf20..de22cfa0 100644 --- a/hwe/install.php +++ b/hwe/install.php @@ -45,7 +45,7 @@ if($session->userGrade < 5 && !$allowReset){

설치(환경 설정) -

+
@@ -80,7 +80,7 @@ if($session->userGrade < 5 && !$allowReset){
- +
@@ -91,7 +91,7 @@ if($session->userGrade < 5 && !$allowReset){ - +
시간 단위에 맞게 년/월이 설정됩니다.
예: 120분(오전1시=1월), 60분(오전/오후 1시=1월) @@ -104,7 +104,7 @@ if($session->userGrade < 5 && !$allowReset){
- +
@@ -168,30 +168,30 @@ if($session->userGrade < 5 && !$allowReset){
- +
@@ -366,7 +366,7 @@ if($session->userGrade < 5 && !$allowReset){ - + diff --git a/hwe/ts/install.ts b/hwe/ts/install.ts index a6335d26..b02f8240 100644 --- a/hwe/ts/install.ts +++ b/hwe/ts/install.ts @@ -4,9 +4,7 @@ import { setAxiosXMLHttpRequest } from "./util/setAxiosXMLHttpRequest"; import axios from "axios"; import { InvalidResponse } from "./defs"; import { Rules } from "async-validator"; -import { isArray } from "lodash"; import { JQValidateForm } from "./util/jqValidateForm"; -import { unwrap } from "./util"; import { convertFormData } from "./util/convertFormData"; type ResponseScenarioItem = { @@ -121,95 +119,97 @@ function scenarioPreview() { if (scenario.npcEx_cnt == 0) { $npcEx.html(''); } else { - $npcEx.html('+{0}명'.format(scenario.npcEx_cnt)); + $npcEx.html(`+${scenario.npcEx_cnt}명`); } $nation.html(''); $.each(scenario.nation, function (idx, nation) { - $nation.append('{1} {2}명. {3}
'.format( - nation.color, nation.name, nation.generals, nation.cities.join(', ') - )); + $nation.append(`${nation.name} ${nation.generals}명. ${nation.cities.join(', ')}
`); }); } const descriptor: Rules = { turnterm: { required: true, + type: "enum", + enum: [1, 2, 5, 10, 20, 30, 60, 120], + transform: parseInt, }, sync: { required: true, + type: "enum", + enum: [1, 0], + transform: parseInt, }, scenario: { required: true, }, fiction: { required: true, + type: "integer", + transform: parseInt, }, extend: { required: true, + type: "integer", + transform: parseInt, }, npcmode: { required: true, + type: "integer", + transform: parseInt, }, show_img_level: { required: true, + type: "integer", + transform: parseInt, }, tournament_trig: { required: true, + type: "integer", + transform: parseInt, }, join_mode: { required: true, + type: "enum", + enum: ["full", "onlyRandom"] }, autorun_user: { type: 'array', + required: false, defaultField: { type: 'enum', - enum: ['develop', 'warp', 'recruit', 'recruit-high', 'train', 'battle'] + enum: ['develop', 'warp', 'recruit', 'recruit_high', 'train', 'battle'] }, }, autorun_user_minutes: { - type: 'number', + type: 'integer', required: true, + transform: parseInt, min: 0, validator: (rule, value, _callback, source) => { - if (!isArray(source.autorun_user)) { - return new Error('옵션이 올바른 타입이 아닙니다.'); + if(value == 0 && !source.autorun_user?.length){ + return true; } - if (source.autorun_user.length == 0 && parseInt(value) > 0) { - return new Error('유효 시간과 옵션은 동시에 설정해야합니다.'); + if(value != 0 && source.autorun_user?.length){ + return true; } + return new Error('유효 시간과 옵션은 동시에 설정해야합니다.'); } + }, + reserve_open: { + type: 'pattern', + pattern: new RegExp(/\d{4,4}-\d{2,2}-\d{2,2} \d{2,2}:\d{2,2}/) + }, + pre_reserve_open: { + type: 'pattern', + pattern: new RegExp(/\d{4,4}-\d{2,2}-\d{2,2} \d{2,2}:\d{2,2}/) } }; function formSetup() { - - const autorunMap: Map = new Map([ - ['autorun_develop', 'develop'], - ['autorun_warp', 'warp'], - ['autorun_recruit', 'recruit'], - ['autorun_recruit_high', 'recruit_high'], - ['autorun_train', 'train'], - ['autorun_battle', 'battle'], - ['autorun_chief', 'chief'], - ]); - const validator = new JQValidateForm($('#game_form'), descriptor, { - postParse: (values) => { - const newValues: Record & { autorun_user: string[] } = { - autorun_user: [] - }; - for (const [key, value] of Object.entries(values)) { - if (!autorunMap.has(key)) { - newValues[key] = value; - continue; - } - - const convValue = unwrap(autorunMap.get(key)); - newValues.autorun_user.push(convValue); - } - return newValues; - } - }); + const validator = new JQValidateForm($('#game_form'), descriptor); + validator.installChangeHandler(); $('#game_form').on('submit', async function (e) { e.preventDefault(); @@ -219,7 +219,7 @@ function formSetup() { } let result: InvalidResponse; - try{ + try { const response = await axios({ url: 'j_install.php', method: 'post', @@ -228,12 +228,12 @@ function formSetup() { }); result = response.data; } - catch(e){ + catch (e) { alert(`알수 없는 에러: ${e}`); return; } - if(!result.result){ + if (!result.result) { alert(result.reason); return; } @@ -248,4 +248,7 @@ $(async function () { void loadScenarios(); $('#scenario_sel').on('change', scenarioPreview); formSetup(); -}) \ No newline at end of file + +}) + +window.$ = $; \ No newline at end of file diff --git a/hwe/ts/install_db.ts b/hwe/ts/install_db.ts index 1c98feac..dcfe0435 100644 --- a/hwe/ts/install_db.ts +++ b/hwe/ts/install_db.ts @@ -20,9 +20,9 @@ jQuery(async function ($) { }, db_port: { type: 'integer', - validator: (rule, value: string) => { - const num = parseInt(value); - if (num <= 0 || num >= 65535) { + transform: parseInt, + validator: (rule, value: number) => { + if (value <= 0 || value >= 65535) { return new Error('올바른 포트 범위가 아닙니다.'); } return true; @@ -43,7 +43,6 @@ jQuery(async function ($) { }; const validator = new JQValidateForm($('#db_form'), descriptor); validator.installChangeHandler(); - $('#db_form').on('submit', async function (e) { e.preventDefault(); @@ -67,7 +66,6 @@ jQuery(async function ($) { alert(e); return false; } - if(!data.result){ alert(`에러: ${data.reason}`); return false;