Skip to content

Commit b80f391

Browse files
committed
feat(arc-lib): created component zoombar and scrollbar
created component zoombar and scrollbar GH-58
1 parent 755b2df commit b80f391

14 files changed

+308
-10
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="w-100 p-3 mt-1 display-flex flex-direction-row">
2+
<nb-icon
3+
icon="chevron-left"
4+
class="gantt-scroll-icon cursor-pointer"
5+
(click)="scrollBack()"
6+
></nb-icon>
7+
<nb-icon
8+
icon="chevron-right"
9+
class="gantt-scroll-icon cursor-pointer"
10+
(click)="scrollForward()"
11+
></nb-icon>
12+
</div>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gantt-scroll-icon {
2+
height: 2rem;
3+
width: 2rem;
4+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {ComponentFixture, TestBed} from '@angular/core/testing';
2+
3+
import {GanttScrollComponent} from './gantt-scroll.component';
4+
5+
describe('GanttScrollComponent', () => {
6+
let component: GanttScrollComponent;
7+
let fixture: ComponentFixture<GanttScrollComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [GanttScrollComponent],
12+
}).compileComponents();
13+
14+
fixture = TestBed.createComponent(GanttScrollComponent);
15+
component = fixture.componentInstance;
16+
fixture.detectChanges();
17+
});
18+
19+
it('should create', () => {
20+
expect(component).toBeTruthy();
21+
});
22+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {Component, Inject} from '@angular/core';
2+
import {AnyObject} from '@project-lib/core/api';
3+
import {GANTT_SCALES} from '../../const';
4+
import {GanttService} from '../../services';
5+
import {GanttScaleService} from '../../types';
6+
7+
@Component({
8+
selector: 'arc-gantt-scroll',
9+
templateUrl: './gantt-scroll.component.html',
10+
styleUrls: ['./gantt-scroll.component.scss'],
11+
})
12+
export class GanttScrollComponent<T extends AnyObject> {
13+
constructor(
14+
private ganttService: GanttService<T>,
15+
@Inject(GANTT_SCALES)
16+
private readonly scales: GanttScaleService<T>[],
17+
) {}
18+
scrollBack() {
19+
const selectedScale = this.ganttService.selectedScale;
20+
const scale = this.scales.find(s => s.scale === selectedScale);
21+
scale?.scroll(false, this.ganttService);
22+
}
23+
scrollForward() {
24+
const selectedScale = this.ganttService.selectedScale;
25+
const scale = this.scales.find(s => s.scale === selectedScale);
26+
scale?.scroll(true, this.ganttService);
27+
}
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<nb-layout>
2+
<nb-layout-header fixed>
3+
<div class="icon-wrapper">
4+
<nb-icon class="icon" icon="fit_content" (click)="fitToScreen()">
5+
</nb-icon>
6+
<nb-icon class="icon" pack="eva" name="maximize-outline"></nb-icon>
7+
<nb-icon class="icon" icon="star" (click)="zoomIn()"> </nb-icon>
8+
<nb-icon class="icon" icon="heart-outline" (click)="zoomOut()"> </nb-icon>
9+
</div>
10+
</nb-layout-header>
11+
</nb-layout>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.icon-wrapper {
2+
display: flex;
3+
gap: 16px;
4+
}
5+
6+
.icon {
7+
cursor: pointer;
8+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {ComponentFixture, TestBed} from '@angular/core/testing';
2+
3+
import {GanttZoomBarComponent} from './gantt-zoombar.component';
4+
import {AnyObject} from '@project-lib/core/api';
5+
import {CoreModule} from '@project-lib/core/core.module';
6+
import {LocalizationModule} from '@project-lib/core/localization';
7+
import {IconPacksManagerService} from '@project-lib/theme/services';
8+
import {ThemeModule} from '@project-lib/theme/theme.module';
9+
import {GanttProviders, GANTT_SCALES} from '../../const';
10+
11+
describe('GanttZoomBarComponent', () => {
12+
let component: GanttZoomBarComponent<AnyObject>;
13+
let fixture: ComponentFixture<GanttZoomBarComponent<AnyObject>>;
14+
let service: IconPacksManagerService;
15+
16+
beforeEach(async () => {
17+
await TestBed.configureTestingModule({
18+
declarations: [GanttZoomBarComponent],
19+
providers: [
20+
GanttProviders,
21+
{
22+
provide: GANTT_SCALES,
23+
useValue: [],
24+
},
25+
],
26+
imports: [ThemeModule.forRoot('arc'), LocalizationModule, CoreModule],
27+
}).compileComponents();
28+
service = TestBed.inject(IconPacksManagerService);
29+
service.registerFontAwesome();
30+
service.registerSvgs();
31+
});
32+
33+
beforeEach(() => {
34+
fixture = TestBed.createComponent(GanttZoomBarComponent);
35+
component = fixture.componentInstance;
36+
fixture.detectChanges();
37+
});
38+
39+
it('should create', () => {
40+
expect(component).toBeTruthy();
41+
});
42+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {Component} from '@angular/core';
2+
import {TranslateService} from '@ngx-translate/core';
3+
import {TranslationService} from '@project-lib/core/localization';
4+
import {GanttService} from '../../services';
5+
import {AnyObject} from '@project-lib/core/api';
6+
import {TimelineArray} from '../../types';
7+
8+
@Component({
9+
selector: 'arc-gantt-zoombar',
10+
templateUrl: './gantt-zoombar.component.html',
11+
styleUrls: ['./gantt-zoombar.component.scss'],
12+
})
13+
export class GanttZoomBarComponent<T extends AnyObject> {
14+
translate: TranslateService;
15+
constructor(
16+
private ganttService: GanttService<T>,
17+
private readonly translationService: TranslationService,
18+
) {
19+
this.translate = this.translationService.translate;
20+
console.log(TimelineArray);
21+
}
22+
23+
zoomIn() {
24+
this.ganttService.zoomIn();
25+
}
26+
27+
zoomOut() {
28+
this.ganttService.zoomOut();
29+
}
30+
31+
fitToScreen() {
32+
this.ganttService.fitToScreen();
33+
}
34+
}

projects/arc-lib/src/lib/components/gantt/enum.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
export enum GanttEventTypes {
1+
export enum GanttEventValues {
22
Kebab = 'kebab',
33
Expand = 'expand',
44
Name = 'name',
55
Sort = 'sort',
6+
SubAllocation = 'sub-allocation',
67
Bar = 'bar',
78
Tooltip = 'tooltip',
89
Unknown = 'unknown',
10+
OpenedTooltip = 'opened-tooltip',
11+
ExpandBar = 'expand-bar',
912
}
1013

1114
export enum GanttScaleUnits {
@@ -15,3 +18,8 @@ export enum GanttScaleUnits {
1518
Year = 'year',
1619
Quarter = 'quarter',
1720
}
21+
22+
export enum GanttEventTypes {
23+
Click = 'click',
24+
Hover = 'hover',
25+
}

projects/arc-lib/src/lib/components/gantt/gantt.module.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@ import {CommonModule} from '@angular/common';
22
import {NgModule} from '@angular/core';
33
import {ReactiveFormsModule} from '@angular/forms';
44
import {ThemeModule} from '@project-lib/theme/theme.module';
5-
import {GANTT, GANTT_SCALES} from './const';
5+
import {GANTT, GANTT_SCALES, GanttProviders} from './const';
66
import {MonthlyScaleService} from './services/timeline-scales/monthly-scale.service';
77
import {QuarterlyScaleService} from './services/timeline-scales/quarterly-scale.service';
88
import {WeeklyScaleService} from './services/timeline-scales/weekly-scale.service';
99
import {GanttRoutingModule} from './gantt-routing.module';
10-
import {GanttService} from './services';
1110
import {gantt} from 'dhtmlx-gantt';
12-
import {
13-
CustomGanttAdapter,
14-
GanttAdapter,
15-
GanttLib,
16-
GanttScaleService,
17-
} from './types';
11+
import {CustomGanttAdapter, GanttAdapter} from './types';
1812

1913
import {
2014
GanttBarsComponent,
@@ -23,23 +17,31 @@ import {
2317
GanttTooltipComponent,
2418
} from './components';
2519
import {NbInputModule} from '@nebular/theme/components/input/input.module';
20+
import {GanttZoomBarComponent} from './components/gantt-zoombar/gantt-zoombar.component';
21+
import {GanttScrollComponent} from './components/gantt-scroll/gantt-scroll.component';
22+
import {DateOperationService} from './services/date-operation.service';
2623

2724
@NgModule({
2825
declarations: [
2926
GanttBarsComponent,
3027
GanttColumnComponent,
3128
GanttHeaderComponent,
3229
GanttTooltipComponent,
30+
GanttZoomBarComponent,
31+
GanttScrollComponent,
3332
],
3433
imports: [CommonModule, ReactiveFormsModule, ThemeModule, GanttRoutingModule],
3534
exports: [
3635
GanttBarsComponent,
3736
GanttColumnComponent,
3837
GanttHeaderComponent,
3938
GanttTooltipComponent,
39+
GanttZoomBarComponent,
40+
GanttScrollComponent,
4041
],
4142
providers: [
42-
GanttService,
43+
GanttProviders,
44+
DateOperationService,
4345
{
4446
provide: GANTT,
4547
useValue: gantt,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {Injectable} from '@angular/core';
2+
import * as moment from 'moment';
3+
4+
@Injectable()
5+
export class DateOperationService {
6+
convertToMoment(date: moment.MomentInput) {
7+
return moment(date);
8+
}
9+
10+
getTotalMonths(startDate: moment.Moment, endDate: moment.Moment) {
11+
let months = 0;
12+
const date = startDate.clone().startOf('month');
13+
const end = endDate.clone().endOf('month');
14+
while (date < end) {
15+
months++;
16+
date.add(1, 'month');
17+
}
18+
return months;
19+
}
20+
21+
calculateWeeksBetweenDates(startDate: Date | string, endDate: Date | string) {
22+
const startMoment = moment(startDate);
23+
const endMoment = moment(endDate);
24+
const totalWeeks = endMoment.diff(startMoment, 'weeks') + 1;
25+
return totalWeeks;
26+
}
27+
28+
getNumberOfDaysBetweenDates(date1: Date, date2: Date): number {
29+
const momentDate1 = moment(date1);
30+
const momentDate2 = moment(date2);
31+
32+
const daysDifference = momentDate2.diff(momentDate1, 'days');
33+
34+
return daysDifference;
35+
}
36+
37+
getNumberOfMonthsBetweenDates(date1: Date, date2: Date): number {
38+
const momentDate1 = moment(date1);
39+
const momentDate2 = moment(date2);
40+
41+
const monthsDifference = momentDate2.diff(momentDate1, 'months') + 1;
42+
43+
return monthsDifference;
44+
}
45+
}

projects/arc-lib/src/lib/components/gantt/services/timeline-scales/monthly-scale.service.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import {Injectable} from '@angular/core';
22
import {GanttScaleUnits} from '../../enum';
33
import {GanttScaleService, Timelines} from '../../types';
4+
import {AnyObject} from '@project-lib/core/api';
5+
import {DIGITS} from '@project-lib/core/constants';
6+
import {GanttService} from '../gantt.service';
47

58
@Injectable()
69
export class MonthlyScaleService implements GanttScaleService {
@@ -21,4 +24,29 @@ export class MonthlyScaleService implements GanttScaleService {
2124
},
2225
];
2326
}
27+
28+
scroll(forward: boolean, ganttService: GanttService<AnyObject>): void {
29+
const currentScrollState: number = ganttService.gantt.getScrollState().x;
30+
const currentScrollDate: Date =
31+
ganttService.gantt.dateFromPos(currentScrollState);
32+
const newScrollDate: Date = ganttService.gantt.date.add(
33+
currentScrollDate,
34+
forward ? +DIGITS.ONE : -DIGITS.ONE,
35+
'month',
36+
);
37+
const newScrollState: number =
38+
ganttService.gantt.posFromDate(newScrollDate);
39+
ganttService.gantt.scrollTo(newScrollState, null);
40+
}
41+
moveToToday(ganttService: GanttService<AnyObject>): void {
42+
const dateToday: Date = new Date();
43+
const newScrollDate: Date = ganttService.gantt.date.add(
44+
dateToday,
45+
-DIGITS.ONE,
46+
'month',
47+
);
48+
const newScrollState: number =
49+
ganttService.gantt.posFromDate(newScrollDate);
50+
ganttService.gantt.scrollTo(newScrollState, null);
51+
}
2452
}

projects/arc-lib/src/lib/components/gantt/services/timeline-scales/quarterly-scale.service.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {Injectable} from '@angular/core';
22
import {MONTHS_IN_QUARTER} from '../../const';
33
import {GanttScaleUnits} from '../../enum';
44
import {GanttScaleService, Timelines} from '../../types';
5+
import {AnyObject} from '@project-lib/core/api';
6+
import {DIGITS} from '@project-lib/core/constants';
7+
import {GanttService} from '../gantt.service';
58

69
@Injectable()
710
export class QuarterlyScaleService implements GanttScaleService {
@@ -21,6 +24,30 @@ export class QuarterlyScaleService implements GanttScaleService {
2124
},
2225
];
2326
}
27+
scroll(forward: boolean, ganttService: GanttService<AnyObject>): void {
28+
const currentScrollState: number = ganttService.gantt.getScrollState().x;
29+
const currentScrollDate: Date =
30+
ganttService.gantt.dateFromPos(currentScrollState);
31+
const newScrollDate: Date = ganttService.gantt.date.add(
32+
currentScrollDate,
33+
forward ? +DIGITS.FOUR : -DIGITS.FOUR,
34+
'month',
35+
);
36+
const newScrollState: number =
37+
ganttService.gantt.posFromDate(newScrollDate);
38+
ganttService.gantt.scrollTo(newScrollState, null);
39+
}
40+
moveToToday(ganttService: GanttService<AnyObject>): void {
41+
const dateToday: Date = new Date();
42+
const newScrollDate: Date = ganttService.gantt.date.add(
43+
dateToday,
44+
-DIGITS.FOUR,
45+
'month',
46+
);
47+
const newScrollState: number =
48+
ganttService.gantt.posFromDate(newScrollDate);
49+
ganttService.gantt.scrollTo(newScrollState, null);
50+
}
2451

2552
private _formatQuarterScale(date: Date) {
2653
const month = date.getMonth();

0 commit comments

Comments
 (0)