Skip to content

Commit

Permalink
First version of graph configurations table modal
Browse files Browse the repository at this point in the history
  • Loading branch information
james-strauss-uwa committed Aug 13, 2024
1 parent 24023c1 commit 9d076af
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/GraphConfigurationsTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as ko from "knockout";

import { Eagle } from './Eagle';
import { Node } from "./Node";

export class GraphConfigurationsTable {

static openModal = () : void => {
const eagle: Eagle = Eagle.getInstance();

eagle.showEagleIsLoading()

setTimeout(function(){
if($('.modal.show').length>0){
if($('.modal.show').attr('id')==='parameterTableModal'){
// TODO: use closeModal here!
$('#parameterTableModal').modal('hide')
eagle.showTableModal(false)
}else{
return
}
}

eagle.showTableModal(true)

},5)
}

static closeModal = (): void => {
$('#parameterTableModal').modal('hide')
Eagle.getInstance().showTableModal(false)
}

static addEmptyTableRow = () : void => {
let fieldIndex:number
const selectedNode: Node = Eagle.getInstance().selectedNode();

/*
if(ParameterTable.hasSelection()){
// A cell in the table is selected well insert new row instead of adding at the end
fieldIndex = ParameterTable.selectionParentIndex() + 1
selectedNode.addEmptyField(fieldIndex)
}else{
selectedNode.addEmptyField(-1)
//getting the length of the array to use as an index to select the last row in the table
fieldIndex = selectedNode.getFields().length-1;
}
*/

//a timeout was necessary to wait for the element to be added before counting how many there are
setTimeout(function() {
//handling selecting and highlighting the newly created row
const clickTarget = $($("#paramsTableWrapper tbody").children()[fieldIndex]).find('.selectionTargets')[0]

clickTarget.click() //simply clicking the element is best as it also lets knockout handle all of the selection and observable update processes
clickTarget.focus() // used to focus the field allowing the user to immediately start typing
$(clickTarget).trigger("select")

//scroll to new row
$("#parameterTableModal .modal-body").animate({
scrollTop: (fieldIndex*30)
}, 1000);
}, 100);
}
}


2 changes: 2 additions & 0 deletions src/KeyboardShortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Setting } from './Setting';
import { TutorialSystem } from './Tutorial';
import { Utils } from './Utils';
import { GraphRenderer } from './GraphRenderer';
import { GraphConfigurationsTable } from './GraphConfigurationsTable';


