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

54 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';
2018-04-28 10:44:52 +02:00
import {Subscription} from 'rxjs/Subscription';
import {Campaign} from '../../../models/model-interfaces';
import {CampaignService} from '../../../services/logs/campaign.service';
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
2017-09-14 11:47:41 +02:00
@Component({
selector: 'campaign-submit',
templateUrl: './campaign-submit.component.html',
styleUrls: ['./campaign-submit.component.css', '../../../style/entry-form.css', '../../../style/overview.css']
2017-09-14 11:47:41 +02:00
})
export class CampaignSubmitComponent {
campaign: Campaign = {};
2018-04-28 10:44:52 +02:00
subscription: Subscription;
2017-09-14 11:47:41 +02:00
@ViewChild(NgForm) form: NgForm;
constructor(private route: ActivatedRoute,
private router: Router,
private campaignService: CampaignService,
private snackBarService: SnackBarService) {
2018-04-28 10:44:52 +02:00
this.subscription = this.route.params
.map(params => params['id'])
.filter(id => id !== undefined)
.flatMap(id => this.campaignService.getCampaign(id))
.subscribe(campaign => {
this.campaign = campaign;
});
2017-09-14 11:47:41 +02:00
}
saveCampaign() {
this.campaignService.submitCampaign(this.campaign)
2018-02-26 09:04:27 +01:00
.subscribe(campaign => {
let redirectSuccessUrl = '../overview/';
if (this.campaign._id) {
2018-04-29 09:51:28 +02:00
redirectSuccessUrl = '../' + redirectSuccessUrl;
}
2018-10-05 15:51:46 +02:00
this.snackBarService.showSuccess('generic.save.success');
this.router.navigate([redirectSuccessUrl + campaign._id], {relativeTo: this.route});
2018-02-26 09:04:27 +01:00
},
error => this.snackBarService.showError(error._body.error.message, 15000));
2017-09-14 11:47:41 +02:00
}
cancel() {
this.router.navigate(['..'], {relativeTo: this.route});
return false;
}
}