Add edit campaign frontend
parent
6381c1ca86
commit
3754974bfb
|
@ -18,14 +18,23 @@ export class CampaignService {
|
||||||
}
|
}
|
||||||
|
|
||||||
submitCampaign(campaign: Campaign) {
|
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)
|
return this.http.post(this.config.apiCampaignPath, campaign)
|
||||||
.map(res => res.json());
|
.map(res => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
deleteCampaign(id: string) {
|
deleteCampaign(id: string) {
|
||||||
return this.http.delete(this.config.apiCampaignPath + '/' + id)
|
return this.http.delete(this.config.apiCampaignPath + '/' + id)
|
||||||
.map(res => res.json());
|
.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">
|
<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">
|
<div class="form-group">
|
||||||
<label for="title">Titel</label>
|
<label for="title">Titel</label>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {Component, ViewChild} from '@angular/core';
|
import {Component, ViewChild} from '@angular/core';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import {NgForm} from '@angular/forms';
|
import {NgForm} from '@angular/forms';
|
||||||
|
import {Subscription} from 'rxjs/Subscription';
|
||||||
import {Campaign} from '../../models/model-interfaces';
|
import {Campaign} from '../../models/model-interfaces';
|
||||||
import {CampaignService} from '../../services/logs/campaign.service';
|
import {CampaignService} from '../../services/logs/campaign.service';
|
||||||
|
|
||||||
|
@ -18,11 +19,21 @@ export class CampaignSubmitComponent {
|
||||||
|
|
||||||
error;
|
error;
|
||||||
|
|
||||||
|
subscription: Subscription;
|
||||||
|
|
||||||
@ViewChild(NgForm) form: NgForm;
|
@ViewChild(NgForm) form: NgForm;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute,
|
constructor(private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private campaignService: CampaignService) {
|
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() {
|
saveCampaign() {
|
||||||
|
|
|
@ -33,7 +33,12 @@ export const statsRoutes: Routes = [{
|
||||||
outlet: 'right'
|
outlet: 'right'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'new-campaign',
|
path: 'campaign',
|
||||||
|
component: CampaignSubmitComponent,
|
||||||
|
outlet: 'right'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'campaign/:id',
|
||||||
component: CampaignSubmitComponent,
|
component: CampaignSubmitComponent,
|
||||||
outlet: 'right'
|
outlet: 'right'
|
||||||
},
|
},
|
||||||
|
|
|
@ -46,7 +46,7 @@ export class WarListComponent implements OnInit {
|
||||||
|
|
||||||
selectNewCampaign() {
|
selectNewCampaign() {
|
||||||
this.selectedWarId = null;
|
this.selectedWarId = null;
|
||||||
this.router.navigate([{outlets: {'right': ['new-campaign']}}], {relativeTo: this.route});
|
this.router.navigate([{outlets: {'right': ['campaign']}}], {relativeTo: this.route});
|
||||||
}
|
}
|
||||||
|
|
||||||
selectNewWar() {
|
selectNewWar() {
|
||||||
|
@ -100,6 +100,6 @@ export class WarListComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
editCampaign(selectCampaign) {
|
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