Skip to content

Commit 3023169

Browse files
committed
Merge branch 'master' of https://github.com/ioet/time-tracker-ui into TT-294-Fex-calendar-text-overflow
2 parents 7fe4b9d + 83e50c8 commit 3023169

File tree

6 files changed

+111
-55
lines changed

6 files changed

+111
-55
lines changed

package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "time-tracker",
3-
"version": "1.46.1",
3+
"version": "1.47.0",
44
"scripts": {
55
"preinstall": "npx npm-force-resolutions",
66
"ng": "ng",
@@ -106,8 +106,8 @@
106106
},
107107
"config": {
108108
"commit-message-validator": {
109-
"pattern": "^(fix: TT-|feat: TT-|perf: TT-|build: TT-|ci: TT-|docs: TT-|refactor: TT-|style: TT-|test: TT-)[0-9].*",
110-
"errorMessage": "Your commit message needs to start with fix: , feat:, or perf: followed by any commit message, e.g. fix: TT-43 any commit message"
109+
"pattern": "^(fix: TT-|feat: TT-|perf: TT-|build: TT-|ci: TT-|docs: TT-|refactor: TT-|style: TT-|test: TT-|code-smell: TT-)[0-9].*",
110+
"errorMessage": "Your commit message needs to start with fix: , feat:, or perf: followed by any commit message, e.g. fix: TT-43 any commit message."
111111
}
112112
},
113113
"resolutions": {

src/app/modules/time-entries/components/calendar/calendar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
</div>
140140
</div>
141141

142-
<div [ngSwitch]="calendarView">
142+
<div class="switch-calendar-view" [ngSwitch]="calendarView" #scrollContainer>
143143
<mwl-calendar-month-view
144144
*ngSwitchCase="CALENDAR_VIEW_ENUM.Month"
145145
[viewDate]="currentDate"

src/app/modules/time-entries/components/calendar/calendar.component.scss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@ $activity-text-size: $max-lines-activity * $line-height-base;
2121
@return darken(saturate(adjust-hue($text-color, 6), 46.19), 40.98);
2222
}
2323

