Skip to content

Commit 69994bf

Browse files
authored
Merge pull request #335 from ReproNim/fix/elements
Fix/elements
2 parents a483963 + 6837c90 commit 69994bf

File tree

12 files changed

+1074
-1186
lines changed

12 files changed

+1074
-1186
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,50 @@ npm test
202202
npm run lint
203203
```
204204

205+
## To test protocols and schemas locally
206+
207+
Run this cors server script in the root directory of your reproschema. For
208+
example, if you clone the demo-protocol, run the script inside the cloned
209+
directory. This script will serve the tree locally.
210+
211+
```python
212+
#!/usr/bin/env python3
213+
214+
# It's python3 -m http.server PORT for a CORS world
215+
216+
from http.server import HTTPServer, SimpleHTTPRequestHandler
217+
import sys
218+
219+
class CORSRequestHandler(SimpleHTTPRequestHandler):
220+
221+
def end_headers(self):
222+
self.send_header('Access-Control-Allow-Origin', '*')
223+
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
224+
self.send_header('Access-Control-Allow-Headers', 'Content-Type, Authorization')
225+
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
226+
return super(CORSRequestHandler, self).end_headers()
227+
228+
def do_OPTIONS(self):
229+
self.send_response(200)
230+
self.send_header('Access-Control-Allow-Origin', '*')
231+
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
232+
self.send_header('Access-Control-Allow-Headers', 'Content-Type, Authorization')
233+
self.end_headers()
234+
235+
host = sys.argv[1] if len(sys.argv) > 2 else '0.0.0.0'
236+
port = int(sys.argv[len(sys.argv)-1]) if len(sys.argv) > 1 else 8000
237+
238+
print("Listening on {}:{}".format(host, port))
239+
httpd = HTTPServer((host, port), CORSRequestHandler)
240+
httpd.serve_forever()
241+
```
242+
243+
Change config.js in this ui repo to point to your local schema. For example,
244+
if you cloned the demo protocol it would look like this:
245+
246+
```
247+
githubSrc: 'http://localhost:8000/DemoProtocol/DemoProtocol_schema',
248+
```
249+
250+
251+

package-lock.json

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

src/components/InputSelector/InputSelector.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,7 @@ export default {
343343
this.$emit('dontKnow');
344344
},
345345
sendData(val) {
346-
if (val instanceof Date) {
347-
this.$emit('valueChanged', val.getFullYear());
348-
} else this.$emit('valueChanged', val);
346+
this.$emit('valueChanged', val);
349347
this.$emit('next');
350348
},
351349
},

src/components/Inputs/MultiTextInput/MultiTextInput.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ export default {
3535
methods: {
3636
onSubmit(e) {
3737
e.preventDefault();
38-
const name = { first_name: this.input1, middle_name: this.input2, last_name: this.input3 };
38+
const name = { "schema:givenName": this.input1,
39+
"schema:additionalName": this.input2,
40+
"schema:familyName": this.input3,
41+
"@type": "schema:Person" };
3942
this.$emit('valueChanged', name);
4043
},
4144
},

src/components/Inputs/SelectInput/SelectInput.vue

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,37 @@
33
<multiselect v-if=" inputType=== 'select' && this.constraints['http://schema.org/itemListElement']"
44
v-model="selected" :options="this.options" :searchable="false"
55
:show-labels="false"
6-
placeholder="Pick a value" @input="checkNotOtherAndSendData">
6+
placeholder="Pick a value">
7+
</multiselect>
8+
<multiselect v-else-if="multipleAllowed" v-model="selected" id="ajax"
9+
placeholder="Type to search"
10+
:options="this.options" :multiple="true"
11+
:searchable="true"
12+
:internal-search="true" :clear-on-select="false"
13+
:close-on-select="true" :options-limit="300"
14+
:limit="5" :limit-text="limitText" :max-height="600"
15+
:show-no-results="false" :hide-selected="true">
716
</multiselect>
817
<multiselect v-else v-model="selected" id="ajax"
918
placeholder="Type to search"
10-
:options="this.options" :multiple="multipleAllowed"
19+
:options="this.options"
1120
:searchable="true"
1221
:internal-search="true" :clear-on-select="false"
1322
:close-on-select="true" :options-limit="300"
1423
:limit="5" :limit-text="limitText" :max-height="600"
15-
:show-no-results="false" :hide-selected="true"
16-
@input="checkNotOtherAndSendData">
24+
:show-no-results="false" :hide-selected="false">
1725
<span slot="noResult">{{ $t('select-invalid-query')}}</span>
1826
</multiselect>
1927
<div v-if="checkOther" id="ifOther" style="display: block;">
20-
<br><b-form-input v-model="otherInput" placeholder="Please describe" @change="sendData">
21-
</b-form-input>
28+
<br>
29+
<b-form-input v-model="otherInput" placeholder="Please describe">
30+
</b-form-input>
2231
</div>
32+
<br>
33+
<b-form v-if="this.selected" @submit="checkAndSendData">
34+
<b-btn type="submit">{{ $t('submit-button')}}</b-btn>
35+
</b-form>
2336
</div>
24-
2537
</template>
2638

2739
<script>
@@ -47,6 +59,7 @@ export default {
4759
options: [],
4860
selectedCountries: [],
4961
isLoading: false,
62+
valueMap: {},
5063
};
5164
},
5265
watch: {
@@ -57,14 +70,34 @@ export default {
5770
5871
},
5972
methods: {
60-
checkNotOtherAndSendData(val) {
61-
if (val !== 'Other') {
62-
this.$emit('valueChanged', val);
73+
checkAndSendData() {
74+
if (this.selected) {
75+
if (this.selected.includes('Other')) {
76+
if (!_.isEmpty(this.valueMap)) {
77+
this.valueMap["Other"] = this.otherInput;
78+
}
79+
}
80+
let out = null;
81+
if (this.multipleAllowed) {
82+
if (!_.isEmpty(this.valueMap)) {
83+
out = _.map(this.selected, v => this.valueMap[v]);
84+
} else if (this.selected.includes('Other')) {
85+
out = [...this.selected.slice(0, -1), this.otherInput];
86+
} else {
87+
out = [...this.selected]
88+
}
89+
} else {
90+
if (!_.isEmpty(this.valueMap)) {
91+
out = this.valueMap[this.selected];
92+
} else if (this.selected === 'Other') {
93+
out = this.otherInput;
94+
} else {
95+
out = this.selected;
96+
}
97+
}
98+
this.$emit('valueChanged', out);
6399
}
64100
},
65-
sendData(val) {
66-
this.$emit('valueChanged', [this.selected, val]);
67-
},
68101
limitText(count) {
69102
return `and ${count} other countries`;
70103
},
@@ -82,6 +115,9 @@ export default {
82115
const activeValueChoices = _.filter(v['http://schema.org/name'], ac => ac['@language'] === this.selected_language);
83116
return (activeValueChoices[0]['@value']);
84117
});
118+
this.options.forEach((key, index) => {
119+
this.valueMap[key] = this.constraints['http://schema.repronim.org/choices'][index]['http://schema.repronim.org/value'][0]['@value'];
120+
});
85121
} else if (this.constraints['http://schema.repronim.org/choices'].length === 1) { // choice list defined in external file
86122
axios.get(this.constraints['http://schema.repronim.org/choices'][0]['@value'])
87123
.then((resp) => {
@@ -97,12 +133,17 @@ export default {
97133
multipleAllowed() {
98134
if (this.constraints['http://schema.repronim.org/multipleChoice']) {
99135
// console.log(94, this.constraints[this.reprotermsUrl+'multipleChoice']);
100-
return true;
101-
} return false;
136+
return this.constraints['http://schema.repronim.org/multipleChoice'][0]['@value'];
137+
}
138+
return false;
102139
},
103140
checkOther() {
104-
if (this.selected === 'Other') {
105-
return true;
141+
if (this.selected) {
142+
if (this.multipleAllowed) {
143+
return this.selected.includes('Other');
144+
} else {
145+
return this.selected === 'Other';
146+
}
106147
}
107148
return false;
108149
},

src/components/Inputs/StaticReadOnly/StaticReadOnly.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="staticReadOnly">
33
<div v-if="true">
4-
<b-btn @click="onSubmit"> Done reading </b-btn>
4+
<b-btn @click="onSubmit"> Continue activity </b-btn>
55
</div>
66
<div v-else>
77
<b-alert show>

src/components/Inputs/TimeRange/TimeRange.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,7 @@ export default {
121121
},
122122
methods: {
123123
sendData() {
124-
this.$emit('valueChanged', {
125-
startTime: this.sleptAt.toISOString(),
126-
endTime: this.wokeAt.toISOString(),
127-
difference: this.timeSlept,
128-
});
124+
this.$emit('valueChanged', this.sleptAt.toISOString() + "/" + this.wokeAt.toISOString());
129125
},
130126
},
131127
watch: {

src/components/Inputs/WebFloatInput/FloatInput.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ export default {
7373
this.$refs.form.className = 'was-validated';
7474
if (this.isValidFloat) {
7575
if (this.hasUnit) { // send value + unit
76-
const name = { value: this.input1, unitCode: this.input2 };
76+
const name = {
77+
value: this.input1,
78+
unitCode: this.input2,
79+
"@type": "schema:QuantitativeValue"
80+
};
7781
this.$emit('valueChanged', name);
7882
} else this.$emit('valueChanged', this.input1);
7983
}

src/components/Inputs/WebIntegerInput/IntegerInput.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ export default {
7373
this.$refs.form.className = 'was-validated';
7474
if (this.isValidInt) {
7575
if (this.hasUnit) { // send value + unit
76-
const name = { value: this.input1, unitCode: this.input2 };
76+
const name = {
77+
value: this.input1,
78+
unitCode: this.input2,
79+
"@type": "schema:QuantitativeValue"
80+
};
7781
this.$emit('valueChanged', name);
7882
} this.$emit('valueChanged', this.input1); // else send only value
7983
}

src/components/Inputs/YearInput/YearInput.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@ export default {
2020
watch: {
2121
input() {
2222
// if there is a change, emit it.
23-
this.$emit('valueChanged', this.input);
24-
23+
this.$emit('valueChanged', this.customFormatter(this.input));
2524
// make sure you validate the date based on this.constraints.
2625
},
2726
},
2827
methods: {
29-
sendData(val) {
30-
this.$emit('valueChanged', val.getFullYear());
31-
},
3228
customFormatter(date) {
3329
if (this.inputType === 'year') {
3430
return moment(date).format('YYYY');
3531
} else if (this.inputType === 'date') {
36-
return moment(date).format('MMM DD YYYY');
32+
return moment(date).format('YYYY MMM DD');
3733
} return date;
3834
},
3935
},

0 commit comments

Comments
 (0)