mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
1e152c666c
* chore: moved app & space from apps to root * chore: modified workspace configuration * chore: modified dockerfiles for space and web * chore: modified icons for space * feat: updated files for new svg icons supported by next-images * chore: added /spaces base path for next * chore: added compose config for space * chore: updated husky configuration * chore: updated workflows for new configuration * chore: changed app name to web * fix: resolved build errors with web * chore: reset file tracing root for both projects * chore: added nginx config for deploy * fix: eslint and tsconfig settings for space app * husky setup fixes based on new dir * eslint fixes * prettier formatting --------- Co-authored-by: Henit Chobisa <chobisa.henit@gmail.com>
115 lines
3.9 KiB
TypeScript
115 lines
3.9 KiB
TypeScript
// types
|
|
import { ChartDataType } from "../types";
|
|
// data
|
|
import { weeks, months } from "../data";
|
|
// helpers
|
|
import { getDatesBetweenTwoDates, getWeeksByMonthAndYear } from "./helpers";
|
|
|
|
const generateMonthDataByMonthAndYearInMonthView = (month: number, year: number) => {
|
|
const currentMonth: number = month;
|
|
const currentYear: number = year;
|
|
const today = new Date();
|
|
|
|
const weeksBetweenTwoDates = getWeeksByMonthAndYear(month, year);
|
|
|
|
const weekPayload = {
|
|
year: currentYear,
|
|
month: currentMonth,
|
|
monthData: months[currentMonth],
|
|
children: weeksBetweenTwoDates.map((weekData: any) => {
|
|
const date: Date = weekData.startDate;
|
|
return {
|
|
date: date,
|
|
startDate: weekData.startDate,
|
|
endDate: weekData.endDate,
|
|
day: date.getDay(),
|
|
dayData: weeks[date.getDay()],
|
|
weekNumber: weekData.weekNumber,
|
|
title: `W${weekData.weekNumber} (${date.getDate()})`,
|
|
active: false,
|
|
today: today >= weekData.startDate && today <= weekData.endDate ? true : false,
|
|
};
|
|
}),
|
|
title: `${months[currentMonth].title} ${currentYear}`,
|
|
};
|
|
|
|
return weekPayload;
|
|
};
|
|
|
|
export const generateYearChart = (yearPayload: ChartDataType, side: null | "left" | "right") => {
|
|
let renderState = yearPayload;
|
|
const renderPayload: any = [];
|
|
|
|
const range: number = renderState.data.approxFilterRange || 6;
|
|
let filteredDates: Date[] = [];
|
|
let minusDate: Date = new Date();
|
|
let plusDate: Date = new Date();
|
|
|
|
if (side === null) {
|
|
const currentDate = renderState.data.currentDate;
|
|
|
|
minusDate = new Date(currentDate.getFullYear(), currentDate.getMonth() - range, 1);
|
|
plusDate = new Date(currentDate.getFullYear(), currentDate.getMonth() + range, 0);
|
|
|
|
if (minusDate && plusDate) filteredDates = getDatesBetweenTwoDates(minusDate, plusDate);
|
|
|
|
renderState = {
|
|
...renderState,
|
|
data: {
|
|
...renderState.data,
|
|
startDate: filteredDates[0],
|
|
endDate: filteredDates[filteredDates.length - 1],
|
|
},
|
|
};
|
|
} else if (side === "left") {
|
|
const currentDate = renderState.data.startDate;
|
|
|
|
minusDate = new Date(currentDate.getFullYear(), currentDate.getMonth() - range, 1);
|
|
plusDate = new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 0);
|
|
|
|
if (minusDate && plusDate) filteredDates = getDatesBetweenTwoDates(minusDate, plusDate);
|
|
|
|
renderState = {
|
|
...renderState,
|
|
data: { ...renderState.data, startDate: filteredDates[0] },
|
|
};
|
|
} else if (side === "right") {
|
|
const currentDate = renderState.data.endDate;
|
|
|
|
minusDate = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1);
|
|
plusDate = new Date(currentDate.getFullYear(), currentDate.getMonth() + range, 0);
|
|
|
|
if (minusDate && plusDate) filteredDates = getDatesBetweenTwoDates(minusDate, plusDate);
|
|
|
|
renderState = {
|
|
...renderState,
|
|
data: { ...renderState.data, endDate: filteredDates[filteredDates.length - 1] },
|
|
};
|
|
}
|
|
|
|
if (filteredDates && filteredDates.length > 0)
|
|
for (const currentDate in filteredDates) {
|
|
const date = filteredDates[parseInt(currentDate)];
|
|
const currentYear = date.getFullYear();
|
|
const currentMonth = date.getMonth();
|
|
renderPayload.push(generateMonthDataByMonthAndYearInMonthView(currentMonth, currentYear));
|
|
}
|
|
|
|
const scrollWidth =
|
|
renderPayload
|
|
.map((monthData: any) => monthData.children.length)
|
|
.reduce((partialSum: number, a: number) => partialSum + a, 0) * yearPayload.data.width;
|
|
|
|
return { state: renderState, payload: renderPayload, scrollWidth: scrollWidth };
|
|
};
|
|
|
|
export const getNumberOfDaysBetweenTwoDatesInYear = (startDate: Date, endDate: Date) => {
|
|
let weeksDifference: number = 0;
|
|
|
|
const timeDiff = Math.abs(endDate.getTime() - startDate.getTime());
|
|
const diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
|
weeksDifference = Math.floor(diffDays / 7);
|
|
|
|
return weeksDifference;
|
|
};
|