var app = function () { var loader = $("#loader"); var cluster_default_size = 9; var search_filter = $("#search-filter"); var form_controller = $("#search-controller"); var hidden_dcloud = $("#delta_cloud"); var delta_cloud = $("#delta-could"); const DOCUMENT_PAGE = "/doc?id="; var query_hidden_input = $("#query_values"); var clusters_content = $("#clusters_content"); var cluster_selector = $("#clusterSize"); var top_items_section = $("#top_products_section"); var aggs_list = {}; var grp_aggr_selector = $('#grp_agg_content'); var discipl_aggr_selector = $('#disp_agg_content'); var author_aggr_selector = $('#author_agg_content'); var publication_period = $('#publication_period'); var keydiff = $("#keywordDiff"); var choices; function getRandomColor(step) { var letters = '123456789ABCDEF'; var color = '#'; for (var i = 0; i < 6; i++) { color += letters[Math.floor(Math.random() * 16)]; } return color; } var charsController = function (size, filter) { jQuery.ajax('/v3/data', { data: { "cluster_size": $('#clusterSize').find(":selected").text(), "filter": filter, "query": query_hidden_input.val(), "cluster": query_hidden_input.attr("data-filter"), "depth": query_hidden_input.attr("data-depth"), "delta_cloud": hidden_dcloud.val(), "grp_name": grp_aggr_selector.find(":selected").val(), "disp_name": discipl_aggr_selector.find(":selected").val(), "author_name": author_aggr_selector.find(":selected").val(), "pub_period": publication_period.val(), "uniq_keys": keydiff.find(":selected").val() }, dataType: 'json', success: function (data, status, xhr) { loader.hide(); createCharts(data.result); }, error: function (jqXhr, textStatus, errorMessage) { // error callback console.log(errorMessage) } }); }; var facetsController = function (selected) { jQuery.ajax('/v3/facets', { data: { "cluster_size": $('#clusterSize').find(":selected").text(), "query": query_hidden_input.val(), "grp_name": grp_aggr_selector.find(":selected").val(), "disp_name": discipl_aggr_selector.find(":selected").val(), "author_name": author_aggr_selector.find(":selected").val(), "pub_period": publication_period.val() }, dataType: 'json', success: function (data, status, xhr) { buildFacet(data.result); }, error: function (jqXhr, textStatus, errorMessage) { // error callback console.log(errorMessage) } }); }; var buildFacet = function (data) { if (data.hits.total === 0) { emptyResult(); return } var disciplines = data.aggregations.discipline.buckets; var group_name = data.aggregations.group_name.buckets; var author = data.aggregations.author.buckets; var option = ''; var selected = ""; for (var index in disciplines) { if (!disciplines.hasOwnProperty(index)) continue; if (aggs_list["disp_agg_content"] === disciplines[index].key) { selected = "selected" } option += ''; } $("#disp_agg_content").html(option); option = ''; selected = ""; for (index in group_name) { if (!group_name.hasOwnProperty(index)) continue; if (aggs_list["grp_agg_content"] === group_name[index].key) { selected = "selected" } option += ''; } $("#grp_agg_content").html(option); option = ''; selected = ""; for (index in author) { if (!author.hasOwnProperty(index)) continue; if (aggs_list["author_agg_content"] === author[index].key) { selected = "selected" } option += ''; } author_aggr_selector.html(option) }; var searchController = function () { choices = new Choices('#search-input', { searchEnabled: true, maxItemCount: 10, removeItemButton: true, removeItems: true, silent: true, removeItem: function (item) { console.log(item) } }); choices.passedElement.addEventListener('addItem', function (event) { if (query_hidden_input.val().length > 0) { query_hidden_input.val(query_hidden_input.val() + "," + event.detail.value); } else { query_hidden_input.val(event.detail.value); } reload_page(); }, false); choices.passedElement.addEventListener('removeItem', function (event) { var values = query_hidden_input.val().split(","); var query = []; for (var element in values) { if (!values.hasOwnProperty(element)) continue; if (values[element] !== event.detail.value) { query.push(values[element]) } } query_hidden_input.val(query); reload_page(); }, false); }; var deltaCloudController = function () { if ($("#delta_cloud").val() === "true") { delta_cloud.attr("checked", true) } else { delta_cloud.attr("checked", false) } delta_cloud.change(function () { if ($(this).is(":checked")) { hidden_dcloud.val(true); } else { hidden_dcloud.val(false); } form_controller.submit(); }); }; var createCharts = function (result) { var html_content = ""; var clsname = [] var clustersize = cluster_selector.find(":selected").val(); for (var cluster in result) { if (!result.hasOwnProperty(cluster)) continue; if (result[cluster]["total"] === 0) continue; var display = "none"; var url = DOCUMENT_PAGE + window.location.search + "&name=" + result[cluster]["name"] + "&cluster_size=" + clustersize; if (parseInt(result[cluster]["total"]) < 2) { display = "block"; } clsname.push(result[cluster]["name"]); html_content += "