From 1e860e9443f87582e34e7782b4f135e05ea99bc5 Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 18 Aug 2021 02:59:58 +0900 Subject: [PATCH] =?UTF-8?q?js2ts=20&=20wip:=20install=20-=20jqValidateForm?= =?UTF-8?q?=EC=97=90=20=EC=A0=84/=ED=9B=84=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/install.php | 3 - hwe/ts/install.ts | 251 ++++++++++++++++++++++++++++++++++ hwe/ts/util/jqValidateForm.ts | 15 +- webpack.config.js | 1 + 4 files changed, 265 insertions(+), 5 deletions(-) create mode 100644 hwe/ts/install.ts diff --git a/hwe/install.php b/hwe/install.php index b88aba19..cc1fdf20 100644 --- a/hwe/install.php +++ b/hwe/install.php @@ -30,9 +30,6 @@ if($session->userGrade < 5 && !$allowReset){ - - - diff --git a/hwe/ts/install.ts b/hwe/ts/install.ts new file mode 100644 index 00000000..a6335d26 --- /dev/null +++ b/hwe/ts/install.ts @@ -0,0 +1,251 @@ +import $ from "jquery"; +import 'bootstrap'; +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 = { + year?: number, + title: string, + npc_cnt: number, + npcEx_cnt: number, + npcNeutral_cnt: number, + nation: Record +} + +type ExpandedScenarioItem = ResponseScenarioItem & { + category: string, + idx: string, + year: number, +} + +type ResponseScenario = { + result: true, + scenario: Record +} + +async function loadScenarios() { + + let result: InvalidResponse | ResponseScenario; + try { + const response = await axios({ + url: 'j_load_scenarios.php', + method: 'post', + responseType: 'json' + }); + result = response.data; + } + catch (e) { + alert(`시나리오를 불러오는데 실패했습니다.: ${e}`); + return; + } + + if (!result.result) { + alert(result.reason); + return; + } + + const list: Record> = {}; + const pat = /【(.*?)[0-9\-_.a-zA-Z]*】/; + + for (const [idx, value] of Object.entries(result.scenario)) { + const title = value.title || "-"; + const categoryRes = pat.exec(title); + const category = categoryRes ? categoryRes[1] : '-'; + + if (!(category in list)) { + list[category] = {}; + } + + list[category][idx] = { + ...value, + title: title, + category: category, + idx: idx, + year: value.year ?? 180 + }; + } + + + const $select = $('#scenario_sel'); + for (const [category, items] of Object.entries(list)) { + const $optgroup = $('').attr('label', category); + for (const [idx, scenario] of Object.entries(items)) { + const $option = $('