diff --git a/js/source/legacy/CXGN/List.js b/js/source/legacy/CXGN/List.js index ba864e01e5..decb5000f1 100644 --- a/js/source/legacy/CXGN/List.js +++ b/js/source/legacy/CXGN/List.js @@ -54,6 +54,9 @@ CXGN.List = function () { +// Keep track of the rendered lists page number and sort column between refreshes +var render_lists_page = 0; // first page +var render_lists_order = [[0, "asc"]]; // sort by list name, ascending CXGN.List.prototype = { @@ -336,7 +339,11 @@ CXGN.List.prototype = { }, renderLists: function(div) { + var type = jQuery('#render_lists_type').val(); + var autocreated = jQuery("#render_lists_autocreated").is(":checked"); var lists = this.availableLists(); + var types = this.allListTypes(); + var html = ''; html = html + '
'; html = html + '
'; @@ -346,35 +353,79 @@ CXGN.List.prototype = { jQuery('#'+div+'_div').html(html); } - html += '
'; + // List Table Container + html += "
"; + + // Table Header + html += "
"; + + // Filter Container + html += "
" + + // Filter by List Type + html += "
" + html += "

Filter Lists by Type:

"; + html += ""; + html += "
"; + + // Autocreated filter + html += "
"; + html += "

Include Autocreated Lists:

"; + let checked = autocreated ? 'checked' : '' + html += ""; + html += "
"; + + // End Filter Container + html += "
"; + + // Multiple List Container + html += "
"; + + // End Header + html += "
"; + + // List Table + html += '
'; html += ''; for (var i = 0; i < lists.length; i++) { - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - if (lists[i][6] == 0){ - html += ''; - } else if (lists[i][6] == 1){ - html += ''; + if ( (!type || type === lists[i][5]) && (autocreated || !(lists[i][2] || '').startsWith("Autocreated")) ) { + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + if (lists[i][6] == 0){ + html += ''; + } else if (lists[i][6] == 1){ + html += ''; + } + html += ''; } - html += ''; } - html = html + '
List NameDescriptionDate CreatedDate ModifiedCountTypeValidateViewDeleteDownloadShareGroup
'+lists[i][1]+''+lists[i][2]+''+lists[i][7]+''+lists[i][8]+''+lists[i][3]+''+lists[i][5]+'
'+lists[i][1]+''+(lists[i][2] ? lists[i][2] : '')+''+(lists[i][7] ? new Date(lists[i][7]).toLocaleDateString() : '')+''+(lists[i][8] ? new Date(lists[i][8]).toLocaleDateString() : '')+''+(lists[i][3] ? lists[i][3] : '0')+''+(lists[i][5] ? lists[i][5] : '<NOT SET>')+'
'; - html += '
'; + html += ''; + html += ''; jQuery('#'+div+'_div').html(html); - jQuery('#private_list_data_table').DataTable({ + var table = jQuery('#private_list_data_table').DataTable({ "destroy": true, - "columnDefs": [ { "orderable": false, "targets": [4,5,6,7,8] } ] + "columnDefs": [{ "orderable": false, "targets": [6,7,8,9,10,11] }], + "order": render_lists_order }); + table.page(render_lists_page).draw('page'); + table.on('order', () => render_lists_order = table.order()); + table.on('page', () => render_lists_page = table.page.info().page); jQuery('#add_list_button').click(function() { var lo = new CXGN.List(); @@ -392,26 +443,54 @@ CXGN.List.prototype = { lo.renderPublicLists('public_list_dialog_div'); }); - jQuery("input[name='list_select_checkbox']").click(function() { + function render_selected_lists_container() { var total=jQuery("input[name='list_select_checkbox']:checked").length; var list_group_select_action_html=''; - if (total == 0) { - list_group_select_action_html += ''; - } else { + if (total > 1) { var selected = []; jQuery("input[name='list_select_checkbox']:checked").each(function() { selected.push(jQuery(this).attr('value')); }); - list_group_select_action_html = '
For Selected Lists:
'; - if (total == 1) { - list_group_select_action_html += 'Delete Make Public Make Private'; - } else if (total > 1) { - list_group_select_action_html += 'Delete Make Public Make Private

'; - } - list_group_select_action_html += '
'; + // Delete / Public / Private Functions + list_group_select_action_html += '
'; + list_group_select_action_html += '

Modify Selected Lists:

'; + list_group_select_action_html += '
'; + list_group_select_action_html += 'Delete Make Public Make Private'; + list_group_select_action_html += '
'; // end column + list_group_select_action_html += '
'; // end row + + // Union / Intersection Icons + var unionIcon = ''; + var intersectionIcon = ''; + + // Union / Intersection Functions + list_group_select_action_html += '
'; + list_group_select_action_html += '

Combine List Items From Selected Lists to a New List:

'; + list_group_select_action_html += '
'; + list_group_select_action_html += '
' + list_group_select_action_html += ''; + list_group_select_action_html += ''; + list_group_select_action_html += ''; + list_group_select_action_html += ''; + list_group_select_action_html += '
'; // End input group + list_group_select_action_html += '
'; // end column + list_group_select_action_html += '
'; // end row + } + else { + list_group_select_action_html += '
'; + list_group_select_action_html += '

Select 2 or more lists in the Group column to modify or combine them

'; + list_group_select_action_html += '
'; } jQuery("#list_group_select_action").html(list_group_select_action_html); + } + jQuery('body').on("click", "input[name='list_select_checkbox']", render_selected_lists_container); + render_selected_lists_container(); + + jQuery(".render_lists_filter").on("change", function() { + render_lists_page = 0; + var lo = new CXGN.List(); + lo.renderLists('list_dialog'); }); }, @@ -1718,36 +1797,69 @@ function makePrivateSelectedListGroup(list_ids) { } } -function combineSelectedListGroup(list_ids) { +/** + * Combine the items from the selected lists and create a new list + * The items can be combined either using a union method or intersection method + * @param {Array[Integer]} list_ids Array of List IDs of Lists to combine + * @param {String} type Method of combining lists (either 'union' or 'intersection', union is default) + */ +function combineSelectedListGroup(list_ids, type = 'union') { var arrayLength = list_ids.length; var list_name = jQuery('#new_combined_list_name').val(); - if (confirm('Combine selected lists into a new list called '+list_name+'?')) { - var arrayItems = []; + if ( !list_name || list_name === '' ) return alert("You must enter a new list name first"); + + if ( confirm('Combine selected lists into a new list called '+list_name+'?') ) { var lo = new CXGN.List(); - var first_list_type = lo.getListType(list_ids[0]); - var same_list_types = true; - for (var i=0; i 1 && !confirm('Are you sure you want to combine these list types: ' + list_types.join(', ')) ) return; + + // Combine list items + var arrayItems = []; + + // INTERSECTION + if ( type === 'intersection' ) { + var allListItems = []; + for ( var i=0; i result.filter(value => array.includes(value))); } - var new_list_id = lo.newList(list_name); - if (same_list_types == true) { - lo.setListType(new_list_id, first_list_type); - } - for (var i=0; i