@@ -60,30 +40,23 @@ import OrganizationsIcon from '@/components/Icons/OrganizationsIcon.vue'
import LayoutHeader from '@/components/LayoutHeader.vue'
import OrganizationModal from '@/components/Modals/OrganizationModal.vue'
import OrganizationsListView from '@/components/ListViews/OrganizationsListView.vue'
-import SortBy from '@/components/SortBy.vue'
-import Filter from '@/components/Filter.vue'
-import ViewSettings from '@/components/ViewSettings.vue'
-import { useOrderBy } from '@/composables/orderby'
-import { useFilter } from '@/composables/filter'
-import { useDebounceFn } from '@vueuse/core'
-import { FeatherIcon, Breadcrumbs, Dropdown, createResource } from 'frappe-ui'
+import ViewControls from '@/components/ViewControls.vue'
+import { FeatherIcon, Breadcrumbs } from 'frappe-ui'
import {
dateFormat,
dateTooltipFormat,
timeAgo,
formatNumberIntoCurrency,
} from '@/utils'
-import { ref, computed, watch } from 'vue'
+import { ref, computed } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
-const { get: getOrderBy } = useOrderBy()
-const { getArgs, storage } = useFilter()
const showOrganizationModal = ref(false)
const currentOrganization = computed(() => {
- return organizations.data?.data?.find(
+ return organizations.value?.data?.data?.find(
(organization) => organization.name === route.params.organizationId
)
})
@@ -101,53 +74,13 @@ const breadcrumbs = computed(() => {
return items
})
-const currentView = ref({
- label: 'List',
- icon: 'list',
-})
-
-function getParams() {
- const filters = getArgs() || {}
- const order_by = getOrderBy() || 'modified desc'
-
- return {
- doctype: 'CRM Organization',
- filters: filters,
- order_by: order_by,
- }
-}
-
-const organizations = createResource({
- url: 'crm.api.doc.get_list_data',
- params: getParams(),
- auto: true,
-})
-
-watch(
- () => getOrderBy(),
- (value, old_value) => {
- if (!value && !old_value) return
- organizations.params = getParams()
- organizations.reload()
- },
- { immediate: true }
-)
-
-watch(
- storage,
- useDebounceFn((value, old_value) => {
- if (JSON.stringify([...value]) === JSON.stringify([...old_value])) return
- organizations.params = getParams()
- organizations.reload()
- }, 300),
- { deep: true }
-)
+const organizations = ref({})
const rows = computed(() => {
- if (!organizations.data?.data) return []
- return organizations.data.data.map((organization) => {
+ if (!organizations.value?.data?.data) return []
+ return organizations.value?.data.data.map((organization) => {
let _rows = {}
- organizations.data.rows.forEach((row) => {
+ organizations.value?.data.rows.forEach((row) => {
_rows[row] = organization[row]
if (row === 'organization_name') {
@@ -170,49 +103,6 @@ const rows = computed(() => {
})
})
-const viewsDropdownOptions = [
- {
- label: 'List',
- icon: 'list',
- onClick() {
- currentView.value = {
- label: 'List',
- icon: 'list',
- }
- },
- },
- {
- label: 'Table',
- icon: 'grid',
- onClick() {
- currentView.value = {
- label: 'Table',
- icon: 'grid',
- }
- },
- },
- {
- label: 'Calender',
- icon: 'calendar',
- onClick() {
- currentView.value = {
- label: 'Calender',
- icon: 'calendar',
- }
- },
- },
- {
- label: 'Board',
- icon: 'columns',
- onClick() {
- currentView.value = {
- label: 'Board',
- icon: 'columns',
- }
- },
- },
-]
-
function website(url) {
return url && url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, '')
}
diff --git a/frontend/src/stores/views.js b/frontend/src/stores/views.js
new file mode 100644
index 00000000..64039643
--- /dev/null
+++ b/frontend/src/stores/views.js
@@ -0,0 +1,34 @@
+import { defineStore } from 'pinia'
+import { createListResource } from 'frappe-ui'
+import { reactive } from 'vue'
+
+export const viewsStore = defineStore('crm-views', () => {
+ let viewsByName = reactive({})
+
+ const views = createListResource({
+ doctype: 'CRM View Settings',
+ fields: ['*'],
+ cache: 'crm-views',
+ initialData: [],
+ auto: true,
+ transform(views) {
+ for (let view of views) {
+ viewsByName[view.name] = view
+ }
+ return views
+ },
+ })
+
+ function getView(view) {
+ if (!view) return null
+ if (!viewsByName[view]) {
+ views.reload()
+ }
+ return viewsByName[view]
+ }
+
+ return {
+ views,
+ getView,
+ }
+})