my-test123
Version:
A planner front-end for Fabric8.
126 lines • 5.42 kB
JavaScript
import { GlobalSettings } from '../shared/globals';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { Logger } from 'ngx-base';
import { AuthenticationService } from 'ngx-login-client';
import { HttpService } from './http-service';
import { Spaces } from 'ngx-fabric8-wit';
var GroupTypesService = /** @class */ (function () {
function GroupTypesService(logger, http, auth, globalSettings, spaces) {
var _this = this;
this.logger = logger;
this.http = http;
this.auth = auth;
this.globalSettings = globalSettings;
this.spaces = spaces;
this.groupTypes = [];
this.headers = new Headers({ 'Content-Type': 'application/json' });
this.selectedGroupType = [];
this.groupTypeSelected = new Subject();
this.workItemSelected = new Subject();
this.groupName = '';
this.spaces.current.subscribe(function (val) { return _this._currentSpace = val; });
}
GroupTypesService.prototype.getGroupTypes = function () {
var _this = this;
return this.spaces.current.take(1).switchMap(function (space) {
var workitemtypesUrl = space.relationships.workitemtypegroups.links.related;
return _this.http
.get(workitemtypesUrl)
.map(function (response) {
if (/^[5, 4][0-9]/.test(response.status.toString())) {
throw new Error('API error occured');
}
_this.groupTypes = response.json().data;
_this.setCurrentGroupType(_this.groupTypes[0].relationships.typeList.data, _this.groupTypes[0].attributes.name);
return _this.groupTypes;
})
.catch(function (error) {
if (error.status === 401) {
//this.notifyError('You have been logged out.', error);
_this.auth.logout();
}
else {
console.log('Fetch iteration API returned some error - ', error.message);
//this.notifyError('Fetching iterations has from server has failed.', error);
}
return Observable.throw(new Error(error.message));
});
});
};
GroupTypesService.prototype.getGroupTypes2 = function (url) {
var _this = this;
return this.http
.get(url)
.map(function (response) {
if (/^[5, 4][0-9]/.test(response.status.toString())) {
throw new Error('API error occured');
}
_this.groupTypes = response.json().data;
_this.setCurrentGroupType(_this.groupTypes[0].relationships.typeList.data, _this.groupTypes[0].attributes.name);
return _this.groupTypes;
})
.catch(function (error) {
if (error.status === 401) {
//this.notifyError('You have been logged out.', error);
_this.auth.logout();
}
else {
console.log('Fetch iteration API returned some error - ', error.message);
//this.notifyError('Fetching iterations has from server has failed.', error);
}
return Observable.throw(new Error(error.message));
});
};
GroupTypesService.prototype.getFlatGroupList = function () {
//this.mockData();
if (this._currentSpace) {
//Normalize the response - we don't want two portfolio - that is
//no two entries for the same level
return Observable.of(this.groupTypes);
}
else {
return Observable.of([]);
;
}
};
GroupTypesService.prototype.getWitGroupList = function () {
return this.groupTypes ? this.groupTypes : [];
};
GroupTypesService.prototype.getCurrentGroupName = function () {
return this.groupName ? this.groupName : '';
};
GroupTypesService.prototype.setCurrentGroupType = function (groupType, groupName) {
if (groupName === void 0) { groupName = ''; }
this.selectedGroupType = groupType;
this.groupName = groupName;
//emit observable. Listener on planner backlog view
this.groupTypeSelected.next(groupType);
};
GroupTypesService.prototype.getCurrentGroupType = function () {
return this.selectedGroupType;
};
GroupTypesService.prototype.getAllowedChildWits = function (workItem, wits) {
var WITid = workItem.relationships.baseType.data.id;
var selectedWIT = wits.find(function (wit) { return wit.id === WITid; });
if (selectedWIT && selectedWIT.relationships.guidedChildTypes)
this.workItemSelected.next(selectedWIT.relationships.guidedChildTypes.data.map(function (i) { return i.id; }));
else
this.workItemSelected.next([]);
};
GroupTypesService.decorators = [
{ type: Injectable },
];
/** @nocollapse */
GroupTypesService.ctorParameters = function () { return [
{ type: Logger, },
{ type: HttpService, },
{ type: AuthenticationService, },
{ type: GlobalSettings, },
{ type: Spaces, },
]; };
return GroupTypesService;
}());
export { GroupTypesService };
//# sourceMappingURL=group-types.service.js.map