Newer
Older
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {Product} from "../../model/product";
import {verticleSlide} from "../../animations";
import {ProductsService} from "../../services/products.service";
import {AlertService} from "../../services/alert.service";
@Component({
selector: 'app-product',
templateUrl: './product.component.html',
styleUrls: ['./product.component.scss'],
animations: [verticleSlide]
})
export class ProductComponent implements OnInit {
@Input() product: Product;
@Input() canDeleteProducts: boolean;
@Output() refreshProducts = new EventEmitter<boolean>();
productStatuses: Array<string> = ["WAITING", "READY", "COMPLETED", "PROCESSING", "CACHED"];
detailsExposed: boolean = false;
constructor(private productService: ProductsService, private alertService: AlertService) {
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
}
ngOnInit() {
}
getName(): string {
if (this.product.typeName == 'schedblock') {
return this.product.name + ' (' + this.product.optId + ')';
} else {
return this.product.name;
}
}
getStatusBadgeClass(): string {
switch (this.product.status) {
case 'COMPLETED':
return 'btn-success';
case 'READY':
return 'btn-info';
case 'WAITING':
return 'btn-warning';
case 'PROCESSING':
return 'btn-primary';
default:
return 'btn-light';
}
}
showImageDetails(): boolean {
let showTypes = [
'quicklook',
'se_cont',
'se_coarse_cube_image',
'se_coarse_plane_image',
'se_coarse_plane_I_image',
'se_coarse_plane_Q_image',
'se_coarse_plane_U_image'
];
return showTypes.indexOf(this.product.typeName) > -1;
}
getPhaseCenterRA(): string {
return parseFloat(this.product.phaseCenterRA).toFixed(4);
}
getPhaseCenterDec(): string {
return parseFloat(this.product.phaseCenterDec).toFixed(4);
}
getImageSizeX(): string {
return parseFloat(this.product.imageSizeX).toFixed(4);
}
getImageSizeY(): string {
return parseFloat(this.product.imageSizeY).toFixed(4);
}
updateStatus(status: string) {
if (status.toLowerCase() !== this.product.status.toLowerCase()) {
this.productService.updateProductStatus(this.product.id, status).subscribe(response => {
this.product.status = response;
});
}
}
deleteProduct(): void {
if (this.canDeleteProducts) {
let confirmed = confirm('Are you sure you want to delete ' + this.product.id);
if (confirmed) {
this.alertService.info('Deleting Product');
this.productService.deleteProduct(this.product.id).subscribe(response => {
this.alertService.success('Product Deleted');
this.refreshProducts.emit(true);
}, error => {
this.alertService.error('Product deletion failed');
});
}
}
}