11import { nextTick , onMounted , ref , resolveComponent } from 'vue' ;
2- import type { CoreConfig } from './spa_types/core' ;
3- import type { ValidationObject } from './types/Common.js' ;
4- import router from "./router" ;
5- import { useCoreStore } from './stores/core' ;
6- import { useUserStore } from './stores/user' ;
2+ import type { CoreConfig } from '.. /spa_types/core' ;
3+ import type { ValidationObject } from '.. /types/Common.js' ;
4+ import router from ".. /router" ;
5+ import { useCoreStore } from '.. /stores/core' ;
6+ import { useUserStore } from '.. /stores/user' ;
77import { Dropdown } from 'flowbite' ;
8- import adminforth from './adminforth' ;
8+ import adminforth from '.. /adminforth' ;
99import sanitizeHtml from 'sanitize-html'
1010import debounce from 'debounce' ;
1111import type { AdminForthResourceColumnInputCommon , Predicate } from '@/types/Common' ;
12- import { i18nInstance } from './i18n'
12+ import { i18nInstance } from '.. /i18n'
1313
14- import { type AdminForthResourceCommon } from './types/Common' ;
15- import { useAdminforth } from '@/adminforth' ;
16- import { showErrorTost } from '@/composables/useFrontendApi'
1714
1815
1916const LS_LANG_KEY = `afLanguage` ;
@@ -117,7 +114,7 @@ export const loadFile = (file: string) => {
117114 baseUrl = new URL ( `./${ path } ` , import . meta. url ) . href ;
118115 } else if ( file . startsWith ( '@@/' ) ) {
119116 path = file . replace ( '@@/' , '' ) ;
120- baseUrl = new URL ( `./custom/${ path } ` , import . meta. url ) . href ;
117+ baseUrl = new URL ( `.. /custom/${ path } ` , import . meta. url ) . href ;
121118 } else {
122119 baseUrl = new URL ( `./${ file } ` , import . meta. url ) . href ;
123120 }
@@ -519,88 +516,3 @@ export function btoa_function(source: string): string {
519516export function atob_function ( source : string ) : string {
520517 return atob ( source ) ;
521518}
522-
523-
524- export async function getList ( resource : AdminForthResourceCommon , isPageLoaded : boolean , page : number | null , pageSize : number , sort : any , checkboxes :{ value : any [ ] } , filters : any = [ ] ) {
525- let rows : any [ ] = [ ] ;
526- let totalRows : number | null = null ;
527- if ( ! isPageLoaded ) {
528- return ;
529- }
530- const data = await callAdminForthApi ( {
531- path : '/get_resource_data' ,
532- method : 'POST' ,
533- body : {
534- source : 'list' ,
535- resourceId : resource . resourceId ,
536- limit : pageSize ,
537- offset : ( ( page || 1 ) - 1 ) * pageSize ,
538- filters : filters ,
539- sort : sort ,
540- }
541- } ) ;
542- if ( data . error ) {
543- showErrorTost ( data . error ) ;
544- rows = [ ] ;
545- totalRows = 0 ;
546- return { rows, totalRows, error : data . error } ;
547- }
548- rows = data . data ?. map ( ( row : any ) => {
549- if ( resource ?. columns ?. find ( c => c . primaryKey ) ?. foreignResource ) {
550- row . _primaryKeyValue = row [ resource . columns . find ( c => c . primaryKey ) ! . name ] . pk ;
551- } else if ( resource ) {
552- row . _primaryKeyValue = row [ resource . columns . find ( c => c . primaryKey ) ! . name ] ;
553- }
554- return row ;
555- } ) ;
556- totalRows = data . total ;
557-
558- // if checkboxes have items which are not in current data, remove them
559- checkboxes . value = checkboxes . value . filter ( ( pk : any ) => rows . some ( ( r : any ) => r . _primaryKeyValue === pk ) ) ;
560- await nextTick ( ) ;
561- return { rows, totalRows } ;
562- }
563-
564-
565-
566- export async function startBulkAction ( actionId : string , resource : AdminForthResourceCommon , checkboxes : { value : any [ ] } ,
567- bulkActionLoadingStates : { value : Record < string , boolean > } , getListInner : ( ) => Promise < any > ) {
568- const action = resource ?. options ?. bulkActions ?. find ( a => a . id === actionId ) ;
569- const { confirm, alert } = useAdminforth ( ) ;
570-
571- if ( action ?. confirm ) {
572- const confirmed = await confirm ( {
573- message : action . confirm ,
574- } ) ;
575- if ( ! confirmed ) {
576- return ;
577- }
578- }
579- bulkActionLoadingStates . value [ actionId ] = true ;
580-
581- const data = await callAdminForthApi ( {
582- path : '/start_bulk_action' ,
583- method : 'POST' ,
584- body : {
585- resourceId : resource . resourceId ,
586- actionId : actionId ,
587- recordIds : checkboxes . value
588- }
589- } ) ;
590- bulkActionLoadingStates . value [ actionId ] = false ;
591- if ( data ?. ok ) {
592- checkboxes . value = [ ] ;
593- await getListInner ( ) ;
594-
595- if ( data . successMessage ) {
596- alert ( {
597- message : data . successMessage ,
598- variant : 'success'
599- } ) ;
600- }
601-
602- }
603- if ( data ?. error ) {
604- showErrorTost ( data . error ) ;
605- }
606- }
0 commit comments