From 3c3861c3e3f68b1d8a8a5698551ecee1377507ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Sun, 14 Sep 2025 19:55:57 +0900 Subject: [PATCH] dbmsv2 init...1 --- .../Admin/Customer/ClientController.php | 6 +- .../Admin/Customer/ServiceController.php | 6 +- .../Admin/Equipment/LineController.php | 19 +++-- .../Admin/Equipment/ServerController.php | 20 +----- .../Admin/Equipment/ServerPartController.php | 33 ++++++++- app/Controllers/Admin/UserController.php | 6 +- app/Controllers/Auth/AuthController.php | 6 +- app/Controllers/CommonController.php | 71 ++++++++----------- app/Services/CommonService.php | 21 ++++++ app/Services/Customer/ServiceService.php | 1 + app/Services/Equipment/IPService.php | 36 ---------- app/Services/Equipment/ServerPartService.php | 23 +++++- app/Services/Equipment/ServerService.php | 18 +++++ app/Views/admin/serverpart/create_form.php | 1 - public/js/admin/serverpart.js | 34 +++++---- 15 files changed, 166 insertions(+), 135 deletions(-) diff --git a/app/Controllers/Admin/Customer/ClientController.php b/app/Controllers/Admin/Customer/ClientController.php index 03d294a..438c912 100644 --- a/app/Controllers/Admin/Customer/ClientController.php +++ b/app/Controllers/Admin/Customer/ClientController.php @@ -103,7 +103,7 @@ class ClientController extends CustomerController $this->getService()->setFormFilters(); $this->getService()->setFormRules(); //기본값정의 - $this->setFormDatas($this->request->getGet()); + $this->getService()->setFormDatas($this->request->getGet()); $this->getService()->setFormOptions(); //일괄작업용 Fields정의 $entity = $this->getService()->getEntity($uid); @@ -139,14 +139,14 @@ class ClientController extends CustomerController $this->getService()->setFormFilters(); $this->getService()->setFormRules(); //전달값정의 - $this->setFormDatas($this->request->getPost()); + $this->getService()->setFormDatas($this->request->getPost()); $this->doValidations(); //기존 Entity 가져오기 $entity = $this->getService()->getEntity($uid); if (!$entity) { throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } - $this->entity = $this->getService()->history($entity, $this->getFormDatas()); + $this->entity = $this->getService()->history($entity, $this->getService()->getFormDatas()); $db->transCommit(); return $this->getResultSuccess('고객 비고가 수정되었습니다.'); } catch (\Exception $e) { diff --git a/app/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php index 658b276..d9b71bd 100644 --- a/app/Controllers/Admin/Customer/ServiceController.php +++ b/app/Controllers/Admin/Customer/ServiceController.php @@ -69,7 +69,7 @@ class ServiceController extends CustomerController throw new \Exception(__METHOD__ . "에서 code의 format[Server.Prefix.code.format]이 정의되지 않았습니다."); } //기본값정의 - $this->setFormDatas([ + $this->getService()->setFormDatas([ 'location' => 'chiba', 'type' => 'normal', 'billing_at' => date("Y-m-d"), @@ -116,14 +116,14 @@ class ServiceController extends CustomerController $this->getService()->setFormFilters(); $this->getService()->setFormRules(); //전달값정의 - $this->setFormDatas($this->request->getPost()); + $this->getService()->setFormDatas($this->request->getPost()); $this->doValidations(); //기존 Entity 가져오기 $entity = $this->getService()->getEntity($uid); if (!$entity) { throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } - $this->entity = $this->getService()->history($entity, $this->getFormDatas()); + $this->entity = $this->getService()->history($entity, $this->getService()->getFormDatas()); $db->transCommit(); return $this->getResultSuccess('서비스객 비고가 수정되었습니다.'); } catch (\Exception $e) { diff --git a/app/Controllers/Admin/Equipment/LineController.php b/app/Controllers/Admin/Equipment/LineController.php index 67c15ac..ba814f4 100644 --- a/app/Controllers/Admin/Equipment/LineController.php +++ b/app/Controllers/Admin/Equipment/LineController.php @@ -2,14 +2,15 @@ namespace App\Controllers\Admin\Equipment; -use App\Entities\Equipment\LineEntity; -use App\Helpers\Equipment\LineHelper; -use App\Services\Equipment\IPService; +use Psr\Log\LoggerInterface; +use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\HTTP\RequestInterface; use App\Services\Equipment\LineService; -use CodeIgniter\HTTP\RequestInterface; -use CodeIgniter\HTTP\ResponseInterface; -use Psr\Log\LoggerInterface; +use App\Services\Equipment\IPService; +use App\Helpers\Equipment\LineHelper; +use App\Entities\Equipment\LineEntity; +use App\Entities\Equipment\IPEntity; class LineController extends EquipmentController { @@ -50,7 +51,11 @@ class LineController extends EquipmentController $entity = parent::create_process($formDatas); //Prefixed IP to array 자동 등록 foreach ($this->getService()->getHelper()->cidrToIpRange($formDatas['bandwith']) as $ip) { - $this->getIPService()->createByLineInfo($entity, $ip); + $this->getIPService()->create([ + 'lineinfo_uid' => $entity->getPK(), + 'ip' => $ip, + 'status' => IPEntity::DEFAULT_STATUS, + ]); } return $entity; } diff --git a/app/Controllers/Admin/Equipment/ServerController.php b/app/Controllers/Admin/Equipment/ServerController.php index a964209..f55f9e1 100644 --- a/app/Controllers/Admin/Equipment/ServerController.php +++ b/app/Controllers/Admin/Equipment/ServerController.php @@ -49,24 +49,6 @@ class ServerController extends EquipmentController } return $result; } - protected function setFormData(string $field, array $requestDatas, array $formDatas): array - { - switch ($field) { - case 'CPU': - case 'RAM': - $formDatas[$field] = $requestDatas[$field] ?? null; - $formDatas["{$field}_cnt"] = $requestDatas["{$field}_cnt"] ?? null; - break; - case 'DISK': - $formDatas[$field] = $requestDatas[$field] ?? null; - $formDatas["{$field}_cnt"] = $requestDatas["{$field}_cnt"] ?? null; - $formDatas["{$field}_extra"] = $requestDatas["{$field}_extra"] ?? null; - break; - default: - $formDatas = parent::setFormData($field, $requestDatas, $formDatas); - } - return $formDatas; - } //생성 protected function create_form_process(): void { @@ -75,7 +57,7 @@ class ServerController extends EquipmentController throw new \Exception(__METHOD__ . "에서 code의 format[Server.Prefix.code.format]이 정의되지 않았습니다."); } //기본값정의 - $this->setFormDatas([ + $this->getService()->setFormDatas([ 'code' => $this->getService()->getLastestCode( $format, (int)env("Server.Default.code", 0) diff --git a/app/Controllers/Admin/Equipment/ServerPartController.php b/app/Controllers/Admin/Equipment/ServerPartController.php index efa9a1b..0314c6b 100644 --- a/app/Controllers/Admin/Equipment/ServerPartController.php +++ b/app/Controllers/Admin/Equipment/ServerPartController.php @@ -2,10 +2,11 @@ namespace App\Controllers\Admin\Equipment; -use App\Services\Equipment\ServerPartService; -use CodeIgniter\HTTP\RequestInterface; -use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; +use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\HTTP\RequestInterface; +use CodeIgniter\HTTP\RedirectResponse; +use App\Services\Equipment\ServerPartService; class ServerPartController extends EquipmentController { @@ -24,4 +25,30 @@ class ServerPartController extends EquipmentController } return $this->_service; } + //Index,FieldForm관련 + protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string + { + switch ($this->getService()->getAction()) { + case 'create_form': + case 'modify_form': + $this->service = $this->getService(); + $this->control = $this->getService()->getControlDatas(); + $this->getService()->getHelper()->setViewDatas($this->getViewDatas()); + $actionTemplate = $this->request->getVar('ActionTemplate') ?? $actionTemplate ?? 'serverpart'; + if ($actionTemplate) { + $view_file = $this->view_path . $actionTemplate . DIRECTORY_SEPARATOR . $this->getService()->getAction(); + } else { + $view_file = $this->view_path . $this->getService()->getAction(); + } + $result = view($view_file, ['viewDatas' => $this->getViewDatas()]); + break; + case 'history': + $result = redirect()->to($this->request->getGET('return_url'))->with('error', $message); + break; + default: + $result = parent::getResultSuccess($message, $actionTemplate); + break; + } + return $result; + } } diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 87c33ee..9562bce 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -82,7 +82,7 @@ class UserController extends AdminController $this->getService()->setFormRules(); $this->getService()->setFormOptions(); //기본값정의 - $this->setFormDatas($this->request->getGet()); + $this->getService()->setFormDatas($this->request->getGet()); //기존 Entity 가져오기 $entity = $this->getService()->getEntity($uid); if (!$entity) { @@ -107,14 +107,14 @@ class UserController extends AdminController $this->getService()->setFormFilters(); $this->getService()->setFormRules(); //전달값정의 - $this->setFormDatas($this->request->getPost()); + $this->getService()->setFormDatas($this->request->getPost()); $this->doValidations(); //기존 Entity 가져오기 $entity = $this->getService()->getEntity($uid); if (!$entity) { throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } - $this->entity = $this->modify_process($entity, $this->getFormDatas()); + $this->entity = $this->modify_process($entity, $this->getService()->getFormDatas()); $this->_db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { diff --git a/app/Controllers/Auth/AuthController.php b/app/Controllers/Auth/AuthController.php index 19f91e6..f8f7098 100644 --- a/app/Controllers/Auth/AuthController.php +++ b/app/Controllers/Auth/AuthController.php @@ -61,7 +61,7 @@ abstract class AuthController extends CommonController $this->getService()->setFormRules(); $this->getService()->setFormOptions(); //기본값정의 - $this->setFormDatas($this->request->getGet()); + $this->getService()->setFormDatas($this->request->getGet()); $this->login_form_process(); helper(['form']); $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; @@ -82,9 +82,9 @@ abstract class AuthController extends CommonController $this->getService()->setFormFilters(); $this->getService()->setFormRules(); //전달값정의 - $this->setFormDatas($this->request->getPost()); + $this->getService()->setFormDatas($this->request->getPost()); $this->doValidations(); - $this->entity = $this->login_process($this->getFormDatas()); + $this->entity = $this->login_process($this->getService()->getFormDatas()); $db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 5dae1c2..e333bf5 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -66,17 +66,6 @@ abstract class CommonController extends BaseController } //Index,FieldForm관련 //FormDatas 전달값,Default값 - final protected function getFormDatas(): array - { - return $this->getService()->getControlDatas('form_datas'); - } - final protected function setFormDatas(array $requestDatas, array $formDatas = []): void - { - foreach ($this->getService()->getControlDatas('actionFields') as $field) { - $formDatas = $this->setFormData($field, $requestDatas, $formDatas); - } - $this->getService()->setControlDatas('form_datas', $formDatas); - } //FormDatas 검증 final protected function doValidations(): void { @@ -85,7 +74,7 @@ abstract class CommonController extends BaseController foreach ($this->getService()->getControlDatas('field_rules') as $field => $rule) { $validation = $this->doValidation($validation, $field, $rule); } - if (!$validation->run($this->getFormDatas())) { + if (!$validation->run($this->getService()->getFormDatas())) { throw new \Exception("{$this->getService()->getClassName()} 작업 데이터 검증 오류발생\n" . implode( "\n", $validation->getErrors() @@ -94,17 +83,7 @@ abstract class CommonController extends BaseController // return $validation->getValidated(); } //공통 필수기능 - //FieldForm관련용 //FormData Field별 전달값 처리 - protected function setFormData(string $field, array $requestDatas, array $formDatas): array - { - switch ($field) { - default: - $formDatas[$field] = $requestDatas[$field] ?? null; - break; - } - return $formDatas; - } protected function doValidation(Validation $validation, string $field, string $rule): Validation { switch ($field) { @@ -161,13 +140,14 @@ abstract class CommonController extends BaseController public function create_form(): RedirectResponse|string { try { + //초기화 $this->getService()->setAction(__FUNCTION__); $this->getService()->setFormFields(); + //기본전달값정의 + $this->getService()->setFormDatas($this->request->getGet()); $this->getService()->setFormFilters(); $this->getService()->setFormRules(); $this->getService()->setFormOptions(); - //기본값정의 - $this->setFormDatas($this->request->getGet()); $this->create_form_process(); helper(['form']); $this->forms = ['attributes' => ['method' => "post",], 'hiddens' => []]; @@ -188,12 +168,12 @@ abstract class CommonController extends BaseController try { $this->getService()->setAction(__FUNCTION__); $this->getService()->setFormFields(); + //기본전달값정의 + $this->getService()->setFormDatas($this->request->getPost()); $this->getService()->setFormFilters(); $this->getService()->setFormRules(); - //전달값정의 - $this->setFormDatas($this->request->getPost()); $this->doValidations(); - $this->entity = $this->create_process($this->getFormDatas()); + $this->entity = $this->create_process($this->getService()->getFormDatas()); $db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { @@ -211,11 +191,11 @@ abstract class CommonController extends BaseController try { $this->getService()->setAction(__FUNCTION__); $this->getService()->setFormFields(); + //기본전달값정의 + $this->getService()->setFormDatas($this->request->getGet()); $this->getService()->setFormFilters(); $this->getService()->setFormRules(); $this->getService()->setFormOptions(); - //기본값정의 - $this->setFormDatas($this->request->getGet()); //기존 Entity 가져오기 $entity = $this->getService()->getEntity($uid); if (!$entity) { @@ -241,17 +221,17 @@ abstract class CommonController extends BaseController try { $this->getService()->setAction(__FUNCTION__); $this->getService()->setFormFields(); + //기본전달값정의 + $this->getService()->setFormDatas($this->request->getPost()); $this->getService()->setFormFilters(); $this->getService()->setFormRules(); - //전달값정의 - $this->setFormDatas($this->request->getPost()); $this->doValidations(); //기존 Entity 가져오기 $entity = $this->getService()->getEntity($uid); if (!$entity) { throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } - $this->entity = $this->modify_process($entity, $this->getFormDatas()); + $this->entity = $this->modify_process($entity, $this->getService()->getFormDatas()); $db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { @@ -272,18 +252,18 @@ abstract class CommonController extends BaseController try { $this->getService()->setAction(__FUNCTION__); $this->getService()->setFormFields([$field]); + //기본전달값정의 + $this->getService()->setFormDatas($this->request->getGet()); $this->getService()->setFormFilters(); $this->getService()->setFormRules(); $this->getService()->setFormOptions(); - //기본값정의 - $this->setFormDatas($this->request->getGet()); $this->doValidations(); //기존 Entity 가져오기 $entity = $this->getService()->getEntity($uid); if (!$entity) { throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } - $this->entity = $this->toggle_process($entity, $this->getFormDatas()); + $this->entity = $this->toggle_process($entity, $this->getService()->getFormDatas()); $db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { @@ -326,11 +306,11 @@ abstract class CommonController extends BaseController $this->getService()->setAction(__FUNCTION__); list($selectedFields, $formDatas, $uids) = $this->batchjob_pre_process(); $this->getService()->setFormFields($selectedFields); + //기본전달값정의 + $this->getService()->setFormDatas($this->request->getPost()); $this->getService()->setFormFilters(); $this->getService()->setFormRules(); $this->getService()->setFormOptions(); - //기본값정의 - $this->setFormDatas($this->request->getPost()); $this->doValidations(); $entities = []; foreach ($uids as $uid) { @@ -425,11 +405,11 @@ abstract class CommonController extends BaseController try { $this->getService()->setAction(__FUNCTION__); $this->getService()->setFormFields(); + //기본전달값정의 + $this->getService()->setFormDatas($this->request->getGet()); $this->getService()->setFormFilters(); $this->getService()->setFormRules(); $this->getService()->setFormOptions(); - //기본값정의 - $this->setFormDatas($this->request->getGet()); //기존 Entity 가져오기 $entity = $this->getService()->getEntity($uid); if (!$entity) { @@ -510,11 +490,11 @@ abstract class CommonController extends BaseController try { $this->getService()->setAction(__FUNCTION__); $this->getService()->setFormFields(); + //기본전달값정의 + $this->getService()->setFormDatas($this->request->getGet()); $this->getService()->setFormFilters(); $this->getService()->setFormRules(); $this->getService()->setFormOptions(); - //기본값정의 - $this->setFormDatas($this->request->getGet()); //일괄작업용 Fields정의 $this->getService()->setControlDatas('batchjob_fields', $this->getService()->getBatchjobFields()); //일괄작업용 버튼정의 @@ -546,7 +526,7 @@ abstract class CommonController extends BaseController } } //OUPUT Document 관련 - private function download_process(string $document_type, mixed $loaded_data): array + protected function download_process(string $document_type, mixed $loaded_data): array { $full_path = WRITEPATH . DIRECTORY_SEPARATOR . "excel"; switch ($document_type) { @@ -569,6 +549,8 @@ abstract class CommonController extends BaseController try { $this->getService()->setAction(__FUNCTION__); $this->getService()->setFormFields(); + //기본전달값정의 + $this->getService()->setFormDatas($this->request->getGet()); $this->getService()->setFormFilters(); $this->getService()->setFormRules(); $this->getService()->setFormOptions(); @@ -578,7 +560,10 @@ abstract class CommonController extends BaseController case 'excel': case 'pdf': helper(['form']); - $this->index_process(); + foreach ($this->getService()->getEntities() as $entity) { + $entities[] = $entity; + } + $this->entities = $entities; $html = $this->getResultSuccess(); //data loading $reader = new Html(); diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 23fc8fd..5bd3ab9 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -191,6 +191,18 @@ abstract class CommonService throw new \Exception($message); } } // + final public function getFormDatas(): array + { + return $this->getControlDatas('form_datas'); + } + final public function setFormDatas(array $requestDatas, array $formDatas = []): void + { + foreach ($this->getControlDatas('actionFields') as $field) { + $formDatas = $this->setFormData($field, $requestDatas, $formDatas); + } + $this->setControlDatas('form_datas', $formDatas); + } + //기본 기능부분 //FieldForm관련용 public function getViewFields(): array { @@ -250,6 +262,15 @@ abstract class CommonService } return $rule; } + public function setFormData(string $field, array $requestDatas, array $formDatas): array + { + switch ($field) { + default: + $formDatas[$field] = $requestDatas[$field] ?? null; + break; + } + return $formDatas; + } //생성 public function create(array $formDatas): mixed { diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index a20d362..300b749 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -27,6 +27,7 @@ class ServiceService extends CustomerService "location", "type", "clientinfo_uid", + 'serverinfo_uid', "billing_at", "amount", "start_at", diff --git a/app/Services/Equipment/IPService.php b/app/Services/Equipment/IPService.php index 04118aa..c1165a5 100644 --- a/app/Services/Equipment/IPService.php +++ b/app/Services/Equipment/IPService.php @@ -78,42 +78,6 @@ class IPService extends EquipmentService } return $options; } - //회선정보에 따른 IP생성 - public function createByLineInfo(LineEntity $entity, string $ip): IPEntity - { - $formDatas = [ - 'lineinfo_uid' => $entity->getPK(), - 'ip' => $ip, - 'status' => IPEntity::DEFAULT_STATUS, - ]; - return $this->create($formDatas); - } - private function getFormDatasByServer(ServerEntity $serverEntity, array $formDatas): array - { - $temps = [ - "serverinfo_uid" => $serverEntity->getPK(), - "clientinfo_uid" => $serverEntity->getClientInfoUID(), - "serviceinfo_uid" => $serverEntity->getServiceInfoUID(), - "status" => STATUS['OCCUPIED'] - ]; - return $temps; - } - //생성 - public function createByServer(ServerEntity $serverEntity, array $formDatas): IPEntity - { - $entity = $this->getEntity($formDatas("ipinfo_uid")); - if (!$entity) { - throw new \Exception("{$formDatas("ipinfo_uid")}에 대한 IP정보를 찾을수 없습니다."); - } - $entity = parent::modify( - $entity, - $this->getFormDatasByServer( - $serverEntity, - $formDatas - ) - ); - return $entity; - } //List 검색용 //OrderBy 처리 public function setOrderBy(mixed $field = null, mixed $value = null): void diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index f1a2d3d..6d5d3ee 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -2,7 +2,6 @@ namespace App\Services\Equipment; -use App\Entities\Equipment\PartEntity; use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerPartEntity; use App\Helpers\Equipment\ServerPartHelper; @@ -41,6 +40,28 @@ class ServerPartService extends EquipmentService "billing", ]; } + + public function getIndexFields(): array + { + return [ + "serverinfo_uid", + "type", + "part_uid", + "billing", + "amount", + "cnt", + "extra", + ]; + } + public function getIndexFilters(): array + { + return [ + "serverinfo_uid", + "type", + "part_uid", + "billing", + ]; + } public function getBatchjobFields(): array { return ['billing', 'type']; diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 9e39d04..2842bfd 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -84,6 +84,24 @@ class ServerService extends EquipmentService } //기본 기능부분 //FieldForm관련용 + public function setFormData(string $field, array $requestDatas, array $formDatas): array + { + switch ($field) { + case 'CPU': + case 'RAM': + $formDatas[$field] = $requestDatas[$field] ?? null; + $formDatas["{$field}_cnt"] = $requestDatas["{$field}_cnt"] ?? null; + break; + case 'DISK': + $formDatas[$field] = $requestDatas[$field] ?? null; + $formDatas["{$field}_cnt"] = $requestDatas["{$field}_cnt"] ?? null; + $formDatas["{$field}_extra"] = $requestDatas["{$field}_extra"] ?? null; + break; + default: + $formDatas = parent::setFormData($field, $requestDatas, $formDatas); + } + return $formDatas; + } //create용 장비코드 마지막번호 가져오기 final public function getLastestCode(string $format, int $default): string { diff --git a/app/Views/admin/serverpart/create_form.php b/app/Views/admin/serverpart/create_form.php index 034d36f..9e537b1 100644 --- a/app/Views/admin/serverpart/create_form.php +++ b/app/Views/admin/serverpart/create_form.php @@ -1,6 +1,5 @@ extend(LAYOUTS[$viewDatas['layout']]['path']) ?> section('content') ?> - getHelper()->alert($error) ?>
include("templates/{$viewDatas['layout']}/form_content_top"); ?>
diff --git a/public/js/admin/serverpart.js b/public/js/admin/serverpart.js index c7c9a12..28bba35 100644 --- a/public/js/admin/serverpart.js +++ b/public/js/admin/serverpart.js @@ -2,28 +2,36 @@ const typeSelect = document.querySelector("select[name=type]"); const partSelect = document.querySelector("select[name=part_uid]"); const amountInput = document.querySelector("input[name=amount]"); -// type 선택 시 part_uid 옵션 필터링 +// 원본 옵션들 저장 (clone 해서 나중에 다시 쓰기) +const allOptions = Array.from(partSelect.options).map(opt => opt.cloneNode(true)); + +// type 선택 시 part_uid 옵션 재구성 typeSelect.addEventListener("change", function () { let selectedType = this.value; - for (let option of partSelect.options) { - if (option.value === "") { - option.style.display = ""; // "부품정보 선택"은 항상 표시 - continue; - } - if (!selectedType || option.dataset.type === selectedType) { - option.style.display = ""; - } else { - option.style.display = "none"; - } + // partSelect 초기화 + partSelect.innerHTML = ""; + + // "부품정보 선택" 기본 옵션 추가 + let defaultOpt = allOptions.find(opt => opt.value === ""); + if (defaultOpt) { + partSelect.appendChild(defaultOpt.cloneNode(true)); } - // 선택 초기화 + // 선택된 type 에 맞는 옵션만 추가 + allOptions.forEach(opt => { + if (!opt.value) return; // 기본옵션은 이미 넣음 + if (!selectedType || opt.dataset.type === selectedType) { + partSelect.appendChild(opt.cloneNode(true)); + } + }); + + // 선택값/금액 초기화 partSelect.value = ""; amountInput.value = ""; }); -// part_uid 선택 시 amount 자동 반영 +// part_uid 선택 시 amount 값 자동 반영 partSelect.addEventListener("change", function () { let selectedOption = this.options[this.selectedIndex]; let price = selectedOption.getAttribute("data-price") || "";