UNPKG

my-test123

Version:
316 lines 13.5 kB
import { EventService } from './../../services/event.service'; import { Component, Input, ViewChild } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { Http } from '@angular/http'; import { cloneDeep, trimEnd } from 'lodash'; import { Broadcaster, NotificationType, Notifications } from 'ngx-base'; import { WorkItemService } from '../../services/work-item.service'; var WorkItemLinkComponent = /** @class */ (function () { // showLinksList : Boolean = false; function WorkItemLinkComponent(workItemService, router, route, broadcaster, eventService, notifications, http) { this.workItemService = workItemService; this.router = router; this.route = route; this.broadcaster = broadcaster; this.eventService = eventService; this.notifications = notifications; this.linkTypes = []; this.selectedWorkItem = {}; this.selectedLinkType = false; this.selectedValue = ''; this.searchWorkItems = []; this.showLinkComponent = false; this.showLinkView = false; this.showLinkCreator = true; this.searchNotAllowedIds = []; this.prevWItem = null; this.selectedTab = null; this.eventListeners = []; this.existingQueryParams = {}; } WorkItemLinkComponent.prototype.ngOnInit = function () { this.loadLinkTypes(); this.listenToEvents(); }; WorkItemLinkComponent.prototype.ngOnChanges = function (changes) { this.loadLinkTypes(); this.showLinkComponent = false; this.showLinkView = false; this.selectedLinkType = false; this.resetSearchData(); }; WorkItemLinkComponent.prototype.ngDoCheck = function () { // To reset selected link type on change wi type if (this.prevWItem && this.prevWItem.relationships.baseType.data.id !== this.workItem.relationships.baseType.data.id) { // Change in work item type // Reset selected link type this.selectedLinkType = false; } this.prevWItem = cloneDeep(this.workItem); }; WorkItemLinkComponent.prototype.ngOnDestroy = function () { console.log('Destroying all the listeners in wi link component'); this.eventListeners.forEach(function (subscriber) { return subscriber.unsubscribe(); }); }; WorkItemLinkComponent.prototype.createLinkObject = function (workItemId, linkWorkItemId, linkId, linkType) { this.link = { // id: '', 'type': 'workitemlinks', 'attributes': { 'version': 0 }, 'relationships': { 'link_type': { 'data': { 'id': linkId, 'type': 'workitemlinktypes' } }, 'source': { 'data': { 'id': linkType == 'forward' ? workItemId : linkWorkItemId, 'type': 'workitems' } }, 'target': { 'data': { 'id': linkType == 'reverse' ? workItemId : linkWorkItemId, 'type': 'workitems' } } } }; }; WorkItemLinkComponent.prototype.onSelectRelation = function (relation) { //clear the search box and reset values related to search this.searchBox.nativeElement.value = ''; this.searchWorkItems = []; this.selectedWorkItemId = null; this.selectedLinkType = relation; this.setSearchNotAllowedIds(); }; WorkItemLinkComponent.prototype.setSearchNotAllowedIds = function () { var _this = this; this.searchNotAllowedIds.push(this.workItem.id); var relatedLinks = this.workItem.relationalData.linkDicts.find(function (item) { return item.linkName == _this.selectedLinkType.name; }); if (typeof (relatedLinks) !== 'undefined') { relatedLinks.links.forEach(function (item) { if (_this.searchNotAllowedIds.indexOf(item.relationalData.source.id) === -1) { _this.searchNotAllowedIds.push(item.relationalData.source.id); } if (_this.searchNotAllowedIds.indexOf(item.relationalData.target.id) === -1) { _this.searchNotAllowedIds.push(item.relationalData.target.id); } }); } console.log('Your search results will not have ' + this.searchNotAllowedIds.join(', ')) + ' IDs'; }; WorkItemLinkComponent.prototype.createLink = function (event) { var _this = this; if (event === void 0) { event = null; } this.createLinkObject(this.workItem.id, this.selectedWorkItemId, this.selectedLinkType.linkId, this.selectedLinkType.linkType); var tempValue = { 'data': this.link }; this.workItemService .createLink(tempValue) .subscribe(function (_a) { var link = _a[0], includes = _a[1]; _this.workItemService.addLinkToWorkItem(link, includes, _this.workItem); _this.resetSearchData(); _this.eventService.workItemListReloadOnLink.next(true); }, function (error) { if ((error._body).indexOf('single parent in tree topology') >= 0) { try { _this.notifications.message({ message: 'Work item can only have a single parent.', type: NotificationType.DANGER }); } catch (e) { console.log(error._body); } } }); }; // deleteLink(link : Link){ WorkItemLinkComponent.prototype.deleteLink = function (event, link, currentWorkItem) { var _this = this; event.stopPropagation(); this.workItemService .deleteLink(link, currentWorkItem.id) .subscribe(function () { _this.workItemService.removeLinkFromWorkItem(link, currentWorkItem); _this.eventService.workItemListReloadOnLink.next(true); }, function (error) { return console.log(error); }); }; WorkItemLinkComponent.prototype.loadLinkTypes = function () { var _this = this; this.workItemService .getLinkTypes(this.workItem) .subscribe(function (linkTypes) { _this.linkTypes = cloneDeep(linkTypes); }, function (e) { return console.log(e); }); }; WorkItemLinkComponent.prototype.toggleLinkComponent = function (onlyOpen) { if (onlyOpen === void 0) { onlyOpen = false; } if (this.loggedIn) { if (onlyOpen) { this.showLinkComponent = true; } else { this.showLinkComponent = !this.showLinkComponent; } } if (!this.showLinkComponent) { this.selectedTab = null; } else { if (!this.selectedTab) { this.selectedTab = 'all'; } } }; WorkItemLinkComponent.prototype.toggleLinkView = function () { this.showLinkView = !this.showLinkView; }; WorkItemLinkComponent.prototype.toggleLinkCreator = function () { this.showLinkCreator = !this.showLinkCreator; }; WorkItemLinkComponent.prototype.onDetailUrl = function (links, workItem) { var workItemId = links['relationships']['target']['data']['id']; if (links['relationships']['target']['data']['id'] == workItem['id']) { workItemId = links['relationships']['source']['data']['id']; } this.router.navigateByUrl(trimEnd(this.router.url.split('plan')[0], '/') + '/detail/' + workItemId); }; WorkItemLinkComponent.prototype.getWILink = function (link, workItem) { return trimEnd(this.router.url.split('plan')[0], '/') + '/plan/detail/' + (link.relationalData.source.id == workItem.id ? link.relationalData.target.number : link.relationalData.source.number); }; WorkItemLinkComponent.prototype.linkSearchWorkItem = function (term, event) { var _this = this; event.stopPropagation(); //console.log(this.searchResultList.nativeElement.children.length); if (event.keyCode == 40 || event.keyCode == 38) { var lis = this.searchResultList.nativeElement.children; var i = 0; for (; i < lis.length; i++) { if (lis[i].classList.contains('selected')) { break; } } if (i == lis.length) { if (event.keyCode == 40) { lis[0].classList.add('selected'); lis[0].scrollIntoView(false); } else { lis[lis.length - 1].classList.add('selected'); lis[lis.length - 1].scrollIntoView(false); } } else { lis[i].classList.remove('selected'); if (event.keyCode == 40) { lis[(i + 1) % lis.length].classList.add('selected'); lis[(i + 1) % lis.length].scrollIntoView(false); } else { // In javascript mod gives exact mod for negative value // For example, -1 % 6 = -1 but I need, -1 % 6 = 5 // To get the round positive value I am adding the divisor // with the negative dividend lis[(((i - 1) % lis.length) + lis.length) % lis.length].classList.add('selected'); lis[(((i - 1) % lis.length) + lis.length) % lis.length].scrollIntoView(false); } } } else if (event.keyCode == 13) { var lis = this.searchResultList.nativeElement.children; var i = 0; for (; i < lis.length; i++) { if (lis[i].classList.contains('selected')) { break; } } if (i < lis.length) { var selectedId = lis[i].dataset.wiid; var selectedNumber = lis[i].dataset.winumber; var selectedTitle = lis[i].dataset.wititle; this.selectSearchResult(selectedId, selectedNumber, selectedTitle); } } else { if (term.trim() != "") { // Search on atleast 3 char or numeric if (term.length >= 3 || !isNaN(term)) { this.workItemService.searchLinkWorkItem(term) .subscribe(function (searchData) { _this.searchWorkItems = searchData.filter(function (item) { return _this.searchNotAllowedIds.indexOf(item.id) == -1; }); console.log(_this.searchWorkItems); }, function (err) { return console.log(err); }); } } else { // Reseting search data this.searchWorkItems = []; if (this.selectedWorkItemId) { this.resetSearchData(); } } } }; WorkItemLinkComponent.prototype.resetSearchData = function () { this.selectedWorkItemId = null; this.selectedValue = ''; this.selectedLinkType = false; this.searchNotAllowedIds = []; }; WorkItemLinkComponent.prototype.selectSearchResult = function (id, number, title) { this.selectedWorkItemId = id; this.selectedValue = number + ' - ' + title; this.searchWorkItems = []; }; WorkItemLinkComponent.prototype.selectTab = function (linkTypeName) { if (linkTypeName === void 0) { linkTypeName = null; } this.selectedTab = linkTypeName; this.resetSearchData(); this.toggleLinkComponent(true); }; WorkItemLinkComponent.prototype.listenToEvents = function () { var _this = this; this.eventListeners.push(this.route.queryParams.subscribe(function (params) { _this.existingQueryParams = params; })); }; WorkItemLinkComponent.decorators = [ { type: Component, args: [{ selector: 'alm-work-item-link', template: require('./work-item-link.component.html'), styles: [require('./work-item-link.component.css').toString()], },] }, ]; /** @nocollapse */ WorkItemLinkComponent.ctorParameters = function () { return [ { type: WorkItemService, }, { type: Router, }, { type: ActivatedRoute, }, { type: Broadcaster, }, { type: EventService, }, { type: Notifications, }, { type: Http, }, ]; }; WorkItemLinkComponent.propDecorators = { 'workItem': [{ type: Input },], 'loggedIn': [{ type: Input },], 'searchBox': [{ type: ViewChild, args: ['searchBox',] },], 'searchResultList': [{ type: ViewChild, args: ['searchResultList',] },], }; return WorkItemLinkComponent; }()); export { WorkItemLinkComponent }; //# sourceMappingURL=work-item-link.component.js.map