cedar-embeddable-editor 0.9.6 → 0.9.7

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 ADDED
@@ -0,0 +1,195 @@
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), proceed with the following steps:
10
+
11
+ ### Clone the repository
12
+
13
+ Clone this repository onto a local directory of your choice:
14
+
15
+ ```shell
16
+ git clone https://github.com/metadatacenter/cedar-embeddable-editor.git
17
+ ```
18
+
19
+ ### Edit configuration
20
+
21
+ 1. Open the file ```cedar-embeddable-editor/src/app/app.component.dev.ts``` in your favorite editor.
22
+ 2. Edit configuration parameters based on your local environment (see section [Configuration](https://github.com/metadatacenter/cedar-embeddable-editor/tree/develop#configuration) for details).
23
+
24
+ ### Build the project and start the server
25
+
26
+ 1. Navigate to the CEE directory:
27
+ ```shell
28
+ $cd <...>/<clone directory>/cedar-embeddable-editor/
29
+ ```
30
+ 1. Run these commands:
31
+ ```shell
32
+ cedar-embeddable-editor$ npm install
33
+ cedar-embeddable-editor$ ng serve
34
+ ```
35
+ 1. In your browser, navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
36
+
37
+ ## Running as a Webcomponent
38
+
39
+ 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:
40
+
41
+ ### Build and copy the Webcomponent JS file
42
+
43
+ 1. Run the build command:
44
+ ```shell
45
+ cedar-embeddable-editor$ ng build --configuration production --output-hashing=none
46
+ ```
47
+ 1. Combine the generated files into a single file and copy the final JS to the sample application:
48
+ ```shell
49
+ cedar-embeddable-editor$ cat dist/cedar-embeddable-editor/{runtime,polyfills,main}.js > "/dev/cedar/cedar-cee-demo-generic/assets/js/cedar-embeddable-editor.js"
50
+ ```
51
+
52
+ ## Configuration
53
+
54
+ ### Configuration file
55
+
56
+ The CEE configuration file format and storage location depends on the application and the mode in which CEE is being used.
57
+
58
+ * 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`.
59
+ * 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:
60
+ ```javascript
61
+ document.addEventListener('WebComponentsReady', function () {
62
+ const cee = document.querySelector('cedar-embeddable-editor');
63
+ cee.loadConfigFromURL('assets/data/cee-config.json');
64
+ });
65
+ ```
66
+ * When using the Angular 2 sample application (https://github.com/metadatacenter/cedar-cee-demo-angular), the configuration is stored in the file: `assets/data/appConfig.json`.
67
+
68
+
69
+ ### Required configuration parameters
70
+
71
+ * **sampleTemplateLocationPrefix:** The base URL that contains the sample CEDAR templates
72
+ * **terminologyIntegratedSearchUrl:** The URL of the CEDAR integrated search endpoint that communicates with BioPortal
73
+
74
+ ```json
75
+ {
76
+ "sampleTemplateLocationPrefix": "https://component.metadatacenter.orgx/cedar-embeddable-editor-sample-templates/",
77
+ "terminologyIntegratedSearchUrl": "https://terminology.metadatacenter.org/bioportal/integrated-search"
78
+ }
79
+ ```
80
+
81
+ ### Optional configuration parameters
82
+
83
+ 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.
84
+
85
+ ```json
86
+ {
87
+ "showSampleTemplateLinks": true,
88
+ "loadSampleTemplateName": "19",
89
+ "expandedSampleTemplateLinks": false,
90
+ "showTemplateRenderingRepresentation": true,
91
+ "expandedTemplateRenderingRepresentation": false,
92
+ "showInstanceDataCore": true,
93
+ "expandedInstanceDataCore": true,
94
+ "showInstanceDataFull": false,
95
+ "expandedInstanceDataFull": false,
96
+ "showMultiInstanceInfo": false,
97
+ "expandedMultiInstanceInfo": false,
98
+ "showTemplateSourceData": true,
99
+ "expandedTemplateSourceData": false,
100
+ "showHeader": true,
101
+ "showFooter": true,
102
+ "collapseStaticComponents": true
103
+ }
104
+ ```
105
+
106
+ ## Metadata API
107
+
108
+ CEE Webcomponent includes APIs for exporting metadata externally and importing metadata into CEE.
109
+
110
+ ### Metadata Export
111
+
112
+ The metadata currently being edited inside CEE can be exported at anytime by making this API call:
113
+
114
+ ```javascript
115
+ const meta = cee.currentMetadata;
116
+ ```
117
+
118
+ In the example below, the metadata is sent to an external endpoint every 15 seconds:
119
+
120
+ ```javascript
121
+ document.addEventListener('WebComponentsReady', function () {
122
+ const cee = document.querySelector('cedar-embeddable-editor');
123
+ cee.loadConfigFromURL('assets/data/cee-config.json');
124
+ const saveTime = 15000; // 15 seconds
125
+
126
+ setInterval(() => {
127
+ const meta = cee.currentMetadata;
128
+
129
+ const xhr = new XMLHttpRequest();
130
+ xhr.open("POST", "http://localhost:8001/metadatasave.php");
131
+ xhr.setRequestHeader("Accept", "application/json");
132
+ xhr.setRequestHeader("Content-Type", "application/json");
133
+ xhr.send(JSON.stringify(meta, null, 2));
134
+ console.log('Saved metadata after ' + saveTime / 1000 + ' seconds');
135
+ }, saveTime);
136
+ });
137
+ ```
138
+
139
+ ### Metadata Import
140
+
141
+ You can import your metadata into CEE Webcomponent, provided it matches the template currently being edited. To import your metadata, execute this API call:
142
+
143
+ ```javascript
144
+ cee.metadata = yourCustomMetadataJson
145
+ ```
146
+
147
+ In the example below, the metadata is fetched from a remote URL and imported into CEE:
148
+
149
+ ```javascript
150
+ function restoreMetadataFromURL(metaUrl, cee, successHandler = null, errorHandler = null) {
151
+ const xhr = new XMLHttpRequest();
152
+ xhr.onreadystatechange = () => {
153
+ if (xhr.readyState === XMLHttpRequest.DONE) {
154
+ if (xhr.status === 200) {
155
+ const jsonMeta = JSON.parse(xhr.responseText);
156
+ cee.metadata = jsonMeta;
157
+
158
+ if (successHandler) {
159
+ successHandler(jsonMeta);
160
+ }
161
+ } else {
162
+ if (errorHandler) {
163
+ errorHandler(xhr);
164
+ }
165
+ }
166
+ }
167
+ };
168
+ xhr.open('GET', metaUrl, true);
169
+ xhr.send();
170
+ }
171
+
172
+ document.addEventListener('WebComponentsReady', function () {
173
+ const cee = document.querySelector('cedar-embeddable-editor');
174
+ cee.loadConfigFromURL('assets/data/cee-config.json');
175
+ restoreMetadataFromURL('uploads/metadata-for-restore.json', cee);
176
+ });
177
+ ```
178
+
179
+ To reiterate, the metadata being imported **MUST** match the template currently being edited and open in your browser window.
180
+
181
+ ## Example Applications
182
+
183
+ There are two sample applications you can use to demonstrate how to embed and use CEE. 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.
184
+
185
+ ### CEE Demo Generic
186
+
187
+ This demo uses a generic HTML page with the CEE Webcomponent embedded in it. It runs standalone, with no dependency on any web framework.
188
+
189
+ https://github.com/metadatacenter/cedar-cee-demo-generic
190
+
191
+ ### CEE Demo Angular
192
+
193
+ This demo is written in Angular 2 and requires that framework to run properly.
194
+
195
+ https://github.com/metadatacenter/cedar-cee-demo-angular