Browse Source

Revert "Misc performance improvements"

This reverts commit ea82bc8514.
dev
Atridad Lahiji 11 months ago
parent
commit
cdc8b841c5
  1. 2
      .gitignore
  2. BIN
      assets/logo.png
  3. BIN
      assets/logo.webp
  4. 23
      backend/db.js
  5. 12
      backend/login.js
  6. 47
      components/session/FinalResults.vue
  7. 47
      components/session/LiveResults.vue
  8. 4
      components/workflow/LoginForm.vue
  9. 2
      config.js
  10. 9
      firebase.json
  11. 2
      layouts/default.vue
  12. 41
      nuxt.config.js
  13. 15434
      package-lock.json
  14. 12
      package.json
  15. 37
      plugins/fireauth.js
  16. 35
      plugins/firebase/firebase.js
  17. 14
      plugins/firebase/firebase_local_config.js.sample
  18. 17
      store/index.js
  19. 12035
      yarn.lock

2
.gitignore

@ -90,7 +90,7 @@ sw.*
*.swp
# Firebase
firebase_config.js
firebase_local_config.js
test/__snapshots__/Logo.spec.js.snap
test/unit/__snapshots__/HomeScreen.spec.js.snap
tests_output/

BIN
assets/logo.png

After

Width: 3000  |  Height: 3000  |  Size: 435 KiB

BIN
assets/logo.webp

23
backend/db.js

