trafficmonitor init...1

This commit is contained in:
choi.jh 2025-11-13 14:57:52 +09:00
parent 9307603e42
commit 716d8ab887
5 changed files with 17 additions and 18 deletions

View File

@ -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 // 이 데이터는 이제 사용자가 제공한 필드 구조를 가집니다.
]);

View File

@ -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);

View File

@ -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'];

View File

@ -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;

View File

@ -43,31 +43,26 @@
</head>
<body class="p-4 p-md-5">
<div id="app" class="container-fluid" style="max-width: 1200px;">
<header class="text-center mb-5">
<h1 class="display-5 fw-bold text-dark mb-2"><?= $title ?? '트래픽 데이터 시각화 대시보드' ?></h1>
<p class="text-secondary">기간을 선택하여 트래픽 추이를 확인하세요.</p>
</header>
<!-- Configuration Card -->
<div class="card shadow-lg mb-5 dashboard-card">
<div class="card-body p-4 p-md-5">
<h2 class="h5 card-title text-dark mb-4">데이터 조회 설정</h2>
<h2 class="h5 card-title text-dark mb-4"><?= $viewDatas['entity']->getCustomTitle() ?>데이터 조회 설정</h2>
<div class="row g-3 align-items-end">
<!-- 1. Start Date Picker -->
<div class="col-12 col-md-3">
<label for="startDate" class="form-label text-muted">시작 날짜</label>
<input type="date" id="startDate" class="form-control" value="<?= date('Y-m-d', strtotime('-7 days')) ?>">
<input type="date" id="startDate" class="form-control" value="<?= date('Y-m-d') ?>">
</div>
<!-- 2. End Date Picker -->
<div class="col-12 col-md-3">
<label for="endDate" class="form-label text-muted">종료 날짜</label>
<input type="date" id="endDate" class="form-control" value="<?= date('Y-m-d') ?>">
</div>
</div>
<button onclick="fetchDataAndDrawChart()" id="viewChartBtn" class="mt-4 btn btn-primary btn-lg w-100 w-md-auto shadow-sm">
차트 보기
</button>
@ -99,10 +94,8 @@
</div>
</div>
</div>
<!-- Bootstrap 5 JS Bundle 로드 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// 전역 변수 설정
let trafficChart = null;
@ -116,7 +109,7 @@
// -----------------------------------------------------------
async function fetchAggregatedData(startDate, endDate) {
const baseEndpoint = '<?= base_url("traffic/data") ?>'; // CI4 라우트로 지정된 기본 엔드포인트
const baseEndpoint = '<?= base_url("traffic/data/{$entity->getPK()}") ?>'; // CI4 라우트로 지정된 기본 엔드포인트
// GET 요청을 위해 쿼리 파라미터를 생성합니다.
const params = new URLSearchParams({