New dashboard look & feel
[src/xds/xds-agent.git] / webapp / src / app / pages / projects / project-card / project-card.component.ts
1 import { Component, Input, Pipe, PipeTransform } from '@angular/core';
2 import { ProjectService, IProject, ProjectType, ProjectTypeEnum } from '../../../@core-xds/services/project.service';
3 import { AlertService } from '../../../@core-xds/services/alert.service';
4
5
6 @Component({
7   selector: 'xds-project-card',
8   styleUrls: ['./project-card.component.scss'],
9   templateUrl: './project-card.component.html',
10 })
11 export class ProjectCardComponent {
12
13   // FIXME workaround of https://github.com/angular/angular-cli/issues/2034
14   // should be removed with angular 5
15   // @Input() project: IProject;
16   @Input() project = <IProject>null;
17
18   constructor(
19     private alert: AlertService,
20     private projectSvr: ProjectService
21   ) {
22   }
23
24   delete(prj: IProject) {
25     this.projectSvr.Delete(prj).subscribe(
26       res => { },
27       err => this.alert.error('ERROR delete: ' + err)
28     );
29   }
30
31   sync(prj: IProject) {
32     this.projectSvr.Sync(prj).subscribe(
33       res => { },
34       err => this.alert.error('ERROR: ' + err)
35     );
36   }
37 }
38
39 // Make Project type human readable
40 @Pipe({
41   name: 'readableType'
42 })
43
44 export class ProjectReadableTypePipe implements PipeTransform {
45   transform(type: ProjectTypeEnum): string {
46     switch (type) {
47       case ProjectType.NATIVE_PATHMAP: return 'Native (path mapping)';
48       case ProjectType.SYNCTHING: return 'Cloud (Syncthing)';
49       default: return String(type);
50     }
51   }
52 }