Skip to content

Commit

Permalink
SonarQube
Browse files Browse the repository at this point in the history
  • Loading branch information
oscrx committed Aug 6, 2023
1 parent 988a628 commit 99f425f
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 119 deletions.
2 changes: 1 addition & 1 deletion beer-import/services/processData.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const processData = (data, stores) => {
if (!newStores[data[obj].store]) {
newStores[data[obj].store] = data[obj].store
}
if (storeMap && storeMap.get(data[obj].store)) {
if (storeMap?.get(data[obj].store)) {
data[obj].rawStore = data[obj].store
data[obj].store = storeMap.get(data[obj].store)
}
Expand Down
7 changes: 2 additions & 5 deletions pils-frontend/build/check-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ if (shell.which('npm')) {
module.exports = function () {
const warnings = []

for (let i = 0; i < versionRequirements.length; i++) {
const mod = versionRequirements[i]

for (const mod of versionRequirements) {
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
warnings.push(mod.name + ': ' +
chalk.red(mod.currentVersion) + ' should be ' +
Expand All @@ -43,8 +41,7 @@ module.exports = function () {
console.log(chalk.yellow('To use this template, you must update following to modules:'))
console.log()

for (let i = 0; i < warnings.length; i++) {
const warning = warnings[i]
for (const warning of warnings) {
console.log(' ' + warning)
}

Expand Down
2 changes: 1 addition & 1 deletion pils-frontend/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ exports.createNotifierCallback = () => {
if (severity !== 'error') return

const error = errors[0]
const filename = error.file && error.file.split('!').pop()
const filename = error.file?.split('!').pop()

notifier.notify({
title: packageConfig.name,
Expand Down
1 change: 0 additions & 1 deletion pils-frontend/build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const config = require('../config')
const merge = require('webpack-merge')
const path = require('path')
const baseWebpackConfig = require('./webpack.base.conf')
// const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const portfinder = require('portfinder')
Expand Down
1 change: 0 additions & 1 deletion pils-frontend/build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const webpack = require('webpack')
const config = require('../config')
const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.conf')
// const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
Expand Down
2 changes: 1 addition & 1 deletion pils-frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
Expand Down
16 changes: 8 additions & 8 deletions pils-frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
<div class="has-text-centered">
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<!-- <a class="navbar-item" href="#/">
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28">
</a> -->

<a role="button" class="navbar-burger burger" v-if="isAuthenticated" @click="burger = !burger" aria-label="menu" aria-expanded="false" data-target="navbar" v-bind:class="{'is-active': burger}">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
Expand Down Expand Up @@ -81,19 +77,23 @@
</template>

<script>
// addToHomescreen();
import Api from '@/services/Api'
export default {
name: 'App',
data() {
const isAuthenticated = !!localStorage.getItem('isAuthenticated')
const isAdmin = !!localStorage.getItem('isAdmin')
const userId = isAuthenticated ? localStorage.getItem('userId') : null
return {
burger: false,
isAuthenticated: localStorage.getItem('isAuthenticated') ? true : false,
isAdmin: localStorage.getItem('isAdmin') ? true : false,
userId: localStorage.getItem('isAuthenticated')
isAuthenticated,
isAdmin,
userId,
}
},
}
methods: {
Logout() {
Api().delete(`/api/v1/users/logout`)
Expand Down
26 changes: 12 additions & 14 deletions pils-frontend/src/components/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<h3 class="title has-text-grey">Scan this QR code</h3>
<a :href='otp.uri'>
<div class="container" id="qrcode">
<img id="preview" src="/favicon.ico">
<img id="preview" src="/favicon.ico" alt="Beer emoji">
<img :src='otp.QRdata' :alt='otp.uri'>
</div>
</a>
Expand Down Expand Up @@ -113,20 +113,18 @@
this.Account()
},
computed: {
isDisabled:function() {
pwned(this.newUser.password).then(isPwned => {
this.state.pwned = isPwned
})
async isDisabled() {
// Check if the password is pwned
this.state.pwned = await pwned(this.newUser.password);
if (this.newUser.password !== this.verifyPassword) {
this.state.notEqual = true
} else {
this.state.notEqual = false
}
const stuffToEdit = (this.newUser.password || this.newUser.username || this.newUser.otp) ? true : false
return (this.newUser.oldPassword && stuffToEdit && !this.state.pwned && !this.state.notEqual) ? false : true
// Check if the password is not equal to the verified password
this.state.notEqual = this.newUser.password !== this.verifyPassword;
// Check if there is anything to edit (password, username, or otp)
const stuffToEdit = this.newUser.password || this.newUser.username || this.newUser.otp;
// Determine if the form should be disabled
return !(this.newUser.oldPassword && stuffToEdit && !this.state.pwned && !this.state.notEqual);
}
},
methods: {
Expand Down
120 changes: 62 additions & 58 deletions pils-frontend/src/components/Discounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</div>
</nav>
<progress v-if="discounts.length === 0" class="progress is-small"></progress>
<table class='table container'>
<table class='table container' description="Table of beer discounts">
<thead>
<tr><!-- first row -->
<th><input class='input' v-model='search' type='text' placeholder='Search' autofocus></th>
Expand Down Expand Up @@ -98,18 +98,12 @@ export default {
data () {
return {
discounts: [],
discountAverage: [],
literAverage: [],
percentageAverage: [],
onlineCounter: 0,
search: '',
online: false,
zero: true,
store: '',
stores: [],
volume: '',
volumes: [],
sort:'literPrice',
sort: 'literPrice',
sortDir: 1,
headers: {
brand: 'Brand',
Expand All @@ -125,71 +119,81 @@ export default {
}
},
created () {
this.getPils()
this.getPils() // Fetch discounts data when component is created
},
methods: {
async getPils () {
// Fetch discounts data from the API
const response = await Api().get('/api/v1/discounts')
for (let i = 0; i < response.data.length; i++) {
// take data to main object for sorting
response.data[i].discount = ((response.data[i].pricing.oldPrice - response.data[i].pricing.newPrice) / 100).toFixed(2)
response.data[i].discountPercentage = (100 - (response.data[i].pricing.newPrice * 100 / response.data[i].pricing.oldPrice)).toPrecision(2)
// response.data[i].literPrice = response.data[i].pricing.literPrice
response.data[i].literPrice = response.data[i].pricing.newPrice / response.data[i].liter * 10 // Temporary
response.data[i].newPrice = response.data[i].pricing.newPrice
response.data[i].oldPrice = response.data[i].pricing.oldPrice
this.discountAverage.push(response.data[i].discount)
this.percentageAverage.push(response.data[i].discountPercentage)
this.literAverage.push(response.data[i].literPrice)
if (response.data[i].uri){ this.onlineCounter++ }
if(this.stores.indexOf(response.data[i].store) === -1) {this.stores.push(response.data[i].store)}
if(this.volumes.indexOf(response.data[i].volume) === -1) {this.volumes.push(response.data[i].volume)}
}
this.discounts = response.data
this.volumes.sort()
// Process and update the discounts data
this.discounts = response.data.map((discount) => ({
...discount,
discount: ((discount.pricing.oldPrice - discount.pricing.newPrice) / 100).toFixed(2),
discountPercentage: (100 - (discount.pricing.newPrice * 100 / discount.pricing.oldPrice)).toPrecision(2),
literPrice: (discount.pricing.newPrice / discount.liter * 10).toFixed(2) // Temporary
}))
// Calculate onlineCounter, stores, and volumes based on discounts data
this.onlineCounter = this.discounts.filter((discount) => discount.uri).length
this.stores = [...new Set(this.discounts.map((discount) => discount.store))]
this.volumes = [...new Set(this.discounts.map((discount) => discount.volume))].sort()
},
toggleSort:function(input) {
if(input === this.sort) {
toggleSort (input) {
// Toggle sort direction if the same column header is clicked
if (input === this.sort) {
this.sortDir = this.sortDir === 1 ? -1 : 1
}
this.sort = input
this.sort = input // Set the current sorting column
},
average:function(inputArray){
let result = 0
for (let i = 0; i < inputArray.length; i++) {
result += Number(inputArray[i]) // x += y same as x = x + y
}
return result / inputArray.length
average (inputArray) {
// Calculate the average of an array of numbers
return (inputArray.reduce((total, num) => total + Number(num), 0) / inputArray.length).toFixed(2)
}
},
computed:{
processed:function() {
let data = this.discounts
data = this.orderBy(this.discounts, this.sort, this.sortDir)
if (this.online) { data = data.filter(obj => obj.uri) }
if (!this.zero) { data = data.filter(obj => obj.alcoholPercentage > 100) }
data = this.filterBy(data, this.search)
data = this.filterBy(data, this.store)
data = this.filterBy(data, this.volume)
return data
computed: {
processed () {
let data = [...this.discounts]
data = this.orderBy(data, this.sort, this.sortDir) // Sort the data based on the current sort column and direction
if (this.online) data = data.filter((obj) => obj.uri) // Filter by online status
if (!this.zero) data = data.filter((obj) => obj.alcoholPercentage > 100) // Filter by alcohol percentage
data = this.filterBy(data, this.search) // Filter by search text
data = this.filterBy(data, this.store) // Filter by store
data = this.filterBy(data, this.volume) // Filter by volume
return data // Return the processed data to be displayed
},
averageDiscount () {
// Calculate the average discount percentage
return this.average(this.discounts.map((discount) => discount.discount))
},
averageLiterPrice () {
// Calculate the average liter price
return this.average(this.discounts.map((discount) => discount.literPrice))
},
averagePercentage () {
// Calculate the average discount percentage
return this.average(this.discounts.map((discount) => discount.discountPercentage))
}
},
updated () {
const query = {}
if (this.search) query.search = this.search
if (this.store) query.store = this.store
if (this.volume) query.volume = this.volume
if (this.online) query.online = this.online
if (this.zero) query.zero = this.zero
this.$router.replace({query})
// Update the route query parameters when the filters change
const query = {
search: this.search,
store: this.store,
volume: this.volume,
online: this.online,
zero: this.zero
}
this.$router.replace({ query })
},
mounted () {
this.search = this.$route.query.search
this.store = this.$route.query.store
this.volume = this.$route.query.volume
this.online = this.$route.query.online
this.zero = this.$route.query.zero
},
// Set the initial filter values based on the route query parameters
const { search, store, volume, online, zero } = this.$route.query
this.search = search
this.store = store
this.volume = volume
this.online = online
this.zero = zero
}
}
</script>
33 changes: 23 additions & 10 deletions pils-frontend/src/components/Logging.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<button class="delete" @click="message = ''"></button>
{{message}}
</div>
<table class='table container'>
<table class='table container' description='Table of logs'>
<thead>
<tr> <!-- first row -->
<th><a class="button is-danger" @click='state.deleteMsg = !state.deleteMsg'>Delete all logs</a></th>
Expand Down Expand Up @@ -107,23 +107,36 @@ export default {
}
},
methods: {
async getLogs () {
async getLogs() {
try {
const response = await Api().get('/api/v1/logging')
this.logs = response.data
for (let i = 0; i < response.data.length; i++){
if (this.contexts.indexOf(response.data[i].context) === -1) {
this.contexts.push(response.data[i].context)
// Create separate arrays for contexts and types if they don't exist already
this.contexts = this.contexts || []
this.types = this.types || []
for (const log of response.data) {
if (!this.contexts.includes(log.context)) {
this.contexts.push(log.context)
}
if (this.types.indexOf(response.data[i].type) === -1) {
this.types.push(response.data[i].type)
if (!this.types.includes(log.type)) {
this.types.push(log.type)
}
}
},
async deleteLogs() {
const response = await Api().delete(`/api/v1/logging`)
} catch (error) {
console.error('Error fetching logs:', error)
}
},
async deleteLogs() {
try {
const response = await Api().delete('/api/v1/logging')
this.message = response.data
this.logs = []
} catch (error) {
console.error('Error deleting logs:', error)
}
}
}
}
</script>
5 changes: 1 addition & 4 deletions pils-frontend/src/components/NotFound.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<template>
<!-- <figure class="image is-16by9">
<img :src="`//media.disquscdn.com/errors/img/${Math.ceil( Math.random() * 8 )}.gif`">
</figure> -->
<figure class="image is-16by9">
<img :src="`//media.disquscdn.com/errors/img/${3}.gif`">
<img :src="`//media.disquscdn.com/errors/img/${3}.gif`" alt='404 page, people slapping threir forehead gif.'>
</figure>
</template>
13 changes: 8 additions & 5 deletions pils-frontend/src/components/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@
}
},
computed: {
isDisabled:function() {
pwned(this.$data.password).then(isPwned => {
this.$data.isPwned = isPwned
})
return (this.$data.username && this.$data.password && !this.$data.isPwned) ? false : true
async isPwnedPassword(password) {
const isPwned = await pwned(password);
return isPwned;
},
async isDisabled() {
const { username, password } = this.$data;
const isPwned = await this.isPwnedPassword(password);
return !(username && password && !isPwned);
}
},
methods: {
Expand Down

0 comments on commit 99f425f

Please sign in to comment.