24+
.switch-calendar-view {
25+
height: calc(100vh - 320px);
26+
overflow-y: auto;
27+
}
28+
29+
::-webkit-scrollbar {
30+
width: 5px;
31+
}
32+
33+
::-webkit-scrollbar-track {
34+
background: #f1f1f1;
35+
border-radius: 5px;
36+
}
37+
38+
::-webkit-scrollbar-thumb {
39+
background: transparent;
40+
}
41+
42+
::-webkit-scrollbar-thumb:hover {
43+
background: #888;
44+
border-radius: 5px;
45+
}
46+
2447
@for $card-height from 12 through $max-lines-description {
2548
$wrap-height: ($card-height * 0.625rem) -
2649
$project-text-size -

src/app/modules/time-entries/components/calendar/calendar.component.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ describe('CalendarComponent', () => {
221221
expect(component.calendarView).toEqual(fakeCalendarView);
222222
});
223223

224+
it('set srcoll to current time marker in calendarView when is call scrollToCurrentTimeMarker', () => {
225+
const fakeCalendarView: CalendarView = CalendarView.Week;
226+
spyOn(component, 'scrollToCurrentTimeMarker');
227+
component.changeCalendarView(fakeCalendarView);
228+
expect(component.scrollToCurrentTimeMarker).toHaveBeenCalled();
229+
});
230+
224231
it('set false in nextDateDisabled when call navigationEnable and calendarView != Month and currentDate + 1 day is not greater to initialDate', () => {
225232
component.currentDate = moment().subtract(2, 'day').toDate();
226233
component.initialDate = moment().toDate();

src/app/modules/time-entries/components/calendar/calendar.component.ts

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
1-
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
21
import {
3-
CalendarEvent,
4-
CalendarView,
5-
} from 'angular-calendar';
2+
ChangeDetectorRef,
3+
Component,
4+
ElementRef,
5+
EventEmitter,
6+
Input,
7+
OnInit,
8+
Output,
9+
ViewChild,
10+
} from '@angular/core';
11+
import { CalendarEvent, CalendarView } from 'angular-calendar';
612
import { Observable } from 'rxjs';
713
import * as moment from 'moment';
814
import { DataSource } from '../../../shared/models/data-source.model';
915
import { Entry } from 'src/app/modules/shared/models';
1016
import { map } from 'rxjs/operators';
1117
import { SubstractDatePipe } from 'src/app/modules/shared/pipes/substract-date/substract-date.pipe';
18+
import { differenceInMinutes, startOfDay, startOfHour } from 'date-fns';
1219

1320
@Component({
1421
selector: 'app-calendar',
1522
templateUrl: './calendar.component.html',
1623
styleUrls: ['./calendar.component.scss'],
1724
})
1825
export class CalendarComponent implements OnInit {
19-
readonly HALF_HOUR: number = 30;
26+
readonly DEFAULT_HEADER_HEIGHT = 52;
2027
readonly VARIATION_HEIGHT: number = 2;
2128
readonly VISIBLE_TARGETS_FOR_TIME_ENTRIES_DESCRIPTION: CalendarView[] = [CalendarView.Week, CalendarView.Day];
2229
readonly CALENDAR_VIEW_ENUM: typeof CalendarView = CalendarView;
2330

24-
@Input() set timeEntries$(timeEntries: Observable<DataSource<Entry>>){
31+
@ViewChild('scrollContainer') scrollContainer: ElementRef<HTMLElement>;
32+
33+
@Input() set timeEntries$(timeEntries: Observable<DataSource<Entry>>) {
2534
this.castEntryToCalendarEvent(timeEntries);
2635
}
2736
@Input() calendarView: CalendarView = CalendarView.Month;
@@ -30,7 +39,7 @@ export class CalendarComponent implements OnInit {
3039
@Output() viewModal: EventEmitter<any> = new EventEmitter<string>();
3140
@Output() deleteTimeEntry: EventEmitter<any> = new EventEmitter<string>();
3241
@Output() changeDate: EventEmitter<any> = new EventEmitter<{
33-
date: Date
42+
date: Date;
3443
}>();
3544

3645
initialDate: Date;
@@ -39,83 +48,100 @@ export class CalendarComponent implements OnInit {
3948
timeEntriesAsEvent: CalendarEvent[];
4049
nextDateDisabled: boolean;
4150

42-
constructor() {
51+
constructor(private referenceChangeDetector: ChangeDetectorRef) {
4352
this.initialDate = new Date();
4453
this.previusDate = new Date();
4554
this.isToday = false;
4655
this.timeEntriesAsEvent = [];
4756
this.nextDateDisabled = true;
48-
}
57+
}
4958

5059
ngOnInit(): void {
5160
this.isToday = this.isVisibleForCurrentDate();
5261
this.navigationEnable(this.calendarView);
5362
}
5463

64+
scrollToCurrentTimeMarker() {
65+
if (this.calendarView === CalendarView.Week || CalendarView.Day) {
66+
const minutesSinceStartOfDay = differenceInMinutes(startOfHour(this.currentDate), startOfDay(this.currentDate));
67+
const headerHeight = this.calendarView === CalendarView.Week ? this.DEFAULT_HEADER_HEIGHT : 0;
68+
this.scrollContainer.nativeElement.scrollTop = minutesSinceStartOfDay * this.VARIATION_HEIGHT + headerHeight;
69+
}
70+
}
71+
5572
castEntryToCalendarEvent(timeEntries$: Observable<DataSource<Entry>>) {
56-
timeEntries$.pipe(
57-
map((timeEntriesDatasorce) => timeEntriesDatasorce.data.map(
58-
(timeEntries) => ({
59-
start: new Date(timeEntries.start_date),
60-
end: timeEntries.end_date ? new Date(timeEntries.end_date) : null ,
61-
title: timeEntries.description,
62-
id: timeEntries.id,
63-
meta: timeEntries
64-
} as CalendarEvent)
73+
timeEntries$
74+
.pipe(
75+
map((timeEntriesDatasorce) =>
76+
timeEntriesDatasorce.data.map(
77+
(timeEntries) =>
78+
({
79+
start: new Date(timeEntries.start_date),
80+
end: timeEntries.end_date ? new Date(timeEntries.end_date) : null,
81+
title: timeEntries.description,
82+
id: timeEntries.id,
83+
meta: timeEntries,
84+
} as CalendarEvent)
85+
)
6586
)
6687
)
67-
)
68-
.subscribe((timeEntriesAsEvent) => {
88+
.subscribe((timeEntriesAsEvent) => {
6989
this.timeEntriesAsEvent = [...timeEntriesAsEvent].reverse();
70-
});
90+
});
7191
}
7292

7393
handleEditEvent(timeEntryAsEvent: CalendarEvent): void {
74-
this.viewModal.emit( {
75-
id: timeEntryAsEvent.id
94+
this.viewModal.emit({
95+
id: timeEntryAsEvent.id,
7696
});
7797
}
7898

7999
handleDeleteEvent(timeEntryAsEvent: CalendarEvent): void {
80100
this.deleteTimeEntry.emit({
81-
timeEntry: timeEntryAsEvent.meta
101+
timeEntry: timeEntryAsEvent.meta,
82102
});
83103
}
84104

85-
handleChangeDateEvent(): void{
105+
handleChangeDateEvent(): void {
86106
const date = this.currentDate;
87107
this.isToday = this.isVisibleForCurrentDate();
88108
this.navigationEnable(this.calendarView);
89-
this.changeDate.emit({date});
109+
this.changeDate.emit({ date });
90110
}
91111

92-
changeCalendarView(calendarView: CalendarView){
112+
changeCalendarView(calendarView: CalendarView) {
93113
this.calendarView = calendarView;
114+
this.scrollContainer.nativeElement.scrollTop = 0;
115+
if (this.calendarView !== CalendarView.Month) {
116+
this.referenceChangeDetector.detectChanges();
117+
this.scrollToCurrentTimeMarker();
118+
}
94119
}
95120

96-
navigationEnable(calendarView: CalendarView){
121+
navigationEnable(calendarView: CalendarView) {
97122
let enable = false;
98123
const currentDate = moment(this.currentDate);
99124
const initialDate = moment(this.initialDate);
100-
if (calendarView === CalendarView.Month){
125+
if (calendarView === CalendarView.Month) {
101126
if (currentDate.month() === initialDate.month() && currentDate.year() === initialDate.year()) {
102127
enable = true;
103128
}
104129
}
105130
currentDate.add(1, 'day');
106-
if (currentDate > initialDate){
131+
if (currentDate > initialDate) {
107132
enable = true;
108133
}
109134
this.nextDateDisabled = enable;
110135
}
111136

112-
getTimeWork(startDate: Date, endDate: Date): number{
113-
if (!endDate){
137+
getTimeWork(startDate: Date, endDate: Date): number {
138+
if (!endDate) {
114139
return 30;
115140
}
116-
return new SubstractDatePipe().transformInMinutes( endDate , startDate);
141+
return new SubstractDatePipe().transformInMinutes(endDate, startDate);
117142
}
118143

144+
timeIsGreaterThan(startDate: Date, endDate: Date, timeRange: number): boolean {
119145
getCardEntryHeight(startDate: Date, endDate: Date): number{
120146
const heightCard = this.getTimeWork(startDate, endDate) * this.VARIATION_HEIGHT;
121147
const finalHeightCard = heightCard / 10;
@@ -131,7 +157,7 @@ export class CalendarComponent implements OnInit {
131157
return desiredView.includes(currentCalendarView);
132158
}
133159

134-
isVisibleForCurrentDate(): boolean{
160+
isVisibleForCurrentDate(): boolean {
135161
const currentDate: Date = new Date(this.currentDate);
136162
const initialDate: Date = new Date(this.initialDate);
137163
return currentDate.setHours(0, 0, 0, 0) === initialDate.setHours(0, 0, 0, 0);

0 commit comments

Comments
 (0)