add delete campaign funct

pull/9/head
Florian Hartwich 2017-09-12 15:02:35 +02:00
parent 51f78bd5f3
commit b266f00e2f
10 changed files with 86 additions and 19 deletions

View File

@ -54,6 +54,22 @@ campaigns.route('/:id')
return next(); return next();
}); });
}) })
.delete((req, res, next) => {
CampaignModel.findByIdAndRemove(req.params.id, (err, item) => {
if (err) {
err.status = codes.wrongrequest;
return next(err);
}
else if (!item) {
err = new Error("item not found");
err.status = codes.notfound;
return next(err);
}
return next();
})
})
.all( .all(
routerHandling.httpMethodNotAllowed routerHandling.httpMethodNotAllowed
); );

View File

@ -14,6 +14,7 @@ export class AppConfig {
public readonly apiRequestAwardPath = this.apiUrl + '/request/award'; public readonly apiRequestAwardPath = this.apiUrl + '/request/award';
public readonly apiPromotionPath = this.apiUrl + '/request/promotion'; public readonly apiPromotionPath = this.apiUrl + '/request/promotion';
public readonly apiWarPath = this.apiUrl + '/wars'; public readonly apiWarPath = this.apiUrl + '/wars';
public readonly apiCampaignPath = this.apiUrl + '/campaigns';
} }

View File

@ -0,0 +1,31 @@
import {Injectable} from "@angular/core";
import {Campaign} from "../../models/model-interfaces";
import {AppConfig} from "../../app.config";
import {HttpClient} from "../http-client";
@Injectable()
export class CampaignService {
campaigns: Campaign[];
constructor(private http: HttpClient,
private config: AppConfig) {
}
getAllCampaigns() {
return this.http.get(this.config.apiWarPath)
.map(res => res.json())
}
submitCampaign(campaign: Campaign) {
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())
}
}

View File

