my-test123
Version:
A planner front-end for Fabric8.
191 lines • 8.36 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 { Store } from '@ngrx/store';
import { Actions, Effect } from '@ngrx/effects';
import { Injectable } from '@angular/core';
import * as CommentActions from './../actions/comment.actions';
import { Observable } from 'rxjs';
import { WorkItemService } from './../services/work-item.service';
import { CommentMapper, CommentCreatorResolver } from './../models/comment';
import { Notifications, NotificationType } from "ngx-base";
import { UserMapper } from './../models/user';
var CommentEffects = /** @class */ (function () {
function CommentEffects(actions$, workItemService, store, userMapper, notifications) {
var _this = this;
this.actions$ = actions$;
this.workItemService = workItemService;
this.store = store;
this.userMapper = userMapper;
this.notifications = notifications;
this.getWorkItemComments$ = this.actions$
.ofType(CommentActions.GET)
.withLatestFrom(this.store.select('listPage').select('collaborators'))
.map(function (_a) {
var action = _a[0], collaborators = _a[1];
return {
payload: action.payload,
collaborators: collaborators
};
})
.switchMap(function (cp) {
var payload = cp.payload;
var collaborators = cp.collaborators;
return _this.workItemService.resolveComments(payload)
.map(function (comments) {
return comments.data.map(function (comment) {
var cMapper = new CommentMapper(_this.userMapper);
var commentUI = cMapper.toUIModel(comment);
var creatorResolver = new CommentCreatorResolver(commentUI);
creatorResolver.resolveCreator(collaborators);
return creatorResolver.getComment();
});
})
.map(function (comments) {
return new CommentActions.GetSuccess(comments);
})
.catch(function (e) {
try {
_this.notifications.message({
message: "Problem in fetching Comments.",
type: NotificationType.DANGER
});
}
catch (e) {
console.log('Problem in fetching Comments.');
}
return Observable.of(new CommentActions.GetError());
});
});
this.addComment$ = this.actions$
.ofType(CommentActions.ADD)
.withLatestFrom(this.store.select('listPage').select('collaborators'))
.map(function (_a) {
var action = _a[0], collaborators = _a[1];
return {
payload: action.payload,
collaborators: collaborators
};
})
.switchMap(function (cp) {
var payload = cp.payload;
var collaborators = cp.collaborators;
return _this.workItemService.createComment(payload.url, payload.comment)
.map(function (comment) {
var cMapper = new CommentMapper(_this.userMapper);
var commentUI = cMapper.toUIModel(comment);
var creatorResolver = new CommentCreatorResolver(commentUI);
creatorResolver.resolveCreator(collaborators);
return new CommentActions.AddSuccess(creatorResolver.getComment());
})
.catch(function (e) {
try {
_this.notifications.message({
message: "Problem in add comment.",
type: NotificationType.DANGER
});
}
catch (e) {
console.log('Problem in add comment.');
}
return Observable.of(new CommentActions.AddError());
});
});
this.updateComment$ = this.actions$
.ofType(CommentActions.UPDATE)
.withLatestFrom(this.store.select('listPage').select('collaborators'))
.map(function (_a) {
var action = _a[0], collaborators = _a[1];
return {
payload: action.payload,
collaborators: collaborators
};
})
.switchMap(function (cp) {
var payload = cp.payload;
var collaborators = cp.collaborators;
var cMapper = new CommentMapper(_this.userMapper);
var comment = cMapper.toServiceModel(payload);
return _this.workItemService.updateComment(comment)
.map(function (comment) {
var cMapper = new CommentMapper(_this.userMapper);
var commentUI = cMapper.toUIModel(comment);
var creatorResolver = new CommentCreatorResolver(commentUI);
creatorResolver.resolveCreator(collaborators);
return new CommentActions.UpdateSuccess(creatorResolver.getComment());
})
.catch(function (e) {
try {
_this.notifications.message({
message: "Problem in update comment.",
type: NotificationType.DANGER
});
}
catch (e) {
console.log('Problem in update comment.');
}
return Observable.of(new CommentActions.UpdateError());
});
});
this.deleteComment$ = this.actions$
.ofType(CommentActions.DELETE)
.map(function (action) { return action.payload; })
.switchMap(function (payload) {
var cMapper = new CommentMapper(_this.userMapper);
var comment = cMapper.toServiceModel(payload);
return _this.workItemService.deleteComment(comment)
.map(function () {
var cMapper = new CommentMapper(_this.userMapper);
return new CommentActions.DeleteSuccess(payload);
})
.catch(function (e) {
try {
_this.notifications.message({
message: "Problem in delete comment.",
type: NotificationType.DANGER
});
}
catch (e) {
console.log('Problem in delete comment.');
}
return Observable.of(new CommentActions.DeleteError());
});
});
}
CommentEffects.decorators = [
{ type: Injectable },
];
/** @nocollapse */
CommentEffects.ctorParameters = function () { return [
{ type: Actions, },
{ type: WorkItemService, },
{ type: Store, },
{ type: UserMapper, },
{ type: Notifications, },
]; };
__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