fabric8-planner
Version:
A planner front-end for Fabric8.
205 lines • 8.29 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 { Injectable } from '@angular/core';
import { createEntityAdapter } from '@ngrx/entity';
// MemoizedSelector is needed even if it's not being used in this file
// Else you get this error
// Exported variable 'workItemSelector' has or is using name 'MemoizedSelector'
// from external module "@ngrx/store/src/selector" but cannot be named.
import { createSelector, select, Store } from '@ngrx/store';
import { filter, map } from 'rxjs/operators';
import { modelService, normalizeArray, switchModel } from './common.model';
import { plannerSelector } from './space';
var WorkItemType = /** @class */ (function (_super) {
__extends(WorkItemType, _super);
function WorkItemType() {
return _super !== null && _super.apply(this, arguments) || this;
}
return WorkItemType;
}(modelService));
export { WorkItemType };
var WorkItemTypeField = /** @class */ (function () {
function WorkItemTypeField() {
}
return WorkItemTypeField;
}());
export { WorkItemTypeField };
var WorkItemTypeMapper = /** @class */ (function () {
function WorkItemTypeMapper() {
this.serviceToUiMapTree = [{
fromPath: ['id'],
toPath: ['id']
}, {
fromPath: ['attributes', 'name'],
toPath: ['name']
}, {
fromPath: ['attributes', 'icon'],
toPath: ['icon']
}, {
fromPath: ['attributes', 'version'],
toPath: ['version']
}, {
fromPath: ['relationships', 'guidedChildTypes', 'data'],
toPath: ['childTypes'],
toFunction: function (item) {
return !!item ? item : [];
}
}, {
fromPath: ['attributes', 'fields'],
toPath: ['fields']
}, {
fromPath: ['attributes', 'fields'],
toPath: ['dynamicfields'],
toFunction: filterDynamicFields
}, {
toPath: ['type'],
toValue: 'workitemtypes'
}, {
fromPath: ['attributes', 'description'],
toPath: ['description'],
toFunction: function (value) { return value || 'no info-tip'; }
}];
this.uiToServiceMapTree = [{
toPath: ['id'],
fromPath: ['id']
}, {
toPath: ['attributes', 'name'],
fromPath: ['name']
}, {
toPath: ['attributes', 'icon'],
fromPath: ['icon']
}, {
toPath: ['attributes', 'version'],
fromPath: ['version']
}, {
toPath: ['type'],
toValue: 'workitemtypes'
}, {
fromPath: ['childTypes'],
toPath: ['relationships', 'guidedChildTypes', 'data'],
toFunction: function (item) {
return !!item ? item : [];
}
}, {
toPath: ['attributes', 'fields'],
fromPath: ['fields']
}
];
}
WorkItemTypeMapper.prototype.toUIModel = function (arg) {
return switchModel(arg, this.serviceToUiMapTree);
};
WorkItemTypeMapper.prototype.toServiceModel = function (arg) {
return switchModel(arg, this.uiToServiceMapTree);
};
return WorkItemTypeMapper;
}());
export { WorkItemTypeMapper };
var WorkItemTypeResolver = /** @class */ (function () {
function WorkItemTypeResolver(allTypes) {
if (allTypes === void 0) { allTypes = []; }
this.allTypes = allTypes;
this.normalizedTypes = normalizeArray(allTypes);
}
WorkItemTypeResolver.prototype.resolveChildren = function () {
var _this = this;
this.allTypes.forEach(function (type) {
type.childTypes = type.childTypes.map(function (ct) { return _this.normalizedTypes[ct.id]; });
});
};
WorkItemTypeResolver.prototype.getResolvedWorkItemTypes = function () {
return this.allTypes;
};
return WorkItemTypeResolver;
}());
export { WorkItemTypeResolver };
function filterDynamicFields(fields) {
if (fields !== null) {
var fieldKeys = Object.keys(fields);
// These fields won't show up in the details page
var staticFields_1 = [
'system.area',
'system.assignees',
'system.codebase',
'system.created_at',
'system.creator',
'system.description',
'system.iteration',
'system.labels',
'system.number',
'system.order',
'system.remote_item_id',
'system.state',
'system.title',
'system.updated_at',
'system.metastate'
];
// These fields types won't show up in the details page
var restrictedFieldTypes_1 = [
'float', 'string', 'integer', 'enum', 'markup'
];
return fieldKeys.filter(function (f) {
return staticFields_1.findIndex(function (sf) { return sf === f; }) === -1 &&
restrictedFieldTypes_1.indexOf(fields[f].type.kind) > -1;
});
}
else {
return [];
}
}
var workItemTypeAdapter = createEntityAdapter();
// Do not export it
var _a = workItemTypeAdapter.getSelectors(), selectIds = _a.selectIds, selectEntities = _a.selectEntities, selectAll = _a.selectAll, selectTotal = _a.selectTotal;
export var workItemTypeSelector = createSelector(plannerSelector, function (state) { return state ? state.workItemTypes : { ids: [], entities: {} }; });
// Do not export it
var getWorkItemTypeEntitiesSelector = createSelector(workItemTypeSelector, selectEntities);
var WorkItemTypeQuery = /** @class */ (function () {
function WorkItemTypeQuery(store) {
this.store = store;
this.getAllWorkItemTypesSelector = createSelector(workItemTypeSelector, selectAll);
this.getWorkItemTypesWithChildrenSelector = createSelector(this.getAllWorkItemTypesSelector, getWorkItemTypeEntitiesSelector, function (types, typeEntities) {
return types.map(function (type) {
var childTypes = type.childTypes.map(function (t) { return typeEntities[t.id]; });
type.childTypes = childTypes;
return type;
});
});
this.workItemTypeSource = this.store.pipe(select(this.getAllWorkItemTypesSelector));
}
/**
* return observable of all workItemTypes
* without their child types
*/
WorkItemTypeQuery.prototype.getWorkItemTypes = function () {
return this.workItemTypeSource.pipe(filter(function (w) { return !!w.length; }));
};
WorkItemTypeQuery.prototype.getWorkItemTypesWithChildren = function () {
return this.store.pipe(select(this.getWorkItemTypesWithChildrenSelector), filter(function (t) { return !!t.length; }));
};
WorkItemTypeQuery.prototype.getWorkItemTypeWithChildrenById = function (id) {
return this.store.pipe(select(this.getWorkItemTypesWithChildrenSelector), map(function (types) {
return types.filter(function (type) { return type.id === id; })[0];
}));
};
WorkItemTypeQuery.prototype.getWorkItemTypeById = function (id) {
return this.store.pipe(select(getWorkItemTypeEntitiesSelector), map(function (wt) { return wt[id]; }));
};
WorkItemTypeQuery.decorators = [
{ type: Injectable },
];
/** @nocollapse */
WorkItemTypeQuery.ctorParameters = function () { return [
{ type: Store, },
]; };
return WorkItemTypeQuery;
}());
export { WorkItemTypeQuery };
//# sourceMappingURL=work-item-type.js.map