filter增强
This commit is contained in:
parent
20819f0864
commit
d63b1c46db
|
|
@ -57,9 +57,7 @@ export declare function same<ED extends EntityDict, T extends keyof ED>(entity:
|
|||
* @param filter 查询当前行的条件
|
||||
* @param level
|
||||
*/
|
||||
export declare function makeTreeAncestorFilter<ED extends EntityDict, T extends keyof ED>(entity: T, parentKey: string, filter: ED[T]['Selection']['filter'], level?: number, includeAll?: true): ED[T]["Selection"]["filter"] | {
|
||||
$or: ED[T]["Selection"]["filter"][];
|
||||
};
|
||||
export declare function makeTreeAncestorFilter<ED extends EntityDict, T extends keyof ED>(entity: T, parentKey: string, filter: ED[T]['Selection']['filter'], level?: number, includeAll?: boolean, includeSelf?: boolean): ED[T]['Selection']['filter'];
|
||||
/**
|
||||
* 寻找在树形结构中满足条件的数据行的下层数据
|
||||
* 例如在area表中,如果“杭州市”满足这一条件,则希望查到更低层的“西湖区”,即可构造出满足条件的filter
|
||||
|
|
@ -68,6 +66,4 @@ export declare function makeTreeAncestorFilter<ED extends EntityDict, T extends
|
|||
* @param filter 查询当前行的条件
|
||||
* @param level
|
||||
*/
|
||||
export declare function makeTreeDescendantFilter<ED extends EntityDict, T extends keyof ED>(entity: T, parentKey: string, filter: ED[T]['Selection']['filter'], level?: number, includeAll?: true): ED[T]["Selection"]["filter"] | {
|
||||
$or: ED[T]["Selection"]["filter"][];
|
||||
};
|
||||
export declare function makeTreeDescendantFilter<ED extends EntityDict, T extends keyof ED>(entity: T, parentKey: string, filter: ED[T]['Selection']['filter'], level?: number, includeAll?: boolean, includeSelf?: boolean): ED[T]['Selection']['filter'];
|
||||
|
|
|
|||
|
|
@ -212,11 +212,14 @@ exports.same = same;
|
|||
* @param filter 查询当前行的条件
|
||||
* @param level
|
||||
*/
|
||||
function makeTreeAncestorFilter(entity, parentKey, filter, level, includeAll) {
|
||||
function makeTreeAncestorFilter(entity, parentKey, filter, level, includeAll, includeSelf) {
|
||||
var _a;
|
||||
if (level === void 0) { level = 1; }
|
||||
(0, assert_1.default)(level >= 0);
|
||||
var idInFilters = [filter];
|
||||
var idInFilters = [];
|
||||
if (includeSelf) {
|
||||
idInFilters.push(filter);
|
||||
}
|
||||
var currentLevelInFilter = filter;
|
||||
while (level > 0) {
|
||||
currentLevelInFilter = {
|
||||
|
|
@ -252,25 +255,20 @@ exports.makeTreeAncestorFilter = makeTreeAncestorFilter;
|
|||
* @param filter 查询当前行的条件
|
||||
* @param level
|
||||
*/
|
||||
function makeTreeDescendantFilter(entity, parentKey, filter, level, includeAll) {
|
||||
function makeTreeDescendantFilter(entity, parentKey, filter, level, includeAll, includeSelf) {
|
||||
var _a;
|
||||
if (level === void 0) { level = 1; }
|
||||
(0, assert_1.default)(level >= 0);
|
||||
(0, assert_1.default)(parentKey.endsWith('Id'));
|
||||
var parentKeyRef = parentKey.slice(0, parentKey.length - 2);
|
||||
var idInFilters = [filter];
|
||||
var idInFilters = [];
|
||||
if (includeSelf) {
|
||||
idInFilters.push(filter);
|
||||
}
|
||||
var currentLevelInFilter = filter;
|
||||
while (level > 0) {
|
||||
currentLevelInFilter = (_a = {},
|
||||
_a[parentKey] = {
|
||||
$in: {
|
||||
entity: entity,
|
||||
data: {
|
||||
id: 1,
|
||||
},
|
||||
filter: currentLevelInFilter,
|
||||
}
|
||||
},
|
||||
_a[parentKeyRef] = currentLevelInFilter,
|
||||
_a);
|
||||
if (includeAll) {
|
||||
idInFilters.push(currentLevelInFilter);
|
||||
|
|
|
|||
|
|
@ -224,9 +224,13 @@ export function makeTreeAncestorFilter<ED extends EntityDict, T extends keyof ED
|
|||
parentKey: string,
|
||||
filter: ED[T]['Selection']['filter'],
|
||||
level: number = 1,
|
||||
includeAll?: true) {
|
||||
includeAll?: boolean,
|
||||
includeSelf?: boolean): ED[T]['Selection']['filter'] {
|
||||
assert(level >= 0);
|
||||
let idInFilters: ED[T]['Selection']['filter'][] = [filter];
|
||||
let idInFilters: ED[T]['Selection']['filter'][] = [];
|
||||
if (includeSelf) {
|
||||
idInFilters.push(filter);
|
||||
}
|
||||
let currentLevelInFilter: ED[T]['Selection']['filter'] = filter;
|
||||
while (level > 0) {
|
||||
currentLevelInFilter = {
|
||||
|
|
@ -248,7 +252,7 @@ export function makeTreeAncestorFilter<ED extends EntityDict, T extends keyof ED
|
|||
if (includeAll) {
|
||||
return {
|
||||
$or: idInFilters,
|
||||
};
|
||||
} as ED[T]['Selection']['filter'];
|
||||
}
|
||||
return currentLevelInFilter;
|
||||
}
|
||||
|
|
@ -266,23 +270,19 @@ export function makeTreeDescendantFilter<ED extends EntityDict, T extends keyof
|
|||
parentKey: string,
|
||||
filter: ED[T]['Selection']['filter'],
|
||||
level: number = 1,
|
||||
includeAll?: true) {
|
||||
includeAll?: boolean,
|
||||
includeSelf?: boolean): ED[T]['Selection']['filter'] {
|
||||
assert(level >= 0);
|
||||
assert(parentKey.endsWith('Id'));
|
||||
const parentKeyRef = parentKey.slice(0, parentKey.length - 2);
|
||||
let idInFilters: ED[T]['Selection']['filter'][] = [filter];
|
||||
let idInFilters: ED[T]['Selection']['filter'][] = [];
|
||||
if (includeSelf) {
|
||||
idInFilters.push(filter);
|
||||
}
|
||||
let currentLevelInFilter: ED[T]['Selection']['filter'] = filter;
|
||||
while (level > 0) {
|
||||
currentLevelInFilter = {
|
||||
[parentKey]: {
|
||||
$in: {
|
||||
entity,
|
||||
data: {
|
||||
id: 1,
|
||||
},
|
||||
filter: currentLevelInFilter,
|
||||
}
|
||||
},
|
||||
[parentKeyRef]: currentLevelInFilter,
|
||||
};
|
||||
if (includeAll) {
|
||||
idInFilters.push(currentLevelInFilter);
|
||||
|
|
@ -292,7 +292,7 @@ export function makeTreeDescendantFilter<ED extends EntityDict, T extends keyof
|
|||
if (includeAll) {
|
||||
return {
|
||||
$or: idInFilters,
|
||||
};
|
||||
} as ED[T]['Selection']['filter'];
|
||||
}
|
||||
return currentLevelInFilter;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue