UNPKG

my-test123

Version:
994 lines 43.5 kB
import { Component, Input, Output, ViewChild, EventEmitter, Renderer2, HostListener } from '@angular/core'; import { ActivatedRoute, Router, NavigationStart } from '@angular/router'; import { Broadcaster } from 'ngx-base'; import { cloneDeep, merge, remove } from 'lodash'; import { Spaces } from 'ngx-fabric8-wit'; import { Observable } from 'rxjs'; import { AreaService } from './../../services/area.service'; import { IterationService } from './../../services/iteration.service'; import { LabelService } from './../../services/label.service'; import { WorkItemTypeControlService } from './../../services/work-item-type-control.service'; import { WorkItemDataService } from './../../services/work-item-data.service'; import { ModalService } from '../../services/modal.service'; import { UrlService } from './../../services/url.service'; import { WorkItem, WorkItemRelations } from './../../models/work-item'; import { WorkItemService } from './../../services/work-item.service'; import { CollaboratorService } from '../../services/collaborator.service'; import { AuthenticationService, UserService } from 'ngx-login-client'; var WorkItemNewDetailComponent = /** @class */ (function () { function WorkItemNewDetailComponent(areaService, auth, broadcaster, collaboratorService, iterationService, labelService, route, router, spaces, userService, urlService, workItemService, workItemDataService, workItemTypeControlService, renderer, modalService) { this.areaService = areaService; this.auth = auth; this.broadcaster = broadcaster; this.collaboratorService = collaboratorService; this.iterationService = iterationService; this.labelService = labelService; this.route = route; this.router = router; this.spaces = spaces; this.userService = userService; this.urlService = urlService; this.workItemService = workItemService; this.workItemDataService = workItemDataService; this.workItemTypeControlService = workItemTypeControlService; this.renderer = renderer; this.modalService = modalService; this.selectedLabels = []; this.selectedAssignees = []; this.onOpenSelector = new EventEmitter(); this.onCloseSelector = new EventEmitter(); this.areas = []; this.comments = []; this.iterations = []; this.eventListeners = []; this.loadingComments = true; this.loadingTypes = false; this.loadingIteration = false; this.loadingArea = false; this.loadingLabels = false; this.loadingAssignees = false; this.loggedIn = false; this.users = []; this.filteredUsers = []; this.usersLoaded = false; this.searchAssignee = false; this.headerEditable = false; this.descText = ''; this.labels = []; this.activeAddAssignee = false; } WorkItemNewDetailComponent.prototype.onClick = function (targetElement, assigned_user) { var clickedInsidePopup = this.assignee.nativeElement.contains(targetElement); if (!clickedInsidePopup && !assigned_user) { this.cancelAssignment(); } }; WorkItemNewDetailComponent.prototype.ngOnInit = function () { var _this = this; this.loggedIn = this.auth.isLoggedIn(); var takeUntilObserver = this.router.events .filter(function (event) { return event instanceof NavigationStart; }) .filter(function (event) { return event.url.indexOf('plan/detail') == -1; }); this.eventListeners.push(this.spaces.current.switchMap(function (space) { return _this.route.params; }) .filter(function (params) { return params['id'] !== undefined; }) .takeUntil(takeUntilObserver) .subscribe(function (params) { var workItemId = params['id']; if (workItemId === 'new') { // Create new work item ID // you can add type, iteration and area GET params to the url to preselect values var type = _this.route.snapshot.queryParams['type']; var iteration = _this.route.snapshot.queryParams['iteration']; var area = _this.route.snapshot.queryParams['area']; _this.createWorkItemObj(type, iteration, area); } else if (workItemId.split('-').length > 1) { // The ID is a UUID // To make it backword compaitable // We find the number and redirect // the URL to the new humna readable URL _this.workItemService.getWorkItemByNumber(workItemId) .subscribe(function (workItem) { var urlSplit = location.pathname.split('/'); urlSplit[urlSplit.length - 1] = workItem.attributes['system.number']; var redirectTo = urlSplit.join('/'); _this.router.navigateByUrl(redirectTo); }); } else { if (Object.keys(params).indexOf('entity') > -1 && Object.keys(params).indexOf('space') > -1) { console.log('Work item ID: ', workItemId); _this.loadWorkItem(workItemId, params['entity'], params['space']); } else { console.log('Work item ID: ', workItemId); _this.loadWorkItem(workItemId); } } })); this.listenToEvents(); }; WorkItemNewDetailComponent.prototype.ngOnDestroy = function () { console.log('Destroying all the listeners in detail component'); this.eventListeners.forEach(function (subscriber) { return subscriber.unsubscribe(); }); document.getElementsByTagName('body')[0].style.overflow = "auto"; }; WorkItemNewDetailComponent.prototype.ngAfterViewChecked = function () { if (this.detailHeader) { var HdrDivHeight = this.detailHeader.nativeElement.offsetHeight; var targetHeight = window.innerHeight - HdrDivHeight - 90; this.renderer.setStyle(this.detailContent.nativeElement, 'height', targetHeight + "px"); } if (document.getElementsByTagName('body')) { document.getElementsByTagName('body')[0].style.overflow = "hidden"; } }; WorkItemNewDetailComponent.prototype.onResize = function (event) { }; WorkItemNewDetailComponent.prototype.createWorkItemObj = function (type, iterationId, areaId) { var _this = this; this.workItem = new WorkItem(); this.workItem.id = null; this.workItem.attributes = new Map(); this.workItem.attributes['system.title'] = ''; 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' } } }; // create base empty relationship structure this.workItem.relationships = Object.assign(this.workItem.relationships, {}); // Add creator this.userService.getUser() .subscribe(function (user) { _this.workItem.relationships.creator = { data: user }; }, function (err) { return console.log(err); }); // if the iteration is given, add the iteration if (iterationId) { this.iterationService.getIterationById(iterationId) .subscribe(function (iteration) { // update the iteration value list _this.getIterations(); // select the returned iteration in that list _this.iterations.forEach(function (thisIteration) { return thisIteration.selected = thisIteration.key === iteration.id; }); // set the value on the model _this.workItem.relationships.iteration = { data: iteration }; }, function (err) { return console.log(err); }); } // if the area is given, add the area if (areaId) { this.areaService.getAreaById(areaId) .subscribe(function (area) { // update the area value list _this.getAreas(); // select the returned area in that list _this.areas.forEach(function (thisArea) { return thisArea.selected = thisArea.key === area.id; }); // set the value on the model _this.workItem.relationships.area = { data: area }; }, function (err) { return console.log(err); }); } this.workItem.relationalData = {}; this.workItemService.resolveType(this.workItem); this.workItem.attributes['system.state'] = 'new'; }; WorkItemNewDetailComponent.prototype.loadWorkItem = function (id, owner, space) { var _this = this; if (owner === void 0) { owner = ''; } if (space === void 0) { space = ''; } var t1 = performance.now(); this.eventListeners.push(this.workItemDataService.getItembyNumber(id) .do(function (workItem) { if (workItem) { _this.workItem = workItem; var t2 = performance.now(); console.log('Performance :: Details page first paint (local data) - ' + (t2 - t1) + ' milliseconds.'); } }) .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, owner, space); }) .do(function (workItem) { _this.workItem = workItem; _this.workItemDataService.setItem(workItem); // Open the panel once work item is ready var t2 = performance.now(); console.log('Performance :: Details page first paint - ' + (t2 - t1) + ' milliseconds.'); }) .do(function (workItem) { return console.log('Work item fetched: ', 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) { //setTimeout(() => this.itemSubscription.unsubscribe()); // this.closeDetails(); })); }; WorkItemNewDetailComponent.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; }); }; WorkItemNewDetailComponent.prototype.resolveAssignees = function () { var _this = this; this.activeSearchAssignee(); return this.workItemService.resolveAssignees(this.workItem.relationships.assignees) .do(function (assignees) { // Resolve assignees _this.workItem.relationships.assignees = { data: assignees }; _this.loadingAssignees = false; console.log("RESOLVE"); }); }; WorkItemNewDetailComponent.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 }; }); }; WorkItemNewDetailComponent.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; }); }; WorkItemNewDetailComponent.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; }); }; WorkItemNewDetailComponent.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); }); }); }; WorkItemNewDetailComponent.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; }); }; WorkItemNewDetailComponent.prototype.resolveLabels = function () { var _this = this; return this.labelService.getLabels() .do(function (labels) { _this.loadingLabels = false; _this.labels = 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: [] }; } }); }; WorkItemNewDetailComponent.prototype.onLabelSelectorOpen = function (event) { var _this = this; if (!this.workItem.id) { this.labelService.getLabels() .subscribe(function (labels) { return _this.labels = labels; }); } }; WorkItemNewDetailComponent.prototype.onAssigneeSelectorOpen = function (event) { console.log("Dropdown open"); }; WorkItemNewDetailComponent.prototype.getAllUsers = function () { return Observable.combineLatest(this.userService.getUser(), this.collaboratorService.getCollaborators()); }; WorkItemNewDetailComponent.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; }; WorkItemNewDetailComponent.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; }; WorkItemNewDetailComponent.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; if (this.workItem.id) { 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); }); } else { var payload = cloneDeep(this.workItem); payload.attributes['system.title'] = value; this.save(payload, true) .subscribe(function () { callBack(value); }, function (err) { console.log(err); callBack(value, 'Something went wrong'); }); } } }; WorkItemNewDetailComponent.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) { return Observable.throw(error); }); } else { var t1_1 = performance.now(); if (this.workItem.attributes['system.title']) { retObservable = this.workItemService .create(this.workItem) .do(function (workItem) { var queryParams = cloneDeep(_this.route.snapshot.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); var t2 = performance.now(); console.log('Performance :: Detail add work item - ' + (t2 - t1_1) + ' milliseconds.'); }) .catch(function (error) { return Observable.throw(error); }); } } if (returnObservable) { return retObservable; } else { retObservable.subscribe(); } }; WorkItemNewDetailComponent.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']; // this.updateOnList(); }); } }; WorkItemNewDetailComponent.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; })); } }; WorkItemNewDetailComponent.prototype.updateOnList = function () { this.workItemService.emitEditWI(this.workItem); }; WorkItemNewDetailComponent.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.filteredUsers = _this.users; _this.usersLoaded = true; }); this.closeUserRestFields(); this.searchAssignee = true; // Takes a while to render the component setTimeout(function () { if (_this.userSearch) { _this.userSearch.nativeElement.focus(); } }, 50); } }; WorkItemNewDetailComponent.prototype.deactiveSearchAssignee = function () { this.closeUserRestFields(); }; WorkItemNewDetailComponent.prototype.assignUser = function (users) { var _this = this; this.loadingAssignees = true; 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 }; _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 }; console.log("STEP 3"); } //this.searchAssignee = false; }; WorkItemNewDetailComponent.prototype.updateLabels = function (selectedLabels) { var _this = this; 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) { // 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 }; _this.loadingLabels = false; }); } else { this.workItem.relationships.labels = { data: selectedLabels }; } }; WorkItemNewDetailComponent.prototype.cancelAssignment = function () { this.searchAssignee = false; }; WorkItemNewDetailComponent.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(); } }; WorkItemNewDetailComponent.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); }); }; WorkItemNewDetailComponent.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); } }; WorkItemNewDetailComponent.prototype.updateComment = function (comment) { // Nothing required here }; WorkItemNewDetailComponent.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); }); }; WorkItemNewDetailComponent.prototype.getAreas = function () { var _this = this; this.areaService.getAreas() .subscribe(function (response) { _this.areas = _this.extractAreaKeyValue(response); }, function (err) { return console.log(err); }); }; WorkItemNewDetailComponent.prototype.getIterations = function () { var _this = this; this.iterationService.getIterations() .subscribe(function (iteration) { _this.iterations = _this.extractIterationKeyValue(iteration); }, function (err) { return console.log(err); }); }; WorkItemNewDetailComponent.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(); }; WorkItemNewDetailComponent.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(); }; WorkItemNewDetailComponent.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; _this.updateOnList(); }); } else { var area = {}; if (areaId) { // area was set to a value. area = { data: { id: areaId, type: 'area' } }; } ; this.workItem.relationships.area = 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; }); }); } }; WorkItemNewDetailComponent.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; _this.updateOnList(); _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 = {}; if (iterationId) { iteration = { data: { // Why do we need attribute for the relationship // attributes: { // name: this.findIterationById(iterationId).attributes.name // }, id: iterationId, type: 'iteration' } }; } this.workItem.relationships.iteration = 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; }); }); } }; WorkItemNewDetailComponent.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']; _this.updateOnList(); }); } else { this.workItem.attributes['system.description'] = this.descText.trim(); this.workItem.attributes['system.description.markup'] = 'Markdown'; this.workItemService.renderMarkDown(this.workItem.attributes['system.description']).subscribe(function (rendered) { callBack(_this.workItem.attributes['system.description'], rendered); }); } }; WorkItemNewDetailComponent.prototype.showPreview = function (event) { var rawText = event.rawText; var callBack = event.callBack; this.workItemService.renderMarkDown(rawText) .subscribe(function (renderedHtml) { callBack(rawText, renderedHtml); }); }; WorkItemNewDetailComponent.prototype.navigateBack = function () { if (this.urlService.getLastListOrBoard() === '') { this.router.navigate(['../..'], { relativeTo: this.route }); } else { this.router.navigateByUrl(this.urlService.getLastListOrBoard()); } }; WorkItemNewDetailComponent.prototype.onLabelClick = function (label) { if (this.urlService.getLastListOrBoard() === '') { var params = { label: label.attributes.name }; // Prepare navigation extra with query params var navigationExtras = { relativeTo: this.route, queryParams: params }; this.router.navigate(['../..'], navigationExtras); } else { var url = this.urlService.getLastListOrBoard().split('?')[0] + '?label=' + label.attributes.name; this.router.navigateByUrl(url); } }; WorkItemNewDetailComponent.prototype.openDropdown = function () { this.dropdownRef.openDropdown(); }; WorkItemNewDetailComponent.prototype.closeDropdown = function () { this.dropdownRef.closeDropdown(); }; WorkItemNewDetailComponent.prototype.closeAddAssignee = function () { this.activeAddAssignee = false; }; WorkItemNewDetailComponent.decorators = [ { type: Component, args: [{ selector: 'work-item-new-detail', template: require('./work-item-new-detail.component.html'), styles: [require('./work-item-new-detail.component.css').toString()] },] }, ]; /** @nocollapse */ WorkItemNewDetailComponent.ctorParameters = function () { return [ { type: AreaService, }, { type: AuthenticationService, }, { type: Broadcaster, }, { type: CollaboratorService, }, { type: IterationService, }, { type: LabelService, }, { type: ActivatedRoute, }, { type: Router, }, { type: Spaces, }, { type: UserService, }, { type: UrlService, }, { type: WorkItemService, }, { type: WorkItemDataService, }, { type: WorkItemTypeControlService, }, { type: Renderer2, }, { type: ModalService, }, ]; }; WorkItemNewDetailComponent.propDecorators = { 'userSearch': [{ type: ViewChild, args: ['userSearch',] },], 'areaSelectbox': [{ type: ViewChild, args: ['areaSelectbox',] },], 'iterationSelectbox': [{ type: ViewChild, args: ['iterationSelectbox',] },], 'userList': [{ type: ViewChild, args: ['userList',] },], 'detailHeader': [{ type: ViewChild, args: ['detailHeader',] },], 'detailContent': [{ type: ViewChild, args: ['detailContent',] },], 'assignee': [{ type: ViewChild, args: ['assignee',] },], '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"' + ')'],] },], 'onResize': [{ type: HostListener, args: ['window:resize', ['$event'],] },], }; return WorkItemNewDetailComponent; }()); export { WorkItemNewDetailComponent }; //# sourceMappingURL=work-item-new-detail.component.js.map