@azrico/webobject 1.4.157 → 1.4.158
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import WebObject from "./WebObject";
|
|
2
|
+
type mrow = {
|
|
3
|
+
__parent__table_id: any;
|
|
4
|
+
__table_id: any;
|
|
5
|
+
__children?: any[];
|
|
6
|
+
};
|
|
2
7
|
/**
|
|
3
8
|
* This web object contains some more webobjects
|
|
4
9
|
*/
|
|
@@ -6,5 +11,14 @@ export declare class ParentWebObject extends WebObject {
|
|
|
6
11
|
constructor(is_readonly?: boolean);
|
|
7
12
|
__children: WebObject[] | undefined;
|
|
8
13
|
set_children(val: WebObject[] | undefined): void;
|
|
14
|
+
private static getParentTableId;
|
|
15
|
+
private static getTableId;
|
|
16
|
+
static fixChildParentRelations<T extends mrow>(rows: T[]): T[];
|
|
17
|
+
/**
|
|
18
|
+
* assign children of row based on all_rows
|
|
19
|
+
* @param row
|
|
20
|
+
* @param all_rows
|
|
21
|
+
*/
|
|
22
|
+
private static assignChildren;
|
|
9
23
|
}
|
|
10
24
|
export default ParentWebObject;
|
|
@@ -44,6 +44,78 @@ var ParentWebObject = exports.ParentWebObject = /*#__PURE__*/function (_WebObjec
|
|
|
44
44
|
} else val = [];
|
|
45
45
|
this.__children = val;
|
|
46
46
|
}
|
|
47
|
+
}], [{
|
|
48
|
+
key: "getParentTableId",
|
|
49
|
+
value: function getParentTableId(obj) {
|
|
50
|
+
var _ref, _obj$__parent__table_;
|
|
51
|
+
return (_ref = (_obj$__parent__table_ = obj.__parent__table_id) !== null && _obj$__parent__table_ !== void 0 ? _obj$__parent__table_ : obj.parentid) !== null && _ref !== void 0 ? _ref : obj.parent;
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
key: "getTableId",
|
|
55
|
+
value: function getTableId(obj) {
|
|
56
|
+
var _obj$__table_id;
|
|
57
|
+
return (_obj$__table_id = obj.__table_id) !== null && _obj$__table_id !== void 0 ? _obj$__table_id : obj._id;
|
|
58
|
+
}
|
|
59
|
+
}, {
|
|
60
|
+
key: "fixChildParentRelations",
|
|
61
|
+
value: function fixChildParentRelations(rows) {
|
|
62
|
+
var _this2 = this;
|
|
63
|
+
if (!Array.isArray(rows)) rows = [];
|
|
64
|
+
var anyparentid = rows.find(function (r) {
|
|
65
|
+
return _this2.getParentTableId(r);
|
|
66
|
+
});
|
|
67
|
+
var anyselfid = rows.find(function (r) {
|
|
68
|
+
return _this2.getTableId(r);
|
|
69
|
+
});
|
|
70
|
+
if (!anyparentid || !anyselfid) return rows;
|
|
71
|
+
var converted_rows = rows.filter(function (r) {
|
|
72
|
+
return r != null;
|
|
73
|
+
}).map(function (r) {
|
|
74
|
+
return {
|
|
75
|
+
parent: _this2.getParentTableId(r),
|
|
76
|
+
self: _this2.getTableId(r),
|
|
77
|
+
data: r
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
var top_level_rows = converted_rows.filter(function (r) {
|
|
81
|
+
return !r.parent;
|
|
82
|
+
});
|
|
83
|
+
var any_child = converted_rows.find(function (r) {
|
|
84
|
+
return Boolean(r.parent);
|
|
85
|
+
});
|
|
86
|
+
if (any_child) {
|
|
87
|
+
//find children of top-level parents:
|
|
88
|
+
for (var index = 0; index < top_level_rows.length; index++) {
|
|
89
|
+
var mrow = top_level_rows[index];
|
|
90
|
+
this.assignChildren(mrow, converted_rows);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return top_level_rows.map(function (r) {
|
|
94
|
+
return r.data;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* assign children of row based on all_rows
|
|
99
|
+
* @param row
|
|
100
|
+
* @param all_rows
|
|
101
|
+
*/
|
|
102
|
+
}, {
|
|
103
|
+
key: "assignChildren",
|
|
104
|
+
value: function assignChildren(row, all_rows) {
|
|
105
|
+
var my_children = all_rows.filter(function (s) {
|
|
106
|
+
return row.self == s.parent;
|
|
107
|
+
});
|
|
108
|
+
if (my_children.length > 0) {
|
|
109
|
+
//find children of my children:
|
|
110
|
+
for (var index = 0; index < my_children.length; index++) {
|
|
111
|
+
var child = my_children[index];
|
|
112
|
+
this.assignChildren(child, all_rows);
|
|
113
|
+
}
|
|
114
|
+
row.data.__children = my_children.map(function (r) {
|
|
115
|
+
return r.data;
|
|
116
|
+
});
|
|
117
|
+
} else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0) row.data.__children = undefined;
|
|
118
|
+
}
|
|
47
119
|
}]);
|
|
48
120
|
return ParentWebObject;
|
|
49
121
|
}(_WebObject2["default"]);
|