浏览代码

Add some fix before events.

Cixo Develop 1 月之前
父节点
当前提交
b695b1d9ff

+ 2 - 1
application/assets/languages/english.json

@@ -68,5 +68,6 @@
     "creating-new-product": "Creating new product...",
     "created-new-product-success": "Product created successfully!",
     "close": "Close",
-    "search": "Search..."
+    "search": "Search...",
+    "barcode-category": "Barcode"
 }

+ 2 - 1
application/assets/languages/polish.json

@@ -68,5 +68,6 @@
     "creating-new-product": "Tworzenie nowego produktu...",
     "created-new-product-success": "Produkt utworzono pomyślnie!",
     "close": "Zamknij",
-    "search": "Wyszukaj..."
+    "search": "Wyszukaj...",
+    "barcode-category": "Kod kreskowy"
 }

+ 71 - 0
application/assets/languages/sample-phrasebook.json

@@ -0,0 +1,71 @@
+{
+    "do-you-want-to-remove-it": "",
+    "you-try-to-remove-__name__": "",
+    "product-give-back": "",
+    "processing": "",
+    "give-back-successfull": "",
+    "name-category": "",
+    "author-category": "",
+    "not-found-anything": "",
+    "browse-our-products": "",
+    "you-must-confirm-it": "",
+    "clear": "",
+    "send": "",
+    "product-editor": "",
+    "name-prompt": "",
+    "name-sample": "",
+    "description-prompt": "",
+    "description-sample": "",
+    "author-prompt": "",
+    "author-sample": "",
+    "barcode-prompt": "",
+    "barcode-sample": "",
+    "stock-count-prompt": "",
+    "stock-count-sample": "",
+    "change-product-image": "",
+    "updating-product-data": "",
+    "processing-image": "",
+    "uploaded-successfull": "",
+    "email-prompt": "",
+    "email-sample": "",
+    "phone-number-prompt": "",
+    "phone-number-sample": "",
+    "import-products-json": "",
+    "loading-file": "",
+    "parsing-file-to-dataset": "",
+    "skipping-import-product-__barcode__": "",
+    "searching-for-product-__barcode__": "",
+    "creating-product-__barcode__": "",
+    "can-not-add-product-__barcode__": "",
+    "skipping-product-__barcode": "",
+    "created-product-__barcode__": "",
+    "all-items-imported": "",
+    "not-all-items-imported": "",
+    "product-rent": "",
+    "new-rent-added": "",
+    "product-not-avairable": "",
+    "this-product-is-not-avairable-yet": "",
+    "all-rents": "",
+    "loading": "",
+    "user-must-be-logged-in": "",
+    "fail-when-request-__url__": "",
+    "bad-response-not-contain-result": "",
+    "login-window": "",
+    "logged-in": "",
+    "can-not-login-check-nick-and-password": "",
+    "nick-prompt": "",
+    "nick-sample": "",
+    "password-prompt": "",
+    "password-sample": "",
+    "incomplete-request-with-good-status": "",
+    "add-product": "",
+    "fill-barcode-first": "",
+    "searching-in-the-web": "",
+    "autocomplete-ready-check-results": "",
+    "autocomplete": "",
+    "image-prompt": "",
+    "load-any-image-first": "",
+    "creating-new-product": "",
+    "created-new-product-success": "",
+    "close": ""
+}

文件差异内容过多而无法显示
+ 0 - 3
application/cx-libtranslate.debug.js.map


文件差异内容过多而无法显示
+ 0 - 0
application/cx-libtranslate.min.js


文件差异内容过多而无法显示
+ 0 - 3
application/cx-libtranslate.min.js.map


+ 2 - 2
application/scripts/confirm_action.js

