fabric8-planner
Version:
A planner front-end for Fabric8.
83 lines • 3.2 kB
JavaScript
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import { HttpClientService } from './../shared/http-module/http.service';
var IterationService = /** @class */ (function () {
function IterationService(http) {
this.http = http;
}
/**
* getIteration - We call this service method to fetch
* @param iterationUrl - The url to get all the iteration
* @return Promise of IterationModel[] - Array of iterations.
*/
IterationService.prototype.getIterations = function (iterationUrl) {
var _this = this;
return this.http
.get(iterationUrl)
.pipe(map(function (r) { return r.data; }), map(function (d) { return _this.resolveChildren(d); }));
};
/**
* Create new iteration
* @param iterationUrl - POST url
* @param iteration - data to create a new iteration
* @return new item
*/
IterationService.prototype.createIteration = function (url, iteration) {
console.log('Create on iteration service.');
return this.http.post(url, { data: iteration })
.pipe(map(function (r) { return r.data; }));
};
/**
* Update an existing iteration
* @param iteration - Updated iteration
* @return updated iteration's reference from the list
*/
IterationService.prototype.updateIteration = function (iteration) {
console.log('Update on iteration service.');
return this.http
.patch(iteration.links.self, { data: iteration })
.pipe(map(function (r) { return r.data; }));
};
IterationService.prototype.isRootIteration = function (parentPath) {
return parentPath === '/';
};
/**
* usage - Finds the children of an iteration
* @param parent
* @param iterations
*/
IterationService.prototype.checkForChildIterations = function (parent, iterations) {
return iterations.filter(function (i) { return i.relationships.parent ? parent.id === i.relationships.parent.data.id : false; });
};
/**
* takes all the iterations and resolve the children
* @param data
*/
IterationService.prototype.resolveChildren = function (iterations) {
var _this = this;
return iterations.map(function (iteration) {
var childIterations = _this.checkForChildIterations(iteration, iterations);
if (childIterations.length > 0) {
iteration.hasChildren = true;
iteration.children = childIterations;
}
return iteration;
});
};
IterationService.prototype.getTopLevelIterations = function (iterations) {
var topLevelIterations = iterations.filter(function (iteration) {
return ((iteration.parentPath.split('/')).length - 1) === 1;
});
return topLevelIterations;
};
IterationService.decorators = [
{ type: Injectable },
];
/** @nocollapse */
IterationService.ctorParameters = function () { return [
{ type: HttpClientService, },
]; };
return IterationService;
}());
export { IterationService };
//# sourceMappingURL=iteration.service.js.map