-
Notifications
You must be signed in to change notification settings - Fork 20
Refactor audio/video components #366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
b69da21
c03c21d
2f29ed1
366344b
7c61f2e
51f59aa
c783a79
09b0705
3b1b380
18430ee
79135cd
d7a33e4
ce341eb
b36ccd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -518,11 +518,16 @@ export default { | |
| _.map(eachActivityList, (itemObj) => { | ||
| const newObj = { ...itemObj }; | ||
| if (itemObj['@type'] === 'reproschema:Response') { | ||
| if (itemObj.value instanceof Blob) { | ||
| if (itemObj.value instanceof Blob && itemObj.mimeType == "audio/wav") { | ||
| const keyStrings = (itemObj.isAbout.split('/')); | ||
| const rId = itemObj['@id'].split('uuid:')[1]; | ||
| jszip.folder(fileName).file(`${keyStrings[keyStrings.length-1]}-${rId}.wav`, itemObj.value); | ||
| newObj.value = `${keyStrings[keyStrings.length-1]}-${rId}.wav`; | ||
| jszip.folder(fileName).file(`${keyStrings[keyStrings.length-1]}-${rId}.wav`, itemObj.value); //changed from wav | ||
| newObj.value = `${keyStrings[keyStrings.length-1]}-${rId}.wav`; //changed from wav | ||
| } else if (itemObj.value instanceof Blob && itemObj.mimeType == "video/mp4") { | ||
| const keyStrings = (itemObj.isAbout.split('/')); | ||
| const rId = itemObj['@id'].split('uuid:')[1]; | ||
| jszip.folder(fileName).file(`${keyStrings[keyStrings.length-1]}-${rId}.mp4`, itemObj.value); //changed from wav | ||
| newObj.value = `${keyStrings[keyStrings.length-1]}-${rId}.mp4`; //changed from wav | ||
| } | ||
| } | ||
| activityData.push(newObj); | ||
|
|
@@ -552,81 +557,6 @@ export default { | |
| }); | ||
| }, | ||
| }, | ||
| watch: { | ||
| $route() { | ||
| if (this.$route.params.id !== undefined) { | ||
| this.$store.dispatch('setActivityIndex', this.$route.params.id); | ||
| } | ||
| }, | ||
| visibilityConditions: { | ||
| handler(newC) { | ||
| if (!_.isEmpty(newC)) { | ||
| this.setVisbility(); | ||
| } | ||
| }, | ||
| deep: true, | ||
| }, | ||
| }, | ||
| created() { | ||
| const url = this.$route.query.url; | ||
| if (url) { | ||
| this.protocolUrl = url; | ||
| } | ||
| this.$store.dispatch('getBaseSchema', url).then(() => this.getPrefLabel()); | ||
| // this.$store.dispatch('getBaseSchema', url); | ||
| }, | ||
| mounted() { | ||
| new EmailDecoder('[data-email]'); | ||
| this.clientSpecs = JSON.stringify(Bowser.parse(window.navigator.userAgent)); | ||
| this.browserType = Bowser.parse(window.navigator.userAgent).browser.name; | ||
| if (config.checkMediaPermission) { | ||
| this.checkPermission(); | ||
| } | ||
| if (this.$route.query.lang) { | ||
| this.selected_language = this.$route.query.lang; | ||
| i18n.locale = this.selected_language; | ||
| } else this.selected_language = 'en'; | ||
|
|
||
| if (this.$route.query.uid) { | ||
| // console.log(407, this.$route.query.uid); | ||
| this.$store.dispatch('saveParticipantId', this.$route.query.uid); | ||
| } else if (config.generateRandomUid) { | ||
| this.$store.dispatch('saveParticipantId', uuidv4()); | ||
| } | ||
| if (this.$route.params.id) { | ||
| this.$store.dispatch('setActivityIndex', this.$route.params.id); | ||
| } | ||
| axios.get('https://raw.githubusercontent.com/ReproNim/reproschema-library/master/resources/languages.json').then((resp) => { | ||
| this.langMap = resp.data; | ||
| }); | ||
| this.$store.dispatch('setParticipantUUID', uuidv4()); // set participant UUID for the current user | ||
| if (this.$route.query.expiry_time) { | ||
| this.$store.dispatch('setExpiryMinutes', this.$route.query.expiry_time); | ||
| } | ||
| if (this.$route.query.auth_token) { | ||
| this.$store.dispatch('setAuthToken', this.$route.query.auth_token); | ||
| } | ||
| if (!_.isEmpty(this.$route.query)) { | ||
| this.$store.dispatch('setQueryParameters', this.$route.query); | ||
| } | ||
|
|
||
| // const formData = new FormData(); | ||
| // const TOKEN = this.$store.getters.getAuthToken; | ||
| // if (TOKEN) { | ||
| // formData.append('file', null); | ||
| // formData.append('auth_token', `${TOKEN}`); | ||
| // axios.post(`${config.backendServer}/submit`, formData, { | ||
| // 'Content-Type': 'multipart/form-data', | ||
| // }).then((res) => { | ||
| // // console.log('SUCCESS!!', res.status); | ||
| // }) | ||
| // .catch((e) => { | ||
| // if (e.response.status === 403) { | ||
| // this.invalidToken = true; | ||
| // } | ||
| // }); | ||
| // } | ||
| }, | ||
| computed: { | ||
| accessDeniedPath() { | ||
| let path = require('./assets/403-Access-Forbidden-HTML-Template.gif'); | ||
|
|
@@ -704,6 +634,7 @@ export default { | |
| if (!_.isEmpty(this.$store.state.schema)) { | ||
| const order = _.map(this.$store.state.schema['http://schema.repronim.org/order'][0]['@list'], | ||
| u => u['@id']); | ||
| console.log(order) | ||
|
||
| return order; | ||
| } | ||
| return []; | ||
|
|
@@ -817,6 +748,81 @@ export default { | |
| return this.$store.getters.getParticipantId; | ||
| }, | ||
| }, | ||
| mounted() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The component options ( |
||
| new EmailDecoder('[data-email]'); | ||
| this.clientSpecs = JSON.stringify(Bowser.parse(window.navigator.userAgent)); | ||
| this.browserType = Bowser.parse(window.navigator.userAgent).browser.name; | ||
| if (config.checkMediaPermission) { | ||
| this.checkPermission(); | ||
| } | ||
| if (this.$route.query.lang) { | ||
| this.selected_language = this.$route.query.lang; | ||
| i18n.locale = this.selected_language; | ||
| } else this.selected_language = 'en'; | ||
|
|
||
| if (this.$route.query.uid) { | ||
| // console.log(407, this.$route.query.uid); | ||
| this.$store.dispatch('saveParticipantId', this.$route.query.uid); | ||
| } else if (config.generateRandomUid) { | ||
| this.$store.dispatch('saveParticipantId', uuidv4()); | ||
| } | ||
| if (this.$route.params.id) { | ||
| this.$store.dispatch('setActivityIndex', this.$route.params.id); | ||
| } | ||
| axios.get('https://raw.githubusercontent.com/ReproNim/reproschema-library/master/resources/languages.json').then((resp) => { | ||
| this.langMap = resp.data; | ||
| }); | ||
| this.$store.dispatch('setParticipantUUID', uuidv4()); // set participant UUID for the current user | ||
| if (this.$route.query.expiry_time) { | ||
| this.$store.dispatch('setExpiryMinutes', this.$route.query.expiry_time); | ||
| } | ||
| if (this.$route.query.auth_token) { | ||
| this.$store.dispatch('setAuthToken', this.$route.query.auth_token); | ||
| } | ||
| if (!_.isEmpty(this.$route.query)) { | ||
| this.$store.dispatch('setQueryParameters', this.$route.query); | ||
| } | ||
|
|
||
| // const formData = new FormData(); | ||
| // const TOKEN = this.$store.getters.getAuthToken; | ||
| // if (TOKEN) { | ||
| // formData.append('file', null); | ||
| // formData.append('auth_token', `${TOKEN}`); | ||
| // axios.post(`${config.backendServer}/submit`, formData, { | ||
| // 'Content-Type': 'multipart/form-data', | ||
| // }).then((res) => { | ||
| // // console.log('SUCCESS!!', res.status); | ||
| // }) | ||
| // .catch((e) => { | ||
| // if (e.response.status === 403) { | ||
| // this.invalidToken = true; | ||
| // } | ||
| // }); | ||
| // } | ||
| }, | ||
| watch: { | ||
| $route() { | ||
| if (this.$route.params.id !== undefined) { | ||
| this.$store.dispatch('setActivityIndex', this.$route.params.id); | ||
| } | ||
| }, | ||
| visibilityConditions: { | ||
| handler(newC) { | ||
| if (!_.isEmpty(newC)) { | ||
| this.setVisbility(); | ||
| } | ||
| }, | ||
| deep: true, | ||
| }, | ||
| }, | ||
| created() { | ||
| const url = this.$route.query.url; | ||
| if (url) { | ||
| this.protocolUrl = url; | ||
| } | ||
| this.$store.dispatch('getBaseSchema', url).then(() => this.getPrefLabel()); | ||
| // this.$store.dispatch('getBaseSchema', url); | ||
| } | ||
| }; | ||
| </script> | ||
|
|
||
|
|
@@ -943,5 +949,3 @@ export default { | |
|
|
||
|
|
||
| </style> | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,66 +23,59 @@ | |
| </div> | ||
|
|
||
| <div v-else-if="inputType === 'audioCheck'"> | ||
| <AudioRecord | ||
| <MediaRecord | ||
| :constraints="valueConstraints" | ||
| :selected_language="selected_language" | ||
| :init="init" v-on:valueChanged="sendData"/> | ||
| </div> | ||
|
|
||
| <!-- If type is audioRecord --> | ||
| <div v-else-if="inputType === 'audioRecord'"> | ||
| <AudioRecord | ||
| :constraints="valueConstraints" | ||
| :selected_language="selected_language" | ||
| :init="init" v-on:valueChanged="sendData"/> | ||
| </div> | ||
|
|
||
| <div v-else-if="inputType === 'audioPassageRecord'"> | ||
| <AudioRecord | ||
| :constraints="valueConstraints" | ||
| :selected_language="selected_language" | ||
| :init="init" v-on:valueChanged="sendData"/> | ||
| :init="init" | ||
| :audio="true" | ||
| :visualizer="true" | ||
| v-on:valueChanged="sendData"/> | ||
| </div> | ||
|
||
|
|
||
| <!-- If type is audioImageRecord --> | ||
| <div v-else-if="inputType === 'audioImageRecord'"> | ||
| <AudioRecord | ||
| <div v-else-if="inputType === 'videoCheck'"> | ||
| <MediaRecord | ||
| :constraints="valueConstraints" | ||
| :fieldData="fieldData" | ||
| :selected_language="selected_language" | ||
| :init="init" v-on:valueChanged="sendData" | ||
| mode="audioImageRecord" /> | ||
| :init="init" | ||
| :audio="false" | ||
| :visualizer="false" | ||
| v-on:valueChanged="sendData"/> | ||
| </div> | ||
|
|
||
| <!-- If type is audioRecordNumberTask --> | ||
| <div v-else-if="inputType === 'audioRecordNumberTask'"> | ||
| <AudioRecord | ||
| <div v-else-if="inputType === 'audioVideoCheck'"> | ||
| <MediaRecord | ||
| :constraints="valueConstraints" | ||
| :selected_language="selected_language" | ||
| :init="init" v-on:valueChanged="sendData" | ||
| mode="audioRecordNumberTask" /> | ||
| :init="init" | ||
| :audio="true" | ||
| :visualizer="true" | ||
| v-on:valueChanged="sendData"/> | ||
| </div> | ||
|
|
||
| <!-- If type is audioRecordAudioTask --> | ||
| <div v-else-if="inputType === 'audioRecordAudioTask'"> | ||
| <AudioRecord | ||
| <div v-else-if="inputType.startsWith('audio')"> | ||
| <MediaRecord | ||
| :constraints="valueConstraints" | ||
| :selected_language="selected_language" | ||
| :init="init" v-on:valueChanged="sendData" | ||
| :init="init" | ||
| :audio="true" | ||
| :visualizer="true" | ||
| :mode="inputType" | ||
| :fieldData="fieldData" | ||
| mode="audioRecordAudioTask" /> | ||
| v-on:valueChanged="sendData"/> | ||
| </div> | ||
|
|
||
| <!-- If type is audioRecordNoStop --> | ||
| <div v-else-if="inputType === 'audioRecordNoStop'"> | ||
| <AudioRecord | ||
| <div v-else-if="inputType.startsWith('video')"> | ||
| <MediaRecord | ||
| :constraints="valueConstraints" | ||
| :selected_language="selected_language" | ||
| :init="init" v-on:valueChanged="sendData" | ||
| mode="audioRecordNoStop" /> | ||
| :init="init" | ||
| :audio="false" | ||
| :visualizer="false" | ||
| :mode="inputType" | ||
| :fieldData="fieldData" | ||
| v-on:valueChanged="sendData"/> | ||
| </div> | ||
|
|
||
|
|
||
| <!-- If type is text --> | ||
| <div v-else-if="inputType === 'text'"> | ||
| <TextInput | ||
|
|
@@ -153,7 +146,7 @@ | |
| :constraints="valueConstraints" | ||
| :selected_language="selected_language" | ||
| :init="init" v-on:valueChanged="sendData"/> | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- If type is date --> | ||
| <div v-else-if="inputType === 'date' || inputType === 'year'"> | ||
|
|
@@ -248,20 +241,19 @@ | |
|
|
||
| <script> | ||
| import Radio from '../Inputs/WebRadio/'; | ||
| import AudioRecord from '../Inputs/WebAudioRecord/'; | ||
| import MediaRecord from '../Inputs/MediaRecord/'; | ||
| import TextInput from '../Inputs/WebTextInput/'; | ||
| import TextArea from '../Inputs/TextArea/'; | ||
| import IntegerInput from '../Inputs/WebIntegerInput/'; | ||
| import FloatInput from '../Inputs/WebFloatInput/'; | ||
| import RangeInput from '../Inputs/RangeInput/'; | ||
| import DateInput from '../Inputs/YearInput/'; | ||
| import DocumentUpload from '../Inputs/DocumentUpload'; | ||
| import MultiTextInput from '../Inputs/MultiTextInput'; | ||
| import SliderInput from '../Inputs/SliderInput'; | ||
| import TimeRange from '../Inputs/TimeRange'; | ||
| import SelectInput from '../Inputs/SelectInput'; | ||
| // import AudioCheck from '../Inputs/AudioCheck'; | ||
| import StaticReadOnly from '../Inputs/StaticReadOnly'; | ||
| import DocumentUpload from '../Inputs/DocumentUpload/'; | ||
| import MultiTextInput from '../Inputs/MultiTextInput/'; | ||
| import SliderInput from '../Inputs/SliderInput/'; | ||
| import TimeRange from '../Inputs/TimeRange/'; | ||
| import SelectInput from '../Inputs/SelectInput/'; | ||
| import StaticReadOnly from '../Inputs/StaticReadOnly/'; | ||
| import SaveData from '../Inputs/SaveData/SaveData'; | ||
| import StudySign from '../StudySign/StudySign'; | ||
| // import Static from '../Inputs/Static'; | ||
|
|
@@ -314,7 +306,7 @@ export default { | |
| StudySign, | ||
| SaveData, | ||
| Radio, | ||
| AudioRecord, | ||
| MediaRecord, | ||
| TextInput, | ||
| TextArea, | ||
| EmailInput, | ||
|
|
@@ -372,3 +364,4 @@ export default { | |
| } | ||
|
|
||
| </style> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for handling
audio/wavandvideo/mp4blobs is duplicated. This can be refactored to be more DRY by extracting the common parts. Also, it's a good practice to use===for strict equality checks.