@@ -88,7 +88,7 @@ export class confirm_action {
         const cancel_button = document.createElement("button");
         cancel_button.classList.add("cancel");
         cancel_button.classList.add("material-icons");
-        cancel_button.innerText = _("clear");
+        cancel_button.innerText = "close";
         buttons.appendChild(cancel_button);
  
         cancel_button.addEventListener("click", () => {
@@ -99,7 +99,7 @@ export class confirm_action {
             const confirm_button = document.createElement("button");
             confirm_button.classList.add("confirm");
             confirm_button.classList.add("material-icons");
-            confirm_button.innerText = _("send");
+            confirm_button.innerText = "send";
             buttons.appendChild(confirm_button);
             
             confirm_button.addEventListener("click", () => {

+ 4 - 0
application/scripts/product_container.js

@@ -151,6 +151,10 @@ export class product_container {
     }
 
     get #cache_bypass() {
+        if (!this.#login) {
+            return "?cache=1";
+        }
+
         return "?cache=" + new String(Math.floor(Math.random() * 100));
     }
 

+ 25 - 3
application/scripts/products_loader.js

@@ -9,12 +9,27 @@ export class products_loader {
     }
 
     static #response_to_collection(response) {
-        const result = new Array();
-        
         if (response.result !== "success") {
-            return result;
+            return new Array();
         }
 
+        if ("collection" in response) {
+            return this.#list_response_to_collection(response);
+        }
+
+        return this.#single_response_to_collection(response);
+    }
+
+    static #single_response_to_collection(response) {
+        const result = new Array();
+        result.push(new product(response.product));
+        
+        return result;
+    }
+
+    static #list_response_to_collection(response) {
+        const result = new Array();
+        
         response.collection.forEach(serialized => {
             result.push(new product(serialized));
         });
@@ -36,6 +51,13 @@ export class products_loader {
         );
     }
 
+    static async search_barcode(barcode) {
+        return await products_loader.#search(
+            "/product/get/barcode",
+            barcode
+        );
+    }
+
     static async #search(path, parameter) {
         const coded = encodeURI(parameter);
         const request = await fetch(path + "/" + coded);

+ 4 - 2
application/scripts/searcher.js

@@ -45,7 +45,8 @@ export class searcher {
     get categories() {
         return {
             "name": _("name-category"),
-            "author": _("author-category")
+            "author": _("author-category"),
+            "barcode": _("barcode-category"),
         }
     }
 
@@ -65,7 +66,8 @@ export class searcher {
     get #loader() {
         return {
             "name": products_loader.search_name,
-            "author": products_loader.search_author
+            "author": products_loader.search_author,
+            "barcode": products_loader.search_barcode,
         }[this.category];
     }
 

+ 3 - 3
assets/autoadder.py

@@ -1,7 +1,7 @@
 import json
 import base64
 import requests
-import duckduckgo_search
+import ddgs
 import typing
 
 from .validator import barcode_validator
@@ -15,8 +15,8 @@ class autoadder:
         self.__engine = engine
         self.__gemini = gemini_search(apikey)
 
-    def __ddg(self) -> duckduckgo_search.DDGS:
-        return duckduckgo_search.DDGS()
+    def __ddg(self) -> ddgs.DDGS:
+        return ddgs.DDGS()
 
     def __search(self, phrase: str) -> str:
         for count in self.__ddg().text(phrase, max_results = 1):

+ 1 - 0
requirements.txt

@@ -7,3 +7,4 @@ beautifulsoup4
 requests
 google-genai
 duckduckgo-search
+ddgs

+ 2 - 1
static/assets/languages/english.json

@@ -68,5 +68,6 @@
     "creating-new-product": "Creating new product...",
     "created-new-product-success": "Product created successfully!",
     "close": "Close",
-    "search": "Search..."
+    "search": "Search...",
+    "barcode-category": "Barcode"
 }

+ 2 - 1
static/assets/languages/polish.json

@@ -68,5 +68,6 @@
     "creating-new-product": "Tworzenie nowego produktu...",
     "created-new-product-success": "Produkt utworzono pomyślnie!",
     "close": "Zamknij",
-    "search": "Wyszukaj..."
+    "search": "Wyszukaj...",
+    "barcode-category": "Kod kreskowy"
 }

+ 71 - 0
static/assets/languages/sample-phrasebook.json

