Skip to content

Commit d5c118d

Browse files
committed
chore: more timers
1 parent 129dfad commit d5c118d

File tree

5 files changed

+58
-18
lines changed

5 files changed

+58
-18
lines changed

public/src/app/contributions-tab/contributions-tab.component.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnChanges, OnInit } from '@angular/core';
1+
import { ChangeDetectorRef, Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
22
import { issueLabelScopes } from '../../../../shared/issue-labels';
33
import { getUserAvatarUrl, getTz } from '../../../../shared/users';
44
import { appState } from '../../state';
@@ -13,7 +13,7 @@ import { repoShortNameFromGithubUrl } from '../utility/repoShortNameFromGithubUr
1313
styleUrls: ['./contributions-tab.component.css'],
1414
standalone: false
1515
})
16-
export class ContributionsTabComponent implements OnInit, OnChanges {
16+
export class ContributionsTabComponent implements OnInit, OnChanges, OnDestroy {
1717

1818
@Input() user: any;
1919

@@ -24,8 +24,18 @@ export class ContributionsTabComponent implements OnInit, OnChanges {
2424
get sites() { return dataModel.sites }
2525
get userTz() { return getTz(this.user?.login); }
2626

27+
private timerId = null;
28+
private currentTime: Date = new Date();
29+
30+
constructor(private changeDetectorRef: ChangeDetectorRef) { }
31+
32+
refresh() {
33+
this.currentTime = new Date();
34+
this.changeDetectorRef.detectChanges();
35+
}
36+
2737
userDate() {
28-
return new Date().toLocaleString([], {
38+
return this.currentTime.toLocaleString([], {
2939
weekday: "short",
3040
hour: "2-digit",
3141
minute: "2-digit",
@@ -43,13 +53,16 @@ export class ContributionsTabComponent implements OnInit, OnChanges {
4353

4454
_issues = null;
4555

46-
constructor() { }
47-
4856
stringify(o: any) {
4957
return JSON.stringify(o);
5058
}
5159

5260
ngOnInit(): void {
61+
this.timerId = setInterval(() => this.refresh(), 1000);
62+
}
63+
64+
ngOnDestroy() {
65+
clearInterval(this.timerId);
5366
}
5467

5568
ngOnChanges() {

public/src/app/contributions/contributions.component.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121

2222
.availability-tablet {
23-
width: 24px;
2423
height: 18px;
2524
font-size: 12px;
25+
text-align: center;
2626
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<span *ngIf="shouldDisplay(user)" class="avatar-box {{user.login == activeTab ? 'selected' : ''}}" [style]="{background: userAvailability(user).color}"
1+
<span *ngIf="shouldDisplay(user)" class="avatar-box {{user.login == activeTab ? 'selected' : ''}}" [style]="{background: userAvailability(user).background, color: userAvailability(user).color}"
22
(click)="selectUser(user.login)" [title]="userDate(user)">
33
<img *ngIf="user.login == ''" class="avatar-40" src="assets/unassigned.png">
44
<img *ngIf="user.login != ''" class="avatar-40" src="{{getUserAvatar(user, 40)}}">
5-
<div class='availability-tablet'></div>
5+
<div class='availability-tablet'>{{userTime(user)}}</div>
66
</span>

public/src/app/contributions/contributions.component.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
1+
import { Component, Input, OnInit, Output, EventEmitter, ChangeDetectorRef, OnDestroy } from '@angular/core';
22
import { getUserAvatarUrl, getTz } from '../../../../shared/users';
33
import { appState } from '../../state';
44
import { dataModel } from '../data/data.model';
@@ -9,7 +9,7 @@ import { dataModel } from '../data/data.model';
99
styleUrls: ['./contributions.component.css'],
1010
standalone: false
1111
})
12-
export class ContributionsComponent implements OnInit {
12+
export class ContributionsComponent implements OnInit, OnDestroy {
1313

1414
// data proxies
1515
get status() { return dataModel.status }
@@ -27,7 +27,7 @@ export class ContributionsComponent implements OnInit {
2727
private timerId = null;
2828
private currentTime: Date = new Date();
2929

30-
constructor() { }
30+
constructor(private changeDetectorRef: ChangeDetectorRef) { }
3131

3232
stringify(o: any) {
3333
return JSON.stringify(o);
@@ -37,8 +37,13 @@ export class ContributionsComponent implements OnInit {
3737
this.timerId = setInterval(() => this.refresh(), 1000);
3838
}
3939

40+
ngOnDestroy() {
41+
clearInterval(this.timerId);
42+
}
43+
4044
private refresh() {
4145
this.currentTime = new Date();
46+
this.changeDetectorRef.detectChanges();
4247
}
4348

4449
shouldDisplay(user) {
@@ -59,6 +64,24 @@ export class ContributionsComponent implements OnInit {
5964
return getUserAvatarUrl(user, size);
6065
}
6166

67+
userTime(user) {
68+
if(user.login == '') {
69+
return ' ';
70+
}
71+
72+
const tz = getTz(user.login);
73+
if(!tz) {
74+
return ' ';
75+
}
76+
77+
return this.currentTime.toLocaleString([], {
78+
hour: "2-digit",
79+
minute: "2-digit",
80+
hour12: false,
81+
timeZone: tz,
82+
});
83+
}
84+
6285
userDate(user) {
6386
if(user.login == '') {
6487
return 'Unassigned issues';
@@ -84,22 +107,25 @@ export class ContributionsComponent implements OnInit {
84107
userAvailability(user) {
85108
const tz = getTz(user.login);
86109
if(!tz) {
87-
return {color: 'rgba(0,0,0,0)'}; //TODO
110+
return {background: 'rgba(0,0,0,0)', color: 'rgba(0,0,0,0)'}; //TODO
88111
}
89-
const now = new Date();
112+
const now = this.currentTime;
90113
const result = {
91114
weekDay: now.toLocaleString('en-GB', { weekday: 'short', timeZone: tz }),
92115
time: now.toLocaleString('en-GB', { hour: "2-digit", minute: "2-digit", hour12: false, timeZone: tz }),
93116
hour: 0,
94-
color: 'green'
117+
background: 'green',
118+
color: 'white',
95119
};
96120

97121
result.hour = parseInt(result.time, 10);
98122

99123
if(result.weekDay == 'Sat' || result.weekDay == 'Sun' || result.hour < 6 || result.hour > 21) {
100-
result.color = 'red';
124+
result.background = 'red';
125+
// result.color = 'black';
101126
} else if(result.hour < 8 || result.hour > 17) {
102-
result.color = 'orange';
127+
result.background = 'orange';
128+
result.color = 'black';
103129
}
104130
return result;
105131
}

public/src/app/service-state-popup/service-state-popup.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Keyman is copyright (C) SIL Global. MIT License.
33
*/
4-
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
4+
import { ChangeDetectorRef, Component, Input, OnDestroy, OnInit } from '@angular/core';
55
import { PopupComponent } from '../popup/popup.component';
66
import { PopupCoordinatorService } from '../popup-coordinator.service';
77
import { VisibilityService } from '../visibility/visibility.service';
@@ -19,7 +19,7 @@ export class ServiceStatePopupComponent extends PopupComponent implements OnInit
1919
private timerId = null;
2020
private currentTime: number = new Date().valueOf();
2121

22-
constructor(popupCoordinator: PopupCoordinatorService, visibilityService: VisibilityService) {
22+
constructor(popupCoordinator: PopupCoordinatorService, visibilityService: VisibilityService, private changeDetectorRef: ChangeDetectorRef) {
2323
super(popupCoordinator, visibilityService);
2424
}
2525

@@ -52,6 +52,7 @@ export class ServiceStatePopupComponent extends PopupComponent implements OnInit
5252

5353
refresh() {
5454
this.currentTime = new Date().valueOf();
55+
this.changeDetectorRef.detectChanges();
5556
}
5657

5758
lastChange(service: ServiceStateRecord): string {

0 commit comments

Comments
 (0)