From 2910fcb051a56e098be6b4d065b29c411f6816e8 Mon Sep 17 00:00:00 2001 From: solderq35 Date: Mon, 18 Dec 2023 15:51:53 -0800 Subject: [PATCH] fix linter spacing --- .eslintrc.js | 2 +- src/App.vue | 4 +- .../administration/historicalDataDialog.vue | 34 +++---- .../administration/oldDataDialog.vue | 38 +++++--- src/components/calculator/calcCarousel.vue | 16 ++-- src/components/calculator/calcDesktop.vue | 26 ++--- src/components/calculator/calcMobile.vue | 22 ++--- .../graphs/chartComponents/barChart.vue | 18 ++-- .../countryComparisonChart.vue | 12 +-- .../graphs/chartComponents/pieChart.vue | 14 +-- .../graphs/chartComponents/trendChart.vue | 38 ++++---- .../calculator/graphs/chartContainer.vue | 96 +++++++++---------- .../calculator/questions/dependentValue.vue | 6 +- .../calculator/questions/editableCell.vue | 20 ++-- src/components/calculator/questions/list.vue | 16 ++-- .../questions/numericalUnitInput.vue | 16 ++-- .../calculator/questions/tableQuestion.vue | 56 +++++------ src/components/calculator/questions/value.vue | 4 +- src/components/index.vue | 2 +- src/components/navBar.vue | 10 +- src/main.js | 10 +- src/router/index.js | 6 +- src/store/index.js | 6 +- src/store/modules/calculator.js | 28 +++--- src/store/modules/ui.js | 8 +- src/store/modules/user.js | 30 +++--- src/utils/api/cc.js | 10 +- src/utils/api/user.js | 16 ++-- tests/unit/example.spec.js | 14 +-- vue.config.js | 6 +- 30 files changed, 296 insertions(+), 288 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 404eac9..28b3e55 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,7 +12,7 @@ module.exports = { 'generator-star-spacing': 'off', camelcase: [0, { properties: 'never' }], 'vue/no-use-v-if-with-v-for': 'off', - 'space-in-parens': [1, 'always'] + 'space-in-parens': [1, 'never'] }, parserOptions: { parser: 'babel-eslint' diff --git a/src/App.vue b/src/App.vue index 907e7e3..04b64d3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -31,10 +31,10 @@ export default { }, created () { // Update user variables (if logged in) - this.$store.dispatch( 'user/setUserVars' ) + this.$store.dispatch('user/setUserVars') // Download the cc categories and questions - this.$store.dispatch( 'calculator/downloadCategories' ) + this.$store.dispatch('calculator/downloadCategories') }, data () { return { diff --git a/src/components/administration/historicalDataDialog.vue b/src/components/administration/historicalDataDialog.vue index 593c023..18b25e3 100644 --- a/src/components/administration/historicalDataDialog.vue +++ b/src/components/administration/historicalDataDialog.vue @@ -63,8 +63,8 @@ export default { }, tableData () { let data = [] - this.histData.forEach( ( entry ) => { - data.push( { + this.histData.forEach((entry) => { + data.push({ date: entry.date, transportation: entry.totals[0], consumption: entry.totals[1], @@ -72,17 +72,17 @@ export default { food: entry.totals[3], water: entry.totals[4], waste: entry.totals[5] - } ) - } ) + }) + }) return data } }, methods: { - handleDelete ( row ) { - this.$store.commit( 'user/removeHistData', row ) - UserApi.deleteHistData( row ) + handleDelete (row) { + this.$store.commit('user/removeHistData', row) + UserApi.deleteHistData(row) }, - confirmDeletion ( row ) { + confirmDeletion (row) { this.$confirm( 'This will permanently delete your results from ' + this.$store.getters['user/data'][row].date + @@ -94,19 +94,19 @@ export default { type: 'warning' } ) - .then( () => { - this.$message( { + .then(() => { + this.$message({ type: 'success', message: 'Deleted data.' - } ) - this.handleDelete( row ) - } ) - .catch( () => { - this.$message( { + }) + this.handleDelete(row) + }) + .catch(() => { + this.$message({ type: 'info', message: 'Delete canceled.' - } ) - } ) + }) + }) } } } diff --git a/src/components/administration/oldDataDialog.vue b/src/components/administration/oldDataDialog.vue index 0d94cbb..cd8a9bb 100644 --- a/src/components/administration/oldDataDialog.vue +++ b/src/components/administration/oldDataDialog.vue @@ -64,7 +64,7 @@ export default { tableData () { let data = [] this.histData.forEach((entry, index) => { - if (index >== data.length - 2) { + if (index >= data.length - 2) { data.push({ date: entry.date, transportation: entry.totals[0], @@ -85,22 +85,30 @@ export default { UserApi.deleteHistData(row) }, confirmDeletion (row) { - this.$confirm('This will permanently delete your results from ' + this.$store.getters['user/data'][row].date + '. Continue?', 'Warning', { - confirmButtonText: 'Delete', - cancelButtonText: 'Cancel', - type: 'warning' - }).then(() => { - this.$message({ - type: 'success', - message: 'Deleted data.' + this.$confirm( + 'This will permanently delete your results from ' + + this.$store.getters['user/data'][row].date + + '. Continue?', + 'Warning', + { + confirmButtonText: 'Delete', + cancelButtonText: 'Cancel', + type: 'warning' + } + ) + .then(() => { + this.$message({ + type: 'success', + message: 'Deleted data.' + }) + this.handleDelete(row) }) - this.handleDelete(row) - }).catch(() => { - this.$message({ - type: 'info', - message: 'Delete canceled.' + .catch(() => { + this.$message({ + type: 'info', + message: 'Delete canceled.' + }) }) - }) } } } diff --git a/src/components/calculator/calcCarousel.vue b/src/components/calculator/calcCarousel.vue index ecf61f1..8484dca 100644 --- a/src/components/calculator/calcCarousel.vue +++ b/src/components/calculator/calcCarousel.vue @@ -161,12 +161,12 @@ export default { } }, methods: { - setFocus ( newSlideIndex, oldSlideIndex ) { + setFocus (newSlideIndex, oldSlideIndex) { let scope = this - let carousel = document.querySelector( '.carousel' ) + let carousel = document.querySelector('.carousel') // Listen for the "transitioned" event on the carousel element - if ( carousel ) { + if (carousel) { carousel.addEventListener( 'transitioned', function () { @@ -176,18 +176,18 @@ export default { ) // Update the carousel index - this.$nextTick( () => { - this.$refs.carousel.setSlide( newSlideIndex ) - } ) + this.$nextTick(() => { + this.$refs.carousel.setSlide(newSlideIndex) + }) } } }, watch: { studentType () { - this.$store.commit( { + this.$store.commit({ type: 'user/setStudentType', newType: this.studentType - } ) + }) } } } diff --git a/src/components/calculator/calcDesktop.vue b/src/components/calculator/calcDesktop.vue index 8753019..599d46f 100644 --- a/src/components/calculator/calcDesktop.vue +++ b/src/components/calculator/calcDesktop.vue @@ -87,12 +87,12 @@ export default { return this.$store.getters['calculator/categories'] }, determineTitle () { - if ( this.currentTitle === 0 ) return 'About the Calculator' - else if ( this.currentTitle === 6 ) return 'Waste' + if (this.currentTitle === 0) return 'About the Calculator' + else if (this.currentTitle === 6) return 'Waste' else return this.categories[this.currentTitle - 1].title // Subtract 1 to remove the Introduction from the calculation }, progressPercentage () { - return ( this.currentTitle / 6 ) * 100 + return (this.currentTitle / 6) * 100 } }, data () { @@ -104,7 +104,7 @@ export default { }, methods: { next () { - if ( this.$refs.calcCarousel.$refs.carousel.activeIndex === 0 ) { + if (this.$refs.calcCarousel.$refs.carousel.activeIndex === 0) { this.lastSlide = true this.openOffsetsDialog() } else { @@ -113,17 +113,17 @@ export default { } }, prev () { - if ( this.lastSlide ) { + if (this.lastSlide) { this.lastSlide = false } else { this.currentTitle-- this.$refs.calcCarousel.$refs.carousel.prev() } }, - setFocus ( newSlideIndex, oldSlideIndex ) { + setFocus (newSlideIndex, oldSlideIndex) { let scope = this - let carousel = document.querySelector( '.carousel' ) - if ( carousel ) { + let carousel = document.querySelector('.carousel') + if (carousel) { // Listen for the "transitioned" event on the carousel element carousel.addEventListener( 'transitioned', @@ -134,9 +134,9 @@ export default { ) // Update the carousel index - this.$nextTick( () => { - this.$refs.carousel.setSlide( newSlideIndex ) - } ) + this.$nextTick(() => { + this.$refs.carousel.setSlide(newSlideIndex) + }) } }, // This method opens the "carbon offsets" dialog when the calculator reaches its final page. @@ -149,12 +149,12 @@ export default { cancelButtonText: 'No Thanks', dangerouslyUseHTMLString: true } - ).then( () => { + ).then(() => { window.open( 'https://fa.oregonstate.edu/sustainability/carbon-offsets-osu-funded-travel', '_blank' ) - } ) + }) } } } diff --git a/src/components/calculator/calcMobile.vue b/src/components/calculator/calcMobile.vue index 9051fca..8d7d9be 100644 --- a/src/components/calculator/calcMobile.vue +++ b/src/components/calculator/calcMobile.vue @@ -89,12 +89,12 @@ export default { return this.$store.getters['calculator/categories'].length < 1 }, determineTitle () { - if ( this.currentTitle === 0 ) return 'About the Calculator' - else if ( this.currentTitle === 6 ) return 'Waste' + if (this.currentTitle === 0) return 'About the Calculator' + else if (this.currentTitle === 6) return 'Waste' else return this.categories[this.currentTitle - 1].title // Subtract 1 to remove the Introduction from the calculation }, progressPercentage () { - return ( this.currentTitle / 6 ) * 100 + return (this.currentTitle / 6) * 100 } }, data () { @@ -105,7 +105,7 @@ export default { }, methods: { next () { - if ( this.$refs.calcCarousel.$refs.carousel.activeIndex === 0 ) { + if (this.$refs.calcCarousel.$refs.carousel.activeIndex === 0) { this.chartsVisible = true } else { this.currentTitle++ @@ -113,18 +113,18 @@ export default { } }, prev () { - if ( this.chartsVisible ) { + if (this.chartsVisible) { this.chartsVisible = false } else { this.currentTitle-- this.$refs.calcCarousel.$refs.carousel.prev() } }, - setFocus ( newSlideIndex, oldSlideIndex ) { + setFocus (newSlideIndex, oldSlideIndex) { let scope = this - let carousel = document.querySelector( '.carousel' ) + let carousel = document.querySelector('.carousel') - if ( carousel ) { + if (carousel) { // Listen for the "transitioned" event on the carousel element carousel.addEventListener( 'transitioned', @@ -135,9 +135,9 @@ export default { ) // Update the carousel index - this.$nextTick( () => { - this.$refs.carousel.setSlide( newSlideIndex ) - } ) + this.$nextTick(() => { + this.$refs.carousel.setSlide(newSlideIndex) + }) } } } diff --git a/src/components/calculator/graphs/chartComponents/barChart.vue b/src/components/calculator/graphs/chartComponents/barChart.vue index bd95569..96d90e2 100644 --- a/src/components/calculator/graphs/chartComponents/barChart.vue +++ b/src/components/calculator/graphs/chartComponents/barChart.vue @@ -55,12 +55,12 @@ export default { fontFamily: 'Open Sans', padding: 20 }, - onHover: function ( e ) { + onHover: function (e) { e.target.style.cursor = 'pointer' } }, hover: { - onHover: function ( e ) { + onHover: function (e) { e.target.style.cursor = 'default' } }, @@ -76,10 +76,10 @@ export default { bodyFontFamily: 'Open Sans', cornerRadius: 4, callbacks: { - label: ( item ) => { + label: (item) => { return this.resultsToggle - ? parseFloat( item.yLabel ).toFixed( 1 ) + ' kgCO2e' - : parseFloat( item.yLabel ).toFixed( 1 ) + '%' + ? parseFloat(item.yLabel).toFixed(1) + ' kgCO2e' + : parseFloat(item.yLabel).toFixed(1) + '%' } } } @@ -170,18 +170,18 @@ export default { this.chartdata.datasets[0].data, this.dataObj.transportation ) - Object.assign( this.chartdata.datasets[1].data, this.dataObj.consumption ) + Object.assign(this.chartdata.datasets[1].data, this.dataObj.consumption) Object.assign( this.chartdata.datasets[2].data, this.dataObj.energyAndHeating ) - Object.assign( this.chartdata.datasets[3].data, this.dataObj.food ) - Object.assign( this.chartdata.datasets[4].data, this.dataObj.water ) + Object.assign(this.chartdata.datasets[3].data, this.dataObj.food) + Object.assign(this.chartdata.datasets[4].data, this.dataObj.water) } }, mounted () { this.assignStackedData() - this.renderChart( this.chartdata, this.options ) + this.renderChart(this.chartdata, this.options) }, watch: { dataObj () { diff --git a/src/components/calculator/graphs/chartComponents/countryComparisonChart.vue b/src/components/calculator/graphs/chartComponents/countryComparisonChart.vue index 4f92e1c..94ee682 100644 --- a/src/components/calculator/graphs/chartComponents/countryComparisonChart.vue +++ b/src/components/calculator/graphs/chartComponents/countryComparisonChart.vue @@ -58,12 +58,12 @@ export default { fontFamily: 'Open Sans', padding: 20 }, - onHover: function ( e ) { + onHover: function (e) { e.target.style.cursor = 'pointer' } }, hover: { - onHover: function ( e ) { + onHover: function (e) { e.target.style.cursor = 'default' } }, @@ -79,8 +79,8 @@ export default { bodyFontFamily: 'Open Sans', cornerRadius: 4, callbacks: { - label: ( item ) => { - return parseFloat( item.yLabel ).toFixed( 1 ) + ' kgCO2e' + label: (item) => { + return parseFloat(item.yLabel).toFixed(1) + ' kgCO2e' } } } @@ -144,12 +144,12 @@ export default { methods: { assignStackedData () { // Use Object.assign for vue reactivity - Object.assign( this.chartdata.datasets[6].data, this.dataObj ) + Object.assign(this.chartdata.datasets[6].data, this.dataObj) } }, mounted () { this.assignStackedData() - this.renderChart( this.chartdata, this.options ) + this.renderChart(this.chartdata, this.options) }, watch: { dataObj () { diff --git a/src/components/calculator/graphs/chartComponents/pieChart.vue b/src/components/calculator/graphs/chartComponents/pieChart.vue index e0567e1..b5ea1c7 100644 --- a/src/components/calculator/graphs/chartComponents/pieChart.vue +++ b/src/components/calculator/graphs/chartComponents/pieChart.vue @@ -29,12 +29,12 @@ export default { fontFamily: 'Open Sans', padding: 20 }, - onHover: function ( e ) { + onHover: function (e) { e.target.style.cursor = 'pointer' } }, hover: { - onHover: function ( e ) { + onHover: function (e) { e.target.style.cursor = 'default' } }, @@ -50,8 +50,8 @@ export default { bodyFontFamily: 'Open Sans', cornerRadius: 4, callbacks: { - label: ( item ) => { - return parseFloat( item.yLabel ).toFixed( 1 ) + ' kgCO2e' + label: (item) => { + return parseFloat(item.yLabel).toFixed(1) + ' kgCO2e' } } } @@ -84,13 +84,13 @@ export default { }, mounted () { // Use Object.assign for vue reactivity - Object.assign( this.chartdata.datasets[0].data, this.dataObj.totals ) - this.renderChart( this.chartdata, this.options ) + Object.assign(this.chartdata.datasets[0].data, this.dataObj.totals) + this.renderChart(this.chartdata, this.options) }, watch: { dataObj () { // Use Object.assign for vue reactivity - Object.assign( this.chartdata.datasets[0].data, this.dataObj.totals ) + Object.assign(this.chartdata.datasets[0].data, this.dataObj.totals) this.$data._chart.update() } } diff --git a/src/components/calculator/graphs/chartComponents/trendChart.vue b/src/components/calculator/graphs/chartComponents/trendChart.vue index 69c2f12..54cac6d 100644 --- a/src/components/calculator/graphs/chartComponents/trendChart.vue +++ b/src/components/calculator/graphs/chartComponents/trendChart.vue @@ -51,12 +51,12 @@ export default { fontFamily: 'Open Sans', padding: 20 }, - onHover: function ( e ) { + onHover: function (e) { e.target.style.cursor = 'pointer' } }, hover: { - onHover: function ( e ) { + onHover: function (e) { e.target.style.cursor = 'default' } }, @@ -72,8 +72,8 @@ export default { bodyFontFamily: 'Open Sans', cornerRadius: 4, callbacks: { - label: ( item ) => { - return parseFloat( item.yLabel ).toFixed( 1 ) + ' kgCO2e' + label: (item) => { + return parseFloat(item.yLabel).toFixed(1) + ' kgCO2e' } } } @@ -122,27 +122,27 @@ export default { ] // Iterate over each dataset, and add each historical data point - datasets.forEach( ( set, index ) => { + datasets.forEach((set, index) => { set.data = [] set.fill = index === 0 ? 'origin' : index - 1 - data.forEach( ( entry ) => { - set.data.push( entry.totals[index] ) - if ( index === 1 ) dates.push( entry.date ) // Only push one date for each set of totals. I have arbitrarily chosen to do this on the 1st totals category. - } ) + data.forEach((entry) => { + set.data.push(entry.totals[index]) + if (index === 1) dates.push(entry.date) // Only push one date for each set of totals. I have arbitrarily chosen to do this on the 1st totals category. + }) // Add current totals to dataset if data has been entered. - if ( !this.isIncomplete ) { + if (!this.isIncomplete) { // Append a new datapoint - set.data.push( this.totals[index] ) - if ( index === 1 ) dates.push( 'Today' ) + set.data.push(this.totals[index]) + if (index === 1) dates.push('Today') } - } ) + }) // Check to see if data has already been collected for today. // eslint-disable-next-line if (dates[dates.length - 2] == new Date().toLocaleDateString()) { // Update today's datapoint by overwriting - this.$set( dates, dates.length - 2, 'Earlier Today' ) + this.$set(dates, dates.length - 2, 'Earlier Today') } return { datasets, dates } @@ -150,15 +150,15 @@ export default { }, mounted () { // Use Object.assign for vue reactivity - Object.assign( this.chartdata.datasets, this.dataObj.datasets ) - Object.assign( this.chartdata.labels, this.dataObj.dates ) - this.renderChart( this.chartdata, this.options ) + Object.assign(this.chartdata.datasets, this.dataObj.datasets) + Object.assign(this.chartdata.labels, this.dataObj.dates) + this.renderChart(this.chartdata, this.options) }, watch: { dataObj () { // Use Object.assign for vue reactivity - Object.assign( this.chartdata.datasets, this.dataObj.datasets ) - Object.assign( this.chartdata.labels, this.dataObj.dates ) + Object.assign(this.chartdata.datasets, this.dataObj.datasets) + Object.assign(this.chartdata.labels, this.dataObj.dates) this.$data._chart.update() } } diff --git a/src/components/calculator/graphs/chartContainer.vue b/src/components/calculator/graphs/chartContainer.vue index a10a305..92d6f35 100644 --- a/src/components/calculator/graphs/chartContainer.vue +++ b/src/components/calculator/graphs/chartContainer.vue @@ -147,9 +147,9 @@ export default { // Empty array of category totals (in order) let totals = [] - this.categories.forEach( ( category ) => { + this.categories.forEach((category) => { let total = 0 - category.questions.forEach( ( question ) => { + category.questions.forEach((question) => { // Multiply this value by parent question's coefficient // eslint-disable-next-line if (question.input.type == "dependentValue") { @@ -163,27 +163,27 @@ export default { // eslint-disable-next-line if (triggerValue == parentQuestion.value) { // Find the location of the correct coefficient in parentQuestion's value list by mapping and linear searching array - valueMap = parentQuestion.input.values.map( ( obj ) => obj.val ) - location = valueMap.indexOf( triggerValue ) + valueMap = parentQuestion.input.values.map((obj) => obj.val) + location = valueMap.indexOf(triggerValue) } else { // if (triggerValue == 'any') // Find the location of the correct coefficient in parentQuestion's value list by mapping and linear searching array - valueMap = parentQuestion.input.values.map( ( obj ) => obj.val ) - location = valueMap.indexOf( parentQuestion.value ) + valueMap = parentQuestion.input.values.map((obj) => obj.val) + location = valueMap.indexOf(parentQuestion.value) } // If the parentQuestion has not been rendered, its value will be incorrect. Ignore this question if it's parent is undefined. - if ( typeof parentQuestion.input.values[location] !== 'undefined' ) { + if (typeof parentQuestion.input.values[location] !== 'undefined') { // Add to the total for this category // If the parentQuestion has a 0 coefficient, the child question has the coefficient - if ( parentQuestion.input.values[location].coef === 0 ) { + if (parentQuestion.input.values[location].coef === 0) { // Multiply the current question's value to the child question's coefficient total += question.value * question.input.values[0].coef } else { // Multiply the current question's value to the parent question's coefficient if ( - !isNaN( question.value ) && - !isNaN( parentQuestion.input.values[location].coef ) + !isNaN(question.value) && + !isNaN(parentQuestion.input.values[location].coef) ) { total += question.value * parentQuestion.input.values[location].coef @@ -204,48 +204,48 @@ export default { ) { total += question.input.values[ - question.input.values.map( ( a ) => a.val ).indexOf( question.value ) + question.input.values.map((a) => a.val).indexOf(question.value) ].coef } - } ) + }) - totals.push( total ) - } ) + totals.push(total) + }) // Add baseline data for each student type to the calculator. - this.$set( totals, 2, this.studentBaseline[0] + totals[2] ) - this.$set( totals, 4, this.studentBaseline[1] + totals[4] ) + this.$set(totals, 2, this.studentBaseline[0] + totals[2]) + this.$set(totals, 4, this.studentBaseline[1] + totals[4]) return totals }, resultsBarData () { // Determine what data should be shown. - if ( !this.resultsToggle ) { + if (!this.resultsToggle) { // Show 0-100% category comparison vs US Average // Sum all US data let USDataSum = 0 - this.usAvgDataObj.totals.forEach( ( d ) => { + this.usAvgDataObj.totals.forEach((d) => { USDataSum += d - } ) + }) // Compute percentages let USData = [] - this.usAvgDataObj.totals.forEach( ( d ) => { - USData.push( ( d / USDataSum ) * 100 ) - } ) + this.usAvgDataObj.totals.forEach((d) => { + USData.push((d / USDataSum) * 100) + }) // Sum all user data let userDataSum = 0 - this.totals.forEach( ( d ) => { + this.totals.forEach((d) => { userDataSum += d - } ) + }) // Compute Percentages let userData = [] - this.totals.forEach( ( d ) => { - userData.push( ( d / userDataSum ) * 100 ) - } ) + this.totals.forEach((d) => { + userData.push((d / userDataSum) * 100) + }) let finalDataObject = { transportation: [USData[0], userData[0]], @@ -271,9 +271,9 @@ export default { // Returns true if no data has been entered into the calculator let incomplete = true - this.totals.forEach( ( t ) => { - if ( t !== 0 ) incomplete = false - } ) + this.totals.forEach((t) => { + if (t !== 0) incomplete = false + }) return incomplete }, @@ -285,11 +285,11 @@ export default { }, countryComparisonChartData () { let sum = 0 - this.totals.forEach( ( t ) => { + this.totals.forEach((t) => { sum += t - } ) + }) let arr = [] - arr.push( sum ) + arr.push(sum) return arr } }, @@ -304,21 +304,21 @@ export default { type: 'warning' } ) - .then( () => { - this.uploadTotals( this.totals ) - this.$message( { + .then(() => { + this.uploadTotals(this.totals) + this.$message({ type: 'success', message: 'Saved your most recent results!' - } ) - } ) - .catch( () => { - this.$message( { + }) + }) + .catch(() => { + this.$message({ type: 'success', message: 'Kept your previous response!' - } ) - } ) + }) + }) }, - uploadTotals ( totals ) { + uploadTotals (totals) { // Initialize user object for upload let userObject = {} userObject['onid'] = this.$store.getters['user/onid'] @@ -334,7 +334,7 @@ export default { } // Upload userObject for DB entry - UserApi.uploadUserData( data ) + UserApi.uploadUserData(data) }, redirectToLogin () { window.location = this.loginLink @@ -344,14 +344,14 @@ export default { lastSlide () { // Get historical data from vuex store. let data = this.$store.getters['user/data'] - if ( this.lastSlide ) { - if ( data.map( ( d ) => d.date ).indexOf( this.todayDate ) !== -1 ) { + if (this.lastSlide) { + if (data.map((d) => d.date).indexOf(this.todayDate) !== -1) { // Prompt the user for which data to keep (today's previous response, or today's new response). this.confirmData() } else { // Upload this data if the user is logged in and has no historical data for today. - if ( this.$store.getters['user/isLoggedIn'] ) { - this.uploadTotals( this.totals ) + if (this.$store.getters['user/isLoggedIn']) { + this.uploadTotals(this.totals) } } } diff --git a/src/components/calculator/questions/dependentValue.vue b/src/components/calculator/questions/dependentValue.vue index d418a4b..1a30834 100644 --- a/src/components/calculator/questions/dependentValue.vue +++ b/src/components/calculator/questions/dependentValue.vue @@ -37,15 +37,15 @@ export default { showQuestion () { // Return true if the trigger value matches the parent's value, or return true if the trigger value is 'any' and the parent's value is not the default return ( - ( this.triggerValue === 'any' && + (this.triggerValue === 'any' && this.parentQuestion.value !== - this.parentQuestion.input.values[0].val ) || + this.parentQuestion.input.values[0].val) || this.parentQuestion.value === this.triggerValue ) }, questionDataWithMeta () { let questionData = this.questionData - this.$set( questionData, 'metaData', this.parentQuestion.metaData ) + this.$set(questionData, 'metaData', this.parentQuestion.metaData) return questionData } }, diff --git a/src/components/calculator/questions/editableCell.vue b/src/components/calculator/questions/editableCell.vue index 5cd709c..cbc4833 100644 --- a/src/components/calculator/questions/editableCell.vue +++ b/src/components/calculator/questions/editableCell.vue @@ -82,8 +82,8 @@ export default { get () { return this.value }, - set ( val ) { - this.$emit( 'input', val ) + set (val) { + this.$emit('input', val) } }, listeners () { @@ -96,28 +96,28 @@ export default { methods: { onFieldClick () { this.editMode = true - this.$nextTick( () => { + this.$nextTick(() => { let inputRef = this.$refs.input - if ( inputRef ) { + if (inputRef) { inputRef.focus() } - } ) + }) }, onInputExit () { this.editMode = false }, - onInputChange ( val ) { - this.$emit( 'input', val ) + onInputChange (val) { + this.$emit('input', val) } }, mounted () { - if ( !isNaN( parseInt( this.value ) ) ) this.numerical = true + if (!isNaN(parseInt(this.value))) this.numerical = true }, watch: { value () { - if ( this.numerical && isNaN( this.value ) ) { + if (this.numerical && isNaN(this.value)) { this.value = 0 - this.$emit( 'input', this.value ) + this.$emit('input', this.value) } } } diff --git a/src/components/calculator/questions/list.vue b/src/components/calculator/questions/list.vue index 165fd8f..36ca85f 100644 --- a/src/components/calculator/questions/list.vue +++ b/src/components/calculator/questions/list.vue @@ -51,42 +51,42 @@ export default { } }, created () { - if ( this.questionData.value !== 0 ) { + if (this.questionData.value !== 0) { this.value = this.questionData.value } else { this.value = this.questionData.input.values[0].val } // Update VueX for switch type - this.$store.commit( { + this.$store.commit({ type: 'calculator/updateQuestionValue', categoryID: this.categoryID, questionIndex: this.index, value: this.answer ? this.questionData.input.values[1].val : this.questionData.input.values[0].val - } ) + }) }, methods: { updateQuestionValue () { // Update VueX for list type - if ( this.questionData.input.values.length > 2 ) { - this.$store.commit( { + if (this.questionData.input.values.length > 2) { + this.$store.commit({ type: 'calculator/updateQuestionValue', categoryID: this.categoryID, questionIndex: this.index, value: this.value - } ) + }) } else { // Update VueX for switch type - this.$store.commit( { + this.$store.commit({ type: 'calculator/updateQuestionValue', categoryID: this.categoryID, questionIndex: this.index, value: this.answer ? this.questionData.input.values[1].val : this.questionData.input.values[0].val - } ) + }) this.value = this.answer ? this.questionData.input.values[1].val : this.questionData.input.values[0].val diff --git a/src/components/calculator/questions/numericalUnitInput.vue b/src/components/calculator/questions/numericalUnitInput.vue index 129e97c..9bb5146 100644 --- a/src/components/calculator/questions/numericalUnitInput.vue +++ b/src/components/calculator/questions/numericalUnitInput.vue @@ -60,23 +60,23 @@ export default { event: 'change' }, methods: { - add ( val ) { - this.value = parseInt( this.value ) + val - this.$emit( 'change', this.value ) + add (val) { + this.value = parseInt(this.value) + val + this.$emit('change', this.value) }, - longPressStart ( val ) { + longPressStart (val) { this.val = val this.longPress = setInterval( - ( function ( scope ) { + (function (scope) { return function () { scope.value += 5 * scope.val } - } )( this ), + })(this), 50 ) }, longPressStop () { - clearInterval( this.longPress ) + clearInterval(this.longPress) } }, computed: { @@ -96,7 +96,7 @@ export default { watch: { value () { this.value = this.value < 0 ? 0 : this.value - this.value = isNaN( this.value ) ? 0 : this.value + this.value = isNaN(this.value) ? 0 : this.value } } } diff --git a/src/components/calculator/questions/tableQuestion.vue b/src/components/calculator/questions/tableQuestion.vue index 99760f9..a3cd9d0 100644 --- a/src/components/calculator/questions/tableQuestion.vue +++ b/src/components/calculator/questions/tableQuestion.vue @@ -53,21 +53,21 @@ export default { created () { // Dynamically build JSON object from 2D array to fit ElementUI specifications // JSON object data is stored in the first row of values - this.questionData.input.values.forEach( ( row, index ) => { + this.questionData.input.values.forEach((row, index) => { let rowObj = {} - row.forEach( ( data, index ) => { + row.forEach((data, index) => { // Create a property with variable title and assign data to it // 0 is the first row of the data array, which contains column titles. // [index] refers to the title that corresponds with this data point rowObj[this.questionData.input.values[0][index]] = data rowObj[index] = false // Initialize each cell in the table to be non-editable. - } ) + }) // Add this row to tableData - if ( index !== 0 ) { - this.tableData.push( rowObj ) + if (index !== 0) { + this.tableData.push(rowObj) } - } ) + }) // Disable the loading animation (enabled when component is rendered) this.loading = false @@ -81,9 +81,9 @@ export default { showQuestion () { // Return true if the trigger value matches the parent's value, or return true if the trigger value is 'any' and the parent's value is not the default return ( - ( this.triggerValue === 'any' && + (this.triggerValue === 'any' && this.parentQuestion.value !== - this.parentQuestion.input.values[0].val ) || + this.parentQuestion.input.values[0].val) || this.parentQuestion.value === this.triggerValue ) } @@ -99,52 +99,52 @@ export default { updateQuestionValue () { // Convert strings to integers let values = [] - this.questionData.input.values.forEach( ( row, x ) => { + this.questionData.input.values.forEach((row, x) => { let newRow = [] - row.forEach( ( cell, y ) => { - newRow.push( parseInt( this.questionData.input.values[x][y] ) ) - } ) - values.push( newRow ) - } ) + row.forEach((cell, y) => { + newRow.push(parseInt(this.questionData.input.values[x][y])) + }) + values.push(newRow) + }) let total = 0 // This will sum each entry in coefRow once it's multiplied by the primary column // Before commiting to the VueX store, multiply/sum each value in the table - values.slice( 1 ).forEach( ( row ) => { + values.slice(1).forEach((row) => { let primaryColVal = - row[parseInt( this.questionData.input.primaryColumn )] + row[parseInt(this.questionData.input.primaryColumn)] let quantityColVal = - row[parseInt( this.questionData.input.quantityColumn )] + row[parseInt(this.questionData.input.quantityColumn)] // Multiply each quantity by its coefficient - let coefRow = row.slice( 0 ) - this.questionData.input.coefficients.forEach( ( c, index ) => { - if ( index === this.questionData.input.quantityColumn ) { + let coefRow = row.slice(0) + this.questionData.input.coefficients.forEach((c, index) => { + if (index === this.questionData.input.quantityColumn) { coefRow[index] = 0 } else coefRow[index] *= c - } ) + }) // Multiply each value in coefRow by the primary column - this.questionData.input.sumColumns.forEach( ( index ) => { + this.questionData.input.sumColumns.forEach((index) => { total += coefRow[index] * primaryColVal * quantityColVal - } ) + }) // Save result this.questionData.value = total * this.questionData.input.coefficient - } ) + }) // Update VueX Store - this.$store.commit( { + this.$store.commit({ type: 'calculator/updateQuestionValue', categoryID: this.categoryID, questionIndex: this.index, value: this.questionData.value - } ) + }) }, - setEditMode ( row, index ) { + setEditMode (row, index) { this.tableData[row][index] = true }, - saveRow ( row, index ) { + saveRow (row, index) { this.tableData[row][index] = false } } diff --git a/src/components/calculator/questions/value.vue b/src/components/calculator/questions/value.vue index 66f655d..d9f651f 100644 --- a/src/components/calculator/questions/value.vue +++ b/src/components/calculator/questions/value.vue @@ -42,12 +42,12 @@ export default { }, methods: { updateQuestionValue () { - this.$store.commit( { + this.$store.commit({ type: 'calculator/updateQuestionValue', categoryID: this.categoryID, questionIndex: this.index, value: this.questionData.value - } ) + }) } }, data () { diff --git a/src/components/index.vue b/src/components/index.vue index a696e2d..d558dbb 100644 --- a/src/components/index.vue +++ b/src/components/index.vue @@ -43,7 +43,7 @@ export default { // eslint-disable-next-line return ( typeof window.orientation !== 'undefined' || - navigator.userAgent.indexOf( 'IEMobile' ) !== -1 || + navigator.userAgent.indexOf('IEMobile') !== -1 || this.mobileWidth ) } diff --git a/src/components/navBar.vue b/src/components/navBar.vue index 1c0403f..c4dd43f 100644 --- a/src/components/navBar.vue +++ b/src/components/navBar.vue @@ -63,26 +63,26 @@ export default { } }, methods: { - handleClick ( key ) { - switch ( key ) { + handleClick (key) { + switch (key) { case '0': window.location = this.officeHomepageLink break case '1': - this.router.go( '#' ) + this.router.go('#') break case '2': window.location = this.loginLink break case '3-1': - this.$store.commit( 'ui/toggleHistoricalDataDialog' ) + this.$store.commit('ui/toggleHistoricalDataDialog') break case '3-2': window.location = this.dashboardLink break case '3-4': window.location = this.logoutLink - this.$store.commit( 'user/logout' ) + this.$store.commit('user/logout') break default: break diff --git a/src/main.js b/src/main.js index ce72b09..463bba7 100644 --- a/src/main.js +++ b/src/main.js @@ -20,8 +20,8 @@ import locale from 'element-ui/lib/locale/lang/en' import '@/assets/element-variables.scss' // For element UI -Vue.use( Vuei18n ) -Vue.use( elm, { locale: locale } ) +Vue.use(Vuei18n) +Vue.use(elm, { locale: locale }) Vue.config.productionTip = false Vue.config.debug = false @@ -33,11 +33,11 @@ Vue.config.debug = false Vue.config.devtools = false /* eslint-disable no-new */ -window.vue = new Vue( { +window.vue = new Vue({ el: '#app', router, store, components: { App }, template: '', - render: ( h ) => h( App ) -} ) + render: (h) => h(App) +}) diff --git a/src/router/index.js b/src/router/index.js index aa2177d..080835a 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -2,9 +2,9 @@ import Vue from 'vue' import Router from 'vue-router' import index from '@/components/index' -Vue.use( Router ) +Vue.use(Router) -export default new Router( { +export default new Router({ routes: [ { path: '/', @@ -12,4 +12,4 @@ export default new Router( { component: index } ] -} ) +}) diff --git a/src/store/index.js b/src/store/index.js index a567d0a..746a1a9 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -20,9 +20,9 @@ import UIModule from './modules/ui.js' // storage: localStorage // }) -Vue.use( Vuex ) // Use Vuex as central data store +Vue.use(Vuex) // Use Vuex as central data store -export default new Vuex.Store( { +export default new Vuex.Store({ state: {}, getters: {}, mutations: {}, @@ -32,6 +32,6 @@ export default new Vuex.Store( { calculator: CalculatorModule, ui: UIModule } -} ) +}) // Add for vuex-persist: , // plugins: [vuexPersist.plugin] diff --git a/src/store/modules/calculator.js b/src/store/modules/calculator.js index c650c8c..208f6b5 100644 --- a/src/store/modules/calculator.js +++ b/src/store/modules/calculator.js @@ -16,45 +16,45 @@ export default { graphs: [] }, getters: { - categories: ( state ) => { + categories: (state) => { return state.categories }, - graphs: ( state ) => { + graphs: (state) => { return state.graphs } }, mutations: { // Initializes/updates all of the user variables. - updateCategoryTotal ( state, categoryID, newTotal ) { + updateCategoryTotal (state, categoryID, newTotal) { state.categories[categoryID].total = newTotal }, // Updates the value input by the user - updateQuestionValue ( state, payload ) { + updateQuestionValue (state, payload) { state.categories[payload.categoryID].questions[ payload.questionIndex ].value = payload.value }, - initializeCategories ( state, categories ) { + initializeCategories (state, categories) { // Initialize value endpoint for computed property reactivity - categories.forEach( ( c ) => { - c.questions.forEach( ( q ) => { + categories.forEach((c) => { + c.questions.forEach((q) => { q.value = 0 - } ) - } ) + }) + }) state.categories = categories } }, actions: { // Downloads all of the questions and categories - downloadCategories ( context ) { - ccApi.downloadCategories().then( ( categories ) => { + downloadCategories (context) { + ccApi.downloadCategories().then((categories) => { context.commit( 'initializeCategories', - categories.sort( ( a, b ) => { + categories.sort((a, b) => { return a.categoryID > b.categoryID ? 1 : -1 - } ) + }) ) - } ) + }) } } } diff --git a/src/store/modules/ui.js b/src/store/modules/ui.js index 1ef0569..b6cfbc1 100644 --- a/src/store/modules/ui.js +++ b/src/store/modules/ui.js @@ -14,20 +14,20 @@ export default { oldDataDialog: false }, getters: { - historicalDataDialog: ( state ) => { + historicalDataDialog: (state) => { return state.historicalDataDialog }, - oldDataDialog: ( state ) => { + oldDataDialog: (state) => { return state.oldDataDialog } }, mutations: { // Initializes/updates all of the user variables. - toggleHistoricalDataDialog ( state ) { + toggleHistoricalDataDialog (state) { state.historicalDataDialog = !state.historicalDataDialog }, // Initializes/updates all of the user variables. - toggleOldDataDialog ( state ) { + toggleOldDataDialog (state) { state.oldDataDialog = !state.oldDataDialog } } diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 337f790..6b8aa3a 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -21,31 +21,31 @@ export default { administrator: false }, getters: { - onid: ( state ) => { + onid: (state) => { return state.onid }, - firstName: ( state ) => { + firstName: (state) => { return state.firstName }, - primaryAffiliation: ( state ) => { + primaryAffiliation: (state) => { return state.primaryAffiliation }, - data: ( state ) => { + data: (state) => { return state.data }, - isLoggedIn: ( state ) => { + isLoggedIn: (state) => { return state.isLoggedIn }, - studentType: ( state ) => { + studentType: (state) => { return state.studentType }, - administrator: ( state ) => { + administrator: (state) => { return state.administrator } }, mutations: { // Initializes/updates all of the user variables. - update ( state, userObject ) { + update (state, userObject) { state.onid = userObject.onid state.firstName = userObject.firstName state.primaryAffiliation = userObject.primaryAffiliation @@ -56,19 +56,19 @@ export default { state.data = userObject.data }, // Removes one historical data entry - removeHistData ( state, index ) { - state.data.splice( index, 1 ) + removeHistData (state, index) { + state.data.splice(index, 1) }, - setStudentType ( state, data ) { + setStudentType (state, data) { state.studentType = data.newType } }, actions: { - setUserVars ( context ) { + setUserVars (context) { // Download user data using the user api - UserApi.downloadUserData().then( ( userObject ) => { - context.commit( 'update', userObject ) - } ) + UserApi.downloadUserData().then((userObject) => { + context.commit('update', userObject) + }) } } } diff --git a/src/utils/api/cc.js b/src/utils/api/cc.js index 87d0905..b5fc6a6 100644 --- a/src/utils/api/cc.js +++ b/src/utils/api/cc.js @@ -4,12 +4,12 @@ export default { // Returns a JSON object containing the Carbon Calculator questions downloadCategories () { return axios - .get( '/questions', { withCredentials: true } ) - .then( ( res ) => { + .get('/questions', { withCredentials: true }) + .then((res) => { return res.data - } ) - .catch( ( e ) => { + }) + .catch((e) => { return [] - } ) + }) } } diff --git a/src/utils/api/user.js b/src/utils/api/user.js index 56f9639..67c20f5 100644 --- a/src/utils/api/user.js +++ b/src/utils/api/user.js @@ -12,30 +12,30 @@ import axios from 'axios' export default { // Downloads the user's onid, firstName, primaryAffiliation, and historical data downloadUserData () { - return axios.get( '/download', { withCredentials: true } ).then( ( res ) => { + return axios.get('/download', { withCredentials: true }).then((res) => { return res.data - } ) + }) }, // Deletes the user's previous data - deleteHistData ( row ) { - axios.get( '/delete?id=' + row, { withCredentials: true } ) + deleteHistData (row) { + axios.get('/delete?id=' + row, { withCredentials: true }) }, // Sends a request to the api route responsible for destroying user sessions. DOES NOT LOG OUT OF ONID!!! // 11/7/2019 - Need to create logout route & verify that it works. logout () { - axios.get( 'auth/logout', { withCredentials: true } ) + axios.get('auth/logout', { withCredentials: true }) }, // Uploads the user's data. // This data contains the totals for each category of the calculator - uploadUserData ( data ) { - axios.post( '/upload', data, { + uploadUserData (data) { + axios.post('/upload', data, { withCredentials: true, headers: { 'Content-Type': 'text/plain' } - } ) + }) } } diff --git a/tests/unit/example.spec.js b/tests/unit/example.spec.js index 485eba4..f84fb39 100644 --- a/tests/unit/example.spec.js +++ b/tests/unit/example.spec.js @@ -1,12 +1,12 @@ import { shallowMount } from '@vue/test-utils' import HelloWorld from '@/components/HelloWorld.vue' -describe( 'HelloWorld.vue', () => { - it( 'renders props.msg when passed', () => { +describe('HelloWorld.vue', () => { + it('renders props.msg when passed', () => { const msg = 'new message' - const wrapper = shallowMount( HelloWorld, { + const wrapper = shallowMount(HelloWorld, { propsData: { msg } - } ) - expect( wrapper.text() ).toMatch( msg ) - } ) -} ) + }) + expect(wrapper.text()).toMatch(msg) + }) +}) diff --git a/vue.config.js b/vue.config.js index 27333ce..305a501 100644 --- a/vue.config.js +++ b/vue.config.js @@ -10,10 +10,10 @@ // vue.config.js module.exports = { - chainWebpack: ( config ) => { + chainWebpack: (config) => { // Load and render SVG images - const svgRule = config.module.rule( 'svg' ) + const svgRule = config.module.rule('svg') svgRule.uses.clear() - svgRule.use( 'vue-svg-loader' ).loader( 'vue-svg-loader' ) + svgRule.use('vue-svg-loader').loader('vue-svg-loader') } }