From cf0d205f75ab5abc6e4c7240ce3bbadbab310e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Thu, 3 Oct 2024 15:16:31 +0900 Subject: [PATCH] cfmgrv4 init...1 --- app/Config/Constants.php | 6 ++ app/Controllers/Admin/UserController.php | 59 +++--------- app/Controllers/MVController.php | 96 ++++++++++++------- app/Helpers/Admin/User_helper.php | 47 +++++++++ app/Views/admin/cloudflare/auth/index.php | 2 +- app/Views/admin/cloudflare/record/index.php | 2 +- app/Views/admin/cloudflare/zone/index.php | 2 +- app/Views/admin/mapurl/index.php | 2 +- app/Views/admin/user/index.php | 11 +-- app/Views/layouts/empty.php | 2 - .../admin/{actionform.php => iframe_form.php} | 0 .../templates/admin/iframe_form_close.php | 8 ++ .../admin/{modalform.php => modal_form.php} | 12 +++ .../templates/admin/modal_form_close.php | 8 ++ app/Views/templates/empty/footer.php | 64 ------------- app/Views/templates/empty/header.php | 0 16 files changed, 167 insertions(+), 154 deletions(-) rename app/Views/templates/admin/{actionform.php => iframe_form.php} (100%) create mode 100644 app/Views/templates/admin/iframe_form_close.php rename app/Views/templates/admin/{modalform.php => modal_form.php} (81%) create mode 100644 app/Views/templates/admin/modal_form_close.php delete mode 100644 app/Views/templates/empty/footer.php delete mode 100644 app/Views/templates/empty/header.php diff --git a/app/Config/Constants.php b/app/Config/Constants.php index a09cf8e..e746a14 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -101,6 +101,12 @@ define('DEFAULTS', [ 'DELIMITER_FILE' => "||", 'DELIMITER_ROLE' => ",", ]); +//FORM +define('FORMS', [ + 'MODAL' => 'modal_form', + 'IFRAME' => 'iframe_form', + 'ACTION' => 'action_form', +]); //URL define('URLS', [ 'LOGIN' => '/user/login', diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 3d84cbb..b8cf8cf 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -8,6 +8,7 @@ use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\Validation\Validation; use Psr\Log\LoggerInterface; class UserController extends AdminController @@ -28,6 +29,19 @@ class UserController extends AdminController } return $this->_model; } + protected function setFormFieldRule($field, Validation $validation, string $action): Validation + { + switch ($field) { + case 'role': + //아래 Rule Array는 필드명.* checkbox를 사용 + $validation->setRule($field . ".*", $field, $this->getModel()->getFieldRule($action, $field)); + break; + default: + $validation = parent::setFormFieldRule($field, $validation, $action); + break; + } + return $validation; + } protected function getFormFieldOption(string $field, array $options = []): array { switch ($field) { @@ -62,29 +76,6 @@ class UserController extends AdminController $this->field_options = $this->getFormFieldOptions($this->filter_fields); } //생성 - protected function create_validate(string $action, array $fields): void - { - //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 - $this->validation = service('validation'); - foreach ($fields as $field) { - switch ($field) { - case 'role': - //아래 Rule Array는 필드명.* checkbox를 사용 - $this->validation->setRule($field . ".*", $field, $this->getModel()->getFieldRule($action, $field)); - break; - default: - $this->validation->setRule($field, $field, $this->getModel()->getFieldRule($action, $field)); - break; - } - } - if (!$this->validation->withRequest($this->request)->run()) { - throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( - "\n", - $this->validation->getErrors() - )); - // redirect()->back()->withInput()->with('errors', $this->validation->getErrors()); - } - } public function create_form(): RedirectResponse|string { $this->init('create'); @@ -96,28 +87,6 @@ class UserController extends AdminController return $this->create_procedure(); } //수정 - protected function modify_validate(string $action, array $fields): void - { - //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 - $this->validation = service('validation'); - foreach ($fields as $field) { - switch ($field) { - case 'role': - //아래 Rule Array는 필드명.* checkbox를 사용 - $this->validation->setRule($field . ".*", $field, $this->getModel()->getFieldRule($action, $field)); - break; - default: - $this->validation->setRule($field, $field, $this->getModel()->getFieldRule($action, $field)); - break; - } - } - if (!$this->validation->withRequest($this->request)->run()) { - throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( - "\n", - $this->validation->getErrors() - )); - } - } public function modify_form(string $uid): RedirectResponse|string { $this->init('modify'); diff --git a/app/Controllers/MVController.php b/app/Controllers/MVController.php index a6ebef5..d892f4b 100644 --- a/app/Controllers/MVController.php +++ b/app/Controllers/MVController.php @@ -6,6 +6,7 @@ use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\Validation\Validation; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Reader\Html; use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf; @@ -17,8 +18,26 @@ abstract class MVController extends CommonController { parent::initController($request, $response, $logger); helper('common'); + $this->action_form = getenv("mvc.default.action.form") ?? "modal_form"; } abstract protected function getModel(): mixed; + //Field별 Form Rule용 + protected function setFormFieldRule($field, Validation $validation, string $action): Validation + { + switch ($field) { + default: + $validation->setRule($field, $field, $this->getModel()->getFieldRule($action, $field)); + break; + } + return $validation; + } + final protected function setFormFieldRules(array $fields, Validation $validation, string $action): Validation + { + foreach ($fields as $field) { + $validation = $this->setFormFieldRule($field, $validation, $action); + } + return $validation; + } //Field별 Form Option용 protected function getFormFieldOption(string $field, array $options): array { @@ -62,10 +81,7 @@ abstract class MVController extends CommonController protected function create_validate(string $action, array $fields): void { //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 - $this->validation = service('validation'); - foreach ($fields as $field) { - $this->validation->setRule($field, $field, $this->getModel()->getFieldRule($action, $field)); - } + $this->validation = $this->setFormFieldRules($fields, service('validation'), $action); if (!$this->validation->withRequest($this->request)->run()) { throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( "\n", @@ -103,10 +119,21 @@ abstract class MVController extends CommonController try { $this->create_process(); $this->getModel()->transCommit(); - log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); - // $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); - // return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); - return alert_CommonHelper(__FUNCTION__ . " => 작업을 완료하였습니다.\n"); + $this->message = "입력작업이 완료되었습니다."; + log_message("notice", __FUNCTION__ . $this->message); + switch ($this->action_form) { + case FORMS['MODAL']: + $result = view("templates/{$this->layout}/{$this->action_form}_close", data: ['viewDatas' => $this->getViewDatas()]); + break; + case FORMS['IFRAM']: + $result = view("templates/{$this->layout}/{$this->action_form}_close", data: ['viewDatas' => $this->getViewDatas()]); + break; + default: + $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], $this->message); + $result = redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + break; + } + return $result; } catch (\Exception $e) { //Transaction Rollback $this->getModel()->transRollback(); @@ -120,10 +147,7 @@ abstract class MVController extends CommonController protected function modify_validate(string $action, array $fields): void { //변경할 값 확인 : Upload된 파일 검증시 $this->request->getVar()보다 먼처 체크필요 - $this->validation = service('validation'); - foreach ($fields as $field) { - $this->validation->setRule($field, $field, $this->getModel()->getFieldRule($action, $field)); - } + $this->validation = $this->setFormFieldRules($fields, service('validation'), $action); if (!$this->validation->withRequest($this->request)->run()) { throw new \Exception("{$this->class_name} 작업 데이터 검증 오류발생\n" . implode( "\n", @@ -172,10 +196,21 @@ abstract class MVController extends CommonController try { $this->modify_process($uid); $this->getModel()->transCommit(); - log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); - // $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); - // return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); - return alert_CommonHelper(__FUNCTION__ . " => 작업을 완료하였습니다.\n"); + $this->message = "수정작업이 완료되었습니다."; + log_message("notice", __FUNCTION__ . $this->message); + switch ($this->action_form) { + case FORMS['MODAL']: + $result = view("templates/{$this->layout}/{$this->action_form}_close", data: ['viewDatas' => $this->getViewDatas()]); + break; + case FORMS['IFRAME']: + $result = view("templates/{$this->layout}/{$this->action_form}_close", data: ['viewDatas' => $this->getViewDatas()]); + break; + default: + $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], $this->message); + $result = redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); + break; + } + return $result; } catch (\Exception $e) { //Transaction Rollback $this->getModel()->transRollback(); @@ -193,25 +228,21 @@ abstract class MVController extends CommonController return $this->modify_procedure($uid); } //일괄처리작업 - protected function batcjob_process(): void - { - //변경할 UIDS - $uids = $this->request->getVar('batchjob_uids[]'); - if (!count($uids)) { - throw new \Exception("지정된 정보가 없습니다."); - } - $this->entitys = []; - foreach ($uids as $uid) { - $this->modify_process($uid); - $this->entitys = $this->entity; - } - } final protected function batcjob_procedure(): RedirectResponse { //Transaction Start $this->getModel()->transStart(); try { - $this->batcjob_process(); + //변경할 UIDS + $uids = $this->request->getVar('batchjob_uids[]'); + if (!count($uids)) { + throw new \Exception("지정된 정보가 없습니다."); + } + $this->entitys = []; + foreach ($uids as $uid) { + $this->modify_process($uid); + $this->entitys = $this->entity; + } $this->getModel()->transCommit(); log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); @@ -241,8 +272,9 @@ abstract class MVController extends CommonController try { $this->delete_process($uid); $this->getModel()->transCommit(); - log_message("notice", __FUNCTION__ . "=> 작업을 완료하였습니다."); - $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " => 작업을 완료하였습니다.\n"); + $message = "삭제작업을 완료하였습니다."; + log_message("notice", $message); + $this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], $message); return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/"); } catch (\Exception $e) { //Transaction Rollback diff --git a/app/Helpers/Admin/User_helper.php b/app/Helpers/Admin/User_helper.php index 5c8a2ec..1d82eb6 100644 --- a/app/Helpers/Admin/User_helper.php +++ b/app/Helpers/Admin/User_helper.php @@ -101,6 +101,53 @@ function getFieldView_UserHelper(string $field, UserEntity $entity, array $viewD } return $value; } // +function getListAction_UserHelper(string $action, $entity, array $viewDatas, array $extras = []): string +{ + switch ($action) { + case 'modify': + $cnt = $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $extras['cnt']); + $checkbox = form_checkbox([ + "id" => "checkbox_uid_{$entity->getPK()}", + "name" => "batchjob_uids[]", + "value" => $entity->getPK(), + "class" => "batchjobuids_checkboxs" + ]); + $url = current_url() . '/' . $action . '/' . $entity->getPK(); + switch ($viewDatas['action_form']) { + case FORMS['MODAL']: + $value = form_label( + $cnt, + "", + [ + "data-src" => $url, + "data-bs-toggle" => "modal", + "data-bs-target" => "#index_action_form", + ...$extras + ] + ); + break; + case FORMS['IFRAME']: + $value = form_label($cnt, "", [ + "onClick" => "changeIframe_src('{$url}')", + ...$extras + ]); + break; + default: + $value = anchor($url, $cnt, $extras); + break; + } + $result = $checkbox . $value; + break; + case 'delete': + $result = anchor( + current_url() . '/delete/' . $entity->getPK(), + ICONS['DELETE'], + ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self", ...$extras] + ); + break; + } + return $result; +} function getListColumns_UserHelper(string $field, array $viewDatas, array $extras = []): string { $label = getFieldLabel_UserHelper($field, $viewDatas, $extras); diff --git a/app/Views/admin/cloudflare/auth/index.php b/app/Views/admin/cloudflare/auth/index.php index 9c53ea9..30240c7 100644 --- a/app/Views/admin/cloudflare/auth/index.php +++ b/app/Views/admin/cloudflare/auth/index.php @@ -47,5 +47,5 @@
-include('templates/' . $viewDatas['layout'] . '/modalform'); ?> +include('templates/' . $viewDatas['layout'] . '/' . $viewDatas['action_form']); ?> endSection() ?> \ No newline at end of file diff --git a/app/Views/admin/cloudflare/record/index.php b/app/Views/admin/cloudflare/record/index.php index cd0342f..b692536 100644 --- a/app/Views/admin/cloudflare/record/index.php +++ b/app/Views/admin/cloudflare/record/index.php @@ -49,5 +49,5 @@
-include('templates/' . $viewDatas['layout'] . '/modalform'); ?> +include('templates/' . $viewDatas['layout'] . '/' . $viewDatas['action_form']); ?> endSection() ?> \ No newline at end of file diff --git a/app/Views/admin/cloudflare/zone/index.php b/app/Views/admin/cloudflare/zone/index.php index 6360e9d..37130cd 100644 --- a/app/Views/admin/cloudflare/zone/index.php +++ b/app/Views/admin/cloudflare/zone/index.php @@ -47,5 +47,5 @@
-include('templates/' . $viewDatas['layout'] . '/modalform'); ?> +include('templates/' . $viewDatas['layout'] . '/' . $viewDatas['action_form']); ?> endSection() ?> \ No newline at end of file diff --git a/app/Views/admin/mapurl/index.php b/app/Views/admin/mapurl/index.php index 8ec44ef..6cd89c0 100644 --- a/app/Views/admin/mapurl/index.php +++ b/app/Views/admin/mapurl/index.php @@ -47,5 +47,5 @@
-include('templates/' . $viewDatas['layout'] . '/modalform'); ?> +include('templates/' . $viewDatas['layout'] . '/' . $viewDatas['action_form']); ?> endSection() ?> \ No newline at end of file diff --git a/app/Views/admin/user/index.php b/app/Views/admin/user/index.php index 2df1912..beb9192 100644 --- a/app/Views/admin/user/index.php +++ b/app/Views/admin/user/index.php @@ -17,18 +17,15 @@ - status != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?>> + status != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?>> - "checkbox_uid_{$entity->getPK()}", "name" => "batchjob_uids[]", "value" => $entity->getPK(), "class" => "batchjobuids_checkboxs"]); ?> - - - + $cnt, "style" => "cursor:pointer"]) ?> - getPK(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?> + @@ -47,5 +44,5 @@
-include('templates/' . $viewDatas['layout'] . '/modalform'); ?> +include('templates/' . $viewDatas['layout'] . '/' . $viewDatas['action_form']); ?> endSection() ?> \ No newline at end of file diff --git a/app/Views/layouts/empty.php b/app/Views/layouts/empty.php index bfb5042..2631393 100644 --- a/app/Views/layouts/empty.php +++ b/app/Views/layouts/empty.php @@ -23,9 +23,7 @@ -
include('templates/empty/header'); ?>
renderSection('content') ?>
- \ No newline at end of file diff --git a/app/Views/templates/admin/actionform.php b/app/Views/templates/admin/iframe_form.php similarity index 100% rename from app/Views/templates/admin/actionform.php rename to app/Views/templates/admin/iframe_form.php diff --git a/app/Views/templates/admin/iframe_form_close.php b/app/Views/templates/admin/iframe_form_close.php new file mode 100644 index 0000000..48dc854 --- /dev/null +++ b/app/Views/templates/admin/iframe_form_close.php @@ -0,0 +1,8 @@ +extend("layouts/empty") ?> +section('content') ?> +
+
+

작업 완료 후 아래 버튼을 클릭하면 모달이 닫힙니다.

+ +
+endSection() ?> \ No newline at end of file diff --git a/app/Views/templates/admin/modalform.php b/app/Views/templates/admin/modal_form.php similarity index 81% rename from app/Views/templates/admin/modalform.php rename to app/Views/templates/admin/modal_form.php index 49e9786..aafee54 100644 --- a/app/Views/templates/admin/modalform.php +++ b/app/Views/templates/admin/modal_form.php @@ -27,6 +27,18 @@ iframe.style.height = iframe.contentWindow.document.body.scrollHeight + 'px'; } + function closeBootstrapModal() { + var modalElement = document.getElementById('index_action_form'); // 모달의 실제 DOM 요소 가져오기 + var modalInstance = bootstrap.Modal.getInstance(modalElement); // 모달 인스턴스 가져오기 + if (modalInstance) { + // 먼저 모달을 호출한 페이지를 리로드 + window.location.reload(); + modalInstance.hide(); // 모달 닫기 (hide() 메서드 사용) + } else { + console.error("Modal instance not found."); + } + } + var index_action_form = document.getElementById('index_action_form'); index_action_form.addEventListener('show.bs.modal', function(event) { // 버튼이 클릭된 이벤트를 가져옴 diff --git a/app/Views/templates/admin/modal_form_close.php b/app/Views/templates/admin/modal_form_close.php new file mode 100644 index 0000000..a48a201 --- /dev/null +++ b/app/Views/templates/admin/modal_form_close.php @@ -0,0 +1,8 @@ +extend("layouts/empty") ?> +section('content') ?> +
+
+

작업 완료 후 아래 버튼을 클릭하면 모달이 닫힙니다.

+ +
+endSection() ?> \ No newline at end of file diff --git a/app/Views/templates/empty/footer.php b/app/Views/templates/empty/footer.php deleted file mode 100644 index 099ead1..0000000 --- a/app/Views/templates/empty/footer.php +++ /dev/null @@ -1,64 +0,0 @@ -getFlashdata(SESSION_NAMES['RETURN_MSG']) ? alert_CommonHelper($viewDatas['session']->getFlashdata(SESSION_NAMES['RETURN_MSG'])) : "" ?> - \ No newline at end of file diff --git a/app/Views/templates/empty/header.php b/app/Views/templates/empty/header.php deleted file mode 100644 index e69de29..0000000