Skip to content

Commit

Permalink
Merge pull request #335 from ReproNim/fix/elements
Browse files Browse the repository at this point in the history
Fix/elements
  • Loading branch information
satra authored Aug 9, 2024
2 parents a483963 + 6837c90 commit 69994bf
Show file tree
Hide file tree
Showing 12 changed files with 1,074 additions and 1,186 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,50 @@ npm test
npm run lint
```

## To test protocols and schemas locally

Run this cors server script in the root directory of your reproschema. For
example, if you clone the demo-protocol, run the script inside the cloned
directory. This script will serve the tree locally.

```python
#!/usr/bin/env python3

# It's python3 -m http.server PORT for a CORS world

from http.server import HTTPServer, SimpleHTTPRequestHandler
import sys

class CORSRequestHandler(SimpleHTTPRequestHandler):

def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
self.send_header('Access-Control-Allow-Headers', 'Content-Type, Authorization')
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
return super(CORSRequestHandler, self).end_headers()

def do_OPTIONS(self):
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
self.send_header('Access-Control-Allow-Headers', 'Content-Type, Authorization')
self.end_headers()

host = sys.argv[1] if len(sys.argv) > 2 else '0.0.0.0'
port = int(sys.argv[len(sys.argv)-1]) if len(sys.argv) > 1 else 8000