let currentEvent:any = null // this is used for keyboard shortcut functions that need the event object to function
Expand Down Expand Up @@ -214,6 +215,7 @@ export class KeyboardShortcut {
new KeyboardShortcut("open_keyboard_shortcut_modal", "Open Keyboard Shortcut Modal", ["k"], "keydown", KeyboardShortcut.Modifier.None, KeyboardShortcut.true, ['shortcuts'], KeyboardShortcut.true, KeyboardShortcut.true, (eagle): void => {eagle.smartToggleModal('shortcutsModal')}),
new KeyboardShortcut("open_parameter_table_modal", "Open Parameter Table Modal", ["t"], "keydown", KeyboardShortcut.Modifier.None, KeyboardShortcut.true, ['fields','field','node','table'], function(){return !Setting.findValue(Setting.STUDENT_SETTINGS_MODE)}, function(){return !Setting.findValue(Setting.STUDENT_SETTINGS_MODE)}, (eagle): void => {ParameterTable.openModal(ParameterTable.Mode.NodeFields, ParameterTable.SelectType.Normal);}),
new KeyboardShortcut("open_graph_configuration_table_modal", "Open Graph Configuration Table Modal", ["t"], "keydown", KeyboardShortcut.Modifier.Shift, KeyboardShortcut.true, ['fields','field','node','graph','table','favourites'], KeyboardShortcut.true, KeyboardShortcut.true, (eagle): void => {ParameterTable.openModal(ParameterTable.Mode.GraphConfig, ParameterTable.SelectType.Normal);}),
new KeyboardShortcut("open_graph_configurations_table_modal", "Open Graph Configurations Table Modal", ["c"], "keydown", KeyboardShortcut.Modifier.Shift, KeyboardShortcut.true, [], KeyboardShortcut.true, KeyboardShortcut.true, (eagle): void => {GraphConfigurationsTable.openModal();}),
new KeyboardShortcut("undo", "Undo", ["z"], "keydown", KeyboardShortcut.Modifier.None, KeyboardShortcut.true, ['back','history'], KeyboardShortcut.true, KeyboardShortcut.true, (eagle): void => {eagle.undo().prevSnapshot(eagle)}),
new KeyboardShortcut("redo", "Redo", ["z"], "keydown", KeyboardShortcut.Modifier.Shift, KeyboardShortcut.true, ['forward','history'], KeyboardShortcut.true, KeyboardShortcut.true, (eagle): void => {eagle.undo().nextSnapshot(eagle)}),
new KeyboardShortcut("check_graph", "Check Graph", ["!"], "keydown", KeyboardShortcut.Modifier.Shift, KeyboardShortcut.true, ['error','errors','fix'], KeyboardShortcut.allowGraphEditing, function(){return KeyboardShortcut.graphNotEmpty && Setting.findValue(Setting.ALLOW_GRAPH_EDITING) }, (eagle): void => {eagle.showGraphErrors();}),
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { Errors } from './Errors';
import { GitHub } from './GitHub';
import { GitLab } from './GitLab';
import { GraphConfig } from "./GraphConfig";
import { GraphConfigurationsTable } from "./GraphConfigurationsTable";
import { GraphRenderer } from "./GraphRenderer";
import { Hierarchy } from './Hierarchy';
import { KeyboardShortcut } from './KeyboardShortcut';
Expand Down Expand Up @@ -76,6 +77,7 @@ $(function(){
(<any>window).EagleConfig = EagleConfig;
(<any>window).Errors = Errors;
(<any>window).GraphConfig = GraphConfig;
(<any>window).GraphConfigurationsTable = GraphConfigurationsTable;
(<any>window).Hierarchy = Hierarchy;
(<any>window).ParameterTable = ParameterTable;
(<any>window).Repositories = Repositories;
Expand Down
1 change: 1 addition & 0 deletions src/require-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ require.config({
"RightClick": "./static/built/RightClick",
"Repositories": "./static/built/Repositories",
"ParameterTable": "./static/built/ParameterTable",
"GraphConfigurationsTable": "./static/built/GraphConfigurationsTable"
},
shim: {
"bootstrap": {
Expand Down
1 change: 1 addition & 0 deletions templates/modals.html
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ <h5>Editor for the Advanced Graph Language Environment</h5>
{% include 'modals/shortcuts.html' %}

{% include 'modals/parameter_table.html' %}
{% include 'modals/graph_configurations_table.html' %}

{% include 'modals/edit_edge.html' %}
{% include 'modals/edit_field.html' %}
Expand Down
62 changes: 62 additions & 0 deletions templates/modals/graph_configurations_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!-- Graph Configurations Table Modal -->
<div class="modal fade" id="graphConfigurationsTableModal" tabindex="-1" role="dialog" aria-labelledby="graphConfigurationsTableModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
Graph Configurations Table
</h5>
<div class="searchBarContainer" data-bind="clickBubble:false, click:function(){}">
<i class="material-icons md-18 searchBarIcon">search</i>
<a href="#" data-bind="click:function(data, event){$root.emptySearchBar(Eagle.tableSearchString,data,event)}">
<i class="material-icons md-18 searchBarIconClose">close</i>
</a>
<input class="componentSearchBar" type="text" placeholder="Search: eg. app, string" data-bind="valueUpdate: ['afterkeydown', 'input'], value:Eagle.tableSearchString, event:{keyup: function(data,event){$root.setSearchBarClearBtnState(data,event)}},eagleTooltip:`Search for names, types, anything really! You may enter several terms that should match separated by a ','`">
</div>
</div>
<div class="modal-body">
<!-- ko if: logicalGraph().graphConfigs().length === 0 -->
<div class="container h-100">
<div class="row align-items-center h-100">
<div class="col-md-12 text-center">
<span class="fs-3">No graph configurations</span>
<br/>
<span class="fs-6">Create a configuration using the Config menu in the navbar</span>
</div>
</div>
</div>
<!-- /ko -->
<!-- ko if: logicalGraph().graphConfigs().length !== 0 -->
<table id="paramsTableWrapper">
<div id="tableInspector">
<input id="tableInspectorSelection" type="text" placeholder="Selection" data-bind="value: ParameterTable.formatTableInspectorSelection()" readonly>
<input id="tableInspectorValue" type="text" placeholder="Content" data-bind="value: ParameterTable.formatTableInspectorValue(), readonly: ParameterTable.selectionReadonly(), event: {keyup: ParameterTable.tableInspectorUpdateSelection($element.value)}">
</div>
<thead>
<tr>
<th data-bind="eagleTooltip:''" data-bs-placement="top"></th>
<th data-bind="eagleTooltip:''" data-bs-placement="top">Config Name</th>
</tr>
</thead>
<tbody data-bind="foreach: graphConfigs()">
<!-- ko if: $data.fitsTableSearchQuery() -->
<tr data-bind="attr: {'id' : 'tableRow_'+$data.getId()}">
<td class='columnCell column_KeyAttr'>
<!-- kept for now as we will need the space for the row drag handle -->
</td>
<td class='columnCell column_NodeName'>
<input class="tableParameter" type="string" data-bind="value: $root.logicalGraph().findNodeByKey(nodeKey()).getName(), disabled: true, eagleTooltip: $root.logicalGraph().findNodeByKey(nodeKey()).getDescription()">
</td>
</tr>
<!-- /ko -->
</tbody>
</table>
<!-- /ko -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="graphConfigurationsTableModalAddParameterButton" data-bind="click: GraphConfigurationsTable.addEmptyTableRow, clickBubble:false" ><span id="parameterTableModalAddParameter">Add Parameter</span></button>
<button type="button" class="btn btn-primary" id="graphConfigurationsTableModalAffirmativeButton" data-bs-dismiss="modal" data-bind="clickBubble:false"><span id="graphConfigurationsTableModalAffirmativeAnswer">Close</span></button>
</div>
</div>
</div>
</div>

0 comments on commit 9d076af

Please sign in to comment.