fabric8-planner
Version:
A planner front-end for Fabric8.
219 lines • 9.64 kB
JavaScript
import { Component, ElementRef, EventEmitter, Input, Output, Renderer2, ViewChild, ViewChildren } from '@angular/core';
import { Logger } from 'ngx-base';
import { filter } from 'rxjs/operators';
import { WorkItem, WorkItemRelations } from '../../models/work-item';
import { PermissionQuery } from './../../models/permission.model';
import { WorkItemQuery } from './../../models/work-item';
// ngrx stuff
import { FormControl } from '@angular/forms';
import { select, Store } from '@ngrx/store';
import * as WorkItemActions from './../../actions/work-item.actions';
var WorkItemQuickAddComponent = /** @class */ (function () {
function WorkItemQuickAddComponent(logger, renderer, store, workItemQuery, permissionQuery) {
this.logger = logger;
this.renderer = renderer;
this.store = store;
this.workItemQuery = workItemQuery;
this.permissionQuery = permissionQuery;
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;
this.addDisabled = this.permissionQuery.isAllowedToAdd();
this.workItemTitle = new FormControl('');
// Board view specific
this.initialDescHeight = 0;
this.initialDescHeightDiff = 0;
this.descHeight = '27px';
this.descResize = 'none';
this.createId = 0;
this.eventListeners = [];
this.blockAdd = false;
this.infotipSource = this.store
.pipe(select('planner'), select('infotips'));
}
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.workItemQuery.getWorkItems()
.pipe(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';
};
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'
}
};
// Setting state value from selected work item type
// This line can be removed when space template backend is in
// The backend will take care of setting the default state to
// a newly create work item
this.workItem.attributes['system.state'] =
this.selectedType.fields['system.state'].type.values[0];
// 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,
openDetailPage: openStatus
}));
if (this.wilistview === 'wi-query-view') {
this.workItemTitle.setValue('');
this.resetQuickAdd();
}
}
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.prototype.getInfotipText = function (id) {
return this.infotipSource
.pipe(select(function (s) { return s[id]; }), select(function (i) { return i ? i['en'] : id; }));
};
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: Renderer2, },
{ type: Store, },
{ type: WorkItemQuery, },
{ type: PermissionQuery, },
]; };
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