2024-07-21 15:17:36 +03:00
|
|
|
/**
|
|
|
|
* Module: API for OperationSystem.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { TextMatcher } from '@/utils/utils';
|
|
|
|
|
2024-08-17 22:30:49 +03:00
|
|
|
import { ILibraryItem } from './library';
|
|
|
|
import { IOperation, IOperationSchema } from './oss';
|
2024-07-21 15:17:36 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a given target {@link IOperation} matches the specified query using.
|
|
|
|
*
|
|
|
|
* @param target - The target object to be matched.
|
|
|
|
* @param query - The query string used for matching.
|
|
|
|
*/
|
|
|
|
export function matchOperation(target: IOperation, query: string): boolean {
|
|
|
|
const matcher = new TextMatcher(query);
|
|
|
|
return matcher.test(target.alias) || matcher.test(target.title);
|
|
|
|
}
|
2024-08-17 22:30:49 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sorts library items relevant for the specified {@link IOperationSchema}.
|
|
|
|
*
|
|
|
|
* @param oss - The {@link IOperationSchema} to be sorted.
|
|
|
|
* @param items - The items to be sorted.
|
|
|
|
*/
|
|
|
|
export function sortItemsForOSS(oss: IOperationSchema, items: ILibraryItem[]): ILibraryItem[] {
|
|
|
|
const result = items.filter(item => item.location === oss.location);
|
|
|
|
for (const item of items) {
|
|
|
|
if (item.visible && item.owner === oss.owner && !result.includes(item)) {
|
|
|
|
result.push(item);
|
|
|
|
}
|
|
|
|
}
|
2024-08-18 12:55:41 +03:00
|
|
|
for (const item of items) {
|
2024-08-17 22:30:49 +03:00
|
|
|
if (item.visible && !result.includes(item)) {
|
|
|
|
result.push(item);
|
|
|
|
}
|
|
|
|
}
|
2024-08-18 12:55:41 +03:00
|
|
|
for (const item of items) {
|
2024-08-17 22:30:49 +03:00
|
|
|
if (!result.includes(item)) {
|
|
|
|
result.push(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|