Permalink
Browse files

feat(favicon): change favicon on build status

  • Loading branch information...
jkuri committed Aug 20, 2017
1 parent d411e4c commit 3dbf64889f2ad91b2b2542ae33aa866cdb08afb2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,6 @@
import { Component, OnInit, NgZone } from '@angular/core';
import { Component, OnInit, NgZone, Inject, OnDestroy } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';
import { ApiService } from '../../services/api.service';
import { SocketService } from '../../services/socket.service';
@@ -8,7 +10,7 @@ import { distanceInWordsToNow, distanceInWordsStrict, format } from 'date-fns';
selector: 'app-build-details',
templateUrl: 'app-build-details.component.html'
})
export class AppBuildDetailsComponent implements OnInit {
export class AppBuildDetailsComponent implements OnInit, OnDestroy {
loading: boolean;
id: string;
build: any;
@@ -25,7 +27,9 @@ export class AppBuildDetailsComponent implements OnInit {
private apiService: ApiService,
private route: ActivatedRoute,
private ngZone: NgZone,
private router: Router
private router: Router,
@Inject(DOCUMENT) private document: any,
private titleService: Title
) {
this.loading = true;
this.status = 'queued';
@@ -86,6 +90,11 @@ export class AppBuildDetailsComponent implements OnInit {
});
}

ngOnDestroy() {
this.document.getElementById('favicon').setAttribute('href', 'images/favicon.png');
this.titleService.setTitle('Abstruse CI');
}

updateJobTimes(): void {
let currentTime = new Date().getTime() - this.socketService.timeSyncDiff;
this.build.jobs = this.build.jobs.map(job => {
@@ -116,19 +125,27 @@ export class AppBuildDetailsComponent implements OnInit {

getBuildStatus(): string {
let status = 'queued';
let favicon = 'images/favicon-queued.png';

if (this.build.jobs.findIndex(job => job.status === 'failed') !== -1) {
status = 'failed';
favicon = 'images/favicon-error.png';
}

if (this.build.jobs.findIndex(job => job.status === 'running') !== -1) {
status = 'running';
favicon = 'images/favicon-running.png';
}

if (this.build.jobs.length === this.build.jobs.filter(job => job.status === 'success').length) {
status = 'success';
favicon = 'images/favicon.png';
}

this.document.getElementById('favicon').setAttribute('href', favicon);
const titleStatus = status.charAt(0).toUpperCase() + status.slice(1);
this.titleService.setTitle(`Abstruse CI - Build ${titleStatus}`);

return status;
}

@@ -15,7 +15,7 @@ export class AppBuildItemComponent implements OnInit {
constructor(private socketService: SocketService) { }

ngOnInit() {
if (this.build.data.ref && this.build.data.ref.startsWith('refs/tags/')) {
if (this.build.data && this.build.data.ref && this.build.data.ref.startsWith('refs/tags/')) {
this.tag = this.build.data.ref.replace('refs/tags/', '');
}

@@ -44,7 +44,10 @@ export class AppBuildsComponent implements OnInit, OnDestroy {
});

this.socketService.outputEvents
.filter(x => x.data.toString().startsWith('job'))
.filter(x => {
x = x.data.toString() || '';
return x.startsWith('job');
})
.subscribe(e => {
const build = this.builds.findIndex(build => build.id === e.build_id);
const index = this.builds[build].jobs.findIndex(job => job.id === e.job_id);
@@ -1,4 +1,6 @@
import { Component, OnInit, OnDestroy, NgZone } from '@angular/core';
import { Component, OnInit, OnDestroy, NgZone, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute } from '@angular/router';
import { ApiService } from '../../services/api.service';
import { SocketService } from '../../services/socket.service';
@@ -20,7 +22,6 @@ export class AppJobComponent implements OnInit, OnDestroy {
id: number;
job: any;
jobRun: any;
status: string;
terminalReady: boolean;
terminalOptions: { size: 'small' | 'large' };
terminalInput: any;
@@ -36,10 +37,11 @@ export class AppJobComponent implements OnInit, OnDestroy {
private socketService: SocketService,
private apiService: ApiService,
private route: ActivatedRoute,
private ngZone: NgZone
private ngZone: NgZone,
@Inject(DOCUMENT) private document: any,
private titleService: Title
) {
this.loading = true;
this.status = 'queued';
this.terminalOptions = { size: 'large' };
this.id = null;
this.expectedProgress = 0;
@@ -83,6 +85,8 @@ export class AppJobComponent implements OnInit, OnDestroy {
this.jobRun.status = 'failed';
this.jobRun.end_time = new Date().getTime();
}

this.setFavicon();
});

this.route.params.subscribe(params => {
@@ -91,13 +95,14 @@ export class AppJobComponent implements OnInit, OnDestroy {
this.apiService.getJob(this.id).subscribe(job => {
this.job = job;

if (this.job.build.data.ref.startsWith('refs/tags/')) {
if (this.job.build.data.ref && this.job.build.data.ref.startsWith('refs/tags/')) {
this.tag = this.job.build.data.ref.replace('refs/tags/', '');
}

this.jobRun = job.runs[job.runs.length - 1];
this.terminalInput = this.jobRun.log;
this.timeWords = distanceInWordsToNow(job.build.start_time);
this.setFavicon();
this.loading = false;
if (this.job.lastJob && this.job.lastJob.end_time) {
this.previousRuntime = this.job.lastJob.end_time - this.job.lastJob.start_time;
@@ -114,6 +119,8 @@ export class AppJobComponent implements OnInit, OnDestroy {
ngOnDestroy() {
this.termSub.unsubscribe();
this.sub.unsubscribe();
this.document.getElementById('favicon').setAttribute('href', 'images/favicon.png');
this.titleService.setTitle('Abstruse CI');
}

updateJobTime(): void {
@@ -128,6 +135,21 @@ export class AppJobComponent implements OnInit, OnDestroy {
}
}

setFavicon(): void {
let favicon;
switch (this.jobRun.status) {
case 'queued': favicon = 'images/favicon-queued.png'; break;
case 'failed': favicon = 'images/favicon-error.png'; break;
case 'running': favicon = 'images/favicon-running.png'; break;
case 'success': favicon = 'images/favicon.png'; break;
default: favicon = 'images/favicon.png'; break;
}

const status = this.jobRun.status.charAt(0).toUpperCase() + this.jobRun.status.slice(1);
this.titleService.setTitle(`Abstruse CI - Job ${status}`);
this.document.getElementById('favicon').setAttribute('href', favicon);
}

restartJob(e: MouseEvent): void {
e.preventDefault();
e.stopPropagation();
@@ -5,7 +5,7 @@
<title>Abstruse CI</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="images/favicon.ico">
<link id="favicon" rel="icon" type="image/x-icon" href="images/favicon.png">
</head>
<body>
<app-root></app-root>

0 comments on commit 3dbf648

Please sign in to comment.