107 lines
3.3 KiB
TypeScript
107 lines
3.3 KiB
TypeScript
|
|
import { Component, OnInit } from '@angular/core';
|
||
|
|
import { Title } from '@angular/platform-browser';
|
||
|
|
import { ActivatedRoute } from '@angular/router';
|
||
|
|
|
||
|
|
import { CommitTrackerService } from '../../shared/service/commit-tracker.service';
|
||
|
|
import { Commit } from '../../shared/commit';
|
||
|
|
import { CommitStatus } from '../../shared/commit-status.enum';
|
||
|
|
import { Result } from '../../shared/result.enum';
|
||
|
|
|
||
|
|
@Component({
|
||
|
|
selector: 'app-commit-tracker',
|
||
|
|
templateUrl: './commit-tracker.component.html',
|
||
|
|
styleUrls: ['./commit-tracker.component.css']
|
||
|
|
})
|
||
|
|
export class CommitTrackerComponent implements OnInit {
|
||
|
|
|
||
|
|
public CommitStatus = CommitStatus;
|
||
|
|
|
||
|
|
constructor(private commitTrackerService: CommitTrackerService,
|
||
|
|
private titleService: Title,
|
||
|
|
private route: ActivatedRoute) {}
|
||
|
|
|
||
|
|
ngOnInit() {
|
||
|
|
this.titleService.setTitle('Commit-tracker : MTAStv');
|
||
|
|
this.route.data.subscribe((data: {commits: Array<Commit>}) => this.commits = data.commits);
|
||
|
|
}
|
||
|
|
|
||
|
|
get commits(): Array<Commit> {
|
||
|
|
return this.commitTrackerService.commits;
|
||
|
|
}
|
||
|
|
|
||
|
|
set commits(commits: Array<Commit>) {
|
||
|
|
this.commitTrackerService.commits = commits;
|
||
|
|
}
|
||
|
|
|
||
|
|
public labelClasses(commit: Commit, commitStatus: String) {
|
||
|
|
const classes: Object = {
|
||
|
|
ui: true,
|
||
|
|
big: true,
|
||
|
|
circular: true,
|
||
|
|
label: true,
|
||
|
|
};
|
||
|
|
|
||
|
|
switch (commitStatus) {
|
||
|
|
case CommitStatus.Verified:
|
||
|
|
return Object.assign(classes, {
|
||
|
|
green: commit.gerrit_verified === 2,
|
||
|
|
yellow: commit.gerrit_verified === 0,
|
||
|
|
red: commit.gerrit_verified === -2,
|
||
|
|
});
|
||
|
|
case CommitStatus.CodeReview:
|
||
|
|
return Object.assign(classes, {
|
||
|
|
green: commit.gerrit_code_review === 1,
|
||
|
|
yellow: commit.gerrit_code_review === 0,
|
||
|
|
red: commit.gerrit_code_review === -1,
|
||
|
|
});
|
||
|
|
case CommitStatus.CommitFeedbackLoop:
|
||
|
|
return Object.assign(classes, {
|
||
|
|
green: commit.cfl_result === Result.Success,
|
||
|
|
yellow: commit.cfl_result === Result.Aborted,
|
||
|
|
orange: commit.cfl_result === Result.Unstable,
|
||
|
|
red: commit.cfl_result === Result.Failure,
|
||
|
|
brown: commit.cfl_result === Result.NotBuilt,
|
||
|
|
});
|
||
|
|
case CommitStatus.ShortFeedbackLoop:
|
||
|
|
return Object.assign(classes, {
|
||
|
|
green: commit.sfl_result === Result.Success,
|
||
|
|
yellow: commit.sfl_result === Result.Aborted,
|
||
|
|
orange: commit.sfl_result === Result.Unstable,
|
||
|
|
red: commit.sfl_result === Result.Failure,
|
||
|
|
brown: commit.sfl_result === Result.NotBuilt,
|
||
|
|
});
|
||
|
|
case CommitStatus.NightlyFeedbackLoop:
|
||
|
|
return Object.assign(classes, {
|
||
|
|
green: commit.nfl_result === Result.Success,
|
||
|
|
yellow: commit.nfl_result === Result.Aborted,
|
||
|
|
red: commit.nfl_result === Result.Failure,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
return classes;
|
||
|
|
}
|
||
|
|
|
||
|
|
public rowClasses(commit: Commit) {
|
||
|
|
return {
|
||
|
|
positive: this.isAllOk(commit),
|
||
|
|
negative: this.hasAnyFailure(commit)
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
private isAllOk(commit: Commit) {
|
||
|
|
return [
|
||
|
|
commit.cfl_result,
|
||
|
|
commit.sfl_result,
|
||
|
|
commit.nfl_result,
|
||
|
|
].every(result => result === Result.Success);
|
||
|
|
}
|
||
|
|
|
||
|
|
private hasAnyFailure(commit: Commit) {
|
||
|
|
return [
|
||
|
|
commit.cfl_result,
|
||
|
|
commit.sfl_result,
|
||
|
|
commit.nfl_result,
|
||
|
|
].some(result => result === Result.Failure);
|
||
|
|
}
|
||
|
|
}
|