UNPKG

my-test123

Version:
367 lines 15.5 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 { Store } from '@ngrx/store'; import { Actions, Effect } from '@ngrx/effects'; import { Injectable } from '@angular/core'; import { Notifications, NotificationType } from "ngx-base"; import * as WorkItemActions from './../actions/work-item.actions'; import { Observable } from 'rxjs'; import { WorkItemService as WIService } from './../services/work-item.service'; import { WorkItemMapper, WorkItemResolver } from './../models/work-item'; var WorkItemEffects = /** @class */ (function () { function WorkItemEffects(actions$, workItemService, store, notifications) { var _this = this; this.actions$ = actions$; this.workItemService = workItemService; this.store = store; this.notifications = notifications; this.workItemMapper = new WorkItemMapper(); this.addWorkItems$ = this.actions$ .ofType(WorkItemActions.ADD) .withLatestFrom(this.store.select('listPage')) .map(function (_a) { var action = _a[0], state = _a[1]; return { payload: action.payload, state: state }; }) .switchMap(function (op) { var payload = op.payload; var state = op.state; var createID = payload.createId; var workItem = payload.workItem; var parentId = payload.parentId; return _this.workItemService.create(workItem) .map(function (item) { var itemUI = _this.workItemMapper.toUIModel(item); var workItemResolver = new WorkItemResolver(itemUI); workItemResolver.resolveArea(state.areas); workItemResolver.resolveIteration(state.iterations); workItemResolver.resolveCreator(state.collaborators); workItemResolver.resolveType(state.workItemTypes); var wItem = workItemResolver.getWorkItem(); wItem.createId = createID; return wItem; }) .mergeMap(function (wItem) { // If a child item is created if (parentId) { wItem.parentID = parentId; // TODO : solve the hack :: link the item var linkPayload = _this.createLinkObject(parentId, wItem.id, '25c326a7-6d03-4f5a-b23b-86a9ee4171e9'); return _this.workItemService.createLink({ data: linkPayload }).map(function () { // for a normal (not a child) work item creation // Add item success notification try { _this.notifications.message({ message: "New child added.", type: NotificationType.SUCCESS }); } catch (e) { console.log('New child added.'); } var parent = state.workItems.find(function (w) { return w.id === parentId; }); if (!parent.childrenLoaded && parent.hasChildren) { return new WorkItemActions.GetChildren(parent); } else { return new WorkItemActions.AddSuccess(wItem); } }); } else { // for a normal (not a child) work item creation // Add item success notification try { _this.notifications.message({ message: "Work item is added.", type: NotificationType.SUCCESS }); } catch (e) { console.log('Work item is added.'); } return Observable.of(new WorkItemActions.AddSuccess(wItem)); } }) .catch(function () { try { _this.notifications.message({ message: "Problem adding work item.", type: NotificationType.DANGER }); } catch (e) { console.log('Problem adding work item.'); } return Observable.of(new WorkItemActions.AddError()); }); }); this.getWorkItems$ = this.actions$ .ofType(WorkItemActions.GET) .withLatestFrom(this.store.select('listPage')) .map(function (_a) { var action = _a[0], state = _a[1]; return { payload: action.payload, state: state }; }) .switchMap(function (wp) { var payload = wp.payload; var state = wp.state; return _this.workItemService.getWorkItems2(payload.pageSize, payload.filters) .map(function (data) { var wis = []; if (payload.isShowTree) { var ancestors = data.ancestorIDs; wis = _this.resolveWorkItems(data.workItems, state, payload.isShowTree, ancestors); var wiIncludes = _this.resolveWorkItems(data.included, state, false, ancestors); return wis.concat(wiIncludes); } else { wis = _this.resolveWorkItems(data.workItems, state, payload.isShowTree); } return wis.slice(); }) .map(function (workItems) { return new WorkItemActions.GetSuccess(workItems); }) .catch(function (e) { try { _this.notifications.message({ message: "Problem loading workitems.", type: NotificationType.DANGER }); } catch (e) { console.log('Problem loading workitems.'); } return Observable.of(new WorkItemActions.GetError()); }); }); this.getWorkItemChildren$ = this.actions$ .ofType(WorkItemActions.GET_CHILDREN) .withLatestFrom(this.store.select('listPage')) .map(function (_a) { var action = _a[0], state = _a[1]; return { payload: action.payload, state: state }; }) .switchMap(function (wp) { var parent = wp.payload; var state = wp.state; return _this.workItemService .getChildren2(parent.childrenLink) .map(function (data) { var wis = _this.resolveWorkItems(data, state) .map(function (w) { w.parentID = parent.id; return w; }); return wis.slice(); }) .map(function (workItems) { return new WorkItemActions.GetChildrenSuccess({ parent: parent, children: workItems }); }) .catch(function () { try { _this.notifications.message({ message: "Problem loading children.", type: NotificationType.DANGER }); } catch (e) { console.log('Problem loading children.'); } return Observable.of(new WorkItemActions.GetChildrenError(parent)); }); }); this.updateWorkItem$ = this.actions$ .ofType(WorkItemActions.UPDATE) .withLatestFrom(this.store.select('listPage')) .map(function (_a) { var action = _a[0], state = _a[1]; return { payload: action.payload, state: state }; }) .switchMap(function (wp) { var payload = _this.workItemMapper.toServiceModel(wp.payload); var state = wp.state; return _this.workItemService.update(payload) .map(function (w) { return _this.resolveWorkItems([w], state)[0]; }) .map(function (w) { var item = state.workItems.find(function (i) { return i.id === w.id; }); if (item) { w.treeStatus = item.treeStatus; w.bold = item.bold; w.childrenLoaded = item.childrenLoaded; w.parentID = item.parentID; } try { _this.notifications.message({ message: "Workitem updated.", type: NotificationType.SUCCESS }); } catch (e) { console.log('workitem updated.'); } return w; }) .map(function (workItem) { return new WorkItemActions.UpdateSuccess(workItem); }) .catch(function () { try { _this.notifications.message({ message: "Problem in update Workitem.", type: NotificationType.DANGER }); } catch (e) { console.log('Problem in update Workitem.'); } return Observable.of(new WorkItemActions.UpdateError()); }); }); this.Reorder = this.actions$ .ofType(WorkItemActions.REORDER) .withLatestFrom(this.store.select('listPage')) .map(function (_a) { var action = _a[0], state = _a[1]; return { payload: action.payload, state: state }; }) .switchMap(function (op) { var workitem = _this.workItemMapper.toServiceModel(op.payload.workitem); return _this.workItemService.reOrderWorkItem(workitem, op.payload.destinationWorkitemID, op.payload.direction) .map(function (w) { return _this.resolveWorkItems([w], op.state)[0]; }) .map(function (w) { w.treeStatus = op.payload.workitem.treeStatus; w.bold = op.payload.workitem.bold; w.childrenLoaded = op.payload.workitem.childrenLoaded; w.parentID = op.state.workItems.find(function (wi) { return wi.id === w.id; }).parentID; return w; }) .map(function (w) { return new WorkItemActions.UpdateSuccess(w); }) .catch(function (e) { try { _this.notifications.message({ message: "Problem in reorder workitem.", type: NotificationType.DANGER }); } catch (e) { console.log('Problem in reorder workitem.'); } return Observable.of(new WorkItemActions.UpdateError()); }); }); } WorkItemEffects.prototype.resolveWorkItems = function (workItems, state, matchingQuery, ancestors) { var _this = this; if (matchingQuery === void 0) { matchingQuery = false; } if (ancestors === void 0) { ancestors = []; } var hasAncestors = !!ancestors.length; return workItems.map(function (wi) { var workItemUI = _this.workItemMapper.toUIModel(wi); workItemUI.bold = matchingQuery; if (hasAncestors) { workItemUI.treeStatus = ancestors.findIndex(function (a) { return a === workItemUI.id; }) > -1 ? 'expanded' : workItemUI.treeStatus; if (workItemUI.treeStatus === 'expanded') { workItemUI.childrenLoaded = true; } } var workItemResolver = new WorkItemResolver(workItemUI); workItemResolver.resolveArea(state.areas); workItemResolver.resolveIteration(state.iterations); workItemResolver.resolveCreator(state.collaborators); workItemResolver.resolveType(state.workItemTypes); workItemResolver.resolveAssignees(state.collaborators); workItemResolver.resolveWiLabels(state.labels); return workItemResolver.getWorkItem(); }); }; WorkItemEffects.prototype.createLinkObject = function (parentWorkItemId, childWorkItemId, linkId) { return { 'type': 'workitemlinks', 'attributes': { 'version': 0 }, 'relationships': { 'link_type': { 'data': { 'id': linkId, 'type': 'workitemlinktypes' } }, 'source': { 'data': { 'id': parentWorkItemId, 'type': 'workitems' } }, 'target': { 'data': { 'id': childWorkItemId, 'type': 'workitems' } } } }; }; WorkItemEffects.decorators = [ { type: Injectable }, ]; /** @nocollapse */ WorkItemEffects.ctorParameters = function () { return [ { type: Actions, }, { type: WIService, }, { type: Store, }, { type: Notifications, }, ]; }; __decorate([ Effect(), __metadata("design:type", Object) ], WorkItemEffects.prototype, "addWorkItems$", void 0); __decorate([ Effect(), __metadata("design:type", Observable) ], WorkItemEffects.prototype, "getWorkItems$", void 0); __decorate([ Effect(), __metadata("design:type", Observable) ], WorkItemEffects.prototype, "getWorkItemChildren$", void 0); __decorate([ Effect(), __metadata("design:type", Observable) ], WorkItemEffects.prototype, "updateWorkItem$", void 0); __decorate([ Effect(), __metadata("design:type", Observable) ], WorkItemEffects.prototype, "Reorder", void 0); return WorkItemEffects; }()); export { WorkItemEffects }; //# sourceMappingURL=work-item.effects.js.map