@skysoftware-co/bayan-hr-widgets-ui 1.0.26 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2248,7 +2248,9 @@ class MyCalendarWidgetComponent {
2248
2248
  selfWidgetsService;
2249
2249
  baseUrl = '';
2250
2250
  headerContainerClass = '';
2251
+ datasource = null;
2251
2252
  isLoadingChanged = new EventEmitter();
2253
+ //test
2252
2254
  calendarIcon = faCalendarDays;
2253
2255
  legendContainerClass = 'row mb-2';
2254
2256
  legendRowClass = 'd-flex';
@@ -2270,17 +2272,29 @@ class MyCalendarWidgetComponent {
2270
2272
  eventsColor = this.constants.defaultEventsColor;
2271
2273
  hrCalendar;
2272
2274
  scheduleCalenderVacation = [];
2273
- minDate = new Date();
2275
+ minDate;
2274
2276
  maxDate;
2277
+ baseCalendarData = [];
2278
+ hrVacations = [];
2279
+ calendarLoaded = false;
2275
2280
  constructor(selfWidgetsService) {
2276
2281
  this.selfWidgetsService = selfWidgetsService;
2277
- const currentDate = moment().date(1).subtract(1, 'month');
2278
- this.minDate = new Date(currentDate.year(), currentDate.month(), currentDate.date());
2279
- this.maxDate = new Date(this.minDate.getFullYear() + 1, this.minDate.getMonth() + 1, 0);
2282
+ this.initDateRange();
2280
2283
  }
2281
2284
  ngOnInit() {
2282
2285
  this.loadCalendar();
2283
2286
  }
2287
+ ngOnChanges(changes) {
2288
+ if (changes['datasource'] && this.datasource && this.calendarLoaded) {
2289
+ this.buildCalendarData();
2290
+ this.refreshCalendar();
2291
+ }
2292
+ }
2293
+ initDateRange() {
2294
+ const currentDate = moment().date(1).subtract(1, 'month');
2295
+ this.minDate = new Date(currentDate.year(), currentDate.month(), currentDate.date());
2296
+ this.maxDate = new Date(this.minDate.getFullYear() + 1, this.minDate.getMonth() + 1, 0);
2297
+ }
2284
2298
  getCalendar(month, year, monthsCount) {
2285
2299
  return this.selfWidgetsService.getCalendar(this.baseUrl, month, year, monthsCount);
2286
2300
  }
@@ -2294,46 +2308,54 @@ class MyCalendarWidgetComponent {
2294
2308
  this.isLoadingChanged.emit(false);
2295
2309
  this.mapCalendarData(response.ResponseData);
2296
2310
  },
2297
- error: (error) => {
2311
+ error: () => {
2298
2312
  this.isLoadingChanged.emit(false);
2299
2313
  },
2300
2314
  });
2301
2315
  }
