74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
|
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';
|
||
|
|
||
|
|
||
|
@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']
|
||
|
})
|
||
|
export class WarSubmitComponent {
|
||
|
|
||
|
war: War = {players: []};
|
||
|
|
||
|
fileList: FileList;
|
||
|
|
||
|
readonly validExtensions = ['.rpt', '.log', '.txt'];
|
||
|
|
||
|
showFileError = false;
|
||
|
|
||
|
showErrorLabel = false;
|
||
|
|
||
|
loading = false;
|
||
|
|
||
|
error;
|
||
|
|
||
|
@ViewChild(NgForm) form: NgForm;
|
||
|
|
||
|
constructor(private route: ActivatedRoute,
|
||
|
private router: Router,
|
||
|
private warService: WarService,
|
||
|
public campaignService: CampaignService) {
|
||
|
}
|
||
|
|
||
|
fileChange(event) {
|
||
|
if (this.validExtensions.filter(ext => event.target.files[0] &&
|
||
|
event.target.files[0].name.endsWith(ext)).length === 1) {
|
||
|
this.showFileError = false;
|
||
|
this.fileList = event.target.files;
|
||
|
} else {
|
||
|
this.showFileError = true;
|
||
|
this.fileList = undefined;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
saveWar() {
|
||
|
if (this.fileList) {
|
||
|
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.error = error._body.error.message;
|
||
|
this.showErrorLabel = true;
|
||
|
this.loading = false;
|
||
|
});
|
||
|
} else {
|
||
|
return window.alert(`Logfile ist ein Pflichtfeld`);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
cancel() {
|
||
|
this.router.navigate(['..'], {relativeTo: this.route});
|
||
|
return false;
|
||
|
}
|
||
|
}
|