From 3ca0db7a3ec1981ebdc853d2cc89e597103ecf56 Mon Sep 17 00:00:00 2001 From: JuMiSanAr Date: Tue, 5 Apr 2022 13:00:28 +0200 Subject: [PATCH] sf_shopinvader_mobile_base: remove unused files --- .../static/wms/src/cart.js | 151 ---------- .../static/wms/src/orders.js | 152 ---------- .../static/wms/src/products.js | 274 ------------------ .../static/wms/src/store/index.js | 16 - .../static/wms/src/utils_cart.js | 25 -- 5 files changed, 618 deletions(-) delete mode 100644 shopfloor_shopinvader_mobile_base/static/wms/src/cart.js delete mode 100644 shopfloor_shopinvader_mobile_base/static/wms/src/orders.js delete mode 100644 shopfloor_shopinvader_mobile_base/static/wms/src/products.js delete mode 100644 shopfloor_shopinvader_mobile_base/static/wms/src/store/index.js delete mode 100644 shopfloor_shopinvader_mobile_base/static/wms/src/utils_cart.js diff --git a/shopfloor_shopinvader_mobile_base/static/wms/src/cart.js b/shopfloor_shopinvader_mobile_base/static/wms/src/cart.js deleted file mode 100644 index 7ab3929252e..00000000000 --- a/shopfloor_shopinvader_mobile_base/static/wms/src/cart.js +++ /dev/null @@ -1,151 +0,0 @@ -/** - * Copyright 2021 Camptocamp SA (http://www.camptocamp.com) - * @author Simone Orsi - * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - */ - -import store from "./store/index.js"; - -import CartModule from "./store/modules/cart_store.js"; -import {translation_registry} from "/shopfloor_mobile_base/static/wms/src/services/translation_registry.js"; - -const cart_module = new CartModule(); -store.registerModule("cart_module", cart_module); - -import {process_registry} from "/shopfloor_mobile_base/static/wms/src/services/process_registry.js"; - -const Cart = { - template: ` - - - - - {{$t("screen.cart.total_in_cart")}}: {{ cart.amount.total.toFixed(2) }} - - - {{$t("screen.cart.checkout")}} - - -
-

The cart is empty

-
- NEW PURCHASE -
-
-
-

Checkout successful!

-
- NEW PURCHASE - ORDERS -
-
-

Something went wrong with checkout...

-
- `, - data: function () { - return { - has_cart: false, - checkout_success: false, - checkout_failure: false, - }; - }, - mounted() { - this.initialize_cart(); - }, - updated() { - const cart_lines = this.$store.state.cart_module.cart.lines; - if (_.isEmpty(cart_lines.items)) { - this.has_cart = false; - } - }, - methods: { - initialize_cart: function () { - // TODO: if we want the cart to persist between sessions, should it go to localStorage? - const cart = this.utils.cart.get_cart(); - - if (cart) { - this.$store.commit("cart_loadCart", cart); - this.has_cart = true; - } - }, - get_odoo: function () { - const odoo_params = { - base_url: this.$root.app_info.shop_api_route, - usage: "cart", - headers: {}, - }; - - if (!_.isEmpty(this.cart)) { - odoo_params.headers["SESS-CART-ID"] = this.cart.id; - } - - return this.$root.getOdoo(odoo_params); - }, - to_products: function () { - this.$router.push({name: "products"}); - }, - to_orders: function () { - this.$router.push({name: "orders"}); - }, - checkout: function () { - // TODO: Update this once the backend is updated - // and doesn't require adding one line at a time. - // At the moment the checkout button only updates - // the UI, and it's for the rest of the app to send calls - // to the backend. - this.has_cart = false; - this.checkout_success = true; - this.utils.cart.remove_cart(); - }, - }, - computed: { - cart: function () { - return this.$store.state.cart_module.cart; - }, - screen_info: function () { - return { - title: this.screen_title, - klass: "shop cart", - }; - }, - screen_title: function () { - return this.$t("screen.cart.title"); - }, - }, -}; - -process_registry.add( - "cart", - Cart, - { - path: "/cart", - }, - { - menu: { - _type: "all", - name: "Cart", - id: "cart", - to: { - name: "cart", - }, - }, - } -); - -translation_registry.add("en-US.screen.cart.title", "Cart"); -translation_registry.add("fr-FR.screen.cart.title", "Panier"); -translation_registry.add("de-DE.screen.cart.title", "Warenkorb"); - -translation_registry.add("en-US.screen.cart.total_in_cart", "Total in cart"); -translation_registry.add("fr-FR.screen.cart.total_in_cart", "Total dans le panier"); -translation_registry.add("de-DE.screen.cart.total_in_cart", "Gesamt im Warenkorb"); - -translation_registry.add("en-US.screen.cart.checkout", "CHECKOUT"); -translation_registry.add("fr-FR.screen.cart.checkout", "COMMANDER"); -translation_registry.add("de-DE.screen.cart.checkout", "BESTELLEN"); - -export default Cart; diff --git a/shopfloor_shopinvader_mobile_base/static/wms/src/orders.js b/shopfloor_shopinvader_mobile_base/static/wms/src/orders.js deleted file mode 100644 index 150b970abee..00000000000 --- a/shopfloor_shopinvader_mobile_base/static/wms/src/orders.js +++ /dev/null @@ -1,152 +0,0 @@ -import {process_registry} from "/shopfloor_mobile_base/static/wms/src/services/process_registry.js"; -import {translation_registry} from "/shopfloor_mobile_base/static/wms/src/services/translation_registry.js"; - -import store from "./store/index.js"; - -import OrderModule from "./store/modules/order_store.js"; - -const orders_module = new OrderModule(); -store.registerModule("orders_module", orders_module); - -const Orders = { - template: ` - - - - - Order {{ order.name}} - {{ format_date(order.date) }} - Products purchased: {{ order.lines.items.length }} - Total number of units purchased: {{ calculate_items(order) }} - - - - - - mdi-arrow-left - {{$t("screen.orders.back_to_orders")}} - - -
-

Order {{ current_order.name }}

-
- - -
-

{{ item.product.name }}

-

Price: {{ item.amount.price }}

-

Quantity: {{ item.qty }}

-

Total: {{ item.amount.total }}

- - - - - - - `, - data: function () { - return { - current_order: {}, - }; - }, - mounted() { - const odoo_params = { - base_url: this.$root.app_info.shop_api_route, - usage: "sales", - }; - this.odoo = this.$root.getOdoo(odoo_params); - this._fetch(this.$route.params.identifier); - }, - beforeRouteUpdate(to, from, next) { - if (to.params.identifier) { - this._load_order(to.params.identifier); - } - next(); - }, - methods: { - _fetch: function (identifier) { - const params = {}; - const self = this; - this.odoo.get("search", params).then((result) => { - this.$store.commit("orders_loadOrders", result.data); - if (identifier) { - this._load_order(identifier); - } - }); - }, - format_date: function (date) { - const split_date = date.split("T"); - return split_date[0] + " - " + split_date[1]; - }, - calculate_items: function (order) { - return order.lines.items.reduce((acc, next) => { - return acc + next.qty; - }, 0); - }, - _load_order: function (identifier) { - const order = _.find(this.orders, ["name", identifier]); - this.$set(this, "current_order", order); - }, - view_order: function (order) { - this.$router.push({name: "orders", params: {identifier: order.name}}); - }, - to_orders: function (e) { - this.current_order = {}; - this.$router.push({name: "orders", params: {identifier: undefined}}); - }, - }, - computed: { - orders: function () { - return this.$store.state.orders_module.orders; - }, - screen_info: function () { - return { - title: this.screen_title, - klass: "shop orders", - }; - }, - screen_title: function () { - return this.$t("screen.orders.title"); - }, - }, -}; - -translation_registry.add("en-US.screen.orders.title", "Orders"); -translation_registry.add("fr-FR.screen.orders.title", "Commandes"); -translation_registry.add("de-DE.screen.orders.title", "Bestellungen"); - -translation_registry.add("en-US.screen.orders.back_to_orders", "Back to orders"); -translation_registry.add("fr-FR.screen.orders.back_to_orders", "Vers vos ordres"); -translation_registry.add( - "de-DE.screen.orders.back_to_orders", - "Zurück zu Bestellungen" -); - -process_registry.add( - "orders", - Orders, - { - path: "/orders/:identifier?", - }, - { - menu: { - _type: "all", - name: "Orders", - id: "order", - to: { - name: "orders", - }, - }, - } -); diff --git a/shopfloor_shopinvader_mobile_base/static/wms/src/products.js b/shopfloor_shopinvader_mobile_base/static/wms/src/products.js deleted file mode 100644 index 3f30503cf5e..00000000000 --- a/shopfloor_shopinvader_mobile_base/static/wms/src/products.js +++ /dev/null @@ -1,274 +0,0 @@ -/** - * Copyright 2021 Camptocamp SA (http://www.camptocamp.com) - * @author Simone Orsi - * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - */ - -import {process_registry} from "/shopfloor_mobile_base/static/wms/src/services/process_registry.js"; -import {translation_registry} from "/shopfloor_mobile_base/static/wms/src/services/translation_registry.js"; -import ProductModule from "./store/modules/product_store.js"; -import store from "./store/index.js"; - -const products_module = new ProductModule(); -store.registerModule("products_module", products_module); - -// TODO: add pagination for products (currently showing only 1 page of 10 items by default) -// TODO: add images to detail and list - -const Products = { - template: ` - - - Searching for "{{filter_text}}" - - {{$t('screen.products.remove_filter')}} - - - - - - - {{ record.name }} - - Price: {{record.price.default.value.toFixed(2)}} - - - - {{$t("screen.products.add_to_cart")}} - - - - - - - - - - mdi-arrow-left - - {{$t("screen.products.back_to_catalog")}} - - - - - {{current_product.name}} - -
{{current_product.meta_description || description_lipsum}}
-
- Price: {{current_product.price.default.value.toFixed(2)}} - - - - {{$t("screen.products.add_to_cart")}} - - -
-
- `, - data: function () { - return { - current_product: {}, - has_filter: false, - filter_text: "", - filtered_products: [], - // TODO: Delete once the backend provides a product description. - description_lipsum: - "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", - }; - }, - mounted() { - const cart = this.utils.cart.get_cart(); - if (cart) { - this.$store.commit("cart_loadCart", cart); - } - const odoo_params = { - base_url: this.$root.app_info.shop_api_route, - usage: "products", - }; - this.odoo = this.$root.getOdoo(odoo_params); - this._fetch(this.$route.params.identifier); - }, - beforeRouteUpdate(to, from, next) { - if (to.params.identifier) { - this._load_product(to.params.identifier); - } - next(); - }, - methods: { - to_catalog: function () { - this.current_product = {}; - this.$router.push({name: "products", params: {identifier: undefined}}); - }, - // TODO: fetch should be done from the sync service. - // We should pick product from the local storage instead. - _fetch: function (identifier) { - const params = {}; - const self = this; - this.odoo.get("search", params).then((result) => { - this.$store.commit("products_loadProducts", result.data); - if (identifier) { - this._load_product(identifier); - } - }); - }, - _load_product: function (identifier) { - const product = _.find(this.products, ["sku", identifier]); - this.$set(this, "current_product", product); - }, - view_product: function (product) { - this.$router.push({name: "products", params: {identifier: product.sku}}); - }, - show_products: function () { - if (this.has_filter) { - return this.filtered_products; - } else { - return this.products; - } - }, - on_search: function (input) { - if (_.isEmpty(input.text)) { - this.remove_filter(); - } else { - this.has_filter = true; - this.filter_text = input.text; - this.filtered_products = this.products.filter((product) => { - return product.name - .toLowerCase() - .includes(input.text.toLowerCase()); - }); - } - }, - remove_filter: function () { - this.has_filter = false; - this.filter_text = ""; - this.filtered_products = []; - }, - add_to_cart: function (record) { - // TODO: Create utils for cart. - const cart = this.utils.cart.get_cart(); - const has_cart = !_.isEmpty(cart); - - const self = this; - const odoo_params = { - base_url: this.$root.app_info.shop_api_route, - usage: "cart", - headers: {}, - }; - - if (has_cart) { - odoo_params.headers["SESS-CART-ID"] = cart.id; - } - - // TODO: update this once the backend accepts - // retrieving cart data. At the moment - // it is necessary to initialize a cart. - - const odoo = this.$root.getOdoo(odoo_params); - - odoo.post("add_item", { - params: {product_id: record.id, item_qty: 1}, - }).then(function (result) { - if (!has_cart) { - result.data.lines.items[0] = { - product: result.data.lines.items[0].product, - total: result.data.lines.items[0].product.price.default.value, - qty: 1, - }; - self.$store.commit("cart_loadCart", result.data); - } else { - self.$store.commit("cart_addItemToCart", record); - } - }); - }, - }, - computed: { - products: function () { - return this.$store.state.products_module.products; - }, - screen_info: function () { - return { - title: this.screen_title, - klass: "shop products", - user_message: this.user_message, - }; - }, - screen_title: function () { - return this.$t("screen.products.title", { - what: this.$route.params.identifier, - }); - }, - }, -}; - -process_registry.add( - "products", - Products, - { - path: "/products/:identifier?", - }, - { - menu: { - _type: "all", - name: "Catalog", - id: "catalog", - to: { - name: "products", - params: {}, - }, - }, - } -); - -translation_registry.add("en-US.screen.products.title", "Products"); -translation_registry.add("fr-FR.screen.products.title", "Produits"); -translation_registry.add("de-DE.screen.products.title", "Produkte"); - -translation_registry.add("en-US.screen.products.add_to_cart", "ADD TO CART"); -translation_registry.add("fr-FR.screen.products.add_to_cart", "AJOUTER AU PANIER"); -translation_registry.add( - "de-DE.screen.products.add_to_cart", - "PRODUKT IN DEN WARENKORB LEGEN" -); - -translation_registry.add("en-US.screen.products.back_to_catalog", "Back to catalog"); -translation_registry.add("fr-FR.screen.products.back_to_catalog", "Vers le catalogue"); -translation_registry.add("de-DE.screen.products.back_to_catalog", "Zurück zum Katalog"); - -translation_registry.add("en-US.screen.products.search", "Search"); -translation_registry.add("fr-FR.screen.products.search", "Rechercher"); -translation_registry.add("de-DE.screen.products.search", "Suchen"); - -translation_registry.add("en-US.screen.products.remove_filter", "Remove filter"); -translation_registry.add("fr-FR.screen.products.remove_filter", "Supprimer le filtre"); -translation_registry.add("de-DE.screen.products.remove_filter", "Filter entfernen"); - -export default Products; diff --git a/shopfloor_shopinvader_mobile_base/static/wms/src/store/index.js b/shopfloor_shopinvader_mobile_base/static/wms/src/store/index.js deleted file mode 100644 index f625c174e28..00000000000 --- a/shopfloor_shopinvader_mobile_base/static/wms/src/store/index.js +++ /dev/null @@ -1,16 +0,0 @@ -const store = new Vuex.Store(); - -// This is called every time the Vuex store is updated -// so that the browser storage is updated accordingly. -store.subscribe((mutation, state) => { - const state_key = mutation.type.split("_")[0]; - const module_name = state_key + "_module"; - const storage_key = "shopfloor_" + state_key; - - window.sessionStorage.setItem( - storage_key, - JSON.stringify({value: state[module_name][state_key]}) - ); -}); - -export default store; diff --git a/shopfloor_shopinvader_mobile_base/static/wms/src/utils_cart.js b/shopfloor_shopinvader_mobile_base/static/wms/src/utils_cart.js deleted file mode 100644 index 67ef03f1d80..00000000000 --- a/shopfloor_shopinvader_mobile_base/static/wms/src/utils_cart.js +++ /dev/null @@ -1,25 +0,0 @@ -import {utils_registry} from "/shopfloor_mobile_base/static/wms/src/services/utils_registry.js"; -import store from "./store/index.js"; - -export class CartUtils { - get_cart() { - const sessionStorage_key = this._get_storage_key(); - return JSON.parse(window.sessionStorage.getItem(sessionStorage_key)) - ? JSON.parse(window.sessionStorage.getItem(sessionStorage_key)).value - : undefined; - } - set_cart(payload) { - const sessionStorage_key = this._get_storage_key(); - window.sessionStorage.setItem(sessionStorage_key, payload); - } - remove_cart() { - const sessionStorage_key = this._get_storage_key(); - window.sessionStorage.removeItem(sessionStorage_key); - } - _get_storage_key() { - const cart_state_key = store.getters._get_cart_state_key; - return "shopfloor_" + cart_state_key; - } -} - -utils_registry.add("cart", new CartUtils());