|
37 | 37 | </template> |
38 | 38 | <template #[`item.created`]="{ item }"> |
39 | 39 | <div class="font-weight-bold"> |
40 | | - {{ formatDate(item.created,'MMMM DD, YYYY') }} |
| 40 | + {{ formatDate(moment.utc(item.created).toDate(), 'MMMM DD, YYYY h:mm A') }} |
41 | 41 | </div> |
42 | 42 | </template> |
43 | 43 | </v-data-table> |
|
46 | 46 | </template> |
47 | 47 |
|
48 | 48 | <script lang="ts"> |
49 | | -import { Action, State } from 'pinia-class' |
50 | 49 | import { ActivityLog, ActivityLogFilterParams } from '@/models/activityLog' |
51 | | -import { Component, Mixins, Prop, Watch } from 'vue-property-decorator' |
52 | | -import { Member, Organization } from '@/models/Organization' |
53 | | -import AccountChangeMixin from '@/components/auth/mixins/AccountChangeMixin.vue' |
| 50 | +import { PropType, computed, defineComponent, onBeforeUnmount, onMounted, reactive, toRefs, watch } from '@vue/composition-api' |
54 | 51 | import CommonUtils from '@/util/common-util' |
| 52 | +import moment from 'moment' |
55 | 53 | import { useActivityStore } from '@/stores/activityLog' |
56 | 54 | import { useOrgStore } from '@/stores/org' |
57 | 55 |
|
58 | | -@Component({}) |
59 | | -export default class ActivityLogs extends Mixins(AccountChangeMixin) { |
60 | | - @Prop({ default: '' }) private orgId: number |
61 | | - @State(useOrgStore) public currentOrganization!: Organization |
62 | | - @State(useOrgStore) public currentMembership!: Member |
63 | | - @State(useActivityStore) public currentOrgActivity!: ActivityLog |
64 | | - @Action(useActivityStore) public getActivityLog!:(filterParams:ActivityLogFilterParams) =>Promise<ActivityLog> |
65 | | -
|
66 | | - private readonly ITEMS_PER_PAGE = 5 |
67 | | - private readonly PAGINATION_COUNTER_STEP = 4 |
68 | | - public formatDate = CommonUtils.formatDisplayDate |
69 | | - public totalActivityCount: number = 0 |
70 | | - public tableDataOptions: any = {} |
71 | | - public isDataLoading: boolean = false |
72 | | - public activityList: ActivityLog[] = [] |
73 | | - public isLoading: boolean = false |
74 | | -
|
75 | | - public readonly activityHeader = [ |
76 | | - { |
77 | | - text: 'Date', |
78 | | - align: 'left', |
79 | | - sortable: false, |
80 | | - value: 'created', |
81 | | - class: 'bold-header' |
82 | | - }, |
83 | | -
|
84 | | - { |
85 | | - text: 'Initiated by', |
86 | | - align: 'left', |
87 | | - sortable: false, |
88 | | - value: 'actor', |
89 | | - class: 'bold-header' |
90 | | - }, |
91 | | - { |
92 | | - text: 'Subject', |
93 | | - align: 'left', |
94 | | - sortable: false, |
95 | | - value: 'action', |
96 | | - class: 'bold-header' |
| 56 | +export default defineComponent({ |
| 57 | + name: 'ActivityLogs', |
| 58 | + props: { |
| 59 | + orgId: { |
| 60 | + type: Number as PropType<number>, |
| 61 | + default: 0 |
97 | 62 | } |
98 | | - ] |
| 63 | + }, |
| 64 | + setup () { |
| 65 | + const activityStore = useActivityStore() |
| 66 | + const orgStore = useOrgStore() |
99 | 67 |
|
100 | | - public get getPaginationOptions () { |
101 | | - return [...Array(this.PAGINATION_COUNTER_STEP)].map((value, index) => this.ITEMS_PER_PAGE * (index + 1)) |
102 | | - } |
| 68 | + const ITEMS_PER_PAGE = 5 |
| 69 | + const PAGINATION_COUNTER_STEP = 4 |
103 | 70 |
|
104 | | - public async mounted () { |
105 | | - this.setAccountChangedHandler(this.initialize) |
106 | | - this.initialize() |
107 | | - } |
| 71 | + const state = reactive({ |
| 72 | + totalActivityCount: 0, |
| 73 | + tableDataOptions: {}, |
| 74 | + isDataLoading: false, |
| 75 | + activityList: [] as ActivityLog[], |
| 76 | + isLoading: false, |
| 77 | + activityHeader: [ |
| 78 | + { |
| 79 | + text: 'Date (Pacific Time)', |
| 80 | + align: 'left', |
| 81 | + sortable: false, |
| 82 | + value: 'created', |
| 83 | + class: 'bold-header' |
| 84 | + }, |
| 85 | + { |
| 86 | + text: 'Initiated by', |
| 87 | + align: 'left', |
| 88 | + sortable: false, |
| 89 | + value: 'actor', |
| 90 | + class: 'bold-header' |
| 91 | + }, |
| 92 | + { |
| 93 | + text: 'Subject', |
| 94 | + align: 'left', |
| 95 | + sortable: false, |
| 96 | + value: 'action', |
| 97 | + class: 'bold-header' |
| 98 | + } |
| 99 | + ] |
| 100 | + }) |
108 | 101 |
|
109 | | - public async initialize () { |
110 | | - await this.loadActivityList() |
111 | | - } |
| 102 | + const currentOrganization = computed(() => orgStore.currentOrganization) |
| 103 | + const currentMembership = computed(() => orgStore.currentMembership) |
| 104 | + const currentOrgActivity = computed(() => activityStore.currentOrgActivity) |
112 | 105 |
|
113 | | - @Watch('tableDataOptions', { deep: true }) |
114 | | - async getActivityLogs (val) { |
115 | | - const pageNumber = val?.page || 1 |
116 | | - const itemsPerPage = val?.itemsPerPage |
117 | | - await this.loadActivityList(pageNumber, itemsPerPage) |
118 | | - } |
| 106 | + const getPaginationOptions = computed(() => { |
| 107 | + return [...Array(PAGINATION_COUNTER_STEP)].map((value, index) => ITEMS_PER_PAGE * (index + 1)) |
| 108 | + }) |
| 109 | +
|
| 110 | + const loadActivityList = async (pageNumber?: number, itemsPerPage?: number) => { |
| 111 | + state.isDataLoading = true |
| 112 | + const filterParams: ActivityLogFilterParams = { |
| 113 | + pageNumber: pageNumber, |
| 114 | + pageLimit: itemsPerPage, |
| 115 | + orgId: currentOrganization.value.id |
| 116 | + } |
| 117 | + try { |
| 118 | + const resp: any = await activityStore.getActivityLog(filterParams) |
| 119 | + state.activityList = resp?.activityLogs || [] |
| 120 | + state.totalActivityCount = resp?.total || 0 |
| 121 | + state.isDataLoading = false |
| 122 | + } catch { |
| 123 | + state.activityList = [] |
| 124 | + state.totalActivityCount = 0 |
| 125 | + state.isDataLoading = false |
| 126 | + } |
| 127 | + } |
| 128 | +
|
| 129 | + const initialize = async () => { |
| 130 | + await loadActivityList() |
| 131 | + } |
| 132 | +
|
| 133 | + let unregisterHandler: (() => void) | null = null |
119 | 134 |
|
120 | | - public async loadActivityList (pageNumber?: number, itemsPerPage?: number) { |
121 | | - this.isDataLoading = true |
122 | | - const filterParams: ActivityLogFilterParams = { |
123 | | - pageNumber: pageNumber, |
124 | | - pageLimit: itemsPerPage, |
125 | | - orgId: this.currentOrganization.id |
| 135 | + const setAccountChangedHandler = (handler: () => any) => { |
| 136 | + unregisterHandler = orgStore.$onAction(({ name, after }) => { |
| 137 | + after(() => { |
| 138 | + if (['syncOrganization', 'setCurrentOrganization'].includes(name)) { |
| 139 | + handler() |
| 140 | + } |
| 141 | + }) |
| 142 | + }) |
126 | 143 | } |
127 | | - try { |
128 | | - const resp:any = await this.getActivityLog(filterParams) |
129 | | - this.activityList = resp?.activityLogs || [] |
130 | | - this.totalActivityCount = resp?.total || 0 |
131 | | - this.isDataLoading = false |
132 | | - } catch { |
133 | | - this.activityList = [] |
134 | | - this.totalActivityCount = 0 |
135 | | - this.isDataLoading = false |
| 144 | +
|
| 145 | + watch(() => state.tableDataOptions, async (val: any) => { |
| 146 | + const pageNumber = val?.page || 1 |
| 147 | + const itemsPerPage = val?.itemsPerPage |
| 148 | + await loadActivityList(pageNumber, itemsPerPage) |
| 149 | + }, { deep: true }) |
| 150 | +
|
| 151 | + onMounted(async () => { |
| 152 | + setAccountChangedHandler(initialize) |
| 153 | + await initialize() |
| 154 | + }) |
| 155 | +
|
| 156 | + onBeforeUnmount(() => { |
| 157 | + if (unregisterHandler) { |
| 158 | + unregisterHandler() |
| 159 | + } |
| 160 | + }) |
| 161 | +
|
| 162 | + return { |
| 163 | + ...toRefs(state), |
| 164 | + currentOrganization, |
| 165 | + currentMembership, |
| 166 | + currentOrgActivity, |
| 167 | + getPaginationOptions, |
| 168 | + formatDate: CommonUtils.formatDisplayDate, |
| 169 | + loadActivityList, |
| 170 | + initialize, |
| 171 | + moment |
136 | 172 | } |
137 | 173 | } |
138 | | -} |
| 174 | +}) |
139 | 175 | </script> |
140 | 176 |
|
141 | 177 | <style lang="scss" scoped> |
|
0 commit comments