<commit_before>/* global _ */

'use strict';

var CTRL = function(
    $scope, $rootScope, SearchHelperService, $location, SearchDao, $timeout,
    SearchResultNavigatorService, CleanJSObjectService, ToolbarHeaderService,
    $state
) {

  var queryChangedOnInit = false;
  var tabChangedOnInitFlag = false;
  var locationChanged = false;
  var selectedTabChangeIsBeingHandled = false;
  var queryChangeIsBeingHandled = false;
  var relatedObjects = [];

  //Information for the different tabs
  var tabs = [{
    title: 'search-management.tabs.studies',
    inputLabel: 'search-management.input-label.studies',
    icon: 'assets/images/icons/study.svg',
    elasticSearchType: 'studies',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.studies',
    group: 'studies'
  }, {
    title: 'search-management.tabs.surveys',
    inputLabel: 'search-management.input-label.surveys',
    icon: 'assets/images/icons/survey.svg',
    elasticSearchType: 'surveys',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.surveys',
    group: 'surveys'
  }, {
    title: 'search-management.tabs.instruments',
    inputLabel: 'search-management.input-label.instruments',
    icon: 'assets/images/icons/instrument.svg',
    elasticSearchType: 'instruments',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.instruments',
    group: 'instruments'
  }, {
    title: 'search-management.tabs.questions',
    inputLabel: 'search-management.input-label.questions',
    icon: 'assets/images/icons/question.svg',
    elasticSearchType: 'questions',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.questions',
    group: 'questions'
  }, {
    title: 'search-management.tabs.data_sets',
    inputLabel: 'search-management.input-label.data-sets',
    icon: 'assets/images/icons/data-set.svg',
    elasticSearchType: 'data_sets',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.data-sets',
    group: 'dataSets'
  }, {
    title: 'search-management.tabs.variables',
    inputLabel: 'search-management.input-label.variables',
    icon: 'assets/images/icons/variable.svg',
    elasticSearchType: 'variables',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.variables',
    group: 'variables'
  }, {
    title: 'search-management.tabs.related_publications',
    inputLabel: 'search-management.input-label.related-publications',
    icon: 'assets/images/icons/related-publication.svg',
    elasticSearchType: 'related_publications',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.related-publications',
    group: 'publications'
  }, {
    title: 'search-management.tabs.concepts',
    inputLabel: 'search-management.input-label.concepts',
    icon: 'assets/images/icons/concept.svg',
    elasticSearchType: 'concepts',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.concepts',
    group: 'concepts'
  }];

  var tabsFilter = function(data) {
    tabs.forEach(function(tab, index) {
      var prop = tab.group + 'Count';
      if (data.hasOwnProperty(prop)) {
        tabs[index].count = data[prop];
        relatedObjects.push(tabs[index]);
      }
    });
  };
  var getSelectedMetadataType = function() {
    return $scope.tabs[$scope.searchParams.selectedTabIndex]
      .elasticSearchType;
  };
  // write the searchParams object to the location with the correct types
  var writeSearchParamsToLocation = function() {
    var locationSearch = {};
    locationSearch.page = '' + $scope.options.pageObject.page;
    locationSearch.size = '' + $scope.options.pageObject.size;
    try {
      locationSearch.type = $scope.tabs[
        $scope.searchParams.selectedTabIndex].elasticSearchType;
    } catch (e) {
      $scope.searchParams.selectedTabIndex = 0;
      locationSearch.type = $scope.tabs[
        $scope.searchParams.selectedTabIndex].elasticSearchType;
    }
    if ($scope.searchParams.query && $scope.searchParams.query !== '') {
      locationSearch.query = $scope.searchParams.query;
    }
    if ($scope.searchParams.sortBy && $scope.searchParams.sortBy !== '') {
      locationSearch['sort-by'] = $scope.searchParams.sortBy;
    } else {
      delete locationSearch['sort-by'];
    }
    _.assign(locationSearch, $scope.searchParams.filter);
    locationChanged = !angular.equals($location.search(),
      locationSearch);
    $location.search(locationSearch);
  };

  // read the searchParams object from the location with the correct types
  var readSearchParamsFromLocation = function() {
    var locationSearch = $location.search();
    if (CleanJSObjectService.isNullOrEmpty(locationSearch)) {
      $scope.options.pageObject.page = 1;
      $scope.options.pageObject.size = 10;
      $scope.searchParams = {
        query: '',
        size: $scope.options.pageObject.size,
        selectedTabIndex: 0
      };
    } else {
      if (locationSearch.page != null) {
        $scope.options.pageObject.page = parseInt(locationSearch.page);
      } else {
        $scope.options.pageObject.page = 1;
      }
      if (locationSearch.size != null) {
        $scope.options.pageObject.size = parseInt(locationSearch.size);
        $scope.searchParams.size = $scope.options.pageObject.size;
      } else {
        $scope.options.pageObject.size = 10;
        $scope.searchParams.size = $scope.options.pageObject.size;<commit_msg>Fix breadcrumbs error<commit_after>/* global _ */

'use strict';

var CTRL = function(
    $scope, $rootScope, SearchHelperService, $location, SearchDao, $timeout,
    SearchResultNavigatorService, CleanJSObjectService, ToolbarHeaderService,
    $state
) {

  var queryChangedOnInit = false;
  var tabChangedOnInitFlag = false;
  var locationChanged = false;
  var selectedTabChangeIsBeingHandled = false;
  var queryChangeIsBeingHandled = false;
  var relatedObjects = [];

  //Information for the different tabs
  var tabs = [{
    title: 'search-management.tabs.studies',
    inputLabel: 'search-management.input-label.studies',
    icon: 'assets/images/icons/study.svg',
    elasticSearchType: 'studies',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.studies',
    group: 'studies'
  }, {
    title: 'search-management.tabs.surveys',
    inputLabel: 'search-management.input-label.surveys',
    icon: 'assets/images/icons/survey.svg',
    elasticSearchType: 'surveys',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.surveys',
    group: 'surveys'
  }, {
    title: 'search-management.tabs.instruments',
    inputLabel: 'search-management.input-label.instruments',
    icon: 'assets/images/icons/instrument.svg',
    elasticSearchType: 'instruments',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.instruments',
    group: 'instruments'
  }, {
    title: 'search-management.tabs.questions',
    inputLabel: 'search-management.input-label.questions',
    icon: 'assets/images/icons/question.svg',
    elasticSearchType: 'questions',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.questions',
    group: 'questions'
  }, {
    title: 'search-management.tabs.data_sets',
    inputLabel: 'search-management.input-label.data-sets',
    icon: 'assets/images/icons/data-set.svg',
    elasticSearchType: 'data_sets',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.data-sets',
    group: 'dataSets'
  }, {
    title: 'search-management.tabs.variables',
    inputLabel: 'search-management.input-label.variables',
    icon: 'assets/images/icons/variable.svg',
    elasticSearchType: 'variables',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.variables',
    group: 'variables'
  }, {
    title: 'search-management.tabs.related_publications',
    inputLabel: 'search-management.input-label.related-publications',
    icon: 'assets/images/icons/related-publication.svg',
    elasticSearchType: 'related_publications',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.related-publications',
    group: 'publications'
  }, {
    title: 'search-management.tabs.concepts',
    inputLabel: 'search-management.input-label.concepts',
    icon: 'assets/images/icons/concept.svg',
    elasticSearchType: 'concepts',
    count: null,
    uploadFunction: null,
    disabled: false,
    visibleForPublicUser: true,
    noResultsText: 'search-management.no-results-text.concepts',
    group: 'concepts'
  }];

  var tabsFilter = function(data) {
    tabs.forEach(function(tab, index) {
      var prop = tab.group + 'Count';
      if (data.hasOwnProperty(prop)) {
        tabs[index].count = data[prop];
        relatedObjects.push(tabs[index]);
      }
    });
  };
  var getSelectedMetadataType = function() {
    return $scope.tabs[$scope.searchParams.selectedTabIndex]
      .elasticSearchType;
  };
  // write the searchParams object to the location with the correct types
  var writeSearchParamsToLocation = function() {
    var locationSearch = {};
    locationSearch.page = '' + $scope.options.pageObject.page;
    locationSearch.size = '' + $scope.options.pageObject.size;
    try {
      locationSearch.type = $scope.tabs[
        $scope.searchParams.selectedTabIndex].elasticSearchType;
    } catch (e) {
      $scope.searchParams.selectedTabIndex = 0;
      locationSearch.type = $scope.tabs[
        $scope.searchParams.selectedTabIndex].elasticSearchType;
    }
    if ($scope.searchParams.query && $scope.searchParams.query !== '') {
      locationSearch.query = $scope.searchParams.query;
    }
    if ($scope.searchParams.sortBy && $scope.searchParams.sortBy !== '') {
      locationSearch['sort-by'] = $scope.searchParams.sortBy;
    } else {
      delete locationSearch['sort-by'];
    }
    _.assign(locationSearch, $scope.searchParams.filter);
    locationChanged = !angular.equals($location.search(),
      locationSearch);
    // Todo: Find solution for breadcrumbs error when selecting a tab
    // Changed from $location.search to $location.replace
    // Negative: We can not link to the selected tab in the details page
    $location.replace(locationSearch);
  };

  // read the searchParams object from the location with the correct types
  var readSearchParamsFromLocation = function() {
    var locationSearch = $location.search();
    if (CleanJSObjectService.isNullOrEmpty(locationSearch)) {
      $scope.options.pageObject.page = 1;
      $scope.options.pageObject.size = 10;
      $scope.searchParams = {
        query: '',
        size: $scope.options.pageObject.size,
        selectedTabIndex: 0
      };
    } else {
      if (locationSearch.page != null) {
        $scope.options.pageObject.page = parseInt(locationSearch.page);
      } else {
        $scope.options.pageObject.page = 1;
      }
      if (locationSearch.size != null) {
        $scope.options.pageObject.size = parseInt(locationSearch.size);
        $scope.searchParams.size = $scope.options.pageObject.size;
      } else {
        $scope.options.pageObject.size = 10;
        $scope.searchParams.size = $scope.options.pageObject.size;
{'fraction_non_alphanumeric': 0.12654924983692106, 'fraction_numerical': 0.001304631441617743, 'mean_word_length': 3.4664967225054624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2684085', 'n_tokens_mistral': 3695, 'n_tokens_neox': 3626, 'n_words': 671}