<commit_before>'use strict';

angular.module('myApp.view-task', ['ngRoute', 'angularModalService'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/task/:taskId?', {
    templateUrl: 'view-task/view-task.html',
    controller: 'viewTaskCtrl'
  });
}])

.controller('viewTaskCtrl', ['$scope', '$filter', '$routeParams', '$location', '$document', 'ModalService', 'TaskList', 'ShiftList', 'focus', 
	function($scope, $filter, $routeParams, $location, $document, ModalService, TaskList, ShiftList, focus) {

  $scope.openRecord = function () {

    ModalService.showModal({
      templateUrl: "components/zyski/findTaskId.html",
      controller: "findTaskIdCtrl",
      inputs: {
        currentId: $scope.record.id,
      }
    }).then(function(modal) {
      // modal now on screen
      modal.close.then(function(result) {
        if (result) {
          $scope.settings.taskId = result;
          $location.path('task/' + result);
        }
      });
    });
  }

  $scope.saveRecord = function () {
    var id = $scope.record.id;
    $scope.record = TaskList.save($scope.record);
    $scope.master = angular.copy($scope.record);
    if ($scope.record.id === id) {
      $scope.init();
    } else {
      $location.path('task/' + $scope.record.id);
    }
  };

  $scope.revertRecord = function () {
    angular.copy($scope.master, $scope.record);
  };

  $scope.createRecord = function () {
    $location.path('task/new');
  };

  $scope.recordChanged = function () {
    if (angular.equals($scope.record, $scope.master)) {
      return "btn-default";
    } else {
      return "btn-warning";
    }
  };

  // Object to store user settings
  function Settings (json) {
    if (!json) json = {};
    // Last task opened
    this.taskId = json.taskId || null;
    // Summary report type
    this.summary = {};
    this.summary.type = 1;
    if (json.summary && json.summary.type > -1) {
      this.summary.type = json.summary.type;
    }
  }

  function loadSettings () {
    // Load settings
    if ('task' in localStorage) {
      $scope.settings = new Settings(angular.fromJson(localStorage['task']));
    } else {
      $scope.settings = new Settings();
    }
  }

  function saveSettings () {
    localStorage['task'] = angular.toJson($scope.settings);
  }

  $scope.setSummaryReport = function (type) {
    if (type > -1 && $scope.summary.types.length) {
      $scope.settings.summary.type = type;
    }
    $scope.summary.typeName = $scope.summary.types[$scope.settings.summary.type];

    saveSettings();
    $scope.runSummaryReport();
  };


  $scope.runSummaryReport = function () {
    var now = new Date();
    switch ($scope.settings.summary.type) {
      case 1:
        // this week (Monday-Sunday). Sunday=0 in javascript so change to 7 to make calcs easier
        var day = now.getDay() || 7;
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1 - day);
        $scope.summary.end = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 7 - day);
        break;

      case 2:
        // this calendar month
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), 1);
        $scope.summary.end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
        break;

      case 3:
        // Last seven days
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 6);
        $scope.summary.end = new Date(now);
        break;

      case 4:
        // Last fourteen days
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 13);
        $scope.summary.end = new Date(now);
        break;

      case 5:
        // Last twenty days
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 19);
        $scope.summary.end = new Date(now);
        break;

      case 6:
        // Last 365 days
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 364);
        $scope.summary.end = new Date(now);
        break;

      case 0:
      default:
        // today
        $scope.summary.start = new Date(now);
        $scope.summary.end = new Date(now);
        break;
    };
    
    $scope.summary.report = ShiftList.reportTask($scope.record, $scope.summary.start, $scope.summary.end);
  };


  $scope.init = function () {
    $scope.params = $routeParams;
    loadSettings();

    if ($scope.params.taskId) {
      // Use route
      $scope.settings.taskId = $scope.params.taskId;
    } else {
      // Use last task viewed
      if ($scope.settings.taskId) {
        $location.path('task/' + $scope.settings.taskId);
        return;
      }
    }

    $scope.summary = {};
    $scope.summary.types = ['Today', 'This Week', 'This Month', 'Last 7 days', 'Last 14 days', 'Last 20 days', 'Last 365 days'];<commit_msg>Add 'This FY' and 'Last FY' task reports<commit_after>'use strict';

angular.module('myApp.view-task', ['ngRoute', 'angularModalService'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/task/:taskId?', {
    templateUrl: 'view-task/view-task.html',
    controller: 'viewTaskCtrl'
  });
}])

