my-test123
Version:
A planner front-end for Fabric8.
289 lines • 12.8 kB
JavaScript
import { ActivatedRoute } from '@angular/router';
import { Component, Input, ViewChild, ViewEncapsulation } from '@angular/core';
import { Broadcaster, Logger, NotificationType, Notifications } from 'ngx-base';
import { AuthenticationService } from 'ngx-login-client';
import { IterationService } from '../../services/iteration.service';
import { WorkItemService } from '../../services/work-item.service';
import { FilterService } from './../../services/filter.service';
// ngrx stuff
import { Store } from '@ngrx/store';
import * as IterationActions from './../../actions/iteration.actions';
var IterationComponent = /** @class */ (function () {
function IterationComponent(log, auth, broadcaster, filterService, iterationService, notifications, route, workItemService, store) {
this.log = log;
this.auth = auth;
this.broadcaster = broadcaster;
this.filterService = filterService;
this.iterationService = iterationService;
this.notifications = notifications;
this.route = route;
this.workItemService = workItemService;
this.store = store;
this.takeFromInput = false;
this.iterations = [];
this.collection = [];
this.sidePanelOpen = true;
this.witGroup = '';
this.showTree = '';
this.authUser = null;
this.loggedIn = true;
this.editEnabled = false;
this.barchatValue = 70;
this.allIterations = [];
this.eventListeners = [];
this.treeIterations = [];
this.activeIterations = [];
this.spaceId = '';
this.startedCheckingURL = false;
this.spaceSubscription = null;
}
IterationComponent.prototype.ngOnInit = function () {
var _this = this;
this.listenToEvents();
this.loggedIn = this.auth.isLoggedIn();
this.editEnabled = true;
this.selectedIteration = {};
this.spaceSubscription = this.store
.select('listPage')
.select('space')
.subscribe(function (space) {
if (space) {
console.log('[IterationComponent] New Space selected: ' + space.attributes.name);
console.log('collection is ', _this.collection);
_this.spaceId = space.id;
_this.editEnabled = true;
_this.getAndfilterIterations();
}
else {
console.log('[IterationComponent] Space deselected.');
_this.editEnabled = false;
_this.allIterations = [];
_this.activeIterations = [];
}
});
};
IterationComponent.prototype.ngOnChanges = function () {
if (this.takeFromInput) {
// do not display the root iteration on the iteration panel.
this.allIterations = [];
for (var i = 0; i < this.iterations.length; i++) {
if (!this.iterationService.isRootIteration(this.iterations[i].parentPath)) {
this.allIterations.push(this.iterations[i]);
}
}
this.clusterIterations();
this.treeIterations = this.iterationService.getTopLevelIterations2(this.allIterations);
}
};
IterationComponent.prototype.ngOnDestroy = function () {
// prevent memory leak when component is destroyed
this.spaceSubscription.unsubscribe();
this.eventListeners.forEach(function (subscriber) { return subscriber.unsubscribe(); });
};
IterationComponent.prototype.constructURL = function (iterationId) {
//Query for work item type group
var type_query = this.filterService.queryBuilder('typegroup.name', this.filterService.equal_notation, this.witGroup);
//Query for space
var space_query = this.filterService.queryBuilder('space', this.filterService.equal_notation, this.spaceId);
//Query for iteration
var iteration_query = this.filterService.queryBuilder('iteration', this.filterService.equal_notation, iterationId);
//Join type and space query
var first_join = this.filterService.queryJoiner({}, this.filterService.and_notation, space_query);
var second_join = this.filterService.queryJoiner(first_join, this.filterService.and_notation, type_query);
var third_join = this.filterService.queryJoiner(second_join, this.filterService.and_notation, iteration_query);
//this.setGroupType(witGroup);
//second_join gives json object
return this.filterService.jsonToQuery(third_join);
};
IterationComponent.prototype.getAndfilterIterations = function () {
var _this = this;
if (this.takeFromInput) {
// do not display the root iteration on the iteration panel.
this.allIterations = [];
for (var i = 0; i < this.iterations.length; i++) {
if (!this.iterationService.isRootIteration(this.iterations[i].parentPath)) {
this.allIterations.push(this.iterations[i]);
}
}
this.clusterIterations();
this.treeIterations =
this.iterationService.getTopLevelIterations2(this.allIterations);
}
else {
this.eventListeners.push(this.store
.select('listPage')
.select('iterations')
.filter(function (iterations) { return !!iterations.length; })
.subscribe(function (iterations) {
// do not display the root iteration on the iteration panel.
_this.allIterations = iterations.filter(function (i) {
return !_this.iterationService.isRootIteration(i.parentPath);
});
_this.clusterIterations();
_this.treeIterations =
_this.iterationService.getTopLevelIterations2(_this.allIterations);
if (!_this.startedCheckingURL) {
_this.checkURL();
}
}, function (e) {
console.log('Some error has occured', e);
}));
}
};
IterationComponent.prototype.clusterIterations = function () {
this.activeIterations = this.allIterations.filter(function (iteration) { return iteration.isActive; });
};
IterationComponent.prototype.updateItemCounts = function () {
// this.log.log('Updating item counts..');
// this.iterationService.getIterations().first().subscribe((updatedIterations: IterationUI[]) => {
// // updating the counts from the response. May not the best solution on performance right now.
// updatedIterations.forEach((thisIteration:IterationUI) => {
// for (let i=0; i<this.iterations.length; i++) {
// if (this.iterations[i].id === thisIteration.id) {
// this.iterations[i].workItemTotalCount = thisIteration.workItemTotalCount;
// this.iterations[i].workItemClosedCount = thisIteration.workItemClosedCount;
// }
// }
// });
// }, err => console.log(err));
};
IterationComponent.prototype.assignWIToIteration = function (workItemId, reqVersion, iterationID, selfLink) {
var _this = this;
var workItemPayload = {
id: workItemId,
type: 'workitems',
attributes: {
'version': reqVersion
},
relationships: {
iteration: {
data: {
id: iterationID,
type: 'iteration'
}
}
},
links: {
self: selfLink
}
};
this.workItemService.update(workItemPayload)
.switchMap(function (item) {
return _this.iterationService.getIteration(item.relationships.iteration)
.map(function (iteration) {
item.relationships.iteration.data = iteration;
return item;
});
})
.subscribe(function (workItem) {
_this.iterationService.emitDropWI(workItem);
_this.updateItemCounts();
try {
_this.notifications.message({
message: workItem.attributes['system.title'] + ' has been associated with ' + workItem.relationships.iteration.data.attributes['name'],
type: NotificationType.SUCCESS
});
}
catch (error) {
console.log('Error in displaying notification. work item associated with iteration.');
}
}, function (err) {
_this.iterationService.emitDropWI(workItemPayload, true);
try {
_this.notifications.message({
message: 'Something went wrong. Please try again',
type: NotificationType.DANGER
});
}
catch (error) {
console.log('Error in displaying notification. Error in work item association with iteration.');
}
});
};
IterationComponent.prototype.kebabMenuClick = function (event) {
event.stopPropagation();
};
IterationComponent.prototype.onEdit = function (iteration) {
this.modal.openCreateUpdateModal('update', iteration);
};
IterationComponent.prototype.onClose = function (iteration) {
this.modal.openCreateUpdateModal('close', iteration);
};
IterationComponent.prototype.onCreateChild = function (iteration) {
this.modal.openCreateUpdateModal('createChild', iteration);
};
IterationComponent.prototype.listenToEvents = function () {
var _this = this;
this.eventListeners.push(this.broadcaster.on('backlog_selected')
.subscribe(function (message) {
_this.selectedIteration = null;
}));
this.eventListeners.push(this.broadcaster.on('logout')
.subscribe(function (message) {
_this.loggedIn = false;
_this.authUser = null;
}));
this.eventListeners.push(this.broadcaster.on('wi_change_state_it')
.subscribe(function (actions) {
_this.updateItemCounts();
}));
this.eventListeners.push(this.broadcaster.on('associate_iteration')
.subscribe(function (data) {
_this.updateItemCounts();
}));
this.eventListeners.push(this.broadcaster.on('create_workitem')
.subscribe(function (data) {
_this.updateItemCounts();
}));
};
IterationComponent.prototype.checkURL = function () {
var _this = this;
this.startedCheckingURL = true;
this.eventListeners.push(this.route.queryParams.subscribe(function (val) {
if (val.hasOwnProperty('q')) {
var selectedIterationID_1 = _this.filterService.getConditionFromQuery(val.q, 'iteration');
if (selectedIterationID_1 !== undefined) {
var selectedIteration = _this.allIterations.find(function (it) { return it.id === selectedIterationID_1; });
if (!selectedIteration.selected) {
_this.store.dispatch(new IterationActions.Select(selectedIteration));
}
}
else {
_this.store.dispatch(new IterationActions.Select());
}
}
}));
};
IterationComponent.decorators = [
{ type: Component, args: [{
encapsulation: ViewEncapsulation.None,
selector: 'fab-planner-iteration',
template: require('./iterations-panel.component.html'),
styles: [require('./iterations-panel.component.css').toString()]
},] },
];
/** @nocollapse */
IterationComponent.ctorParameters = function () { return [
{ type: Logger, },
{ type: AuthenticationService, },
{ type: Broadcaster, },
{ type: FilterService, },
{ type: IterationService, },
{ type: Notifications, },
{ type: ActivatedRoute, },
{ type: WorkItemService, },
{ type: Store, },
]; };
IterationComponent.propDecorators = {
'takeFromInput': [{ type: Input },],
'iterations': [{ type: Input },],
'collection': [{ type: Input },],
'sidePanelOpen': [{ type: Input },],
'witGroup': [{ type: Input },],
'showTree': [{ type: Input },],
'modal': [{ type: ViewChild, args: ['modal',] },],
};
return IterationComponent;
}());
export { IterationComponent };
//# sourceMappingURL=iterations-panel.component.js.map