<commit_before>define([
  'text!./cam-tasklist-task.html'
], function(template) {
  'use strict';

  function fixReadDateTimezone(dateStr) {
    if (!dateStr) { return dateStr; }
    var d = new Date(dateStr);
    return (new Date(d.getTime() + (d.getTimezoneOffset() * 60 * 1000))).toJSON();
  }

  return [
    '$rootScope',
    '$location',
    'camUID',
    'camAPI',
  function(
    $rootScope,
    $location,
    camUID,
    camAPI
  ) {
    var Task = camAPI.resource('task');

    $rootScope.batchActions = {};
    $rootScope.batchActions.selected = [];

    return {
      scope: {
        task: '='
      },

      template: template,

      link: function(scope, element) {
        var _scopeEvents = [];
        element.on('$destroy', function() {
          if (!_scopeEvents.length) { return; }
          angular.forEach(_scopeEvents, function(fn) { fn(); });
        });

		    //active tabs
        scope.tabs = {
          form: true,
          description: false,
          history: false,
          diagram: false
        };

        scope.elUID = camUID();

        function refreshTabs() {
          var activePane = element.find('.tab-pane.active > div');
          var paneScope = activePane.hasClass('ng-isolated-scope') ?
                          activePane.isolateScope() :
                          activePane.scope();

          if (activePane.hasClass('diagram-pane')) {
            paneScope.drawDiagram();
          }
        }


        function loadTask(taskId) {
          Task.get(taskId, function(err, loadedTask) {
            if (err) { throw err; }


            loadedTask.due = fixReadDateTimezone(loadedTask.due);
            loadedTask.followUp = fixReadDateTimezone(loadedTask.followUp);

            scope.task = loadedTask;
            if (!$rootScope.currentTask || $rootScope.currentTask.id !== loadedTask.id) {
              $rootScope.currentTask = loadedTask;
            }
            refreshTabs();
          });
        }


        function setTask(newTask) {
          if (newTask && newTask.id) {
            if (!$rootScope.currentTask || $rootScope.currentTask.id !== newTask.id) {
              $rootScope.currentTask = newTask;
            }
            scope.task = newTask;
            return;
          }

          var state = $location.search();
          var urlTaskId = state.task;

          if ($rootScope.currentTask) {
            if (urlTaskId && urlTaskId === $rootScope.currentTask.id) {
              scope.task = $rootScope.currentTask;
              refreshTabs();
            }
            else if (urlTaskId) {
              loadTask(urlTaskId);
            }
          }
          else if(urlTaskId) {
            loadTask(urlTaskId);
          }
          else {
            // should we load the next task?
            // that would happen here
            scope.task = null;
            refreshTabs();
          }
        }

        scope.selectTab = function(tabName) {<commit_msg>refactor(task): simplify the current task check<commit_after>define([
  'text!./cam-tasklist-task.html'
], function(template) {
  'use strict';

  function fixReadDateTimezone(dateStr) {
    if (!dateStr) { return dateStr; }
    var d = new Date(dateStr);
    return (new Date(d.getTime() + (d.getTimezoneOffset() * 60 * 1000))).toJSON();
  }

  return [
    '$rootScope',
    '$location',
    'camUID',
    'camAPI',
  function(
    $rootScope,
    $location,
    camUID,
    camAPI
  ) {
    var Task = camAPI.resource('task');

    $rootScope.batchActions = {};
    $rootScope.batchActions.selected = [];

    return {
      scope: {
        task: '='
      },

      template: template,

      link: function(scope, element) {
        var _scopeEvents = [];
        element.on('$destroy', function() {
          if (!_scopeEvents.length) { return; }
          angular.forEach(_scopeEvents, function(fn) { fn(); });
        });

		    //active tabs
        scope.tabs = {
          form: true,
          description: false,
          history: false,
          diagram: false
        };

        scope.elUID = camUID();

        function refreshTabs() {
          var activePane = element.find('.tab-pane.active > div');
          var paneScope = activePane.hasClass('ng-isolated-scope') ?
                          activePane.isolateScope() :
                          activePane.scope();

          if (activePane.hasClass('diagram-pane')) {
            paneScope.drawDiagram();
          }
        }


        function loadTask(taskId) {
          Task.get(taskId, function(err, loadedTask) {
            if (err) { throw err; }


            loadedTask.due = fixReadDateTimezone(loadedTask.due);
            loadedTask.followUp = fixReadDateTimezone(loadedTask.followUp);

            scope.task = loadedTask;
            if (!$rootScope.currentTask || $rootScope.currentTask.id !== loadedTask.id) {
              $rootScope.currentTask = loadedTask;
            }
            refreshTabs();
          });
        }


        function setTask(newTask) {
          var state = $location.search();
          var urlTaskId = state.task;

          if(
            urlTaskId &&
            (
              !scope.task ||
              (scope.task && scope.task.id !== urlTaskId)
            )
          ) {
            loadTask(urlTaskId);
          }
          else {
            // should we load the next task?
            // that would happen here
            scope.task = null;
            refreshTabs();
          }
        }

        scope.selectTab = function(tabName) {
{'fraction_non_alphanumeric': 0.12642019837691615, 'fraction_numerical': 0.002164111812443643, 'mean_word_length': 1.6197449220595181, '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': '1460786', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1543, 'n_words': 294}