|
1 | 1 | import OCL from 'openchemlib'; |
| 2 | +import API from 'src/util/api'; |
| 3 | +import Twig from 'src/util/twig'; |
| 4 | +import UI from 'src/util/ui'; |
2 | 5 |
|
3 | | -// returns GHS information based on pubchem and a smiles |
| 6 | +/** |
| 7 | + * @typedef {object} GhsOptions |
| 8 | + * @property {boolean} [detailed=false] - Show full GHS data instead of summary |
| 9 | + */ |
4 | 10 |
|
5 | | -define(['src/util/ui', 'src/util/api'], (UI, API) => { |
6 | | - async function fromIDCode(oclCode, options) { |
7 | | - const molecule = OCL.Molecule.fromIDCode(oclCode); |
8 | | - const smiles = molecule.toSmiles(); |
9 | | - return fromSMILES(smiles, options); |
10 | | - } |
| 11 | +/** |
| 12 | + * @param {string} oclCode |
| 13 | + * @param {GhsOptions} [options] |
| 14 | + */ |
| 15 | +async function fromIDCode(oclCode, options) { |
| 16 | + const molecule = OCL.Molecule.fromIDCode(oclCode); |
| 17 | + const smiles = molecule.toSmiles(); |
| 18 | + return fromSMILES(smiles, options); |
| 19 | +} |
11 | 20 |
|
12 | | - async function fromSMILES(smiles, options = {}) { |
13 | | - const { detailed = false } = options; |
| 21 | +/** |
| 22 | + * @param {string} smiles |
| 23 | + * @param {GhsOptions} [options] |
| 24 | + */ |
| 25 | +async function fromSMILES(smiles, options = {}) { |
| 26 | + const { detailed = false } = options; |
14 | 27 |
|
15 | | - const { Compound } = await API.require( |
16 | | - 'https://www.lactame.com/lib/pubchem/0.2.0/pubchem.js', |
17 | | - ); |
18 | | - const compound = await Compound.fromSmiles(String(smiles)); |
19 | | - const compoundData = await compound.getData(); |
| 28 | + const { Compound } = await API.require( |
| 29 | + 'https://www.lactame.com/lib/pubchem/0.2.0/pubchem.js', |
| 30 | + ); |
| 31 | + const compound = await Compound.fromSmiles(String(smiles)); |
| 32 | + const compoundData = await compound.getData(); |
20 | 33 |
|
21 | | - const ghs = compoundData.ghs; |
22 | | - const ghsFull = compoundData.getGHS(); |
| 34 | + const ghs = compoundData.ghs; |
| 35 | + const ghsFull = compoundData.getGHS(); |
23 | 36 |
|
24 | | - const html = detailed |
25 | | - ? await UI.renderTwig(ghsFullTemplate, { ghsFull }) |
26 | | - : await UI.renderTwig(ghsTemplate, { ghs }); |
| 37 | + const html = detailed |
| 38 | + ? await Twig.renderTwig(ghsFullTemplate, { ghsFull }) |
| 39 | + : await Twig.renderTwig(ghsTemplate, { ghs }); |
27 | 40 |
|
28 | | - UI.dialog(html, { |
29 | | - width: 1000, |
30 | | - height: 800, |
31 | | - title: 'GHS information', |
32 | | - }); |
33 | | - } |
| 41 | + UI.dialog(html, { |
| 42 | + width: 1000, |
| 43 | + height: 800, |
| 44 | + title: 'GHS information', |
| 45 | + }); |
| 46 | +} |
34 | 47 |
|
35 | | - return { fromIDCode, fromSMILES }; |
36 | | -}); |
| 48 | +export default { fromIDCode, fromSMILES }; |
37 | 49 |
|
38 | 50 | const ghsTemplate = ` |
39 | 51 | <style> |
40 | 52 | #ghsSmmary { |
41 | | - |
| 53 | +
|
42 | 54 | } |
43 | 55 | #ghsSummary table { |
44 | 56 | border-collapse: collapse; |
@@ -110,7 +122,7 @@ const ghsTemplate = ` |
110 | 122 | const ghsFullTemplate = ` |
111 | 123 | <style> |
112 | 124 | #ghsFull { |
113 | | - |
| 125 | +
|
114 | 126 | } |
115 | 127 | #ghsFull table { |
116 | 128 | border-collapse: collapse; |
|
0 commit comments