mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Fix multi-select with private items
This commit is contained in:
parent
d457f66e8b
commit
87479c32de
@ -27,23 +27,33 @@ export class SelectComponent extends AbstractInputComponent<number> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_items: any[]
|
_items: any[]
|
||||||
privateItems: any[] = []
|
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set items(items) {
|
set items(items) {
|
||||||
this._items = items
|
this._items = items
|
||||||
if (this.value) this.checkForPrivateItem(this.value)
|
if (items && this.value) this.checkForPrivateItems(this.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
writeValue(newValue: any): void {
|
writeValue(newValue: any): void {
|
||||||
if (newValue && this._items) this.checkForPrivateItem(newValue)
|
if (newValue && this._items) {
|
||||||
|
this.checkForPrivateItems(newValue)
|
||||||
|
this.items = [...this._items] // we need to explicitly re-set items
|
||||||
|
}
|
||||||
super.writeValue(newValue)
|
super.writeValue(newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForPrivateItem(value) {
|
checkForPrivateItems(value: any) {
|
||||||
if (this._items.find((i) => i.id === value) === undefined) {
|
if (Array.isArray(value) && value.length > 0) {
|
||||||
this.privateItems.push({
|
value.forEach((id) => this.checkForPrivateItem(id))
|
||||||
id: value,
|
} else {
|
||||||
|
this.checkForPrivateItem(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkForPrivateItem(id) {
|
||||||
|
if (this._items.find((i) => i.id === id) === undefined) {
|
||||||
|
this._items.push({
|
||||||
|
id: id,
|
||||||
name: $localize`Private`,
|
name: $localize`Private`,
|
||||||
private: true,
|
private: true,
|
||||||
})
|
})
|
||||||
@ -51,7 +61,7 @@ export class SelectComponent extends AbstractInputComponent<number> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get items(): any[] {
|
get items(): any[] {
|
||||||
return this._items?.concat(this.privateItems)
|
return this._items
|
||||||
}
|
}
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user