2018-03-07 11:56:50 +01:00
|
|
|
import {Component, ViewChild} from '@angular/core';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {NgForm} from '@angular/forms';
|
2018-04-29 10:12:27 +02:00
|
|
|
import {WarService} from '../../../services/logs/war.service';
|
|
|
|
import {War} from '../../../models/model-interfaces';
|
|
|
|
import {CampaignService} from '../../../services/logs/campaign.service';
|
2018-06-30 17:29:58 +02:00
|
|
|
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
|
2017-07-14 23:33:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'war-submit',
|
|
|
|
templateUrl: './war-submit.component.html',
|
2018-04-29 10:12:27 +02:00
|
|
|
styleUrls: ['./war-submit.component.css', '../../../style/load-indicator.css',
|
|
|
|
'../../../style/entry-form.css', '../../../style/overview.css']
|
2017-07-14 23:33:17 +02:00
|
|
|
})
|
|
|
|
export class WarSubmitComponent {
|
|
|
|
|
2017-10-21 15:00:49 +02:00
|
|
|
war: War = {players: []};
|
2017-07-14 23:33:17 +02:00
|
|
|
|
|
|
|
fileList: FileList;
|
|
|
|
|
2018-04-28 16:31:14 +02:00
|
|
|
readonly validExtensions = ['.rpt', '.log', '.txt'];
|
|
|
|
|
|
|
|
showFileError = false;
|
2017-07-14 23:33:17 +02:00
|
|
|
|
|
|
|
loading = false;
|
|
|
|
|
|
|
|
error;
|
|
|
|
|
|
|
|
@ViewChild(NgForm) form: NgForm;
|
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
2017-09-14 12:01:16 +02:00
|
|
|
private warService: WarService,
|
2018-06-30 17:29:58 +02:00
|
|
|
private snackBarService: SnackBarService,
|
2017-10-08 12:17:21 +02:00
|
|
|
public campaignService: CampaignService) {
|
2017-07-14 23:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fileChange(event) {
|
2018-04-28 16:31:14 +02:00
|
|
|
if (this.validExtensions.filter(ext => event.target.files[0] &&
|
2018-04-29 09:51:28 +02:00
|
|
|
event.target.files[0].name.endsWith(ext)).length === 1) {
|
2018-04-28 16:31:14 +02:00
|
|
|
this.showFileError = false;
|
2017-07-14 23:33:17 +02:00
|
|
|
this.fileList = event.target.files;
|
2018-04-28 16:31:14 +02:00
|
|
|
} else {
|
|
|
|
this.showFileError = true;
|
|
|
|
this.fileList = undefined;
|
2017-07-14 23:33:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
saveWar() {
|
2018-06-30 17:29:58 +02:00
|
|
|
if (!this.fileList) {
|
2017-07-14 23:33:17 +02:00
|
|
|
return window.alert(`Logfile ist ein Pflichtfeld`);
|
|
|
|
}
|
2018-06-30 17:29:58 +02:00
|
|
|
const file: File = this.fileList[0];
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
this.warService.submitWar(this.war, file)
|
|
|
|
.subscribe(war => {
|
|
|
|
this.router.navigate(['../war/' + war._id], {relativeTo: this.route});
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.loading = false;
|
|
|
|
const errorMsg = JSON.parse(error._body).error.message;
|
|
|
|
this.snackBarService.showError('Error: '.concat(errorMsg), 10000);
|
|
|
|
});
|
2017-07-14 23:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
this.router.navigate(['..'], {relativeTo: this.route});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|