UNPKG

my-test123

Version:
346 lines 14.9 kB
import { AuthenticationService } from 'ngx-login-client'; import { UrlService } from './../../services/url.service'; import { Observable } from 'rxjs/Observable'; import { ActivatedRoute, Router } from '@angular/router'; import { Component, Input, Output, EventEmitter, ViewChild, Renderer2, HostListener } from '@angular/core'; // ngrx stuff import { Store } from '@ngrx/store'; import * as WorkItemActions from './../../actions/work-item.actions'; import * as DetailWorkItemActions from './../../actions/detail-work-item.actions'; import * as SpaceActions from './../../actions/space.actions'; import { WorkItemService } from './../../services/work-item.service'; var WorkItemDetailComponent = /** @class */ (function () { function WorkItemDetailComponent(store, route, router, urlService, auth, renderer, workItemService) { var _this = this; this.store = store; this.route = route; this.router = router; this.urlService = urlService; this.auth = auth; this.renderer = renderer; this.workItemService = workItemService; this.spaceSource = this.store .select('listPage') .select('space') .do(function (s) { if (!s) _this.store.dispatch(new SpaceActions.Get()); }) .filter(function (s) { return !!s; }); this.areaSource = this.store .select('listPage') .select('areas') .filter(function (a) { return !!a.length; }); this.iterationSource = this.store .select('listPage') .select('iterations') .filter(function (i) { return !!i.length; }); this.labelSource = this.store .select('listPage') .select('labels'); this.collaboratorSource = this.store .select('listPage') .select('collaborators') .filter(function (c) { return !!c.length; }); this.workItemStateSource = this.store .select('listPage') .select('workItemStates') .filter(function (wis) { return !!wis.length; }); this.workItemTypeSource = this.store .select('listPage') .select('workItemTypes') .filter(function (w) { return !!w.length; }); this.workItemSource = this.store .select('detailPage') .select('workItem'); this.combinedSources = Observable.combineLatest(this.areaSource, this.iterationSource, this.labelSource, this.collaboratorSource, this.workItemStateSource, this.workItemTypeSource); this.closePreview = new EventEmitter(); this.workItem = null; this.detailContext = 'preview'; this.eventListeners = []; this.workItemSubscriber = null; this.workItemStates = []; this.collaborators = []; this.loggedIn = false; this.titleCallback = null; this.descCallback = null; this._areas = []; this.areas = []; // this goes in dropdown component this._iterations = []; this.iterations = []; // this goes in dropdown component this.labels = []; this.loadingComments = true; this.loadingTypes = false; this.loadingIteration = false; this.loadingArea = false; this.loadingLabels = false; this.loadingAssignees = false; this.loggedInUser = null; this.listenToEsc = false; } Object.defineProperty(WorkItemDetailComponent.prototype, "workItemInput", { set: function (val) { if (val && val != null) { if (this.workItemSubscriber !== null) { this.workItemSubscriber.unsubscribe(); this.workItemSubscriber = null; } this.detailContext = 'preview'; var workItemNumber = val.number; this.setWorkItem(workItemNumber); this.listenToEsc = true; } }, enumerable: true, configurable: true }); WorkItemDetailComponent.prototype.ngOnInit = function () { var currentRoute = this.router.url; this.loggedIn = this.auth.isLoggedIn(); if (currentRoute.includes('plan/detail/')) { this.detailContext = 'detail'; var workItemNumber = currentRoute.split('plan/detail/')[1]; this.setWorkItem(workItemNumber); } }; WorkItemDetailComponent.prototype.ngOnDestroy = function () { this.eventListeners.forEach(function (e) { return e.unsubscribe(); }); if (this.workItemSubscriber !== null) { this.workItemSubscriber.unsubscribe(); this.workItemSubscriber = null; } }; WorkItemDetailComponent.prototype.ngAfterViewChecked = function () { if (this.detailContext === 'detail') { if (this.detailHeader) { var HdrDivHeight = this.detailHeader.nativeElement.offsetHeight; var targetHeight = window.innerHeight - HdrDivHeight - 90; this.renderer.setStyle(this.detailContent.nativeElement, 'height', targetHeight + "px"); } } if (document.getElementsByTagName('body')) { document.getElementsByTagName('body')[0].style.overflow = "hidden"; } }; WorkItemDetailComponent.prototype.setWorkItem = function (wiNumber) { var _this = this; this.workItemSubscriber = this.spaceSource .switchMap(function (s) { return _this.combinedSources; }) .switchMap(function (_a) { var areas = _a[0], iterations = _a[1], labels = _a[2], collabs = _a[3], states = _a[4], type = _a[5]; _this.workItemStates = states; _this.collaborators = collabs.filter(function (c) { return !c.currentUser; }); _this.loggedInUser = collabs.find(function (c) { return c.currentUser; }); _this._areas = areas; _this._iterations = iterations; _this.labels = labels; _this.store.dispatch(new DetailWorkItemActions.GetWorkItem({ number: wiNumber })); return _this.workItemSource; }) .filter(function (w) { return w !== null; }) .subscribe(function (workItem) { _this.workItem = workItem; _this.setAreas(); _this.setIterations(); _this.loadingAssignees = false; _this.loadingArea = false; _this.loadingIteration = false; _this.loadingLabels = false; if ((_this.detailContext === 'preview') && (_this.descMarkdown)) { _this.descMarkdown.closeClick(); } // set title on update if (_this.titleCallback !== null) { _this.titleCallback(_this.workItem.title); _this.titleCallback = null; } // set desc on update if (_this.descCallback !== null) { _this.descCallback(_this.workItem.description, _this.workItem.descriptionRendered); _this.descCallback = null; } }); }; WorkItemDetailComponent.prototype.closeDetail = function () { this.workItem = null; if (this.workItemSubscriber !== null) { this.workItemSubscriber.unsubscribe(); this.workItemSubscriber = null; } if (this.detailContext === 'detail') { this.navigateBack(); } else { this.inlineInput.closeClick(); this.closePreview.emit(); } }; WorkItemDetailComponent.prototype.navigateBack = function () { if (this.urlService.getLastListOrBoard() === '') { this.router.navigate(['../..'], { relativeTo: this.route }); } else { this.router.navigateByUrl(this.urlService.getLastListOrBoard()); } }; WorkItemDetailComponent.prototype.constructUrl = function (workItem) { return this.router.url.split('plan')[0] + 'plan/detail/' + workItem.number; }; WorkItemDetailComponent.prototype.saveTitle = function (event) { var value = event.value.trim(); this.titleCallback = event.callBack; if (value === '') { this.titleCallback(value, 'Empty title not allowed'); } else if (this.workItem.title === value) { this.titleCallback(value); } else { var workItem = {}; workItem['version'] = this.workItem.version; workItem['link'] = this.workItem.link; workItem['id'] = this.workItem.id; workItem['title'] = value; this.store.dispatch(new WorkItemActions.Update(workItem)); } }; WorkItemDetailComponent.prototype.onChangeState = function (state) { if (state !== this.workItem.state) { var workItem = {}; workItem['version'] = this.workItem.version; workItem['link'] = this.workItem.link; workItem['id'] = this.workItem.id; workItem['state'] = state; this.store.dispatch(new WorkItemActions.Update(workItem)); } }; WorkItemDetailComponent.prototype.assignUser = function (users) { this.loadingAssignees = true; var workItem = {}; workItem['version'] = this.workItem.version; workItem['link'] = this.workItem.link; workItem['id'] = this.workItem.id; workItem['assignees'] = users; this.store.dispatch(new WorkItemActions.Update(workItem)); }; WorkItemDetailComponent.prototype.setAreas = function () { var _this = this; this.areas = this._areas.map(function (a) { return { key: a.id, value: (a.parentPathResolved != '/' ? a.parentPathResolved : '') + '/' + a.name, selected: a.id === _this.workItem.area.id, cssLabelClass: undefined }; }); }; WorkItemDetailComponent.prototype.focusArea = function () { }; WorkItemDetailComponent.prototype.areaUpdated = function (areaID) { this.loadingArea = true; var workItem = {}; workItem['version'] = this.workItem.version; workItem['link'] = this.workItem.link; workItem['id'] = this.workItem.id; workItem['area'] = this._areas.find(function (a) { return a.id === areaID; }); this.store.dispatch(new WorkItemActions.Update(workItem)); }; WorkItemDetailComponent.prototype.setIterations = function () { var _this = this; this.iterations = this._iterations.map(function (i) { return { key: i.id, value: (i.resolvedParentPath != '/' ? i.resolvedParentPath : '') + '/' + i.name, selected: i.id === _this.workItem.iteration.id, cssLabelClass: undefined }; }); }; WorkItemDetailComponent.prototype.focusIteration = function () { }; WorkItemDetailComponent.prototype.iterationUpdated = function (iterationID) { this.loadingIteration = true; var workItem = {}; workItem['version'] = this.workItem.version; workItem['link'] = this.workItem.link; workItem['id'] = this.workItem.id; workItem['iteration'] = this._iterations.find(function (a) { return a.id === iterationID; }); this.store.dispatch(new WorkItemActions.Update(workItem)); }; WorkItemDetailComponent.prototype.updateLabels = function (labels) { this.loadingLabels = true; var workItem = {}; workItem['version'] = this.workItem.version; workItem['link'] = this.workItem.link; workItem['id'] = this.workItem.id; workItem['labels'] = labels; this.store.dispatch(new WorkItemActions.Update(workItem)); }; WorkItemDetailComponent.prototype.removeLable = function (label) { this.loadingLabels = true; var workItem = {}; workItem['version'] = this.workItem.version; workItem['link'] = this.workItem.link; workItem['id'] = this.workItem.id; workItem['labels'] = this.workItem.labels.filter(function (l) { return l.id != label.id; }); this.store.dispatch(new WorkItemActions.Update(workItem)); }; WorkItemDetailComponent.prototype.showPreview = function (event) { var rawText = event.rawText; var callBack = event.callBack; this.workItemService.renderMarkDown(rawText) .subscribe(function (renderedHtml) { callBack(rawText, renderedHtml); }); }; WorkItemDetailComponent.prototype.descUpdate = function (event) { var rawText = event.rawText; this.descCallback = event.callBack; var workItem = {}; workItem['version'] = this.workItem.version; workItem['link'] = this.workItem.link; workItem['id'] = this.workItem.id; workItem['description'] = rawText; this.store.dispatch(new WorkItemActions.Update(workItem)); }; WorkItemDetailComponent.prototype.onKeyEvent = function (event) { // for ESC key handling if (event.keyCode == 27 && this.listenToEsc) { this.closeDetail(); this.listenToEsc = false; } }; WorkItemDetailComponent.decorators = [ { type: Component, args: [{ selector: 'work-item-detail', template: require('./work-item-detail.component.html'), styles: [require('./work-item-detail.component.css').toString()] },] }, ]; /** @nocollapse */ WorkItemDetailComponent.ctorParameters = function () { return [ { type: Store, }, { type: ActivatedRoute, }, { type: Router, }, { type: UrlService, }, { type: AuthenticationService, }, { type: Renderer2, }, { type: WorkItemService, }, ]; }; WorkItemDetailComponent.propDecorators = { 'detailHeader': [{ type: ViewChild, args: ['detailHeader',] },], 'detailContent': [{ type: ViewChild, args: ['detailContent',] },], 'inlineInput': [{ type: ViewChild, args: ['inlineInput',] },], 'descMarkdown': [{ type: ViewChild, args: ['descMarkdown',] },], 'workItemInput': [{ type: Input, args: ['workItem',] },], 'closePreview': [{ type: Output },], 'onKeyEvent': [{ type: HostListener, args: ['window:keydown', ['$event'],] },], }; return WorkItemDetailComponent; }()); export { WorkItemDetailComponent }; //# sourceMappingURL=work-item-detail.component.js.map