Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utility features for FTA #29

Merged
merged 29 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2c10e0f
comp IDs are underlined when description is shown + min size for gates
Drakae Mar 5, 2024
dc0857f
stpa: IDs are underlined when description is also shown
Drakae Mar 6, 2024
b54ca66
added check for conflicting UCAs
Drakae Mar 7, 2024
54551d6
added chekc for conflicting DCAs with UCAs
Drakae Apr 11, 2024
d26cf0f
removed "hide" from synthesis options
Drakae Jun 3, 2024
98e438d
Merge branch 'master' into jep/utility
Drakae Jun 3, 2024
69f694b
fixed node ids for translation of json to elkt
Drakae Jun 11, 2024
ec31aef
fixed conflict detection of UCAs and DCAs
Drakae Jun 11, 2024
cd0b771
added check for dublicate DCAs
Drakae Jun 11, 2024
97483f6
subcomponents in control structure have flexible node size option
Drakae Jun 11, 2024
8f4a186
fixed linking of context table with UCAs in editor
Drakae Jun 11, 2024
2b2603a
updated node version in github actions
Drakae Jun 19, 2024
5e94716
updated node version in github actions
Drakae Jun 19, 2024
0cabd9d
fixed showing of description
Drakae Jun 21, 2024
a8e2bcf
update diagram without resetting viewport
Drakae Jun 21, 2024
8a9096c
fixed filtering of loss scenarios
Drakae Jun 21, 2024
882f80f
update diagram on change
Drakae Jun 24, 2024
cf76985
context table: selected control action is not resetted when updating
Drakae Jun 24, 2024
1e1d986
context table: no hard reset when file changes
Drakae Jun 24, 2024
76493f9
context table: subcomponents are shown for action selection
Drakae Jun 24, 2024
3fb5bbf
diagram reload when opening new text document
Drakae Jun 24, 2024
28ade7d
validator checks that actions of subcomps are referenced bz UCA
Drakae Jun 24, 2024
dca11f7
improved content assist for UCAs + DCAs
Drakae Jun 24, 2024
27cb802
updates options for svg generation
Drakae Jun 25, 2024
322045e
SVG Gen: fixed option + update view only when not triggered by svg gen
Drakae Jun 25, 2024
06e6940
nodes are not aligned based on out/in-coming edges
Drakae Jun 26, 2024
fffa74f
ID enforcer expanded with IDs for DCAs and DCARules
Drakae Jun 27, 2024
bbff8d2
formatting
Drakae Jun 27, 2024
baa8768
mka feedback
Drakae Jun 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14.x
node-version: 16.x
- run: yarn
- run: yarn lint
- run: yarn build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14.x
node-version: 16.x
registry-url: 'https://registry.npmjs.org'
scope: '@kieler'
- run: yarn
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14.x"
node-version: "16.x"
registry-url: 'https://registry.npmjs.org'
scope: '@kieler'
- run: yarn
Expand All @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14.x"
node-version: "16.x"
- run: yarn
- run: yarn package

Expand Down
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@
"reflect-metadata": "^0.1.13",
"feather-icons": "^4.28.0",
"sprotty-vscode-webview": "^0.5.0",
"@kieler/table-webview": "^0.0.3",
"@kieler/table-webview": "^0.0.5",
"snabbdom": "^3.5.1",
"dayjs": "^1.11.8"
},
Expand Down
17 changes: 13 additions & 4 deletions extension/src-context-table/html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,22 @@ export function createSelector(id: string, index: number, options: string[], top
}
}

/**
* Creates a table VNode enclosed by a div element with the 'context table' class.
* @param id The id of the table.
* @returns A table VNode enclosed by a div element.
*/
export function initContextTable(id: string): VNode {
return <div class={{contextTable: true}}>{createTable(id)}</div>;
}

/**
* Creates a table VNode.
* @param id The id of the table.
* @returns A table VNode.
*/
export function createTable(id: string): VNode {
return <div class={{contextTable: true}}><table attrs={{ id: id }}></table></div>;
return <table attrs={{ id: id }}></table>;
}

