my-test123
Version:
A planner front-end for Fabric8.
334 lines • 13.7 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 __());
};
})();
import { cloneDeep } from 'lodash';
import { WorkItemTypeMapper } from './work-item-type';
import { AreaMapper } from './area.model';
import { CommentMapper } from './comment';
import { IterationMapper } from './iteration.model';
import { LabelMapper } from './label.model';
import { UserMapper } from './user';
import { modelService, switchModel, cleanObject } from './common.model';
var WorkItem = /** @class */ (function (_super) {
__extends(WorkItem, _super);
function WorkItem() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.attributes = {};
return _this;
}
return WorkItem;
}(modelService));
export { WorkItem };
var WorkItemRelations = /** @class */ (function () {
function WorkItemRelations() {
}
return WorkItemRelations;
}());
export { WorkItemRelations };
var RelationalData = /** @class */ (function () {
function RelationalData() {
}
return RelationalData;
}());
export { RelationalData };
var LinkDict = /** @class */ (function () {
function LinkDict() {
}
return LinkDict;
}());
export { LinkDict };
var WorkItemMapper = /** @class */ (function () {
function WorkItemMapper() {
this.itMapper = new IterationMapper();
this.wiTypeMapper = new WorkItemTypeMapper();
this.areaMapper = new AreaMapper();
this.userMapper = new UserMapper();
this.labelMapper = new LabelMapper();
this.commentMapper = new CommentMapper(this.userMapper);
this.serviceToUiMapTree = [{
fromPath: ['id'],
toPath: ['id']
}, {
fromPath: ['attributes', 'system.title'],
toPath: ['title']
}, {
fromPath: ['attributes', 'system.number'],
toPath: ['number']
}, {
fromPath: ['attributes', 'system.order'],
toPath: ['order']
}, {
fromPath: ['attributes', 'system.created_at'],
toPath: ['createdAt']
}, {
fromPath: ['attributes', 'system.updated_at'],
toPath: ['updatedAt']
}, {
fromPath: ['attributes', 'system.state'],
toPath: ['state']
}, {
fromPath: ['attributes', 'system.description.markup'],
toPath: ['descriptionMarkup']
}, {
fromPath: ['attributes', 'system.description.rendered'],
toPath: ['descriptionRendered']
}, {
fromPath: ['attributes', 'system.description'],
toPath: ['description']
}, {
fromPath: ['attributes', 'version'],
toPath: ['version']
}, {
fromPath: ['links', 'self'],
toPath: ['link']
}, {
fromPath: ['relationships', 'workItemLinks', 'links', 'related'],
toPath: ['WILinkUrl']
}, {
fromPath: ['relationships', 'area', 'data'],
toPath: ['area'],
toFunction: this.areaMapper.toUIModel.bind(this.areaMapper)
}, {
fromPath: ['relationships', 'creator', 'data'],
toPath: ['creator'],
toFunction: this.userMapper.toUIModel.bind(this.userMapper)
}, {
fromPath: ['relationships', 'iteration', 'data'],
toPath: ['iteration'],
toFunction: this.itMapper.toUIModel.bind(this.itMapper)
}, {
fromPath: ['relationships', 'baseType', 'data'],
toPath: ['type'],
toFunction: this.wiTypeMapper.toUIModel.bind(this.wiTypeMapper)
}, {
fromPath: ['relationships', 'comments', 'links', 'related'],
toPath: ['commentLink']
}, {
fromPath: ['relationships', 'assignees', 'data'],
toPath: ['assignees'],
toFunction: function (assignees) {
var _this = this;
if (!assignees)
return [];
return assignees.map(function (assignee) { return _this.userMapper.toUIModel(assignee); });
}.bind(this)
}, {
fromPath: ['relationships', 'labels', 'data'],
toPath: ['labels'],
toFunction: function (labels) {
var _this = this;
if (!labels)
return [];
return labels.map(function (label) { return _this.labelMapper.toUIModel(label); });
}.bind(this)
}, {
toPath: ['children'],
toValue: []
}, {
fromPath: ['relationships', 'children', 'meta', 'hasChildren'],
toPath: ['hasChildren']
}, {
fromPath: ['relationships', 'parent', 'data', 'id'],
toPath: ['parentID']
}, {
fromPath: ['relationships', 'children', 'links', 'related'],
toPath: ['childrenLink']
}, {
fromPath: ['relationships', 'children', 'meta', 'hasChildren'],
toPath: ['treeStatus'],
toFunction: function (hasChildren) {
if (!hasChildren) {
return 'disabled';
}
else {
return 'collapsed';
}
}
}, {
toPath: ['childrenLoaded'],
toValue: false
}, {
toPath: ['bold'],
toValue: false
},
];
this.uiToServiceMapTree = [{
toPath: ['id'],
fromPath: ['id']
}, {
fromPath: ['title'],
toPath: ['attributes', 'system.title']
}, {
fromPath: ['number'],
toPath: ['attributes', 'system.number']
}, {
fromPath: ['order'],
toPath: ['attributes', 'system.order']
}, {
fromPath: ['createdAt'],
toPath: ['attributes', 'system.created_at']
}, {
fromPath: ['updatedAt'],
toPath: ['attributes', 'system.updated_at']
}, {
fromPath: ['state'],
toPath: ['attributes', 'system.state'],
}, {
toPath: ['attributes', 'system.description.markup'],
toValue: 'Markdown'
}, {
fromPath: ['descriptionRendered'],
toPath: ['attributes', 'system.description.rendered'],
}, {
fromPath: ['description'],
toPath: ['attributes', 'system.description'],
}, {
fromPath: ['version'],
toPath: ['attributes', 'version']
}, {
fromPath: ['link'],
toPath: ['links', 'self']
}, {
fromPath: ['WILinkUrl'],
toPath: ['relationships', 'workItemLinks', 'links', 'related']
}, {
fromPath: ['area'],
toPath: ['relationships', 'area', 'data'],
toFunction: this.areaMapper.toServiceModel.bind(this.areaMapper)
}, {
fromPath: ['creator'],
toPath: ['relationships', 'creator', 'data'],
toFunction: this.userMapper.toServiceModel.bind(this.userMapper)
}, {
fromPath: ['iteration'],
toPath: ['relationships', 'iteration', 'data'],
toFunction: this.itMapper.toServiceModel.bind(this.itMapper)
}, {
fromPath: ['type'],
toPath: ['relationships', 'baseType', 'data'],
toFunction: this.wiTypeMapper.toServiceModel.bind(this.wiTypeMapper)
}, {
fromPath: ['commentLink'],
toPath: ['relationships', 'comments', 'links', 'related']
}, {
fromPath: ['assignees'],
toPath: ['relationships', 'assignees', 'data'],
toFunction: function (assignees) {
var _this = this;
if (!assignees)
return null;
return assignees.map(function (assignee) { return _this.userMapper.toServiceModel(assignee); });
}.bind(this)
}, {
fromPath: ['labels'],
toPath: ['relationships', 'labels', 'data'],
toFunction: function (labels) {
var _this = this;
if (!labels)
return null;
return labels.map(function (label) { return _this.labelMapper.toServiceModel(label); });
}.bind(this)
}, {
fromPath: ['hasChildren'],
toPath: ['relationships', 'children', 'meta', 'hasChildren']
}, {
fromPath: ['parentID'],
toPath: ['relationships', 'parent', 'data', 'id'],
}, {
fromPath: ['childrenLink'],
toPath: ['relationships', 'children', 'links', 'related'],
}, {
toPath: ['type'],
toValue: 'workitems'
}
];
}
WorkItemMapper.prototype.toUIModel = function (arg) {
return switchModel(arg, this.serviceToUiMapTree);
};
WorkItemMapper.prototype.toServiceModel = function (arg) {
var serviceModel = switchModel(arg, this.uiToServiceMapTree);
// Removing relationship part of iteration
if (serviceModel.relationships.iteration.data !== null) {
serviceModel.relationships.iteration.data =
cleanObject(serviceModel.relationships.iteration.data, ['relationships']);
}
// Removing attributes from assignees
if (serviceModel.relationships.assignees.data !== null) {
serviceModel.relationships.assignees.data =
serviceModel.relationships.assignees.data.map(function (a) {
return cleanObject(a, ['attributes']);
});
}
// Removing relationship part of baseType
if (serviceModel.relationships.baseType.data !== null) {
serviceModel.relationships.baseType.data =
cleanObject(serviceModel.relationships.baseType.data, ['relationships']);
}
return cleanObject(serviceModel);
};
WorkItemMapper.prototype.cleanModel = function (arg, keysToRemove) {
if (keysToRemove === void 0) { keysToRemove = []; }
return cleanObject(arg, keysToRemove);
};
return WorkItemMapper;
}());
export { WorkItemMapper };
var WorkItemResolver = /** @class */ (function () {
function WorkItemResolver(workItem) {
this.workItem = workItem;
}
WorkItemResolver.prototype.resolveArea = function (areas) {
var _this = this;
var area = areas.find(function (a) { return a.id === _this.workItem.area.id; });
if (area) {
this.workItem.area = cloneDeep(area);
}
};
WorkItemResolver.prototype.resolveIteration = function (iterations) {
var _this = this;
var iteration = iterations.find(function (it) { return it.id === _this.workItem.iteration.id; });
if (iteration) {
this.workItem.iteration = cloneDeep(iteration);
// We don't need this much value for a work item
this.workItem.iteration.children = [];
}
};
WorkItemResolver.prototype.resolveAssignees = function (users) {
this.workItem.assignees = this.workItem.assignees.map(function (assignee) {
return cloneDeep(users.find(function (u) { return u.id === assignee.id; }));
}).filter(function (item) { return !!item; });
};
WorkItemResolver.prototype.resolveCreator = function (users) {
var _this = this;
var creator = users.find(function (user) { return user.id === _this.workItem.creator.id; });
if (creator) {
this.workItem.creator = cloneDeep(creator);
}
};
WorkItemResolver.prototype.resolveType = function (types) {
var _this = this;
var type = types.find(function (t) { return t.id === _this.workItem.type.id; });
if (type) {
this.workItem.type = cloneDeep(type);
}
};
WorkItemResolver.prototype.resolveWiLabels = function (labels) {
this.workItem.labels = this.workItem.labels.map(function (label) {
return cloneDeep(labels.find(function (l) { return l.id === label.id; }));
}).filter(function (item) { return !!item; });
};
WorkItemResolver.prototype.getWorkItem = function () {
return this.workItem;
};
return WorkItemResolver;
}());
export { WorkItemResolver };
//# sourceMappingURL=work-item.js.map