<commit_before>// ### Search
//
// lookup for saved searches
/*jslint browser: true */
/*jslint node: true */
/* global $,alert */
'use strict';

var savedSearches, context;
var _ = require('lodash');

var sline = _.template('<tr onclick=\'javascript:$("#loadSearch").val("<%= searchName %>")\'><td><div class="ui icon button"><i class="remove icon"></i></div></td><td><%= searchName %></td><td><a><%= categories %></a></td><td><%= hits %><td><%= team %></td><td><%= input %></td><td><%= cron %></td><td><%= lastRun %></td></tr>');

exports.init = function(ctx) {
  context = ctx;
  // set team input as select2 input
  $('.team.container').select2();
  setupCronInput();

  // show search scheduler according to checkbox
  $('#scheduleSearch').on('change', function() {
    $('#scheduleInput').toggle(this.checked);
  });

  $('input.cron').val();

  $('.load.search').click(function() {
    $('.load.modal').modal('show');
  });
  
  // setup semantic-ui form validation
  $('.searching.form').form(
    {
      searchInput: {
        identifier  : 'searchInput',
        rules: [
          {
            type   : 'empty',
            prompt : 'Please enter member input'
          }
        ]
      },
      searchCategories: {
        identifier : 'searchCategories',
        rules: [
          {
            type   : 'empty',
            prompt : 'Please enter one or more comma-seperated categories'
          }
        ]
      },
      searchTeam: {
        identifier : 'searchTeam',
        rules: [
          {
            type   : 'empty',
            prompt : 'Please enter one or more members'
          }
        ]
      }
    },
    {
      onSuccess: submitSearch
    }
  );

// Retreive existing searches.
  context.pubsub.subSearches(function(results) {
    savedSearches = results;
    if (results && results.hits.total > 0) {
      // display saved searches
      $('#savedSearches tbody').html('');
      _.pluck(results.hits.hits, '_source').forEach(function(i) {
        i.lastRun = 'Never';
        i.hits = 0;
        $('#savedSearches tbody').append(sline(i));
      });
      /*
      $("#loadSearch").select2({
        data: results.hits.hits.map(function(i) { return { id: i._source.searchName, text: i._source.searchName }; })
      });
      */
    }
  });

  // save a search
  $('.save.search').click(function() {
    var searchInput = getSearchInput();
    if (searchInput.valid && searchInput.searchName.length > 0) {
      context.pubsub.searchSave(searchInput);
    } else {
      alert('Missing parameters');
    }
  });

  // load a search
  $('.confirm.search.load').click(function() {
    var v = $('#loadSearch').val();
    savedSearches.hits.hits.forEach(function(s) {
      if (s._source.searchName === v) {
        var r = s._source;
        if (r.cron) {
          $('input.cron').val(r.cron);
          $('#scheduleSearch').prop('checked', true);
        } else {
          $('#scheduleSearch').prop('checked', false);
        }
        setupCronInput(r.cron);
        $('#scheduleSearch').trigger('change');
        $('#searchName').val(v);
        $('#targetResults').val(r.targetResults);
        $('#searchInput').val(r.input);
        $('#searchContinue').val(r.relevance);
        $('#searchCategories').val(r.categories);
        $('select.searching.team').val(r.team);
        $('.team.container').select2('val', r.team);
        return;
      }
    });
  });
  // set up the cron scheduler input
  function setupCronInput(val) {
    $('input.cron').jqCron({
      enabled_minute: false,
      multiple_dom: true,
      multiple_month: true,
      multiple_mins: true,<commit_msg>add minutes<commit_after>// ### Search
//
// lookup for saved searches
/*jslint browser: true */
/*jslint node: true */
/* global $,alert */
'use strict';

var savedSearches, context;
var _ = require('lodash');

var sline = _.template('<tr onclick=\'javascript:$("#loadSearch").val("<%= searchName %>")\'><td><div class="ui icon button"><i class="remove icon"></i></div></td><td><%= searchName %></td><td><a><%= categories %></a></td><td><%= hits %><td><%= team %></td><td><%= input %></td><td><%= cron %></td><td><%= lastRun %></td></tr>');

exports.init = function(ctx) {
  context = ctx;
  // set team input as select2 input
  $('.team.container').select2();
  setupCronInput();

  // show search scheduler according to checkbox
  $('#scheduleSearch').on('change', function() {
    $('#scheduleInput').toggle(this.checked);
  });

  $('input.cron').val();

  $('.load.search').click(function() {
    $('.load.modal').modal('show');
  });

  // setup semantic-ui form validation
  $('.searching.form').form(
    {
      searchInput: {
        identifier  : 'searchInput',
        rules: [
          {
            type   : 'empty',
            prompt : 'Please enter member input'
          }
        ]
      },
      searchCategories: {
        identifier : 'searchCategories',
        rules: [
          {
            type   : 'empty',
            prompt : 'Please enter one or more comma-seperated categories'
          }
        ]
      },
      searchTeam: {
        identifier : 'searchTeam',
        rules: [
          {
            type   : 'empty',
            prompt : 'Please enter one or more members'
          }
        ]
      }
    },
    {
      onSuccess: submitSearch
    }
  );

// Retreive existing searches.
  context.pubsub.subSearches(function(results) {
    savedSearches = results;
    if (results && results.hits.total > 0) {
      // display saved searches
      $('#savedSearches tbody').html('');
      _.pluck(results.hits.hits, '_source').forEach(function(i) {
        i.lastRun = 'Never';
        i.hits = 0;
        $('#savedSearches tbody').append(sline(i));
      });
      /*
      $("#loadSearch").select2({
        data: results.hits.hits.map(function(i) { return { id: i._source.searchName, text: i._source.searchName }; })
      });
      */
    }
  });

  // save a search
  $('.save.search').click(function() {
    var searchInput = getSearchInput();
    if (searchInput.valid && searchInput.searchName.length > 0) {
      context.pubsub.searchSave(searchInput);
    } else {
      alert('Missing parameters');
    }
  });

  // load a search
  $('.confirm.search.load').click(function() {
    var v = $('#loadSearch').val();
    savedSearches.hits.hits.forEach(function(s) {
      if (s._source.searchName === v) {
        var r = s._source;
        if (r.cron) {
          $('input.cron').val(r.cron);
          $('#scheduleSearch').prop('checked', true);
        } else {
          $('#scheduleSearch').prop('checked', false);
        }
        setupCronInput(r.cron);
        $('#scheduleSearch').trigger('change');
        $('#searchName').val(v);
        $('#targetResults').val(r.targetResults);
        $('#searchInput').val(r.input);
        $('#searchContinue').val(r.relevance);
        $('#searchCategories').val(r.categories);
        $('select.searching.team').val(r.team);
        $('.team.container').select2('val', r.team);
        return;
      }
    });
  });
  // set up the cron scheduler input
  function setupCronInput(val) {
    $('input.cron').jqCron({
      enabled_minute: true,
      multiple_dom: true,
      multiple_month: true,
      multiple_mins: true,
{'fraction_non_alphanumeric': 0.193805918788713, 'fraction_numerical': 0.0019270474879559533, 'mean_word_length': 2.3360881542699725, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 69, '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': '2178292', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2245, 'n_words': 422}