cedar-embeddable-editor 0.9.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -0
- package/cedar-embeddable-editor.js +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# Cedar Embeddable Editor (CEE)
|
|
2
|
+
|
|
3
|
+
The CEDAR Embeddable Editor is as a web component that implements the functionality of the CEDAR Metadata Editor.
|
|
4
|
+
|
|
5
|
+
It takes CEDAR JSON Schema templates as input, and produces CEDAR JSON-LD metadata.
|
|
6
|
+
|
|
7
|
+
## Running as a standalone application
|
|
8
|
+
|
|
9
|
+
You can run CEE as a standalone application. This is helpful for developers to see changes to the code reflected immediately in the application. To run CEE in the standalone mode (NOT as a Webcomponent), you will need the editor itself and the sample templates that the editor uses. These are stored in a [separate repo](https://github.com/metadatacenter/cedar-component-distribution).
|
|
10
|
+
|
|
11
|
+
Proceed with the following steps:
|
|
12
|
+
|
|
13
|
+
### Clone the repository
|
|
14
|
+
|
|
15
|
+
Clone this repository onto a local directory of your choice:
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
git clone https://github.com/metadatacenter/cedar-embeddable-editor.git
|
|
19
|
+
git clone https://github.com/metadatacenter/cedar-component-distribution.git
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Edit configuration
|
|
23
|
+
|
|
24
|
+
1. Open the file ```cedar-embeddable-editor/src/app/app.component.dev.ts``` in your favorite editor.
|
|
25
|
+
2. Edit configuration parameters based on your local environment (see section [Configuration](https://github.com/metadatacenter/cedar-embeddable-editor/tree/develop#configuration) for details).
|
|
26
|
+
|
|
27
|
+
### Build the project and start the server
|
|
28
|
+
|
|
29
|
+
1. Navigate to the CEE directory:
|
|
30
|
+
```shell
|
|
31
|
+
$ cd <...>/<clone directory>/cedar-embeddable-editor/
|
|
32
|
+
```
|
|
33
|
+
1. Run these commands:
|
|
34
|
+
```shell
|
|
35
|
+
cedar-embeddable-editor$ npm install
|
|
36
|
+
cedar-embeddable-editor$ ng serve
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
1. In a different shell navigate to the component distribution directory:
|
|
40
|
+
```shell
|
|
41
|
+
$ cd <...>/<clone directory>/cedar-component-distribution/
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
1. Run these commands:
|
|
45
|
+
```shell
|
|
46
|
+
cedar-embeddable-editor$ npm install
|
|
47
|
+
cedar-embeddable-editor$ ng serve
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
1. In your browser, navigate to `http://localhost:4400/`. The app will automatically reload if you change any of the source files.
|
|
51
|
+
|
|
52
|
+
## Running as a Webcomponent
|
|
53
|
+
|
|
54
|
+
This method creates a single Javascript (JS) file that encapsulates all the functionality of CEE. The JS file can be embedded in any application or HTML page. To build a CEE Webcomponent, proceed with these steps:
|
|
55
|
+
|
|
56
|
+
### Build and copy the Webcomponent JS file
|
|
57
|
+
|
|
58
|
+
1. Run the build command:
|
|
59
|
+
```shell
|
|
60
|
+
cedar-embeddable-editor$ ng build --configuration=production
|
|
61
|
+
```
|
|
62
|
+
1. Combine the generated files into a single file and copy the final JS to the sample application:
|
|
63
|
+
```shell
|
|
64
|
+
cedar-embeddable-editor$ cat dist/cedar-embeddable-editor/{runtime,polyfills,main}.js > cedar-embeddable-editor.js
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Running as an `npm` package
|
|
68
|
+
|
|
69
|
+
Please import the latest version of the editor into your project from: [https://www.npmjs.com/package/cedar-embeddable-editor](https://www.npmjs.com/package/cedar-embeddable-editor)
|
|
70
|
+
|
|
71
|
+
## Configuration
|
|
72
|
+
|
|
73
|
+
### Configuration file
|
|
74
|
+
|
|
75
|
+
The CEE configuration file format and storage location depends on the application and the mode in which CEE is being used.
|
|
76
|
+
|
|
77
|
+
* When running CEE in the standalone mode (developer mode), the configuration parameters are stored in and read from the file: `src/app/app.component.dev.ts`.
|
|
78
|
+
* When running CEE as a generic Webcomponent, the configuration parameters can be stored in any `.json` file that is visible to the application that embeds CEE Webcomponent. CEE Webcomponent API provides a method for loading the configuration file from its path at runtime. For example:
|
|
79
|
+
```javascript
|
|
80
|
+
document.addEventListener('WebComponentsReady', function () {
|
|
81
|
+
const cee = document.querySelector('cedar-embeddable-editor');
|
|
82
|
+
cee.loadConfigFromURL('assets/data/cee-config.json');
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
* The configuration can also be passed into the editor as a json map. In Angular this looks as follows:
|
|
86
|
+
```html
|
|
87
|
+
<cedar-embeddable-editor
|
|
88
|
+
[config]="conf"
|
|
89
|
+
[templateObject]="template"
|
|
90
|
+
[instanceObject]="instance"
|
|
91
|
+
></cedar-embeddable-editor>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Required configuration parameters
|
|
96
|
+
|
|
97
|
+
* **showSampleTemplateLinks:** Wether the sample links are shown or not.
|
|
98
|
+
* For production this should be false, the template should be injected into the component by the embedding application
|
|
99
|
+
* **terminologyIntegratedSearchUrl:** The URL of the CEDAR integrated search endpoint that communicates with BioPortal.
|
|
100
|
+
* The value `https://terminology.metadatacenter.org/bioportal/integrated-search` should work for the majority of applications.
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"showSampleTemplateLinks": false,
|
|
105
|
+
"terminologyIntegratedSearchUrl": 'https://terminology.metadatacenter.org/bioportal/integrated-search',
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Optional configuration parameters
|
|
110
|
+
|
|
111
|
+
There are other optional configuration parameters available for controlling various aspects of the CEE user interface. Most of these are self-explanatory. The example below includes the default values in cases, where the parameter isn't explicitly declared.
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"sampleTemplateLocationPrefix": "http://localhost:4240/cedar-embeddable-editor-sample-templates/",
|
|
116
|
+
"loadSampleTemplateName": "01",
|
|
117
|
+
"expandedSampleTemplateLinks": true,
|
|
118
|
+
|
|
119
|
+
"showTemplateRenderingRepresentation": true,
|
|
120
|
+
"showInstanceDataCore": true,
|
|
121
|
+
"expandedInstanceDataCore": false,
|
|
122
|
+
"showMultiInstanceInfo": true,
|
|
123
|
+
"expandedMultiInstanceInfo": false,
|
|
124
|
+
|
|
125
|
+
"expandedTemplateRenderingRepresentation": false,
|
|
126
|
+
"showInstanceDataFull": false,
|
|
127
|
+
"expandedInstanceDataFull": false,
|
|
128
|
+
"showTemplateSourceData": true,
|
|
129
|
+
"expandedTemplateSourceData": false,
|
|
130
|
+
|
|
131
|
+
"showHeader": true,
|
|
132
|
+
"showFooter": true,
|
|
133
|
+
|
|
134
|
+
"defaultLanguage": "en",
|
|
135
|
+
"fallbackLanguage": "en",
|
|
136
|
+
|
|
137
|
+
"collapseStaticComponents": false,
|
|
138
|
+
"showStaticText": true
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Metadata API
|
|
143
|
+
|
|
144
|
+
CEE Webcomponent includes APIs for exporting metadata externally and importing metadata into CEE.
|
|
145
|
+
|
|
146
|
+
### Metadata Export
|
|
147
|
+
|
|
148
|
+
The metadata currently being edited inside CEE can be exported at anytime by making this API call:
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
const meta = cee.currentMetadata;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
In the example below, the metadata is sent to an external endpoint every 15 seconds:
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
document.addEventListener('WebComponentsReady', function () {
|
|
158
|
+
const cee = document.querySelector('cedar-embeddable-editor');
|
|
159
|
+
cee.loadConfigFromURL('assets/data/cee-config.json');
|
|
160
|
+
const saveTime = 15000; // 15 seconds
|
|
161
|
+
|
|
162
|
+
setInterval(() => {
|
|
163
|
+
const meta = cee.currentMetadata;
|
|
164
|
+
|
|
165
|
+
const xhr = new XMLHttpRequest();
|
|
166
|
+
xhr.open("POST", "http://localhost:8001/metadatasave.php");
|
|
167
|
+
xhr.setRequestHeader("Accept", "application/json");
|
|
168
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
169
|
+
xhr.send(JSON.stringify(meta, null, 2));
|
|
170
|
+
console.log('Saved metadata after ' + saveTime / 1000 + ' seconds');
|
|
171
|
+
}, saveTime);
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Template Injection
|
|
176
|
+
|
|
177
|
+
You can inject your template into CEE:
|
|
178
|
+
|
|
179
|
+
```javascript
|
|
180
|
+
cee.templateObject = yourCustomTemplateJson;
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Metadata Injection
|
|
184
|
+
|
|
185
|
+
You can inject your metadata into CEE, provided it matches the template currently being edited:
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
cee.instanceObject = yourCustomMetadataJson
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
In the example below, the metadata is fetched from a remote URL and injected into CEE:
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
function restoreMetadataFromURL(metaUrl, cee, successHandler = null, errorHandler = null) {
|
|
195
|
+
const xhr = new XMLHttpRequest();
|
|
196
|
+
xhr.onreadystatechange = () => {
|
|
197
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
198
|
+
if (xhr.status === 200) {
|
|
199
|
+
const jsonMeta = JSON.parse(xhr.responseText);
|
|
200
|
+
cee.instanceObject = jsonMeta;
|
|
201
|
+
|
|
202
|
+
if (successHandler) {
|
|
203
|
+
successHandler(jsonMeta);
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
if (errorHandler) {
|
|
207
|
+
errorHandler(xhr);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
xhr.open('GET', metaUrl, true);
|
|
213
|
+
xhr.send();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
document.addEventListener('WebComponentsReady', function () {
|
|
217
|
+
const cee = document.querySelector('cedar-embeddable-editor');
|
|
218
|
+
cee.loadConfigFromURL('assets/data/cee-config.json');
|
|
219
|
+
restoreMetadataFromURL('uploads/metadata-for-restore.json', cee);
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
To reiterate, the metadata being injected **MUST** match the template currently being edited and open in your browser window.
|
|
224
|
+
|
|
225
|
+
## Example Applications
|
|
226
|
+
|
|
227
|
+
There is a sample applications you can use to demonstrate how to embed and use CEE.
|
|
228
|
+
Follow the links below to the demo application of your choice. The documentation for each demo application can be found in the README file of the corresponding application.
|
|
229
|
+
|
|
230
|
+
### CEE Demo Angular
|
|
231
|
+
|
|
232
|
+
This demo is written in Angular 2 and requires that framework to run properly.
|
|
233
|
+
|
|
234
|
+
https://github.com/metadatacenter/cedar-cee-demo/tree/main/cedar-cee-demo-angular-src
|