UNPKG

fabric8-planner

Version:
147 lines 5.71 kB
import { Component, Input } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { Spaces } from 'ngx-fabric8-wit'; import { AuthenticationService } from 'ngx-login-client'; import { FilterService } from '../../services/filter.service'; import { ModalService } from '../../services/modal.service'; // ngrx stuff import { select, Store } from '@ngrx/store'; import { first } from 'rxjs/operators'; import * as CustomQueryActions from './../../actions/custom-query.actions'; var CustomQueryComponent = /** @class */ (function () { function CustomQueryComponent(auth, filterService, modalService, route, spaces, store) { this.auth = auth; this.filterService = filterService; this.modalService = modalService; this.route = route; this.spaces = spaces; this.store = store; this.sidePanelOpen = true; this.authUser = null; this.eventListeners = []; this.customQueries = []; this.startedCheckingURL = false; this.showTree = ''; this.showCompleted = ''; } CustomQueryComponent.prototype.ngOnInit = function () { var _this = this; var customQueriesData = this.store .pipe(select('planner'), select('customQueries')); this.eventListeners.push(customQueriesData .subscribe(function (customQueries) { _this.customQueries = customQueries; if (!_this.startedCheckingURL && !!_this.customQueries.length) { _this.checkURL(); } })); }; CustomQueryComponent.prototype.ngOnDestroy = function () { this.eventListeners.forEach(function (e) { return e.unsubscribe(); }); }; CustomQueryComponent.prototype.constructUrl = function (attributes) { var jsonAttributes = JSON.parse(attributes); var jsonQuery = this.filterService.jsonToQuery(jsonAttributes); return jsonQuery; }; CustomQueryComponent.prototype.checkURL = function () { var _this = this; this.startedCheckingURL = true; this.eventListeners.push(this.route.queryParams.subscribe(function (val) { if (val.hasOwnProperty('q')) { var urlQuery_1 = val['q']; var foundMatch_1 = false; _this.customQueries.forEach(function (q) { if (_this.constructUrl(q.attributes.fields) === urlQuery_1) { foundMatch_1 = true; _this.store.dispatch(new CustomQueryActions.Select(q)); } }); if (!foundMatch_1) { _this.store.dispatch(new CustomQueryActions.SelectNone()); } } if (val.hasOwnProperty('showTree')) { _this.showTree = val.showTree; } else { _this.showTree = ''; } if (val.hasOwnProperty('showCompleted')) { _this.showCompleted = val.showCompleted; } else { _this.showCompleted = ''; } })); }; CustomQueryComponent.prototype.addRemoveQueryParams = function (queryField) { if (this.showCompleted && this.showTree) { return { q: this.constructUrl(queryField), showTree: this.showTree, showCompleted: this.showCompleted }; } else if (this.showTree) { return { q: this.constructUrl(queryField), showTree: this.showTree }; } else if (this.showCompleted) { return { q: this.constructUrl(queryField), showCompleted: this.showCompleted }; } else { return { q: this.constructUrl(queryField) }; } }; CustomQueryComponent.prototype.getRouterLink = function () { return this.context === 'board' ? ['..'] : []; }; CustomQueryComponent.prototype.stopPropagation = function (event) { event.stopPropagation(); }; CustomQueryComponent.prototype.confirmCustomQueryDelete = function (event, customQuery) { var _this = this; // this.stopPropagation(event); this.modalService.openModal('Delete Filter', 'Are you sure you want to delete this filter?', 'Delete', 'deleteFilter') .pipe(first()) .subscribe(function (actionKey) { if (actionKey === 'deleteFilter') { _this.deleteCustomQuery(customQuery); } }); }; CustomQueryComponent.prototype.deleteCustomQuery = function (customQuery) { this.store.dispatch(new CustomQueryActions.Delete(customQuery)); }; CustomQueryComponent.decorators = [ { type: Component, args: [{ selector: 'custom-query', template: require('./custom-query-panel.component.html'), styles: [require('./custom-query-panel.component.css').toString()] },] }, ]; /** @nocollapse */ CustomQueryComponent.ctorParameters = function () { return [ { type: AuthenticationService, }, { type: FilterService, }, { type: ModalService, }, { type: ActivatedRoute, }, { type: Spaces, }, { type: Store, }, ]; }; CustomQueryComponent.propDecorators = { 'sidePanelOpen': [{ type: Input },], 'context': [{ type: Input },], }; return CustomQueryComponent; }()); export { CustomQueryComponent }; //# sourceMappingURL=custom-query-panel.component.js.map