@ -12,10 +12,11 @@ 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 fetchQuestions = function (context) {
// Define a database reference for user questions based on a specific pollid and creates a Firebase watcher
const qRef = context.$fireDb.ref(`/users/${context.GET_LOGGED_IN_USER.uid}/questions`).orderByChild('pollid').equalTo(context.pollEventObject.pollid)
const qRef = firebase.database().ref(`/users/${context.GET_LOGGED_IN_USER.uid}/questions`).orderByChild('pollid').equalTo(context.pollEventObject.pollid)
qRef.on('value', (snapshot) => {
const tempQuestionKeys = []
snapshot.forEach((questionSnapshot) => {
@ -33,7 +34,7 @@ const fetchQuestions = function (context) {
const fetchSessions = function (context) {
// Define a database reference for sessions based on a specific pollid and creates a Firebase watcher
const sessionRef = context.$fireDb.ref('/sessions/').orderByChild('pollid').equalTo(context.pollEventObject.pollid)
const sessionRef = firebase.database().ref('/sessions/').orderByChild('pollid').equalTo(context.pollEventObject.pollid)
sessionRef.on('value', (snapshot) => {
let tempActiveQuestionID = ''
let tempSessionKey = ''
@ -57,7 +58,7 @@ const fetchSessions = function (context) {
const fetchPolls = function (context) {
// Define database reference for user polls
const pollRef = context.$fireDb.ref(`/users/${context.GET_LOGGED_IN_USER.uid}/polls`)
const pollRef = firebase.database().ref(`/users/${context.GET_LOGGED_IN_USER.uid}/polls`)
// Create Firebase watcher for user polls
pollRef.on('value', (snapshot) => {
const tempPollKeys = []
@ -79,13 +80,13 @@ const fetchPolls = function (context) {
const fetchPollSessions = function (context) {
// Getting session IDs for all polls if they exist
// Define database reference for sessions
const sessionUserRef = context.$fireDb.ref(`/sessions/`).orderByChild('owneruid').equalTo(context.GET_LOGGED_IN_USER.uid)
const sessionUserRef = firebase.database().ref(`/sessions/`).orderByChild('owneruid').equalTo(context.GET_LOGGED_IN_USER.uid)
// Create Firebase watcher for sessions
sessionUserRef.on('value', (sessionUserSnapshot) => {
// If the sessions list on the DB changed at all, loop through Polls
context.pollKeys.forEach((poll, index, pollKeys) => {
// Define database reference for sessions with a given pollid
const sessionRef = context.$fireDb.ref('/sessions/').orderByChild('pollid').equalTo(poll.pollid)
const sessionRef = firebase.database().ref('/sessions/').orderByChild('pollid').equalTo(poll.pollid)
// Get the session(s) with the pollid provided
sessionRef.on('value', (snapshot) => {
let tempSessionKey = ''
@ -105,7 +106,7 @@ const fetchFinalResults = function (context, isActivated) {
// Check if the dialog has been activated
if (isActivated) {
// Define a database reference for user questions based on a specific qid and creates a Firebase watcher
const sessionRef = context.$fireDb.ref(`/users/${context.GET_LOGGED_IN_USER.uid}/questions/${context.qid}`)
const sessionRef = firebase.database().ref(`/users/${context.GET_LOGGED_IN_USER.uid}/questions/${context.qid}`)
sessionRef.on('value', (snapshot) => {
context.qobj = {
qid: snapshot.key,
@ -114,7 +115,7 @@ const fetchFinalResults = function (context, isActivated) {
})
} else {
// If the dialog is deactivated, destroy the watcher
const sessionRef = context.$fireDb.ref(`/users/${context.GET_LOGGED_IN_USER.uid}/questions/${context.qid}`)
const sessionRef = firebase.database().ref(`/users/${context.GET_LOGGED_IN_USER.uid}/questions/${context.qid}`)
sessionRef.off('value')
}
}
@ -123,7 +124,7 @@ const fetchLiveResults = function (context, isActivated) {
// Check if the dialog has been activated
if (isActivated) {
// Define a database reference for sessions based on a specific sessionid and creates a Firebase watcher
const sessionRef = context.$fireDb.ref(`/sessions/${context.sessionid}`)
const sessionRef = firebase.database().ref(`/sessions/${context.sessionid}`)
sessionRef.on('value', (snapshot) => {
try {
context.activeQuestion = {
@ -139,14 +140,14 @@ const fetchLiveResults = function (context, isActivated) {
}
})
} else {
const sessionRef = context.$fireDb.ref(`/sessions/${context.sessionid}`)
const sessionRef = firebase.database().ref(`/sessions/${context.sessionid}`)
sessionRef.off('value')
}
}
const fetchActiveQuestion = function (context) {
// Define a database reference for sessions based on a specific sessionid and creates a Firebase watcher
const sessionRef = context.$fireDb.ref(`/sessions/${context.sessionid}`)
const sessionRef = firebase.database().ref(`/sessions/${context.sessionid}`)
sessionRef.on('value', (snapshot) => {
try {
context.activeQuestion = {
@ -166,7 +167,7 @@ const fetchActiveQuestion = function (context) {
const checkSessionExists = function (context) {
if (context.pollCode.length > 0) {
// Defines a database reference to a specific session based on a given session ID (poll code)
const sessionRef = context.$fireDb.ref(`/sessions/${context.pollCode.toUpperCase()}`)
const sessionRef = firebase.database().ref(`/sessions/${context.pollCode.toUpperCase()}`)
// Gets the session associated with the provided session ID
sessionRef.once('value', function (snapshot) {
if (snapshot.hasChildren()) {

12
backend/login.js

@ -15,14 +15,14 @@ along with Pollo. If not, see <https://www.gnu.org/licenses/>. */
import firebase from '@firebase/app'
// Trigger a Firebase login event with the Google identity provider
const login = function (context) {
const login = function () {
const provider = new firebase.auth.GoogleAuthProvider()
context.$fireAuth.signInWithRedirect(provider)
firebase.auth().signInWithRedirect(provider)
}
// Define a watcher for the result of the login redirect
const loginRedirectWatcher = function (context) {
context.$fireAuth.getRedirectResult()
const loginRedirectWatcher = function () {
firebase.auth().getRedirectResult()
.then(
(result) => {
const apiconfig = require('../functions/apiconfig.js')
@ -38,8 +38,8 @@ const loginRedirectWatcher = function (context) {
})
}
const logout = function (context) {
context.$fireAuth.signOut()
const logout = function () {
firebase.auth().signOut()
.then(() => {
// Reloads the page to ensure that the UI gets the updated state
window.location.reload()

47
components/session/FinalResults.vue

@ -140,6 +140,53 @@ export default {
}, [])
return reducedList
},
// This dynamically formats the data for the chartjs plot
chartData () {
return {
labels: this.optionsList,
datasets: [
{
label: this.qobj.question.qname,
backgroundColor: this.graphColor,
data: this.responseCountList
}
]
}
},
// This dynamically formats the style options for the chartjs plot
chartOptions () {
return {
responsive: true,
maintainAspectRatio: false,
legend: {
position: 'top',
labels: {
fontColor: ((this.GET_DARK_THEME) ? '#ffffff' : '#000000')
}
},
scales: {
xAxes: [{
gridLines: {
color: 'rgba(0, 0, 0, 0)',
zeroLineColor: ((this.GET_DARK_THEME) ? '#ffffff' : '#000000')
},
ticks: {
fontColor: ((this.GET_DARK_THEME) ? '#ffffff' : '#000000')
}
}],
yAxes: [{
gridLines: {
color: 'rgba(0, 0, 0, 0)',
zeroLineColor: ((this.GET_DARK_THEME) ? '#ffffff' : '#000000')
},
ticks: {
fontColor: ((this.GET_DARK_THEME) ? '#ffffff' : '#000000'),
beginAtZero: true
}
}]
}
}
}
},
methods: {

47
components/session/LiveResults.vue

@ -134,6 +134,53 @@ export default {
}, [])
return reducedList
},
// This dynamically formats the data for the chartjs plot
chartData () {
return {
labels: this.optionsList,
datasets: [
{
label: this.activeQuestion.activequestion.qname,
backgroundColor: this.graphColor,
data: this.responseCountList
}
]
}
},
// This dynamically formats the style options for the chartjs plot
chartOptions () {
return {
responsive: true,
maintainAspectRatio: false,
legend: {
position: 'top',
labels: {
fontColor: ((this.GET_DARK_THEME) ? '#ffffff' : '#000000')
}
},
scales: {
xAxes: [{
gridLines: {
color: 'rgba(0, 0, 0, 0)',
zeroLineColor: ((this.GET_DARK_THEME) ? '#ffffff' : '#000000')
},
ticks: {
fontColor: ((this.GET_DARK_THEME) ? '#ffffff' : '#000000')
}
}],
yAxes: [{
gridLines: {
color: 'rgba(0, 0, 0, 0)',
zeroLineColor: ((this.GET_DARK_THEME) ? '#ffffff' : '#000000')
},
ticks: {
fontColor: ((this.GET_DARK_THEME) ? '#ffffff' : '#000000'),
beginAtZero: true
}
}]
}
}
}
}
}

4
components/workflow/LoginForm.vue

@ -60,11 +60,11 @@ export default {
}
},
mounted () {
loginRedirectWatcher(this)
loginRedirectWatcher()
},
methods: {
login () {
login(this)
login()
}
}
}

2
config.js

@ -1,6 +1,6 @@
/* eslint-disable*/
const config = {
logoName: 'logo.webp',
logoName: 'logo.png',
mainColor: '#f79d02',
startColor: '#228B22',
stopColor: '#dd2c00',

9
firebase.json

@ -5,14 +5,7 @@
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"headers": [ {
"source": "**/*.@(jpg|jpeg|gif|png)",
"headers": [ {
"key": "Cache-Control",
"value": "max-age=7200"
} ]
} ]
]
},
"functions": {
"predeploy": [

2
layouts/default.vue

@ -111,7 +111,7 @@ export default {
methods: {
// Triggers a Firebase logout event
logout () {
logout(this)
logout()
},
// Toggles the vuex state for the current theme
toggleDarkTheme () {

41
nuxt.config.js

@ -1,5 +1,3 @@
import { prod_config, development_config } from './firebase_config'
export default {
mode: 'spa',
/*
@ -29,6 +27,8 @@ export default {
** Plugins to load before mounting the App
*/
plugins: [
{ src: '~/plugins/firebase/firebase', ssr: false },
{ src: '~/plugins/fireauth', ssr: false },
{ src: '~/plugins/vue-graph.js', ssr: false },
'@plugins/vuetify'
],
@ -45,8 +45,7 @@ export default {
modules: [
// Doc: https://axios.nuxtjs.org/usage
'@nuxtjs/axios',
'@nuxtjs/pwa',
'@nuxtjs/firebase'
'@nuxtjs/pwa'
],
/*
** Axios module configuration
@ -75,45 +74,11 @@ export default {
commons: true,
runtime: true,
layouts: false
},
babel: {
presets({ isServer }) {
return [
[
require.resolve('@nuxt/babel-preset-app'),
// require.resolve('@nuxt/babel-preset-app-edge'), // For nuxt-edge users
{
buildTarget: isServer ? 'server' : 'client',
corejs: { version: 3 }
}
]
]
}
}
},
router: {
middleware: [
'router-auth'
]
},
firebase: {
config: {
production: prod_config,
development: development_config
},
onFirebaseHosting: true,
services: {
auth: {
persistence: 'local',
initialize: {
onAuthStateChangedMutation: "SET_LOGGED_IN_USER"
}
},
functions: {
location: 'us-central1', // Default
emulatorPort: 12345
},
realtimeDb: true
}
}
}

15434
package-lock.json
File diff suppressed because it is too large
View File

12
package.json

@ -14,30 +14,30 @@
"test-e2e": "nightwatch ./test/e2e"
},
"dependencies": {
"@firebase/app": "^0.6.0",
"@firebase/auth": "^0.14.1",
"@firebase/database": "^0.5.24",
"@firebase/functions": "^0.4.38",
"@mdi/font": "^5.0.45",
"@mdi/js": "^5.0.45",
"@nuxtjs/axios": "^5.3.6",
"@nuxtjs/firebase": "^5.2.0",
"@nuxtjs/pwa": "^3.0.0-0",
"chart.js": "^2.9.3",
"file-saver": "^2.0.2",
"firebase": "^7.14.5",
"json2csv": "^4.5.4",
"nuxt": "^2.12.2",
"vue-chartjs": "^3.5.0",
"nuxt": "^2.12.1",
"vue-graph": "^0.8.7",
"vuetify": "^2.2.15",
"vuex-persistedstate": "^2.7.1"
},
"devDependencies": {
"@babel/runtime-corejs3": "^7.9.6",
"@babel/runtime-corejs3": "^7.9.2",
"@nuxtjs/eslint-config": "^1.1.2",
"@nuxtjs/eslint-module": "^1.0.0",
"@vue/test-utils": "^1.0.0-beta.27",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.9.0",
"chromedriver": "^80.0.1",
"core-js": "3",
"eslint": "^6.1.0",
"eslint-plugin-nuxt": ">=0.4.2",
"jest": "^24.9.0",

37
plugins/fireauth.js

@ -0,0 +1,37 @@
/* 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 apiconfig = require('../functions/apiconfig.js')
export default (context) => {
const { store } = context
return new Promise((resolve, reject) => {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
if (apiconfig.domain !== '' && !user.email.includes(apiconfig.domain)) {
store.commit('SET_LOGGED_IN_USER', null)
} else {
store.commit('SET_LOGGED_IN_USER', user)
}
return resolve(store.commit('SET_USER_PHOTO_URL', user.photoURL))
} else {
store.commit('SET_LOGGED_IN_USER', null)
}
return resolve()
})
})
}

35
plugins/firebase/firebase.js

@ -0,0 +1,35 @@
/* 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'
import '@firebase/auth'
import '@firebase/database'
import '@firebase/functions'
import { fb } from './firebase_local_config'
fetch('/__/firebase/init.json').then((response) => {
if (response.ok) {
return response.json()
} else {
throw new Error('404')
}
}).then((responseJson) => {
firebase.initializeApp(responseJson)
}).catch((err) => {
console.log('Fallback')
firebase.initializeApp(fb)
return err
})

14
firebase_config.js.sample → plugins/firebase/firebase_local_config.js.sample

@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License
along with Pollo. If not, see <https://www.gnu.org/licenses/>. */
/* eslint-disable*/
const prod_config = {
const fb = {
apiKey: '',
authDomain: '',
databaseURL: '',
@ -24,15 +24,5 @@ const prod_config = {
appId: ''
}
const development_config = {
apiKey: '',
authDomain: '',
databaseURL: '',
projectId: '',
storageBucket: '',
messagingSenderId: '',
appId: ''
}
export { prod_config, development_config }
export { fb }
/* eslint-enable */

17
store/index.js

@ -14,7 +14,6 @@ You should have received a copy of the GNU General Public License
along with Pollo. If not, see <https://www.gnu.org/licenses/>. */
import createPersistedState from 'vuex-persistedstate'
const apiconfig = require('../functions/apiconfig.js')
export const strict = false
@ -25,17 +24,11 @@ export const state = () => ({
})
export const mutations = {
SET_LOGGED_IN_USER (state, { authUser }) {
if (authUser) {
if (apiconfig.domain !== '' && !authUser.email.includes(apiconfig.domain)) {
state.user = null
} else {
state.user = authUser
}
state.userPhoto = authUser.photoURL
} else {
state.userPhoto = null
}
SET_LOGGED_IN_USER (state, payload) {
state.user = payload || null
},
SET_USER_PHOTO_URL (state, payload) {
state.userPhoto = payload || ''
},
SET_DARK_THEME (state, payload) {
state.darkTheme = payload

12035
yarn.lock
File diff suppressed because it is too large
View File