Skip to content

Commit

Permalink
fix(pmp-web): display proper maxWaitingTime
Browse files Browse the repository at this point in the history
Add time ago and resolve hours pipes.
Hide Constraints tab.
Hide Login by gitlab.
  • Loading branch information
Sikora00 authored and MaciejSikorski committed Apr 24, 2020
1 parent 6f78d19 commit 7dea623
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export class LoginPageComponent {
imageSrc: 'assets/images/bitbucket_logo.png',
name: Platform.bitbucket,
color: '#0052CC'
},
{
imageSrc: 'assets/images/gitlab_logo.png',
name: Platform.gitlab,
color: '#FC6D27'
}
// {
// imageSrc: 'assets/images/gitlab_logo.png',
// name: Platform.gitlab,
// color: '#FC6D27'
// }
];

login(system: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ <h1 class="page__title">Repository settings</h1>
</pimp-my-pr-repositories-settings-table>
</ng-template>
</mat-tab>
<mat-tab label="Constraints">
<ng-template matTabContent>
<h4>Some tab content</h4>
</ng-template>
</mat-tab>
<!-- <mat-tab label="Constraints">-->
<!-- <ng-template matTabContent>-->
<!-- <h4>Some tab content</h4>-->
<!-- </ng-template>-->
<!-- </mat-tab>-->
</mat-tab-group>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<span>{{ 'Sum of time PR waiting' }}</span>
</mat-header-cell>
<mat-cell *matCellDef="let element">
{{ element.sumOfHoursPrsWaiting | resolveHours }}
{{ element.sumOfHoursPrsWaiting | timeAgo }}
</mat-cell>
</ng-container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
>Time waiting</mat-header-cell
>
<mat-cell *matCellDef="let element" class="waiting-time-column">
{{ element.timeWaiting | resolveHours }}
{{ element.timeWaiting | timeAgo }}
</mat-cell>
</ng-container>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ResolveHoursPipe } from './resolve-hourse.pipe';
import { TimeUnit } from '@pimp-my-pr/shared/domain';

describe('ResolveHours', () => {
let pipe: ResolveHoursPipe;

beforeEach(() => {
pipe = new ResolveHoursPipe();
});
it('should handle 0', () => {
expect(pipe.transform(0)).toBe(`-`);
});
it('should handle null', () => {
expect(pipe.transform(null)).toBe(`-`);
});
it('should handle singular', () => {
expect(pipe.transform(1)).toBe(`1 hour`);
});
it('should handle plural', () => {
expect(pipe.transform(2)).toBe(`2 hours`);
});
it('handle days', () => {
expect(pipe.transform(48)).toBe(`2 days`);
});
it('should handle exactly values', () => {
expect(pipe.transform(49)).toBe(`49 hours`);
});
it('10 days', () => {
expect(pipe.transform(10 * +TimeUnit.Day)).toBe(`10 days`);
});
it('2 months', () => {
expect(pipe.transform(2 * +TimeUnit.Month)).toBe(`2 months`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Pipe, PipeTransform } from '@angular/core';
import { TimeUnit } from '@pimp-my-pr/shared/domain';

@Pipe({
name: 'resolveHours'
})
export class ResolveHoursPipe implements PipeTransform {
transform(value: number): string {
const timeValues: { hrsInThatPeriod: number; name: string }[] = [
{ hrsInThatPeriod: +TimeUnit.Year, name: 'year' },
{ hrsInThatPeriod: +TimeUnit.Month, name: 'month' },
{ hrsInThatPeriod: +TimeUnit.Week, name: 'week' },
{ hrsInThatPeriod: +TimeUnit.Day, name: 'day' },
{ hrsInThatPeriod: +TimeUnit.Hour, name: 'hour' }
];

if (!value) {
return '-';
}
let timeLabel: string,
incr = 0;

while (!timeLabel) {
if (!timeValues[incr]) break;

if (value % timeValues[incr].hrsInThatPeriod === 0) {
const valueInTheUnit = value / timeValues[incr].hrsInThatPeriod;
if (valueInTheUnit > 1) {
timeLabel = `${valueInTheUnit} ${timeValues[incr].name}s`;
} else {
timeLabel = `${valueInTheUnit} ${timeValues[incr].name}`;
}
break;
}

incr++;
}

return timeLabel;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ResolveHoursPipe } from './resolve-hours.pipe';
import { TimeAgoPipe } from './time-ago.pipe';

describe('ResolveHoursPipe', () => {
let pipe: ResolveHoursPipe;
describe('TimeAgoPipe', () => {
let pipe: TimeAgoPipe;

beforeEach(() => {
pipe = new ResolveHoursPipe();
pipe = new TimeAgoPipe();
});
it('expect(pipe.transform(0))', () => {
expect(pipe.transform(0)).toBe(`less than an hour`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Pipe, PipeTransform } from '@angular/core';
import { TimeUnit } from '@pimp-my-pr/shared/domain';

@Pipe({
name: 'resolveHours'
name: 'timeAgo'
})
export class ResolveHoursPipe implements PipeTransform {
export class TimeAgoPipe implements PipeTransform {
transform(value: number): string {
const timeValues: { hrsInThatPeriod: number; name: string }[] = [
{ hrsInThatPeriod: 8760, name: 'year' },
{ hrsInThatPeriod: 730, name: 'month' },
{ hrsInThatPeriod: 168, name: 'week' },
{ hrsInThatPeriod: 24, name: 'day' },
{ hrsInThatPeriod: 1, name: 'hour' }
{ hrsInThatPeriod: +TimeUnit.Year, name: 'year' },
{ hrsInThatPeriod: +TimeUnit.Month, name: 'month' },
{ hrsInThatPeriod: +TimeUnit.Week, name: 'week' },
{ hrsInThatPeriod: +TimeUnit.Day, name: 'day' },
{ hrsInThatPeriod: +TimeUnit.Hour, name: 'hour' }
];

let timeLabel: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ResolveHoursPipe } from './pipes/resolve-hours.pipe';
import { TimeAgoPipe } from './pipes/time-ago/time-ago.pipe';
import { ResolveHoursPipe } from './pipes/resolve-hours/resolve-hourse.pipe';

@NgModule({
imports: [CommonModule],
declarations: [ResolveHoursPipe],
exports: [ResolveHoursPipe]
declarations: [TimeAgoPipe, ResolveHoursPipe],
exports: [TimeAgoPipe, ResolveHoursPipe]
})
export class PmpWebSharedUtilModule {}
4 changes: 3 additions & 1 deletion libs/shared/domain/src/lib/enums/time-unit.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
export enum TimeUnit {
Hour = '1',
Day = '24',
Week = '168'
Week = '168',
Month = '720',
Year = '8760'
}

0 comments on commit 7dea623

Please sign in to comment.