my-test123
Version:
A planner front-end for Fabric8.
375 lines • 17 kB
JavaScript
import { Spaces } from 'ngx-fabric8-wit';
import { Component, EventEmitter, ElementRef, Input, Output, Renderer2, ViewChild, ViewChildren } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { cloneDeep } from 'lodash';
import { Broadcaster, Logger, Notifications } from 'ngx-base';
import { AuthenticationService } from 'ngx-login-client';
import { FilterService } from '../../services/filter.service';
import { GroupTypesService } from '../../services/group-types.service';
import { WorkItem, WorkItemRelations } from '../../models/work-item';
import { WorkItemService } from '../../services/work-item.service';
var WorkItemQuickAddComponent = /** @class */ (function () {
function WorkItemQuickAddComponent(workItemService, broadcaster, logger, notifications, auth, filterService, groupTypesService, route, spaces, renderer) {
this.workItemService = workItemService;
this.broadcaster = broadcaster;
this.logger = logger;
this.notifications = notifications;
this.auth = auth;
this.filterService = filterService;
this.groupTypesService = groupTypesService;
this.route = route;
this.spaces = spaces;
this.renderer = renderer;
this.parentWorkItemId = null;
this.quickAddContext = [];
this.wilistview = 'wi-list-view';
this.workItemCreate = new EventEmitter();
this.error = false;
this.initialDescHeight = 0;
this.initialDescHeightDiff = 0;
this.descHeight = '27px';
this.descResize = 'none';
this.spaceSubscription = null;
this.selectedType = null;
this.availableTypes = null;
this.eventListeners = [];
this.allWorkItemTypes = null;
this.childLinkType = null;
this.allowedWITs = [];
}
Object.defineProperty(WorkItemQuickAddComponent.prototype, "WITypeSetter", {
set: function (val) {
var _this = this;
if (JSON.stringify(val) !== JSON.stringify(this.allWorkItemTypes)) {
this.allWorkItemTypes = val;
this.availableTypes = cloneDeep(this.allWorkItemTypes);
this.allowedWITs = this.allWorkItemTypes.filter(function (entry) {
return _this.quickAddContext.findIndex(function (i) { return i.id === entry.id; }) >= 0;
});
if (this.availableTypes.length) {
//this.selectedType = this.availableTypes[0];
this.selectedType = this.allowedWITs[0];
if (this.wilistview === 'wi-table-view-top' || this.wilistview === 'wi-card-view') {
this.createWorkItemObj();
}
}
}
},
enumerable: true,
configurable: true
});
;
Object.defineProperty(WorkItemQuickAddComponent.prototype, "forcedType", {
set: function (val) {
if (this.forcedType) {
this.logger.log('Updated forcedType on quick add component to ' + this.forcedType.attributes.name);
this.selectedType = this.forcedType;
}
},
enumerable: true,
configurable: true
});
;
WorkItemQuickAddComponent.prototype.ngOnInit = function () {
this.createWorkItemObj();
this.showQuickAdd = false;
this.showQuickAddBtn = this.auth.isLoggedIn();
this.listenToEvents();
};
WorkItemQuickAddComponent.prototype.ngOnDestroy = function () {
// prevent memory leak when component is destroyed
};
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';
//set the default work item type
this.workItem.relationships.baseType = {
data: {
id: this.selectedType ? this.selectedType.id : 'testtypeid',
type: this.selectedType ? this.selectedType.type : 'testtype'
}
};
//Go through the active filters and apply them
var currentFilters = this.filterService.getAppliedFilters();
if (currentFilters.length) {
for (var f = 0; f < currentFilters.length; f++) {
switch (currentFilters[f].id) {
case 'iteration':
this.workItem.relationships.iteration = {
data: {
id: currentFilters[f].value,
type: currentFilters[f].id
}
};
break;
case 'area':
this.workItem.relationships.area = {
data: {
id: currentFilters[f].value,
type: currentFilters[f].id
}
};
break;
case 'workitemtype':
this.workItem.relationships.baseType = {
data: {
id: currentFilters[f].value,
type: currentFilters[f].id + 's'
}
};
break;
case 'assignee':
this.workItem.relationships.assignees = {
data: [{
id: currentFilters[f].value,
type: 'identities'
}]
};
break;
}
}
}
};
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.attributes.name + ' for quick add.');
this.selectedType = type;
this.qaTitle.nativeElement.focus();
};
WorkItemQuickAddComponent.prototype.createLinkObject = function (parentWorkItemId, childWorkItemId, linkId) {
this.linkObject = {
'type': 'workitemlinks',
'attributes': {
'version': 0
},
'relationships': {
'link_type': {
'data': {
'id': linkId,
'type': 'workitemlinktypes'
}
},
'source': {
'data': {
'id': parentWorkItemId,
'type': 'workitems'
}
},
'target': {
'data': {
'id': childWorkItemId,
'type': 'workitems'
}
}
}
};
};
WorkItemQuickAddComponent.prototype.save = function (event, openStatus) {
var _this = this;
if (event === void 0) { event = null; }
if (openStatus === void 0) { openStatus = false; }
if (event)
event.preventDefault();
this.workItemCreate.emit({ parentId: this.parentWorkItemId });
// Setting type in relationship
// this.workItem.relationships = {
// baseType: {
// data: {
// id: this.selectedType?this.selectedType.id:'testtypeid',
// type: this.selectedType?this.selectedType.type:'testtype'
// }
// }
// } as WorkItemRelations;
//Set the current selected iteration
// 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() : '';
if (this.workItem.attributes['system.title']) {
this.qaSubmit.nativeElement.setAttribute('disabled', true);
this.qaTitle.nativeElement.setAttribute('disabled', true);
this.workItem.hasChildren = false;
this.workItem.relationships.baseType.data = this.selectedType;
console.log('before create ', this.workItem);
this.workItemService
.create(this.workItem)
.map(function (workItem) {
workItem.hasChildren = false;
return workItem;
})
.subscribe(function (workItem) {
if (_this.parentWorkItemId != null) {
_this.createLinkObject(_this.parentWorkItemId, workItem.id, '25c326a7-6d03-4f5a-b23b-86a9ee4171e9');
var tempLinkObject = { 'data': _this.linkObject };
_this.workItemService.createLink(tempLinkObject)
.subscribe(function (_a) {
var link = _a[0], includes = _a[1];
_this.workItemService.emitAddWIChild({
pwid: _this.parentWorkItemId,
wid: workItem.id, status: openStatus
});
});
}
else {
_this.workItemService.emitAddWI({ wi: workItem, status: openStatus });
}
_this.workItem = workItem; // saved workItem, w/ id if new
_this.resetQuickAdd();
}, function (error) {
_this.error = error;
_this.qaSubmit.nativeElement.removeAttribute('disabled');
_this.qaTitle.nativeElement.removeAttribute('disabled');
}); // TODO: Display error message
}
else {
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.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.resetQuickAdd = function () {
this.validTitle = false;
this.createWorkItemObj();
this.showQuickAddBtn = false;
this.showQuickAdd = true;
this.descHeight = this.initialDescHeight ? this.initialDescHeight : '26px';
this.qaSubmit.nativeElement.removeAttribute('disabled');
this.qaTitle.nativeElement.removeAttribute('disabled');
this.qaTitle.nativeElement.focus();
};
WorkItemQuickAddComponent.prototype.toggleQuickAdd = function () {
this.showQuickAdd = !this.showQuickAdd;
this.showQuickAddBtn = !this.showQuickAddBtn;
if (!this.showQuickAdd) {
this.workItem.attributes['system.description'] = '';
this.workItem.attributes['system.title'] = '';
this.validTitle = false;
this.descHeight = this.initialDescHeight ? this.initialDescHeight : 'inherit';
}
else {
this.createWorkItemObj();
}
};
WorkItemQuickAddComponent.prototype.preventDef = function (event) {
event.preventDefault();
};
WorkItemQuickAddComponent.prototype.setGuidedWorkItemType = function (wiTypeCollection) {
//if (this.wilistview === 'wi-list-view' || this.wilistview === 'wi-card-view')
if (wiTypeCollection.length > 0) {
var currentGT_1 = this.groupTypesService.getCurrentGroupType();
this.allowedWITs = this.allWorkItemTypes.filter(function (entry) {
return currentGT_1.findIndex(function (i) { return i.id === entry.id; }) >= 0;
});
this.availableTypes = cloneDeep(this.allWorkItemTypes);
var setWITCollection_1 = new Set(wiTypeCollection);
var setAvailableTypes = new Set(this.availableTypes);
var intersection = new Set(Array.from(setAvailableTypes).slice().filter(function (x) { return setWITCollection_1.has(x.id); }));
this.availableTypes = Array.from(intersection).slice();
//this.selectedType = this.availableTypes[0];
this.selectedType = this.allowedWITs[0];
this.showQuickAdd = false;
this.showQuickAddBtn = true;
}
else {
this.showQuickAddBtn = false;
this.showQuickAdd = false;
}
};
WorkItemQuickAddComponent.prototype.listenToEvents = function () {
var _this = this;
this.eventListeners.push(this.filterService.filterObservable.subscribe(function (item) {
_this.createWorkItemObj();
}));
this.eventListeners.push(this.groupTypesService.workItemSelected.subscribe(function (wiTypeCollection) {
_this.setGuidedWorkItemType(wiTypeCollection);
}));
this.eventListeners.push(this.groupTypesService.groupTypeSelected.subscribe(function (wiTypeCollection) {
_this.setGuidedWorkItemType(wiTypeCollection);
}));
};
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: WorkItemService, },
{ type: Broadcaster, },
{ type: Logger, },
{ type: Notifications, },
{ type: AuthenticationService, },
{ type: FilterService, },
{ type: GroupTypesService, },
{ type: ActivatedRoute, },
{ type: Spaces, },
{ type: Renderer2, },
]; };
WorkItemQuickAddComponent.propDecorators = {
'qaTitle': [{ type: ViewChild, args: ['quickAddTitle',] },],
'qaDesc': [{ type: ViewChild, args: ['quickAddDesc',] },],
'qaTitleRef': [{ type: ViewChildren, args: ['quickAddTitle', { read: ElementRef },] },],
'qaSubmit': [{ type: ViewChild, args: ['quickAddSubmit',] },],
'quickAddElement': [{ type: ViewChild, args: ['quickAddElement',] },],
'inlinequickAddElement': [{ type: ViewChild, args: ['inlinequickAddElement',] },],
'parentWorkItemId': [{ type: Input },],
'quickAddContext': [{ type: Input },],
'WITypeSetter': [{ type: Input, args: ['WITypes',] },],
'wilistview': [{ type: Input },],
'forcedType': [{ type: Input },],
'workItemCreate': [{ type: Output, args: ['workItemCreate',] },],
};
return WorkItemQuickAddComponent;
}());
export { WorkItemQuickAddComponent };
//# sourceMappingURL=work-item-quick-add.component.js.map