dbms_init...1

This commit is contained in:
최준흠 2025-05-14 18:50:12 +09:00
parent 7f099e35e5
commit b988774fdb
4 changed files with 155 additions and 73 deletions

View File

@ -2,14 +2,15 @@
namespace App\Controllers\Admin\Equipment; namespace App\Controllers\Admin\Equipment;
use App\Helpers\Equipment\ServerHelper;
use App\Services\Equipment\PartService;
use App\Services\Equipment\ServerService;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Validation\Validation;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use App\Helpers\Equipment\ServerHelper;
use App\Services\Equipment\ServerService;
use App\Services\Equipment\PartService;
class ServerController extends EquipmentController class ServerController extends EquipmentController
{ {
private ?PartService $_partService = null; private ?PartService $_partService = null;
@ -46,15 +47,28 @@ class ServerController extends EquipmentController
} }
//Index,FieldForm관련 //Index,FieldForm관련
protected function getFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
}
switch ($field) {
case 'cpu_partinfo_uid':
case 'ram_partinfo_uid':
case 'disk_partinfo_uid':
$rule = "if_exist|permit_empty|numeric";
break;
default:
$rule = parent::getFieldRule($action, $field);
break;
}
return $rule;
}
protected function getFormFieldOption(string $field, array $options = []): array protected function getFormFieldOption(string $field, array $options = []): array
{ {
switch ($field) { switch ($field) {
case 'cpu_partinfo_uid': case 'cpu_partinfo_uid':
$options[$field] = $this->getPartService()->getFormFieldOption($field);
break;
case 'ram_partinfo_uid': case 'ram_partinfo_uid':
$options[$field] = $this->getPartService()->getFormFieldOption($field);
break;
case 'disk_partinfo_uid': case 'disk_partinfo_uid':
$options[$field] = $this->getPartService()->getFormFieldOption($field); $options[$field] = $this->getPartService()->getFormFieldOption($field);
break; break;
@ -64,8 +78,48 @@ class ServerController extends EquipmentController
} }
return $options; return $options;
} }
protected function setValidation(Validation $validation, string $action, string $field, ?string $rule = null): Validation
{
switch ($field) {
case 'cpu_partinfo_uid':
case 'ram_partinfo_uid':
case 'disk_partinfo_uid':
//아래 Rule Array는 필드명.* checkbox를 사용
$validation->setRule("{$field}.*", $field, $rule);
break;
default:
$validation = parent::setValidation($validation, $action, $field, $rule);
break;
}
return $validation;
}
//Index,FieldForm관련 //Index,FieldForm관련
protected function create_process(): mixed
{
$entity = parent::create_process();
//변경할 UIDS
$cpu_uids = $this->request->getVar('cpu_partinfo_uid[]');
if (!is_array($cpu_uids) || !count($cpu_uids)) {
throw new \Exception("CPU가 정의되지 않았습니다.");
}
$ram_uids = $this->request->getVar('ram_partinfo_uid[]');
if (!is_array($ram_uids) || !count($ram_uids)) {
throw new \Exception("RAM가 정의되지 않았습니다.");
}
$disk_uids = $this->request->getVar('cpu_partinfo_uid[]');
if (!is_array($disk_uids) || !count($disk_uids)) {
throw new \Exception("DISK가 정의되지 않았습니다.");
}
//데이터가 있는경우 Field만 처리하기위해
$fields = [];
foreach ($this->batchjob_fields as $field) {
if ($this->request->getVar($field)) {
$fields[] = $field;
}
}
return $this->getService()->create($this->formDatas);
}
protected function index_process(): array protected function index_process(): array
{ {
$fields = [ $fields = [

View File

@ -25,16 +25,24 @@ class ServerHelper extends EquipmentHelper
if (!is_array($viewDatas['field_options'][$field])) { if (!is_array($viewDatas['field_options'][$field])) {
throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다."); throw new \Exception(__METHOD__ . "에서 {$field}의 field_options가 array형태가 아닙니다.");
} }
$formOptions = array_merge(
["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택'],
$viewDatas['field_options'][$field]
);
$extra_class = isset($extras['class']) ? $extras['class'] : "";
$form = form_dropdown($field, $formOptions, $value, ['id' => "{$field}_Select", 'class' => $extra_class, ...array_diff_key($extras, ['class' => ''])]);
if (in_array($viewDatas['action'], ['create_form', 'modify_form'])) { if (in_array($viewDatas['action'], ['create_form', 'modify_form'])) {
$form .= "<button type=\"button\" onclick=\"addComponent('{$field}')\">추가</button>"; $form = " <button type=\"button\" class=\"server_partinfo_layer_btn\" onclick=\"openLayer('{$field}')\">" . lang($viewDatas['class_path'] . '.label.' . $field) . " 추가</button>";
$form .= "<button type=\"button\" onclick=\"removeCheckedComponents('{$field}')\">선택 삭제</button>"; $form .= "<div id=\"{$field}_layer\" class=\"server_partinfo_layer\" style=\"display: none;\">";
$form .= "<div id=\"{$field}_List\"></div>"; $form .= "<div class=\"server_partinfo_layer_inner\">";
$form .= "<ul class=\"server_partinfo_item_list\">";
foreach ($viewDatas['field_options'][$field] as $key => $label) {
$form .= "<li><label onclick=\"addComponentFromLabel('{$field}', {$key},'{$label}')\">{$label}</label></li>";
}
$form .= "</ul>";
$form .= "<button type=\"button\" onclick=\"closeLayer('{$field}')\">닫기</button>";
$form .= "</div></div>";
$form .= "<div id=\"{$field}_list\" class=\"server_partinfo_items\" style=\"border:1px solid silver\"></div>";
} else {
$formOptions = ["" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택'];
foreach ($viewDatas['field_options'][$field] as $key => $label) {
$formOptions[$key] = $label;
}
$form = form_dropdown($field, $formOptions, $value, $extras);
} }
break; break;
default: default:

View File

@ -1,29 +1,56 @@
.layer { .server_partinfo_layer_btn {
display: none; background-color: #0d6efd; /* Bootstrap 5 primary color */
position: fixed; color: #fff; /* 흰색 텍스트 */
top: 20%; border: 1px solid #0d6efd;
left: 50%; padding: 0.375rem 0.75rem; /* 기본 패딩 */
transform: translate(-50%, -20%); font-size: 1rem;
background: #fff; line-height: 1.5;
border: 1px solid #ccc; border-radius: 0.375rem; /* 기본 border-radius */
padding: 20px; cursor: pointer;
box-shadow: 0 0 10px rgba(0,0,0,0.3); text-align: center;
z-index: 1000; display: inline-block;
text-decoration: none;
transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
} }
.server_partinfo_layer_btn:hover {
background-color: #0b5ed7;
border-color: #0a58ca;
}
.server_partinfo_layer {
position: fixed;
top: 20%;
left: 50%;
transform: translateX(-50%);
background: #fff;
border: 1px solid #ccc;
padding: 20px;
z-index: 1000;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
}
.server_partinfo_layer_inner {
text-align:center;
}
.server_partinfo_item_list li {
margin: 5px 0;
}
.server_partinfo_item_list label {
cursor: pointer;
color: #007bff;
text-decoration: underline;
}
.server_partinfo_items {
margin-top: 20px;
}
.server_partinfo_item { .server_partinfo_item {
margin: 5px 0; padding: 5px 10px;
background: #f0f0f0;
margin: 5px 0;
display: flex;
align-items: left;
} }
.list-container {
margin-top: 20px;
}
.btn {
padding: 6px 10px;
margin: 5px;
background: #007BFF;
color: #fff;
border: none;
cursor: pointer;
}
.btn:hover {
background: #0056b3;
}

View File

@ -1,46 +1,39 @@
function openLayer(type) { function openLayer(field) {
document.getElementById(type + '_Layer').style.display = 'block'; const layer = document.getElementById(`${field}_layer`);
if (layer) layer.style.display = 'block';
} }
function closeLayer(type) { function closeLayer(field) {
document.getElementById(type + '_Layer').style.display = 'none'; const layer = document.getElementById(`${field}_layer`);
if (layer) layer.style.display = 'none';
} }
function applyCheckedComponents(type) { function addComponentFromLabel(field, value, text) {
const checkboxes = document.querySelectorAll(`#${type}_Layer input[type="checkbox"]:checked`); const listDiv = document.getElementById(`${field}_list`);
const listDiv = document.getElementById(`${type}_List`); if (!listDiv) return;
checkboxes.forEach(cb => {
// 중복 방지
const exists = listDiv.querySelector(`input[type="hidden"][value="${cb.value}"]`);
if (exists) return;
const wrapper = document.createElement('div'); const wrapper = document.createElement('div');
wrapper.className = 'server_partinfo_item'; wrapper.className = 'server_partinfo_item';
const checkbox = document.createElement('input'); const checkbox = document.createElement('input');
checkbox.type = 'checkbox'; checkbox.type = 'checkbox';
checkbox.className = `${type}_checkbox`; checkbox.name = `${field}[]`;
checkbox.value = value;
checkbox.checked = true;
const hiddenInput = document.createElement('input'); // 체크 해제되면 해당 항목 삭제
hiddenInput.type = 'hidden'; checkbox.addEventListener('change', () => {
hiddenInput.name = `${type}[]`; if (!checkbox.checked) {
hiddenInput.value = cb.value; wrapper.remove();
}
});
const span = document.createElement('span'); const label = document.createElement('label');
span.textContent = cb.getAttribute('data-label'); label.textContent = text;
label.style.marginLeft = '5px';
wrapper.appendChild(checkbox); wrapper.appendChild(checkbox);
wrapper.appendChild(hiddenInput); wrapper.appendChild(label);
wrapper.appendChild(span);
listDiv.appendChild(wrapper); listDiv.appendChild(wrapper);
});
closeLayer(type);
} }
function removeCheckedComponents(type) {
const checkboxes = document.querySelectorAll(`#${type}_List .${type}_checkbox:checked`);
checkboxes.forEach(cb => cb.closest('.server_partinfo_item').remove());
}