fabric8-planner
Version:
A planner front-end for Fabric8.
89 lines • 4.77 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Observable } from 'rxjs';
import { catchError, map, switchMap } from 'rxjs/operators';
import * as CommentActions from './../actions/comment.actions';
import { CommentMapper } from './../models/comment';
import { WorkItemService } from './../services/work-item.service';
import { ErrorHandler } from './work-item-utils';
var CommentEffects = /** @class */ (function () {
function CommentEffects(actions$, workItemService, errHandler) {
var _this = this;
this.actions$ = actions$;
this.workItemService = workItemService;
this.errHandler = errHandler;
this.commentMapper = new CommentMapper();
this.getWorkItemComments$ = this.actions$
.pipe(ofType(CommentActions.GET), switchMap(function (action) {
var payload = action.payload;
return _this.workItemService.resolveComments(payload)
.pipe(map(function (comments) {
return comments.data.map(function (comment) {
return _this.commentMapper.toUIModel(comment);
});
}), map(function (comments) {
return new CommentActions.GetSuccess(comments);
}), catchError(function (err) { return _this.errHandler.handleError(err, "Problem in fetching Comments.", new CommentActions.GetError()); }));
}));
this.addComment$ = this.actions$
.pipe(ofType(CommentActions.ADD), switchMap(function (data) {
return _this.workItemService.createComment(data.payload.url, data.payload.comment)
.pipe(map(function (comment) {
return new CommentActions.AddSuccess(_this.commentMapper.toUIModel(comment));
}), catchError(function (err) { return _this.errHandler.handleError(err, "Problem in add comment.", new CommentActions.AddError()); }));
}));
this.updateComment$ = this.actions$
.pipe(ofType(CommentActions.UPDATE), switchMap(function (action) {
var comment = action.payload;
return _this.workItemService.updateComment(comment)
.pipe(map(function (comment) {
return new CommentActions.UpdateSuccess(_this.commentMapper.toUIModel(comment));
}), catchError(function (err) { return _this.errHandler.handleError(err, "Problem in Update comment.", new CommentActions.UpdateError()); }));
}));
this.deleteComment$ = this.actions$
.pipe(ofType(CommentActions.DELETE), map(function (action) { return action.payload; }), switchMap(function (payload) {
var comment = _this.commentMapper.toServiceModel(payload);
return _this.workItemService.deleteComment(comment)
.pipe(map(function () {
return new CommentActions.DeleteSuccess(payload);
}), catchError(function (err) { return _this.errHandler.handleError(err, "Problem in Delete comment.", new CommentActions.DeleteError()); }));
}));
}
CommentEffects.decorators = [
{ type: Injectable },
];
/** @nocollapse */
CommentEffects.ctorParameters = function () { return [
{ type: Actions, },
{ type: WorkItemService, },
{ type: ErrorHandler, },
]; };
__decorate([
Effect(),
__metadata("design:type", Observable)
], CommentEffects.prototype, "getWorkItemComments$", void 0);
__decorate([
Effect(),
__metadata("design:type", Observable)
], CommentEffects.prototype, "addComment$", void 0);
__decorate([
Effect(),
__metadata("design:type", Observable)
], CommentEffects.prototype, "updateComment$", void 0);
__decorate([
Effect(),
__metadata("design:type", Observable)
], CommentEffects.prototype, "deleteComment$", void 0);
return CommentEffects;
}());
export { CommentEffects };
//# sourceMappingURL=comment.effects.js.map