Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1496 from DashboardHub/issue-1493
Browse files Browse the repository at this point in the history
fix(projects): #1493 removed alert column from project list component
  • Loading branch information
eddiejaoude committed Sep 12, 2019
2 parents bc13a5e + ba98e83 commit d1ce327
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
10 changes: 9 additions & 1 deletion functions/src/mappers/github/repository.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export interface GitHubRepositoryInput {
url: string;
private: boolean;
fork: boolean;
forks_count: number;
stargazers_count: number;
watchers_count: number;
}

export interface GitHubRepositoryModel {
Expand All @@ -36,14 +39,19 @@ export interface GitHubRepositoryModel {
milestones?: GitHubMilestoneModel[];
updatedAt: firestore.Timestamp;
webhook?: GitHubRepositoryWebhookModel;
forksCount: number;
stargazersCount: number;
watchersCount: number;
}

export class GitHubRepositoryMapper {
static import(input: GitHubRepositoryInput, type: 'minimum' | 'all' | 'event' = 'minimum'): GitHubRepositoryModel {
const output: any = {};

if (type === 'all') {
output.fork = input.fork;
output.forksCount = input.forks_count;
output.stargazersCount = input.stargazers_count;
output.watchersCount = input.watchers_count;
}

if (type === 'event' || type === 'all') {
Expand Down
32 changes: 27 additions & 5 deletions web/src/app/core/services/repository.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ export class RepositoryService {
}

public getRating(repo: RepositoryModel): number {
let rating: number = 0;
const issuePoints: number = repo.issues.length > 0 ? this.getPoints(repo.issues[0].createdOn.toDate()) : 0;
const releasesPoints: number = repo.releases.length > 0 ? this.getPoints(repo.releases[0].createdOn.toDate()) : 0;
rating = (issuePoints + releasesPoints) / 2;
const checks: number[] = [];

return rating;
checks.push(repo.issues.length > 0 ? this.getPoints(repo.issues[0].createdOn.toDate()) : 0);
checks.push(repo.releases.length > 0 ? this.getPoints(repo.releases[0].createdOn.toDate()) : 0);
checks.push(repo.milestones.length > 0 ? this.getPoints(new Date(repo.milestones[0].updatedAt)) : 0);
checks.push(repo.url ? 100 : 0);
checks.push(repo.description ? 100 : 0);
checks.push(repo.forksCount ? this.getPointsByCount(repo.forksCount, 50) : 0);
checks.push(repo.stargazersCount ? this.getPointsByCount(repo.stargazersCount, 100) : 0);
checks.push(repo.watchersCount ? this.getPointsByCount(repo.watchersCount, 25) : 0);

return checks.reduce((total: number, current: number) => total + current, 0) / checks.length;
}

public getPoints(date: Date): number {
Expand All @@ -76,4 +82,20 @@ export class RepositoryService {

return ((boundary - duration) / 30) * 100; // percentage
}

public getPointsByCount(count: number, limit: number): number {
let points: number;
switch (true) {
case (count >= 1 && count <= limit):
points = 50;
break;
case (count > limit):
points = 100;
break;
default:
points = 0;
}

return points;
}
}
2 changes: 1 addition & 1 deletion web/src/app/projects/repository/repository.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ <h3 fxLayout fxLayoutAlign="start center" class="info__header__orange">
</ng-template>
<ng-template #emptyData>no data</ng-template>
<ng-template #refresh>
<button mat-button type="submit" class="repository__header__contributors__refresh" (click)="reloadRepository(repository.fullName, $event)" [disabled]="manualReload">
<button mat-button type="submit" class="repository__header__contributors__refresh" (click)="reloadRepository(repository, $event)" [disabled]="manualReload">
<span fxLayout="row" fxLayoutAlign="center center">
<mat-icon svgIcon="refresh_icon"></mat-icon>
<span fxHide.lt-lg fxFlexOffset="10px">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
<mat-icon svgIcon="{{ checkTypeOfProject(element) }}"></mat-icon>
</td>
</ng-container>
<ng-container matColumnDef="alert">
<th mat-header-cell *matHeaderCellDef>Alert</th>
<td mat-cell *matCellDef="let element">{{ element.repositories.length }}</td>
</ng-container>
<ng-container matColumnDef="title">
<th mat-header-cell *matHeaderCellDef>Title</th>
<td mat-cell *matCellDef="let element">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ export class ProjectsListComponent implements OnChanges {
.subscribe((state: BreakpointState) => {
if (state.matches) {
this.isSmallScreen = false;
this.displayedColumns = ['type', 'alert', 'title', 'url', 'repository', 'monitors', 'pings', 'user', 'lastDate'];
this.displayedColumns = ['type', 'title', 'url', 'repository', 'monitors', 'pings', 'user', 'lastDate'];
} else {
this.isSmallScreen = false;
this.displayedColumns = ['type', 'alert', 'title', 'description', 'url', 'repository', 'monitors', 'pings', 'user', 'lastDate'];
this.displayedColumns = ['type', 'title', 'description', 'url', 'repository', 'monitors', 'pings', 'user', 'lastDate'];
}
});
this.breakpointObserver
.observe([Breakpoints.Small])
.subscribe((state: BreakpointState) => {
if (state.matches) {
this.displayedColumns = ['type', 'alert', 'title', 'url', 'repository', 'monitors', 'pings'];
this.displayedColumns = ['type', 'title', 'url', 'repository', 'monitors', 'pings'];
this.isSmallScreen = false;
}
});
Expand Down
4 changes: 4 additions & 0 deletions web/src/app/shared/models/repository.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class RepositoryModel {
contributors: ContributorModel[];
milestones: MilestoneModel[];
webhook: WebhookModel;
url?: string;
forksCount: number;
stargazersCount: number;
watchersCount: number;

constructor(uid?: string) {
this.uid = uid;
Expand Down

0 comments on commit d1ce327

Please sign in to comment.