Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit, ViewChild } from '@angular/core';
- import { BecPeriod } from '../dataModel/becPeriod';
- import { AppService } from '../app.service';
- import { SelectionParamsService } from '../sharedComponents/selection-params/selection-params.service';
- import { Ratio } from '../dataModel/ratio';
- import { Category } from '../dataModel/category';
- import { Group } from '../dataModel/group';
- import { Subgroup } from '../dataModel/subgroup';
- import * as _ from 'lodash';
- import { FacingService } from '../facing/facing.service';
- import { RatioService } from './ratio.service';
- import { Table } from 'primeng/table';
- import { LaunchType } from '../dataModel/launchType';
- import { ShopSize } from '../dataModel/shopSize';
- import { MatDialog } from '@angular/material';
- import { RatioBulkComponent } from './ratio-bulk/ratio-bulk.component';
- import { FormControl } from '@angular/forms';
- @Component({
- selector: 'app-ratio',
- templateUrl: './ratio.component.html',
- styleUrls: ['./ratio.component.sass']
- })
- export class RatioComponent implements OnInit {
- selectionExpandState: boolean = false;
- allSelected: boolean = false;
- isExportInProgress: boolean = false;
- isSaveInProgress: boolean = false;
- aChangeWasMade: boolean = false;
- excelPath: string;
- readonly debounceTime: number = 1500;
- areTableFiltersChanged: boolean = false;
- searchTableFormControl = new FormControl('');
- selectedRows: Ratio[];
- ratioIdsToUpdate: string[];
- ratios: Ratio[] = [];
- becPeriods: BecPeriod[];
- selectedBecPeriod: BecPeriod[];
- private categories: Category[];
- private selectedCategories: Category[];
- groups: Group[];
- selectedGroups: Group[];
- subgroups: Subgroup[];
- selectedSubgroups: Subgroup[];
- launchTypes: LaunchType[]
- selectedLaunchTypes: LaunchType[]
- shopSizes: ShopSize[]
- selectedShopSizes: ShopSize[]
- becDropdownSettings = this._selectionParamsService.createSingleSelectOptions('BEC Period', 'becId', 'becDescription');
- cols = [
- { field: 'selection', header: '', style: { 'width': '20px' }, class: "selection-checkbox" },
- { field: 'deCategory', header: 'Category', style: { 'width': '100px' } },
- { field: 'deGroup', header: 'Group', style: { 'width': '100px' } },
- { field: 'deSubgroup', header: 'Subgroup', style: { 'width': '100px' } },
- { field: 'deLaunchType', header: 'Launch Size', style: { 'width': '100px' } },
- { field: 'deShopSize', header: 'Shop Size', style: { 'width': '100px' } },
- { field: 'ratio', header: 'Ratio', style: { 'width': '100px' } },
- ];
- constructor(
- private _AppService: AppService,
- private _selectionParamsService: SelectionParamsService,
- private _RatioService: RatioService,
- private _FacingService: FacingService,
- public dialog: MatDialog
- ) { }
- ngOnInit() {
- this._AppService.getBecPeriods().subscribe(
- data => this.becPeriods = data,
- error => alert(JSON.stringify(error)),
- () => {
- this.selectedBecPeriod = [this._selectionParamsService.findCurrentBecPeriod(this.becPeriods)];
- this.searchRatios();
- });
- }
- searchRatios() {
- this._RatioService.getRatios(this.selectedBecPeriod[0].becId).subscribe(
- data => this.ratios = data,
- error => alert(JSON.stringify(error)),
- () => {
- _.forEach(this.ratios, function (o) {
- o.deCategory = o.becCategory.description;
- o.deGroup = o.becGroup.description;
- o.deSubgroup = o.becSubgroup.description;
- o.deLaunchType = o.becLaunchType.description;
- o.deShopSize = o.becShopSize.description;
- });
- this.categories = _.uniqBy(_.map(this.ratios, 'becCategory'), 'description');
- this.selectedCategories = this.categories;
- this.groups = _.uniqBy(_.map(this.ratios, 'becGroup'), 'description');
- this.selectedGroups = this.groups;
- this.subgroups = _.uniqBy(_.map(this.ratios, 'becSubgroup'), 'description');
- this.selectedSubgroups = this.subgroups;
- this.launchTypes = _.uniqBy(_.map(this.ratios, 'becLaunchType'), 'description');
- this.selectedLaunchTypes = this.launchTypes;
- this.shopSizes = _.uniqBy(_.map(this.ratios, 'becShopSize'), 'description');
- this.selectedShopSizes = this.shopSizes;
- });
- }
- searchTable(tableRef: Table) {
- tableRef.filterGlobal(this.searchTableFormControl.value, 'contains')
- }
- clearFilters(tableRef: Table) {
- tableRef.reset();
- this.searchTableFormControl.setValue("");
- }
- onEdit(id): void {
- this.aChangeWasMade = true;
- this.addForSave(id);
- }
- addForSave(idToSave) {
- if (_.isNil(this.ratioIdsToUpdate))
- this.ratioIdsToUpdate = [];
- if (this.allreadyUpForSave(idToSave) == false)
- this.ratioIdsToUpdate.push(idToSave);
- }
- allreadyUpForSave(idToSave) {
- return (_.findIndex(this.ratioIdsToUpdate, function (id) { return id == idToSave; }) >= 0)
- }
- disableBulkButton(): boolean {
- return _.isEmpty(this.selectedRows) || this.selectedRows.length < 2;
- }
- bulkSetSize(): void {
- let dialogRef = this.dialog.open(RatioBulkComponent, {
- width: '500px'
- });
- dialogRef.afterClosed().subscribe(result => {
- if (_.isNil(result)) return;
- this.aChangeWasMade = true;
- _.forEach(this.selectedRows, function (o) {
- _.forEach(this.ratios, function (i) {
- if (i.id == o.id) {
- i.ratio = result;
- i.isChanged = true;
- this.onEdit(i.id);
- return false;
- }
- }.bind(this));
- }.bind(this));
- });
- }
- filterColumn(tableRef: Table, event, colField) {
- var values: string[] = _.map(event.value, 'description');
- tableRef.filter(values, colField, 'in');
- }
- disableSaveButton(): boolean {
- if (this.aChangeWasMade == false || this.isExportInProgress || this.isSaveInProgress)
- return true;
- return false;
- }
- saveButtonStateInfo(): string {
- if (_.isNil(this.ratios) || _.isEmpty(this.ratios))
- return "No item to save";
- else if (this.isSaveInProgress)
- return "Saving.."
- return "Save";
- }
- saveRatios(): void {
- var toSaveList = [];
- _.forEach(this.ratios, function (ratio) {
- if (this.allreadyUpForSave(ratio.id))
- toSaveList.push(ratio);
- }.bind(this));
- if (_.isNil(toSaveList) || _.isEmpty(toSaveList))
- return;
- this.isSaveInProgress = true;
- this._RatioService.saveRatios(toSaveList).subscribe(
- data => data,
- error => alert(JSON.stringify(error)),
- () => {
- this.isSaveInProgress = false;
- this.aChangeWasMade = false;
- this.ratioIdsToUpdate = null;
- this.searchRatios();
- }
- );
- }
- disableExportButton(): boolean {
- if (_.isNil(this.ratios) || _.isEmpty(this.ratios))
- return true;
- else if (this.isExportInProgress)
- return true;
- return false;
- }
- exportButtonStateInfo(): string {
- if (this.disableExportButton())
- return "No items to export";
- if (this.isExportInProgress)
- return "Exporting..";
- return "Export";
- }
- exportConfigurationReport(): void {
- this.isExportInProgress = true;
- this._FacingService.exportConfigurationReport(this.selectedBecPeriod[0]).subscribe(
- data => this.excelPath = data,
- error => alert(JSON.stringify(error)),
- () => {
- this.isExportInProgress = false;
- window.open(this._AppService.download(this.excelPath));
- }
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement