Browse Source

Removed references to firebase functions in frontend

wip-firestore
Atridad Lahiji 1 year ago
parent
commit
f1bed2ada5
  1. 5
      components/dialog/AddPollDialog.vue
  2. 6
      components/dialog/AddQuestionDialog.vue
  3. 46
      components/dialog/EditPollDialog.vue
  4. 5
      components/dialog/EditQuestionDialog.vue
  5. 2
      components/dialog/FinalResultsViewDialog.vue
  6. 4
      components/dialog/StudentPollViewDialog.vue
  7. 9
      components/tables/TextResponseTable.vue
  8. 4
      components/workflow/HomeScreen.vue
  9. 24
      functions/invoker.js
  10. 4
      layouts/default.vue
  11. 4
      store/index.js

5
components/dialog/AddPollDialog.vue

@ -70,8 +70,8 @@ along with Pollo. If not, see <https://www.gnu.org/licenses/>. -->
</template>
<script>
import firebase from '@firebase/app'
import { mdiClose } from '@mdi/js'
import { invokeFunction } from '~/functions/invoker.js'
import { config } from '~/config.js'
export default {
@ -102,8 +102,7 @@ export default {
// If a poll name has been entered, trigger the creation of a poll
if (this.addPollName.length > 0) {
// Calls a cloud function that creates the poll in the realtime database
const createPoll = firebase.functions().httpsCallable('createPoll')
createPoll({
invokeFunction('createPoll', {
pollname: this.addPollName
})
this.closeAddPollDialog()

6
components/dialog/AddQuestionDialog.vue

@ -140,8 +140,8 @@ along with Pollo. If not, see <https://www.gnu.org/licenses/>. -->
</template>
<script>
import firebase from '@firebase/app'
import { mdiClose, mdiMinusCircle, mdiPlusCircle } from '@mdi/js'
import { invokeFunction } from '@/functions/invoker.js'
import { config } from '~/config.js'
export default {
@ -191,8 +191,6 @@ export default {
// Adds a question if the question name is longer than 0 characters
addQuestion () {
if (this.qname.length > 0) {
// Calls a cloud function that creates the poll in the realtime database
const createQuestion = firebase.functions().httpsCallable('createQuestion')
let qoptions = []
if (this.tab === 0) {
qoptions = this.qoptions
@ -210,7 +208,7 @@ export default {
}
]
}
createQuestion({
invokeFunction('createQuestion', {
pollid: this.pollEventObject.pollid,
qname: this.qname,
qtype: this.qtypeMap[this.tab],

46
components/dialog/EditPollDialog.vue

@ -234,6 +234,7 @@ along with Pollo. If not, see <https://www.gnu.org/licenses/>. -->
import firebase from '@firebase/app'
import { mdiClose, mdiPlay, mdiStop, mdiPlus, mdiStopCircleOutline, mdiPlayCircleOutline, mdiSquareEditOutline, mdiPollBoxOutline, mdiDeleteOutline } from '@mdi/js'
import { saveAs } from 'file-saver'
import { invokeFunction } from '~/functions/invoker.js'
import { config } from '~/config.js'
import AddQuestionDialog from '~/components/dialog/AddQuestionDialog.vue'
import EditQuestionDialog from '~/components/dialog/EditQuestionDialog.vue'
@ -295,6 +296,7 @@ export default {
}
},
computed: {
// Import mainColor from config
mainColor () {
return config.mainColor
@ -318,8 +320,6 @@ export default {
editPollDialog: function (isActivated) {
if (isActivated) {
this.editPollName = this.pollEventObject.pollobj.pollname
// Grabs the current user
firebase.auth().onAuthStateChanged((user) => {
// Define a database reference for user questions based on a specific pollid and creates a Firebase watcher
const qRef = firebase.database().ref(`/users/${user.uid}/questions`).orderByChild('pollid').equalTo(this.pollEventObject.pollid)
@ -336,28 +336,26 @@ export default {
// Saves question information in a list
this.questionKeys = tempQuestionKeys
})
// Define a database reference for sessions based on a specific pollid and creates a Firebase watcher
const sessionRef = firebase.database().ref('/sessions/').orderByChild('pollid').equalTo(this.pollEventObject.pollid)
sessionRef.on('value', (snapshot) => {
let tempActiveQuestionID = ''
snapshot.forEach((sessionSnapshot) => {
tempActiveQuestionID = sessionSnapshot.val().activeqid
})
// Sets the active question qid
this.activeQuestionID = tempActiveQuestionID
})
})
// Define a database reference for sessions based on a specific pollid and creates a Firebase watcher
const sessionRef = firebase.database().ref('/sessions/').orderByChild('pollid').equalTo(this.pollEventObject.pollid)
sessionRef.on('value', (snapshot) => {
const sessionRef1 = firebase.database().ref('/sessions/').orderByChild('pollid').equalTo(this.pollEventObject.pollid)
sessionRef1.on('value', (snapshot) => {
let tempActiveQuestionID = ''
let tempSessionKey = ''
snapshot.forEach((sessionSnapshot) => {
tempActiveQuestionID = sessionSnapshot.val().activeqid
})
snapshot.forEach((sessionSnapshot) => {
if (sessionSnapshot.key) {
tempSessionKey = sessionSnapshot.key
}
})
// Sets the active question qid
this.activeQuestionID = tempActiveQuestionID
// Sets the sessionid
this.sessionID = tempSessionKey
})
@ -369,8 +367,7 @@ export default {
deleteQuestion (payload) {
const initialQuestionCount = this.questionKeys.length
// Calls a cloud function that deletes the question in the realtime database
const deleteQuestion = firebase.functions().httpsCallable('deleteQuestion')
deleteQuestion({
invokeFunction('deleteQuestion', {
qid: payload.qid,
pollid: payload.pollid
})
@ -390,10 +387,9 @@ export default {
editPoll () {
if (this.editPollName.length > 0) {
// Calls a cloud function that creates the poll in the realtime database
const editPoll = firebase.functions().httpsCallable('editPoll')
const newPollEventObject = this.pollEventObject
newPollEventObject.pollobj.pollname = this.editPollName
editPoll({
invokeFunction('editPoll', {
pollid: newPollEventObject.pollid,
pollobj: newPollEventObject.pollobj
})
@ -403,8 +399,7 @@ export default {
// Creates a new session for the current pollid
createSession () {
const initialSessionID = this.sessionID
const createSession = firebase.functions().httpsCallable('createSession')
createSession({
invokeFunction('createSession', {
pollid: this.pollEventObject.pollid
})
@ -426,8 +421,7 @@ export default {
// Deletes the session with the current pollid
deleteSession () {
const initialSessionID = this.sessionID
const deleteSession = firebase.functions().httpsCallable('deleteSession')
deleteSession({
invokeFunction('deleteSession', {
pollid: this.pollEventObject.pollid
})
@ -449,8 +443,7 @@ export default {
// Sets the active question based on the qid
activateQuestion (qid, pollid, sessionid) {
const initialActiveQuestion = this.activeQuestionID
const setActiveQuestion = firebase.functions().httpsCallable('setActiveQuestion')
setActiveQuestion({
invokeFunction('setActiveQuestion', {
qid,
pollid,
sessionid
@ -474,8 +467,7 @@ export default {
// Removes the active question based on the qid
stopActiveQuestion (qid, pollid, sessionid) {
const initialActiveQuestion = this.activeQuestionID
const stopActiveQuestion = firebase.functions().httpsCallable('stopActiveQuestion')
stopActiveQuestion({
invokeFunction('stopActiveQuestion', {
qid,
pollid,
sessionid

5
components/dialog/EditQuestionDialog.vue

@ -183,8 +183,8 @@ along with Pollo. If not, see <https://www.gnu.org/licenses/>. -->
</template>
<script>
import firebase from '@firebase/app'
import { mdiClose, mdiMinusCircle, mdiPlusCircle } from '@mdi/js'
import { invokeFunction } from '~/functions/invoker.js'
import { config } from '~/config.js'
export default {
@ -238,7 +238,6 @@ export default {
// If the question name is longer than 0, update the question in the DB with local changes
if (this.qname.length > 0) {
// Calls a cloud function that creates the poll in the realtime database
const editQuestion = firebase.functions().httpsCallable('editQuestion')
const tempqobj = this.questionEventObject.qobj
tempqobj.qname = this.qname
tempqobj.qtype = this.qtypeMap[this.tab]
@ -263,7 +262,7 @@ export default {
delete tempqobj.responses
}
editQuestion({
invokeFunction('editQuestion', {
pollid: this.questionEventObject.pollid,
qid: this.questionEventObject.qid,
qobj: tempqobj

2
components/dialog/FinalResultsViewDialog.vue

@ -98,7 +98,7 @@ export default {
firebase.auth().onAuthStateChanged((user) => {
// Define a database reference for user questions based on a specific qid and creates a Firebase watcher
const sessionRef = firebase.database().ref(`/users/${user.uid}/questions/${this.qid}`)
sessionRef.once('value', (snapshot) => {
sessionRef.on('value', (snapshot) => {
this.qobj = {
qid: snapshot.key,
question: snapshot.val()

4
components/dialog/StudentPollViewDialog.vue

@ -60,6 +60,7 @@ along with Pollo. If not, see <https://www.gnu.org/licenses/>. -->
import firebase from '@firebase/app'
import { mdiClose } from '@mdi/js'
import Question from '~/components/session/Question.vue'
import { invokeFunction } from '~/functions/invoker.js'
import { config } from '~/config.js'
export default {
@ -119,8 +120,7 @@ export default {
methods: {
// Sends a response under the user's uid to the active question
sendResponse (event) {
const sendResponse = firebase.functions().httpsCallable('sendResponse')
sendResponse({
invokeFunction('sendResponse', {
sessionid: this.sessionid,
response: event.response
})

9
components/tables/TextResponseTable.vue

@ -43,13 +43,8 @@
export default {
props: {
responseList: {
type: Object,
default () {
return {
response: '',
count: ''
}
}
type: Array,
default: () => []
}
}
}

4
components/workflow/HomeScreen.vue

@ -145,6 +145,7 @@ import EditPollDialog from '~/components/dialog/EditPollDialog.vue'
import StudentPollViewDialog from '~/components/dialog/StudentPollViewDialog.vue'
import LiveResultsViewDialog from '~/components/dialog/LiveResultsViewDialog.vue'
import FinalResultsViewDialog from '~/components/dialog/FinalResultsViewDialog.vue'
import { invokeFunction } from '~/functions/invoker.js'
import { config } from '~/config.js'
export default {
@ -273,8 +274,7 @@ export default {
deletePoll (pollid) {
const initialPollCount = this.pollKeys.length
// Calls a cloud function that deletes the poll in the realtime database
const deletePoll = firebase.functions().httpsCallable('deletePoll')
deletePoll({
invokeFunction('deletePoll', {
pollid
})

24
functions/invoker.js

@ -0,0 +1,24 @@
/* This file is part of Pollo.
Pollo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pollo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Pollo. If not, see <https://www.gnu.org/licenses/>. */
import firebase from '@firebase/app'
const invokeFunction = function (functionName, params) {
// Calls a cloud function
const callableFunction = firebase.functions().httpsCallable(functionName)
callableFunction(params)
}
export { invokeFunction }

4
layouts/default.vue

@ -39,7 +39,7 @@ along with Pollo. If not, see <https://www.gnu.org/licenses/>. -->
</v-icon>
</v-btn>
<v-menu
v-if="IS_AUTHENTICATED"
v-if="GET_LOGGED_IN_USER"
offset-y
open-on-hover
class="mx-2"
@ -92,7 +92,7 @@ export default {
computed: {
// Importing vuex getters
...mapGetters([
'IS_AUTHENTICATED',
'GET_LOGGED_IN_USER',
'GET_USER_PHOTO_URL',
'GET_DARK_THEME'
]),

4
store/index.js

@ -36,8 +36,8 @@ export const mutations = {
}
export const getters = {
IS_AUTHENTICATED (state) {
return !!state.user
GET_LOGGED_IN_USER (state) {
return state.user
},
GET_USER_PHOTO_URL (state) {
return state.userPhoto