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(() => {
TestBed.configureTestingModule({
imports: [ProcessServiceCloudTestingModule]
imports: [ProcessServiceCloudTestingModule, DateRangeFilterComponent]
});
fixture = TestBed.createComponent(DateRangeFilterComponent);
component = fixture.componentInstance;
service = TestBed.inject(DateRangeFilterService);
service = new DateRangeFilterService();
component.processFilterProperty = {
key: 'createdDate',
@@ -16,13 +16,17 @@
*/
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 { FormGroup, FormControl } from '@angular/forms';
import { FormGroup, FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { DateRangeFilter, DateCloudFilterType } from '../../models/date-cloud-filter.model';
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 { 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 {
from: FormControl<Date>;
@@ -31,6 +35,17 @@ interface DateRangeFormProps {
@Component({
selector: 'adf-cloud-date-range-filter',
standalone: true,
imports: [
CommonModule,
TranslateModule,
MatDatepickerModule,
MatFormFieldModule,
FormsModule,
ReactiveFormsModule,
MatOptionModule,
MatSelectModule
],
styleUrls: ['./date-range-filter.component.scss'],
templateUrl: './date-range-filter.component.html',
providers: [
@@ -15,17 +15,15 @@
* limitations under the License.
*/
import { TestBed } from '@angular/core/testing';
import { DateRangeFilterService } from './date-range-filter.service';
import { DateCloudFilterType } from '../../models/date-cloud-filter.model';
import { add, endOfDay, endOfMonth, endOfQuarter, endOfYear, startOfDay, startOfMonth, startOfQuarter, startOfYear } from 'date-fns';
describe('Date Range Filter service', () => {
let service: DateRangeFilterService;
beforeEach(() => {
service = TestBed.inject(DateRangeFilterService);
service = new DateRangeFilterService();
});
it('should return today range', () => {
@@ -15,27 +15,42 @@
* limitations under the License.
*/
import { Injectable } from '@angular/core';
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 {
currentDate = new Date();
getDateRange(type: DateCloudFilterType): DateRangeFilter {
switch (type) {
case DateCloudFilterType.TODAY: return this.getTodayDateRange();
case DateCloudFilterType.TOMORROW: return this.getTomorrowDateRange();
case DateCloudFilterType.NEXT_7_DAYS: return this.getNext7DaysDateRange();
case DateCloudFilterType.WEEK: 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();
case DateCloudFilterType.TODAY:
return this.getTodayDateRange();
case DateCloudFilterType.TOMORROW:
return this.getTomorrowDateRange();
case DateCloudFilterType.NEXT_7_DAYS:
return this.getNext7DaysDateRange();
case DateCloudFilterType.WEEK:
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 {
return {
return {
startDate: startOfWeek(new Date()).toISOString(),
endDate: endOfWeek(new Date()).toISOString()
};
@@ -16,17 +16,10 @@
*/
import { NgModule } from '@angular/core';
import { CoreModule } from '@alfresco/adf-core';
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({
declarations: [DateRangeFilterComponent],
imports: [CommonModule, CoreModule, MaterialModule, ReactiveFormsModule],
exports: [DateRangeFilterComponent],
providers: [DateRangeFilterService]
imports: [DateRangeFilterComponent],
exports: [DateRangeFilterComponent]
})
export class ProcessCommonModule {}