@ -1,22 +1,15 @@
import {Injectable} from "@angular/core"; import {Injectable} from "@angular/core";
import {Campaign, War} from "../../models/model-interfaces"; import {War} from "../../models/model-interfaces";
import {AppConfig} from "../../app.config"; import {AppConfig} from "../../app.config";
import {HttpClient} from "../http-client"; import {HttpClient} from "../http-client";
@Injectable() @Injectable()
export class WarService { export class WarService {
campaigns: Campaign[];
constructor(private http: HttpClient, constructor(private http: HttpClient,
private config: AppConfig) { private config: AppConfig) {
} }
getAllCampaigns() {
return this.http.get(this.config.apiWarPath)
.map(res => res.json())
}
getWar(warId: string) { getWar(warId: string) {
return this.http.get(this.config.apiWarPath + '/' + warId) return this.http.get(this.config.apiWarPath + '/' + warId)
.map(res => res.json()) .map(res => res.json())

View File

@ -1,7 +1,7 @@
import {Component} from "@angular/core"; import {Component} from "@angular/core";
import {WarService} from "../../services/war-service/war.service";
import {ActivatedRoute} from "@angular/router"; import {ActivatedRoute} from "@angular/router";
import {CarouselConfig} from "ngx-bootstrap"; import {CarouselConfig} from "ngx-bootstrap";
import {CampaignService} from "../../services/campaign-service/campaign.service";
@Component({ @Component({
@ -26,7 +26,7 @@ export class StatisticOverviewComponent {
}; };
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private warService: WarService) { private campaignService: CampaignService) {
} }
ngOnInit() { ngOnInit() {
@ -34,10 +34,10 @@ export class StatisticOverviewComponent {
.map(params => params['id']) .map(params => params['id'])
.subscribe((id) => { .subscribe((id) => {
this.id = id; this.id = id;
if (this.warService.campaigns) { if (this.campaignService.campaigns) {
this.initWars(this.warService.campaigns); this.initWars(this.campaignService.campaigns);
} else { } else {
this.warService.getAllCampaigns().subscribe(campaigns => { this.campaignService.getAllCampaigns().subscribe(campaigns => {
this.initWars(campaigns); this.initWars(campaigns);
}) })
} }

View File

@ -6,12 +6,13 @@ import {WarService} from "../services/war-service/war.service";
import {DataTableModule} from "angular2-datatable"; import {DataTableModule} from "angular2-datatable";
import {LineChartModule, PieChartModule} from "@swimlane/ngx-charts"; import {LineChartModule, PieChartModule} from "@swimlane/ngx-charts";
import {AccordionModule, CarouselModule} from "ngx-bootstrap"; import {AccordionModule, CarouselModule} from "ngx-bootstrap";
import {CampaignService} from "../services/campaign-service/campaign.service";
@NgModule({ @NgModule({
declarations: statsRoutingComponents, declarations: statsRoutingComponents,
imports: [CommonModule, SharedModule, statsRouterModule, LineChartModule, PieChartModule, imports: [CommonModule, SharedModule, statsRouterModule, LineChartModule, PieChartModule,
AccordionModule.forRoot(), CarouselModule.forRoot(), DataTableModule], AccordionModule.forRoot(), CarouselModule.forRoot(), DataTableModule],
providers: [WarService] providers: [WarService, CampaignService]
}) })
export class StatsModule { export class StatsModule {
static routes = statsRouterModule; static routes = statsRouterModule;

View File

@ -2,6 +2,7 @@
position: fixed; position: fixed;
overflow-y: scroll; overflow-y: scroll;
overflow-x: hidden; overflow-x: hidden;
border-left: thin solid lightgrey;
bottom: 20px; bottom: 20px;
width: 100%; width: 100%;
padding-left: 50px; padding-left: 50px;

View File

@ -3,7 +3,8 @@
} }
:host /deep/ .card-header { :host /deep/ .card-header {
background-color: slategray; background-color: #222222;
cursor: pointer;
padding: 15px; padding: 15px;
color: white; color: white;
font-weight: 600; font-weight: 600;

View File

@ -1,15 +1,23 @@
<div class="war-list"> <div class="war-list">
<div class="input-group search-bar" style="margin-bottom:12px" *ngIf="loginService.hasPermission(3)"> <div class="input-group search-bar" style="margin-bottom:12px; width:100%;" *ngIf="loginService.hasPermission(3)">
<a class="pull-left btn btn-success" (click)="selectNewWar()"> <a class="pull-left btn btn-success" (click)="selectNewWar()">
Schlacht hinzufügen Schlacht hinzufügen
</a> </a>
<a class="pull-right btn btn-success" (click)="selectNewCampaign()">
Kampagne hinzufügen
</a>
</div> </div>
<accordion *ngFor="let campaign of campaigns; let isFirstRow=first"> <accordion *ngFor="let campaign of campaigns; let isFirstRow=first">
<accordion-group [isOpen]="isFirstRow"> <accordion-group [isOpen]="isFirstRow">
<div accordion-heading (click)="selectOverview(campaign._id)"> <div accordion-heading>
{{campaign.title}} {{campaign.title}}
<span class="pull-right"></span> <span class="pull-right"></span>
<span (click)="deleteCampaign(campaign); $event.stopPropagation()" title="Löschen"
style="color: whitesmoke; padding-top: 0; padding-right: 20px;"
class="glyphicon glyphicon-trash trash pull-right"
*ngIf="loginService.hasPermission(3)">
</span>
</div> </div>
<div class="fade-in list-entry" style="margin-top: -16px; margin-bottom: 10px;" <div class="fade-in list-entry" style="margin-top: -16px; margin-bottom: 10px;"

View File

@ -3,6 +3,7 @@ import {ActivatedRoute, Router} from "@angular/router";
import {Campaign, War} from "../../models/model-interfaces"; import {Campaign, War} from "../../models/model-interfaces";
import {WarService} from "../../services/war-service/war.service"; import {WarService} from "../../services/war-service/war.service";
import {LoginService} from "../../services/login-service/login-service"; import {LoginService} from "../../services/login-service/login-service";
import {CampaignService} from "../../services/campaign-service/campaign.service";
@Component({ @Component({
selector: 'war-list', selector: 'war-list',
@ -16,14 +17,15 @@ export class WarListComponent implements OnInit {
campaigns: Campaign[] = []; campaigns: Campaign[] = [];
constructor(private warService: WarService, constructor(private warService: WarService,
private campaignService: CampaignService,
private loginService: LoginService, private loginService: LoginService,
private router: Router, private router: Router,
private route: ActivatedRoute) { private route: ActivatedRoute) {
} }
ngOnInit() { ngOnInit() {
this.warService.getAllCampaigns().subscribe((items) => { this.campaignService.getAllCampaigns().subscribe((items) => {
this.warService.campaigns = items; this.campaignService.campaigns = items;
this.campaigns = items; this.campaigns = items;
this.selectOverview(this.campaigns[0]._id); this.selectOverview(this.campaigns[0]._id);
}); });
@ -60,4 +62,17 @@ export class WarListComponent implements OnInit {
} }
} }
deleteCampaign(campaign) {
if (confirm('Soll die Kampagne ' + campaign.title + ' wirklich gelöscht werden?')) {
this.campaignService.deleteCampaign(campaign._id)
.subscribe((res) => {
console.log(res)
if (this.selectedWarId === campaign._id) {
this.selectOverview('all');
}
this.campaigns.splice(this.campaigns.indexOf(campaign), 1);
})
}
}
} }