1
+ // Define column constants for better maintainability
2
+ const COLUMNS = {
3
+ NAME : 0 ,
4
+ URL : 1 ,
5
+ DIVISION : 2 ,
6
+ DELTA_URLS : 3 ,
7
+ WORKFLOW_STATUS : 4 ,
8
+ CURATOR : 5 ,
9
+ CONNECTOR_TYPE : 6 ,
10
+ REINDEXING_STATUS : 7 ,
11
+ WORKFLOW_STATUS_RAW : 8 ,
12
+ CURATOR_ID : 9 ,
13
+ REINDEXING_STATUS_RAW : 10
14
+ } ;
15
+
1
16
var uniqueId ; //used for logic related to contents on column customization modal
2
17
3
18
function modalContents ( tableName ) {
@@ -107,156 +122,127 @@ let table = $("#collection_table").DataTable({
107
122
} ,
108
123
] ,
109
124
columnDefs : [
125
+ // hide the data columns
110
126
{
111
- targets : [ 8 , 9 ] , // Added 9 for reindexing status ID
127
+ targets : [ COLUMNS . WORKFLOW_STATUS_RAW , COLUMNS . CURATOR_ID , COLUMNS . REINDEXING_STATUS_RAW ] ,
112
128
visible : false ,
113
129
} ,
114
- { width : "200px" , targets : 1 } ,
130
+ { width : "200px" , targets : COLUMNS . URL } ,
115
131
{
116
132
searchPanes : {
117
133
options : [
118
134
{
119
135
label : "0 URLs" ,
120
136
value : function ( rowData , rowIdx ) {
121
- return $ ( rowData [ 3 ] ) . text ( ) == 0 ;
137
+ return $ ( rowData [ COLUMNS . DELTA_URLS ] ) . text ( ) == 0 ;
122
138
} ,
123
139
} ,
124
140
{
125
141
label : "1 solo URL" ,
126
142
value : function ( rowData , rowIdx ) {
127
- return $ ( rowData [ 3 ] ) . text ( ) == 1 ;
143
+ return $ ( rowData [ COLUMNS . DELTA_URLS ] ) . text ( ) == 1 ;
128
144
} ,
129
145
} ,
130
146
{
131
147
label : "1 to 100 URLs" ,
132
148
value : function ( rowData , rowIdx ) {
133
- return $ ( rowData [ 3 ] ) . text ( ) <= 100 && $ ( rowData [ 3 ] ) . text ( ) > 1 ;
149
+ return $ ( rowData [ COLUMNS . DELTA_URLS ] ) . text ( ) <= 100 && $ ( rowData [ COLUMNS . DELTA_URLS ] ) . text ( ) > 1 ;
134
150
} ,
135
151
} ,
136
152
{
137
153
label : "100 to 1,000 URLs" ,
138
154
value : function ( rowData , rowIdx ) {
139
- return $ ( rowData [ 3 ] ) . text ( ) <= 1000 && $ ( rowData [ 3 ] ) . text ( ) > 100 ;
155
+ return $ ( rowData [ COLUMNS . DELTA_URLS ] ) . text ( ) <= 1000 && $ ( rowData [ COLUMNS . DELTA_URLS ] ) . text ( ) > 100 ;
140
156
} ,
141
157
} ,
142
158
{
143
159
label : "1,000 to 10,000 URLs" ,
144
160
value : function ( rowData , rowIdx ) {
145
- return (
146
- $ ( rowData [ 3 ] ) . text ( ) <= 10000 && $ ( rowData [ 3 ] ) . text ( ) > 1000
147
- ) ;
161
+ return $ ( rowData [ COLUMNS . DELTA_URLS ] ) . text ( ) <= 10000 && $ ( rowData [ COLUMNS . DELTA_URLS ] ) . text ( ) > 1000 ;
148
162
} ,
149
163
} ,
150
164
{
151
165
label : "10,000 to 100,000 URLs" ,
152
166
value : function ( rowData , rowIdx ) {
153
- return (
154
- $ ( rowData [ 3 ] ) . text ( ) <= 100000 && $ ( rowData [ 3 ] ) . text ( ) > 10000
155
- ) ;
167
+ return $ ( rowData [ COLUMNS . DELTA_URLS ] ) . text ( ) <= 100000 && $ ( rowData [ COLUMNS . DELTA_URLS ] ) . text ( ) > 10000 ;
156
168
} ,
157
169
} ,
158
170
{
159
171
label : "Over 100,000 URLs" ,
160
172
value : function ( rowData , rowIdx ) {
161
- return $ ( rowData [ 3 ] ) . text ( ) > 100000 ;
173
+ return $ ( rowData [ COLUMNS . DELTA_URLS ] ) . text ( ) > 100000 ;
162
174
} ,
163
175
} ,
164
176
] ,
165
177
} ,
166
- targets : [ 3 ] ,
178
+ targets : [ COLUMNS . DELTA_URLS ] ,
167
179
type : "num-fmt" ,
168
180
} ,
181
+ // hide the data panes
169
182
{
170
183
searchPanes : {
171
184
show : false ,
172
185
} ,
173
- targets : [ 8 , 9 , 10 ] , // this hides the id columns for reindexing status and some other one
186
+ targets : [ COLUMNS . WORKFLOW_STATUS_RAW , COLUMNS . CURATOR_ID , COLUMNS . REINDEXING_STATUS_RAW ] ,
174
187
} ,
175
188
{
176
189
searchPanes : {
177
190
dtOpts : {
178
191
scrollY : "100%" ,
179
192
} ,
180
193
} ,
181
- targets : [ 5 ] ,
194
+ targets : [ COLUMNS . CURATOR ] ,
182
195
} ,
183
196
{
184
197
searchPanes : {
185
198
dtOpts : {
186
199
scrollY : "100%" ,
187
200
} ,
188
201
} ,
189
- targets : [ 6 ] , // Add searchPane for reindexing status column
202
+ targets : [ COLUMNS . CONNECTOR_TYPE ] ,
190
203
} ,
191
204
] ,
192
205
} ) ;
193
206
194
207
$ ( "#collection-dropdown-4" ) . on ( "change" , function ( ) {
195
208
table
196
- . columns ( 7 )
209
+ . columns ( COLUMNS . WORKFLOW_STATUS_RAW )
197
210
. search ( this . value ? "^" + this . value + "$" : "" , true , false )
198
211
. draw ( ) ;
199
212
} ) ;
200
213
201
214
$ ( "#collection-dropdown-5" ) . on ( "change" , function ( ) {
202
215
table
203
- . columns ( 8 )
216
+ . columns ( COLUMNS . CURATOR_ID )
204
217
. search ( this . value ? "^" + this . value + "$" : "" , true , false )
205
218
. draw ( ) ;
206
219
} ) ;
207
220
221
+ $ ( "#collection-dropdown-6" ) . on ( "change" , function ( ) {
222
+ table
223
+ . columns ( COLUMNS . REINDEXING_STATUS_RAW )
224
+ . search ( this . value ? "^" + this . value + "$" : "" , true , false )
225
+ . draw ( ) ;
226
+ } ) ;
208
227
209
228
$ ( "#nameFilter" ) . on ( "keyup" , function ( ) {
210
- table . columns ( 0 ) . search ( this . value ) . draw ( ) ;
229
+ table . columns ( COLUMNS . NAME ) . search ( this . value ) . draw ( ) ;
211
230
} ) ;
212
231
213
232
$ ( "#urlFilter" ) . on ( "keyup" , function ( ) {
214
- table . columns ( 1 ) . search ( this . value ) . draw ( ) ;
233
+ table . columns ( COLUMNS . URL ) . search ( this . value ) . draw ( ) ;
215
234
} ) ;
216
235
217
236
$ ( "#divisionFilter" ) . on ( "keyup" , function ( ) {
218
- table . columns ( 2 ) . search ( this . value ) . draw ( ) ;
237
+ table . columns ( COLUMNS . DIVISION ) . search ( this . value ) . draw ( ) ;
219
238
} ) ;
220
239
221
240
$ ( "#connectorTypeFilter" ) . on ( "keyup" , function ( ) {
222
- table . columns ( 6 ) . search ( this . value ) . draw ( ) ;
241
+ table . columns ( COLUMNS . CONNECTOR_TYPE ) . search ( this . value ) . draw ( ) ;
223
242
} ) ;
224
243
225
244
var csrftoken = $ ( 'input[name="csrfmiddlewaretoken"]' ) . val ( ) ;
226
245
227
- // I don't think this function is being used
228
- // function handleCurationStatusSelect() {
229
- // $("body").on("click", ".curation_status_select", function () {
230
- // var collection_id = $(this).data('collection-id');
231
- // var curation_status = $(this).attr('value');
232
- // var curation_status_text = $(this).text();
233
- // var color_choices = {
234
- // 1: "btn-light",
235
- // 2: "btn-danger",
236
- // 3: "btn-warning",
237
- // 4: "btn-info",
238
- // 5: "btn-success",
239
- // 6: "btn-primary",
240
- // 7: "btn-info",
241
- // 8: "btn-secondary",
242
- // }
243
-
244
- // $possible_buttons = $('body').find(`[id="curation-status-button-${collection_id}"]`);
245
- // if ($possible_buttons.length > 1) {
246
- // $button = $possible_buttons[1];
247
- // $button = $($button);
248
- // } else {
249
- // $button = $(`#curation-status-button-${collection_id}`);
250
- // }
251
- // $button.text(curation_status_text);
252
- // $button.removeClass('btn-light btn-danger btn-warning btn-info btn-success btn-primary btn-secondary');
253
- // $button.addClass(color_choices[parseInt(curation_status)]);
254
- // $('#collection_table').DataTable().searchPanes.rebuildPane(6);
255
- // var collection_division = $(this).data('collection-division');
256
- // postCurationStatus(collection_id, curation_status, collection_division);
257
- // });
258
- // }
259
-
260
246
function handleWorkflowStatusSelect ( ) {
261
247
$ ( "body" ) . on ( "click" , ".workflow_status_select" , function ( ) {
262
248
var collection_id = $ ( this ) . data ( "collection-id" ) ;
@@ -297,20 +283,21 @@ function handleWorkflowStatusSelect() {
297
283
$button . addClass ( color_choices [ parseInt ( workflow_status ) ] ) ;
298
284
var row = table . row ( "#" + collection_id ) ;
299
285
let index = row . index ( ) ;
300
- var $html = $ ( "<div />" , { html : table . data ( ) [ index ] [ 4 ] } ) ;
286
+ var $html = $ ( "<div />" , { html : table . data ( ) [ index ] [ COLUMNS . WORKFLOW_STATUS ] } ) ;
301
287
$html . find ( "button" ) . html ( workflow_status_text ) ;
302
288
$html
303
289
. find ( "button" )
304
290
. removeClass (
305
291
"btn-light btn-danger btn-warning btn-info btn-success btn-primary btn-secondary"
306
292
) ;
307
293
$html . find ( "button" ) . addClass ( color_choices [ parseInt ( workflow_status ) ] ) ;
308
- table . data ( ) [ index ] [ 4 ] = $html . html ( ) ;
309
- $ ( "#collection_table" ) . DataTable ( ) . searchPanes . rebuildPane ( 4 ) ;
294
+ table . data ( ) [ index ] [ COLUMNS . WORKFLOW_STATUS ] = $html . html ( ) ;
295
+ $ ( "#collection_table" ) . DataTable ( ) . searchPanes . rebuildPane ( COLUMNS . WORKFLOW_STATUS ) ;
310
296
311
297
postWorkflowStatus ( collection_id , workflow_status ) ;
312
298
} ) ;
313
299
}
300
+
314
301
function handleReindexingStatusSelect ( ) {
315
302
$ ( "body" ) . on ( "click" , ".reindexing_status_select" , function ( ) {
316
303
var collection_id = $ ( this ) . data ( "collection-id" ) ;
@@ -341,22 +328,21 @@ function handleReindexingStatusSelect() {
341
328
$button . addClass ( color_choices [ parseInt ( reindexing_status ) ] ) ;
342
329
var row = table . row ( "#" + collection_id ) ;
343
330
let index = row . index ( ) ;
344
- var $html = $ ( "<div />" , { html : table . data ( ) [ index ] [ 7 ] } ) ; // Assuming this is column index 7
331
+ var $html = $ ( "<div />" , { html : table . data ( ) [ index ] [ COLUMNS . REINDEXING_STATUS ] } ) ;
345
332
$html . find ( "button" ) . html ( reindexing_status_text ) ;
346
333
$html
347
334
. find ( "button" )
348
335
. removeClass (
349
336
"btn-light btn-danger btn-warning btn-info btn-success btn-primary btn-secondary"
350
337
) ;
351
338
$html . find ( "button" ) . addClass ( color_choices [ parseInt ( reindexing_status ) ] ) ;
352
- table . data ( ) [ index ] [ 7 ] = $html . html ( ) ;
353
- $ ( "#collection_table" ) . DataTable ( ) . searchPanes . rebuildPane ( 7 ) ;
339
+ table . data ( ) [ index ] [ COLUMNS . REINDEXING_STATUS ] = $html . html ( ) ;
340
+ $ ( "#collection_table" ) . DataTable ( ) . searchPanes . rebuildPane ( COLUMNS . REINDEXING_STATUS ) ;
354
341
355
342
postReindexingStatus ( collection_id , reindexing_status ) ;
356
343
} ) ;
357
344
}
358
345
359
-
360
346
function handleCuratorSelect ( ) {
361
347
$ ( "body" ) . on ( "click" , ".curator_select" , function ( ) {
362
348
var collection_id = $ ( this ) . data ( "collection-id" ) ;
@@ -380,10 +366,10 @@ function handleCuratorSelect() {
380
366
$button . addClass ( "btn-success" ) ;
381
367
var row = table . row ( "#" + collection_id ) ;
382
368
let index = row . index ( ) ;
383
- var $html = $ ( "<div />" , { html : table . data ( ) [ index ] [ 5 ] } ) ;
369
+ var $html = $ ( "<div />" , { html : table . data ( ) [ index ] [ COLUMNS . CURATOR ] } ) ;
384
370
$html . find ( "button" ) . html ( curator_text ) ;
385
- table . data ( ) [ index ] [ 5 ] = $html . html ( ) ;
386
- table . searchPanes . rebuildPane ( 5 ) ;
371
+ table . data ( ) [ index ] [ COLUMNS . CURATOR ] = $html . html ( ) ;
372
+ table . searchPanes . rebuildPane ( COLUMNS . CURATOR ) ;
387
373
postCurator ( collection_id , curator_id ) ;
388
374
} ) ;
389
375
}
@@ -406,23 +392,6 @@ function postReindexingStatus(collection_id, reindexing_status) {
406
392
} ) ;
407
393
}
408
394
409
- function postCurationStatus ( collection_id , curation_status ) {
410
- var url = `/api/collections/${ collection_id } /` ;
411
- $ . ajax ( {
412
- url : url ,
413
- type : "PUT" ,
414
- data : {
415
- curation_status : curation_status ,
416
- csrfmiddlewaretoken : csrftoken ,
417
- } ,
418
- headers : {
419
- "X-CSRFToken" : csrftoken ,
420
- } ,
421
- success : function ( data ) {
422
- toastr . success ( "Curation Status Updated!" ) ;
423
- } ,
424
- } ) ;
425
- }
426
395
427
396
function postWorkflowStatus ( collection_id , workflow_status ) {
428
397
var url = `/api/collections/${ collection_id } /` ;
@@ -486,6 +455,7 @@ $(document).ready(function () {
486
455
// Clear previous search
487
456
table . search ( '' ) . columns ( ) . search ( '' ) ;
488
457
458
+ // TODO: this section might still need to be refactored to align with our column index definitions
489
459
// Filter the table based on the query in the collection name and config folder data attribute
490
460
table . rows ( ) . every ( function ( ) {
491
461
let row = $ ( this . node ( ) ) ;
@@ -519,7 +489,6 @@ $(document).ready(function () {
519
489
} ) ;
520
490
521
491
function setupClickHandlers ( ) {
522
- // handleCurationStatusSelect();
523
492
handleWorkflowStatusSelect ( ) ;
524
493
handleReindexingStatusSelect ( ) ;
525
494
handleCuratorSelect ( ) ;
0 commit comments