mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-04 04:35:06 +03:00
TSK-1182 Filter "Is not" doesn't work (#2985)
This commit is contained in:
parent
abcaa2e980
commit
db4d240f0a
@ -199,6 +199,22 @@ export class StatusMiddleware extends BasePresentationMiddleware implements Pres
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private categorizeStatus (mgr: StatusManager, attr: AnyAttribute, target: Array<Ref<Status>>): Array<Ref<Status>> {
|
||||||
|
for (const sid of [...target]) {
|
||||||
|
const s = mgr.byId.get(sid)
|
||||||
|
if (s !== undefined) {
|
||||||
|
const statuses = mgr.statuses.filter(
|
||||||
|
(it) =>
|
||||||
|
it.ofAttribute === attr._id &&
|
||||||
|
it.name.toLowerCase().trim() === s.name.toLowerCase().trim() &&
|
||||||
|
it._id !== s._id
|
||||||
|
)
|
||||||
|
target.push(...statuses.map((it) => it._id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target.filter((it, idx, arr) => arr.indexOf(it) === idx)
|
||||||
|
}
|
||||||
|
|
||||||
private async updateQueryOptions<T extends Doc>(
|
private async updateQueryOptions<T extends Doc>(
|
||||||
allAttrs: Map<string, AnyAttribute>,
|
allAttrs: Map<string, AnyAttribute>,
|
||||||
h: Hierarchy,
|
h: Hierarchy,
|
||||||
@ -211,34 +227,36 @@ export class StatusMiddleware extends BasePresentationMiddleware implements Pres
|
|||||||
if (attr.type._class === core.class.RefTo && h.isDerived((attr.type as RefTo<Doc>).to, core.class.Status)) {
|
if (attr.type._class === core.class.RefTo && h.isDerived((attr.type as RefTo<Doc>).to, core.class.Status)) {
|
||||||
const mgr = await this.getManager()
|
const mgr = await this.getManager()
|
||||||
let target: Array<Ref<Status>> = []
|
let target: Array<Ref<Status>> = []
|
||||||
|
let targetNin: Array<Ref<Status>> = []
|
||||||
statusFields.push(attr)
|
statusFields.push(attr)
|
||||||
const v = (query as any)[attr.name]
|
const v = (query as any)[attr.name]
|
||||||
|
|
||||||
if (v !== undefined) {
|
if (v !== undefined) {
|
||||||
// Only add filter if we have filer inside.
|
// Only add filter if we have filer inside.
|
||||||
if (v?.$in !== undefined) {
|
if (typeof v === 'string') {
|
||||||
target.push(...v.$in)
|
target.push(v as Ref<Status>)
|
||||||
} else {
|
} else {
|
||||||
target.push(v)
|
if (v.$in !== undefined) {
|
||||||
|
target.push(...v.$in)
|
||||||
|
} else if (v.$nin !== undefined) {
|
||||||
|
targetNin.push(...v.$nin)
|
||||||
|
} else if (v.$ne !== undefined) {
|
||||||
|
targetNin.push(v.$ne)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find all similar name statues for same attribute name.
|
// Find all similar name statues for same attribute name.
|
||||||
for (const sid of [...target]) {
|
target = this.categorizeStatus(mgr, attr, target)
|
||||||
const s = mgr.byId.get(sid)
|
targetNin = this.categorizeStatus(mgr, attr, targetNin)
|
||||||
if (s !== undefined) {
|
if (target.length > 0 || targetNin.length > 0) {
|
||||||
const statuses = mgr.statuses.filter(
|
;(query as any)[attr.name] = {}
|
||||||
(it) =>
|
if (target.length > 0) {
|
||||||
it.ofAttribute === attr._id &&
|
;(query as any)[attr.name].$in = target
|
||||||
it.name.toLowerCase().trim() === s.name.toLowerCase().trim() &&
|
}
|
||||||
it._id !== s._id
|
if (targetNin.length > 0) {
|
||||||
)
|
;(query as any)[attr.name].$nin = targetNin
|
||||||
if (statuses !== undefined) {
|
|
||||||
target.push(...statuses.map((it) => it._id))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
target = target.filter((it, idx, arr) => arr.indexOf(it) === idx)
|
|
||||||
;(query as any)[attr.name] = { $in: target }
|
|
||||||
|
|
||||||
if (finalOptions.lookup !== undefined) {
|
if (finalOptions.lookup !== undefined) {
|
||||||
// Remove lookups by status field
|
// Remove lookups by status field
|
||||||
|
Loading…
Reference in New Issue
Block a user