V1.2
This commit is contained in:
1 parent
7fc7653e6f
commit
d8759eee29
25 files changed
+318
-121
No files matched your search
@@ -31,24 +31,25 @@ export class CalendarService {
|
||||
if (day) {
|
||||
this.setWeekendSelection(day, selectedDates);
|
||||
if (holidays.some(holiday => holiday.getTime() === day.getTime())) {
|
||||
selectedDates.push(new SelectedDate(DayType.CLOSED_DAY, new DateRange<Date>(day, day)));
|
||||
selectedDates._datesSelected.push(new SelectedDate(DayType.CLOSED_DAY, new DateRange<Date>(day, day)));
|
||||
}
|
||||
if (day.getDate() === new Date().getDate() && day.getMonth() === new Date().getMonth() && day.getFullYear() === new Date().getFullYear()) {
|
||||
selectedDates.push(new SelectedDate(DayType.TODAY, new DateRange<Date>(day, day)));
|
||||
selectedDates._datesSelected.push(new SelectedDate(DayType.TODAY, new DateRange<Date>(day, day)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
selectedDates.update();
|
||||
return selectedDates;
|
||||
}
|
||||
|
||||
setWeekendSelection(date: Date, selectedDates: SelectedDates) {
|
||||
if (date.getDay() === 6) {
|
||||
selectedDates.push(new SelectedDate(DayType.WEEKEND, new DateRange<Date>(date, new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1))));
|
||||
selectedDates._datesSelected.push(new SelectedDate(DayType.WEEKEND, new DateRange<Date>(date, new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1))));
|
||||
}
|
||||
if (date.getDate() === 1 && date.getDay() === 0) {
|
||||
selectedDates.push(new SelectedDate(DayType.WEEKEND, new DateRange<Date>(new Date(date.getFullYear(), date.getMonth(), date.getDate() - 1), date)));
|
||||
selectedDates._datesSelected.push(new SelectedDate(DayType.WEEKEND, new DateRange<Date>(new Date(date.getFullYear(), date.getMonth(), date.getDate() - 1), date)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +227,11 @@ export class SelectedDates implements SelectedDateInterface {
|
||||
_datesSelected: SelectedDate[] = [];
|
||||
datesSelected: SelectedDate[] = [];
|
||||
|
||||
update(): void {
|
||||
this.datesSelected = this._datesSelected.slice();
|
||||
this.grouping();
|
||||
}
|
||||
|
||||
push(selectedDate: SelectedDate) {
|
||||
this._datesSelected.push(selectedDate);
|
||||
this.datesSelected = this._datesSelected.slice();
|
||||
@@ -436,21 +442,21 @@ export class SelectedDates implements SelectedDateInterface {
|
||||
optimizeVacations(vacationsNumber: VacationsNumber): void {
|
||||
this.samediMalin(vacationsNumber);
|
||||
while (vacationsNumber.cp > 0) {
|
||||
const result = this.lookForVacationRec(DayType.CP);
|
||||
const result = this.lookForVacation(DayType.CP);
|
||||
if (result.heuristic === -1) {
|
||||
break;
|
||||
}
|
||||
vacationsNumber.cp -= 1;
|
||||
}
|
||||
while (vacationsNumber.rtt > 0) {
|
||||
const result = this.lookForVacationRec(DayType.RTT);
|
||||
const result = this.lookForVacation(DayType.RTT);
|
||||
if (result.heuristic === -1) {
|
||||
break;
|
||||
}
|
||||
vacationsNumber.rtt -= 1;
|
||||
}
|
||||
while (vacationsNumber.other > 0) {
|
||||
const result = this.lookForVacationRec(DayType.OTHER);
|
||||
const result = this.lookForVacation(DayType.OTHER);
|
||||
if (result.heuristic === -1) {
|
||||
break;
|
||||
}
|
||||
@@ -570,7 +576,7 @@ export class SelectedDates implements SelectedDateInterface {
|
||||
}
|
||||
}
|
||||
|
||||
lookForVacationRec(vacType: DayType): { apply: () => void; heuristic: number } {
|
||||
lookForVacation(vacType: DayType): { apply: () => void; heuristic: number } {
|
||||
const daysOfYear = CalendarService.monthsInAYearFromNow();
|
||||
const now = new Date();
|
||||
now.setHours(0, 0, 0, 0);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ThemeService } from './theme-service';
|
||||
|
||||
describe('ThemeService', () => {
|
||||
let service: ThemeService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ThemeService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ThemeService {
|
||||
private lightModeMedia = window.matchMedia('(prefers-color-scheme: light)');
|
||||
isLightMode = signal(this.lightModeMedia.matches);
|
||||
|
||||
constructor() {
|
||||
this.toggleTheme(this.isLightMode());
|
||||
this.lightModeMedia.addEventListener('change', (e) => {
|
||||
this.isLightMode.set(e.matches);
|
||||
});
|
||||
}
|
||||
|
||||
toggleTheme(forceLight?: boolean) {
|
||||
const isLight = forceLight ?? !this.isLightMode();
|
||||
this.isLightMode.set(isLight);
|
||||
document.body.classList.toggle('light-mode', isLight);
|
||||
document.body.classList.toggle('dark-mode', !isLight);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
import { Injectable, signal, PLATFORM_ID, inject } from '@angular/core';
|
||||
import { isPlatformBrowser } from '@angular/common';
|
||||
import Holidays, { HolidaysTypes } from 'date-holidays';
|
||||
import { VacationsNumber } from './calendar-service';
|
||||
|
||||
|
||||
@@ -9,24 +7,16 @@ import { VacationsNumber } from './calendar-service';
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserInputService {
|
||||
private platformId = inject(PLATFORM_ID);
|
||||
|
||||
private getRandomNumber(): number {
|
||||
return Math.floor(Math.random() * 9) + 1;
|
||||
}
|
||||
|
||||
private getInitialValues(): VacationsNumber {
|
||||
if (isPlatformBrowser(this.platformId)) {
|
||||
return {
|
||||
cp: this.getRandomNumber(),
|
||||
rtt: this.getRandomNumber(),
|
||||
other: this.getRandomNumber()
|
||||
};
|
||||
}
|
||||
return {
|
||||
cp: 0,
|
||||
rtt: 0,
|
||||
other: 0
|
||||
cp: this.getRandomNumber(),
|
||||
rtt: this.getRandomNumber(),
|
||||
other: this.getRandomNumber()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user