fabric8-planner
Version:
A planner front-end for Fabric8.
175 lines • 7.51 kB
JavaScript
import { combineLatest } from 'rxjs';
import { filter } from 'rxjs/operators';
import { Component, Input } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Spaces } from 'ngx-fabric8-wit';
import { AuthenticationService } from 'ngx-login-client';
import { GroupTypeQuery } from '../../models/group-types.model';
import { FilterService } from '../../services/filter.service';
import { AND, EQUAL } from '../../services/query-keys';
// ngrx stuff
import { select, Store } from '@ngrx/store';
import { SpaceQuery } from '../../models/space';
import * as GroupTypeActions from './../../actions/group-type.actions';
var GroupTypesComponent = /** @class */ (function () {
function GroupTypesComponent(auth, filterService, groupTypeQuery, spaceQuery, route, router, spaces, store) {
this.auth = auth;
this.filterService = filterService;
this.groupTypeQuery = groupTypeQuery;
this.spaceQuery = spaceQuery;
this.route = route;
this.router = router;
this.spaces = spaces;
this.store = store;
this.sidePanelOpen = true;
this.authUser = null;
this.infotipSource = this.store
.pipe(select('planner'), select('infotips'));
this.eventListeners = [];
this.startedCheckingURL = false;
this.showTree = '';
this.showCompleted = '';
}
GroupTypesComponent.prototype.ngOnInit = function () {
var _this = this;
var groupTypesData = this.groupTypeQuery.getGroupTypes;
var spaceData = this.spaceQuery.getCurrentSpace.pipe(filter(function (space) { return space !== null; }));
this.eventListeners.push(combineLatest(groupTypesData, spaceData)
.subscribe(function (_a) {
var types = _a[0], space = _a[1];
_this.groupTypes = types;
if (!_this.startedCheckingURL) {
_this.checkURL();
}
}));
};
GroupTypesComponent.prototype.ngOnDestroy = function () {
this.eventListeners.forEach(function (e) { return e.unsubscribe(); });
};
GroupTypesComponent.prototype.fnBuildQueryParam = function (witGroup) {
//Query for work item type group
var type_query = this.filterService.queryBuilder('typegroup.name', EQUAL, witGroup.name);
var first_join = this.filterService.queryJoiner({}, AND, type_query);
//second_join gives json object
return this.filterService.jsonToQuery(first_join);
//reverse function jsonToQuery(second_join);
};
GroupTypesComponent.prototype.fnBuildQueryParamForBoard = function (witGroup) {
var type_query = this.filterService.queryBuilder('boardContextId', EQUAL, witGroup.id);
// join query with typeQuery
var second_join = this.filterService.queryJoiner({}, AND, type_query);
return this.filterService.jsonToQuery(second_join);
};
GroupTypesComponent.prototype.addRemoveQueryParams = function (witGroup) {
// If it's a board view then quoery should only have the board id
if (this.context === 'board') {
return { q: this.fnBuildQueryParamForBoard(witGroup) };
}
// For list view it works differently
if (this.showCompleted && this.showTree) {
return {
q: this.fnBuildQueryParam(witGroup),
showTree: this.showTree,
showCompleted: this.showCompleted
};
}
else if (this.showTree) {
return {
q: this.fnBuildQueryParam(witGroup),
showTree: this.showTree
};
}
else if (this.showCompleted) {
return {
q: this.fnBuildQueryParam(witGroup),
showCompleted: this.showCompleted
};
}
else {
return {
q: this.fnBuildQueryParam(witGroup)
};
}
};
GroupTypesComponent.prototype.checkURL = function () {
var _this = this;
this.startedCheckingURL = true;
this.eventListeners.push(this.route.queryParams.subscribe(function (val) {
if (val.hasOwnProperty('q')) {
var selectedTypeGroup = void 0;
if (val['q'].includes('boardContextId')) {
//filter service getConditionFromQuery returns undefined for non AND operations
var selectedTypeGroupId_1 = _this.filterService.getConditionFromQuery(val.q, 'boardContextId');
if (selectedTypeGroupId_1 === undefined) {
selectedTypeGroupId_1 = _this.filterService.queryToFlat(val.q)[0].value;
}
if (selectedTypeGroupId_1) {
selectedTypeGroup =
_this.groupTypes.find(function (g) { return g.id === selectedTypeGroupId_1; });
}
}
else {
var selectedTypeGroupName_1 = _this.filterService.getConditionFromQuery(val.q, 'typegroup.name');
if (selectedTypeGroupName_1) {
selectedTypeGroup =
_this.groupTypes.find(function (g) { return g.name === selectedTypeGroupName_1; });
}
}
if (selectedTypeGroup && !selectedTypeGroup.selected) {
_this.store.dispatch(new GroupTypeActions.SelectType(selectedTypeGroup));
}
}
if (val.hasOwnProperty('showTree')) {
_this.showTree = val.showTree;
}
else {
_this.showTree = '';
}
if (val.hasOwnProperty('showCompleted')) {
_this.showCompleted = val.showCompleted;
}
else {
_this.showCompleted = '';
}
}));
};
GroupTypesComponent.prototype.getInfotipText = function (id) {
return this.infotipSource
.pipe(select(function (s) { return s[id]; }), select(function (i) { return i ? i['en'] : id; }));
};
//This function navigates to the desired work item group type page
GroupTypesComponent.prototype.groupTypeClickHandler = function (e, item) {
if (!e.srcElement.classList.contains('infotip-icon')) {
var q = this.addRemoveQueryParams(item);
this.router.navigate([], {
relativeTo: this.route,
queryParams: q
});
}
};
GroupTypesComponent.decorators = [
{ type: Component, args: [{
selector: 'group-types',
template: require('./group-types-panel.component.html'),
styles: [require('./group-types-panel.component.css').toString()]
},] },
];
/** @nocollapse */
GroupTypesComponent.ctorParameters = function () { return [
{ type: AuthenticationService, },
{ type: FilterService, },
{ type: GroupTypeQuery, },
{ type: SpaceQuery, },
{ type: ActivatedRoute, },
{ type: Router, },
{ type: Spaces, },
{ type: Store, },
]; };
GroupTypesComponent.propDecorators = {
'sidePanelOpen': [{ type: Input },],
'context': [{ type: Input },],
};
return GroupTypesComponent;
}());
export { GroupTypesComponent };
//# sourceMappingURL=group-types-panel.component.js.map