trafficmonitor init...1
This commit is contained in:
parent
9307603e42
commit
716d8ab887
@ -71,20 +71,23 @@ class TrafficController extends AdminController
|
|||||||
{
|
{
|
||||||
return parent::view_process($uid);
|
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(
|
return $this->action_render_process(
|
||||||
$this->getActionPaths(),
|
$this->getActionPaths(),
|
||||||
self::PATH . DIRECTORY_SEPARATOR . __FUNCTION__,
|
self::PATH . DIRECTORY_SEPARATOR . __FUNCTION__,
|
||||||
$this->getViewDatas()
|
['entity' => $entity]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* AJAX 요청을 처리하고, 모델에서 집계된 데이터를 JSON 형식으로 반환합니다.
|
* AJAX 요청을 처리하고, 모델에서 집계된 데이터를 JSON 형식으로 반환합니다.
|
||||||
*/
|
*/
|
||||||
public function getAggregatedData(): ResponseInterface
|
public function getAggregatedData($uid): ResponseInterface
|
||||||
{
|
{
|
||||||
$uid = $this->request->getVar('uid');
|
|
||||||
$entity = $this->service->getEntity($uid);
|
$entity = $this->service->getEntity($uid);
|
||||||
if (!$entity instanceof TrafficEntity) {
|
if (!$entity instanceof TrafficEntity) {
|
||||||
throw new \Exception(__METHOD__ . "에서 오류발생:{$uid}에 해당하는 트래픽정보를 찾을수없습니다.");
|
throw new \Exception(__METHOD__ . "에서 오류발생:{$uid}에 해당하는 트래픽정보를 찾을수없습니다.");
|
||||||
@ -104,7 +107,7 @@ class TrafficController extends AdminController
|
|||||||
$aggregateDatas = $collectorService->getAggregateDatas($entity, $startDate, $endDate);
|
$aggregateDatas = $collectorService->getAggregateDatas($entity, $startDate, $endDate);
|
||||||
// 데이터를 JSON 형식으로 반환
|
// 데이터를 JSON 형식으로 반환
|
||||||
return $this->response->setJSON([
|
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',
|
'status' => 'success',
|
||||||
'data' => $aggregateDatas // 이 데이터는 이제 사용자가 제공한 필드 구조를 가집니다.
|
'data' => $aggregateDatas // 이 데이터는 이제 사용자가 제공한 필드 구조를 가집니다.
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -14,7 +14,6 @@ abstract class CommonEntity extends Entity
|
|||||||
{
|
{
|
||||||
parent::__construct($data);
|
parent::__construct($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function getPK(): int|string
|
final public function getPK(): int|string
|
||||||
{
|
{
|
||||||
$field = constant("static::PK");
|
$field = constant("static::PK");
|
||||||
@ -25,7 +24,7 @@ abstract class CommonEntity extends Entity
|
|||||||
$field = constant("static::TITLE");
|
$field = constant("static::TITLE");
|
||||||
return $this->attributes[$field] ?? "";
|
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);
|
$parameters = array_map(fn($field) => $this->attributes[$field], $fields);
|
||||||
return sprintf($format, ...$parameters);
|
return sprintf($format, ...$parameters);
|
||||||
|
|||||||
@ -15,6 +15,10 @@ class TrafficEntity extends CommonEntity
|
|||||||
protected $casts = [
|
protected $casts = [
|
||||||
// 'role' => 'json-array', // 🚫 CSV 형식 저장을 위해 제거
|
// 'role' => 'json-array', // 🚫 CSV 형식 저장을 위해 제거
|
||||||
];
|
];
|
||||||
|
public function getCustomTitle(): string
|
||||||
|
{
|
||||||
|
return $this->getTitleByFormat("%s[%s]", ['client', 'server_ip']);
|
||||||
|
}
|
||||||
public function getClient(): string
|
public function getClient(): string
|
||||||
{
|
{
|
||||||
return $this->attributes['client'];
|
return $this->attributes['client'];
|
||||||
|
|||||||
@ -33,7 +33,7 @@ class CollectorForm extends CommonForm
|
|||||||
switch ($field) {
|
switch ($field) {
|
||||||
case 'trafficinfo_uid':
|
case 'trafficinfo_uid':
|
||||||
foreach (service('trafficservice')->getEntities() as $entity) {
|
foreach (service('trafficservice')->getEntities() as $entity) {
|
||||||
$tempOptions[$entity->getPK()] = $entity->getCustomTitle("%s[%s]", ['client', 'server_ip']);
|
$tempOptions[$entity->getPK()] = $entity->getCustomTitle();
|
||||||
}
|
}
|
||||||
$options['options'] = $tempOptions;
|
$options['options'] = $tempOptions;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -43,31 +43,26 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="p-4 p-md-5">
|
<body class="p-4 p-md-5">
|
||||||
|
|
||||||
<div id="app" class="container-fluid" style="max-width: 1200px;">
|
<div id="app" class="container-fluid" style="max-width: 1200px;">
|
||||||
<header class="text-center mb-5">
|
<header class="text-center mb-5">
|
||||||
<h1 class="display-5 fw-bold text-dark mb-2"><?= $title ?? '트래픽 데이터 시각화 대시보드' ?></h1>
|
<h1 class="display-5 fw-bold text-dark mb-2"><?= $title ?? '트래픽 데이터 시각화 대시보드' ?></h1>
|
||||||
<p class="text-secondary">기간을 선택하여 트래픽 추이를 확인하세요.</p>
|
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- Configuration Card -->
|
<!-- Configuration Card -->
|
||||||
<div class="card shadow-lg mb-5 dashboard-card">
|
<div class="card shadow-lg mb-5 dashboard-card">
|
||||||
<div class="card-body p-4 p-md-5">
|
<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">
|
<div class="row g-3 align-items-end">
|
||||||
<!-- 1. Start Date Picker -->
|
<!-- 1. Start Date Picker -->
|
||||||
<div class="col-12 col-md-3">
|
<div class="col-12 col-md-3">
|
||||||
<label for="startDate" class="form-label text-muted">시작 날짜</label>
|
<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>
|
</div>
|
||||||
|
|
||||||
<!-- 2. End Date Picker -->
|
<!-- 2. End Date Picker -->
|
||||||
<div class="col-12 col-md-3">
|
<div class="col-12 col-md-3">
|
||||||
<label for="endDate" class="form-label text-muted">종료 날짜</label>
|
<label for="endDate" class="form-label text-muted">종료 날짜</label>
|
||||||
<input type="date" id="endDate" class="form-control" value="<?= date('Y-m-d') ?>">
|
<input type="date" id="endDate" class="form-control" value="<?= date('Y-m-d') ?>">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button onclick="fetchDataAndDrawChart()" id="viewChartBtn" class="mt-4 btn btn-primary btn-lg w-100 w-md-auto shadow-sm">
|
<button onclick="fetchDataAndDrawChart()" id="viewChartBtn" class="mt-4 btn btn-primary btn-lg w-100 w-md-auto shadow-sm">
|
||||||
차트 보기
|
차트 보기
|
||||||
</button>
|
</button>
|
||||||
@ -99,10 +94,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Bootstrap 5 JS Bundle 로드 -->
|
<!-- Bootstrap 5 JS Bundle 로드 -->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// 전역 변수 설정
|
// 전역 변수 설정
|
||||||
let trafficChart = null;
|
let trafficChart = null;
|
||||||
@ -116,7 +109,7 @@
|
|||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
|
|
||||||
async function fetchAggregatedData(startDate, endDate) {
|
async function fetchAggregatedData(startDate, endDate) {
|
||||||
const baseEndpoint = '<?= base_url("traffic/data") ?>'; // CI4 라우트로 지정된 기본 엔드포인트
|
const baseEndpoint = '<?= base_url("traffic/data/{$entity->getPK()}") ?>'; // CI4 라우트로 지정된 기본 엔드포인트
|
||||||
|
|
||||||
// GET 요청을 위해 쿼리 파라미터를 생성합니다.
|
// GET 요청을 위해 쿼리 파라미터를 생성합니다.
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user