dbmsv2 init...1

This commit is contained in:
choi.jh 2025-09-11 17:50:02 +09:00
parent 51c1dbf72e
commit 2cfd1a00d4
4 changed files with 48 additions and 82 deletions

View File

@ -208,7 +208,19 @@ class CommonHelper
} }
// $formOptions는 필터 옵션 배열로, key는 필터 엔티티의 PK, value는 필터 엔티티 객체 // $formOptions는 필터 옵션 배열로, key는 필터 엔티티의 PK, value는 필터 엔티티 객체
$html = sprintf("<select name=\"%s\" %s>", $field, $extra); $html = sprintf("<select name=\"%s\" %s>", $field, $extra);
$html .= $this->form_dropdown_common_process($field, $value, $viewDatas, $extras, $attributes); $html .= "<option value=\"\">" . lang("{$viewDatas['class_path']}.label.{$field}") . " 선택" . "</option>";
foreach ($viewDatas['control']['field_optons'][$field] as $key => $entity) {
$isSelected = $key == $value ? ' selected' : '';
$isDisabled = "";
if (in_array($viewDatas['control']['action'], ['create_form', 'index'])) {
if ($entity->getStatus() != $entity::DEFAULT_STATUS)
$isDisabled = " disabled";
}
$attribute = $this->form_dropdown_common_process($field, $value, $viewDatas, $extras, $attributes, $entity);
$title = $entity->getStatus() != $entity::DEFAULT_STATUS ? "X." : "";
$title .= $entity->getCustomTitle();
$html .= sprintf("<option value=\"%s\"%s%s%s>%s</option>", $key, $isSelected, $isDisabled, $attribute, $title);
}
$html .= '</select>'; $html .= '</select>';
return $html; return $html;
} }
@ -225,27 +237,17 @@ class CommonHelper
return $label; return $label;
} }
// header.php에서 getFieldForm_Helper사용 // header.php에서 getFieldForm_Helper사용
protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = []): string protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = [], mixed $entity): string
{ {
$attribute = "";
switch ($field) { switch ($field) {
default: default:
$html = "<option value=\"\">" . lang("{$viewDatas['class_path']}.label.{$field}") . " 선택" . "</option>"; foreach ($attributes as $attribute_tag => $attribute_value) {
foreach ($viewDatas['control']['field_optons'][$field] as $key => $entity) { $attribute .= sprintf(" %s=\"%s\"", $attribute_tag, $attribute_value);
$isSelected = $key == $value ? ' selected' : '';
$isDisabled = "";
if (in_array($viewDatas['control']['action'], ['create_form', 'index'])) {
if ($entity->getStatus() != $entity::DEFAULT_STATUS)
$isDisabled = ' disabled';
}
$attribute = "";
foreach ($attributes as $attribute_tag => $attribute_value) {
$attribute .= sprintf(" %s=\"%s\"", $attribute_tag, $attribute_value);
}
$html .= sprintf("<option value=\"%s\"%s%s%s>%s</option>", $key, $isSelected, $isDisabled, $attribute, $entity->getCustomTitle());
} }
break; break;
} }
return $html; return $attribute;
} }
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {

View File

@ -12,30 +12,21 @@ class ServiceHelper extends CustomerHelper
parent::__construct(); parent::__construct();
$this->setTitleField(field: ServiceModel::TITLE); $this->setTitleField(field: ServiceModel::TITLE);
} }
protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = []): string protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = [], mixed $entity): string
{ {
$attribute = "";
switch ($field) { switch ($field) {
case 'serverinfo_uid': case 'serverinfo_uid':
$html = "<option value=\"\">" . lang("{$viewDatas['class_path']}.label.{$field}") . " 선택" . "</option>"; $attribute = "";
foreach ($viewDatas['control']['field_optons'][$field] as $key => $entity) { foreach ($attributes as $attribute_tag => $attribute_value) {
$isSelected = $key == $value ? ' selected' : ''; $attribute .= sprintf(" %s=\"%s\"", $attribute_tag, $entity instanceof ServerEntity ? $entity->$attribute_value() : $attribute_value);
$isDisabled = "";
if (in_array($viewDatas['control']['action'], ['create_form', 'index'])) {
if ($entity->getStatus() != $entity::DEFAULT_STATUS)
$isDisabled = ' disabled';
}
$attribute = "";
foreach ($attributes as $attribute_tag => $attribute_value) {
$attribute .= sprintf(" %s=\"%s\"", $attribute_tag, $entity instanceof ServerEntity ? $entity->$attribute_value() : $attribute_value);
}
$html .= sprintf("<option value=\"%s\"%s%s%s>%s</option>", $key, $isSelected, $isDisabled, $attribute, $entity->getCustomTitle());
} }
break; break;
default: default:
$html = parent::form_dropdown_common_process($field, $value, $viewDatas, $extras, $attributes); $attribute = parent::form_dropdown_common_process($field, $value, $viewDatas, $extras, $attributes, $entity);
break; break;
} }
return $html; return $attribute;
} }
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {

View File

@ -2,6 +2,7 @@
namespace App\Helpers\Equipment; namespace App\Helpers\Equipment;
use App\Entities\Equipment\PartEntity;
use App\Models\Equipment\ServerPartModel; use App\Models\Equipment\ServerPartModel;
class ServerPartHelper extends EquipmentHelper class ServerPartHelper extends EquipmentHelper
@ -11,21 +12,20 @@ class ServerPartHelper extends EquipmentHelper
parent::__construct(); parent::__construct();
$this->setTitleField(field: ServerPartModel::TITLE); $this->setTitleField(field: ServerPartModel::TITLE);
} }
protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = []): string protected function form_dropdown_common_process(string $field, mixed $value, array $viewDatas, array $extras = [], array $attributes = [], mixed $entity): string
{ {
$attribute = "";
switch ($field) { switch ($field) {
case 'serverinfo_uid': case 'part_uid':
$html = "<option value=\"\">" . lang("{$viewDatas['class_path']}.label.{$field}") . " 선택" . "</option>"; foreach ($attributes as $attribute_tag => $attribute_value) {
foreach ($viewDatas['control']['field_optons'][$field] as $key => $entity) { $attribute .= sprintf(" %s=\"%s\"", $attribute_tag, $entity instanceof PartEntity ? $entity->$attribute_value() : $attribute_value);
$isSelected = $key == $value ? ' selected' : '';
$html .= sprintf("<option value=\"%s\"%s>%s</option>", $key, $isSelected, $entity->getCustomTitle());
} }
break; break;
default: default:
$html = parent::form_dropdown_common_process($field, $value, $viewDatas, $extras); $attribute = parent::form_dropdown_common_process($field, $value, $viewDatas, $extras, $attributes, $entity);
break; break;
} }
return $html; return $attribute;
} }
public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string public function getFieldForm(string $field, mixed $value, array $viewDatas, array $extras = []): string
{ {
@ -39,12 +39,14 @@ class ServerPartHelper extends EquipmentHelper
case 'DB': case 'DB':
case 'OS': case 'OS':
case 'SOFTWARE': case 'SOFTWARE':
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
$form = $this->form_dropdown_common($field, $value, $viewDatas, $extras);
break;
case 'part_uid': case 'part_uid':
if ($value === null && array_key_exists('entity', $viewDatas)) {
$value = $viewDatas['entity']->getServerEntity()->getPK();
}
$extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field'; $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' select-field' : 'select-field';
$form = $this->form_dropdown_common($field, $value, $viewDatas, $extras); $extras['onChange'] = "document.querySelector('input[name=\'amount\']').value = this.options[this.selectedIndex].getAttribute('data-price')";
$attributes = ['data-price' => 'getPrice'];
$form = $this->form_dropdown_common($field, $value, $viewDatas, $extras, $attributes);
break; break;
default: default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras); $form = parent::getFieldForm($field, $value, $viewDatas, $extras);
@ -64,13 +66,17 @@ class ServerPartHelper extends EquipmentHelper
case 'SWITCH': case 'SWITCH':
case 'IP': case 'IP':
case 'CS': case 'CS':
case 'part_uid':
if (!array_key_exists($field, $viewDatas['entities'])) { if (!array_key_exists($field, $viewDatas['entities'])) {
return ""; return "";
} }
$temps = []; $temps = [];
foreach ($viewDatas['entities'][$field] as $entity) { foreach ($viewDatas['entities'][$field] as $entity) {
$modal = form_label( $title = $entity->getTitle();
ICONS['SETUP'], $title .= $entity->getCnt() > 1 ? "*" . $entity->getCnt() . "" : "";
$title .= $entity->getExtra() !== "" ? "/" . $entity->getExtra() : "";
$temps[] = form_label(
$title,
$field, $field,
[ [
"data-src" => "/admin/equipment/serverpart/modify/{$entity->getPK()}?type={$entity->getType()}&ActionTemplate=popup", "data-src" => "/admin/equipment/serverpart/modify/{$entity->getPK()}?type={$entity->getType()}&ActionTemplate=popup",
@ -80,39 +86,6 @@ class ServerPartHelper extends EquipmentHelper
"target" => "_self" "target" => "_self"
] ]
); );
$temps[] = sprintf(
"%s%s*%s개%s",
$modal,
$entity->getTitle(),
$entity->getCnt(),
!$entity->getExtra() ? "" : "/" . $entity->getExtra()
);
}
$value = implode("<BR>", $temps);
break;
case 'SWITCH_SERVICE':
case 'IP_SERVICE':
case 'OS_SERVICE':
$field = str_replace('_SERVICE', '', $field);
if (!array_key_exists($field, $viewDatas['entities'])) {
return "";
}
$temps = [];
foreach ($viewDatas['entities'][$field] as $entity) {
$modal = form_label(
$entity->getTitle(),
$field,
[
"data-src" => "/admin/equipment/serverpart/modify/{$entity->getPK()}?type={$entity->getType()}&ActionTemplate=popup",
"data-bs-toggle" => "modal",
"data-bs-target" => "#index_action_form",
"class" => "btn btn-sm btn-outline btn-circle",
"target" => "_self"
]
);
$cnt = $entity->getCnt() > 1 ? "*" . $entity->getCnt() . "" : "";
$extra = !$entity->getExtra() ? "" : "/";
$temps[] = $modal . $cnt . $extra;
} }
$value = implode(",", $temps); $value = implode(",", $temps);
break; break;

View File

@ -1,3 +1,3 @@
<?= $serverPartCellDatas['service']->getHelper()->getFieldView('SWITCH_SERVICE', "", $serverPartCellDatas) ?> / <?= $serverPartCellDatas['service']->getHelper()->getFieldView('SWITCH', "", $serverPartCellDatas) ?> /
<?= $serverPartCellDatas['service']->getHelper()->getFieldView('IP_SERVICE', "", $serverPartCellDatas) ?> / <?= $serverPartCellDatas['service']->getHelper()->getFieldView('IP', "", $serverPartCellDatas) ?> /
<?= $serverPartCellDatas['service']->getHelper()->getFieldView('OS_SERVICE', "", $serverPartCellDatas) ?> <?= $serverPartCellDatas['service']->getHelper()->getFieldView('OS', "", $serverPartCellDatas) ?>