Advertisement
SherinKR

pwCategory.ts

Sep 25th, 2024
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 1.50 KB | Source Code | 0 0
  1. import { computed } from "vue";
  2. import { defineStore } from "pinia";
  3. import { createListResource } from "frappe-ui";
  4.  
  5. export let usePwCategoryStore = defineStore("pw_category", () => {
  6.     console.log("usePwCategoryStore called");
  7.     let filters = {}
  8.     let pw_category = localStorage.getItem("pw_category") || 0;
  9.     if (pw_category) {
  10.         filters = { 'pw_category': pw_category }
  11.     }
  12.     let pw_categories = createListResource({
  13.         doctype: "PW Category",
  14.         fields: ["*"],
  15.         auto: true,
  16.         pageLength: 99999,
  17.     });
  18.  
  19.     let dropdown = computed(() =>
  20.         pw_categories.data?.map((o) => ({
  21.             label: o.pw_category,
  22.             value: o.name,
  23.         }))
  24.     );
  25.  
  26.     return {
  27.         dropdown,
  28.         pw_categories,
  29.     };
  30. });
  31.  
  32. export let usePwSubCategoryStore = defineStore("pw_sub_category", () => {
  33.     console.log("usePwSubCategoryStore called");
  34.     let filters = {}
  35.     let pw_category = localStorage.getItem("pw_category") || 0;
  36.     if (pw_category) {
  37.         filters = { 'pw_category': pw_category }
  38.     }
  39.     let pw_sub_categories = createListResource({
  40.         doctype: "PW Sub Category",
  41.         fields: ["*"],
  42.         filters: filters,
  43.         auto: true,
  44.         pageLength: 99999,
  45.     });
  46.  
  47.     let dropdown = computed(() =>
  48.         pw_sub_categories.data?.map((o) => ({
  49.             label: o.pw_sub_category,
  50.             value: o.name,
  51.         }))
  52.     );
  53.  
  54.     return {
  55.         dropdown,
  56.         pw_sub_categories,
  57.     };
  58. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement