import { Component, OnInit, ViewChild } from '@angular/core'; import { SystemAdminService } from 'src/app/shared/services/systemadmin.service'; import { FeedbackPanelComponent } from 'src/app/shared/components/feedback-panel/feedback-panel.component'; import { Discount } from 'tournee.businesslogic'; import { UtilityService } from 'src/app/shared/services/utility.service'; @Component({ selector: 'app-system-admin-discounts', templateUrl: './system-admin-discounts.component.html', styleUrls: ['./system-admin-discounts.component.css'], providers: [ SystemAdminService ] }) export class SystemAdminDiscountsComponent implements OnInit { @ViewChild('FeedbackPanel') FeedbackPanel:FeedbackPanelComponent; Discount: Discount = Discount.create(); Discounts: Array = []; constructor(private _sysadmin: SystemAdminService, public utility: UtilityService) { } ngOnInit() { this._sysadmin.getDiscounts() .then((result) => { this.Discounts = result.result.map((d) => { return new Discount(d); }); }) .catch((err) => { this.FeedbackPanel.triggerError(err); }); } save() { this._sysadmin.saveDiscount(this.Discount) .then((result) => { this.Discounts = result.result.map((d) => { return new Discount(d); }); this.Discount = Discount.create(); this.FeedbackPanel.triggerSuccess("Discount saved successfully"); }) .catch((err) => { this.FeedbackPanel.triggerError(err); }); } cancel() { this.Discount = Discount.create(); } clear() { this.Discount.valid_from = null; this.Discount.valid_to = null; } beginEdit(discount: Discount) { this.Discount = JSON.parse(JSON.stringify(discount)); } delete(discount: Discount) { this._sysadmin.deleteDiscount(discount) .then((result) => { this.FeedbackPanel.triggerSuccess("Discount deleted successfully"); this.Discounts = result.result.map((d) => { return new Discount(d); }); }) .catch((err) => { this.FeedbackPanel.triggerError(err); }); } }