diff --git a/app/Controllers/Admin/TrafficController.php b/app/Controllers/Admin/TrafficController.php index 9384d67..a607d26 100644 --- a/app/Controllers/Admin/TrafficController.php +++ b/app/Controllers/Admin/TrafficController.php @@ -71,20 +71,23 @@ class TrafficController extends AdminController { return parent::view_process($uid); } - public function dashboard(): string + public function dashboard($uid): string { + $entity = $this->service->getEntity($uid); + if (!$entity instanceof TrafficEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생:{$uid}에 해당하는 트래픽정보를 찾을수없습니다."); + } return $this->action_render_process( $this->getActionPaths(), self::PATH . DIRECTORY_SEPARATOR . __FUNCTION__, - $this->getViewDatas() + ['entity' => $entity] ); } /** * AJAX 요청을 처리하고, 모델에서 집계된 데이터를 JSON 형식으로 반환합니다. */ - public function getAggregatedData(): ResponseInterface + public function getAggregatedData($uid): ResponseInterface { - $uid = $this->request->getVar('uid'); $entity = $this->service->getEntity($uid); if (!$entity instanceof TrafficEntity) { throw new \Exception(__METHOD__ . "에서 오류발생:{$uid}에 해당하는 트래픽정보를 찾을수없습니다."); @@ -104,7 +107,7 @@ class TrafficController extends AdminController $aggregateDatas = $collectorService->getAggregateDatas($entity, $startDate, $endDate); // 데이터를 JSON 형식으로 반환 return $this->response->setJSON([ - 'message' => sprintf("[%s~%s] %s 트랙픽차트 ", $startDate, $endDate, $entity->getCustomTitle("%s[%s]", ['client', 'server_ip'])), + 'message' => sprintf("[%s~%s] %s 트랙픽차트 ", $startDate, $endDate, $entity->getCustomTitle()), 'status' => 'success', 'data' => $aggregateDatas // 이 데이터는 이제 사용자가 제공한 필드 구조를 가집니다. ]); diff --git a/app/Entities/CommonEntity.php b/app/Entities/CommonEntity.php index 7605c97..f4b16bf 100644 --- a/app/Entities/CommonEntity.php +++ b/app/Entities/CommonEntity.php @@ -14,7 +14,6 @@ abstract class CommonEntity extends Entity { parent::__construct($data); } - final public function getPK(): int|string { $field = constant("static::PK"); @@ -25,7 +24,7 @@ abstract class CommonEntity extends Entity $field = constant("static::TITLE"); return $this->attributes[$field] ?? ""; } - final public function getCustomTitle(string $format, array $fields): string + final public function getTitleByFormat(string $format, array $fields): string { $parameters = array_map(fn($field) => $this->attributes[$field], $fields); return sprintf($format, ...$parameters); diff --git a/app/Entities/TrafficEntity.php b/app/Entities/TrafficEntity.php index 2cfa2e6..60ec0a1 100644 --- a/app/Entities/TrafficEntity.php +++ b/app/Entities/TrafficEntity.php @@ -15,6 +15,10 @@ class TrafficEntity extends CommonEntity protected $casts = [ // 'role' => 'json-array', // 🚫 CSV 형식 저장을 위해 제거 ]; + public function getCustomTitle(): string + { + return $this->getTitleByFormat("%s[%s]", ['client', 'server_ip']); + } public function getClient(): string { return $this->attributes['client']; diff --git a/app/Forms/CollectorForm.php b/app/Forms/CollectorForm.php index 3790a4e..1e42ed3 100644 --- a/app/Forms/CollectorForm.php +++ b/app/Forms/CollectorForm.php @@ -33,7 +33,7 @@ class CollectorForm extends CommonForm switch ($field) { case 'trafficinfo_uid': foreach (service('trafficservice')->getEntities() as $entity) { - $tempOptions[$entity->getPK()] = $entity->getCustomTitle("%s[%s]", ['client', 'server_ip']); + $tempOptions[$entity->getPK()] = $entity->getCustomTitle(); } $options['options'] = $tempOptions; break; diff --git a/app/Views/admin/traffic/dashboard.php b/app/Views/admin/traffic/dashboard.php index 66e6c47..8191b12 100644 --- a/app/Views/admin/traffic/dashboard.php +++ b/app/Views/admin/traffic/dashboard.php @@ -43,31 +43,26 @@ -

-

기간을 선택하여 트래픽 추이를 확인하세요.

-
-

데이터 조회 설정

+

getCustomTitle() ?>데이터 조회 설정

- +
-
- @@ -99,10 +94,8 @@
- -