UNPKG

fabric8-planner

Version:
166 lines 7.05 kB
import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; import { cloneDeep } from 'lodash'; import { AuthenticationService } from 'ngx-login-client'; import { WorkItemService } from '../../services/work-item.service'; var AssigneeSelectorComponent = /** @class */ (function () { function AssigneeSelectorComponent(auth, workItemService) { this.auth = auth; this.workItemService = workItemService; this.editAllow = false; this.allUsers = []; this.selectedAssignees = []; this._selectedAssigneesBackup = []; this.onSelectAssignee = new EventEmitter(); this.onOpenAssignee = new EventEmitter(); this.onCloseAssignee = new EventEmitter(); this.users = []; this.searchAssignee = false; this.activeAddAssignee = false; this.backup = []; this.assignees = []; this.searchValue = ''; } Object.defineProperty(AssigneeSelectorComponent.prototype, "allUsersSetter", { set: function (val) { var _this = this; this.allUsers = cloneDeep(val); this.backup = cloneDeep(this.allUsers.map(function (user) { return { name: user.name, src: user.avatar, id: user.id, stickontop: false, selected: false }; })); if (this.searchValue.length) { this.assignees = cloneDeep(this.backup.filter(function (i) { return i.name.indexOf(_this.searchValue) > -1; })); } else { this.assignees = cloneDeep(this.backup); } if (this.loggedInUser) { this.backup = [{ name: this.loggedInUser.name, src: this.loggedInUser.avatar, id: this.loggedInUser.id, stickontop: true, selected: false }].concat(this.backup); this.assignees = [this.backup[0]].concat(this.assignees); this.allUsers = [this.loggedInUser].concat(this.allUsers); } this.updateSelection(); }, enumerable: true, configurable: true }); Object.defineProperty(AssigneeSelectorComponent.prototype, "selectedAssigneesSetter", { set: function (val) { this.selectedAssignees = cloneDeep(val); this._selectedAssigneesBackup = cloneDeep(val); this.updateSelection(); }, enumerable: true, configurable: true }); AssigneeSelectorComponent.prototype.onSelect = function (event) { var findSelectedIndex = this.selectedAssignees.findIndex(function (i) { return i.id === event.id; }); if (findSelectedIndex > -1) { this.selectedAssignees.splice(findSelectedIndex, 1); } else { var findAssignee = cloneDeep(this.allUsers.find(function (i) { return i.id === event.id; })); if (findAssignee) { this.selectedAssignees.push(findAssignee); } } this.updateSelection(); this.onSelectAssignee.emit(cloneDeep(this.selectedAssignees)); }; AssigneeSelectorComponent.prototype.updateSelection = function () { var _this = this; this.assignees.forEach(function (assignee, index) { if (_this.selectedAssignees.find(function (a) { return assignee.id === a.id; })) { _this.assignees[index].selected = true; } else { _this.assignees[index].selected = false; } }); this.backup.forEach(function (assignee, index) { if (_this.selectedAssignees.find(function (a) { return assignee.id === a.id; })) { _this.backup[index].selected = true; } else { _this.backup[index].selected = false; } }); }; AssigneeSelectorComponent.prototype.onSearch = function (event) { var needle = event.trim(); this.searchValue = needle; if (needle.length) { this.assignees = cloneDeep(this.backup.filter(function (i) { return i.name.toLowerCase().indexOf(needle.toLowerCase()) > -1 || i.stickontop; })); } else { this.assignees = cloneDeep(this.backup); } }; AssigneeSelectorComponent.prototype.cancelAssignment = function () { this.searchAssignee = false; }; AssigneeSelectorComponent.prototype.onOpen = function (event) { this.onOpenAssignee.emit('open'); }; AssigneeSelectorComponent.prototype.onClose = function (event) { var _this = this; // Setting search input to empty string this.dropdownRef.setSearchText(''); // Thus reset the value this.assignees = cloneDeep(this.backup); var compare1 = this.selectedAssignees.filter(function (i) { return _this._selectedAssigneesBackup.findIndex(function (b) { return b.id === i.id; }) === -1; }); var compare2 = this._selectedAssigneesBackup.filter(function (i) { return _this.selectedAssignees.findIndex(function (b) { return b.id === i.id; }) === -1; }); if (compare1.length !== 0 || compare2.length !== 0) { this.onCloseAssignee.emit(cloneDeep(this.selectedAssignees)); } }; AssigneeSelectorComponent.prototype.openDropdown = function () { this.dropdownRef.openDropdown(); }; AssigneeSelectorComponent.prototype.closeDropdown = function () { this.dropdownRef.closeDropdown(); }; AssigneeSelectorComponent.prototype.closeAddAssignee = function () { this.activeAddAssignee = false; }; AssigneeSelectorComponent.decorators = [ { type: Component, args: [{ selector: 'assignee-selector', template: require('./assignee-selector.component.html'), styles: [require('./assignee-selector.component.css').toString()] },] }, ]; /** @nocollapse */ AssigneeSelectorComponent.ctorParameters = function () { return [ { type: AuthenticationService, }, { type: WorkItemService, }, ]; }; AssigneeSelectorComponent.propDecorators = { 'dropdownRef': [{ type: ViewChild, args: ['dropdown',] },], 'loggedInUser': [{ type: Input },], 'editAllow': [{ type: Input },], 'allUsersSetter': [{ type: Input, args: ['allUsers',] },], 'selectedAssigneesSetter': [{ type: Input, args: ['selectedAssignees',] },], 'onSelectAssignee': [{ type: Output },], 'onOpenAssignee': [{ type: Output },], 'onCloseAssignee': [{ type: Output },], }; return AssigneeSelectorComponent; }()); export { AssigneeSelectorComponent }; //# sourceMappingURL=assignee-selector.component.js.map