.controller('viewTaskCtrl', ['$scope', '$filter', '$routeParams', '$location', '$document', 'ModalService', 'TaskList', 'ShiftList', 'focus', 
	function($scope, $filter, $routeParams, $location, $document, ModalService, TaskList, ShiftList, focus) {

  $scope.openRecord = function () {

    ModalService.showModal({
      templateUrl: "components/zyski/findTaskId.html",
      controller: "findTaskIdCtrl",
      inputs: {
        currentId: $scope.record.id,
      }
    }).then(function(modal) {
      // modal now on screen
      modal.close.then(function(result) {
        if (result) {
          $scope.settings.taskId = result;
          $location.path('task/' + result);
        }
      });
    });
  }

  $scope.saveRecord = function () {
    var id = $scope.record.id;
    $scope.record = TaskList.save($scope.record);
    $scope.master = angular.copy($scope.record);
    if ($scope.record.id === id) {
      $scope.init();
    } else {
      $location.path('task/' + $scope.record.id);
    }
  };

  $scope.revertRecord = function () {
    angular.copy($scope.master, $scope.record);
  };

  $scope.createRecord = function () {
    $location.path('task/new');
  };

  $scope.recordChanged = function () {
    if (angular.equals($scope.record, $scope.master)) {
      return "btn-default";
    } else {
      return "btn-warning";
    }
  };

  // Object to store user settings
  function Settings (json) {
    if (!json) json = {};
    // Last task opened
    this.taskId = json.taskId || null;
    // Summary report type
    this.summary = {};
    this.summary.type = 1;
    if (json.summary && json.summary.type > -1) {
      this.summary.type = json.summary.type;
    }
  }

  function loadSettings () {
    // Load settings
    if ('task' in localStorage) {
      $scope.settings = new Settings(angular.fromJson(localStorage['task']));
    } else {
      $scope.settings = new Settings();
    }
  }

  function saveSettings () {
    localStorage['task'] = angular.toJson($scope.settings);
  }

  $scope.setSummaryReport = function (type) {
    if (type > -1 && $scope.summary.types.length) {
      $scope.settings.summary.type = type;
    }
    $scope.summary.typeName = $scope.summary.types[$scope.settings.summary.type];

    saveSettings();
    $scope.runSummaryReport();
  };


  $scope.runSummaryReport = function () {
    var now = new Date();
    switch ($scope.settings.summary.type) {
      case 1:
        // this week (Monday-Sunday). Sunday=0 in javascript so change to 7 to make calcs easier
        var day = now.getDay() || 7;
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1 - day);
        $scope.summary.end = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 7 - day);
        break;

      case 2:
        // this calendar month
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), 1);
        $scope.summary.end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
        break;

      case 3:
        // this FY
        $scope.summary.start = new Date(now.getMonth() < 7 ? now.getFullYear() - 1 : now.getFullYear(), 6, 1);
        $scope.summary.end = new Date(now);
        break;

      case 4:
        // last FY
        $scope.summary.start = new Date(now.getMonth() < 7 ? now.getFullYear() - 2 : now.getFullYear() - 1, 6, 1);
        $scope.summary.end = new Date($scope.summary.start.getFullYear() + 1, 5, 30);
        break;

      case 5:
        // Last seven days
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 6);
        $scope.summary.end = new Date(now);
        break;

      case 6:
        // Last fourteen days
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 13);
        $scope.summary.end = new Date(now);
        break;

      case 7:
        // Last twenty days
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 19);
        $scope.summary.end = new Date(now);
        break;

      case 8:
        // Last 365 days
        $scope.summary.start = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 364);
        $scope.summary.end = new Date(now);
        break;

      case 0:
      default:
        // today
        $scope.summary.start = new Date(now);
        $scope.summary.end = new Date(now);
        break;
    };
    
    $scope.summary.report = ShiftList.reportTask($scope.record, $scope.summary.start, $scope.summary.end);
  };


  $scope.init = function () {
    $scope.params = $routeParams;
    loadSettings();

    if ($scope.params.taskId) {
      // Use route
      $scope.settings.taskId = $scope.params.taskId;
    } else {
      // Use last task viewed
      if ($scope.settings.taskId) {
        $location.path('task/' + $scope.settings.taskId);
        return;
      }
    }

    $scope.summary = {};
    $scope.summary.types = ['Today', 'This Week', 'This Month', 'This FY', 'Last FY', 'Last 7 days', 'Last 14 days', 'Last 20 days', 'Last 365 days'];
{'fraction_non_alphanumeric': 0.16606427664354792, 'fraction_numerical': 0.008693953306632803, 'mean_word_length': 2.4658090724441437, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3364567', 'n_tokens_mistral': 3349, 'n_tokens_neox': 3191, 'n_words': 692}