/**
Expand Down Expand Up @@ -87,7 +96,7 @@ export function createText(text: string): VNode {
* @param colspan The colspan of the header.
* @returns A header element.
*/
export function createHeaderElement(header: string, top: string, rowspan?: number, colspan?: number) {
export function createHeaderElement(header: string, top: string, rowspan?: number, colspan?: number): VNode {
if (rowspan && colspan) {
return <th attrs={{ rowspan: rowspan, colspan: colspan }} style={{ top: top }}>{header}</th>;
} else if (rowspan) {
Expand All @@ -104,7 +113,7 @@ export function createHeaderElement(header: string, top: string, rowspan?: numbe
* @param headers The headers of the header row.
* @returns A header row element.
*/
export function createHeaderRow(headers: VNode[]) {
export function createHeaderRow(headers: VNode[]): VNode {
return <tr>
{...headers}
</tr>;
Expand All @@ -115,7 +124,7 @@ export function createHeaderRow(headers: VNode[]) {
* @param headers The header rows
* @returns A thead element containing the given header rows.
*/
export function createTHead(headers: VNode[]) {
export function createTHead(headers: VNode[]): VNode {
return <thead>{...headers}</thead>;
}

Expand Down
109 changes: 73 additions & 36 deletions extension/src-context-table/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,33 @@
* SPDX-License-Identifier: EPL-2.0
*/

import './css/table.css';
import { Table } from '@kieler/table-webview/lib/table';
import { SendContextTableDataAction } from './actions';
import { createHeaderElement, createHeaderRow, createRow, createTable, createTHead, patch } from './html';
import "./css/table.css";
import { Table } from "@kieler/table-webview/lib/table";
import { SendContextTableDataAction } from "./actions";
import { createHeaderElement, createHeaderRow, createRow, createTable, createTHead, initContextTable, patch } from "./html";
import {
addSelector, addText, ContextCell, ContextTableControlAction, convertControlActionsToStrings, replaceSelector, ContextTableRule, ContextTableSystemVariables,
Type, ContextTableVariable, ContextTableVariableValues, Row
} from './utils';
addSelector,
addText,
ContextCell,
ContextTableControlAction,
convertControlActionsToStrings,
replaceSelector,
ContextTableRule,
ContextTableSystemVariables,
Type,
ContextTableVariable,
ContextTableVariableValues,
Row,
} from "./utils";
import { VNode } from "snabbdom";
import { createResults, determineUsedRules } from './context-table-logic';
import { createResults, determineUsedRules } from "./context-table-logic";

interface vscode {
postMessage(message: any): void;
}
declare const vscode: vscode;

export class ContextTable extends Table {

/** Ids for the html elements */
protected actionSelectorId = "select_action";
protected typeSelectorId = "select_type";
Expand Down Expand Up @@ -62,17 +71,17 @@ export class ContextTable extends Table {

constructor() {
super();
document.addEventListener('click', (event) => {
document.addEventListener("click", event => {
const node = event.target;
const owner = (node as HTMLElement).parentElement;
if (owner) {
if (this.lastSelected) {
this.lastSelected.parentElement?.classList.remove('focused');
this.lastSelected.classList.remove('selected');
this.lastSelected.parentElement?.classList.remove("focused");
this.lastSelected.classList.remove("selected");
}
this.lastSelected = node as HTMLElement;
owner.classList.add('focused');
(node as HTMLElement).classList.add('selected');
owner.classList.add("focused");
(node as HTMLElement).classList.add("selected");
}
});
}
Expand Down Expand Up @@ -115,19 +124,26 @@ export class ContextTable extends Table {
protected initHtml(identifier: string): void {
this.identifier = identifier;
this.tableId = this.identifier + "_table";
const mainDiv = document.getElementById(identifier + '_container');
const mainDiv = document.getElementById(identifier + "_container");
if (mainDiv) {
// Create text and selector element for selecting a control action
addText(mainDiv, "Choose a Control Action:");
addSelector(mainDiv, this.actionSelectorId, 0, [], "13px", "170px");

// Create text and selector element for selecting the action type
addText(mainDiv, "Choose a Type:");
addSelector(mainDiv, this.typeSelectorId, this.selectedType, ["provided", "not provided", "both"], "43px", "115px");
addSelector(
mainDiv,
this.typeSelectorId,
this.selectedType,
["provided", "not provided", "both"],
"43px",
"115px"
Drakae marked this conversation as resolved.
Show resolved Hide resolved
);

// add listener
const htmlTypeSelector = document.getElementById(this.typeSelectorId) as HTMLSelectElement;
htmlTypeSelector.addEventListener('change', () => {
htmlTypeSelector.addEventListener("change", () => {
switch (htmlTypeSelector.selectedIndex) {
case 0:
this.selectedType = Type.PROVIDED;
Expand All @@ -147,7 +163,7 @@ export class ContextTable extends Table {
// create a table
const placeholderTable = document.createElement("div");
mainDiv.append(placeholderTable);
const table = createTable(this.tableId);
const table = initContextTable(this.tableId);
patch(placeholderTable, table);
}
}
Expand All @@ -160,14 +176,21 @@ export class ContextTable extends Table {
if (selector) {
// translate control actions to strings and add them to the selector
const actions = convertControlActionsToStrings(this.controlActions);
replaceSelector(selector, actions, 0);
// set the selector to the previously selected action if it still exists
const currentSelected = selector.value;
const newIndex = actions.findIndex(action => action === currentSelected);
replaceSelector(selector, actions, newIndex === -1 ? 0 : newIndex);

// update currently selected control action
this.updateControlActionSelection(0);
this.updateControlActionSelection(newIndex === -1 ? 0 : newIndex);

// add listener
const htmlActionSelector = document.getElementById(this.actionSelectorId) as HTMLSelectElement;
htmlActionSelector.addEventListener('change', () => {
if (newIndex !== -1) {
// update the selected control action to the one before the change
htmlActionSelector.value = actions[newIndex];
}
htmlActionSelector.addEventListener("change", () => {
this.updateControlActionSelection(htmlActionSelector.selectedIndex);
this.updateTable();
});
Expand All @@ -178,7 +201,9 @@ export class ContextTable extends Table {
* Sets the current variables based on the current controller.
*/
protected setCurrentVariables(): void {
const variables = this.systemVariables.find(systemVariable => systemVariable.system === this.selectedControlAction.controller)?.variables;
const variables = this.systemVariables.find(
systemVariable => systemVariable.system === this.selectedControlAction.controller
)?.variables;
if (variables) {
this.currentVariables = variables;
} else {
Expand All @@ -193,7 +218,12 @@ export class ContextTable extends Table {
const headers: VNode[] = [];
// the first header column is for the context and needs to span as many columns as there are context variables
if (this.currentVariables.length > 0) {
const contextVariablesHeader = createHeaderElement("Context Variables", "0px", undefined, this.currentVariables.length);
const contextVariablesHeader = createHeaderElement(
"Context Variables",
"0px",
undefined,
this.currentVariables.length
);
headers.push(contextVariablesHeader);
}

Expand Down Expand Up @@ -295,8 +325,13 @@ export class ContextTable extends Table {
for (let i = 0; i < this.contexts.length; i++) {
const variables = this.contexts[i];
// determine the used rules
const usedRules = determineUsedRules(variables, this.rules, this.selectedControlAction.controller,
this.selectedControlAction.action, this.selectedType);
const usedRules = determineUsedRules(
variables,
this.rules,
this.selectedControlAction.controller,
this.selectedControlAction.action,
this.selectedType
);
// save them and map to the current context
this.resultsRules.push(usedRules);
this.resultRulesToContext.set(this.resultsRules.length - 1, i);
Expand All @@ -317,24 +352,23 @@ export class ContextTable extends Table {
}

/**
* Creates a row instance based on the {@code resultRulesIndex}.
* Creates a row instance based on the {@code resultRulesIndex}.
* @param resultRulesIndex Determines which resultsRule should be used.
* @returns a row instance with the context and the result determines by {@code resultRulesIndex}.
*/
protected createRowInstance(resultRulesIndex: number): Row {
// get the context
const context = this.contexts[this.resultRulesToContext.get(resultRulesIndex)!];
// get the hazards and rules
const results: { hazards: string[], rules: ContextTableRule[]; }[] = [];
const results: { hazards: string[]; rules: ContextTableRule[] }[] = [];
this.resultsRules[resultRulesIndex].forEach(resultRules => {
results.push({ hazards: resultRules.map(rule => rule.hazards.toString()), rules: resultRules });
});
return { variables: context, results: results };
}


/**
* Creates and appends one non-header row to the table.
* Creates and appends one non-header row to the table.
* @param table The HTMLTableElement to apply the row to.
* @param row The row to add.
* @param id The id of the row.
Expand All @@ -347,7 +381,9 @@ export class ContextTable extends Table {
let cells: ContextCell[] = [];
if (row.variables.length > 0) {
// values of the context variables
cells = row.variables.map(variable => { return { cssClass: "context-variable", value: variable.value, colSpan: 1 }; });
cells = row.variables.map(variable => {
return { cssClass: "context-variable", value: variable.value, colSpan: 1 };
});
// append the result cells
cells = cells.concat(createResults(row.results));
} else {
Expand All @@ -372,16 +408,19 @@ export class ContextTable extends Table {
patch(placeholderRow, htmlRow);
}


/**
* Generates all possible value combinations of the given variables.
* @param variableIndex Index to determine from which variable to apply a value next.
* @param variableValues All variables with their possible values for which the combinations should be generated.
* @param determinedValues The already determined variable values.
* @returns All possible value combinations of the given variables.
*/
protected createContexts(variableIndex: number, variableValues: ContextTableVariableValues[], determinedValues: ContextTableVariable[]): (ContextTableVariable[])[] {
let result: (ContextTableVariable[])[] = [];
protected createContexts(
variableIndex: number,
variableValues: ContextTableVariableValues[],
determinedValues: ContextTableVariable[]
): ContextTableVariable[][] {
let result: ContextTableVariable[][] = [];
// load the values of the current recursion's variable
const currentValues = variableValues[variableIndex].values;
const lastVariable = variableIndex === variableValues.length - 1;
Expand All @@ -403,8 +442,6 @@ export class ContextTable extends Table {
}
return result;
}


}

new ContextTable();
new ContextTable();
Loading
Loading