my-test123
Version:
A planner front-end for Fabric8.
1,064 lines • 45.6 kB
JavaScript
import { Observable } from 'rxjs/Observable';
import { Component, EventEmitter, HostListener, Input, Output, ViewChild } from '@angular/core';
import { animate, state, style, transition, trigger } from '@angular/animations';
import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';
import { Router } from '@angular/router';
import { cloneDeep, merge, remove } from 'lodash';
import { Spaces } from 'ngx-fabric8-wit';
import { Broadcaster, Logger } from 'ngx-base';
import { AuthenticationService, UserService } from 'ngx-login-client';
import { AreaService } from '../../services/area.service';
import { IterationService } from '../../services/iteration.service';
import { WorkItemTypeControlService } from '../../services/work-item-type-control.service';
import { WorkItem, WorkItemRelations } from '../../models/work-item';
import { WorkItemService } from '../../services/work-item.service';
import { WorkItemDataService } from './../../services/work-item-data.service';
import { CollaboratorService } from '../../services/collaborator.service';
import { LabelService } from '../../services/label.service';
//ngrx stuff
import { Store } from '@ngrx/store';
import * as CommentActions from './../../actions/comment.actions';
var WorkItemDetailComponent = /** @class */ (function () {
function WorkItemDetailComponent(areaService, auth, broadcaster, labelService, workItemService, workItemDataService, route, location, logger, router, iterationService, userService, workItemTypeControlService, spaces, collaboratorService, store) {
this.areaService = areaService;
this.auth = auth;
this.broadcaster = broadcaster;
this.labelService = labelService;
this.workItemService = workItemService;
this.workItemDataService = workItemDataService;
this.route = route;
this.location = location;
this.logger = logger;
this.router = router;
this.iterationService = iterationService;
this.userService = userService;
this.workItemTypeControlService = workItemTypeControlService;
this.spaces = spaces;
this.collaboratorService = collaboratorService;
this.store = store;
this.selectedLabels = [];
this.selectedAssignees = [];
this.onOpenSelector = new EventEmitter();
this.onCloseSelector = new EventEmitter();
this.showDialog = false;
this.submitted = false;
this.active = true;
this.loggedIn = false;
this.headerEditable = false;
this.validTitle = true;
this.titleText = '';
this.descText = '';
this.searchAssignee = false;
this.users = [];
this.addNewWI = false;
this.panelState = 'out';
this.areas = [];
this.iterations = [];
this.comments = [];
this.eventListeners = [];
this.saving = false;
this.savingError = false;
this.errorMessage = '';
this.queryParams = {};
this.itemSubscription = null;
this.loadingComments = true;
this.loadingTypes = false;
this.loadingIteration = false;
this.loadingArea = false;
this.loadingLabels = false;
this.loadingAssignees = false;
this.labels = [];
this.activeAddAssignee = false;
this.searchValue = '';
}
WorkItemDetailComponent.prototype.onClick = function (targetElement, assigned_user) {
if (this.assignee) {
var clickedInsidePopup = this.assignee.nativeElement.contains(targetElement);
if (!clickedInsidePopup && !assigned_user) {
this.cancelAssignment();
}
}
};
WorkItemDetailComponent.prototype.ngOnInit = function () {
this.saving = false;
this.loggedIn = this.auth.isLoggedIn();
this.listenToEvents();
};
WorkItemDetailComponent.prototype.ngOnDestroy = function () {
console.log('Destroying all the listeners in detail component');
this.eventListeners.forEach(function (subscriber) { return subscriber.unsubscribe(); });
};
WorkItemDetailComponent.prototype.openPreview = function (workitem) {
if (!workitem)
return;
this.workItemRef = workitem;
this.loadWorkItem(workitem.id);
};
WorkItemDetailComponent.prototype.closePreview = function () {
var _this = this;
this.panelState = 'out';
this.eventListeners.forEach(function (subscriber) { return subscriber.unsubscribe(); });
setTimeout(function () {
_this.workItem = null;
}, 400);
};
WorkItemDetailComponent.prototype.loadWorkItem = function (id) {
var _this = this;
var t1 = performance.now();
this.eventListeners.push(this.workItemDataService.getItem(id)
.do(function (workItem) {
if (workItem) {
_this.workItem = cloneDeep(workItem);
_this.store.dispatch(new CommentActions.Get(_this.workItem.relationships.comments.links.related));
_this.titleText = _this.workItem.attributes['system.title'];
_this.descText = _this.workItem.attributes['system.description'] || '';
// Open the panel once work item is ready
var t2 = performance.now();
if (_this.panelState === 'out') {
_this.panelState = 'in';
console.log('Performance :: Details page first paint (local data) - ' + (t2 - t1) + ' milliseconds.');
if (_this.headerEditable && typeof (_this.title) !== 'undefined') {
_this.title.nativeElement.focus();
}
}
}
})
.do(function () {
_this.loadingComments = true;
_this.loadingTypes = true;
_this.loadingIteration = true;
_this.loadingArea = true;
_this.loadingLabels = true;
_this.loadingAssignees = true;
})
.switchMap(function () { return _this.workItemService.getWorkItemByNumber(id); })
.do(function (workItem) {
_this.workItem = workItem;
_this.workItemDataService.setItem(workItem);
_this.titleText = _this.workItem.attributes['system.title'];
_this.descText = _this.workItem.attributes['system.description'] || '';
// Open the panel once work item is ready
var t2 = performance.now();
if (_this.panelState === 'out') {
_this.panelState = 'in';
console.log('Performance :: Details page first paint - ' + (t2 - t1) + ' milliseconds.');
if (_this.headerEditable && typeof (_this.title) !== 'undefined') {
_this.title.nativeElement.focus();
}
}
})
.do(function (workItem) { return console.log('Work item fethced: ', cloneDeep(workItem)); })
.take(1)
.switchMap(function () {
return Observable.combineLatest(_this.resolveWITypes(), _this.resolveAssignees(), _this.resolveCreators(), _this.resolveArea(), _this.resolveIteration(), _this.resolveLinks(), _this.resolveComments(), _this.resolveLabels());
})
.subscribe(function () {
_this.closeUserRestFields();
_this.workItemPayload = {
id: _this.workItem.id,
number: _this.workItem.number,
attributes: {
version: _this.workItem.attributes['version']
},
links: {
self: _this.workItem.links.self
},
type: _this.workItem.type
};
// init dynamic form
if (_this.workItem.relationships.baseType.data.attributes) {
_this.dynamicFormGroup = _this.workItemTypeControlService.toFormGroup(_this.workItem);
_this.dynamicFormDataArray = _this.workItemTypeControlService.toAttributeArray(_this.workItem.relationships.baseType.data.attributes.fields);
}
}, function (err) {
//console.log(err);
//setTimeout(() => this.itemSubscription.unsubscribe());
// this.closeDetails();
}));
};
WorkItemDetailComponent.prototype.resolveWITypes = function () {
var _this = this;
return this.workItemService.getWorkItemTypes()
.do(function (workItemTypes) {
// Resolve work item type
_this.workItem.relationships.baseType.data =
workItemTypes.find(function (type) { return type.id === _this.workItem.relationships.baseType.data.id; }) ||
_this.workItem.relationships.baseType.data;
_this.loadingTypes = false;
});
};
WorkItemDetailComponent.prototype.resolveAssignees = function () {
var _this = this;
return this.workItemService.resolveAssignees(this.workItem.relationships.assignees)
.do(function (assignees) {
// Resolve assignees
_this.workItem.relationships.assignees = {
data: assignees
};
_this.loadingAssignees = false;
});
};
WorkItemDetailComponent.prototype.resolveCreators = function () {
var _this = this;
return this.workItemService.resolveCreator2(this.workItem.relationships.creator)
.do(function (creator) {
// Resolve creator
_this.workItem.relationships.creator = {
data: creator
};
});
};
WorkItemDetailComponent.prototype.resolveArea = function () {
var _this = this;
return this.areaService.getArea(this.workItem.relationships.area)
.do(function (area) {
// Resolve area
_this.workItem.relationships.area = {
data: area
};
_this.areas = _this.extractAreaKeyValue([area]);
_this.loadingArea = false;
});
};
WorkItemDetailComponent.prototype.resolveIteration = function () {
var _this = this;
return this.iterationService.getIteration(this.workItem.relationships.iteration)
.do(function (iteration) {
// Resolve iteration
_this.workItem.relationships.iteration = {
data: iteration
};
_this.iterations = _this.extractIterationKeyValue([iteration]);
_this.loadingIteration = false;
});
};
WorkItemDetailComponent.prototype.resolveLinks = function () {
var _this = this;
return this.workItemService.resolveLinks(this.workItem.links.self + '/relationships/links')
.do(function (_a) {
var links = _a[0], includes = _a[1];
// Resolve links
_this.workItem = Object.assign(_this.workItem, {
relationalData: {
linkDicts: [],
totalLinkCount: 0
}
});
links.forEach(function (link) {
_this.workItemService.addLinkToWorkItem(link, includes, _this.workItem);
});
});
};
WorkItemDetailComponent.prototype.resolveComments = function () {
var _this = this;
return this.workItemService.resolveComments(this.workItem.relationships.comments.links.related)
.do(function (comments) {
// Resolve comments
merge(_this.workItem.relationships.comments, comments);
_this.workItem.relationships.comments.data.forEach(function (comment, index) {
_this.workItemService.resolveCommentCreator(comment.relationships['created-by'])
.subscribe(function (creator) {
comment.relationships['created-by'] = {
data: creator
};
});
});
_this.comments = _this.workItem.relationships.comments.data;
_this.loadingComments = false;
});
};
WorkItemDetailComponent.prototype.resolveLabels = function () {
var _this = this;
return this.labelService.getLabels()
.do(function (labels) {
_this.loadingLabels = false;
_this.labels = cloneDeep(labels);
if (_this.workItem.relationships.labels.data) {
_this.workItem.relationships.labels.data =
_this.workItem.relationships.labels.data.map(function (label) {
return _this.labels.find(function (l) { return l.id === label.id; });
});
// Sort labels in alphabetical order
_this.workItem.relationships.labels.data =
_this.workItem.relationships.labels.data.sort(function (labelA, labelB) {
var labelAName = labelA.attributes.name.toUpperCase();
var labelBName = labelB.attributes.name.toUpperCase();
return labelAName.localeCompare(labelBName);
});
}
else {
_this.workItem.relationships.labels = {
data: []
};
}
});
};
WorkItemDetailComponent.prototype.createWorkItemObj = function (type) {
var _this = this;
this.workItem = new WorkItem();
this.workItem.id = null;
this.workItem.attributes = new Map();
this.workItem.attributes['system.description'] = '';
this.workItem.attributes['system.description.rendered'] = '';
this.workItem.relationships = new WorkItemRelations();
this.workItem.type = 'workitems';
this.workItem.relationships = {
baseType: {
data: {
id: type,
type: 'workitemtypes'
}
}
};
// Add creator
this.userService.getUser()
.subscribe(function (user) {
_this.workItem.relationships = Object.assign(_this.workItem.relationships, {
creator: {
data: user
}
});
}, function (err) { return console.log(err); });
this.workItem.relationalData = {};
this.workItemService.resolveType(this.workItem);
this.workItem.attributes['system.state'] = 'new';
};
WorkItemDetailComponent.prototype.getAllUsers = function () {
return Observable.combineLatest(this.userService.getUser(), this.collaboratorService.getCollaborators());
};
WorkItemDetailComponent.prototype.updateOnList = function () {
this.workItemService.emitEditWI(this.workItem);
};
WorkItemDetailComponent.prototype.descUpdate = function (event) {
var _this = this;
var rawText = event.rawText;
var callBack = event.callBack;
this.descText = rawText;
this.workItem.attributes['system.description'] = this.descText.trim();
this.workItem.attributes['system.description.markup'] = 'Markdown';
if (this.workItem.id) {
var payload = cloneDeep(this.workItemPayload);
payload.attributes['system.description'] = this.descText.trim();
payload.attributes['system.description.markup'] = 'Markdown';
this.save(payload, true)
.subscribe(function (workItem) {
callBack(workItem.attributes['system.description'], workItem.attributes['system.description.rendered']);
_this.workItem.attributes['system.description.rendered'] =
workItem.attributes['system.description.rendered'];
_this.workItem.attributes['system.description'] =
workItem.attributes['system.description'];
// TODO: List update hack. should go away
_this.workItemRef.attributes['system.description.rendered'] =
workItem.attributes['system.description.rendered'];
_this.workItemRef.attributes['system.description'] =
workItem.attributes['system.description'];
_this.updateOnList();
});
}
else {
this.save();
}
};
WorkItemDetailComponent.prototype.showPreview = function (event) {
var rawText = event.rawText;
var callBack = event.callBack;
this.workItemService.renderMarkDown(rawText)
.subscribe(function (renderedHtml) {
callBack(rawText, renderedHtml);
});
};
// called when a dynamic field is updated.
WorkItemDetailComponent.prototype.dynamicFieldUpdated = function (event) {
var _this = this;
this.workItem.attributes[event.formControlName] = event.newValue;
if (this.workItem.id) {
var payload = cloneDeep(this.workItemPayload);
payload.attributes[event.formControlName] = event.newValue;
this.save(payload, true)
.subscribe(function (workItem) {
_this.workItem.attributes[event.formControlName] =
workItem.attributes[event.formControlName];
// TODO: List update hack. should go away
_this.workItemRef.attributes[event.formControlName] =
workItem.attributes[event.formControlName];
_this.updateOnList();
});
}
else {
this.save();
}
};
WorkItemDetailComponent.prototype.closeHeader = function () {
this.headerEditable = false;
};
WorkItemDetailComponent.prototype.openHeader = function () {
var _this = this;
if (this.loggedIn) {
/* TODO: send "close up" to the markdown field
if (this.descEditable) {
this.onUpdateDescription();
}
*/
this.closeUserRestFields();
this.headerEditable = true;
setTimeout(function () {
if (_this.headerEditable && typeof (_this.title) !== 'undefined') {
_this.title.nativeElement.focus();
}
});
}
};
WorkItemDetailComponent.prototype.getAreas = function () {
var _this = this;
this.areaService.getAreas()
.subscribe(function (response) {
_this.areas = _this.extractAreaKeyValue(response);
}, function (err) { return console.log(err); });
};
WorkItemDetailComponent.prototype.getIterations = function () {
var _this = this;
this.iterationService.getIterations()
.subscribe(function (iteration) {
_this.iterations = _this.extractIterationKeyValue(iteration);
}, function (err) { return console.log(err); });
};
WorkItemDetailComponent.prototype.onChangeState = function (option) {
var _this = this;
if (this.workItem.relationships.iteration) {
this.broadcaster.broadcast('wi_change_state', [{
workItem: this.workItem,
oldState: this.workItem.attributes['system.state'],
newState: option
}]);
// Item closed for an iteration
if (this.workItem.attributes['system.state'] !== option && option === 'closed') {
this.broadcaster.broadcast('wi_change_state_it', [{
iterationId: this.workItem.relationships.iteration.data.id,
closedItem: +1
}]);
}
// Item opened for an iteration
if (this.workItem.attributes['system.state'] == 'closed' && option != 'closes') {
this.broadcaster.broadcast('wi_change_state_it', [{
iterationId: this.workItem.relationships.iteration.data.id,
closedItem: -1
}]);
}
}
this.workItem.attributes['system.state'] = option;
if (this.workItem.id) {
var payload = cloneDeep(this.workItemPayload);
payload.attributes['system.state'] = option;
this.save(payload, true)
.subscribe(function (workItem) {
_this.workItem.attributes['system.state'] = workItem.attributes['system.state'];
// TODO : List update hack, should go away
_this.workItemRef.attributes['system.state'] = workItem.attributes['system.state'];
_this.updateOnList();
});
}
};
// onChangeType(type: any): void {
// this.workItem.relationships.baseType = {
// data: {
// id: type,
// type: 'workitemtypes'
// }
// };
// let payload = cloneDeep(this.workItemPayload);
// payload['relationships']['baseType'] = {
// data: {
// id: type,
// type: 'workitemtypes'
// }
// };
// this.save(payload);
// }
WorkItemDetailComponent.prototype.saveTitle = function (event) {
var _this = this;
var value = event.value.trim();
var callBack = event.callBack;
if (value === '') {
callBack(value, 'Empty title not allowed');
}
else if (this.workItem.attributes['system.title'] === value) {
callBack(value);
}
else {
this.workItem.attributes['system.title'] = value;
var payload = cloneDeep(this.workItemPayload);
payload.attributes['system.title'] = value;
this.save(payload, true)
.subscribe(function (workItem) {
_this.workItem.attributes['system.title'] = workItem.attributes['system.title'];
callBack(value);
// TODO: List update hack. should go away
_this.workItemRef.attributes['system.title'] = workItem.attributes['system.title'];
_this.updateOnList();
});
}
};
WorkItemDetailComponent.prototype.updateLabels = function (selectedLabels) {
var _this = this;
console.log('labels in WI detail >>>>', selectedLabels);
if (this.workItem.id) {
this.loadingLabels = true;
var payload = cloneDeep(this.workItemPayload);
payload = Object.assign(payload, {
relationships: {
labels: {
data: selectedLabels.map(function (label) {
return {
id: label.id,
type: label.type
};
})
}
}
});
this.save(payload, true)
.subscribe(function (workItem) {
_this.loadingLabels = false;
// Sort labels in alphabetical order
selectedLabels = selectedLabels.sort(function (labelA, labelB) {
var labelAName = labelA.attributes.name.toUpperCase();
var labelBName = labelB.attributes.name.toUpperCase();
return labelAName.localeCompare(labelBName);
});
_this.workItem.relationships.labels = {
data: selectedLabels
};
// TODO: List update hack. should go away
_this.workItemRef.relationships.labels = {
data: selectedLabels
};
_this.updateOnList();
});
}
else {
this.workItem.relationships.labels = {
data: selectedLabels
};
}
};
WorkItemDetailComponent.prototype.save = function (payload, returnObservable) {
var _this = this;
if (returnObservable === void 0) { returnObservable = false; }
var retObservable;
if (this.workItem.id) {
retObservable = this.workItemService
.update(payload)
.do(function (workItem) {
_this.workItemPayload.attributes['version'] =
_this.workItem.attributes['version'] =
workItem.attributes['version'];
})
.take(1)
.catch(function (error) {
_this.savingError = true;
_this.errorMessage = 'Something went wrong. Try again.';
if (error && error.status && error.statusText) {
_this.errorMessage = error.status + ' : ' + error.statusText + '. Try again.';
}
return Observable.throw(error);
});
}
else {
var t1_1 = performance.now();
if (this.validTitle) {
this.saving = true;
this.savingError = false;
retObservable = this.workItemService
.create(this.workItem)
.do(function (workItem) {
var queryParams = cloneDeep(_this.queryParams);
if (Object.keys(queryParams).indexOf('type') > -1) {
delete queryParams['type'];
}
_this.router.navigate([_this.router.url.split('/detail/')[0] + '/detail/' + workItem.id], { queryParams: queryParams });
_this.workItemService.emitAddWI(workItem);
_this.saving = false;
var t2 = performance.now();
console.log('Performance :: Detail add work item - ' + (t2 - t1_1) + ' milliseconds.');
})
.catch(function (error) {
_this.saving = false;
_this.savingError = true;
_this.errorMessage = 'Something went wrong. Try again.';
if (error && error.status && error.statusText) {
_this.errorMessage = error.status + ' : ' + error.statusText + '. Try again.';
}
return Observable.throw(error);
});
}
}
if (returnObservable) {
return retObservable;
}
else {
retObservable.subscribe();
}
};
WorkItemDetailComponent.prototype.createComment = function (comment) {
var _this = this;
this.workItemService
.createComment(this.workItem.relationships.comments.links.related, comment)
.subscribe(function (comment) {
comment.relationships['created-by'].data = _this.loggedInUser;
_this.workItem.relationships.comments.data.splice(0, 0, comment);
_this.workItem.relationships.comments.meta.totalCount += 1;
}, function (error) {
console.log(error);
});
};
WorkItemDetailComponent.prototype.updateComment = function (comment) {
// Nothing required here
};
WorkItemDetailComponent.prototype.deleteComment = function (comment) {
var _this = this;
this.workItemService
.deleteComment(comment)
.subscribe(function (response) {
if (response.status === 200) {
remove(_this.workItem.relationships.comments.data, function (cursor) {
if (!!comment) {
return cursor.id == comment.id;
}
});
}
}, function (err) { return console.log(err); });
};
WorkItemDetailComponent.prototype.removeLable = function (event) {
var labels = cloneDeep(this.workItem.relationships.labels.data);
var index = labels.indexOf(labels.find(function (l) { return l.id === event.id; }));
if (index > -1) {
labels.splice(index, 1);
this.updateLabels(labels);
}
};
WorkItemDetailComponent.prototype.closeDetails = function () {
};
WorkItemDetailComponent.prototype.listenToEvents = function () {
var _this = this;
this.eventListeners.push(this.broadcaster.on('logout')
.subscribe(function (message) {
_this.loggedIn = false;
_this.loggedInUser = null;
}));
if (this.loggedIn) {
this.eventListeners.push(this.userService.loggedInUser.subscribe(function (user) {
_this.loggedInUser = user;
}));
}
var id = null;
this.eventListeners.push(this.spaces.current.subscribe(function (space) {
_this.closePreview();
}));
};
WorkItemDetailComponent.prototype.preventDef = function (event) {
event.preventDefault();
};
WorkItemDetailComponent.prototype.activeSearchAssignee = function () {
var _this = this;
if (this.loggedIn) {
this.getAllUsers()
.subscribe(function (_a) {
var authUser = _a[0], allUsers = _a[1];
_this.users = allUsers;
_this.loggedInUser = authUser;
_this.users = _this.users.filter(function (user) {
return user.id !== authUser.id;
});
});
this.closeUserRestFields();
this.searchAssignee = true;
}
};
WorkItemDetailComponent.prototype.assignUser = function (users) {
var _this = this;
this.loadingAssignees = true;
this.closeUserRestFields();
if (this.workItem.id) {
this.selectedAssignees = users;
var payload = cloneDeep(this.workItemPayload);
payload = Object.assign(payload, {
relationships: {
assignees: {
data: this.selectedAssignees.map(function (assignee) {
return {
id: assignee.id,
type: 'identities'
};
})
}
}
});
this.save(payload, true)
.switchMap(function (workItem) { return _this.workItemService.resolveAssignees(workItem.relationships.assignees); })
.subscribe(function (assignees) {
_this.loadingAssignees = false;
_this.workItem.relationships.assignees = {
data: assignees
};
// TODO: List update hack. should go away
_this.workItemRef.relationships.assignees = {
data: assignees
};
_this.updateOnList();
});
}
else {
var assignees = users.map(function (user) {
return {
attributes: {
fullName: user.attributes.fullName
},
id: user.id,
type: 'identities'
};
});
this.workItem.relationships.assignees = {
data: assignees
};
}
//this.searchAssignee = false;
};
WorkItemDetailComponent.prototype.cancelAssignment = function () {
this.searchAssignee = false;
};
WorkItemDetailComponent.prototype.closeUserRestFields = function () {
this.searchAssignee = false;
if (this.workItem && this.workItem.id != null) {
this.headerEditable = false;
}
if (this.areaSelectbox && this.areaSelectbox.isOpen()) {
this.areaSelectbox.close();
}
if (this.iterationSelectbox && this.iterationSelectbox.isOpen()) {
this.iterationSelectbox.close();
}
};
WorkItemDetailComponent.prototype.iterationUpdated = function (iterationId) {
var _this = this;
if (iterationId === '0')
return; // Loading item
this.loadingIteration = true;
if (this.workItem.id) {
// Send out an iteration change event
var newIteration = iterationId;
var currenIterationID = this.workItem.relationships.iteration.data ? this.workItem.relationships.iteration.data.id : 0;
// If already closed iteration
if (this.workItem.attributes['system.state'] == 'closed') {
this.broadcaster.broadcast('wi_change_state_it', [{
iterationId: currenIterationID,
closedItem: -1
}, {
iterationId: newIteration,
closedItem: +1
}]);
}
var payload = cloneDeep(this.workItemPayload);
if (newIteration) {
payload = Object.assign(payload, {
relationships: {
iteration: {
data: {
id: iterationId,
type: 'iteration'
}
}
}
});
}
else {
payload = Object.assign(payload, {
relationships: {
iteration: {}
}
});
}
this.save(payload, true).subscribe(function (workItem) {
_this.loadingIteration = false;
_this.iterations.forEach(function (it) { return it.selected = it.key === iterationId; });
_this.workItem.relationships.iteration = workItem.relationships.iteration;
// TODO: List update hack. should go away
_this.workItemRef.relationships.iteration = workItem.relationships.iteration;
_this.updateOnList();
_this.logger.log('Iteration has been updated, sending event to iteration panel to refresh counts.');
_this.broadcaster.broadcast('associate_iteration', {
workItemId: workItem.id,
currentIterationId: _this.workItem.relationships.iteration.data ? _this.workItem.relationships.iteration.data.id : undefined,
futureIterationId: workItem.relationships.iteration.data ? workItem.relationships.iteration.data.id : undefined
});
});
}
else {
//creating a new work item - save the user input
var iteration_1 = {};
if (iterationId) {
iteration_1 = {
data: {
// Why do we need attribute for the relationship
// attributes: {
// name: this.findIterationById(iterationId).attributes.name
// },
id: iterationId,
type: 'iteration'
}
};
}
// Need setTimeout for typeahead drop down't change detection to work
setTimeout(function () {
_this.loadingIteration = false;
_this.iterations.forEach(function (it) { return it.selected = it.key === iterationId; });
_this.workItem.relationships.iteration = iteration_1;
});
}
};
WorkItemDetailComponent.prototype.extractAreaKeyValue = function (areas) {
var result = [];
var selectedFound = false;
var selectedAreaId;
if (this.workItem.relationships.area && this.workItem.relationships.area.data && this.workItem.relationships.area.data.id) {
selectedAreaId = this.workItem.relationships.area.data.id;
}
for (var i = 0; i < areas.length; i++) {
result.push({
key: areas[i].id,
value: (areas[i].attributes.parent_path_resolved != '/' ? areas[i].attributes.parent_path_resolved : '') + '/' + areas[i].attributes.name,
selected: selectedAreaId === areas[i].id ? true : false,
cssLabelClass: undefined
});
if (selectedAreaId === areas[i].id)
selectedFound = true;
}
;
return result;
};
WorkItemDetailComponent.prototype.extractIterationKeyValue = function (iterations) {
var result = [];
var selectedFound = false;
var selectedIterationId;
if (this.workItem.relationships.iteration && this.workItem.relationships.iteration.data && this.workItem.relationships.iteration.data.id) {
selectedIterationId = this.workItem.relationships.iteration.data.id;
}
for (var i = 0; i < iterations.length; i++) {
result.push({
key: iterations[i].id,
value: (iterations[i].attributes.resolved_parent_path != '/' ? iterations[i].attributes.resolved_parent_path : '') + '/' + iterations[i].attributes.name,
selected: selectedIterationId === iterations[i].id ? true : false,
cssLabelClass: undefined
});
if (selectedIterationId === iterations[i].id)
selectedFound = true;
}
;
return result;
};
// findIterationById(iterationId: string): IterationModel {
// for (let i=0; i<this.iterations.length; i++)
// if (this.iterations[i].id === iterationId)
// return this.iterations[i];
// return null;
// }
WorkItemDetailComponent.prototype.focusArea = function () {
this.iterationSelectbox.close();
this.cancelAssignment();
this.areas = this.areas.concat([
{
key: '0',
value: '',
selected: false,
cssLabelClass: 'spinner spinner-sm spinner-inline'
}
]);
this.getAreas();
};
WorkItemDetailComponent.prototype.focusIteration = function () {
this.areaSelectbox.close();
this.cancelAssignment();
this.iterations = this.iterations.concat([
{
key: '0',
value: '',
selected: false,
cssLabelClass: 'spinner spinner-sm spinner-inline'
}
]);
this.getIterations();
};
WorkItemDetailComponent.prototype.areaUpdated = function (areaId) {
var _this = this;
this.loadingArea = true;
if (this.workItem.id) {
var payload = cloneDeep(this.workItemPayload);
if (areaId) {
// area was set to a value.
payload = Object.assign(payload, {
relationships: {
area: {
data: {
id: areaId,
type: 'area'
}
}
}
});
}
else {
// area was unset.
payload = Object.assign(payload, {
relationships: {
area: {}
}
});
}
this.save(payload, true)
.subscribe(function (workItem) {
_this.loadingArea = false;
_this.areas.forEach(function (area) { return area.selected = area.key === areaId; });
_this.workItem.relationships.area = workItem.relationships.area;
// TODO: List update hack. should go away
_this.workItemRef.relationships.area = workItem.relationships.area;
_this.updateOnList();
});
}
else {
var area_1 = {};
if (areaId) {
// area was set to a value.
var area_2 = {
data: {
id: areaId,
type: 'area'
}
};
}
;
// Need setTimeout for typeahead drop down't change detection to work
setTimeout(function () {
_this.loadingArea = false;
_this.areas.forEach(function (area) { return area.selected = area.key === areaId; });
_this.workItem.relationships.area = area_1;
});
}
};
WorkItemDetailComponent.prototype.constructUrl = function (workItem) {
return this.router.url.split('plan')[0] + 'plan/detail/' + workItem.attributes['system.number'];
};
WorkItemDetailComponent.prototype.onLabelClick = function (event) {
var params = {
label: event.attributes.name
};
// Prepare navigation extra with query params
var navigationExtras = {
queryParams: params
};
// Navigated to filtered view
this.router.navigate([], navigationExtras);
};
WorkItemDetailComponent.prototype.onKeyEvent = function (event) {
event = (event || window.event);
// for ESC key handling
if (event.keyCode == 27) {
try {
event.preventDefault(); //Non-IE
}
catch (x) {
event.returnValue = false; //IE
}
if (this.headerEditable) {
this.closeHeader();
}
else if (this.searchAssignee) {
this.searchAssignee = false;
}
else if (this.areaSelectbox && this.areaSelectbox.isOpen()) {
this.areaSelectbox.close();
}
else if (this.iterationSelectbox && this.iterationSelectbox.isOpen()) {
this.iterationSelectbox.close();
}
else {
this.closePreview();
}
}
};
WorkItemDetailComponent.prototype.onOpen = function (event) {
this.onOpenSelector.emit('open');
};
WorkItemDetailComponent.prototype.onClose = function (event) {
this.onCloseSelector.emit(cloneDeep(this.selectedLabels));
};
WorkItemDetailComponent.prototype.openDropdown = function () {
this.dropdownRef.openDropdown();
};
WorkItemDetailComponent.prototype.closeDropdown = function () {
this.dropdownRef.closeDropdown();
};
WorkItemDetailComponent.prototype.closeAddAssignee = function () {
this.activeAddAssignee = false;
};
WorkItemDetailComponent.decorators = [
{ type: Component, args: [{
selector: 'work-item-preview',
template: require('./work-item-detail.component.html'),
styles: [require('./work-item-detail.component.css').toString()],
animations: [
trigger('slideInOut', [
state('in', style({
transform: 'translateX(5px)',
left: 'auto'
})),
state('out', style({
transform: 'translateX(100%)',
left: '100%'
})),
transition('in => out', animate('400ms ease-in-out')),
transition('out => in', animate('400ms ease-in-out'))
]),
]
},] },
];
/** @nocollapse */
WorkItemDetailComponent.ctorParameters = function () { return [
{ type: AreaService, },
{ type: AuthenticationService, },
{ type: Broadcaster, },
{ type: LabelService, },
{ type: WorkItemService, },
{ type: WorkItemDataService, },
{ type: ActivatedRoute, },
{ type: Location, },
{ type: Logger, },
{ type: Router, },
{ type: IterationService, },
{ type: UserService, },
{ type: WorkItemTypeControlService, },
{ type: Spaces, },
{ type: CollaboratorService, },
{ type: Store, },
]; };
WorkItemDetailComponent.propDecorators = {
'title': [{ type: ViewChild, args: ['title',] },],
'userList': [{ type: ViewChild, args: ['userList',] },],
'dropdownButton': [{ type: ViewChild, args: ['dropdownButton',] },],
'areaSelectbox': [{ type: ViewChild, args: ['areaSelectbox',] },],
'iterationSelectbox': [{ type: ViewChild, args: ['iterationSelectbox',] },],
'labelSelector': [{ type: ViewChild, args: ['labelSelector',] },],
'assignee': [{ type: ViewChild, args: ['assignee',] },],
'labelnameInput': [{ type: ViewChild, args: ['labelname',] },],
'dropdownRef': [{ type: ViewChild, args: ['dropdown',] },],
'AssigneeSelector': [{ type: ViewChild, args: ['AssigneeSelector',] },],
'selectedLabels': [{ type: Input },],
'selectedAssignees': [{ type: Input },],
'onOpenSelector': [{ type: Output },],
'onCloseSelector': [{ type: Output },],
'onClick': [{ type: HostListener, args: ['document:click', ['$event.target', '$event.target.classList.contains(' + '"assigned_user"' + ')'],] },],
'onKeyEvent': [{ type: HostListener, args: ['window:keydown', ['$event'],] },],
};
return WorkItemDetailComponent;
}());
export { WorkItemDetailComponent };
//# sourceMappingURL=work-item-detail.component.js.map