Skip to content

Commit 87dc652

Browse files
fix: fixes for options time range and add custom option
1 parent 92c8865 commit 87dc652

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

src/app/app.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { MatDatepickerModule } from '@angular/material/datepicker';
1515
import { MatInputModule } from '@angular/material/input';
1616
import { MatIconModule } from '@angular/material/icon';
1717
import { MatCardModule } from '@angular/material/card';
18+
import { MatCheckboxModule } from '@angular/material/checkbox';
19+
import { MatListModule } from '@angular/material/list';
1820
import { MatNativeDateModule } from '@angular/material/core';
1921
import { MatMomentDateModule } from '@angular/material-moment-adapter';
2022
import { NgxPaginationModule } from 'ngx-pagination';
@@ -176,6 +178,8 @@ const maskConfig: Partial<IConfig> = {
176178
DragDropModule,
177179
MatIconModule,
178180
MatCardModule,
181+
MatCheckboxModule,
182+
MatListModule,
179183
MatNativeDateModule,
180184
StoreModule.forRoot(reducers, {
181185
metaReducers,
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
<mat-card class="mat-elevation-z3">
2-
<button
3-
*ngFor="let item of customPresets"
4-
mat-button
5-
color="primary"
6-
(click)="selectRange(item)"
7-
>
8-
{{ item }}
9-
</button>
10-
</mat-card>
1+
<div class="list-time-range">
2+
<mat-selection-list class="custom-items-time-range">
3+
<mat-list-option color="primary" class="custom-mat-list-option" (click)="resetTimeRange()">
4+
custom
5+
</mat-list-option>
6+
</mat-selection-list>
7+
<mat-selection-list class="custom-items-time-range" [multiple]="false">
8+
<mat-list-option class="custom-mat-list-option" *ngFor="let item of customPresets" [value]="item" (click)="selectRange(item)" >
9+
{{item}}
10+
</mat-list-option>
11+
</mat-selection-list>
12+
</div>

src/app/modules/reports/components/time-range-custom/time-range-panel/time-range-panel.component.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,16 @@ $width: 128px;
1212
display: flex;
1313
width: 100%;
1414
}
15+
16+
.list-time-range{
17+
background-color: white;
18+
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
19+
}
20+
21+
.custom-items-time-range{
22+
padding-top: 0 !important;
23+
}
24+
25+
.custom-mat-list-option{
26+
height: 35px !important;
27+
}

src/app/modules/reports/components/time-range-custom/time-range-panel/time-range-panel.component.spec.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { MatCardModule } from '@angular/material/card';
33
import { MatNativeDateModule } from '@angular/material/core';
44
import { MatDateRangePicker } from '@angular/material/datepicker';
55
import { MatDialogModule } from '@angular/material/dialog';
6+
import { MatListModule } from '@angular/material/list';
67
import { By } from '@angular/platform-browser';
78
import { ToastrService } from 'ngx-toastr';
89
import { TimeRangePanelComponent } from './time-range-panel.component';
@@ -22,7 +23,7 @@ describe('TimeRangePanelComponent', () => {
2223

2324
beforeEach(async () => {
2425
await TestBed.configureTestingModule({
25-
imports: [MatNativeDateModule, MatDialogModule, MatCardModule],
26+
imports: [MatNativeDateModule, MatDialogModule, MatCardModule, MatListModule],
2627
declarations: [ TimeRangePanelComponent ],
2728
providers: [
2829
{ provide: MatDateRangePicker, useValue: {select: valueFunction, close: valueFunction} },
@@ -41,17 +42,11 @@ describe('TimeRangePanelComponent', () => {
4142
expect(component).toBeTruthy();
4243
});
4344

44-
it('should click selectRange button', () => {
45-
spyOn(component, 'selectRange');
46-
component.selectRange('this year');
47-
48-
fixture.detectChanges();
49-
50-
fixture.debugElement.query(By.css('button')).nativeElement.click();
51-
expect(component.selectRange).toHaveBeenCalledWith('this year');
45+
it('should call resetTimeRange method and clean time range input ', () => {
46+
component.resetTimeRange();
47+
expect(component.picker.startAt).toEqual(undefined);
5248
});
5349

54-
5550
it('should click selectRange button and call calculateDateRange method', () => {
5651
spyOn(component, 'calculateDateRange').and.returnValues(['', '']);
5752
component.selectRange('today');

src/app/modules/reports/components/time-range-custom/time-range-panel/time-range-panel.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectionStrategy, Component, HostBinding } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, EventEmitter, HostBinding, Output } from '@angular/core';
22
import { DateAdapter } from '@angular/material/core';
33
import { MatDateRangePicker } from '@angular/material/datepicker';
44
import { ToastrService } from 'ngx-toastr';
@@ -108,4 +108,10 @@ export class TimeRangePanelComponent<D> {
108108
}
109109
return today;
110110
}
111+
112+
resetTimeRange() {
113+
this.picker.select(undefined);
114+
this.picker.select(undefined);
115+
}
116+
111117
}

0 commit comments

Comments
 (0)