Skip to content

Commit

Permalink
remove vuexstore and add cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Zusel committed Jun 29, 2024
1 parent d8f57f6 commit 592f20c
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import org.javers.core.metamodel.annotation.DiffIgnore;

import java.util.Date;
import java.util.List;
Expand All @@ -21,6 +22,7 @@ public class Customer {
String streetNumber;

@Temporal(TemporalType.TIMESTAMP)
@DiffIgnore
Date createdOn;

@OneToMany(mappedBy = "customer")
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@mdi/font": "7.0.96",
"axios": "^1.6.8",
"vue": "^3.4.0",
"vue-cookies": "^1.8.4",
"vuetify": "^3.5.0",
"vuex": "^4.1.0"
},
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/cmp_OverviewCustomer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
item-key="id"
style="max-height: 70vh; overflow-y: scroll;">
<template v-slot:[`item.actions`]="{item}">
<show-customer-history-component :customer="item"/>
<edit-customer-component :customer="item"/>
<v-btn @click="deleteCustomer(item)">
Löschen
Expand All @@ -25,10 +26,11 @@
<script>
import RESTUtils from "@/utils/RESTUtils";
import EditCustomerComponent from "@/components/com_EditCustomer.vue";
import ShowCustomerHistoryComponent from "@/components/cmp_ShowCustomerHistory.vue";
export default {
name: 'OverviewCustomerComponent',
components: {EditCustomerComponent},
components: {ShowCustomerHistoryComponent, EditCustomerComponent},
created() {
this.getCustomer();
},
Expand Down
48 changes: 48 additions & 0 deletions frontend/src/components/cmp_ShowCustomerHistory.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<v-dialog v-model="dialog" style="background-color: black">
<template v-slot:activator="{ props: activatorProps }">
<v-btn v-bind="activatorProps">History</v-btn>
</template>
<v-container>
<v-label style="color: white">asdasdasd</v-label>
</v-container>
</v-dialog>
</template>

<style scoped>
</style>


<script>
import RESTUtils from "@/utils/RESTUtils";
export default {
name: "ShowCustomerHistoryComponent",
props: ["customer"],
data() {
return {
dialog: false,
history: []
}
},
methods: {
getCustomerHistory: function () {
RESTUtils.sendGetRequest("/history/customer/" + this.customer.id)
.then(response => {
this.history = response.data
console.log(response.data)
})
}
},
watch: {
dialog:{
handler: function (){
if(this.dialog){
this.getCustomerHistory();
}
}
}
}
}
</script>
23 changes: 4 additions & 19 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,12 @@ import App from './App.vue'

// Composables
import {createApp} from 'vue'
import {createStore} from "vuex";
import VueCookies from 'vue-cookies'

const store = createStore({
state: {
employeeShortName: null
},
getters: {
getEmployeeShortName(state, getters) {
return getters.employeeShortName;
},
},
mutations: {
setEmployeeShortName(state, employeeShortName) {
state.employeeShortName = employeeShortName;
}
}
})

export default store
const app = createApp(App)

export default app
registerPlugins(app)
app.use(store)

app.use(VueCookies, {expires: '1d'})
app.mount('#app')
2 changes: 1 addition & 1 deletion frontend/src/pages/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
}
)
} else {
store.commit("setEmployeeShortName", this.selectedEmployee)
this.$cookies.set("ccm_mgmt_shortname", this.selectedEmployee,'7d')
this.$router.push("/Dashboard")
}
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// Composables
import {createRouter, createWebHistory} from 'vue-router/auto'
import {setupLayouts} from 'virtual:generated-layouts'
import store from "@/main";
import VueCookies from "vue-cookies";


const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
Expand All @@ -18,7 +19,7 @@ router.beforeEach((to, from) => {
if (to.name === "/Login") {
return true;
}
if (store.state.employeeShortName === null) {
if (VueCookies.get("ccm_mgmt_shortname") === null) {
console.log("Login benötigt!")
return "/Login";
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/utils/RESTUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from "axios";
import store from "@/main";
import VueCookies from "vue-cookies";

const VITE_BACKEND_URL = import.meta.env.VITE_BACKEND_URL;
const VITE_BACKEND_PORT = import.meta.env.VITE_BACKEND_PORT;
Expand All @@ -12,9 +12,9 @@ const RESTUtils = {
options["data"] = body
}

if (store.state.employeeShortName != null) {
if (VueCookies.get("ccm_mgmt_shortname") != null) {
options["auth"] = {
username: store.state.employeeShortName,
username: VueCookies.get("ccm_mgmt_shortname"),
password: ""
}
}
Expand Down

0 comments on commit 592f20c

Please sign in to comment.