diff --git a/api/routes/campaigns.js b/api/routes/campaigns.js index b095dbf..381f6a1 100644 --- a/api/routes/campaigns.js +++ b/api/routes/campaigns.js @@ -13,6 +13,8 @@ const checkMT = require('../middleware/permission-check').checkMT; // Mongoose Model using mongoDB const CampaignModel = require('../models/campaign'); +const WarModel = require('../models/war'); + const campaigns = express.Router(); @@ -54,6 +56,25 @@ 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); + } + WarModel.find({campaign: req.params.id}).remove().exec(); + + res.locals.processed = true; + next(); + }) + }) + .all( routerHandling.httpMethodNotAllowed ); diff --git a/package.json b/package.json index e9f25d8..15f21aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opt-cc", - "version": "1.4.3", + "version": "1.4.4", "license": "MIT", "private": true, "scripts": { diff --git a/static/src/app/app.config.ts b/static/src/app/app.config.ts index 2559dbd..2eb172f 100644 --- a/static/src/app/app.config.ts +++ b/static/src/app/app.config.ts @@ -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'; } diff --git a/static/src/app/services/campaign-service/campaign.service.ts b/static/src/app/services/campaign-service/campaign.service.ts new file mode 100644 index 0000000..392bb85 --- /dev/null +++ b/static/src/app/services/campaign-service/campaign.service.ts @@ -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()) + } + +} + diff --git a/static/src/app/services/war-service/war.service.ts b/static/src/app/services/war-service/war.service.ts index 1c2bf61..ee17911 100644 --- a/static/src/app/services/war-service/war.service.ts +++ b/static/src/app/services/war-service/war.service.ts @@ -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()) diff --git a/static/src/app/statistic/campaign-submit/campaign-submit.component.css b/static/src/app/statistic/campaign-submit/campaign-submit.component.css new file mode 100644 index 0000000..f0ba23d --- /dev/null +++ b/static/src/app/statistic/campaign-submit/campaign-submit.component.css @@ -0,0 +1,8 @@ +.overview { + position: fixed; + width: 25%; + min-width: 300px; + padding-left: 50px; + padding-top: 70px; + margin-left: 10px; +} diff --git a/static/src/app/statistic/campaign-submit/campaign-submit.component.html b/static/src/app/statistic/campaign-submit/campaign-submit.component.html new file mode 100644 index 0000000..c4b0880 --- /dev/null +++ b/static/src/app/statistic/campaign-submit/campaign-submit.component.html @@ -0,0 +1,33 @@ +
+

Kampagne hinzufügen

