process common module, date range filter is not a service

This commit is contained in:
Denys Vuika
2024-10-02 09:57:26 -04:00
parent fa61d28dc9
commit c0d60495d0
5 changed files with 53 additions and 32 deletions
@@ -37,11 +37,11 @@ describe('DateRangeFilterComponent', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ProcessServiceCloudTestingModule] imports: [ProcessServiceCloudTestingModule, DateRangeFilterComponent]
}); });
fixture = TestBed.createComponent(DateRangeFilterComponent); fixture = TestBed.createComponent(DateRangeFilterComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
service = TestBed.inject(DateRangeFilterService); service = new DateRangeFilterService();
component.processFilterProperty = { component.processFilterProperty = {
key: 'createdDate', key: 'createdDate',
@@ -16,13 +16,17 @@
*/ */
import { Component, Input, EventEmitter, Output, OnInit } from '@angular/core'; import { Component, Input, EventEmitter, Output, OnInit } from '@angular/core';
import { MatSelectChange } from '@angular/material/select'; import { MatSelectChange, MatSelectModule } from '@angular/material/select';
import { ProcessFilterProperties, ProcessFilterOptions } from '../../process/process-filters/models/process-filter-cloud.model'; import { ProcessFilterProperties, ProcessFilterOptions } from '../../process/process-filters/models/process-filter-cloud.model';
import { FormGroup, FormControl } from '@angular/forms'; import { FormGroup, FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { DateRangeFilter, DateCloudFilterType } from '../../models/date-cloud-filter.model'; import { DateRangeFilter, DateCloudFilterType } from '../../models/date-cloud-filter.model';
import { endOfDay, isValid, startOfDay } from 'date-fns'; import { endOfDay, isValid, startOfDay } from 'date-fns';
import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material/core'; import { DateAdapter, MAT_DATE_FORMATS, MatOptionModule } from '@angular/material/core';
import { ADF_DATE_FORMATS, AdfDateFnsAdapter } from '@alfresco/adf-core'; import { ADF_DATE_FORMATS, AdfDateFnsAdapter } from '@alfresco/adf-core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatFormFieldModule } from '@angular/material/form-field';
interface DateRangeFormProps { interface DateRangeFormProps {
from: FormControl<Date>; from: FormControl<Date>;
@@ -31,6 +35,17 @@ interface DateRangeFormProps {
@Component({ @Component({
selector: 'adf-cloud-date-range-filter', selector: 'adf-cloud-date-range-filter',
standalone: true,
imports: [
CommonModule,
TranslateModule,
MatDatepickerModule,
MatFormFieldModule,
FormsModule,
ReactiveFormsModule,
MatOptionModule,
MatSelectModule
],
styleUrls: ['./date-range-filter.component.scss'], styleUrls: ['./date-range-filter.component.scss'],
templateUrl: './date-range-filter.component.html', templateUrl: './date-range-filter.component.html',
providers: [ providers: [
@@ -15,17 +15,15 @@
* limitations under the License. * limitations under the License.
*/ */
import { TestBed } from '@angular/core/testing';
import { DateRangeFilterService } from './date-range-filter.service'; import { DateRangeFilterService } from './date-range-filter.service';
import { DateCloudFilterType } from '../../models/date-cloud-filter.model'; import { DateCloudFilterType } from '../../models/date-cloud-filter.model';
import { add, endOfDay, endOfMonth, endOfQuarter, endOfYear, startOfDay, startOfMonth, startOfQuarter, startOfYear } from 'date-fns'; import { add, endOfDay, endOfMonth, endOfQuarter, endOfYear, startOfDay, startOfMonth, startOfQuarter, startOfYear } from 'date-fns';
describe('Date Range Filter service', () => { describe('Date Range Filter service', () => {
let service: DateRangeFilterService; let service: DateRangeFilterService;
beforeEach(() => { beforeEach(() => {
service = TestBed.inject(DateRangeFilterService); service = new DateRangeFilterService();
}); });
it('should return today range', () => { it('should return today range', () => {
@@ -15,27 +15,42 @@
* limitations under the License. * limitations under the License.
*/ */
import { Injectable } from '@angular/core';
import { DateRangeFilter, DateCloudFilterType } from '../../models/date-cloud-filter.model'; import { DateRangeFilter, DateCloudFilterType } from '../../models/date-cloud-filter.model';
import { add, endOfDay, endOfMonth, endOfQuarter, endOfWeek, endOfYear, startOfDay, startOfMonth, startOfQuarter, startOfWeek, startOfYear } from 'date-fns'; import {
add,
endOfDay,
endOfMonth,
endOfQuarter,
endOfWeek,
endOfYear,
startOfDay,
startOfMonth,
startOfQuarter,
startOfWeek,
startOfYear
} from 'date-fns';
@Injectable({
providedIn: 'root'
})
export class DateRangeFilterService { export class DateRangeFilterService {
currentDate = new Date(); currentDate = new Date();
getDateRange(type: DateCloudFilterType): DateRangeFilter { getDateRange(type: DateCloudFilterType): DateRangeFilter {
switch (type) { switch (type) {
case DateCloudFilterType.TODAY: return this.getTodayDateRange(); case DateCloudFilterType.TODAY:
case DateCloudFilterType.TOMORROW: return this.getTomorrowDateRange(); return this.getTodayDateRange();
case DateCloudFilterType.NEXT_7_DAYS: return this.getNext7DaysDateRange(); case DateCloudFilterType.TOMORROW:
case DateCloudFilterType.WEEK: return this.getCurrentWeekRange(); return this.getTomorrowDateRange();
case DateCloudFilterType.MONTH: return this.getCurrentMonthDateRange(); case DateCloudFilterType.NEXT_7_DAYS:
case DateCloudFilterType.QUARTER: return this.getQuarterDateRange(); return this.getNext7DaysDateRange();
case DateCloudFilterType.YEAR: return this.getCurrentYearDateRange(); case DateCloudFilterType.WEEK:
default: return this.resetDateRange(); return this.getCurrentWeekRange();
case DateCloudFilterType.MONTH:
return this.getCurrentMonthDateRange();
case DateCloudFilterType.QUARTER:
return this.getQuarterDateRange();
case DateCloudFilterType.YEAR:
return this.getCurrentYearDateRange();
default:
return this.resetDateRange();
} }
} }
@@ -79,7 +94,7 @@ export class DateRangeFilterService {
} }
private getCurrentWeekRange(): DateRangeFilter { private getCurrentWeekRange(): DateRangeFilter {
return { return {
startDate: startOfWeek(new Date()).toISOString(), startDate: startOfWeek(new Date()).toISOString(),
endDate: endOfWeek(new Date()).toISOString() endDate: endOfWeek(new Date()).toISOString()
}; };
@@ -16,17 +16,10 @@
*/ */
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { CoreModule } from '@alfresco/adf-core';
import { DateRangeFilterComponent } from './date-range-filter/date-range-filter.component'; import { DateRangeFilterComponent } from './date-range-filter/date-range-filter.component';
import { MaterialModule } from '../material.module';
import { CommonModule } from '@angular/common';
import { DateRangeFilterService } from './date-range-filter/date-range-filter.service';
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({ @NgModule({
declarations: [DateRangeFilterComponent], imports: [DateRangeFilterComponent],
imports: [CommonModule, CoreModule, MaterialModule, ReactiveFormsModule], exports: [DateRangeFilterComponent]
exports: [DateRangeFilterComponent],
providers: [DateRangeFilterService]
}) })
export class ProcessCommonModule {} export class ProcessCommonModule {}