my-test123
Version:
A planner front-end for Fabric8.
92 lines • 4.1 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Store } from '@ngrx/store';
import { Actions, Effect } from '@ngrx/effects';
import { Injectable } from '@angular/core';
import * as LabelActions from './../actions/label.actions';
import { Observable } from 'rxjs';
import { LabelService } from './../services/label.service';
import { LabelMapper } from "./../models/label.model";
import { Notifications, NotificationType } from "ngx-base";
var LabelEffects = /** @class */ (function () {
function LabelEffects(actions$, labelService, store, notifications) {
var _this = this;
this.actions$ = actions$;
this.labelService = labelService;
this.store = store;
this.notifications = notifications;
this.getLabels$ = this.actions$
.ofType(LabelActions.GET)
.withLatestFrom(this.store.select('listPage').select('space'))
.switchMap(function (_a) {
var action = _a[0], space = _a[1];
return _this.labelService.getLabels2(space.links.self + '/labels')
.map(function (labels) {
var lMapper = new LabelMapper();
return labels.map(function (l) { return lMapper.toUIModel(l); });
})
.map(function (labels) { return new LabelActions.GetSuccess(labels); })
.catch(function () { return Observable.of(new LabelActions.GetError()); });
});
this.createLabel$ = this.actions$
.ofType(LabelActions.ADD)
.map(function (action) { return action.payload; })
.switchMap(function (payload) {
return _this.labelService.createLabel(payload)
.map(function (label) {
var lMapper = new LabelMapper();
var labelUI = lMapper.toUIModel(label);
try {
_this.notifications.message({
message: labelUI.name + " is added.",
type: NotificationType.SUCCESS
});
}
catch (e) {
console.log('label is added');
}
return new LabelActions.AddSuccess(labelUI);
})
.catch(function (e) {
try {
_this.notifications.message({
message: "There was some problem in adding the label.",
type: NotificationType.DANGER
});
}
catch (e) {
console.log('There was some problem in adding the label.');
}
return Observable.of(new LabelActions.AddError());
});
});
}
LabelEffects.decorators = [
{ type: Injectable },
];
/** @nocollapse */
LabelEffects.ctorParameters = function () { return [
{ type: Actions, },
{ type: LabelService, },
{ type: Store, },
{ type: Notifications, },
]; };
__decorate([
Effect(),
__metadata("design:type", Observable)
], LabelEffects.prototype, "getLabels$", void 0);
__decorate([
Effect(),
__metadata("design:type", Observable)
], LabelEffects.prototype, "createLabel$", void 0);
return LabelEffects;
}());
export { LabelEffects };
//# sourceMappingURL=label.effects.js.map