diff --git a/.docker/nginx.conf b/.docker/nginx.conf index 6502937..1e7b11d 100644 --- a/.docker/nginx.conf +++ b/.docker/nginx.conf @@ -24,7 +24,8 @@ server { } location /admin/ { - rewrite ^/admin/(.*) /admin/$1 break; + #rewrite ^/admin/(.*) /admin/$1 break; + rewrite ^/admin/(.*) /$1 break; proxy_pass http://127.0.0.1:8080/; include uwsgi_params; uwsgi_param UWSGI_SCHEME $scheme; diff --git a/.docker/run.sh b/.docker/run.sh index 04c9794..71237c5 100644 --- a/.docker/run.sh +++ b/.docker/run.sh @@ -4,4 +4,4 @@ echo "Starting TraineerBook.." echo "" service nginx start echo "" -exec python manage.py runserver 127.0.0.1:8080 +exec python manage.py runserver 0.0.0.0:8080 diff --git a/backend/traineerbook/settings.py b/backend/traineerbook/settings.py index db39921..524ed2f 100644 --- a/backend/traineerbook/settings.py +++ b/backend/traineerbook/settings.py @@ -81,7 +81,7 @@ CORS_ALLOW_ALL_ORIGINS = True CORS_ALLOW_CREDENTIALS = True CORS_ALLOW_PRIVATE_NETWORK = True -CSRF_TRUSTED_ORIGINS=['http://*', 'https://*'] +CSRF_TRUSTED_ORIGINS=['https://localhost:80', 'https://*'] MIDDLEWARE = [ 'traineerbook.middlewares.AddHeaderMiddleware', diff --git a/frontend/src/components/layout/CarritoHeader.vue b/frontend/src/components/layout/CarritoHeader.vue index 0833cd8..35cd43b 100644 --- a/frontend/src/components/layout/CarritoHeader.vue +++ b/frontend/src/components/layout/CarritoHeader.vue @@ -3,18 +3,15 @@ v-slot="{ navigate }" to="/cart" custom> - + navigate"> - {{ cart.length }} + {{ cart.cart.length }} - + diff --git a/frontend/src/components/pages/clase/ComentariosActividad.vue b/frontend/src/components/pages/clase/ComentariosActividad.vue index 1962524..a1582ee 100644 --- a/frontend/src/components/pages/clase/ComentariosActividad.vue +++ b/frontend/src/components/pages/clase/ComentariosActividad.vue @@ -1,5 +1,7 @@ - + + color="primary" + @click.prevent="submitComment" /> @@ -36,8 +40,31 @@ diff --git a/frontend/src/components/pages/clase/TablaActividad.vue b/frontend/src/components/pages/clase/TablaActividad.vue index 7bc2e07..5ac4174 100644 --- a/frontend/src/components/pages/clase/TablaActividad.vue +++ b/frontend/src/components/pages/clase/TablaActividad.vue @@ -7,7 +7,7 @@ bordered :rows="rows" :columns="columns" - row-key="name" + row-key="key" hide-bottom virtual-scroll selection="multiple" /> @@ -18,7 +18,7 @@ class="ma-3" :label="selected.length > 0 ? `Añadir al carrito (${selected.length} elementos)` : 'Añadir al carrito'" color="purple" - @click="cart.concat(selected)"> + @click="addToCart"> { - cart.concat(selected) + addToCart() navigate() }" /> @@ -46,7 +46,7 @@ import { computed, ref } from 'vue'; const props = defineProps<{ products: Product[] }>(); -const selected = ref([]); +const selected = ref([]); const cart = useCart(); interface Column { @@ -85,6 +85,7 @@ const rows = computed(() => { const stringHoraFin = `${horaFin}:${minutosFin}`; return { + key: product.id, 'dia_start': stringInicio, 'dia_fin': stringFin, 'hora_start': stringHoraInicio, @@ -94,4 +95,14 @@ const rows = computed(() => { }); }); +function addToCart() { + const cartsId = cart.value.cart.map((item) => item.id); + const productsToAdd = selected.value.map((item) => + props.products.find((product) => product.id === item.key)) + .filter((i) => i !== undefined) + .filter((i) => !cartsId.includes(i?.id)); + + cart.value.cart = [...cart.value.cart, ...productsToAdd as Product[]]; +} + diff --git a/frontend/src/composables/use-cart.ts b/frontend/src/composables/use-cart.ts index b941555..ca09b51 100644 --- a/frontend/src/composables/use-cart.ts +++ b/frontend/src/composables/use-cart.ts @@ -1,10 +1,18 @@ import { Product } from '@/api'; -import { Ref, ref } from 'vue'; +import { useStorage } from '@vueuse/core'; + +export const cart = useStorage( + 'cart', + { + cart: [] as Product[], + quantityMap: new Map() + }, + localStorage +); -export const cart = ref([]); /** - * + * Retuns cart store */ -export function useCart(): Ref { +export function useCart(): typeof cart { return cart; } diff --git a/frontend/src/pages/cart.vue b/frontend/src/pages/cart.vue new file mode 100644 index 0000000..d622372 --- /dev/null +++ b/frontend/src/pages/cart.vue @@ -0,0 +1,36 @@ + + + CARRITO + + + + + + {{ getActivityFromProduct(item.id)?.name }} + + + {{ item.price }}€ + + + + + + diff --git a/frontend/src/pages/clase/[id].vue b/frontend/src/pages/clase/[id].vue index 62c4ce3..ab88530 100644 --- a/frontend/src/pages/clase/[id].vue +++ b/frontend/src/pages/clase/[id].vue @@ -1,6 +1,6 @@ @@ -21,7 +21,10 @@ Comentarios - + No se ha encontrado la actividad @@ -31,7 +34,7 @@