Refactor data loading and query projections
This commit is contained in:
@@ -377,11 +377,11 @@
|
||||
{% block script %}
|
||||
<script>
|
||||
const availableYears = {{ available_years | tojson }};
|
||||
const yearlySummary = {{ yearly_summary | tojson }};
|
||||
const monthlySummary = {{ monthly_summary | tojson }};
|
||||
const revenueYearly = {{ project_revenue_mix_yearly | tojson }};
|
||||
const revenueMonthly = {{ project_revenue_mix_monthly | tojson }};
|
||||
const pageSelectedYear = {{ overview_selected_year | tojson }};
|
||||
let yearlySummary = [];
|
||||
let monthlySummary = [];
|
||||
let revenueYearly = [];
|
||||
let revenueMonthly = [];
|
||||
const dashboardRevenueMetricOptions = {{ dashboard_revenue_metric_options | tojson }};
|
||||
const dashboardExpenseMetricOptions = {{ dashboard_expense_metric_options | tojson }};
|
||||
|
||||
@@ -595,6 +595,29 @@
|
||||
.slice(granularity === "yearly" ? -10 : 0);
|
||||
}
|
||||
|
||||
async function loadDashboardBootstrapData() {
|
||||
const queryParams = new URLSearchParams();
|
||||
if (pageSelectedYear) {
|
||||
queryParams.set("overview_year", String(pageSelectedYear));
|
||||
}
|
||||
const query = queryParams.toString() ? `?${queryParams.toString()}` : "";
|
||||
const response = await fetch(`/bootstrap-data${query}`, {
|
||||
method: "GET",
|
||||
credentials: "same-origin",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
},
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok || payload?.error) {
|
||||
throw new Error(payload?.error || `HTTP ${response.status}`);
|
||||
}
|
||||
yearlySummary = Array.isArray(payload?.yearly_summary) ? payload.yearly_summary : [];
|
||||
monthlySummary = Array.isArray(payload?.monthly_summary) ? payload.monthly_summary : [];
|
||||
revenueYearly = Array.isArray(payload?.project_revenue_mix_yearly) ? payload.project_revenue_mix_yearly : [];
|
||||
revenueMonthly = Array.isArray(payload?.project_revenue_mix_monthly) ? payload.project_revenue_mix_monthly : [];
|
||||
}
|
||||
|
||||
function updateRevenueChart() {
|
||||
const granularity = document.getElementById("revenueGranularity").value;
|
||||
syncYearSelection("revenueYear", granularity);
|
||||
@@ -636,9 +659,16 @@
|
||||
}
|
||||
});
|
||||
|
||||
syncYearSelection("revenueYear", document.getElementById("revenueGranularity")?.value || "yearly");
|
||||
syncYearSelection("expenseYear", document.getElementById("expenseGranularity")?.value || "yearly");
|
||||
updateRevenueChart();
|
||||
updateExpenseChart();
|
||||
(async () => {
|
||||
try {
|
||||
await loadDashboardBootstrapData();
|
||||
} catch (error) {
|
||||
console.error("대시보드 부트스트랩 데이터 조회 에러", error);
|
||||
}
|
||||
syncYearSelection("revenueYear", document.getElementById("revenueGranularity")?.value || "yearly");
|
||||
syncYearSelection("expenseYear", document.getElementById("expenseGranularity")?.value || "yearly");
|
||||
updateRevenueChart();
|
||||
updateExpenseChart();
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user