diff --git a/basta/src/App.vue b/basta/src/App.vue index 043fc36..c958742 100644 --- a/basta/src/App.vue +++ b/basta/src/App.vue @@ -7,7 +7,9 @@ -

BaStA

+

+ BaStA +

@@ -15,7 +17,7 @@ - + @@ -37,8 +39,11 @@ - - © Copyright 2018, Michael Götz + + Version 0.1.1 + + + © Copyright 2018, Michael Götz @@ -99,4 +104,9 @@ .font-white { color: #ffffff; } + + #content { + background-color: #343a40; + color: white; + } diff --git a/basta/src/authentication.js b/basta/src/authentication.js index 0457e85..6ba98df 100644 --- a/basta/src/authentication.js +++ b/basta/src/authentication.js @@ -12,11 +12,13 @@ export default { }, // Send a request to the login URL and save the returned JWT - login(creds) { + login(creds, store) { + console.log(store); console.log('LOGIN'); window.axios.post(API_ROOT.concat('/token-auth/token/create/'), creds) .then((response) => { this.user.authenticated = true; + store.dispatch('login').then(); console.log(response); localStorage.setItem('user', JSON.stringify(response)); // Redirect to a specified route @@ -32,21 +34,18 @@ export default { }, // To log out - logout: function (redirect) { + logout: function (store) { window.axios.post(API_ROOT.concat('/token-auth/token/destroy/'),) .then((response) => { this.user.authenticated = false; + store.dispatch('logout').then(); localStorage.removeItem('user'); console.log(response); - // Redirect to a specified route + window.axios.defaults.headers.common = { 'Authorization': '', }; location.reload(); - if (redirect) { - router.push({name: 'home'}); - // router.go(redirect) - } }) .catch(function (error) { console.log(error); diff --git a/basta/src/components/Home.vue b/basta/src/components/Home.vue index 34c3d62..90de85c 100644 --- a/basta/src/components/Home.vue +++ b/basta/src/components/Home.vue @@ -1,5 +1,5 @@ diff --git a/basta/src/components/food/FoodDetail.vue b/basta/src/components/food/FoodDetail.vue index b0e0955..2773c91 100644 --- a/basta/src/components/food/FoodDetail.vue +++ b/basta/src/components/food/FoodDetail.vue @@ -1,44 +1,56 @@ @@ -50,8 +62,6 @@ import PriceOverview from "@/components/food/utils/PriceOverview"; import RatingCombined from "@/components/food/utils/RatingCombined"; import FoodPicture from "@/components/food/utils/FoodPicture"; - import FoodPictureUpload from "@/components/food/utils/PictureUpload"; - import CommentBox from "@/components/food/utils/CommentBox"; import CommentsOverview from "@/components/food/utils/CommentsOverview"; @@ -62,65 +72,34 @@ PriceOverview, RatingCombined, FoodPicture, - FoodPictureUpload, - CommentBox, - CommentsOverview + CommentsOverview, }, data() { return { - food_id: '', - food: {}, - comments: '', - show: true, - images: '', - form: { - file: '', - }, - userFoodImage: '', + mobile: false, }; }, created() { - this.loadFood(); - this.loadUserImage(); + this.addMobileChecker(); + this.$store + .dispatch('loadDetailedFood', {foodId: this.$route.params.id}) + .then(); + this.$store.dispatch('loadDefaultImageLocation').then(); + }, + computed: { + food() { + return this.$store.getters.getDetailedFood; + }, }, methods: { - loadFood() { - window.axios.get(CONFIG.API_ROOT_FOOD - .concat('/meals/').concat(this.$route.params.id)) - .then(response => { - // JSON responses are automatically parsed. - - console.log(JSON.parse(JSON.stringify(response.data))); - this.food = response.data; - this.food_id = this.food.id; - }) - .catch(e => { - }); - window.axios.get(CONFIG.API_ROOT_FOOD - .concat('/meals/').concat(this.$route.params.id).concat('/comments')) - .then(response => { - console.log(JSON.parse(JSON.stringify(response.data))); - this.comments = response.data; - }) - .catch(e => { - }); - }, - loadUserImage() { - if (authentication.authenticated()) { - let url = CONFIG.API_ROOT_ACCOUNT + '/food/images/?food_id=' + this.$route.params.id; - window.axios - .get(url) - .then(response => { - console.log('LOG IMAGE'); - if (response.data.length > 0) { - this.userFoodImage = response.data[0].image.image; - } - }) - .catch() - } - }, isAuthenticated: function () { return authentication.authenticated(); }, + addMobileChecker() { + this.mobile = window.innerWidth < 768; + window.addEventListener('resize', () => { + this.mobile = window.innerWidth < 768; + }, true); + }, } } diff --git a/basta/src/components/food/FoodOverview.vue b/basta/src/components/food/FoodOverview.vue index 30ebd57..b94c24e 100644 --- a/basta/src/components/food/FoodOverview.vue +++ b/basta/src/components/food/FoodOverview.vue @@ -1,12 +1,31 @@ diff --git a/basta/src/components/food/SingleFood.vue b/basta/src/components/food/SingleFood.vue index 0e63c3b..c8a321e 100644 --- a/basta/src/components/food/SingleFood.vue +++ b/basta/src/components/food/SingleFood.vue @@ -1,7 +1,7 @@ @@ -43,21 +54,27 @@ export default { name: "SingleMenu", - props: ['food', 'title', 'defaultImageUrl'], + props: ['food', 'title'], components: {FaRating}, data() { return { userRating: this.food.rating, star: '', }; - }, created() { + }, + computed: { + defaultImageUrl() { + return this.$store.getters.getDefaultImageLocation + }, + }, + created() { // register the icon this.star = Star; // console.log(this.food.rating); // this.userRating = this.food.rating; }, watch: { - userRating: function (newRating) { + userRating: function (newRating, oldRating) { if (authentication.authenticated()) { let url = CONFIG.API_ROOT_FOOD.concat('/meals/').concat(this.food.id).concat('/rating'); window.axios @@ -68,6 +85,7 @@ } ) .catch(); + console.log(oldRating); } else { router.push({name: 'login'}) } diff --git a/basta/src/components/food/TabMenu.vue b/basta/src/components/food/TabMenu.vue index b9fb0f5..f958118 100644 --- a/basta/src/components/food/TabMenu.vue +++ b/basta/src/components/food/TabMenu.vue @@ -1,12 +1,11 @@