Skip to content

Commit

Permalink
Merge pull request #41 from haystack/develop
Browse files Browse the repository at this point in the history
add audio support for comment
  • Loading branch information
JumanaFM authored Mar 3, 2022
2 parents 579809a + f4560bc commit 5fb42d9
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 58 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
"@fortawesome/free-regular-svg-icons": "^5.8.1",
"@fortawesome/free-solid-svg-icons": "^5.8.1",
"@fortawesome/vue-fontawesome": "^0.1.6",
"@sentry/tracing": "^6.2.5",
"@sentry/vue": "^6.2.5",
"axios": ">=0.21.1",
"bootstrap-vue": "^2.21.2",
"express": "^4.17.0",
Expand All @@ -52,6 +50,7 @@
"vue": "^2.6.10",
"vue-avatar-component": "^1.3.1",
"vue-cli": "^2.9.6",
"vue-dictaphone": "^2.0.0",
"vue-draggable-resizable": "^2.3.0",
"vue-jwt-decode": "^0.1.0",
"vue-notification": "^1.3.20",
Expand Down
19 changes: 15 additions & 4 deletions public/style/plugin.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
right: 0;
}


#nb-app input[type=checkbox] {
position: relative;
}

#nb-app .logo {
color: #4a2270;
text-decoration: none;
Expand Down Expand Up @@ -192,7 +197,7 @@
display: none;
}
#nb-app-wrapper .nav-overflow-wrapper .overflow-options {
border-radius: 4px;
border-radius: 0;
border: solid 1px #aaa;
}
#nb-app-wrapper .nav-overflow-wrapper .overflow-option {
Expand Down Expand Up @@ -606,7 +611,7 @@
font-size: 12px;
}
#nb-app .nb-sidebar .thread-view .thread-row .header .timestamp {
font-size: 13px;
font-size: 10px;
color: #444;
cursor: default;
}
Expand Down Expand Up @@ -667,7 +672,7 @@
display: none;
}
#nb-app-wrapper .thread-overflow-wrapper .overflow-options {
border-radius: 4px;
border-radius: 0;
border: solid 1px #aaa;
}
#nb-app-wrapper .thread-overflow-wrapper .overflow-option {
Expand Down Expand Up @@ -1315,4 +1320,10 @@ nb-innotation-controller {

.nb-innotation-block-time {
font-size: 0.7em;
}
}

#nb-app audio {
height: 25px;
background: #f0f3f4;
border: 1px #d5d8d8 solid;
}
28 changes: 10 additions & 18 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ import axios from 'axios'
import VueJwtDecode from "vue-jwt-decode";
import io from "socket.io-client";
import { Environments } from './environments'
// import * as Sentry from "@sentry/vue";
// import { Integrations } from "@sentry/tracing";

//prodcution log
// Sentry.init({
// Vue,
// dsn: "https://[email protected]/5722075",
// integrations: [new Integrations.BrowserTracing()],

// // Set tracesSampleRate to 1.0 to capture 100%
// // of transactions for performance monitoring.
// // We recommend adjusting this value in production
// tracesSampleRate: 1.0,
// });

const currentEnv = Environments.dev

Expand All @@ -51,6 +37,7 @@ library.add(fas, far, faChevronDown, faChevronUp)
const socket = io(currentEnv.baseURL, { reconnect: true })
axios.defaults.baseURL = `${currentEnv.baseURL}/`
export const PLUGIN_HOST_URL = currentEnv.pluginURL
export const BASE_HOST_URL = currentEnv.baseURL
axios.defaults.withCredentials = true

if ((document.attachEvent && document.readyState === 'complete') || (!document.attachEvent && document.readyState !== 'loading')) {
Expand Down Expand Up @@ -333,6 +320,7 @@ function embedNbApp() {
filterMaxThreadsConfig: null,
isShowSpotlightControls: false,
syncNotificationPopupTimerConfig: 60000,
isCommentMediaAudio: false,
},
syncConfig: false,
isDragging: false, // indicates if there's a dragging happening in the UI
Expand Down Expand Up @@ -501,7 +489,6 @@ function embedNbApp() {
return false
})

