2023-11-17 20:51:13 +03:00
|
|
|
/**
|
2023-12-26 14:23:51 +03:00
|
|
|
* Module: API for miscellaneous frontend model types. Future targets for refactoring aimed at extracting modules.
|
2023-11-17 20:51:13 +03:00
|
|
|
*/
|
2023-12-26 14:23:51 +03:00
|
|
|
import { DependencyMode } from './miscellaneous';
|
2023-11-17 20:51:13 +03:00
|
|
|
import { IConstituenta, IRSForm } from './rsform';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter list of {@link ILibraryItem} to a given query.
|
|
|
|
*/
|
|
|
|
export function applyGraphFilter(target: IRSForm, start: number, mode: DependencyMode): IConstituenta[] {
|
|
|
|
if (mode === DependencyMode.ALL) {
|
|
|
|
return target.items
|
|
|
|
}
|
|
|
|
let ids: number[] | undefined = undefined
|
|
|
|
switch (mode) {
|
|
|
|
case DependencyMode.OUTPUTS: { ids = target.graph.nodes.get(start)?.outputs; break}
|
|
|
|
case DependencyMode.INPUTS: { ids = target.graph.nodes.get(start)?.inputs; break}
|
|
|
|
case DependencyMode.EXPAND_OUTPUTS: { ids = target.graph.expandOutputs([start]); break}
|
|
|
|
case DependencyMode.EXPAND_INPUTS: { ids = target.graph.expandInputs([start]); break}
|
|
|
|
}
|
|
|
|
if (!ids) {
|
|
|
|
return target.items
|
|
|
|
} else {
|
|
|
|
return target.items.filter(cst => ids!.find(id => id === cst.id))
|
|
|
|
}
|
2023-12-13 14:32:57 +03:00
|
|
|
}
|