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) {
|
2023-12-28 14:04:44 +03:00
|
|
|
return target.items;
|
2023-11-17 20:51:13 +03:00
|
|
|
}
|
2023-12-28 14:04:44 +03:00
|
|
|
let ids: number[] | undefined = undefined;
|
2023-11-17 20:51:13 +03:00
|
|
|
switch (mode) {
|
2023-12-28 14:04:44 +03:00
|
|
|
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;
|
|
|
|
}
|
2023-11-17 20:51:13 +03:00
|
|
|
}
|
|
|
|
if (!ids) {
|
2023-12-28 14:04:44 +03:00
|
|
|
return target.items;
|
2023-11-17 20:51:13 +03:00
|
|
|
} else {
|
2023-12-28 14:04:44 +03:00
|
|
|
return target.items.filter(cst => ids!.find(id => id === cst.id));
|
2023-11-17 20:51:13 +03:00
|
|
|
}
|
2023-12-28 14:04:44 +03:00
|
|
|
}
|