160 lines
5.4 KiB
TypeScript
160 lines
5.4 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { Inject } from '@angular/core';
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
import { DataService } from '../data.service';
|
|
import {
|
|
MatSnackBar,
|
|
MatSnackBarHorizontalPosition,
|
|
MatSnackBarVerticalPosition,
|
|
} from '@angular/material/snack-bar';
|
|
|
|
@Component({
|
|
selector: 'app-implementer-dialog',
|
|
templateUrl: './implementer-dialog.component.html',
|
|
styleUrls: ['./implementer-dialog.component.css']
|
|
})
|
|
export class ImplementerDialogComponent implements OnInit {
|
|
|
|
|
|
public possibleImplementers: any[] = [
|
|
{value: '-1', viewValue: 'default'}
|
|
];
|
|
public selectedValue : any = this.possibleImplementers[0].value;
|
|
public progress : number = 0;
|
|
public diasbled : boolean = false;
|
|
public bdiasbled : boolean = false;
|
|
public horizontalPosition: MatSnackBarHorizontalPosition = 'end';
|
|
public verticalPosition: MatSnackBarVerticalPosition = 'bottom';
|
|
public labels: string[] = [];
|
|
|
|
private implementers : any[];
|
|
|
|
|
|
/**
|
|
* The constructor injects required Dependencies and sets default values for logic and ui
|
|
* @param dialogRef MatDialog Reference from Angular
|
|
* @param data contains an array of Changes which should be sent to the backend for a status transition
|
|
* @param dataService injects the dataService for data management and backend communication
|
|
*/
|
|
constructor(private dialogRef: MatDialogRef<ImplementerDialogComponent>, @Inject(MAT_DIALOG_DATA) public data: any,private dataService: DataService, private _snackBar: MatSnackBar) {
|
|
this.progress = 0;
|
|
this.bdiasbled = true;
|
|
this.diasbled = false;
|
|
this.selectedValue = -1;
|
|
this.possibleImplementers = [];
|
|
this.labels = [];
|
|
if(this.dataService.selectedLanguage == 'DE'){
|
|
this.labels.push("Implementer Eintragen");
|
|
this.labels.push("Implementer auswählen");
|
|
this.labels.push("Abbrechen");
|
|
this.labels.push("Bestätigen");
|
|
}else{
|
|
this.labels.push("Enter Implementer");
|
|
this.labels.push("Select Implementer");
|
|
this.labels.push("Cancel");
|
|
this.labels.push("Confirm");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The function ngOnInit checks in which actual State the selected changes are, then it provides a list that contains which statuses can be switched to in the current state
|
|
*/
|
|
ngOnInit(): void {
|
|
console.log(this.data.changes[0]);
|
|
this.dataService.fetchImplementers(this.data.changes[0]).then((res: any)=>{
|
|
this.implementers = res;
|
|
console.log(this.implementers);
|
|
this.possibleImplementers = [];
|
|
if(this.implementers.length>0){
|
|
for (const implementer of this.implementers) {
|
|
this.possibleImplementers.push({value: implementer.loginId, viewValue: implementer.memberName});
|
|
}
|
|
}else{
|
|
this.dialogRef.close();
|
|
}
|
|
}).catch((error)=>{
|
|
|
|
});
|
|
|
|
// MOCK:
|
|
// this.implementers = [{name: "Manuel Tauber", loginId: "MT01"}, {name: "Julius Sula", loginId: "MT02"}, {name: "Said Gedik", loginId: "MT03"}];
|
|
// console.log(this.implementers);
|
|
// this.possibleImplementers = [];
|
|
// if(this.implementers.length>0){
|
|
// for (const implementer of this.implementers) {
|
|
// this.possibleImplementers.push({value: implementer.loginId, viewValue: implementer.name});
|
|
// }
|
|
// }else{
|
|
// this.dialogRef.close();
|
|
// }
|
|
}
|
|
|
|
/**
|
|
* The function enableButton is triggered by the selction event of a possible state by the user it anebles the execution button
|
|
*/
|
|
enableButton():void{
|
|
this.bdiasbled = false;
|
|
}
|
|
|
|
/**
|
|
* The function updateState uses the dataService to execute a status transition on the backend. It sends the Changes to the backend one-by-one and calculates the percent-progress value for the progress bar.
|
|
*/
|
|
updateImplementer(): void{
|
|
let counter : number = 0;
|
|
if(this.selectedValue != -1){
|
|
for (let change of this.data.changes){
|
|
this.dataService.updateImplementerPerChange({resourceId: change.pkgId, loginId: this.selectedValue}).then((res: any)=>{
|
|
this.diasbled = true;
|
|
this.bdiasbled = true;
|
|
console.log(res);
|
|
if(res.status == 200){
|
|
counter++;
|
|
this.progress = (counter/this.data.changes.length)*100;
|
|
}
|
|
if(res.status == 500){
|
|
let msg;
|
|
let action;
|
|
if(this.dataService.selectedLanguage == 'DE'){
|
|
msg = 'Implementer Eintragung fehlgeschlagen';
|
|
action ='Schließen';
|
|
}else{
|
|
msg = 'Implementer Update failed';
|
|
action ='close';
|
|
}
|
|
this._snackBar.open(msg, action, {
|
|
horizontalPosition: this.horizontalPosition,
|
|
verticalPosition: this.verticalPosition,
|
|
panelClass: ['mat-primary']
|
|
});
|
|
this.dialogRef.close();
|
|
//this.dialogRef.close();
|
|
//counter++;
|
|
//this.progress = (counter/this.data.changes.length)*100;
|
|
}
|
|
|
|
if(this.progress == 100){
|
|
this.diasbled = false;
|
|
this.bdiasbled = true;
|
|
let msg;
|
|
let action;
|
|
if(this.dataService.selectedLanguage == 'DE'){
|
|
msg = 'Implementer Eintragung erfolgreich';
|
|
action ='Schließen';
|
|
}else{
|
|
msg = 'Implementer Update sucessful';
|
|
action ='close';
|
|
}
|
|
this._snackBar.open(msg, action, {
|
|
horizontalPosition: this.horizontalPosition,
|
|
verticalPosition: this.verticalPosition,
|
|
duration: 5000,
|
|
});
|
|
this.dialogRef.close();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|