Skip to content

Commit 6cc09af

Browse files
committed
feat: add OCL Reaction editor module
1 parent 514f1d5 commit 6cc09af

8 files changed

Lines changed: 172 additions & 11 deletions

File tree

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"mf-parser": "^1.5.0",
8383
"mime-types": "^2.1.35",
8484
"node-jsgraph": "2.4.15",
85-
"openchemlib": "^9.6.0",
85+
"openchemlib": "^9.14.0",
8686
"quill": "2.0.2",
8787
"quill-resize-module": "^2.0.4",
8888
"quill-table-better": "^1.2.1",
@@ -92,6 +92,6 @@
9292
"twig": "^1.17.1"
9393
},
9494
"volta": {
95-
"node": "20.19.1"
95+
"node": "20.19.5"
9696
}
9797
}

src/modules/types/science/chemistry/folder.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"moduleName": "OCL Molecule editor",
1313
"url": "modules/types/science/chemistry/ocl_editor/"
1414
},
15+
{
16+
"moduleName": "OCL Reaction editor",
17+
"url": "modules/types/science/chemistry/ocl_reaction_editor/"
18+
},
1519
{
1620
"moduleName": "Periodic table",
1721
"url": "modules/types/science/chemistry/periodic_table/"

src/modules/types/science/chemistry/ocl_editor/controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ define([
2121
'modules/types/science/chemistry/ocl_editor/help.html',
2222
);
2323
ui.dialog(
24-
`<iframe src=${url} width="100%", height="100%" frameBorder="0"></iframe>`,
24+
`<iframe src=${url} width="100%" height="100%" frameBorder="0"></iframe>`,
2525
{
2626
width: Math.min(w - 40, 800),
2727
height: h - 70,
@@ -103,7 +103,7 @@ define([
103103

104104
Controller.prototype.moduleInformation = {
105105
name: 'OCL Molecule editor',
106-
description: 'Molecule editor using the openchemlib javascript library',
106+
description: 'Molecule editor using the OpenChemLib JavaScript library',
107107
author: 'Michael Zasso',
108108
date: '11.05.2015',
109109
license: 'BSD',
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
'use strict';
2+
3+
define([
4+
'modules/default/defaultcontroller',
5+
'openchemlib',
6+
'src/util/ui',
7+
], function (Default, OCL, ui) {
8+
function Controller() {
9+
this.currentReaction = '';
10+
}
11+
12+
$.extend(true, Controller.prototype, Default);
13+
14+
Controller.prototype.getToolbar = function () {
15+
const base = Default.getToolbar.call(this);
16+
base.unshift({
17+
onClick() {
18+
const w = $(window).width();
19+
const h = $(window).height();
20+
const url = require.toUrl(
21+
'modules/types/science/chemistry/ocl_editor/help.html',
22+
);
23+
ui.dialog(
24+
`<iframe src=${url} width="100%" height="100%" frameBorder="0"></iframe>`,
25+
{
26+
width: Math.min(w - 40, 800),
27+
height: h - 70,
28+
title: 'OpenChemLib editor Help',
29+
},
30+
);
31+
},
32+
title: 'Help',
33+
cssClass: 'fa fa-question',
34+
ifLocked: true,
35+
});
36+
return base;
37+
};
38+
39+
Controller.prototype.moduleInformation = {
40+
name: 'OCL Reaction editor',
41+
description: 'Reaction editor using the OpenChemLib JavaScript library',
42+
author: 'Michael Zasso',
43+
date: '29.10.2025',
44+
license: 'BSD',
45+
cssClass: 'ocl_reaction_editor',
46+
};
47+
48+
Controller.prototype.references = {};
49+
50+
Controller.prototype.variablesIn = [];
51+
52+
Controller.prototype.events = {};
53+
54+
Controller.prototype.actionsIn = $.extend({}, Default.actionsIn, {});
55+
56+
Controller.prototype.configurationStructure = function () {
57+
return {
58+
groups: {
59+
group: {
60+
options: { type: 'list' },
61+
fields: {
62+
prefs: {
63+
type: 'checkbox',
64+
title: 'Options',
65+
options: {
66+
queryFeatures: 'Enable query features',
67+
inPlace: 'Modify input variable',
68+
},
69+
},
70+
},
71+
},
72+
},
73+
};
74+
};
75+
76+
Controller.prototype.configAliases = {
77+
prefs: ['groups', 'group', 0, 'prefs', 0],
78+
};
79+
80+
Controller.prototype.onChange = function (event, reaction) {
81+
const inPlace = this.module.getConfigurationCheckbox('prefs', 'inPlace');
82+
83+
// TODO: handle reaction change
84+
};
85+
86+
return Controller;
87+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
define(['modules/default/defaultmodel'], function (Default) {
4+
function Model() {}
5+
6+
$.extend(true, Model.prototype, Default);
7+
8+
return Model;
9+
});

src/modules/types/science/chemistry/ocl_reaction_editor/style.css

Whitespace-only changes.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
3+
define(['modules/default/defaultview', 'src/util/ui', 'openchemlib'], function (
4+
Default,
5+
ui,
6+
OCL,
7+
) {
8+
function View() {}
9+
10+
$.extend(true, View.prototype, Default, {
11+
init() {
12+
this.editor = null;
13+
},
14+
15+
inDom() {
16+
this.dom = $('<div>').css({
17+
height: '99%',
18+
width: '100%',
19+
});
20+
this.module.getDomContent().html(this.dom);
21+
},
22+
23+
onResize() {
24+
this.dom.empty();
25+
this.initEditor();
26+
},
27+
28+
blank: {},
29+
30+
onActionReceive: {},
31+
32+
update: {},
33+
34+
initEditor() {
35+
const controller = this.module.controller;
36+
this.editor = new OCL.CanvasEditor(this.dom.get(0), {
37+
initialMode: 'reaction',
38+
});
39+
this.editor.setOnChangeListener((event) =>
40+
controller.onChange(event, this.editor.getReaction()),
41+
);
42+
const reaction =
43+
OCL.ReactionEncoder.decode(controller.currentReaction) ||
44+
OCL.Reaction.create();
45+
reaction.setFragment(
46+
this.module.getConfigurationCheckbox('prefs', 'queryFeatures'),
47+
);
48+
this.editor.setReaction(reaction);
49+
this.resolveReady();
50+
},
51+
52+
clearEditor() {
53+
this._currentValue = null;
54+
this._currentType = null;
55+
this.editor.getReaction().clear();
56+
this.editor.moleculeChanged();
57+
},
58+
});
59+
60+
return View;
61+
});

0 commit comments

Comments
 (0)