import { Component, OnInit, ViewChild } from '@angular/core'; import { LookupsService } from 'src/app/shared/services/lookups.service'; import { FeedbackPanelComponent } from 'src/app/shared/components/feedback-panel/feedback-panel.component'; import { GameSystem } from 'tournee.businesslogic'; @Component({ selector: 'app-system-admin-lookups-game-system', templateUrl: './system-admin-lookups-game-system.component.html', styleUrls: ['./system-admin-lookups-game-system.component.css'] }) export class SystemAdminLookupsGameSystemComponent implements OnInit { @ViewChild('FeedbackPanel') FeedbackPanel:FeedbackPanelComponent; isWorking: boolean = false; Expanded: boolean = false; GameSystems: Array = []; EditModel: GameSystem = new GameSystem(null); constructor(private lookups: LookupsService) { } ngOnInit() { this.load() } toggle() { this.Expanded = !this.Expanded; } load() { if (this.isWorking) { return; } this.isWorking = true; this.lookups.get(this.EditModel.getType()) .then((result) => { this.GameSystems = result.result.map((gs) => { return new GameSystem(gs); }); this.isWorking = false; }) .catch((err) => { this.isWorking = false; console.log(err); }); } save() { if (this.isWorking) { return; } this.FeedbackPanel.reset(); this.isWorking = true; if (this.EditModel.id) { this.edit(); } else { this.add(); } } add() { this.lookups.add(this.EditModel) .then((result) => { this.GameSystems = result.result.map((gs) => { return new GameSystem(gs); }); this.isWorking = false; this.reset(); this.FeedbackPanel.triggerSuccess("Game System Details Saved Successfully"); }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); } edit() { this.lookups.update(this.EditModel) .then((result) => { this.GameSystems = result.result.map((gs) => { return new GameSystem(gs); }); this.isWorking = false; this.reset(); this.FeedbackPanel.triggerSuccess("Game System Details Saved Successfully"); }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); } delete(gs) { if (this.isWorking) { return; } this.isWorking = true; this.lookups.delete(gs) .then((result) => { this.GameSystems = result.result.map((gs) => { return new GameSystem(gs); }); this.isWorking = false; this.reset(); this.FeedbackPanel.triggerSuccess("Game System Details Deleted Successfully"); }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); } beginEdit(gameSystem) { this.EditModel.name = gameSystem.name; this.EditModel.manufacturer_name = gameSystem.manufacturer_name; this.EditModel.id = gameSystem.id; } reset() { this.EditModel.name = null; this.EditModel.manufacturer_name = null; this.EditModel.id = null; } }