diff --git a/api/cron-job/update-signatures.js b/api/cron-job/update-signatures.js
index 628b1fd..82f202d 100644
--- a/api/cron-job/update-signatures.js
+++ b/api/cron-job/update-signatures.js
@@ -5,10 +5,7 @@ const async = require('async');
const UserModel = require('../models/user');
const signatureTool = require('../signature-tool/signature-tool');
-
-// Execute daily @ 02:30 AM
-const cronJob = cron.job('00 30 02 * * *', () => {
-
+const createAllSignatures = () => {
console.log('\x1b[35m%s\x1b[0m', new Date().toLocaleString()
+ ': cron job started - UPDATE SIGNATURES');
@@ -42,6 +39,12 @@ const cronJob = cron.job('00 30 02 * * *', () => {
})
});
-});
+};
-module.exports = cronJob;
+// Execute daily @ 02:30 AM
+const cronJob = cron.job('00 30 02 * * *', createAllSignatures);
+
+module.exports = {
+ cronJob: cronJob,
+ createAllSignatures: createAllSignatures
+};
diff --git a/api/models/awarding.js b/api/models/awarding.js
index d653369..bd2b60d 100644
--- a/api/models/awarding.js
+++ b/api/models/awarding.js
@@ -22,8 +22,12 @@ const AwardingSchema = new Schema({
required: true
},
confirmed: {
- type: Boolean,
- default: true
+ type: Number,
+ get: v => Math.round(v),
+ set: v => Math.round(v),
+ min: 0,
+ max: 2,
+ default: 0
},
date: {
type: Date,
diff --git a/api/routes/awardings.js b/api/routes/awardings.js
index 96beea3..8658e68 100644
--- a/api/routes/awardings.js
+++ b/api/routes/awardings.js
@@ -36,6 +36,9 @@ awarding.route('/')
if (req.query.userId) {
filter.userId = req.query.userId;
}
+ if (req.query.inProgress) {
+ filter.confirmed = 0;
+ }
if (req.query.simple) {
AwardingModel.find(filter, {}, {sort: {date: 'desc'}}, (err, items) => {
if (err) {
@@ -53,17 +56,26 @@ awarding.route('/')
});
} else {
AwardingModel.find(filter, {}, {sort: {date: 'desc'}})
- .populate('decorationId').populate('proposer', resultSet).exec((err, items) => {
+ .populate('decorationId').populate('proposer', resultSet).populate('userId').exec((err, items) => {
if (err) {
err.status = codes.servererror;
return next(err);
// with return before (or after) the next(err) we prevent that the code continues here after next(err) has finished.
// this saves an extra else {..}
}
- // if the collection is empty we do not send empty arrays back.
- if (items && items.length > 0) {
+ let results = [];
+ if (req.query.fractFilter) {
+ for (let item of items) {
+ if (item.decorationId.fraction === req.query.fractFilter) {
+ results.push(item)
+ }
+ }
+ res.locals.items = results;
+
+ } else {
res.locals.items = items;
}
+
res.locals.processed = true;
next();
});
@@ -72,6 +84,7 @@ awarding.route('/')
.post(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
const award = new AwardingModel(req.body);
+ award.confirmed = 1;
award.proposer = req.user._id;
// timestamp and default are set automatically by Mongoose Schema Validation
award.save((err) => {
@@ -91,6 +104,36 @@ awarding.route('/')
);
awarding.route('/:id')
+
+ .patch(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
+ if (!req.body || (req.body._id && req.body._id !== req.params.id)) {
+ // little bit different as in PUT. :id does not need to be in data, but if the _id and url id must match
+ const err = new Error('id of PATCH resource and send JSON body are not equal ' + req.params.id + " " + req.body._id);
+ err.status = codes.notfound;
+ next(err);
+ return; // prevent node to process this function further after next() has finished.
+ }
+
+ // optional task 3: increment version manually as we do not use .save(.)
+ req.body.updatedAt = new Date();
+ req.body.$inc = {__v: 1};
+
+ // PATCH is easier with mongoose than PUT. You simply update by all data that comes from outside. no need to reset attributes that are missing.
+ AwardingModel.findByIdAndUpdate(req.params.id, req.body, {new: true}, (err, item) => {
+ if (err) {
+ err.status = codes.wrongrequest;
+ }
+ else if (!item) {
+ err = new Error("item not found");
+ err.status = codes.notfound;
+ }
+ else {
+ res.locals.items = item;
+ }
+ next(err);
+ })
+ })
+
.delete(apiAuthenticationMiddleware, checkHl, (req, res, next) => {
AwardingModel.findByIdAndRemove(req.params.id, (err, item) => {
if (err) {
diff --git a/api/routes/command.js b/api/routes/command.js
index fc6f91e..786e12f 100644
--- a/api/routes/command.js
+++ b/api/routes/command.js
@@ -8,11 +8,19 @@ const logger = require('debug')('cc:command');
const codes = require('./http-codes');
const routerHandling = require('../middleware/router-handling');
+const createAllSignatures = require('../cron-job/update-signatures').createAllSignatures;
const createSignature = require('../signature-tool/signature-tool');
const command = express.Router();
-// add middleware for bonus tasks 4 and 5 to find filter and offset/limit params for GET / and GET /:id
+command.route('/createSignature')
+ .post((req, res, next) => {
+ createAllSignatures();
+ })
+
+ .all(
+ routerHandling.httpMethodNotAllowed
+ );
command.route('/createSignature/:id')
.post((req, res, next) => {
diff --git a/api/routes/request.js b/api/routes/request.js
index e107734..e11d641 100644
--- a/api/routes/request.js
+++ b/api/routes/request.js
@@ -33,7 +33,7 @@ request.route('/award')
.post((req, res, next) => {
const award = new AwardingModel(req.body);
- award.confirmed = false;
+ award.confirmed = 0;
award.proposer = req.user._id;
// timestamp and default are set automatically by Mongoose Schema Validation
award.save((err) => {
diff --git a/api/server.js b/api/server.js
index 51a3b16..c7b375f 100644
--- a/api/server.js
+++ b/api/server.js
@@ -17,7 +17,7 @@ const errorResponseWare = require('./middleware/error-response');
const apiAuthenticationMiddleware = require('./middleware/auth-middleware');
const checkSql = require('./middleware/permission-check').checkSql;
const checkAdmin = require('./middleware/permission-check').checkAdmin;
-const signatureCronJob = require('./cron-job/update-signatures');
+const signatureCronJob = require('./cron-job/update-signatures').cronJob;
// router modules
const authenticateRouter = require('./routes/authenticate');
diff --git a/api/signature-tool/signature-tool.js b/api/signature-tool/signature-tool.js
index 3d0c63f..b965556 100644
--- a/api/signature-tool/signature-tool.js
+++ b/api/signature-tool/signature-tool.js
@@ -209,6 +209,8 @@ let saveJimpImageAndCompress = (image, userId, res, next) => {
}).then((files) => {
res.locals.items = {status: 'success'};
return next();
+ }).catch((error) => {
+ console.log(error)
})
}, 3000);
};
diff --git a/static/src/app/app.component.html b/static/src/app/app.component.html
index a0e53b5..bcf3a01 100644
--- a/static/src/app/app.component.html
+++ b/static/src/app/app.component.html
@@ -48,6 +48,21 @@
+
+
+ Anträge
+
+
+
+
diff --git a/static/src/app/app.config.ts b/static/src/app/app.config.ts
index 4b41471..c082376 100644
--- a/static/src/app/app.config.ts
+++ b/static/src/app/app.config.ts
@@ -4,7 +4,7 @@ export class AppConfig {
public readonly apiUrl = '';
public readonly apiAppUserPath = '/account/';
- public readonly apiAwardPath = '/awardings/';
+ public readonly apiAwardPath = '/awardings';
public readonly apiDecorationPath = '/decorations/';
public readonly apiAuthenticationPath = '/authenticate';
public readonly apiSignupPath = '/authenticate/signup';
diff --git a/static/src/app/app.routing.ts b/static/src/app/app.routing.ts
index 462f7a2..bed999c 100644
--- a/static/src/app/app.routing.ts
+++ b/static/src/app/app.routing.ts
@@ -1,7 +1,7 @@
-import {Routes, RouterModule} from '@angular/router';
-import {LoginComponent} from './login/index';
-import {NotFoundComponent} from './not-found/not-found.component';
-import {LoginGuardAdmin, LoginGuardHL, LoginGuardSQL} from './login/login.guard';
+import {RouterModule, Routes} from "@angular/router";
+import {LoginComponent} from "./login/index";
+import {NotFoundComponent} from "./not-found/not-found.component";
+import {LoginGuardAdmin, LoginGuardHL, LoginGuardSQL} from "./login/login.guard";
import {usersRoutes, usersRoutingComponents} from "./users/users.routing";
import {squadsRoutes, squadsRoutingComponents} from "./squads/squads.routing";
import {decorationsRoutes, decorationsRoutingComponents} from "./decorations/decoration.routing";
@@ -11,6 +11,8 @@ import {SignupComponent} from "./login/signup.component";
import {AdminComponent} from "./admin/admin.component";
import {RequestAwardComponent} from "./request/award/req-award.component";
import {RequestPromotionComponent} from "./request/promotion/req-promotion.component";
+import {ConfirmPromotionComponent} from "./request/confirm-promotion/confirm-promotion.component";
+import {ConfirmAwardComponent} from "./request/confirm-award/confirm-award.component";
export const appRoutes: Routes = [
@@ -23,6 +25,8 @@ export const appRoutes: Routes = [
{path: 'request-award', component: RequestAwardComponent, canActivate: [LoginGuardSQL]},
{path: 'request-promotion', component: RequestPromotionComponent, canActivate: [LoginGuardSQL]},
+ {path: 'confirm-award', component: ConfirmAwardComponent, canActivate: [LoginGuardHL]},
+ {path: 'confirm-promotion', component: ConfirmPromotionComponent, canActivate: [LoginGuardHL]},
{path: 'cc-users', children: usersRoutes, canActivate: [LoginGuardHL]},
{path: 'cc-squads', children: squadsRoutes, canActivate: [LoginGuardHL]},
@@ -38,7 +42,8 @@ export const appRoutes: Routes = [
export const appRouting = RouterModule.forRoot(appRoutes);
-export const routingComponents = [LoginComponent, SignupComponent, RequestAwardComponent, RequestPromotionComponent, AdminComponent, ...armyRoutingComponents , NotFoundComponent, ...usersRoutingComponents,
+export const routingComponents = [LoginComponent, SignupComponent, RequestAwardComponent, RequestPromotionComponent, ConfirmAwardComponent,
+ ConfirmPromotionComponent, AdminComponent, ...armyRoutingComponents, NotFoundComponent, ...usersRoutingComponents,
...squadsRoutingComponents, ...decorationsRoutingComponents, ...ranksRoutingComponents];
export const routingProviders = [LoginGuardHL];
diff --git a/static/src/app/army/army-member.component.html b/static/src/app/army/army-member.component.html
index 1392d10..332cdad 100644
--- a/static/src/app/army/army-member.component.html
+++ b/static/src/app/army/army-member.component.html
@@ -32,7 +32,7 @@
-
+
|
diff --git a/static/src/app/models/model-interfaces.ts b/static/src/app/models/model-interfaces.ts
index d62821b..2371b06 100644
--- a/static/src/app/models/model-interfaces.ts
+++ b/static/src/app/models/model-interfaces.ts
@@ -37,7 +37,7 @@ export interface Award {
reason?: string;
proposer?: AppUser;
date?: number; // since Date.now() returns a number
- confirmed?: boolean;
+ confirmed?: number;
}
export interface Promotion {
diff --git a/static/src/app/request/award/req-award.component.html b/static/src/app/request/award/req-award.component.html
index 2304f51..cfeffbf 100644
--- a/static/src/app/request/award/req-award.component.html
+++ b/static/src/app/request/award/req-award.component.html
@@ -97,10 +97,10 @@
{{award.proposer?.username}}
- {{award.date | date: 'dd.MM.yyyy'}}
+ {{award.date | date: 'dd.MM.yyyy'}}
|
- {{award.confirmed? 'Bestätigt' : 'In Bearbeitung'}}
+ {{award.confirmed === 0? 'In Bearbeitung' : (award.confirmed === 1? 'Genehmigt' : 'Abgelehnt')}}
|
diff --git a/static/src/app/request/confirm-award/confirm-award.component.css b/static/src/app/request/confirm-award/confirm-award.component.css
new file mode 100644
index 0000000..ec81a52
--- /dev/null
+++ b/static/src/app/request/confirm-award/confirm-award.component.css
@@ -0,0 +1,43 @@
+.decoration-preview {
+ padding: 5px;
+}
+
+.action {
+ cursor: pointer;
+}
+
+.table {
+ overflow-wrap: break-word;
+ table-layout: fixed;
+}
+
+.table-container {
+ margin-top: 40px;
+ overflow-x: auto;
+ width: 75%;
+}
+
+/* enable scrolling for long list of awardings */
+.overview {
+ position: fixed;
+ overflow-y: scroll;
+ overflow-x: hidden;
+ width: 100%;
+ border-left: thin solid lightgrey;
+ padding: 20px 0 0 50px;
+ margin-left: 10px;
+ height: 100vh;
+ bottom: 10px;
+}
+
+.form-group {
+ width: 25%;
+}
+
+h3 {
+ margin: 80px 0 20px -20px;
+}
+
+label {
+ display: block;
+}
diff --git a/static/src/app/request/confirm-award/confirm-award.component.html b/static/src/app/request/confirm-award/confirm-award.component.html
new file mode 100644
index 0000000..710b41d
--- /dev/null
+++ b/static/src/app/request/confirm-award/confirm-award.component.html
@@ -0,0 +1,49 @@
+
diff --git a/static/src/app/request/confirm-award/confirm-award.component.ts b/static/src/app/request/confirm-award/confirm-award.component.ts
new file mode 100644
index 0000000..ef0e55d
--- /dev/null
+++ b/static/src/app/request/confirm-award/confirm-award.component.ts
@@ -0,0 +1,42 @@
+import {Component} from "@angular/core";
+import {ActivatedRoute, Router} from "@angular/router";
+import {Award} from "../../models/model-interfaces";
+import {AwardingService} from "../../services/awarding-service/awarding.service";
+
+
+@Component({
+ templateUrl: './confirm-award.component.html',
+ styleUrls: ['./confirm-award.component.css'],
+})
+export class ConfirmAwardComponent {
+ awards: Award[];
+
+ constructor(private router: Router,
+ private route: ActivatedRoute,
+ private awardingService: AwardingService) {
+ }
+
+ ngOnInit() {
+ let currentUser = JSON.parse(localStorage.getItem('currentUser'));
+
+ this.awardingService.getUnconfirmedAwards(currentUser.squad.fraction).subscribe(awards => {
+ this.awards = awards;
+ });
+ }
+
+ confirm(award: Award, decision: boolean) {
+ const updateObject = {
+ _id: award._id,
+ confirmed: decision ? 1 : 2
+ };
+
+ this.awardingService.updateAward(updateObject).subscribe(res => {
+ let currentUser = JSON.parse(localStorage.getItem('currentUser'));
+ this.awardingService.getUnconfirmedAwards(currentUser.squad.fraction).subscribe(awards => {
+ this.awards = awards;
+ });
+ });
+ }
+
+
+}
diff --git a/static/src/app/request/confirm-promotion/confirm-promotion.component.css b/static/src/app/request/confirm-promotion/confirm-promotion.component.css
new file mode 100644
index 0000000..d9356a4
--- /dev/null
+++ b/static/src/app/request/confirm-promotion/confirm-promotion.component.css
@@ -0,0 +1,43 @@
+.decoration-preview {
+ padding: 5px;
+}
+
+.trash {
+ cursor: pointer;
+}
+
+.table {
+ overflow-wrap: break-word;
+ table-layout: fixed;
+}
+
+.table-container {
+ margin-top: 40px;
+ overflow-x: auto;
+ width: 65%;
+}
+
+/* enable scrolling for long list of awardings */
+.overview {
+ position: fixed;
+ overflow-y: scroll;
+ overflow-x: hidden;
+ width: 100%;
+ border-left: thin solid lightgrey;
+ padding: 20px 0 0 50px;
+ margin-left: 10px;
+ height: 100vh;
+ bottom: 10px;
+}
+
+.form-group {
+ width: 25%;
+}
+
+h3 {
+ margin: 80px 0 20px -20px;
+}
+
+label {
+ display: block;
+}
diff --git a/static/src/app/request/confirm-promotion/confirm-promotion.component.html b/static/src/app/request/confirm-promotion/confirm-promotion.component.html
new file mode 100644
index 0000000..4d2f3ad
--- /dev/null
+++ b/static/src/app/request/confirm-promotion/confirm-promotion.component.html
@@ -0,0 +1,105 @@
+
diff --git a/static/src/app/request/confirm-promotion/confirm-promotion.component.ts b/static/src/app/request/confirm-promotion/confirm-promotion.component.ts
new file mode 100644
index 0000000..2a39a98
--- /dev/null
+++ b/static/src/app/request/confirm-promotion/confirm-promotion.component.ts
@@ -0,0 +1,96 @@
+import {Component, ViewChild} from "@angular/core";
+import {ActivatedRoute, Router} from "@angular/router";
+import {Rank, User} from "../../models/model-interfaces";
+import {NgForm} from "@angular/forms";
+import {UserService} from "../../services/user-service/user.service";
+import {RankService} from "../../services/rank-service/rank.service";
+import {PromotionService} from "../../services/promotion-service/promotion.service";
+
+
+@Component({
+ templateUrl: './confirm-promotion.component.html',
+ styleUrls: ['./confirm-promotion.component.css'],
+})
+export class ConfirmPromotionComponent {
+
+ @ViewChild(NgForm) form: NgForm;
+
+ showForm = false;
+
+ showSuccessLabel = false;
+
+ user: User = {};
+
+ newLevel: number;
+
+ ranks: Rank[];
+
+ users: User[];
+
+ uncheckedPromotions = [];
+
+ constructor(private router: Router,
+ private route: ActivatedRoute,
+ private userService: UserService,
+ private rankService: RankService,
+ private promotionService: PromotionService) {
+ }
+
+ ngOnInit() {
+ let currentUser = JSON.parse(localStorage.getItem('currentUser'));
+ // show only current users squad members
+ this.userService.findUsers('', undefined, currentUser.squad._id).subscribe(users => {
+ this.users = users;
+ });
+ this.rankService.findRanks('', currentUser.squad.fraction).subscribe(ranks => {
+ this.ranks = ranks;
+ });
+ this.promotionService.getSquadPromotions(currentUser.squad._id).subscribe(promotions => {
+ this.uncheckedPromotions = promotions;
+ })
+
+ }
+
+ toggleUser() {
+ this.showForm = true;
+ this.newLevel = this.user.rank.level;
+ }
+
+
+ addPromotion() {
+ const promotion = {
+ "userId": this.user._id,
+ "oldRankLvl": this.user.rank.level,
+ "newRankLvl": this.newLevel,
+ };
+
+ this.promotionService.requestPromotion(promotion).subscribe();
+ this.showSuccessLabel = true;
+ setTimeout(() => {
+ this.showSuccessLabel = false;
+ }, 2000);
+ this.showForm = false;
+ this.user = {};
+
+ let currentUser = JSON.parse(localStorage.getItem('currentUser'));
+ this.promotionService.getSquadPromotions(currentUser.squad._id).subscribe(promotions => {
+ this.uncheckedPromotions = promotions;
+ })
+
+ }
+
+ cancel() {
+ this.router.navigate(['..'], {relativeTo: this.route});
+ return false;
+ }
+
+ /**
+ * compare ngValue with ngModel to assign selected element
+ */
+ equals(o1: User, o2: User) {
+ if (o1 && o2) {
+ return o1._id === o2._id;
+ }
+ }
+
+}
diff --git a/static/src/app/services/awarding-service/awarding.service.ts b/static/src/app/services/awarding-service/awarding.service.ts
index ece287e..a8e03f8 100644
--- a/static/src/app/services/awarding-service/awarding.service.ts
+++ b/static/src/app/services/awarding-service/awarding.service.ts
@@ -1,5 +1,5 @@
import {Injectable} from "@angular/core";
-import {User} from "../../models/model-interfaces";
+import {Award, User} from "../../models/model-interfaces";
import {Headers, Http} from "@angular/http";
import {Observable} from "rxjs/Observable";
import {AppConfig} from "../../app.config";
@@ -12,6 +12,11 @@ export class AwardingService {
private config: AppConfig) {
}
+ getUnconfirmedAwards(fraction?: string) {
+ return this.http.get(this.config.apiUrl + this.config.apiAwardPath + '?inProgress=true&fractFilter=' + fraction)
+ .map(res => res.json())
+ }
+
/**
* get awards array with populated decorations
*/
@@ -20,16 +25,21 @@ export class AwardingService {
.map(res => res.json())
}
- addAwarding(award) {
+ addAwarding(award: Award) {
return this.http.post(this.config.apiUrl + this.config.apiAwardPath, award)
}
- requestAwarding(award) {
+ updateAward(award) {
+ return this.http.patch(this.config.apiUrl + this.config.apiAwardPath + '/' + award._id, award)
+ .map(res => res.json())
+ }
+
+ requestAwarding(award: Award) {
return this.http.post(this.config.apiUrl + this.config.apiRequestAwardPath, award)
}
deleteAwarding(awardingId) {
- return this.http.delete(this.config.apiUrl + this.config.apiAwardPath + awardingId)
+ return this.http.delete(this.config.apiUrl + this.config.apiAwardPath + '/' + awardingId)
}
}