Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

client pop-up error management #77

Merged
merged 9 commits into from Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/app.component.html
@@ -1,5 +1,7 @@
<h1>Angular CLI to UI</h1>

<app-popup-error></app-popup-error>

<ng-container *ngIf="isAlive">
<ng-container *ngIf="isReadyForWork">
<app-new
Expand All @@ -13,11 +15,9 @@ <h1>Angular CLI to UI</h1>
<app-serve (sendCommand)="sendCommand($event)"></app-serve>
<app-generate (sendCommand)="sendCommand($event)"></app-generate>
<button
(click)="leaveProject()"
[disabled]="!isProjectLeavable">
(click)="leaveProject()">
Leave Project
</button>
<div *ngIf="!isProjectLeavable">Can not leave this project</div>
</ng-container>
</ng-container>

Expand Down
18 changes: 14 additions & 4 deletions src/app/app.component.ts
Expand Up @@ -5,6 +5,8 @@ import { interval } from 'rxjs';
import { CommandService } from './services/command/command.service';
import { CommandRequest } from './models/angular-command-request';
import { AngularCliProcessStatus } from './models/angular-cli-process-status.enum';
import { ErrorService } from './services/error/error.service';
import { PopUpError } from './models/pop-up-error.interface';

@Component({
selector: 'app-root',
Expand All @@ -20,9 +22,10 @@ export class AppComponent implements OnInit {
timedStatusCheck = interval(1000);
subscription = {};
isAlive = true;
isProjectLeavable = true;

constructor(private commandService: CommandService) {}
constructor(
private commandService: CommandService,
private errorService: ErrorService) {}
ZimGil marked this conversation as resolved.
Show resolved Hide resolved

ngOnInit() {
this.keepAlive();
Expand Down Expand Up @@ -94,8 +97,12 @@ export class AppComponent implements OnInit {
this.commandService.leaveProject()
.subscribe(
() => this.checkAngularProject(),
() => this.isProjectLeavable = false
);
() => {
this.errorService.addError({
errorText: 'Unable to leave this project',
errorDescription: 'To run ngWiz on another project or to create a new one, please run it in the apropriate project direcroty'
});
});
}

sendCommand(userCommand: string): void {
Expand All @@ -108,4 +115,7 @@ export class AppComponent implements OnInit {
});
}

addError(error: PopUpError): void {
ZimGil marked this conversation as resolved.
Show resolved Hide resolved
this.errorService.addError(error);
}
}
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Expand Up @@ -8,14 +8,16 @@ import { NewComponent } from './components/new/new.component';
import { ServeComponent } from './components/serve/serve.component';
import { GenerateComponent } from './components/generate/generate.component';
import { CommandService } from './services/command/command.service';
import { PopupErrorComponent } from './components/popup-error/popup-error.component';


@NgModule({
declarations: [
AppComponent,
ServeComponent,
NewComponent,
GenerateComponent
GenerateComponent,
PopupErrorComponent
],
imports: [
FormsModule,
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions src/app/components/popup-error/popup-error.component.html
@@ -0,0 +1,12 @@
<div
*ngFor="let error of getErrors()"
class="error">
{{error.errorText}}
<ng-container
*ngIf="error.handleFunction"
class="userSelection">
<button (click)="handleError(error)">Yes</button>
<button (click)="clearError(error)">No</button>
</ng-container>
<button *ngIf="!error.handleFunction" (click)="clearError(error)">Ok</button>
</div>
25 changes: 25 additions & 0 deletions src/app/components/popup-error/popup-error.component.spec.ts
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { PopupErrorComponent } from './popup-error.component';

describe('PopupErrorComponent', () => {
let component: PopupErrorComponent;
let fixture: ComponentFixture<PopupErrorComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PopupErrorComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(PopupErrorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
29 changes: 29 additions & 0 deletions src/app/components/popup-error/popup-error.component.ts
@@ -0,0 +1,29 @@
import { Component } from '@angular/core';
import { PopUpError } from './../../models/pop-up-error.interface';
import { ErrorService } from './../../services/error/error.service';

@Component({
selector: 'app-popup-error',
templateUrl: './popup-error.component.html',
styleUrls: ['./popup-error.component.css']
})
export class PopupErrorComponent {

constructor(private errorService: ErrorService) {}

isErrors(): boolean {
return this.errorService.isErrors();
}

getErrors(): PopUpError[] {
return this.errorService.getErrors();
}

handleError(error: PopUpError) {
this.errorService.handleError(error);
}

clearError(error: PopUpError) {
this.errorService.clearError(error);
}
}
6 changes: 6 additions & 0 deletions src/app/models/pop-up-error.interface.ts
@@ -0,0 +1,6 @@
export interface PopUpError {
errorText: string;
errorDescription?: string;
handleFunction?: Function;
callingObject?: Object;
ZimGil marked this conversation as resolved.
Show resolved Hide resolved
}
15 changes: 15 additions & 0 deletions src/app/services/error/error.service.spec.ts
@@ -0,0 +1,15 @@
import { TestBed, inject } from '@angular/core/testing';

import { ErrorService } from './error.service';

describe('ErrorService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [ErrorService]
});
});

it('should be created', inject([ErrorService], (service: ErrorService) => {
expect(service).toBeTruthy();
}));
});
31 changes: 31 additions & 0 deletions src/app/services/error/error.service.ts
@@ -0,0 +1,31 @@
import { Injectable } from '@angular/core';
import { PopUpError } from './../../models/pop-up-error.interface';

@Injectable({
providedIn: 'root'
})
export class ErrorService {

errors: PopUpError[] = [];

addError(error: PopUpError): void {
this.errors.push(error);
}

getErrors(): PopUpError[] {
return this.errors;
}

clearError(error: PopUpError): void {
this.errors.splice(this.errors.indexOf(error), 1);
}

isErrors(): boolean {
return this.errors === [] ? false : true;
ZimGil marked this conversation as resolved.
Show resolved Hide resolved
}

handleError(error: PopUpError): void {
error.handleFunction.call(error.callingObject);
ZimGil marked this conversation as resolved.
Show resolved Hide resolved
this.clearError(error);
}
}