33 v-model:page =" page"
44 v-model:itemsPerPage =" itemsPerPage"
55 :headers =" headers"
6- :items =" items "
6+ :items =" webEndpoints "
77 :totalCount =" totalCount"
88 :loading =" loading"
99 :itemsPerPageOptions =" [10, 20, 50]"
1212 >
1313 <template #rows >
1414 <tr
15- v-for =" endpoint in items "
15+ v-for =" endpoint in webEndpoints "
1616 :key =" endpoint.address"
1717 :class =" isExpired(endpoint.expires_in) ? 'text-warning' : ''"
1818 >
3333
3434 <td data-test =" web-endpoint-url" >
3535 <a
36- :href =" `${urlProtocol }//${endpoint.full_address}`"
36+ :href =" `${protocol }//${endpoint.full_address}`"
3737 target =" _blank"
3838 rel =" noopener noreferrer"
3939 @click =" handleClick"
4040 >
41- {{ `${urlProtocol }//${endpoint.full_address}` }}
41+ {{ `${protocol }//${endpoint.full_address}` }}
4242 </a >
4343 </td >
4444
6161import { ref , watch , computed , onMounted } from " vue" ;
6262import moment from " moment" ;
6363import { useRouter } from " vue-router" ;
64- import { useStore } from " @/store" ;
6564import DataTable from " @/components/DataTable.vue" ;
6665import WebEndpointDelete from " @/components/WebEndpoints/WebEndpointDelete.vue" ;
6766import DeviceIcon from " @/components/Devices/DeviceIcon.vue" ;
68- import { IWebEndpoints } from " @/interfaces/IWebEndpoints" ;
67+ import { IWebEndpoint } from " @/interfaces/IWebEndpoints" ;
68+ import useWebEndpointsStore from " @/store/modules/web_endpoints" ;
69+ import handleError from " @/utils/handleError" ;
6970
7071type SortField = " created_at" | " updated_at" | " address" | " uid" ;
7172
72- const store = useStore ();
73+ const webEndpointsStore = useWebEndpointsStore ();
7374const router = useRouter ();
7475
75- const items = computed <IWebEndpoints []>(() => store . getters [ " webEndpoints/listWebEndpoints " ] );
76- const totalCount = computed (() => store . getters [ " webEndpoints/getTotalCount " ] );
76+ const webEndpoints = computed <IWebEndpoint []>(() => webEndpointsStore . webEndpoints );
77+ const totalCount = computed (() => webEndpointsStore . webEndpointCount );
7778
78- const page = ref (store . getters [ " webEndpoints/getPage " ] );
79- const itemsPerPage = ref (store . getters [ " webEndpoints/getPerPage " ] );
79+ const page = ref (1 );
80+ const itemsPerPage = ref (10 );
8081const loading = ref (false );
81-
82- const sortBy = ref <SortField >( store . getters [ " webEndpoints/getSortBy " ] );
83- const sortDesc = ref < boolean >( store . getters [ " webEndpoints/getOrderBy " ] === " desc " ) ;
82+ const sortField = ref < SortField >();
83+ const sortOrder = ref <" asc " | " desc " >( );
84+ const { protocol } = window . location ;
8485
8586const headers = [
8687 { text: " Device" , value: " device" , sortable: false },
@@ -94,50 +95,35 @@ const headers = [
9495const fetchWebEndpoints = async () => {
9596 loading .value = true ;
9697 try {
97- await store .dispatch (" webEndpoints/get" , {
98- page: page .value ,
99- perPage: itemsPerPage .value ,
100- filter: store .getters [" webEndpoints/getFilter" ],
101- sortBy: sortBy .value ,
102- orderBy: sortDesc .value ? " desc" : " asc" ,
103- });
104-
105- store .commit (" webEndpoints/setPagePerPage" , {
98+ await webEndpointsStore .fetchWebEndpointsList ({
10699 page: page .value ,
107100 perPage: itemsPerPage .value ,
108- filter: store .getters [" webEndpoints/getFilter" ],
109- sortBy: sortBy .value ,
110- orderBy: sortDesc .value ? " desc" : " asc" ,
101+ sortField: sortField .value ,
102+ sortOrder: sortOrder .value ,
111103 });
112- } finally {
113- loading . value = false ;
104+ } catch ( error ) {
105+ handleError ( error ) ;
114106 }
115- };
116107
117- const sortByItem = (field : string ) => {
118- const validFields: SortField [] = [" created_at" , " updated_at" , " address" , " uid" ];
119- if (! validFields .includes (field as SortField )) return ;
108+ loading .value = false ;
109+ };
120110
121- if (sortBy .value === field ) {
122- sortDesc .value = ! sortDesc .value ;
123- } else {
124- sortBy .value = field as SortField ;
125- sortDesc .value = false ;
126- }
111+ const getSortOrder = () => sortOrder .value === " asc" ? " desc" : " asc" ;
127112
128- fetchWebEndpoints ();
113+ const sortByItem = async (field : SortField ) => {
114+ sortField .value = field ;
115+ sortOrder .value = getSortOrder ();
116+ await fetchWebEndpoints ();
129117};
130118
131- watch ([page , itemsPerPage ], () => {
132- fetchWebEndpoints ();
119+ watch ([page , itemsPerPage ], async () => {
120+ await fetchWebEndpoints ();
133121});
134122
135- const refresh = () => {
136- fetchWebEndpoints ();
123+ const refresh = async () => {
124+ await fetchWebEndpoints ();
137125};
138126
139- const urlProtocol = ref (window .location .protocol );
140-
141127const isExpired = (date : string ) => date !== " 0001-01-01T00:00:00Z" && moment ().utc ().isAfter (moment (date ));
142128
143129const formatDate = (expiresIn : string ) => {
0 commit comments