2302
2316
  mapCalendarData(data) {
2303
- const result = [];
2304
- for (const v of data.Vacations) {
2305
- result.push({
2306
- VacationType: ScheduleVacationTypes.Vacations,
2307
- Description: v.VacationTypeName,
2308
- Color: v.Color,
2309
- VacationDays: { StartDate: v.StartDate, EndDate: v.EndDate }
2310
- });
2311
- }
2312
- for (const ph of data.PublicHolidays) {
2313
- result.push({
2317
+ this.baseCalendarData = [
2318
+ ...data.PublicHolidays.map(ph => ({
2314
2319
  VacationType: ScheduleVacationTypes.PublicHoliday,
2315
2320
  Description: ph.Description,
2316
2321
  Color: this.publicHolidayColor,
2317
2322
  VacationDays: { StartDate: ph.StartDate, EndDate: ph.EndDate }
2318
- });
2319
- }
2320
- for (const od of data.OffDays) {
2321
- result.push({
2323
+ })),
2324
+ ...data.OffDays.map(od => ({
2322
2325
  VacationType: ScheduleVacationTypes.DaysOff,
2323
2326
  Description: this.translatePipe.transform('DayOff'),
2324
2327
  Color: this.dayOffColor,
2325
2328
  VacationDays: { StartDate: od, EndDate: od }
2326
- });
2327
- }
2328
- for (const ev of data.Events) {
2329
- result.push({
2330
- VacationType: ScheduleVacationTypes.Events,
2331
- Description: ev.Description,
2332
- Color: this.eventsColor,
2333
- VacationDays: { StartDate: ev.StartDate, EndDate: ev.EndDate }
2334
- });
2335
- }
2336
- this.scheduleCalenderVacation = result;
2329
+ }))
2330
+ ];
2331
+ this.hrVacations = (data.Vacations ?? []).map(v => ({
2332
+ VacationType: ScheduleVacationTypes.Vacations,
2333
+ Description: v.VacationTypeName,
2334
+ Color: v.Color,
2335
+ VacationDays: { StartDate: v.StartDate, EndDate: v.EndDate }
2336
+ }));
2337
+ this.calendarLoaded = true;
2338
+ this.buildCalendarData();
2339
+ this.refreshCalendar();
2340
+ }
2341
+ buildCalendarData() {
2342
+ const pendingVacations = this.datasource?.PendingVacationRequests?.map(v => ({
2343
+ VacationType: ScheduleVacationTypes.Vacations,
2344
+ Description: v.VacationTypeName,
2345
+ Color: v.Color,
2346
+ VacationDays: { StartDate: v.StartDate, EndDate: v.EndDate }
2347
+ })) ?? [];
2348
+ const mergedVacations = this.mergeConsecutiveVacations([...this.hrVacations, ...pendingVacations]
2349
+ .sort((a, b) => new Date(a.VacationDays.StartDate).getTime() - new Date(b.VacationDays.StartDate).getTime()));
2350
+ const events = this.datasource?.PendingEventRequests?.map(ev => ({
2351
+ VacationType: ScheduleVacationTypes.Events,
2352
+ Description: ev.Description,
2353
+ Color: this.eventsColor,
2354
+ VacationDays: { StartDate: ev.StartDate, EndDate: ev.EndDate }
2355
+ })) ?? [];
2356
+ this.scheduleCalenderVacation = [...mergedVacations, ...this.baseCalendarData, ...events];
2357
+ }
2358
+ refreshCalendar() {
2337
2359
  setTimeout(() => {
2338
2360
  if (this.hrCalendar?.calendar) {
2339
2361
  this.hrCalendar.calendar.instance._refresh();
@@ -2341,8 +2363,42 @@ class MyCalendarWidgetComponent {
2341
2363
  }
2342
2364
  }, 100);
2343
2365
  }
2366
+ mergeConsecutiveVacations(vacations) {
2367
+ if (vacations.length === 0)
2368
+ return [];
2369
+ const grouped = new Map();
2370
+ for (const v of vacations) {
2371
+ const key = `${v.Description}|${v.Color ?? ''}`;
2372
+ if (!grouped.has(key))
2373
+ grouped.set(key, []);
2374
+ grouped.get(key).push(v);
2375
+ }
2376
+ const result = [];
2377
+ grouped.forEach((items) => {
2378
+ items.sort((a, b) => new Date(a.VacationDays.StartDate).getTime() - new Date(b.VacationDays.StartDate).getTime());
2379
+ let merged = { ...items[0], VacationDays: { ...items[0].VacationDays } };
2380
+ for (let i = 1; i < items.length; i++) {
2381
+ const current = items[i];
2382
+ const lastEnd = new Date(merged.VacationDays.EndDate);
2383
+ const currentStart = new Date(current.VacationDays.StartDate);
2384
+ const diffDays = (currentStart.getTime() - lastEnd.getTime()) / (1000 * 60 * 60 * 24);
2385
+ if (diffDays <= 1) {
2386
+ const currentEnd = new Date(current.VacationDays.EndDate);
2387
+ if (currentEnd.getTime() > lastEnd.getTime()) {
2388
+ merged.VacationDays.EndDate = current.VacationDays.EndDate;
2389
+ }
2390
+ }
2391
+ else {
2392
+ result.push(merged);
2393
+ merged = { ...current, VacationDays: { ...current.VacationDays } };
2394
+ }
2395
+ }
2396
+ result.push(merged);
2397
+ });
2398
+ return result.sort((a, b) => new Date(a.VacationDays.StartDate).getTime() - new Date(b.VacationDays.StartDate).getTime());
2399
+ }
2344
2400
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: MyCalendarWidgetComponent, deps: [{ token: HRSelfWidgetsService }], target: i0.ɵɵFactoryTarget.Component });
2345
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.20", type: MyCalendarWidgetComponent, isStandalone: true, selector: "hr-my-calendar-widget", inputs: { baseUrl: "baseUrl", headerContainerClass: "headerContainerClass", legendContainerClass: "legendContainerClass", legendRowClass: "legendRowClass", legendItemClass: "legendItemClass", legendDotClass: "legendDotClass", legendLabelClass: "legendLabelClass", publicHolidayDotClass: "publicHolidayDotClass", dayOffDotClass: "dayOffDotClass", eventsDotClass: "eventsDotClass", vacationsContainerClass: "vacationsContainerClass", vacationsItemClass: "vacationsItemClass", vacationsIconClass: "vacationsIconClass", calendarContainerClass: "calendarContainerClass", calendarClass: "calendarClass", publicHolidayColor: "publicHolidayColor", dayOffColor: "dayOffColor", eventsColor: "eventsColor" }, outputs: { isLoadingChanged: "isLoadingChanged" }, viewQueries: [{ propertyName: "hrCalendar", first: true, predicate: HREmployeeCalendarComponent, descendants: true }], ngImport: i0, template: "<hr-card-header\r\n [icon]=\"calendarIcon\"\r\n [title]=\"'Calendar' | HRTranslate\"\r\n [containerClass]=\"'d-flex align-items-center mb-3 ' + headerContainerClass\">\r\n</hr-card-header>\r\n<hr-employee-calendar\r\n [showEvents]=\"true\"\r\n [showUpComingVacations]=\"true\"\r\n [scheduleCalenderVacation]=\"scheduleCalenderVacation\"\r\n [minDate]=\"minDate\"\r\n [maxDate]=\"maxDate\"\r\n [legendContainerClass]=\"legendContainerClass\"\r\n [legendRowClass]=\"legendRowClass\"\r\n [legendItemClass]=\"legendItemClass\"\r\n [legendDotClass]=\"legendDotClass\"\r\n [legendLabelClass]=\"legendLabelClass\"\r\n [publicHolidayDotClass]=\"publicHolidayDotClass\"\r\n [dayOffDotClass]=\"dayOffDotClass\"\r\n [eventsDotClass]=\"eventsDotClass\"\r\n [vacationsContainerClass]=\"vacationsContainerClass\"\r\n [vacationsItemClass]=\"vacationsItemClass\"\r\n [vacationsIconClass]=\"vacationsIconClass\"\r\n [calendarContainerClass]=\"calendarContainerClass\"\r\n [calendarClass]=\"calendarClass\">\r\n</hr-employee-calendar>\r\n", dependencies: [{ kind: "component", type: HREmployeeCalendarComponent, selector: "hr-employee-calendar", inputs: ["showEvents", "showUpComingVacations", "scheduleCalenderVacation", "minDate", "maxDate", "legendContainerClass", "legendRowClass", "legendItemClass", "legendDotClass", "legendLabelClass", "publicHolidayDotClass", "dayOffDotClass", "eventsDotClass", "vacationsContainerClass", "vacationsItemClass", "vacationsIconClass", "calendarContainerClass", "calendarClass"] }, { kind: "component", type: HRCardHeaderComponent, selector: "hr-card-header", inputs: ["icon", "title", "containerClass", "iconClass", "titleClass"] }, { kind: "pipe", type: HRTranslatePipe, name: "HRTranslate" }] });
2401
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.20", type: MyCalendarWidgetComponent, isStandalone: true, selector: "hr-my-calendar-widget", inputs: { baseUrl: "baseUrl", headerContainerClass: "headerContainerClass", datasource: "datasource", legendContainerClass: "legendContainerClass", legendRowClass: "legendRowClass", legendItemClass: "legendItemClass", legendDotClass: "legendDotClass", legendLabelClass: "legendLabelClass", publicHolidayDotClass: "publicHolidayDotClass", dayOffDotClass: "dayOffDotClass", eventsDotClass: "eventsDotClass", vacationsContainerClass: "vacationsContainerClass", vacationsItemClass: "vacationsItemClass", vacationsIconClass: "vacationsIconClass", calendarContainerClass: "calendarContainerClass", calendarClass: "calendarClass", publicHolidayColor: "publicHolidayColor", dayOffColor: "dayOffColor", eventsColor: "eventsColor" }, outputs: { isLoadingChanged: "isLoadingChanged" }, viewQueries: [{ propertyName: "hrCalendar", first: true, predicate: HREmployeeCalendarComponent, descendants: true }], usesOnChanges: true, ngImport: i0, template: "<hr-card-header\r\n [icon]=\"calendarIcon\"\r\n [title]=\"'Calendar' | HRTranslate\"\r\n [containerClass]=\"'d-flex align-items-center mb-3 ' + headerContainerClass\">\r\n</hr-card-header>\r\n<hr-employee-calendar\r\n [showEvents]=\"true\"\r\n [showUpComingVacations]=\"true\"\r\n [scheduleCalenderVacation]=\"scheduleCalenderVacation\"\r\n [minDate]=\"minDate\"\r\n [maxDate]=\"maxDate\"\r\n [legendContainerClass]=\"legendContainerClass\"\r\n [legendRowClass]=\"legendRowClass\"\r\n [legendItemClass]=\"legendItemClass\"\r\n [legendDotClass]=\"legendDotClass\"\r\n [legendLabelClass]=\"legendLabelClass\"\r\n [publicHolidayDotClass]=\"publicHolidayDotClass\"\r\n [dayOffDotClass]=\"dayOffDotClass\"\r\n [eventsDotClass]=\"eventsDotClass\"\r\n [vacationsContainerClass]=\"vacationsContainerClass\"\r\n [vacationsItemClass]=\"vacationsItemClass\"\r\n [vacationsIconClass]=\"vacationsIconClass\"\r\n [calendarContainerClass]=\"calendarContainerClass\"\r\n [calendarClass]=\"calendarClass\">\r\n</hr-employee-calendar>\r\n", dependencies: [{ kind: "component", type: HREmployeeCalendarComponent, selector: "hr-employee-calendar", inputs: ["showEvents", "showUpComingVacations", "scheduleCalenderVacation", "minDate", "maxDate", "legendContainerClass", "legendRowClass", "legendItemClass", "legendDotClass", "legendLabelClass", "publicHolidayDotClass", "dayOffDotClass", "eventsDotClass", "vacationsContainerClass", "vacationsItemClass", "vacationsIconClass", "calendarContainerClass", "calendarClass"] }, { kind: "component", type: HRCardHeaderComponent, selector: "hr-card-header", inputs: ["icon", "title", "containerClass", "iconClass", "titleClass"] }, { kind: "pipe", type: HRTranslatePipe, name: "HRTranslate" }] });
2346
2402
  }
2347
2403
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: MyCalendarWidgetComponent, decorators: [{
2348
2404
  type: Component,
@@ -2351,6 +2407,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImpo
2351
2407
  type: Input
2352
2408
  }], headerContainerClass: [{
2353
2409
  type: Input
2410
+ }], datasource: [{
2411
+ type: Input
2354
2412
  }], isLoadingChanged: [{
2355
2413
  type: Output
2356
2414
  }], legendContainerClass: [{