@barteh/core
Version:
a common library for barteh based projects
178 lines (149 loc) • 4.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AGeo = 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; }
var AGeo =
/*#__PURE__*/
function () {
function AGeo() {
_classCallCheck(this, AGeo);
_defineProperty(this, "sub", void 0);
_defineProperty(this, "firstime", true);
_defineProperty(this, "ChiledList", {});
_defineProperty(this, "layerCount", 6);
_defineProperty(this, "layer_selected_geo", {
'0': {
geoid: "IR",
name: "ایران",
type: 0,
parent: "",
typename: "کشور"
},
'1': {},
'2': {},
'3': {}
});
_defineProperty(this, "layer_list", {
'0': [],
'1': [],
'2': [],
'3': [],
'4': []
});
if (!AGeo.instance) AGeo.instance = this;
this.sub = this.sub || new _rxjs.default.BehaviorSubject();
this.layer_list = this.layer_list || {
'0': [],
'1': [],
'2': [],
'3': [],
'4': []
};
this.layer_list[0] = [{
geoid: "IR",
name: "ایران",
type: 0,
parent: "",
typename: "کشور"
}];
this.changeSelected(0, this.layer_selected_geo[0]);
return AGeo.instance;
}
_createClass(AGeo, [{
key: "getChiledList",
value: function getChiledList(parent, refresh) {
var _this = this;
return new Promise(function (a
/*,b*/
) {
if (!_this.ChiledList[parent] || refresh) {
_this.loadChiledList(parent, refresh).then(function (z) {
_this.ChiledList[parent] = z;
a(_this.ChiledList[parent]);
});
} else {
a(_this.ChiledList[parent]);
}
});
}
}, {
key: "loadChiledList",
value: function loadChiledList(parent
/*,refresh*/
) {
var _this2 = this;
this.ChiledList[parent.toString()] = null;
return new Promise(function (a
/*,b*/
) {
//Server.controller("useredit","countusertogeo",{geoid:parent})
_asService.Server.controller("plancontroller", "sel_geo", {
geoid: parent
}).then(function (r) {
_this2.ChiledList[parent] = r.data;
a(_this2.ChiledList[parent]); // return this.ChiledList[parent];
});
});
}
}, {
key: "changeSelected",
value: function changeSelected(layer, obj) {
var _this3 = this;
//
this.layer_selected_geo[layer] = obj; // if(this.layer_type[layer]==obj.type){
// if(layer==obj.type){
// this.clear_childs(layer);
//}else {
if (layer + 1 < this.layerCount) {
this.getChiledList(obj.geoid).then(function () {
_this3.layer_list[layer + 1] = _this3.ChiledList[obj.geoid];
_this3.clear_childs(layer + 1);
});
} // }
}
}, {
key: "clear_childs",
value: function clear_childs(layer) {
this.layer_selected_geo[layer] = {};
for (var i = layer + 1; i < this.layerCount; i++) {
this.layer_list[i] = null;
this.layer_selected_geo[i] = {};
}
}
}, {
key: "when",
get: function get() {
return new Promise(function (a
/*,b*/
) {
a(AGeo.instance);
});
}
}], [{
key: "get",
value: function get(refresh) {
console.log(55);
var geo = new AGeo();
if (geo.firstime || refresh) {
geo.firstime = false;
geo.getChiledList("IR").then(function () {
geo.sub.next(geo);
});
}
return geo.sub.filter(function (a) {
return a;
});
}
}]);
return AGeo;
}();
exports.AGeo = AGeo;
_defineProperty(AGeo, "instance", null);