Add edit campaign frontend
parent
6381c1ca86
commit
3754974bfb
|
@ -18,14 +18,23 @@ export class CampaignService {
|
|||
}
|
||||
|
||||
submitCampaign(campaign: Campaign) {
|
||||
if (campaign._id) {
|
||||
return this.http.patch(this.config.apiCampaignPath + '/' + campaign._id, campaign);
|
||||
} else {
|
||||
return this.http.post(this.config.apiCampaignPath, campaign)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
deleteCampaign(id: string) {
|
||||
return this.http.delete(this.config.apiCampaignPath + '/' + id)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
getCampaign(id: string) {
|
||||
return this.http.get(this.config.apiCampaignPath + '/' + id)
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<form #form="ngForm" class="overview">
|
||||
<h3>Kampagne hinzufügen</h3>
|
||||
<h3 *ngIf="campaign._id">Kampagne editieren</h3>
|
||||
<h3 *ngIf="!campaign._id">Neue Kampagne hinzufügen</h3>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="title">Titel</label>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {Component, ViewChild} from '@angular/core';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {NgForm} from '@angular/forms';
|
||||
import {Subscription} from 'rxjs/Subscription';
|
||||
import {Campaign} from '../../models/model-interfaces';
|
||||
import {CampaignService} from '../../services/logs/campaign.service';
|
||||
|
||||
|
@ -18,11 +19,21 @@ export class CampaignSubmitComponent {
|
|||
|
||||
error;
|
||||
|
||||
subscription: Subscription;
|
||||
|
||||
@ViewChild(NgForm) form: NgForm;
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private campaignService: CampaignService) {
|
||||
|
||||
this.subscription = this.route.params
|
||||
.map(params => params['id'])
|
||||
.filter(id => id !== undefined)
|
||||
.flatMap(id => this.campaignService.getCampaign(id))
|
||||
.subscribe(campaign => {
|
||||
this.campaign = campaign;
|
||||
});
|
||||
}
|
||||
|
||||
saveCampaign() {
|
||||
|
|
|
@ -33,7 +33,12 @@ export const statsRoutes: Routes = [{
|
|||
outlet: 'right'
|
||||
},
|
||||
{
|
||||
path: 'new-campaign',
|
||||
path: 'campaign',
|
||||
component: CampaignSubmitComponent,
|
||||
outlet: 'right'
|
||||
},
|
||||
{
|
||||
path: 'campaign/:id',
|
||||
component: CampaignSubmitComponent,
|
||||
outlet: 'right'
|
||||
},
|
||||
|
|
|
@ -46,7 +46,7 @@ export class WarListComponent implements OnInit {
|
|||
|
||||
selectNewCampaign() {
|
||||
this.selectedWarId = null;
|
||||
this.router.navigate([{outlets: {'right': ['new-campaign']}}], {relativeTo: this.route});
|
||||
this.router.navigate([{outlets: {'right': ['campaign']}}], {relativeTo: this.route});
|
||||
}
|
||||
|
||||
selectNewWar() {
|
||||
|
@ -100,6 +100,6 @@ export class WarListComponent implements OnInit {
|
|||
}
|
||||
|
||||
editCampaign(selectCampaign) {
|
||||
this.router.navigate([{outlets: {'right': ['overview', selectCampaign._id]}}], {relativeTo: this.route});
|
||||
this.router.navigate([{outlets: {'right': ['campaign', selectCampaign._id]}}], {relativeTo: this.route});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue