add delete campaign funct
parent
51f78bd5f3
commit
b266f00e2f
|
@ -54,6 +54,22 @@ campaigns.route('/:id')
|
|||
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(
|
||||
routerHandling.httpMethodNotAllowed
|
||||
);
|
||||
|
|
|
@ -14,6 +14,7 @@ export class AppConfig {
|
|||
public readonly apiRequestAwardPath = this.apiUrl + '/request/award';
|
||||
public readonly apiPromotionPath = this.apiUrl + '/request/promotion';
|
||||
public readonly apiWarPath = this.apiUrl + '/wars';
|
||||
public readonly apiCampaignPath = this.apiUrl + '/campaigns';
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,22 +1,15 @@
|
|||
import {Injectable} from "@angular/core";
|
||||
import {Campaign, War} from "../../models/model-interfaces";
|
||||
import {War} from "../../models/model-interfaces";
|
||||
import {AppConfig} from "../../app.config";
|
||||
import {HttpClient} from "../http-client";
|
||||
|
||||
@Injectable()
|
||||
export class WarService {
|
||||
|
||||
campaigns: Campaign[];
|
||||
|
||||
constructor(private http: HttpClient,
|
||||
private config: AppConfig) {
|
||||
}
|
||||
|
||||
getAllCampaigns() {
|
||||
return this.http.get(this.config.apiWarPath)
|
||||
.map(res => res.json())
|
||||
}
|
||||
|
||||
getWar(warId: string) {
|
||||
return this.http.get(this.config.apiWarPath + '/' + warId)
|
||||
.map(res => res.json())
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {Component} from "@angular/core";
|
||||
import {WarService} from "../../services/war-service/war.service";
|
||||
import {ActivatedRoute} from "@angular/router";
|
||||
import {CarouselConfig} from "ngx-bootstrap";
|
||||
import {CampaignService} from "../../services/campaign-service/campaign.service";
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -26,7 +26,7 @@ export class StatisticOverviewComponent {
|
|||
};
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private warService: WarService) {
|
||||
private campaignService: CampaignService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
@ -34,10 +34,10 @@ export class StatisticOverviewComponent {
|
|||
.map(params => params['id'])
|
||||
.subscribe((id) => {
|
||||
this.id = id;
|
||||
if (this.warService.campaigns) {
|
||||
this.initWars(this.warService.campaigns);
|
||||
if (this.campaignService.campaigns) {
|
||||
this.initWars(this.campaignService.campaigns);
|
||||
} else {
|
||||
this.warService.getAllCampaigns().subscribe(campaigns => {
|
||||
this.campaignService.getAllCampaigns().subscribe(campaigns => {
|
||||
this.initWars(campaigns);
|
||||
})
|
||||
}
|
||||
|
|
|
@ -6,12 +6,13 @@ import {WarService} from "../services/war-service/war.service";
|
|||
import {DataTableModule} from "angular2-datatable";
|
||||
import {LineChartModule, PieChartModule} from "@swimlane/ngx-charts";
|
||||
import {AccordionModule, CarouselModule} from "ngx-bootstrap";
|
||||
import {CampaignService} from "../services/campaign-service/campaign.service";
|
||||
|
||||
@NgModule({
|
||||
declarations: statsRoutingComponents,
|
||||
imports: [CommonModule, SharedModule, statsRouterModule, LineChartModule, PieChartModule,
|
||||
AccordionModule.forRoot(), CarouselModule.forRoot(), DataTableModule],
|
||||
providers: [WarService]
|
||||
providers: [WarService, CampaignService]
|
||||
})
|
||||
export class StatsModule {
|
||||
static routes = statsRouterModule;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
position: fixed;
|
||||
overflow-y: scroll;
|
||||
overflow-x: hidden;
|
||||
border-left: thin solid lightgrey;
|
||||
bottom: 20px;
|
||||
width: 100%;
|
||||
padding-left: 50px;
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
}
|
||||
|
||||
:host /deep/ .card-header {
|
||||
background-color: slategray;
|
||||
background-color: #222222;
|
||||
cursor: pointer;
|
||||
padding: 15px;
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
<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()">
|
||||
Schlacht hinzufügen
|
||||
</a>
|
||||
<a class="pull-right btn btn-success" (click)="selectNewCampaign()">
|
||||
Kampagne hinzufügen
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<accordion *ngFor="let campaign of campaigns; let isFirstRow=first">
|
||||
<accordion-group [isOpen]="isFirstRow">
|
||||
<div accordion-heading (click)="selectOverview(campaign._id)">
|
||||
<div accordion-heading>
|
||||
{{campaign.title}}
|
||||
<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 class="fade-in list-entry" style="margin-top: -16px; margin-bottom: 10px;"
|
||||
|
|
|
@ -3,6 +3,7 @@ import {ActivatedRoute, Router} from "@angular/router";
|
|||
import {Campaign, War} from "../../models/model-interfaces";
|
||||
import {WarService} from "../../services/war-service/war.service";
|
||||
import {LoginService} from "../../services/login-service/login-service";
|
||||
import {CampaignService} from "../../services/campaign-service/campaign.service";
|
||||
|
||||
@Component({
|
||||
selector: 'war-list',
|
||||
|
@ -16,14 +17,15 @@ export class WarListComponent implements OnInit {
|
|||
campaigns: Campaign[] = [];
|
||||
|
||||
constructor(private warService: WarService,
|
||||
private campaignService: CampaignService,
|
||||
private loginService: LoginService,
|
||||
private router: Router,
|
||||
private route: ActivatedRoute) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.warService.getAllCampaigns().subscribe((items) => {
|
||||
this.warService.campaigns = items;
|
||||
this.campaignService.getAllCampaigns().subscribe((items) => {
|
||||
this.campaignService.campaigns = items;
|
||||
this.campaigns = items;
|
||||
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);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue