ConceptPortal-public/rsconcept/frontend/src/models/miscelanious.ts

107 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-09-11 20:31:54 +03:00
// Module: Miscellanious frontend model types.
import { IConstituenta, IRSForm } from './rsform'
2023-11-01 14:09:44 +03:00
/**
* Represents graph dependency mode.
*/
2023-09-11 20:31:54 +03:00
export enum DependencyMode {
ALL = 0,
EXPRESSION,
OUTPUTS,
INPUTS,
EXPAND_OUTPUTS,
EXPAND_INPUTS
}
2023-11-01 14:09:44 +03:00
/**
* Represents manuals topic.
*/
2023-09-11 20:31:54 +03:00
export enum HelpTopic {
MAIN = 'main',
LIBRARY = 'library',
RSFORM = 'rsform',
CSTLIST = 'cstlist',
CONSTITUENTA = 'constituenta',
GRAPH_TERM = 'graph-term',
RSTEMPLATES = 'rstemplates',
2023-09-29 16:22:49 +03:00
RSLANG = 'rslang',
TERM_CONTROL = 'terminology-control',
2023-09-11 20:31:54 +03:00
EXTEOR = 'exteor',
API = 'api'
}
2023-11-01 14:09:44 +03:00
/**
* Represents {@link IConstituenta} matching mode.
*/
2023-09-11 20:31:54 +03:00
export enum CstMatchMode {
ALL = 1,
EXPR,
TERM,
TEXT,
NAME
}
2023-11-01 14:09:44 +03:00
/**
* Represents Library filter parameters.
*/
2023-09-11 20:31:54 +03:00
export interface ILibraryFilter {
query?: string
is_personal?: boolean
is_owned?: boolean
is_common?: boolean
is_canonical?: boolean
is_subscribed?: boolean
}
2023-11-01 14:09:44 +03:00
/**
* Represents filtering strategy for Library.
*/
2023-09-11 20:31:54 +03:00
export enum LibraryFilterStrategy {
MANUAL = 'manual',
PERSONAL = 'personal',
COMMON = 'common',
SUBSCRIBE = 'subscribe',
CANONICAL = 'canonical',
OWNED = 'owned'
}
2023-11-01 14:09:44 +03:00
/**
* Represents parameters for GraphEditor.
*/
export interface GraphEditorParams {
noHermits: boolean
noTransitive: boolean
noTemplates: boolean
noTerms: boolean
allowBase: boolean
allowStruct: boolean
allowTerm: boolean
allowAxiom: boolean
allowFunction: boolean
allowPredicate: boolean
allowConstant: boolean
allowTheorem: boolean
}
2023-09-11 20:31:54 +03:00
// ================== API ====================
export function applyGraphFilter(schema: IRSForm, start: number, mode: DependencyMode): IConstituenta[] {
if (mode === DependencyMode.ALL) {
return schema.items
}
let ids: number[] | undefined = undefined
switch (mode) {
case DependencyMode.OUTPUTS: { ids = schema.graph.nodes.get(start)?.outputs; break}
case DependencyMode.INPUTS: { ids = schema.graph.nodes.get(start)?.inputs; break}
case DependencyMode.EXPAND_OUTPUTS: { ids = schema.graph.expandOutputs([start]); break}
case DependencyMode.EXPAND_INPUTS: { ids = schema.graph.expandInputs([start]); break}
}
if (!ids) {
return schema.items
} else {
return schema.items.filter(cst => ids!.find(id => id === cst.id))
}
}