UNPKG

my-test123

Version:
166 lines 7.36 kB
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 { Injectable } from "@angular/core"; import { Actions, Effect } from "@ngrx/effects"; import { Observable } from "rxjs"; import { Store } from '@ngrx/store'; import { Notifications, NotificationType } from "ngx-base"; import * as IterationActions from ".././actions/iteration.actions"; import { IterationService } from '.././services/iteration.service'; import { IterationMapper } from "../models/iteration.model"; import { UpdateWorkitemIteration } from "../actions/work-item.actions"; var IterationEffects = /** @class */ (function () { function IterationEffects(actions$, iterationService, notifications, store) { var _this = this; this.actions$ = actions$; this.iterationService = iterationService; this.notifications = notifications; this.store = store; this.getIterations$ = this.actions$ .ofType(IterationActions.GET) .withLatestFrom(this.store.select('listPage').select('space')) .switchMap(function (_a) { var action = _a[0], space = _a[1]; return _this.iterationService.getIterations2(space.relationships.iterations.links.related) .map(function (iterations) { var itMapper = new IterationMapper(); return iterations.map(function (it) { return itMapper.toUIModel(it); }); }) .map(function (iterations) { return _this.resolveChildren(iterations); }) .map(function (iterations) { return (new IterationActions.GetSuccess(iterations)); }) .catch(function () { return Observable.of(new IterationActions.GetError()); }); }); this.addIteration$ = this.actions$ .ofType(IterationActions.ADD) .switchMap(function (action) { var itMapper = new IterationMapper(); var iteration = itMapper.toServiceModel(action.payload.iteration); var parent = action.payload.parent ? itMapper.toServiceModel(action.payload.parent) : null; return _this.iterationService.createIteration(iteration, parent) .map(function (iteration) { return itMapper.toUIModel(iteration); }) .map(function (iteration) { var iterationName = iteration.name; if (iterationName.length > 15) { iterationName = iterationName.slice(0, 15) + '...'; } try { _this.notifications.message({ message: iterationName + " is added.", type: NotificationType.SUCCESS }); } catch (e) { console.log('Iteration is added.'); } return new IterationActions.AddSuccess({ iteration: iteration, parent: parent ? itMapper.toUIModel(parent) : null }); }) .catch(function () { try { _this.notifications.message({ message: "There was some problem adding the iteration.", type: NotificationType.DANGER }); } catch (e) { console.log('There was some problem adding the iteration..'); } return Observable.of(new IterationActions.AddError()); }); }); this.updateIteration$ = this.actions$ .ofType(IterationActions.UPDATE) .switchMap(function (action) { var itMapper = new IterationMapper(); var iteration = itMapper.toServiceModel(action.payload); return _this.iterationService.updateIteration(iteration) .map(function (iteration) { return itMapper.toUIModel(iteration); }) .map(function (iteration) { var iterationName = iteration.name; if (iterationName.length > 15) { iterationName = iterationName.slice(0, 15) + '...'; } try { _this.notifications.message({ message: iterationName + " is updated.", type: NotificationType.SUCCESS }); } catch (e) { console.log('Error displaying notification.'); } var payload = { iteration: iteration }; return [ new IterationActions.UpdateSuccess(iteration), new UpdateWorkitemIteration(payload) ]; }) .switchMap(function (res) { return res; }) .catch(function () { try { _this.notifications.message({ message: "There was some problem updating the iteration.", type: NotificationType.DANGER }); } catch (e) { console.log('Error displaying notification.'); } return Observable.of(new IterationActions.UpdateError()); }); }); } IterationEffects.prototype.resolveChildren = function (iterations) { var _loop_1 = function (i) { iterations[i].children = iterations.filter(function (it) { return it.parentId === iterations[i].id; }); }; for (var i = 0; i < iterations.length; i++) { _loop_1(i); } return iterations; }; IterationEffects.decorators = [ { type: Injectable }, ]; /** @nocollapse */ IterationEffects.ctorParameters = function () { return [ { type: Actions, }, { type: IterationService, }, { type: Notifications, }, { type: Store, }, ]; }; __decorate([ Effect(), __metadata("design:type", Observable) ], IterationEffects.prototype, "getIterations$", void 0); __decorate([ Effect(), __metadata("design:type", Observable) ], IterationEffects.prototype, "addIteration$", void 0); __decorate([ Effect(), __metadata("design:type", Observable) ], IterationEffects.prototype, "updateIteration$", void 0); return IterationEffects; }()); export { IterationEffects }; //# sourceMappingURL=iteration.effects.js.map