From 892dc908ac0283f2705a81e03423a5af0a93a469 Mon Sep 17 00:00:00 2001 From: Jan Kuri Date: Fri, 18 Aug 2017 20:22:13 +0200 Subject: [PATCH] fix(hotfix): fix build item functionality --- .../app-build-item.component.html | 4 +-- .../app-build-item.component.ts | 27 ++++++++++++++++++- .../app-builds/app-builds.component.ts | 22 --------------- .../app-repository.component.ts | 21 --------------- 4 files changed, 28 insertions(+), 46 deletions(-) diff --git a/src/app/components/app-build-item/app-build-item.component.html b/src/app/components/app-build-item/app-build-item.component.html index 1fb68ec23..8de3dd80e 100644 --- a/src/app/components/app-build-item/app-build-item.component.html +++ b/src/app/components/app-build-item/app-build-item.component.html @@ -25,7 +25,7 @@ {{ build?.totalTime }}
- + @@ -34,7 +34,7 @@ - + diff --git a/src/app/components/app-build-item/app-build-item.component.ts b/src/app/components/app-build-item/app-build-item.component.ts index 060804276..a342adea8 100644 --- a/src/app/components/app-build-item/app-build-item.component.ts +++ b/src/app/components/app-build-item/app-build-item.component.ts @@ -1,4 +1,5 @@ -import { Component, Input, HostBinding } from '@angular/core'; +import { Component, Input, HostBinding, OnInit } from '@angular/core'; +import { SocketService } from '../../services/socket.service'; @Component({ selector: 'app-build-item', @@ -7,4 +8,28 @@ import { Component, Input, HostBinding } from '@angular/core'; export class AppBuildItemComponent { @Input() build: any; @HostBinding('class') classes = 'column is-12'; + + processingRequest: boolean; + + constructor(private socketService: SocketService) { } + + ngOnInit() { + this.socketService.outputEvents + .filter(x => x.type === 'buildRestarted' || x.type === 'buildStopped') + .subscribe(e => this.processingRequest = false); + } + + restartBuild(e: MouseEvent, id: number): void { + e.preventDefault(); + e.stopPropagation(); + this.processingRequest = true; + this.socketService.emit({ type: 'restartBuild', data: { buildId: id } }); + } + + stopBuild(e: MouseEvent, id: number): void { + e.preventDefault(); + e.stopPropagation(); + this.processingRequest = true; + this.socketService.emit({ type: 'stopBuild', data: { buildId: id } }); + } } diff --git a/src/app/components/app-builds/app-builds.component.ts b/src/app/components/app-builds/app-builds.component.ts index dd292cefb..935176720 100644 --- a/src/app/components/app-builds/app-builds.component.ts +++ b/src/app/components/app-builds/app-builds.component.ts @@ -36,11 +36,6 @@ export class AppBuildsComponent implements OnInit, OnDestroy { return; } - if (event.type === 'buildRestarted' || event.type === 'buildStopped') { - const buildIndex = this.builds.findIndex(build => build.id === event.data); - this.builds[buildIndex].processingRequest = false; - } - if (event.data === 'jobAdded') { this.show = 5; this.offset = 0; @@ -85,7 +80,6 @@ export class AppBuildsComponent implements OnInit, OnDestroy { fetch(): void { this.apiService.getBuilds(this.show, this.offset).subscribe(builds => { - console.log(builds); this.builds = builds; this.updateJobs(); setInterval(() => this.updateJobs(), 1000); @@ -147,22 +141,6 @@ export class AppBuildsComponent implements OnInit, OnDestroy { }); } - restartBuild(e: MouseEvent, id: number): void { - e.preventDefault(); - e.stopPropagation(); - const buildIndex = this.builds.findIndex(build => build.id === id); - this.builds[buildIndex].processingRequest = true; - this.socketService.emit({ type: 'restartBuild', data: { buildId: id } }); - } - - stopBuild(e: MouseEvent, id: number): void { - e.preventDefault(); - e.stopPropagation(); - const buildIndex = this.builds.findIndex(build => build.id === id); - this.builds[buildIndex].processingRequest = true; - this.socketService.emit({ type: 'stopBuild', data: { buildId: id } }); - } - gotoBuild(buildId: number) { this.router.navigate(['build', buildId]); } diff --git a/src/app/components/app-repository/app-repository.component.ts b/src/app/components/app-repository/app-repository.component.ts index e233aeae9..9090e63c4 100644 --- a/src/app/components/app-repository/app-repository.component.ts +++ b/src/app/components/app-repository/app-repository.component.ts @@ -48,11 +48,6 @@ export class AppRepositoryComponent implements OnInit, OnDestroy { return; } - if (event.type === 'buildRestarted' || event.type === 'buildStopped') { - const buildIndex = this.repo.builds.findIndex(build => build.id === event.data); - this.repo.builds[buildIndex].processingRequest = false; - } - if (event.data === 'jobAdded') { this.fetch(); } @@ -155,22 +150,6 @@ export class AppRepositoryComponent implements OnInit, OnDestroy { }); } - restartBuild(e: MouseEvent, id: number): void { - e.preventDefault(); - e.stopPropagation(); - const buildIndex = this.repo.builds.findIndex(build => build.id === id); - this.repo.builds[buildIndex].processingRequest = true; - this.socketService.emit({ type: 'restartBuild', data: { buildId: id } }); - } - - stopBuild(e: MouseEvent, id: number): void { - e.preventDefault(); - e.stopPropagation(); - const buildIndex = this.repo.builds.findIndex(build => build.id === id); - this.repo.builds[buildIndex].processingRequest = true; - this.socketService.emit({ type: 'stopBuild', data: { buildId: id } }); - } - gotoBuild(buildId: number) { this.router.navigate(['build', buildId]); }