@@ -0,0 +1,71 @@
+{
+    "do-you-want-to-remove-it": "",
+    "you-try-to-remove-__name__": "",
+    "product-give-back": "",
+    "processing": "",
+    "give-back-successfull": "",
+    "name-category": "",
+    "author-category": "",
+    "not-found-anything": "",
+    "browse-our-products": "",
+    "you-must-confirm-it": "",
+    "clear": "",
+    "send": "",
+    "product-editor": "",
+    "name-prompt": "",
+    "name-sample": "",
+    "description-prompt": "",
+    "description-sample": "",
+    "author-prompt": "",
+    "author-sample": "",
+    "barcode-prompt": "",
+    "barcode-sample": "",
+    "stock-count-prompt": "",
+    "stock-count-sample": "",
+    "change-product-image": "",
+    "updating-product-data": "",
+    "processing-image": "",
+    "uploaded-successfull": "",
+    "email-prompt": "",
+    "email-sample": "",
+    "phone-number-prompt": "",
+    "phone-number-sample": "",
+    "import-products-json": "",
+    "loading-file": "",
+    "parsing-file-to-dataset": "",
+    "skipping-import-product-__barcode__": "",
+    "searching-for-product-__barcode__": "",
+    "creating-product-__barcode__": "",
+    "can-not-add-product-__barcode__": "",
+    "skipping-product-__barcode": "",
+    "created-product-__barcode__": "",
+    "all-items-imported": "",
+    "not-all-items-imported": "",
+    "product-rent": "",
+    "new-rent-added": "",
+    "product-not-avairable": "",
+    "this-product-is-not-avairable-yet": "",
+    "all-rents": "",
+    "loading": "",
+    "user-must-be-logged-in": "",
+    "fail-when-request-__url__": "",
+    "bad-response-not-contain-result": "",
+    "login-window": "",
+    "logged-in": "",
+    "can-not-login-check-nick-and-password": "",
+    "nick-prompt": "",
+    "nick-sample": "",
+    "password-prompt": "",
+    "password-sample": "",
+    "incomplete-request-with-good-status": "",
+    "add-product": "",
+    "fill-barcode-first": "",
+    "searching-in-the-web": "",
+    "autocomplete-ready-check-results": "",
+    "autocomplete": "",
+    "image-prompt": "",
+    "load-any-image-first": "",
+    "creating-new-product": "",
+    "created-new-product-success": "",
+    "close": ""
+}

+ 188 - 105
static/bundle/app.js

