create filter and bigdata resume sync
This commit is contained in:
@@ -1,16 +1,64 @@
|
||||
import Big from "big.js";
|
||||
import GlobalConfig, { addThousandSeparators } from "../global-config.js";
|
||||
import flatpickr from "flatpickr";
|
||||
import "flatpickr/dist/flatpickr.min.css";
|
||||
|
||||
class BigData {
|
||||
async init() {
|
||||
try {
|
||||
this.totalTargetPAD = await this.getTargetPAD();
|
||||
this.resultDataTotal = await this.getDataTotalPotensi();
|
||||
this.dataVerification = await this.getDataVerfication();
|
||||
this.dataNonVerification = await this.getDataNonVerfication();
|
||||
this.dataBusiness = await this.getDataBusiness();
|
||||
this.dataNonBusiness = await this.getDataNonBusiness();
|
||||
this.dataTataRuang = await this.getDataTataRuang();
|
||||
this.filterYear = new Date().getFullYear(); // Set initial year
|
||||
|
||||
let yearInput = document.querySelector("#yearPicker");
|
||||
let filterButton = document.querySelector("#btnFilterYear");
|
||||
|
||||
if (!yearInput || !filterButton) {
|
||||
console.error(
|
||||
"Element #yearPicker or #btnFilterYear not found."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set default value for input
|
||||
yearInput.value = this.filterYear;
|
||||
|
||||
// Handle manual input (pressing Enter)
|
||||
yearInput.addEventListener("keypress", (event) => {
|
||||
if (event.key === "Enter") {
|
||||
this.updateYear(yearInput.value);
|
||||
}
|
||||
});
|
||||
|
||||
// Handle button click
|
||||
filterButton.addEventListener("click", () => {
|
||||
this.updateYear(yearInput.value);
|
||||
});
|
||||
|
||||
console.log("init filter this year", this.filterYear);
|
||||
|
||||
// Load initial data
|
||||
await this.updateData(this.filterYear);
|
||||
} catch (error) {
|
||||
console.error("Error initializing data:", error);
|
||||
}
|
||||
}
|
||||
updateYear(value) {
|
||||
let inputYear = parseInt(value, 10);
|
||||
if (!isNaN(inputYear)) {
|
||||
this.filterYear = inputYear;
|
||||
this.updateData(this.filterYear);
|
||||
} else {
|
||||
console.error("Invalid year input");
|
||||
}
|
||||
}
|
||||
async updateData(year) {
|
||||
try {
|
||||
this.totalTargetPAD = await this.getTargetPAD(year);
|
||||
this.resultDataTotal = await this.getDataTotalPotensi(year);
|
||||
this.dataVerification = await this.getDataVerfication(year);
|
||||
this.dataNonVerification = await this.getDataNonVerfication(year);
|
||||
this.dataBusiness = await this.getDataBusiness(year);
|
||||
this.dataNonBusiness = await this.getDataNonBusiness(year);
|
||||
this.dataTataRuang = await this.getDataTataRuang(year);
|
||||
|
||||
// total potensi
|
||||
this.bigTargetPAD = new Big(this.totalTargetPAD ?? 0);
|
||||
@@ -54,10 +102,13 @@ class BigData {
|
||||
this.bigTotalNonVerification = new Big(
|
||||
this.dataNonVerification.total
|
||||
);
|
||||
this.percentageResultNonVerification = this.bigTotalNonVerification
|
||||
.div(this.bigTotalPotensi)
|
||||
.times(100)
|
||||
.toFixed(2);
|
||||
this.percentageResultNonVerification =
|
||||
this.bigTotalNonVerification <= 0 || this.bigTotalPotensi
|
||||
? 0
|
||||
: this.bigTotalNonVerification
|
||||
.div(this.bigTotalPotensi)
|
||||
.times(100)
|
||||
.toFixed(2);
|
||||
|
||||
// verification documents
|
||||
this.bigTotalVerification = new Big(this.dataVerification.total);
|
||||
@@ -82,7 +133,8 @@ class BigData {
|
||||
// non-business documents
|
||||
this.bigTotalNonBusiness = new Big(this.dataNonBusiness.total);
|
||||
this.percentageResultNonBusiness =
|
||||
this.bigTotalNonBusiness <= 0
|
||||
this.bigTotalNonBusiness <= 0 ||
|
||||
this.bigTotalNonVerification <= 0
|
||||
? 0
|
||||
: this.bigTotalNonBusiness
|
||||
.div(this.bigTotalNonVerification)
|
||||
@@ -110,10 +162,10 @@ class BigData {
|
||||
}
|
||||
}
|
||||
|
||||
async getDataTotalPotensi() {
|
||||
async getDataTotalPotensi(year) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${GlobalConfig.apiHost}/api/all-task-documents`,
|
||||
`${GlobalConfig.apiHost}/api/all-task-documents?year=${year}`,
|
||||
{
|
||||
credentials: "include",
|
||||
headers: {
|
||||
@@ -132,7 +184,6 @@ class BigData {
|
||||
|
||||
const data = await response.json();
|
||||
return {
|
||||
seriesData: data.data.series,
|
||||
countData: data.data.count,
|
||||
totalData: data.data.total,
|
||||
};
|
||||
@@ -142,7 +193,7 @@ class BigData {
|
||||
}
|
||||
}
|
||||
|
||||
async getTargetPAD() {
|
||||
async getTargetPAD(year) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${GlobalConfig.apiHost}/api/api-data-settings?search=target_pad`,
|
||||
@@ -160,20 +211,24 @@ class BigData {
|
||||
|
||||
if (!response.ok) {
|
||||
console.error("Network response was not ok", response);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.data[0].value;
|
||||
const valueTargetPAD = data.data[0]?.value ?? 0;
|
||||
const currentMonth = new Date().getMonth() + 1;
|
||||
let result = (currentMonth / 12) * valueTargetPAD;
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("Error fetching chart data:", error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
async getDataVerfication() {
|
||||
async getDataVerfication(year) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${GlobalConfig.apiHost}/api/verification-documents`,
|
||||
`${GlobalConfig.apiHost}/api/verification-documents?year=${year}`,
|
||||
{
|
||||
credentials: "include",
|
||||
headers: {
|
||||
@@ -201,10 +256,10 @@ class BigData {
|
||||
}
|
||||
}
|
||||
|
||||
async getDataNonVerfication() {
|
||||
async getDataNonVerfication(year) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${GlobalConfig.apiHost}/api/non-verification-documents`,
|
||||
`${GlobalConfig.apiHost}/api/non-verification-documents?year=${year}`,
|
||||
{
|
||||
credentials: "include",
|
||||
headers: {
|
||||
@@ -232,10 +287,10 @@ class BigData {
|
||||
}
|
||||
}
|
||||
|
||||
async getDataBusiness() {
|
||||
async getDataBusiness(year) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${GlobalConfig.apiHost}/api/business-documents`,
|
||||
`${GlobalConfig.apiHost}/api/business-documents?year=${year}`,
|
||||
{
|
||||
credentials: "include",
|
||||
headers: {
|
||||
@@ -263,10 +318,10 @@ class BigData {
|
||||
}
|
||||
}
|
||||
|
||||
async getDataNonBusiness() {
|
||||
async getDataNonBusiness(year) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${GlobalConfig.apiHost}/api/non-business-documents`,
|
||||
`${GlobalConfig.apiHost}/api/non-business-documents?year=${year}`,
|
||||
{
|
||||
credentials: "include",
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user