UNPKG

my-test123

Version:
199 lines 8.55 kB
import { Component, EventEmitter, ElementRef, Input, Output, Renderer2, ViewChild, ViewChildren } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { Logger } from 'ngx-base'; import { AuthenticationService } from 'ngx-login-client'; import { WorkItem, WorkItemRelations } from '../../models/work-item'; // ngrx stuff import { Store } from '@ngrx/store'; import * as WorkItemActions from './../../actions/work-item.actions'; var WorkItemQuickAddComponent = /** @class */ (function () { function WorkItemQuickAddComponent(logger, auth, route, renderer, store) { this.logger = logger; this.auth = auth; this.route = route; this.renderer = renderer; this.store = store; this.parentWorkItemId = null; this.workItemTypes = []; this.selectedType = null; this.selectedIteration = null; this.wilistview = 'wi-list-view'; this.onStartCreateWI = new EventEmitter(); this.error = false; this.validTitle = false; // Board view specific this.initialDescHeight = 0; this.initialDescHeightDiff = 0; this.descHeight = '27px'; this.descResize = 'none'; this.createId = 0; this.eventListeners = []; this.blockAdd = false; } WorkItemQuickAddComponent.prototype.ngOnInit = function () { var _this = this; this.createWorkItemObj(); // This is board view specific this.showQuickAdd = false; // listen for item added this.eventListeners.push(this.store .select('listPage') .select('workItems') .filter(function (items) { return !!items.length; }) .subscribe(function (items) { // const addedItem = items.find(item => item.createId === this.createId); _this.resetQuickAdd(); })); }; WorkItemQuickAddComponent.prototype.ngOnDestroy = function () { // prevent memory leak when component is destroyed this.eventListeners.forEach(function (e) { e.unsubscribe(); }); }; WorkItemQuickAddComponent.prototype.setTypeContext = function (type) { this.logger.log('Force set type context on quick add component to ' + type.attributes.name); this.selectedType = type; }; WorkItemQuickAddComponent.prototype.createWorkItemObj = function () { this.workItem = new WorkItem(); this.workItem.attributes = new Map(); this.workItem.relationships = new WorkItemRelations(); this.workItem.type = 'workitems'; this.workItem.attributes['system.state'] = 'new'; }; WorkItemQuickAddComponent.prototype.ngAfterViewInit = function () { var _this = this; this.qaTitleRef.changes.subscribe(function (item) { if (item.length) { _this.qaTitle.nativeElement.focus(); } }); }; WorkItemQuickAddComponent.prototype.ngAfterViewChecked = function () { if (this.quickAddElement) { var quickaddWdth = 0; if (document.getElementsByClassName('f8-wi-list__quick-add').length > 0) { quickaddWdth = document.getElementsByClassName('f8-wi-list__quick-add')[0].offsetWidth; } var targetWidth = quickaddWdth + 20; if (this.quickAddElement.nativeElement.classList.contains('f8-quick-add-inline')) { this.renderer.setStyle(this.quickAddElement.nativeElement, 'max-width', targetWidth + "px"); } } }; WorkItemQuickAddComponent.prototype.selectType = function (event, type) { if (event) event.preventDefault(); this.logger.log('Selected type ' + type.name + ' for quick add.'); this.selectedType = type; this.qaTitle.nativeElement.focus(); }; WorkItemQuickAddComponent.prototype.save = function (event, openStatus) { if (event === void 0) { event = null; } if (openStatus === void 0) { openStatus = false; } if (event) event.preventDefault(); // Do we have a real title? // If yes, trim; if not, reassign it as a (blank) string. this.workItem.attributes['system.title'] = (!!this.workItem.attributes['system.title']) ? this.workItem.attributes['system.title'].trim() : ''; // Same treatment as title, but this is more important. // As we're validating title in the next step // But passing on description as is (causing data type issues) this.workItem.attributes['system.description'] = (!!this.workItem.attributes['system.description']) ? this.workItem.attributes['system.description'].trim() : ''; // Set the default work item type this.workItem.relationships.baseType = { data: { id: this.selectedType ? this.selectedType.id : 'testtypeid', type: 'workitemtypes' } }; // Set the default iteration for new work item if (this.selectedIteration) { this.workItem.relationships.iteration = { data: { id: this.selectedIteration.id, type: 'iterations' } }; } this.createId = new Date().getTime(); if (this.workItem.attributes['system.title']) { this.blockAdd = true; this.onStartCreateWI.emit(this.parentWorkItemId); this.store.dispatch(new WorkItemActions.Add({ createId: this.createId, workItem: this.workItem, parentId: this.parentWorkItemId })); } else { this.blockAdd = false; this.error = 'Title can not be empty.'; } }; WorkItemQuickAddComponent.prototype.checkTitle = function () { if (this.workItem.attributes['system.title'] && this.workItem.attributes['system.title'].trim()) { this.validTitle = true; } else { this.validTitle = false; } }; WorkItemQuickAddComponent.prototype.resetQuickAdd = function () { this.validTitle = false; this.createWorkItemObj(); this.showQuickAdd = true; this.descHeight = this.initialDescHeight ? this.initialDescHeight : '26px'; this.blockAdd = false; if (this.qaTitle) { this.qaTitle.nativeElement.focus(); } }; WorkItemQuickAddComponent.prototype.preventDef = function (event) { event.preventDefault(); }; // This board view specific WorkItemQuickAddComponent.prototype.checkDesc = function () { if (!this.initialDescHeight) { this.initialDescHeight = this.qaDesc.nativeElement.offsetHeight; this.initialDescHeightDiff = this.initialDescHeight - this.qaDesc.nativeElement.scrollHeight; } this.descHeight = this.qaDesc.nativeElement.scrollHeight + this.initialDescHeightDiff; }; WorkItemQuickAddComponent.decorators = [ { type: Component, args: [{ selector: 'alm-work-item-quick-add', template: require('./work-item-quick-add.component.html'), styles: [require('./work-item-quick-add.component.css').toString()] },] }, ]; /** @nocollapse */ WorkItemQuickAddComponent.ctorParameters = function () { return [ { type: Logger, }, { type: AuthenticationService, }, { type: ActivatedRoute, }, { type: Renderer2, }, { type: Store, }, ]; }; WorkItemQuickAddComponent.propDecorators = { 'qaTitle': [{ type: ViewChild, args: ['quickAddTitle',] },], 'qaDesc': [{ type: ViewChild, args: ['quickAddDesc',] },], 'qaTitleRef': [{ type: ViewChildren, args: ['quickAddTitle', { read: ElementRef },] },], 'quickAddElement': [{ type: ViewChild, args: ['quickAddElement',] },], 'inlinequickAddElement': [{ type: ViewChild, args: ['inlinequickAddElement',] },], 'parentWorkItemId': [{ type: Input },], 'workItemTypes': [{ type: Input },], 'selectedType': [{ type: Input },], 'selectedIteration': [{ type: Input },], 'wilistview': [{ type: Input },], 'onStartCreateWI': [{ type: Output },], }; return WorkItemQuickAddComponent; }()); export { WorkItemQuickAddComponent }; //# sourceMappingURL=work-item-quick-add.component.js.map