fabric8-planner
Version:
A planner front-end for Fabric8.
186 lines • 7.03 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
import { Injectable } from '@angular/core';
import { select, Store } from '@ngrx/store';
import { UserService } from 'ngx-login-client';
import { map, switchMap } from 'rxjs/operators';
import { Add as AddCommentAction, Get as GetCommentActions, Update as UpdateCommentAction } from './../actions/comment.actions';
import { cleanObject, modelService, switchModel } from './common.model';
import { UserQuery } from './user';
var Comment = /** @class */ (function (_super) {
__extends(Comment, _super);
function Comment() {
return _super !== null && _super.apply(this, arguments) || this;
}
return Comment;
}(modelService));
export { Comment };
var CommentLink = /** @class */ (function () {
function CommentLink() {
}
return CommentLink;
}());
export { CommentLink };
var CommentAttributes = /** @class */ (function () {
function CommentAttributes() {
}
return CommentAttributes;
}());
export { CommentAttributes };
var Comments = /** @class */ (function () {
function Comments() {
}
return Comments;
}());
export { Comments };
var RelationalData = /** @class */ (function () {
function RelationalData() {
}
return RelationalData;
}());
export { RelationalData };
var CommentMapper = /** @class */ (function () {
function CommentMapper() {
this.serviceToUiMapTree = [{
fromPath: ['id'],
toPath: ['id']
}, {
fromPath: ['attributes', 'body'],
toPath: ['body']
}, {
fromPath: ['attributes', 'markup'],
toPath: ['markup']
}, {
fromPath: ['attributes', 'created-at'],
toPath: ['createdAt']
}, {
fromPath: ['attributes', 'body.rendered'],
toPath: ['bodyRendered']
}, {
fromPath: ['relationships', 'creator', 'data', 'id'],
toPath: ['creatorId']
}, {
fromPath: ['links', 'self'],
toPath: ['selfLink']
}, {
fromPath: ['relationships', 'parent-comment', 'data', 'id'],
toPath: ['parentId']
}];
this.uiToServiceMapTree = [{
toPath: ['id'],
fromPath: ['id']
}, {
toPath: ['attributes', 'body'],
fromPath: ['body']
}, {
toPath: ['attributes', 'markup'],
toValue: 'Markdown'
}, {
toPath: ['attributes', 'created-at'],
fromPath: ['createdAt']
}, {
toPath: ['attributes', 'body.rendered'],
fromPath: ['bodyRendered']
}, {
toPath: ['type'],
toValue: 'comments'
}, {
toPath: ['links', 'self'],
fromPath: ['selfLink']
}, {
toPath: ['relationships', 'parent-comment', 'data', 'id'],
fromPath: ['parentId']
}, {
toPath: ['relationships', 'parent-comment', 'data', 'type'],
fromPath: ['parentId'],
toFunction: function (v) { return !!v ? 'comments' : null; }
}];
}
CommentMapper.prototype.toUIModel = function (arg) {
return switchModel(arg, this.serviceToUiMapTree);
};
CommentMapper.prototype.toServiceModel = function (arg) {
return cleanObject(switchModel(arg, this.uiToServiceMapTree));
};
return CommentMapper;
}());
export { CommentMapper };
var CommentQuery = /** @class */ (function () {
function CommentQuery(store, userQuery, userService) {
this.store = store;
this.userQuery = userQuery;
this.userService = userService;
this.commentSource = this.store.pipe(select(function (state) { return state.detailPage; }), select(function (state) { return state.comments; }));
}
CommentQuery.prototype.getComments = function (commentIds) {
// Not needed now
};
CommentQuery.prototype.getCommentsWithCreators = function () {
var _this = this;
return this.commentSource
.pipe(map(function (comments) {
return comments.map(function (comment) {
return __assign({}, comment, { creator: _this.userQuery.getUserObservableById(comment.creatorId) });
});
}), switchMap(function (comments) {
return _this.userService.loggedInUser
.pipe(map(function (user) { return user ? user : { id: '0' }; }), map(function (user) {
return comments.map(function (c) {
return __assign({}, c, { allowEdit: c.creatorId === user.id });
});
}));
}));
};
CommentQuery.prototype.getCommentsWithChildren = function () {
return this.getCommentsWithCreators()
.pipe(map(function (comments) {
return comments.map(function (comment) {
return __assign({}, comment, { children: comments.filter(function (c) { return c.parentId === comment.id; }) });
})
// keep only the root comments
.filter(function (comment) { return !comment.parentId; });
}));
};
CommentQuery.prototype.createComment = function (url, comment) {
var comMapper = new CommentMapper();
this.store.dispatch(new AddCommentAction({
comment: comMapper.toServiceModel(comment),
url: url
}));
};
CommentQuery.prototype.updateComment = function (comment) {
var comMapper = new CommentMapper();
this.store.dispatch(new UpdateCommentAction(comMapper.toServiceModel(comment)));
};
CommentQuery.prototype.dispatchGet = function (url) {
this.store.dispatch(new GetCommentActions(url));
};
CommentQuery.decorators = [
{ type: Injectable },
];
/** @nocollapse */
CommentQuery.ctorParameters = function () { return [
{ type: Store, },
{ type: UserQuery, },
{ type: UserService, },
]; };
return CommentQuery;
}());
export { CommentQuery };
//# sourceMappingURL=comment.js.map