+ +
+ + + + +
+ + + + + + + {{error}} + + +
diff --git a/static/src/app/statistic/campaign-submit/campaign-submit.component.ts b/static/src/app/statistic/campaign-submit/campaign-submit.component.ts new file mode 100644 index 0000000..469b968 --- /dev/null +++ b/static/src/app/statistic/campaign-submit/campaign-submit.component.ts @@ -0,0 +1,44 @@ +import {Component, ViewChild} from "@angular/core"; +import {ActivatedRoute, Router} from "@angular/router"; +import {NgForm} from "@angular/forms"; +import {Campaign} from "../../models/model-interfaces"; +import {CampaignService} from "../../services/campaign-service/campaign.service"; + + +@Component({ + selector: 'campaign-submit', + templateUrl: './campaign-submit.component.html', + styleUrls: ['./campaign-submit.component.css'] +}) +export class CampaignSubmitComponent { + + campaign: Campaign = {}; + + showErrorLabel = false; + + error; + + @ViewChild(NgForm) form: NgForm; + + constructor(private route: ActivatedRoute, + private router: Router, + private campaignService: CampaignService) { + } + + saveCampaign() { + this.campaignService.submitCampaign(this.campaign) + .subscribe(campaign => { + this.router.navigate(['../overview/' + campaign._id], {relativeTo: this.route}); + }, + error => { + this.error = error._body.error.message; + this.showErrorLabel = true; + }); + } + + cancel() { + this.router.navigate(['..'], {relativeTo: this.route}); + return false; + } + +} diff --git a/static/src/app/statistic/overview/stats-overview.component.ts b/static/src/app/statistic/overview/stats-overview.component.ts index b350b0a..ca737fc 100644 --- a/static/src/app/statistic/overview/stats-overview.component.ts +++ b/static/src/app/statistic/overview/stats-overview.component.ts @@ -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); }) } diff --git a/static/src/app/statistic/stats.module.ts b/static/src/app/statistic/stats.module.ts index 08e153b..15b9e9d 100644 --- a/static/src/app/statistic/stats.module.ts +++ b/static/src/app/statistic/stats.module.ts @@ -5,13 +5,14 @@ import {statsRouterModule, statsRoutingComponents} from "./stats.routing"; import {WarService} from "../services/war-service/war.service"; import {LineChartModule, PieChartModule} from "@swimlane/ngx-charts"; import {AccordionModule, CarouselModule} from "ngx-bootstrap"; +import {CampaignService} from "../services/campaign-service/campaign.service"; import {NgxDatatableModule} from "@swimlane/ngx-datatable"; @NgModule({ declarations: statsRoutingComponents, imports: [CommonModule, SharedModule, statsRouterModule, LineChartModule, PieChartModule, AccordionModule.forRoot(), CarouselModule.forRoot(), NgxDatatableModule], - providers: [WarService] + providers: [WarService, CampaignService] }) export class StatsModule { static routes = statsRouterModule; diff --git a/static/src/app/statistic/stats.routing.ts b/static/src/app/statistic/stats.routing.ts index ffc10cd..acff442 100644 --- a/static/src/app/statistic/stats.routing.ts +++ b/static/src/app/statistic/stats.routing.ts @@ -6,6 +6,7 @@ import {WarListComponent} from "./war-list/war-list.component"; import {StatisticOverviewComponent} from "./overview/stats-overview.component"; import {WarItemComponent} from "./war-list/war-item.component"; import {ModuleWithProviders} from "@angular/core"; +import {CampaignSubmitComponent} from "./campaign-submit/campaign-submit.component"; export const statsRoutes: Routes = [{ @@ -22,6 +23,11 @@ export const statsRoutes: Routes = [{ component: StatisticOverviewComponent, outlet: 'right' }, + { + path: 'new-campaign', + component: CampaignSubmitComponent, + outlet: 'right' + }, { path: 'new', component: WarSubmitComponent, @@ -35,6 +41,6 @@ export const statsRoutes: Routes = [{ export const statsRouterModule: ModuleWithProviders = RouterModule.forChild(statsRoutes); -export const statsRoutingComponents = [StatisticComponent, StatisticOverviewComponent, WarListComponent, - WarSubmitComponent, WarDetailComponent, WarItemComponent]; +export const statsRoutingComponents = [StatisticComponent, StatisticOverviewComponent, CampaignSubmitComponent, + WarListComponent, WarSubmitComponent, WarDetailComponent, WarItemComponent]; diff --git a/static/src/app/statistic/war-detail/war-detail.component.css b/static/src/app/statistic/war-detail/war-detail.component.css index d9a291c..ac08fbe 100644 --- a/static/src/app/statistic/war-detail/war-detail.component.css +++ b/static/src/app/statistic/war-detail/war-detail.component.css @@ -2,6 +2,7 @@ position: fixed; overflow-y: scroll; overflow-x: hidden; + border-left: thin solid lightgrey; bottom: 20px; width: 100%; padding-left: 50px; diff --git a/static/src/app/statistic/war-list/war-list.component.css b/static/src/app/statistic/war-list/war-list.component.css index 971ee7a..2f7bdfe 100644 --- a/static/src/app/statistic/war-list/war-list.component.css +++ b/static/src/app/statistic/war-list/war-list.component.css @@ -3,7 +3,8 @@ } :host /deep/ .card-header { - background-color: slategray; + background-color: rgba(34, 34, 34, 0.80); + cursor: pointer; padding: 15px; color: white; font-weight: 600; diff --git a/static/src/app/statistic/war-list/war-list.component.html b/static/src/app/statistic/war-list/war-list.component.html index 2dfae0c..5e1d82c 100644 --- a/static/src/app/statistic/war-list/war-list.component.html +++ b/static/src/app/statistic/war-list/war-list.component.html @@ -1,15 +1,23 @@
-