UNPKG

@wjya/ngx-webapp-icpc.group.pms

Version:

angular webapp : icpc.group.pms

139 lines 7.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var data_source_helper_1 = require("../../service/data-source.helper"); var core_1 = require("@angular/core"); var ngx_webapp_fx_1 = require("@wjya/ngx-webapp-fx"); var PostAuthorityComponent = /** @class */ (function () { function PostAuthorityComponent(userStorageService, dataSourceHelper) { this.userStorageService = userStorageService; this.dataSourceHelper = dataSourceHelper; this.modalIsVisible = false; this.postResourceIds = []; this.isSpinning = false; this.dataSource = dataSourceHelper.posts; this.postResourceDataSource = dataSourceHelper.postResource; } PostAuthorityComponent.prototype.ngOnInit = function () { this.treeViewDataUrl = '/uaa/api/_my/application-resources?prefix=icpc.group'; this.communityGroupId = this.userStorageService.getCurrentOffice().id; }; PostAuthorityComponent.prototype.loadAll = function () { var _this = this; this.dataSource.findList({ communityGroupId: this.communityGroupId, size: 9999, sort: 'id,asc' }).subscribe(function (res) { _this.options = res.body; if (_this.options.length > 0) { _this.postId = _this.postId ? _this.postId : _this.options[0].id; _this.loadPostResourceId(); } }); }; PostAuthorityComponent.prototype.postIdChange = function () { this.loadPostResourceId(); }; PostAuthorityComponent.prototype.loadPostResourceId = function () { var _this = this; this.isSpinning = true; this.postResourceDataSource.findOne(this.postId).subscribe(function (res) { _this.postResourceIds = res.body; if (_this.treeView.treeView.wholeTreeNodes) { for (var k = 0; k < _this.treeView.treeView.wholeTreeNodes.length; k++) { _this.treeView.treeView.wholeTreeNodes[k].checked = false; } for (var i = 0; i < _this.treeView.treeView.wholeTreeNodes.length; i++) { for (var b = 0; b < _this.postResourceIds.length; b++) { if (_this.treeView.treeView.wholeTreeNodes[i].data.id === _this.postResourceIds[b]) { _this.treeView.treeView.wholeTreeNodes[i].checked = true; } } } _this.isSpinning = false; } }); }; PostAuthorityComponent.prototype.handleCancel = function () { this.modalIsVisible = false; }; PostAuthorityComponent.prototype.treeViewDataLoaded = function (data) { this.setTreeNodeAttributes(Array.isArray(data) ? { children: data } : data); }; PostAuthorityComponent.prototype.setTreeNodeAttributes = function (data) { var _this = this; if (data.children == null) { return; } this.sortBySeq(data); data.children.forEach(function (child) { child.icon = null; child.visible = true; child.childrenUrl = '/uaa/api/_my/nav-resources?parentId=${data.id}'; _this.setTreeNodeAttributes(child); }); data.children.forEach(function (child) { _this.postResourceIds.forEach(function (id) { if (child.id === id) { child.checked = true; } }); }); }; PostAuthorityComponent.prototype.treeViewCheckedChange = function (treeNode) { if (!this.postId) { return; } if (treeNode.checked) { this.onSave(treeNode.data.id); } else { this.delete(treeNode.data.id); } }; PostAuthorityComponent.prototype.onSave = function (treeNodeId) { this.postResourceDataSource.createOne(this.postId, null, { resourceId: treeNodeId }).subscribe(); }; PostAuthorityComponent.prototype.delete = function (treeNodeId) { this.postResourceDataSource.deleteOne(this.postId, { resourceId: treeNodeId }).subscribe(); }; PostAuthorityComponent.prototype.sortBySeq = function (data) { if (!data.children) { return; } data.children = data.children.sort(this.compare('seq')); for (var i = 0; i < data.children.length; i++) { if (data.children[i].children) { this.sortBySeq(data.children[i].children); } } }; PostAuthorityComponent.prototype.compare = function (property) { return function (obj1, obj2) { var value1 = obj1[property]; var value2 = obj2[property]; return value1 - value2; }; }; PostAuthorityComponent.decorators = [ { type: core_1.Component, args: [{ selector: 'zx-post-authority', template: "<nz-modal [nzVisible]=\"modalIsVisible\" [nzWidth]=\"600\" [nzTitle]=\"modalTitle\" [nzContent]=\"modalContent\" [nzFooter]=\"modalFooter\" (nzOnCancel)=\"handleCancel()\"><ng-template #modalTitle><span>\u8BBE\u7F6E\u5C97\u4F4D\u6743\u9650</span> <span>\u9009\u62E9\u5C97\u4F4D\uFF0C\u5E76\u6307\u5B9A\u5C97\u4F4D\u6743\u9650</span></ng-template><ng-template #modalContent><div nz-row nz-form-item><div nz-col [nzSpan]=\"12\"><div nz-col nz-form-label [nzSpan]=\"4\"><label for=\"\">\u5C97\u4F4D</label></div><div nz-col nz-form-control [nzSpan]=\"20\"><nz-select [nzPlaceHolder]=\"'\u8BF7\u9009\u62E9\u5C97\u4F4D'\" [nzSize]=\"'large'\" style=\"width: 100%\" [(ngModel)]=\"postId\" (ngModelChange)=\"postIdChange()\"><nz-option *ngFor=\"let option of options\" [nzLabel]=\"option.name\" [nzValue]=\"option.id\"></nz-option></nz-select></div></div><div nz-col nz-form-label [nzSpan]=\"12\"><p>\u6CE8\uFF1A\u52FE\u9009\u6216\u53D6\u6D88\u52FE\u9009\u6743\u9650\u540E\u5C06\u81EA\u52A8\u4FDD\u5B58\u3002</p></div></div><div nz-row nz-form-item><nz-card nzNoHovering><ng-template #body><nz-spin [nzSpinning]=\"isSpinning\"><zx-tree-view #treeView [dataUrl]=\"treeViewDataUrl\" (checkedChange)=\"treeViewCheckedChange($event)\" (dataLoaded)=\"treeViewDataLoaded($event)\" [accordion]=\"true\" [enableCheckbox]=\"true\" [enableHeader]=\"false\"></zx-tree-view></nz-spin></ng-template></nz-card></div></ng-template><ng-template #modalFooter><button nz-button [nzType]=\"'primary'\" [nzSize]=\"'large'\" (click)=\"handleCancel()\"><span>\u5173 \u95ED</span></button></ng-template></nz-modal>", styles: [ "\n :host ::ng-deep .ant-card-body{\n padding:6px;\n height:480px;\n overflow: auto;\n }\n :host ::ng-deep .ant-modal-body{\n padding-bottom:0;\n }\n\n " ] },] }, ]; /** @nocollapse */ PostAuthorityComponent.ctorParameters = function () { return [ { type: ngx_webapp_fx_1.UserStorageService, }, { type: data_source_helper_1.DataSourceHelper, }, ]; }; PostAuthorityComponent.propDecorators = { "treeView": [{ type: core_1.ViewChild, args: ['treeView',] },], "postId": [{ type: core_1.Input },], }; return PostAuthorityComponent; }()); exports.PostAuthorityComponent = PostAuthorityComponent; //# sourceMappingURL=post-authority.component.js.map