opt-cc/static/src/app/statistic/war/war-submit/war-submit.component.ts

75 lines
1.9 KiB
TypeScript
Raw Normal View History

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';
import {WarService} from '../../../services/logs/war.service';
import {War} from '../../../models/model-interfaces';
import {CampaignService} from '../../../services/logs/campaign.service';
2017-07-14 23:33:17 +02:00
@Component({
selector: 'war-submit',
templateUrl: './war-submit.component.html',
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
showErrorLabel = false;
loading = false;
error;
@ViewChild(NgForm) form: NgForm;
constructor(private route: ActivatedRoute,
private router: Router,
private warService: WarService,
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() {
if (this.fileList) {
2017-08-06 11:55:34 +02:00
const file: File = this.fileList[0];
2017-07-14 23:33:17 +02:00
this.loading = true;
this.warService.submitWar(this.war, file)
2018-02-26 09:04:27 +01:00
.subscribe(war => {
this.router.navigate(['../war/' + war._id], {relativeTo: this.route});
},
error => {
this.error = error._body.error.message;
this.showErrorLabel = true;
this.loading = false;
});
2017-07-14 23:33:17 +02:00
} else {
return window.alert(`Logfile ist ein Pflichtfeld`);
}
}
cancel() {
this.router.navigate(['..'], {relativeTo: this.route});
return false;
}
}