<commit_before>'use strict';
var fs = require('fs');

var template = fs.readFileSync(__dirname + '/cam-tasklist-sorting-choices.html', 'utf8');

var angular = require('camunda-commons-ui/vendor/angular');
var $ = require('jquery');

function stringifySortings(sortingQuery) {
  return JSON.stringify(sortingQuery.map(function(sorting) {
    var obj = {
      sortBy: sorting.by,
      sortOrder: sorting.order
    };

    if (sorting.by.indexOf('Variable') > -1) {
      if (!sorting.parameters) {
        throw new Error('Variable sorting needs parameters');
      }
      obj.parameters = sorting.parameters;
    }

    return obj;
  }));
}

module.exports = [
  'search',
  '$translate',
  '$location',
  '$timeout',
  function(
    search,
    $translate,
    $location,
    $timeout
  ) {
    return {

      restrict: 'A',

      scope: {
        tasklistData: '='
      },

      template: template,

      controller: [function() {}],

      link: function(scope, element) {
        var $bdy = $('body');
        var $newSort = element.find('.new-sort .dropdown-menu');

        scope.sortings = [{
          order:    'desc',
          by:       'created'
        }];

        scope.openDropdowns = [];
        scope.openDropdownNew = false;

        scope.sortedOn = [];

        var plannedRefresh;
        function updateColumns() {
          if (plannedRefresh) {
            $timeout.cancel(plannedRefresh);
          }

          plannedRefresh = $timeout(function() {
            var columns = $(element).parents('.columns');
            var headers = columns.find('.cell.top');
            var bodies = columns.find('.cell.content');
            var shown = $bdy.hasClass('list-column-close');

            element.css('height', 'auto');

            if (shown) {
              var minHeight = parseInt(headers.css('min-height'), 10);
              headers.css('height', minHeight);
              bodies.css('top', minHeight);
              return;
            }

            var height = $(element).height();
            var columnTop = element.parent();
            $(columnTop).height(height);
            var columnTopHeight = height;

            headers.height(columnTopHeight);
            bodies.css('top', columnTopHeight + 12);
            plannedRefresh = null;
          }, 100);
        }

        scope.$on('layout:change', updateColumns);

        scope.uniqueProps = {
          priority:               $translate.instant('PRIORITY'),
          created:                $translate.instant('CREATION_DATE'),
          dueDate:                $translate.instant('DUE_DATE'),
          followUpDate:           $translate.instant('FOLLOW_UP_DATE'),
          nameCaseInsensitive:    $translate.instant('TASK_NAME'),
          assignee:               $translate.instant('ASSIGNEE')
        };

        scope.byLabel = function(index) {
          if (!scope.sortings[index]) {
            return '';
          }

          var by = scope.sortings[index].by;

          if (scope.uniqueProps[by]) {
            return scope.uniqueProps[by];
          }

          if (!scope.sortings[index] || !scope.sortings[index].parameters) {
            return '';
          }

          return scope.sortings[index].parameters.variable;
        };

        /**
         * observe the task list query
         */
        var tasklistData = scope.tasklistData.newChild(scope);

        tasklistData.observe('taskListQuery', function(taskListQuery) {
          if (taskListQuery) {
            var urlSortings = JSON.parse(($location.search() || {}).sorting || '[]');

            scope.sortedOn = [];
            scope.openDropdowns = [];

            scope.availableOptions = angular.copy(scope.uniqueProps);

            scope.sortings = urlSortings.map(function(sorting) {
              scope.sortedOn.push(sorting.sortBy);
              scope.openDropdowns.push(false);

              delete scope.availableOptions[sorting.sortBy];

              var returned = {
                order:      sorting.sortOrder,
                by:         sorting.sortBy
              };

              if (sorting.parameters) {
                returned.parameters = sorting.parameters;
              }

              return returned;
            });


            if (!scope.sortings.length) {
              scope.addSorting('created');
            }

            updateColumns();
          }
        });


        scope.$watch('sortings.length', function(now, before) {
          if (now !== before) { scope.updateSortings(); }
        });

        scope.$watch('sortings', updateColumns, true);

        function positionDropdown(el) {
          var edgeLeft = el.parent().position().left;
          var edgeRight = el.outerWidth() + edgeLeft;<commit_msg>fix(tasklist): do not focus add sorting field initially<commit_after>'use strict';
var fs = require('fs');

var template = fs.readFileSync(__dirname + '/cam-tasklist-sorting-choices.html', 'utf8');

var angular = require('camunda-commons-ui/vendor/angular');
var $ = require('jquery');

function stringifySortings(sortingQuery) {
  return JSON.stringify(sortingQuery.map(function(sorting) {
    var obj = {
      sortBy: sorting.by,
      sortOrder: sorting.order
    };

    if (sorting.by.indexOf('Variable') > -1) {
      if (!sorting.parameters) {
        throw new Error('Variable sorting needs parameters');
      }
      obj.parameters = sorting.parameters;
    }

    return obj;
  }));
}

module.exports = [
  'search',
  '$translate',
  '$location',
  '$timeout',
  function(
    search,
    $translate,
    $location,
    $timeout
  ) {
    return {

      restrict: 'A',

      scope: {
        tasklistData: '='
      },

      template: template,

      controller: [function() {}],

      link: function(scope, element) {
        var $bdy = $('body');
        var $newSort = element.find('.new-sort .dropdown-menu');

        scope.sortings = [{
          order:    'desc',
          by:       'created'
        }];

        scope.openDropdowns = [];
        scope.openDropdownNew = false;

        scope.sortedOn = [];

        var plannedRefresh;
        function updateColumns() {
          if (plannedRefresh) {
            $timeout.cancel(plannedRefresh);
          }

          plannedRefresh = $timeout(function() {
            var columns = $(element).parents('.columns');
            var headers = columns.find('.cell.top');
            var bodies = columns.find('.cell.content');
            var shown = $bdy.hasClass('list-column-close');

            element.css('height', 'auto');

            if (shown) {
              var minHeight = parseInt(headers.css('min-height'), 10);
              headers.css('height', minHeight);
              bodies.css('top', minHeight);
              return;
            }

            var height = $(element).height();
            var columnTop = element.parent();
            $(columnTop).height(height);
            var columnTopHeight = height;

            headers.height(columnTopHeight);
            bodies.css('top', columnTopHeight + 12);
            plannedRefresh = null;
          }, 100);
        }

        scope.$on('layout:change', updateColumns);

        scope.uniqueProps = {
          priority:               $translate.instant('PRIORITY'),
          created:                $translate.instant('CREATION_DATE'),
          dueDate:                $translate.instant('DUE_DATE'),
          followUpDate:           $translate.instant('FOLLOW_UP_DATE'),
          nameCaseInsensitive:    $translate.instant('TASK_NAME'),
          assignee:               $translate.instant('ASSIGNEE')
        };

        scope.byLabel = function(index) {
          if (!scope.sortings[index]) {
            return '';
          }

          var by = scope.sortings[index].by;

          if (scope.uniqueProps[by]) {
            return scope.uniqueProps[by];
          }

          if (!scope.sortings[index] || !scope.sortings[index].parameters) {
            return '';
          }

          return scope.sortings[index].parameters.variable;
        };

        /**
         * observe the task list query
         */
        var tasklistData = scope.tasklistData.newChild(scope);

        tasklistData.observe('taskListQuery', function(taskListQuery) {
          if (taskListQuery) {
            var urlSortings = JSON.parse(($location.search() || {}).sorting || '[]');

            scope.sortedOn = [];
            scope.openDropdowns = [];

            scope.availableOptions = angular.copy(scope.uniqueProps);

            scope.sortings = urlSortings.map(function(sorting) {
              scope.sortedOn.push(sorting.sortBy);
              scope.openDropdowns.push(false);

              delete scope.availableOptions[sorting.sortBy];

              var returned = {
                order:      sorting.sortOrder,
                by:         sorting.sortBy
              };

              if (sorting.parameters) {
                returned.parameters = sorting.parameters;
              }

              return returned;
            });


            if (!scope.sortings.length) {
              // sort by created (descending) by default
              scope.sortings.push({
                order: 'desc',
                by: 'created'
              });
              scope.updateSortings();
            }

            updateColumns();
          }
        });


        scope.$watch('sortings.length', function(now, before) {
          if (now !== before) { scope.updateSortings(); }
        });

        scope.$watch('sortings', updateColumns, true);

        function positionDropdown(el) {
          var edgeLeft = el.parent().position().left;
          var edgeRight = el.outerWidth() + edgeLeft;
{'fraction_non_alphanumeric': 0.13275064267352185, 'fraction_numerical': 0.0018508997429305912, 'mean_word_length': 1.7435825105782792, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7490593', 'n_tokens_mistral': 2677, 'n_tokens_neox': 2546, 'n_words': 463}