UNPKG

fabric8-planner

Version:
185 lines 8.25 kB
import { animate, state, style, transition, trigger } from '@angular/animations'; import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; import { map, switchMap, tap } from 'rxjs/operators'; import { WorkItemLinkQuery } from '../../models/link'; import { WorkItemLinkTypeQuery } from './../../models/link-type'; import { WorkItemService } from '../../services/work-item.service'; //ngrx stuff import { Store } from '@ngrx/store'; import * as WorkItemLinkActions from './../../actions/work-item-link.actions'; import { SpaceQuery } from './../../models/space'; var WorkItemLinkComponent = /** @class */ (function () { function WorkItemLinkComponent(store, workItemService, linkTypeQuery, workItemLinkQuery, spaceQuery) { var _this = this; this.store = store; this.workItemService = workItemService; this.linkTypeQuery = linkTypeQuery; this.workItemLinkQuery = workItemLinkQuery; this.spaceQuery = spaceQuery; this.context = 'list'; this.onLinkClick = new EventEmitter(); // This is needed to check if workItem was changed // Because even during the update input comes through this.workItem = null; this.selectedWorkItem = null; this.selectedLinkType = null; // These are being used in the template this.linkTypesSource = this.linkTypeQuery.getLinkTypesForDropdown .pipe(tap(function (types) { return _this.selectedLinkType = types[0]; })); // Setting up the default link type this.workItemLinksSource = this.workItemLinkQuery.getWorkItemLinks .pipe(tap(function (links) { // Reset the create environment _this.selectedWorkItem = null; _this.lockCreation = false; // to remove the highlight from newly added item if (links && links.findIndex(function (l) { return l.newlyAdded; }) > -1) { setTimeout(function () { _this.store.dispatch(new WorkItemLinkActions.TrivializeAll()); }, 3000); } })); this.workItemLinksCountSource = this.workItemLinkQuery.getWorkItemLinksCount; this.showLinkComponent = false; this.lockCreation = false; // This holds the work item ids not allowed to be in search result this.searchNotAllowedIds = []; } Object.defineProperty(WorkItemLinkComponent.prototype, "workItemSetter", { set: function (workItem) { if (this.workItem === null || this.workItem.id !== workItem.id) { this.workItem = workItem; this.store.dispatch(new WorkItemLinkActions.Get(this.workItem.link + '/relationships/links')); // Reset links value for the new work item first this.store.dispatch(new WorkItemLinkActions.ResetLinks()); this.searchNotAllowedIds = []; this.setSearchNotAllowedIds(); } }, enumerable: true, configurable: true }); WorkItemLinkComponent.prototype.ngOnDestroy = function () { this.store.dispatch(new WorkItemLinkActions.ResetLinks()); }; WorkItemLinkComponent.prototype.ngOnInit = function () { }; WorkItemLinkComponent.prototype.setSearchNotAllowedIds = function () { this.searchNotAllowedIds.push(this.workItem.id); }; WorkItemLinkComponent.prototype.onSelectRelation = function (selectedLinkTypes) { this.selectedLinkType = selectedLinkTypes[0]; }; WorkItemLinkComponent.prototype.onSelectWorkItem = function (event) { if (Array.isArray(event) && event.length > 0) { this.selectedWorkItem = event[0]; } else { this.selectedWorkItem = null; } }; WorkItemLinkComponent.prototype.createLink = function (event) { if (this.selectedLinkType && this.selectedWorkItem && !this.lockCreation) { this.lockCreation = true; var linkPayload = this.createLinkObject(this.workItem.id, this.selectedWorkItem.key, this.selectedLinkType.id, this.selectedLinkType.linkType); this.store.dispatch(new WorkItemLinkActions.Add(linkPayload)); } }; WorkItemLinkComponent.prototype.deleteLink = function (event, wiLink, workItem) { this.store.dispatch(new WorkItemLinkActions.Delete({ wiLink: wiLink, workItemId: workItem.id })); }; WorkItemLinkComponent.prototype.onLinkClicked = function (wiNumber) { this.onLinkClick.emit({ number: wiNumber }); }; WorkItemLinkComponent.prototype.searchWorkItem = function (term) { var _this = this; return this.spaceQuery.getCurrentSpace.pipe(switchMap(function (space) { return _this.workItemService.searchLinkWorkItem(term, space.id) .pipe(map(function (items) { return items .filter(function (item) { return _this.searchNotAllowedIds.indexOf(item.id) == -1; }) .map(function (item) { return { key: item.id, value: item.attributes['system.number'] + " - " + item.attributes['system.title'], selected: false }; }); })); })); }; WorkItemLinkComponent.prototype.createLinkObject = function (sourceId, targetId, linkId, linkType) { return { 'attributes': { 'version': 0 }, 'relationships': { 'link_type': { 'data': { 'id': linkId, 'type': 'workitemlinktypes' } }, 'source': { 'data': { 'id': linkType === 'forward' ? sourceId : targetId, 'type': 'workitems' } }, 'target': { 'data': { 'id': linkType === 'reverse' ? sourceId : targetId, 'type': 'workitems' } } }, 'type': 'workitemlinks' }; }; WorkItemLinkComponent.decorators = [ { type: Component, args: [{ selector: 'work-item-link', template: require('./work-item-link.component.html'), styles: [require('./work-item-link.component.css').toString()], changeDetection: ChangeDetectionStrategy.OnPush, animations: [ trigger('linkState', [ state('inactive', style({ backgroundColor: '#fff' })), state('active', style({ backgroundColor: '#39a5dc' })), transition('inactive => active', animate('0.2s 100ms')), transition('active => inactive', animate('0.2s 100ms')) ]) ] },] }, ]; /** @nocollapse */ WorkItemLinkComponent.ctorParameters = function () { return [ { type: Store, }, { type: WorkItemService, }, { type: WorkItemLinkTypeQuery, }, { type: WorkItemLinkQuery, }, { type: SpaceQuery, }, ]; }; WorkItemLinkComponent.propDecorators = { 'context': [{ type: Input },], 'loggedIn': [{ type: Input },], 'detailContext': [{ type: Input },], 'onLinkClick': [{ type: Output },], 'searchResultList': [{ type: ViewChild, args: ['searchResultList',] },], 'linkTypeSelector': [{ type: ViewChild, args: ['linkTypeSelector',] },], 'wiSearchBox': [{ type: ViewChild, args: ['wiSearchBox',] },], 'workItemSetter': [{ type: Input, args: ['workItem',] },], }; return WorkItemLinkComponent; }()); export { WorkItemLinkComponent }; //# sourceMappingURL=work-item-link.component.js.map