console.log(myHiddenItems);
sortedItems = sortedItems.slice(0, maxThreads)
sortedItems = sortedItems.concat(myHiddenItems)
}
Expand Down Expand Up @@ -576,6 +563,7 @@ function embedNbApp() {
this.currentConfigs.filterMaxThreadsConfig = configs['CONFIG_FILTER_MAX_THREADS'] ? configs['CONFIG_FILTER_MAX_THREADS'] : null
this.currentConfigs.isShowSpotlightControls = configs['SHOW_SPOTLIGHT_CONTROLS'] === 'false' ? false : true
this.currentConfigs.syncNotificationPopupTimerConfig = configs['CONFIG_SYNC_NOTIFICATION_POPUP_TIMER'] ? configs['CONFIG_SYNC_NOTIFICATION_POPUP_TIMER'] : 60000
this.currentConfigs.isCommentMediaAudio = configs['COMMENT_MEDIA_AUDIO_STUDENT'] === 'true' ? true : false

if (document.location.href.includes('/nb_viewer.html')) {
this.currentConfigs.isMarginalia = configs['SPOTLIGHT_MARGIN'] === 'true' ? true : false
Expand Down Expand Up @@ -614,6 +602,10 @@ function embedNbApp() {
this.users = res.data
this.$set(this.user, 'role', this.users[this.user.id].role)

if (this.user.role === 'instructor') {
this.currentConfigs.isCommentMediaAudio = configs['COMMENT_MEDIA_AUDIO_INSTRUCTOR'] === 'true' ? true : false
}

axios.get('/api/annotations/myCurrentSection', config).then(res => {
socket.emit('left', { id: this.user.id, username: this.user.username, classId: oldActiveClass.id, sectionId: this.currentSectionId, sourceURL: this.sourceURL, role: this.user.role })
this.currentSectionId = res.data
Expand Down Expand Up @@ -780,8 +772,8 @@ function embedNbApp() {
// if this thread is open in the thread view, then refresh it
if (this.threadSelected && this.threadSelected.id === oldHeadAnnotationId) {
//this.threadSelected = comment
console.log(this.threadSelected);
console.log(comment);
// console.log(this.threadSelected);
// console.log(comment);
// this.threadSelected.children = comment.children
}

Expand Down Expand Up @@ -880,7 +872,7 @@ function embedNbApp() {
const token = localStorage.getItem("nb.user");
const config = { headers: { Authorization: 'Bearer ' + token }, params: { url: source, class: newActiveClass.id, sectioned: !this.currentConfigs.isIgnoreSectionsInClass } }

axios.get('/api/annotations/new_annotation', config).then(async res => {
axios.get('/api/annotations/annotation', config).then(async res => {
this.threads = []

for (const item of res.data.headAnnotations) {
Expand Down
7 changes: 5 additions & 2 deletions src/components/NbSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
:users="sortedUsers"
:hashtags="sortedHashtags"
:is-submitting="editor.isSubmitting"
:current-configs="currentConfigs"
@editor-empty="onEditorEmpty"
@submit-comment="onSubmitComment"
@cancel-comment="onCancelComment"
Expand Down Expand Up @@ -447,6 +448,7 @@ export default {
this.editor.isSubmitting = true
let comment = new NbComment({
id: null, // will be updated when submitAnnotation() is called
type: data.type,
range: this.draftRange, // null if this is reply
parent: this.replyToComment, // null if this is the head of thread
timestamp: null,
Expand All @@ -462,14 +464,15 @@ export default {
replyRequestCount: data.replyRequested ? 1 : 0,
upvotedByMe: false,
upvoteCount: 0,
seenByMe: true
seenByMe: true,
mediaBlob: data.mediaBlob,
})
let source = this.sourceUrl.length > 0 ? this.sourceUrl : window.location.href.split('?')[0]
try {
await comment.submitAnnotation(this.activeClass.id, source, this.threadViewInitiator, this.replyToComment, this.activeClass, this.user, this.onLogNb)
Vue.notify({ group: 'annotation', title: 'Comment submitted successfully', type: 'success', })
Vue.notify({ group: 'annotation', title: 'Comment submitted successfully', type: 'success', })
this.editor.visible = false
if (this.edittingComment) {
Expand Down
106 changes: 106 additions & 0 deletions src/components/editor/AudioEditor.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<template>
<div class="nb-audio-editor">
<template v-if="showError">
<span>Your browser doesn’t support audio recording or you’ve blocked microphone access.</span>
</template>

<template v-else>
<vue-dictaphone @stop="handleRecording($event)" @error="handleError" mime-type="audio/mp3" v-slot="{ isRecording, startRecording, stopRecording, deleteRecording }">
<button v-if="!isRecording" @click="startRecording"><font-awesome-icon icon="circle" class="ae-icon"></font-awesome-icon></button>
<button v-if="isRecording" @click="stopRecording"><font-awesome-icon icon="stop" class="ae-icon"></font-awesome-icon></button>
<vue-dictaphone-spectrum-analyser v-if="isRecording"/>
</vue-dictaphone>
<template v-if="isRecorded">
<audio :src="audioSource" controls></audio>
</template>
<button v-if="false &&!isRecording && isRecorded" @click="handleDeleteRecording"><font-awesome-icon icon="trash" class="ae-icon"></font-awesome-icon></button>
</template>

</div>
</template>

<script>
import Vue from 'vue'
import VueDictaphone from "vue-dictaphone";
Vue.use(VueDictaphone);
export default {
name: 'audio-editor',
props: {
},
data () {
return {
isRecorded: false,
audioSource: null,
mediaBlob: null,
showError: false,
}
},
methods: {
handleRecording({ blob, src }) {
this.isRecorded = true
this.audioSource = src;
this.mediaBlob = blob
this.$emit("audio-stop", blob)
},
handleDeleteRecording() {
if (window.confirm("Are you sure?")) {
// this.audioSource = null
// this.mediaBlob = null
this.isRecorded = false
console.log('delete now')
}
},
handleError() {
this.showError = true;
},
}
}
</script>

<style>
.nb-audio-editor {
background: #f9f5f5;
height: 75px;
margin: 15px 0;
display: flex;
align-content: center;
justify-content: flex-start;
align-items: center;
border: 1px solid #d5d5d5;
}
.nb-audio-editor div {
display: flex;
align-items: center;
align-content: center;
}
.nb-audio-editor div canvas {
width: calc(100% - 50px);
}
.nb-audio-editor button {
line-height: initial;
height: 40px;
width: 40px;
display: flex;
justify-content: center;
align-items: center;
background: #efefef;
border: 1px solid #969696;
border-radius: 0;
margin: 10px;
}
.nb-audio-editor audio {
margin: 0 10px;
width: 100%;
}
.nb-audio-editor .ae-icon {
}
</style>
Loading

0 comments on commit 5fb42d9

Please sign in to comment.