@@ -322,6 +322,221 @@ function initializeDataTable() {
322
322
} , 1000 )
323
323
) ;
324
324
325
+ var curated_urls_table = $ ( "#curated_urls_table" ) . DataTable ( {
326
+ pageLength : 100 ,
327
+ colReorder : true ,
328
+ stateSave : true ,
329
+ layout : {
330
+ bottomEnd : "inputPaging" ,
331
+ topEnd : null ,
332
+ topStart : {
333
+ info : true ,
334
+ pageLength : {
335
+ menu : [
336
+ [ 25 , 50 , 100 , 500 ] ,
337
+ [ "Show 25" , "Show 50" , "Show 100" , "Show 500" ] ,
338
+ ] ,
339
+ } ,
340
+ buttons : [
341
+ {
342
+ extend : "csv" ,
343
+ exportOptions : {
344
+ columns : [ 0 , 11 , 2 , 12 , 10 ] ,
345
+ } ,
346
+ customize : function ( csv ) {
347
+ var lines = csv . split ( "\n" ) ;
348
+
349
+ // Reorder the header columns
350
+ var headers = lines [ 0 ] . split ( "," ) ;
351
+ headers [ 4 ] = "New Title" ;
352
+ var reorderedHeaders = [
353
+ headers [ 0 ] ,
354
+ headers [ 3 ] ,
355
+ headers [ 1 ] ,
356
+ headers [ 4 ] ,
357
+ headers [ 5 ] ,
358
+ headers [ 2 ] ,
359
+ ] ;
360
+ lines [ 0 ] = reorderedHeaders . join ( "," ) ;
361
+
362
+ const appliedFilt = [
363
+ [ `URL:` , `${ $ ( "#curatedUrlFilter" ) . val ( ) } ` . trim ( ) ] ,
364
+ [ `Exclude:` , `${ $ ( ".dropdown-1" ) . val ( ) } ` . trim ( ) ] ,
365
+ [
366
+ `Scraped Title:` ,
367
+ `${ $ ( "#curatedScrapedTitleFilter" ) . val ( ) } ` . trim ( ) ,
368
+ ] ,
369
+ [ `New Title:` , `${ $ ( "#curatedNewTitleFilter" ) . val ( ) } ` . trim ( ) ] ,
370
+ [ `Document Type:` , `${ dict [ $ ( ".dropdown-4" ) . val ( ) ] } ` . trim ( ) ] ,
371
+ [ `Division By URL:` , `${ dict [ $ ( ".dropdown-5" ) . val ( ) ] } ` . trim ( ) ] ,
372
+ ] ;
373
+
374
+ const filtersAreEmpty = appliedFilt . every ( ( filter ) => {
375
+ return filter [ 1 ] === "" || filter [ 1 ] === "undefined" ;
376
+ } ) ;
377
+
378
+ // Remove the second row with the filters
379
+ if ( lines . length > 2 ) {
380
+ lines . splice ( 1 , 1 ) ;
381
+ }
382
+ let alteredLines = [ ] ;
383
+ lines . forEach ( ( line ) => {
384
+ let newLine = "" ;
385
+ newLine = line . replace ( "open_in_new" , "" ) ;
386
+ alteredLines . push ( newLine ) ;
387
+ } ) ;
388
+
389
+ if ( filtersAreEmpty ) return alteredLines . join ( "\n" ) ;
390
+ else {
391
+ // Add filter information to the first row
392
+ const secondRowFilters = [
393
+ "Export of SDE Curated URLs" ,
394
+ `"(Applied Filters: ${ appliedFilt
395
+ . reduce ( ( acc , curr ) => {
396
+ if (
397
+ curr [ 1 ] !== " undefined" &&
398
+ curr [ 1 ] !== " " &&
399
+ curr [ 1 ] !== "" &&
400
+ curr [ 1 ] !== "undefined"
401
+ ) {
402
+ acc = `${ acc } , ${ curr [ 0 ] } ${ curr [ 1 ] } ` ;
403
+ }
404
+ return acc ;
405
+ } , "" )
406
+ . slice ( 2 ) } )"`,
407
+ ] ;
408
+
409
+ var appliedFiltersInfo = secondRowFilters . join ( "\n" ) ;
410
+ return appliedFiltersInfo + "\n" + alteredLines . join ( "\n" ) ;
411
+ }
412
+ } ,
413
+ } ,
414
+ "spacer" ,
415
+ {
416
+ text : "Customize Columns" ,
417
+ className : "customizeColumns" ,
418
+ action : function ( ) {
419
+ modalContents ( "#curated_urls_table" ) ;
420
+ } ,
421
+ } ,
422
+ ] ,
423
+ } ,
424
+ } ,
425
+ serverSide : true ,
426
+ orderCellsTop : true ,
427
+ pagingType : "input" ,
428
+ rowId : "url" ,
429
+ stateLoadCallback : function ( settings ) {
430
+ var state = JSON . parse (
431
+ localStorage . getItem (
432
+ "DataTables_curated_urls_" + window . location . pathname
433
+ )
434
+ ) ;
435
+ if ( ! state ) {
436
+ settings . oInit . pageLength = 1 ;
437
+ }
438
+ return state ;
439
+ } ,
440
+ ajax : {
441
+ url : `/api/curated-urls/?format=datatables&collection_id=${ collection_id } ` ,
442
+ data : function ( d ) {
443
+ d . is_excluded = $ ( "#filter-checkbox" ) . is ( ":checked" ) ? false : null ;
444
+ } ,
445
+ } ,
446
+ initComplete : function ( data ) {
447
+ const addDropdownSelect = [ 1 , 4 , 5 ] ;
448
+ const dict = {
449
+ 1 : "Images" ,
450
+ 2 : "Data" ,
451
+ 3 : "Documentation" ,
452
+ 4 : "Software and Tools" ,
453
+ 5 : "Missions and Instruments" ,
454
+ } ;
455
+ this . api ( )
456
+ . columns ( )
457
+ . every ( function ( index ) {
458
+ let column = this ;
459
+ if ( addDropdownSelect . includes ( index ) ) {
460
+ $ ( "thead tr td select.dropdown-" + index ) . on ( "change" , function ( ) {
461
+ var val = $ . fn . dataTable . util . escapeRegex ( $ ( this ) . val ( ) ) ;
462
+ column . search ( val ? "^" + val + "$" : "" , true , false ) . draw ( ) ;
463
+ } ) ;
464
+ }
465
+ } ) ;
466
+ } ,
467
+
468
+ columns : [
469
+ getCuratedURLColumn ( ) ,
470
+ getCuratedExcludedColumn ( true_icon , false_icon ) ,
471
+ getCuratedScrapedTitleColumn ( ) ,
472
+ getCuratedGeneratedTitleColumn ( ) ,
473
+ getCuratedDocumentTypeColumn ( ) ,
474
+ getCuratedDivisionColumn ( ) ,
475
+ { data : "id" , visible : false , searchable : false } ,
476
+ { data : "generated_title_id" , visible : false , searchable : false } ,
477
+ { data : "match_pattern_type" , visible : false , searchable : false } ,
478
+ { data : "curated_urls_count" , visible : false , searchable : false } ,
479
+ { data : "excluded" , visible : false , searchable : false } ,
480
+ {
481
+ data : null ,
482
+ render : function ( data , type , row ) {
483
+ if ( ! row . document_type ) return "Select" ;
484
+ return dict [ row . document_type ] ;
485
+ } ,
486
+ visible : false ,
487
+ } ,
488
+ {
489
+ data : null ,
490
+ render : function ( data , type , row ) {
491
+ const excludedDict = {
492
+ true : "Yes" ,
493
+ false : "No" ,
494
+ } ;
495
+ return excludedDict [ row . excluded ] ;
496
+ } ,
497
+ visible : false ,
498
+ } ,
499
+ {
500
+ data : null ,
501
+ render : function ( data , type , row ) {
502
+ return row . generated_title ;
503
+ } ,
504
+ visible : false ,
505
+ } ,
506
+ // ...(is_multi_division === 'true' ? [getDivisionColumn()] : []),
507
+ // getDivisionColumn(),
508
+ ] ,
509
+ createdRow : function ( row , data , dataIndex ) {
510
+ if ( data [ "excluded" ] ) {
511
+ $ ( row ) . attr (
512
+ "style" ,
513
+ "background-color: rgba(255, 61, 87, 0.36) !important"
514
+ ) ;
515
+ }
516
+ } ,
517
+ } ) ;
518
+
519
+ $ ( "#curatedUrlFilter" ) . on (
520
+ "beforeinput" ,
521
+ DataTable . util . debounce ( function ( val ) {
522
+ delta_urls_table . columns ( 0 ) . search ( this . value ) . draw ( ) ;
523
+ } , 1000 )
524
+ ) ;
525
+
526
+ $ ( "#curatedScrapedTitleFilter" ) . on (
527
+ "beforeinput" ,
528
+ DataTable . util . debounce ( function ( val ) {
529
+ delta_urls_table . columns ( 2 ) . search ( this . value ) . draw ( ) ;
530
+ } , 1000 )
531
+ ) ;
532
+
533
+ $ ( "#curatedNewTitleFilter" ) . on (
534
+ "beforeinput" ,
535
+ DataTable . util . debounce ( function ( val ) {
536
+ delta_urls_table . columns ( 3 ) . search ( this . value ) . draw ( ) ;
537
+ } , 1000 )
538
+ ) ;
539
+
325
540
var exclude_patterns_table = $ ( "#exclude_patterns_table" ) . DataTable ( {
326
541
// scrollY: true,
327
542
dom : "lBrtip" ,
@@ -849,6 +1064,30 @@ function getDivisionColumn() {
849
1064
} ;
850
1065
}
851
1066
1067
+ function getCuratedDivisionColumn ( ) {
1068
+ return {
1069
+ data : "division" ,
1070
+ width : "10%" ,
1071
+ visible : ( is_multi_division === "true" ) , searchable : is_multi_division ,
1072
+ render : function ( data , type , row ) {
1073
+ let button_text = data ? divisionDict [ data ] : "Select" ;
1074
+ let button_color = data ? "btn-success" : "btn-secondary" ;
1075
+ return `
1076
+ <div class="dropdown document_type_dropdown" data-match-pattern=${ remove_protocol ( row [ "url" ] ) } >
1077
+ <button class="btn ${ button_color } btn-sm dropdown-toggle selectStyling" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
1078
+ ${ button_text }
1079
+ </button>
1080
+ <div class="dropdown-menu">
1081
+ <a class="dropdown-item division_select" href="#" value="0">None</a>
1082
+ ${ Object . entries ( divisionDict ) . map ( ( [ value , name ] ) => {
1083
+ return `<a class="dropdown-item division_select" href="#" value="${ value } ">${ name } </a>` ;
1084
+ } ) . join ( '' ) }
1085
+ </div>
1086
+ </div>` ;
1087
+ } ,
1088
+ } ;
1089
+ }
1090
+
852
1091
853
1092
function handleDivisionSelect ( ) {
854
1093
$ ( "body" ) . on ( "click" , ".division_select" , function ( ) {
@@ -956,6 +1195,20 @@ function getURLColumn() {
956
1195
} ;
957
1196
}
958
1197
1198
+ function getCuratedURLColumn ( ) {
1199
+ return {
1200
+ data : "url" ,
1201
+ width : "30%" ,
1202
+ render : function ( data , type , row ) {
1203
+ return `<div class="url-cell"><span class="delta_url nameStyling">${ remove_protocol (
1204
+ data
1205
+ ) } </span>
1206
+ <a target="_blank" href="${ data } " data-url="/api/curated-urls/${ row [ "id" ]
1207
+ } /" class="url-link"> <i class="material-icons url-icon">open_in_new</i></a></div>`;
1208
+ } ,
1209
+ } ;
1210
+ }
1211
+
959
1212
function getScrapedTitleColumn ( ) {
960
1213
return {
961
1214
data : "scraped_title" ,
@@ -966,6 +1219,16 @@ function getScrapedTitleColumn() {
966
1219
} ;
967
1220
}
968
1221
1222
+ function getCuratedScrapedTitleColumn ( ) {
1223
+ return {
1224
+ data : "scraped_title" ,
1225
+ width : "30%" ,
1226
+ render : function ( data , type , row ) {
1227
+ return `<span class="whiteText">${ data } </span>` ;
1228
+ } ,
1229
+ } ;
1230
+ }
1231
+
969
1232
function getGeneratedTitleColumn ( ) {
970
1233
return {
971
1234
data : "generated_title" ,
@@ -979,6 +1242,19 @@ function getGeneratedTitleColumn() {
979
1242
} ;
980
1243
}
981
1244
1245
+ function getCuratedGeneratedTitleColumn ( ) {
1246
+ return {
1247
+ data : "generated_title" ,
1248
+ width : "20%" ,
1249
+ render : function ( data , type , row ) {
1250
+ return `<input type="text" class="form-control individual_title_input whiteText" value='${ data } ' data-generated-title-id=${ row [ "generated_title_id" ]
1251
+ } data-match-pattern-type=${ row [ "match_pattern_type" ]
1252
+ } data-curated-urls-count=${ row [ "curated_urls_count" ]
1253
+ } data-url=${ remove_protocol ( row [ "url" ] ) } />`;
1254
+ } ,
1255
+ } ;
1256
+ }
1257
+
982
1258
function getExcludedColumn ( true_icon , false_icon ) {
983
1259
return {
984
1260
data : "excluded" ,
@@ -996,6 +1272,23 @@ function getExcludedColumn(true_icon, false_icon) {
996
1272
} ;
997
1273
}
998
1274
1275
+ function getCuratedExcludedColumn ( true_icon , false_icon ) {
1276
+ return {
1277
+ data : "excluded" ,
1278
+ width : "10%" ,
1279
+ class : "col-1 text-center" ,
1280
+ render : function ( data , type , row ) {
1281
+ return data === true
1282
+ ? `<a class="exclude_individual_url" value=${ remove_protocol (
1283
+ row [ "url" ]
1284
+ ) } >${ true_icon } </a>`
1285
+ : `<a class="exclude_individual_url" value=${ remove_protocol (
1286
+ row [ "url" ]
1287
+ ) } >${ false_icon } </a>`;
1288
+ } ,
1289
+ } ;
1290
+ }
1291
+
999
1292
function getDocumentTypeColumn ( ) {
1000
1293
return {
1001
1294
data : "document_type" ,
@@ -1030,6 +1323,40 @@ function getDocumentTypeColumn() {
1030
1323
} ;
1031
1324
}
1032
1325
1326
+ function getCuratedDocumentTypeColumn ( ) {
1327
+ return {
1328
+ data : "document_type" ,
1329
+ width : "10%" ,
1330
+ render : function ( data , type , row ) {
1331
+ var dict = {
1332
+ 1 : "Images" ,
1333
+ 2 : "Data" ,
1334
+ 3 : "Documentation" ,
1335
+ 4 : "Software and Tools" ,
1336
+ 5 : "Missions and Instruments" ,
1337
+ } ;
1338
+ button_text = data ? dict [ data ] : "Select" ;
1339
+ button_color = data ? "btn-success" : "btn-secondary" ;
1340
+ return `
1341
+ <div class="dropdown document_type_dropdown" data-match-pattern=${ remove_protocol (
1342
+ row [ "url" ]
1343
+ ) } >
1344
+ <button class="btn ${ button_color } btn-sm dropdown-toggle selectStyling" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
1345
+ ${ button_text }
1346
+ </button>
1347
+ <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
1348
+ <a class="dropdown-item document_type_select" href="#" value="0">None</a>
1349
+ <a class="dropdown-item document_type_select" href="#" value="1">Images</a>
1350
+ <a class="dropdown-item document_type_select" href="#" value="2">Data</a>
1351
+ <a class="dropdown-item document_type_select" href="#" value="3">Documentation</a>
1352
+ <a class="dropdown-item document_type_select" href="#" value="4">Software and Tools</a>
1353
+ <a class="dropdown-item document_type_select" href="#" value="5">Missions and Instruments</a>
1354
+ </div>
1355
+ </div>` ;
1356
+ } ,
1357
+ } ;
1358
+ }
1359
+
1033
1360
//template to add enter and escape functionalities to add pattern modals
1034
1361
function addEnterEscapeKeypress ( modalID , formID ) {
1035
1362
$ ( "body" ) . on ( "keydown" , function ( event ) {
0 commit comments