import {Component, Input, OnInit} from '@angular/core'; import {Product} from "../../model/product"; import {verticleSlide} from "../../animations"; import {ProductsService} from "../../services/products.service"; @Component({ selector: 'app-product', templateUrl: './product.component.html', styleUrls: ['./product.component.scss'], animations: [verticleSlide] }) export class ProductComponent implements OnInit { @Input() product: Product; productStatuses: Array<string> = ["WAITING", "READY", "COMPLETED", "PROCESSING", "CACHED"]; detailsExposed: boolean = false; constructor(private productService: ProductsService) { } 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; }); } } }