@barteh/core
Version:
a common library for barteh based projects
360 lines (305 loc) • 11.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AOrgChart = void 0;
var _rxjs = _interopRequireDefault(require("rxjs"));
var _asService = require("@barteh/as-service");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// let orgChartList=null; let deputiesList=null; let topchartList=null; let
// orgList=null;
var AOrgChart =
/*#__PURE__*/
function () {
_createClass(AOrgChart, [{
key: "getChilsOfParent",
value: function getChilsOfParent(parentid, scopeid) {
return this.orgChartList.filter(function (a) {
if (a.parent === parentid && a.scopeid === scopeid) {
return a;
}
});
}
}, {
key: "getOrgchartListAsTree",
value: function getOrgchartListAsTree() {
this.staff_tree = [];
this.org_tree = [];
this.branch_tree = []; // const staff_list = Object.assign([], this.orgChartList.filter(a => a.scopeid
// === 1));
var staff_list = this.orgChartList.filter(function (a) {
return a.scopeid === 1;
});
for (var i = 0; i < staff_list.length - 1; i++) {
staff_list[i].key = staff_list[i].boxid;
staff_list[i].title = staff_list[i].name;
if (staff_list[i].istype === 2) {
staff_list[i].subtitle = staff_list[i].position_name;
}
staff_list[i].children = this.getChilsOfParent(staff_list[i].boxid, 1);
} // this.orgChartList[0].staff_tree=staff_list[0]
this.orgChartList[0].staff_tree = [];
this.orgChartList[0].staff_tree.push(staff_list[0]); // .staff_tree .push(staff_list[0]) const org_list =
// Object.assign([], this.orgChartList.filter(a => a.scopeid === 2));
var org_list = this.orgChartList.filter(function (a) {
return a.scopeid === 2;
});
for (var _i = 0; _i < org_list.length - 1; _i++) {
org_list[_i].key = org_list[_i].boxid;
org_list[_i].title = org_list[_i].name;
if (staff_list[_i].istype === 2) {
staff_list[_i].subtitle = staff_list[_i].position_name;
}
org_list[_i].children = this.getChilsOfParent(org_list[_i].boxid, 2);
}
this.orgChartList[0].org_tree = [];
this.orgChartList[0].org_tree.push(staff_list[0]); // this .org_tree .push(org_list[0]) const branch_list =
// Object.assign([], this.orgChartList.filter(a => a.scopeid === 3));
var branch_list = this.orgChartList.filter(function (a) {
return a.scopeid === 3;
});
for (var _i2 = 0; _i2 < branch_list.length - 1; _i2++) {
branch_list[_i2].key = branch_list[_i2].boxid;
branch_list[_i2].title = branch_list[_i2].name;
if (staff_list[_i2].istype === 2) {
staff_list[_i2].subtitle = staff_list[_i2].position_name;
}
branch_list[_i2].children = this.getChilsOfParent(branch_list[_i2].boxid, 3);
}
this.orgChartList[0].branch_list = [];
this.orgChartList[0].branch_list.push(staff_list[0]); // this .branch_tree .push(branch_list[0])
}
}], [{
key: "getChart",
value: function getChart()
/*refresh, error*/
{
AOrgChart.sub = AOrgChart.sub || new _rxjs.default.BehaviorSubject();
var chart = new AOrgChart(); // if (AOrgChart.firstime || refresh) { AOrgChart.firstime = false; //
// chart // .load(error) // .then(a => { // AOrgChart //
// .sub // .next(chart); // }); }
return chart; // this .sub .filter(a => a!==undefined);
}
}]);
function AOrgChart() {
_classCallCheck(this, AOrgChart);
_defineProperty(this, "selectedOrgChart", {
boxid: -1,
name: ''
});
_defineProperty(this, "orgChartList", []);
_defineProperty(this, "staff_tree", []);
_defineProperty(this, "org_tree", []);
_defineProperty(this, "branch_tree", []);
if (!AOrgChart.instance) AOrgChart.instance = this;
return AOrgChart.instance;
}
_createClass(AOrgChart, [{
key: "deputies",
value: function deputies() {
return this.orgChartList.filter(function (a) {
return a.typeid < 3 && a.scopeid == 1;
});
}
}, {
key: "topChart",
value: function topChart() {
return this.orgChartList.filter(function (a) {
return !a.parent;
});
}
}, {
key: "getOrgList",
value: function getOrgList() {
return this.orgChartList.filter(function (a) {
return a.scopeid === 2;
});
}
}, {
key: "getBoxById",
value: function getBoxById(id) {
return this.orgChartList.filter(function (a) {
return a.boxid === id;
});
}
}, {
key: "getDeepChilds",
value: function getDeepChilds(boxid, arr) {
arr = arr || this.ochart;
for (var i = 0; i < arr.length; i++) {
var temp = this.ochart.find(function (a) {
return a.boxid === arr[i].boxid;
});
arr[i].pl1 = temp.pl1;
arr[i].pl2 = temp.pl2;
arr[i].pl3 = temp.pl3;
arr[i].pl4 = temp.pl4;
arr[i].pl5 = temp.pl5;
arr[i].pl6 = temp.pl6;
arr[i].pl7 = temp.pl7;
arr[i].pl8 = temp.pl8;
arr[i].pl9 = temp.pl9;
}
return arr.filter(function (a) {
if (a.pl1 === boxid || a.pl2 === boxid || a.pl3 === boxid || a.pl4 === boxid || a.pl5 === boxid || a.pl6 === boxid || a.pl7 === boxid || a.pl8 === boxid || a.pl9 === boxid) return true;else return false;
});
}
}, {
key: "getTopChart",
value: function getTopChart() {
// > {a.parent === null }));
return this.orgChartList.find(function (a) {
return a.parent === null;
});
}
}, {
key: "getTopGeoOfScope",
value: function getTopGeoOfScope(scopeid) {
if (AOrgChart._topGeoOfScope) return AOrgChart._topGeoOfScope[scopeid];
AOrgChart._topGeoOfScope[scopeid] = scopeid === 2 || scopeid === 4 ? this.getTopChart() : {};
for (var i = 0; i < AOrgChart.orgChartList.length; i++) {
var oc = AOrgChart.orgChartList[i];
if (oc.scopeid != 2 && oc.scopeid != 4) {
if (!AOrgChart._topGeoOfScope[oc.scopeid]) {
AOrgChart._topGeoOfScope[AOrgChart.orgChartList[i].scopeid] = oc;
} else if (AOrgChart._topGeoOfScope[oc.scopeid].level < oc.level) {
AOrgChart._topGeoOfScope[AOrgChart.orgChartList[i].scopeid] = oc;
}
}
}
return AOrgChart._topGeoOfScope[scopeid];
}
}, {
key: "load",
value: function load(error) {
var _this = this;
this.orgChartList = [];
return new Promise(function (resp, rej) {
_asService.Server.dvm("DVM_App_o_ochart", {
o: 'boxid,parent,typeid'
}, {
cache: false
}).then(function (r) {
if (r.data) {
_this.orgChartList = r.data;
_this.getOrgchartListAsTree(); //this.selectedOrgChart=this.getTopChart(); AOrgChart.getTypes();
resp(_this);
} else {
rej(r.status);
if (error) error(r.status);
}
}).catch(function (e) {
rej(e.status);
});
});
}
}, {
key: "changeSelected",
value: function changeSelected(boxid) {
var x = this.orgChartList.filter(function (a) {
return a.boxid === boxid;
});
if (x.length > 0) {
this.selectedOrgChart = x[0];
return this.selectedOrgChart;
}
}
}, {
key: "editOrgChart",
value: function editOrgChart(t, done) {
_asService.Server.controller('ochart', 'edit_ochart', {
boxid: t.boxid,
parent: t.parent,
typeid: t.typeid || 9,
name: t.name,
position_name: t.position_name,
position_type: t.position_type,
geoid: t.geoid,
geotype: t.geotype,
orders: t.orders,
des: t.des
}).then(function (r) {
done(r.data);
});
}
}, {
key: "addOrgChart",
value: function addOrgChart(parent, t, done) {
_asService.Server.controller('ochart', 'add_ochart', {
scopeid: parent.scopeid,
typeid: 9,
name: t.position_name,
parent: parent.boxid,
//t.parent,
chartbox: parent.chartbox,
geotype: parent.geotype,
istype: 1,
//t.istype,
capacity: 1,
// t.capacity,
postition_name: t.position_name,
geoid: parent.geoid,
// editable: parent.editable,
orders: parent.orders,
relbox: parent.relbox,
des: parent.des
}).then(function (r) {
done(r.data);
});
}
}, {
key: "deleteOrgChart",
value: function deleteOrgChart(box, done) {
_asService.Server.controller('ochart', 'del_ochart', {
boxid: box.boxid
}).then(function (r) {
done(r.data);
});
}
}], [{
key: "getTypes",
value: function getTypes() {
if (AOrgChart.types.length === 0) {
_asService.Server.dvm('DVM_app_type_ch_type', {}).then(function (r) {
if (r.data) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = r.data[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var i = _step.value;
AOrgChart.types.push(i);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
return AOrgChart.types;
}); //.catch(e => {})
}
return AOrgChart.types;
}
}]);
return AOrgChart;
}();
exports.AOrgChart = AOrgChart;
_defineProperty(AOrgChart, "sub", void 0);
_defineProperty(AOrgChart, "firstime", true);
_defineProperty(AOrgChart, "instance", void 0);
_defineProperty(AOrgChart, "_topGeoOfScope", null);
_defineProperty(AOrgChart, "types", []);