dbms_init...1
This commit is contained in:
parent
7f099e35e5
commit
b988774fdb
@ -2,14 +2,15 @@
|
||||
|
||||
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\ResponseInterface;
|
||||
use CodeIgniter\Validation\Validation;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
use App\Helpers\Equipment\ServerHelper;
|
||||
use App\Services\Equipment\ServerService;
|
||||
use App\Services\Equipment\PartService;
|
||||
|
||||
class ServerController extends EquipmentController
|
||||
{
|
||||
private ?PartService $_partService = null;
|
||||
@ -46,15 +47,28 @@ class ServerController extends EquipmentController
|
||||
}
|
||||
|
||||
//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
|
||||
{
|
||||
switch ($field) {
|
||||
case 'cpu_partinfo_uid':
|
||||
$options[$field] = $this->getPartService()->getFormFieldOption($field);
|
||||
break;
|
||||
case 'ram_partinfo_uid':
|
||||
$options[$field] = $this->getPartService()->getFormFieldOption($field);
|
||||
break;
|
||||
case 'disk_partinfo_uid':
|
||||
$options[$field] = $this->getPartService()->getFormFieldOption($field);
|
||||
break;
|
||||
@ -64,8 +78,48 @@ class ServerController extends EquipmentController
|
||||
}
|
||||
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관련
|
||||
|
||||
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
|
||||
{
|
||||
$fields = [
|
||||
|
||||
@ -25,16 +25,24 @@ class ServerHelper extends EquipmentHelper
|
||||
if (!is_array($viewDatas['field_options'][$field])) {
|
||||
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'])) {
|
||||
$form .= "<button type=\"button\" onclick=\"addComponent('{$field}')\">추가</button>";
|
||||
$form .= "<button type=\"button\" onclick=\"removeCheckedComponents('{$field}')\">선택 삭제</button>";
|
||||
$form .= "<div id=\"{$field}_List\"></div>";
|
||||
$form = " <button type=\"button\" class=\"server_partinfo_layer_btn\" onclick=\"openLayer('{$field}')\">" . lang($viewDatas['class_path'] . '.label.' . $field) . " 추가</button>";
|
||||
$form .= "<div id=\"{$field}_layer\" class=\"server_partinfo_layer\" style=\"display: none;\">";
|
||||
$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;
|
||||
default:
|
||||
|
||||
@ -1,29 +1,56 @@
|
||||
.layer {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 20%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -20%);
|
||||
background: #fff;
|
||||
border: 1px solid #ccc;
|
||||
padding: 20px;
|
||||
box-shadow: 0 0 10px rgba(0,0,0,0.3);
|
||||
z-index: 1000;
|
||||
.server_partinfo_layer_btn {
|
||||
background-color: #0d6efd; /* Bootstrap 5 primary color */
|
||||
color: #fff; /* 흰색 텍스트 */
|
||||
border: 1px solid #0d6efd;
|
||||
padding: 0.375rem 0.75rem; /* 기본 패딩 */
|
||||
font-size: 1rem;
|
||||
line-height: 1.5;
|
||||
border-radius: 0.375rem; /* 기본 border-radius */
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
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 {
|
||||
margin: 5px 0;
|
||||
}
|
||||
.list-container {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.btn {
|
||||
padding: 6px 10px;
|
||||
margin: 5px;
|
||||
background: #007BFF;
|
||||
color: #fff;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn:hover {
|
||||
background: #0056b3;
|
||||
padding: 5px 10px;
|
||||
background: #f0f0f0;
|
||||
margin: 5px 0;
|
||||
display: flex;
|
||||
align-items: left;
|
||||
}
|
||||
@ -1,46 +1,39 @@
|
||||
function openLayer(type) {
|
||||
document.getElementById(type + '_Layer').style.display = 'block';
|
||||
function openLayer(field) {
|
||||
const layer = document.getElementById(`${field}_layer`);
|
||||
if (layer) layer.style.display = 'block';
|
||||
}
|
||||
|
||||
function closeLayer(type) {
|
||||
document.getElementById(type + '_Layer').style.display = 'none';
|
||||
function closeLayer(field) {
|
||||
const layer = document.getElementById(`${field}_layer`);
|
||||
if (layer) layer.style.display = 'none';
|
||||
}
|
||||
|
||||
function applyCheckedComponents(type) {
|
||||
const checkboxes = document.querySelectorAll(`#${type}_Layer input[type="checkbox"]:checked`);
|
||||
const listDiv = document.getElementById(`${type}_List`);
|
||||
|
||||
checkboxes.forEach(cb => {
|
||||
// 중복 방지
|
||||
const exists = listDiv.querySelector(`input[type="hidden"][value="${cb.value}"]`);
|
||||
if (exists) return;
|
||||
function addComponentFromLabel(field, value, text) {
|
||||
const listDiv = document.getElementById(`${field}_list`);
|
||||
if (!listDiv) return;
|
||||
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.className = 'server_partinfo_item';
|
||||
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.className = `${type}_checkbox`;
|
||||
checkbox.name = `${field}[]`;
|
||||
checkbox.value = value;
|
||||
checkbox.checked = true;
|
||||
|
||||
const hiddenInput = document.createElement('input');
|
||||
hiddenInput.type = 'hidden';
|
||||
hiddenInput.name = `${type}[]`;
|
||||
hiddenInput.value = cb.value;
|
||||
// 체크 해제되면 해당 항목 삭제
|
||||
checkbox.addEventListener('change', () => {
|
||||
if (!checkbox.checked) {
|
||||
wrapper.remove();
|
||||
}
|
||||
});
|
||||
|
||||
const span = document.createElement('span');
|
||||
span.textContent = cb.getAttribute('data-label');
|
||||
const label = document.createElement('label');
|
||||
label.textContent = text;
|
||||
label.style.marginLeft = '5px';
|
||||
|
||||
wrapper.appendChild(checkbox);
|
||||
wrapper.appendChild(hiddenInput);
|
||||
wrapper.appendChild(span);
|
||||
wrapper.appendChild(label);
|
||||
|
||||
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());
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user