@@ -1,4 +1,27 @@
 (() => {
+  var __accessCheck = (obj, member, msg) => {
+    if (!member.has(obj))
+      throw TypeError("Cannot " + msg);
+  };
+  var __privateGet = (obj, member, getter) => {
+    __accessCheck(obj, member, "read from private field");
+    return getter ? getter.call(obj) : member.get(obj);
+  };
+  var __privateAdd = (obj, member, value) => {
+    if (member.has(obj))
+      throw TypeError("Cannot add the same private member more than once");
+    member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
+  };
+  var __privateSet = (obj, member, value, setter) => {
+    __accessCheck(obj, member, "write to private field");
+    setter ? setter.call(obj, value) : member.set(obj, value);
+    return value;
+  };
+  var __privateMethod = (obj, member, method) => {
+    __accessCheck(obj, member, "access private method");
+    return method;
+  };
+
   // application/scripts/height_equaler.js
   var height_equaler = class {
     #to;
@@ -27,7 +50,7 @@
   };
 
   // application/scripts/product.js
-  var product = class _product {
+  var product = class {
     name;
     description;
     author;
@@ -45,14 +68,22 @@
       this.barcode = null;
       this.thumbnail = null;
       this.on_stock = null;
-      if ("name" in target) this.name = target["name"];
-      if ("description" in target) this.description = target["description"];
-      if ("author" in target) this.author = target["author"];
-      if ("image" in target) this.image = target["image"];
-      if ("stock_count" in target) this.stock_count = target["stock_count"];
-      if ("barcode" in target) this.barcode = target["barcode"];
-      if ("thumbnail" in target) this.thumbnail = target["thumbnail"];
-      if ("on_stock" in target) this.on_stock = target["on_stock"];
+      if ("name" in target)
+        this.name = target["name"];
+      if ("description" in target)
+        this.description = target["description"];
+      if ("author" in target)
+        this.author = target["author"];
+      if ("image" in target)
+        this.image = target["image"];
+      if ("stock_count" in target)
+        this.stock_count = target["stock_count"];
+      if ("barcode" in target)
+        this.barcode = target["barcode"];
+      if ("thumbnail" in target)
+        this.thumbnail = target["thumbnail"];
+      if ("on_stock" in target)
+        this.on_stock = target["on_stock"];
       try {
         this.stock_count = Number(this.stock_count);
       } catch {
@@ -80,53 +111,80 @@
       return dumped;
     }
     get ready() {
-      if (this.name === null || this.description === null) return false;
-      if (this.author === null || this.image === null) return false;
-      if (this.stock_count === null || this.barcode === null) return false;
-      if (this.thumbnail === null) return false;
+      if (this.name === null || this.description === null)
+        return false;
+      if (this.author === null || this.image === null)
+        return false;
+      if (this.stock_count === null || this.barcode === null)
+        return false;
+      if (this.thumbnail === null)
+        return false;
       return true;
     }
     copy() {
-      return new _product(this.dump);
+      return new product(this.dump);
     }
   };
 
   // application/scripts/products_loader.js
-  var products_loader = class _products_loader {
+  var _response_to_collection, response_to_collection_fn, _single_response_to_collection, single_response_to_collection_fn, _list_response_to_collection, list_response_to_collection_fn, _search, search_fn;
+  var _products_loader = class {
     static async all() {
+      var _a;
       const request2 = await fetch("/products/");
       const response = await request2.json();
-      return _products_loader.#response_to_collection(response);
-    }
-    static #response_to_collection(response) {
-      const result = new Array();
-      if (response.result !== "success") {
-        return result;
-      }
-      response.collection.forEach((serialized) => {
-        result.push(new product(serialized));
-      });
-      return result;
+      return __privateMethod(_a = _products_loader, _response_to_collection, response_to_collection_fn).call(_a, response);
     }
     static async search_name(name) {
-      return await _products_loader.#search(
-        "/product/search/name",
-        name
-      );
+      var _a;
+      return await __privateMethod(_a = _products_loader, _search, search_fn).call(_a, "/product/search/name", name);
     }
     static async search_author(author) {
-      return await _products_loader.#search(
-        "/product/search/author",
-        author
-      );
+      var _a;
+      return await __privateMethod(_a = _products_loader, _search, search_fn).call(_a, "/product/search/author", author);
     }
-    static async #search(path, parameter) {
-      const coded = encodeURI(parameter);
-      const request2 = await fetch(path + "/" + coded);
-      const response = await request2.json();
-      return _products_loader.#response_to_collection(response);
+    static async search_barcode(barcode) {
+      var _a;
+      return await __privateMethod(_a = _products_loader, _search, search_fn).call(_a, "/product/get/barcode", barcode);
+    }
+  };
+  var products_loader = _products_loader;
+  _response_to_collection = new WeakSet();
+  response_to_collection_fn = function(response) {
+    if (response.result !== "success") {
+      return new Array();
     }
+    if ("collection" in response) {
+      return __privateMethod(this, _list_response_to_collection, list_response_to_collection_fn).call(this, response);
+    }
+    return __privateMethod(this, _single_response_to_collection, single_response_to_collection_fn).call(this, response);
+  };
+  _single_response_to_collection = new WeakSet();
+  single_response_to_collection_fn = function(response) {
+    const result = new Array();
+    result.push(new product(response.product));
+    return result;
+  };
+  _list_response_to_collection = new WeakSet();
+  list_response_to_collection_fn = function(response) {
+    const result = new Array();
+    response.collection.forEach((serialized) => {
+      result.push(new product(serialized));
+    });
+    return result;
+  };
+  _search = new WeakSet();
+  search_fn = async function(path, parameter) {
+    var _a;
+    const coded = encodeURI(parameter);
+    const request2 = await fetch(path + "/" + coded);
+    const response = await request2.json();
+    return __privateMethod(_a = _products_loader, _response_to_collection, response_to_collection_fn).call(_a, response);
   };
+  __privateAdd(products_loader, _response_to_collection);
+  __privateAdd(products_loader, _single_response_to_collection);
+  __privateAdd(products_loader, _list_response_to_collection);
+  __privateAdd(products_loader, _search);
 
   // application/scripts/fullscreen.js
   var fullscreen = class {
@@ -396,7 +454,7 @@
       const cancel_button = document.createElement("button");
       cancel_button.classList.add("cancel");
       cancel_button.classList.add("material-icons");
-      cancel_button.innerText = _("clear");
+      cancel_button.innerText = "close";
       buttons.appendChild(cancel_button);
       cancel_button.addEventListener("click", () => {
         this.hide();
@@ -405,7 +463,7 @@
         const confirm_button = document.createElement("button");
         confirm_button.classList.add("confirm");
         confirm_button.classList.add("material-icons");
-        confirm_button.innerText = _("send");
+        confirm_button.innerText = "send";
         buttons.appendChild(confirm_button);
         confirm_button.addEventListener("click", () => {
           if (this.#action === false) {
@@ -580,91 +638,111 @@
   };
 
   // application/scripts/searcher.js
-  var searcher = class _searcher {
-    #input;
-    #category;
-    #manager;
-    #result;
-    static #instances;
-    static #add(instance) {
-      if (typeof _searcher.#instances !== "object") {
-        _searcher.#instances = new Array();
-      }
-      _searcher.#instances.push(instance);
+  var _input, _category, _manager, _result, _instances, _add, add_fn, _selector_complete, selector_complete_fn, _loader, loader_get, _result_title, result_title_get, result_title_set, _insert, insert_fn;
+  var _searcher = class {
+    constructor(search_form, manager, result) {
+      __privateAdd(this, _selector_complete);
+      __privateAdd(this, _loader);
+      __privateAdd(this, _result_title);
+      __privateAdd(this, _insert);
+      __privateAdd(this, _input, void 0);
+      __privateAdd(this, _category, void 0);
+      __privateAdd(this, _manager, void 0);
+      __privateAdd(this, _result, void 0);
+      var _a;
+      __privateSet(this, _input, search_form.querySelector('input[type="text"]'));
+      __privateSet(this, _category, search_form.querySelector("select"));
+      __privateSet(this, _manager, manager);
+      __privateSet(this, _result, result);
+      __privateMethod(this, _selector_complete, selector_complete_fn).call(this);
+      search_form.addEventListener("submit", (target) => {
+        target.preventDefault();
+        this.update();
+      });
+      __privateMethod(_a = _searcher, _add, add_fn).call(_a, this);
     }
     static reload() {
-      if (typeof _searcher.#instances !== "object") {
+      if (typeof __privateGet(_searcher, _instances) !== "object") {
         return;
       }
-      _searcher.#instances.forEach((instance) => {
+      __privateGet(_searcher, _instances).forEach((instance) => {
         instance.update();
       });
     }
-    constructor(search_form, manager, result) {
-      this.#input = search_form.querySelector('input[type="text"]');
-      this.#category = search_form.querySelector("select");
-      this.#manager = manager;
-      this.#result = result;
-      this.#selector_complete();
-      search_form.addEventListener("submit", (target) => {
-        target.preventDefault();
-        this.update();
-      });
-      _searcher.#add(this);
-    }
     get categories() {
       return {
         "name": _("name-category"),
-        "author": _("author-category")
+        "author": _("author-category"),
+        "barcode": _("barcode-category")
       };
     }
-    #selector_complete() {
-      const category = this.#category;
-      const categories = this.categories;
-      Object.keys(categories).forEach((name) => {
-        const option = document.createElement("option");
-        option.value = name;
-        option.innerText = categories[name];
-        category.appendChild(option);
-      });
-    }
-    get #loader() {
-      return {
-        "name": products_loader.search_name,
-        "author": products_loader.search_author
-      }[this.category];
-    }
     get category() {
-      return this.#category.value;
+      return __privateGet(this, _category).value;
     }
     get phrase() {
-      return this.#input.value.trim();
-    }
-    get #result_title() {
-      return this.#result.innerText;
-    }
-    set #result_title(target) {
-      this.#result.innerText = target;
+      return __privateGet(this, _input).value.trim();
     }
     async update() {
       if (this.phrase.length === 0) {
         this.show_all();
         return;
       }
-      this.#insert(await this.#loader(this.phrase));
-    }
-    #insert(list) {
-      if (list.length === 0) {
-        this.#result_title = _("not-found-anything");
-      } else {
-        this.#result_title = _("browse-our-products");
-      }
-      this.#manager.clean().add_list(list).update();
+      __privateMethod(this, _insert, insert_fn).call(this, await __privateGet(this, _loader, loader_get).call(this, this.phrase));
     }
     async show_all() {
-      this.#insert(await products_loader.all());
+      __privateMethod(this, _insert, insert_fn).call(this, await products_loader.all());
     }
   };
+  var searcher = _searcher;
+  _input = new WeakMap();
+  _category = new WeakMap();
+  _manager = new WeakMap();
+  _result = new WeakMap();
+  _instances = new WeakMap();
+  _add = new WeakSet();
+  add_fn = function(instance) {
+    if (typeof __privateGet(_searcher, _instances) !== "object") {
+      __privateSet(_searcher, _instances, new Array());
+    }
+    __privateGet(_searcher, _instances).push(instance);
+  };
+  _selector_complete = new WeakSet();
+  selector_complete_fn = function() {
+    const category = __privateGet(this, _category);
+    const categories = this.categories;
+    Object.keys(categories).forEach((name) => {
+      const option = document.createElement("option");
+      option.value = name;
+      option.innerText = categories[name];
+      category.appendChild(option);
+    });
+  };
+  _loader = new WeakSet();
+  loader_get = function() {
+    return {
+      "name": products_loader.search_name,
+      "author": products_loader.search_author,
+      "barcode": products_loader.search_barcode
+    }[this.category];
+  };
+  _result_title = new WeakSet();
+  result_title_get = function() {
+    return __privateGet(this, _result).innerText;
+  };
+  result_title_set = function(target) {
+    __privateGet(this, _result).innerText = target;
+  };
+  _insert = new WeakSet();
+  insert_fn = function(list) {
+    if (list.length === 0) {
+      __privateSet(this, _result_title, _("not-found-anything"), result_title_set);
+    } else {
+      __privateSet(this, _result_title, _("browse-our-products"), result_title_set);
+    }
+    __privateGet(this, _manager).clean().add_list(list).update();
+  };
+  __privateAdd(searcher, _add);
+  __privateAdd(searcher, _instances, void 0);
 
   // application/scripts/delete_product_window.js
   var delete_product_window = class extends confirm_action {
@@ -1128,7 +1206,7 @@
   };
 
   // application/scripts/reservation.js
-  var reservation = class _reservation {
+  var reservation = class {
     email;
     phone_number;
     product_barcode;
@@ -1162,12 +1240,14 @@
       return dumped;
     }
     get ready() {
-      if (this.product_barcode === null) return false;
-      if (this.email === null && this.phone_number === null) return false;
+      if (this.product_barcode === null)
+        return false;
+      if (this.email === null && this.phone_number === null)
+        return false;
       return true;
     }
     copy() {
-      return new _reservation(this.dump);
+      return new reservation(this.dump);
     }
   };
 
@@ -1565,6 +1645,9 @@
       return container;
     }
     get #cache_bypass() {
+      if (!this.#login) {
+        return "?cache=1";
+      }
       return "?cache=" + new String(Math.floor(Math.random() * 100));
     }
     get #image() {

部分文件因为文件数量过多而无法显示