print("Listening on {}:{}".format(host, port))
httpd = HTTPServer((host, port), CORSRequestHandler)
httpd.serve_forever()
```

Change config.js in this ui repo to point to your local schema. For example,
if you cloned the demo protocol it would look like this:

```
githubSrc: 'http://localhost:8000/DemoProtocol/DemoProtocol_schema',
```



2,091 changes: 949 additions & 1,142 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/components/InputSelector/InputSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ export default {
this.$emit('dontKnow');
},
sendData(val) {
if (val instanceof Date) {
this.$emit('valueChanged', val.getFullYear());
} else this.$emit('valueChanged', val);
this.$emit('valueChanged', val);
this.$emit('next');
},
},
Expand Down
5 changes: 4 additions & 1 deletion src/components/Inputs/MultiTextInput/MultiTextInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export default {
methods: {
onSubmit(e) {
e.preventDefault();
const name = { first_name: this.input1, middle_name: this.input2, last_name: this.input3 };
const name = { "schema:givenName": this.input1,
"schema:additionalName": this.input2,
"schema:familyName": this.input3,
"@type": "schema:Person" };
this.$emit('valueChanged', name);
},
},
Expand Down
75 changes: 58 additions & 17 deletions src/components/Inputs/SelectInput/SelectInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,37 @@
<multiselect v-if=" inputType=== 'select' && this.constraints['http://schema.org/itemListElement']"
v-model="selected" :options="this.options" :searchable="false"
:show-labels="false"
placeholder="Pick a value" @input="checkNotOtherAndSendData">
placeholder="Pick a value">
</multiselect>
<multiselect v-else-if="multipleAllowed" v-model="selected" id="ajax"
placeholder="Type to search"
:options="this.options" :multiple="true"
:searchable="true"
:internal-search="true" :clear-on-select="false"
:close-on-select="true" :options-limit="300"
:limit="5" :limit-text="limitText" :max-height="600"
:show-no-results="false" :hide-selected="true">
</multiselect>
<multiselect v-else v-model="selected" id="ajax"
placeholder="Type to search"
:options="this.options" :multiple="multipleAllowed"
:options="this.options"
:searchable="true"
:internal-search="true" :clear-on-select="false"
:close-on-select="true" :options-limit="300"
:limit="5" :limit-text="limitText" :max-height="600"
:show-no-results="false" :hide-selected="true"
@input="checkNotOtherAndSendData">
:show-no-results="false" :hide-selected="false">
<span slot="noResult">{{ $t('select-invalid-query')}}</span>
</multiselect>
<div v-if="checkOther" id="ifOther" style="display: block;">
<br><b-form-input v-model="otherInput" placeholder="Please describe" @change="sendData">
</b-form-input>
<br>
<b-form-input v-model="otherInput" placeholder="Please describe">
</b-form-input>
</div>
<br>
<b-form v-if="this.selected" @submit="checkAndSendData">
<b-btn type="submit">{{ $t('submit-button')}}</b-btn>
</b-form>
</div>

</template>

<script>
Expand All @@ -47,6 +59,7 @@ export default {
options: [],
selectedCountries: [],
isLoading: false,
valueMap: {},
};
},
watch: {
Expand All @@ -57,14 +70,34 @@ export default {
},
methods: {
checkNotOtherAndSendData(val) {
if (val !== 'Other') {
this.$emit('valueChanged', val);
checkAndSendData() {
if (this.selected) {
if (this.selected.includes('Other')) {
if (!_.isEmpty(this.valueMap)) {
this.valueMap["Other"] = this.otherInput;
}
}
let out = null;
if (this.multipleAllowed) {
if (!_.isEmpty(this.valueMap)) {
out = _.map(this.selected, v => this.valueMap[v]);
} else if (this.selected.includes('Other')) {
out = [...this.selected.slice(0, -1), this.otherInput];
} else {
out = [...this.selected]
}
} else {
if (!_.isEmpty(this.valueMap)) {
out = this.valueMap[this.selected];
} else if (this.selected === 'Other') {
out = this.otherInput;
} else {
out = this.selected;
}
}
this.$emit('valueChanged', out);
}
},
sendData(val) {
this.$emit('valueChanged', [this.selected, val]);
},
limitText(count) {
return `and ${count} other countries`;
},
Expand All @@ -82,6 +115,9 @@ export default {
const activeValueChoices = _.filter(v['http://schema.org/name'], ac => ac['@language'] === this.selected_language);
return (activeValueChoices[0]['@value']);
});
this.options.forEach((key, index) => {
this.valueMap[key] = this.constraints['http://schema.repronim.org/choices'][index]['http://schema.repronim.org/value'][0]['@value'];
});
} else if (this.constraints['http://schema.repronim.org/choices'].length === 1) { // choice list defined in external file
axios.get(this.constraints['http://schema.repronim.org/choices'][0]['@value'])
.then((resp) => {
Expand All @@ -97,12 +133,17 @@ export default {
multipleAllowed() {
if (this.constraints['http://schema.repronim.org/multipleChoice']) {
// console.log(94, this.constraints[this.reprotermsUrl+'multipleChoice']);
return true;
} return false;
return this.constraints['http://schema.repronim.org/multipleChoice'][0]['@value'];
}
return false;
},
checkOther() {
if (this.selected === 'Other') {
return true;
if (this.selected) {
if (this.multipleAllowed) {
return this.selected.includes('Other');
} else {
return this.selected === 'Other';
}
}
return false;
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Inputs/StaticReadOnly/StaticReadOnly.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="staticReadOnly">
<div v-if="true">
<b-btn @click="onSubmit"> Done reading </b-btn>
<b-btn @click="onSubmit"> Continue activity </b-btn>
</div>
<div v-else>
<b-alert show>
Expand Down
6 changes: 1 addition & 5 deletions src/components/Inputs/TimeRange/TimeRange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ export default {
},
methods: {
sendData() {
this.$emit('valueChanged', {
startTime: this.sleptAt.toISOString(),
endTime: this.wokeAt.toISOString(),
difference: this.timeSlept,
});
this.$emit('valueChanged', this.sleptAt.toISOString() + "/" + this.wokeAt.toISOString());
},
},
watch: {
Expand Down
6 changes: 5 additions & 1 deletion src/components/Inputs/WebFloatInput/FloatInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export default {
this.$refs.form.className = 'was-validated';
if (this.isValidFloat) {
if (this.hasUnit) { // send value + unit
const name = { value: this.input1, unitCode: this.input2 };
const name = {
value: this.input1,
unitCode: this.input2,
"@type": "schema:QuantitativeValue"
};
this.$emit('valueChanged', name);
} else this.$emit('valueChanged', this.input1);
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/Inputs/WebIntegerInput/IntegerInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export default {
this.$refs.form.className = 'was-validated';
if (this.isValidInt) {
if (this.hasUnit) { // send value + unit
const name = { value: this.input1, unitCode: this.input2 };
const name = {
value: this.input1,
unitCode: this.input2,
"@type": "schema:QuantitativeValue"
};
this.$emit('valueChanged', name);
} this.$emit('valueChanged', this.input1); // else send only value
}
Expand Down
8 changes: 2 additions & 6 deletions src/components/Inputs/YearInput/YearInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@ export default {
watch: {
input() {
// if there is a change, emit it.
this.$emit('valueChanged', this.input);
this.$emit('valueChanged', this.customFormatter(this.input));
// make sure you validate the date based on this.constraints.
},
},
methods: {
sendData(val) {
this.$emit('valueChanged', val.getFullYear());
},
customFormatter(date) {
if (this.inputType === 'year') {
return moment(date).format('YYYY');
} else if (this.inputType === 'date') {
return moment(date).format('MMM DD YYYY');
return moment(date).format('YYYY MMM DD');
} return date;
},
},
Expand Down
8 changes: 0 additions & 8 deletions src/components/Survey/Survey.vue
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,6 @@
let exportVal = val;
let usedList = [];
let isAboutUrl = itemUrl;
// eslint-disable-next-line no-prototype-builtins
if (_.isObject(val) && !val.hasOwnProperty('unitCode') && !(val instanceof Blob)) { // to find sub-activities; condition might need to be changed
const sectionItemKey = Object.keys(val)[0];
const sectionItemValue = Object.values(val)[0];
exportVal = sectionItemValue;
usedList.push(sectionItemKey);
isAboutUrl = sectionItemKey;
}
usedList.push(`${itemUrl}`, `${this.srcUrl}`);
const d2 = new Date();
const t1 = d2.toISOString();
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
githubSrc: 'https://raw.githubusercontent.com/ReproNim/demo-protocol/master/DemoProtocol/DemoProtocol_schema',
githubSrc: 'https://raw.githubusercontent.com/ReproNim/demo-protocol/main/DemoProtocol/DemoProtocol_schema',
startButton: {
"en": 'Join',
"es": 'Participar'
Expand Down

0 comments on commit 69994bf

Please sign in to comment.