1-
21let treeData = [ ] ;
2+ let currentPage = 1 ;
3+ let currentLimit = 1000 ;
4+ let currentDataSource = "all" ;
35
4- async function make_wd_result_for_list ( limit , data_source ) {
5-
6- let sparqlQuery = list_lexemes_query ( limit , data_source ) ;
7- // ---
6+ async function make_wd_result_for_list ( data_source , limit , offset , page_type ) {
7+ let sparqlQuery ;
8+ if ( page_type === "new" ) {
9+ // Use the new lexemes query for the "new" page type
10+ sparqlQuery = new_ar_lexemes_query ( data_source , limit , offset ) ;
11+ } else {
12+ // Use the list lexemes query for the "list" page type
13+ sparqlQuery = list_lexemes_query ( data_source , limit , offset ) ;
14+ }
815 add_sparql_url ( sparqlQuery ) ;
9- // ---
16+
1017 let result = await loadsparqlQuery ( sparqlQuery ) ;
1118
1219 let wd_result = parse_results_group_by ( result ) ;
1320
1421 return wd_result ;
1522}
1623
17- async function fetchListData ( limit , data_source ) {
18- // ---
19- let treeMap = await make_wd_result_for_list ( limit , data_source ) ;
24+ async function fetchListData ( data_source , limit , page , page_type ) {
25+
26+ let offset = ( page - 1 ) * limit ;
27+
28+ let treeMap = await make_wd_result_for_list ( data_source , limit , offset , page_type ) ;
2029
2130 treeMap = slice_data ( treeMap ) ;
2231
@@ -28,28 +37,37 @@ async function fetchListData(limit, data_source) {
2837
2938 treeData = Object . values ( treeMap ) ;
3039 renderTree ( treeData ) ;
40+
41+ // Update pagination controls
42+ updatePaginationControls ( page , limit , count ) ;
3143}
3244
33- function loadfetchData ( ) {
34- // ---
45+ function loadfetchData ( page_type = "list" ) {
46+
3547 showLoading ( ) ;
36- // ---
37- let limit = get_param_from_window_location ( "limit" , 1000 ) ;
48+
49+ let limit = parseInt ( get_param_from_window_location ( "limit" , 100 ) ) ;
3850 let data_source = get_param_from_window_location ( "data_source" , "all" ) ;
3951 let custom_data_source = get_param_from_window_location ( "custom_data_source" , "" ) ;
40- // ---
52+ let page = parseInt ( get_param_from_window_location ( "page" , 1 ) ) ;
53+
4154 // document.getElementById('custom_data_source').value = custom_data_source;
42- // ---
55+
4356 $ ( "#limit" ) . val ( limit ) ;
4457 $ ( "#data_source" ) . val ( data_source ) ;
45- // ---
58+
4659 if ( custom_data_source !== "" && data_source === "custom" ) {
4760 $ ( "#custom_data_source" ) . val ( custom_data_source ) ;
4861 data_source = custom_data_source ;
4962 document . getElementById ( 'custom_data_source' ) . style . display = 'block' ;
5063 }
51- // ---
52- fetchListData ( limit , data_source ) ;
64+
65+ // Store current state
66+ currentPage = page ;
67+ currentLimit = limit ;
68+ currentDataSource = data_source ;
69+
70+ fetchListData ( currentDataSource , currentLimit , currentPage , page_type ) ;
5371}
5472
5573function toggleCustomInput ( ) {
@@ -61,10 +79,69 @@ function toggleCustomInput() {
6179 customInput . style . display = 'none' ;
6280 }
6381}
82+ function updatePaginationControls ( page , limit , count ) {
83+ // Show or hide pagination based on whether we got full results
84+ const paginationDiv = document . getElementById ( "pagination_controls" ) ;
85+ if ( ! paginationDiv ) return ;
86+
87+ const prevBtn = document . getElementById ( "prev_page" ) ;
88+ const nextBtn = document . getElementById ( "next_page" ) ;
89+ // Only show pagination if we got results equal to limit (suggesting more pages exist)
90+ if ( count < limit && page === 1 ) {
91+ prevBtn . classList . add ( 'd-none' ) ;
92+ nextBtn . classList . add ( 'd-none' ) ;
93+ return ;
94+ }
95+
96+ // paginationDiv.classList.remove('d-none');
97+ // paginationDiv.classList.add('d-flex');
98+
99+ // Update page info
100+ // document.getElementById("page_info").textContent = `الصفحة ${page}`;
101+
102+ // Enable/disable previous button
103+ if ( page <= 1 ) {
104+ prevBtn . classList . add ( 'disabled' ) ;
105+ prevBtn . setAttribute ( 'disabled' , 'disabled' ) ;
106+ } else {
107+ prevBtn . classList . remove ( 'disabled' ) ;
108+ prevBtn . removeAttribute ( 'disabled' ) ;
109+ }
110+
111+ // Enable/disable next button based on whether we got full results
112+ if ( count < limit ) {
113+ nextBtn . classList . add ( 'disabled' ) ;
114+ nextBtn . setAttribute ( 'disabled' , 'disabled' ) ;
115+ } else {
116+ nextBtn . classList . remove ( 'disabled' ) ;
117+ nextBtn . removeAttribute ( 'disabled' ) ;
118+ }
119+ }
120+
121+ function navigateToPage ( page ) {
122+ const urlParams = new URLSearchParams ( window . location . search ) ;
123+ urlParams . set ( 'page' , page ) ;
124+ window . location . search = urlParams . toString ( ) ;
125+ }
126+
127+ function previousPage ( ) {
128+ if ( currentPage > 1 ) {
129+ navigateToPage ( currentPage - 1 ) ;
130+ }
131+ }
132+
133+ function nextPage ( ) {
134+ navigateToPage ( currentPage + 1 ) ;
135+ }
136+
64137async function load_list ( ) {
65- // ---
66- loadfetchData ( ) ;
67- // ---
138+ loadfetchData ( "list" ) ;
68139 toggleCustomInput ( ) ;
69- // ---
140+
141+ }
142+
143+ async function load_new ( ) {
144+ loadfetchData ( "new" ) ;
145+ toggleCustomInput ( ) ;
146+
70147}
0 commit comments