<commit_before>/* global Rickshaw:false */
(function () {
  'use strict';

  angular.module('app.organization')
    .controller('organization.Manage', ['$ExceptionlessClient', 'filterService', '$filter', '$state', '$stateParams', '$window', 'billingService', 'dialogService', 'organizationService', 'projectService', 'userService', 'notificationService', 'dialogs', 'STRIPE_PUBLISHABLE_KEY', function ($ExceptionlessClient, filterService, $filter, $state, $stateParams, $window, billingService, dialogService, organizationService, projectService, userService, notificationService, dialogs, STRIPE_PUBLISHABLE_KEY) {
      var source = 'organization.Manage';
      var _ignoreRefresh = false;
      var _organizationId = $stateParams.id;
      var vm = this;

      function activateTab(tabName) {
        vm.tabBillingActive = tabName === 'billing';
        vm.tabProjectsActive = tabName === 'projects';
        vm.tabUsersActive = tabName === 'users';
      }

      function addUser() {
        return dialogs.create('app/organization/manage/add-user-dialog.tpl.html', 'AddUserDialog as vm').result.then(createUser);
      }

      function canChangePlan() {
        return STRIPE_PUBLISHABLE_KEY && vm.organization;
      }

      function changePlan() {
        return billingService.changePlan(vm.organization.id);
      }

      function createUser(emailAddress) {
        function onFailure(response) {
          if (response.status === 426) {
            return billingService.confirmUpgradePlan(response.data.message).then(function() {
              return createUser(emailAddress);
            });
          }

          var message = 'An error occurred while inviting the user.';
          if (response.data && response.data.message) {
            message += ' Message: ' + response.data.message;
          }

          notificationService.error(message);
        }

        return organizationService.addUser(_organizationId, emailAddress).catch(onFailure);
      }

      function get(data) {
        if (_ignoreRefresh) {
          return;
        }

        if (data && data.type === 'Organization' && data.deleted && data.id === _organizationId) {
          $state.go('app.dashboard');
          notificationService.error('The organization "' + _organizationId + '" was deleted.');
          return;
        }

        return getOrganization();
      }

      function getOrganization() {
        function onSuccess(response) {
          vm.organization = response.data.plain();
          vm.organization.usage = vm.organization.usage || [];
          vm.hasMonthlyUsage = vm.organization.max_events_per_month > 0;

          vm.chart.options.series[0].data = vm.organization.usage.map(function (item) {
            return {x: moment.utc(item.date).unix(), y: item.total - item.blocked - item.too_big, data: item};
          });

          vm.chart.options.series[1].data = vm.organization.usage.map(function (item) {
            return {x: moment.utc(item.date).unix(), y: item.blocked, data: item};
          });

          vm.chart.options.series[2].data = vm.organization.usage.map(function (item) {
            return {x: moment.utc(item.date).unix(), y: item.too_big, data: item};
          });

          vm.chart.options.series[3].data = vm.organization.usage.map(function (item) {
            return {x: moment.utc(item.date).unix(), y: item.limit, data: item};
          });
        }

        function onFailure() {
          $state.go('app.dashboard');
          notificationService.error('The organization "' + _organizationId + '" could not be found.');
        }

        return organizationService.getById(_organizationId, false).then(onSuccess, onFailure);
      }

      function getRemainingEventLimit() {
        if (!vm.organization.max_events_per_month) {
          return 0;
        }

        var bonusEvents = moment.utc().isBefore(moment.utc(vm.organization.bonus_expiration)) ? vm.organization.bonus_events_per_month : 0;
        var usage = vm.organization.usage && vm.organization.usage[vm.organization.usage.length - 1];
        if (usage && moment.utc(usage.date).isSame(moment.utc().startOf('month'))) {
          var remaining = usage.limit - usage.total;
          return remaining > 0 ? remaining : 0;
        }

        return vm.organization.max_events_per_month + bonusEvents;
      }

      function hasAdminRole(user) {
        return userService.hasAdminRole(user);
      }

      function hasPremiumFeatures() {
        return vm.organization && vm.organization.has_premium_features;
      }<commit_msg>Update manage-controller.js<commit_after>/* global Rickshaw:false */
(function () {
  'use strict';

  angular.module('app.organization')
    .controller('organization.Manage', ['$ExceptionlessClient', 'filterService', '$filter', '$state', '$stateParams', '$window', 'billingService', 'dialogService', 'organizationService', 'projectService', 'userService', 'notificationService', 'dialogs', 'STRIPE_PUBLISHABLE_KEY', function ($ExceptionlessClient, filterService, $filter, $state, $stateParams, $window, billingService, dialogService, organizationService, projectService, userService, notificationService, dialogs, STRIPE_PUBLISHABLE_KEY) {
      var source = 'organization.Manage';
      var _ignoreRefresh = false;
      var _organizationId = $stateParams.id;
      var vm = this;

      function activateTab(tabName) {
        vm.tabBillingActive = tabName === 'billing';
        vm.tabProjectsActive = tabName === 'projects';
        vm.tabUsersActive = tabName === 'users';
      }

      function addUser() {
        return dialogs.create('app/organization/manage/add-user-dialog.tpl.html', 'AddUserDialog as vm').result.then(createUser);
      }

      function canChangePlan() {
        return STRIPE_PUBLISHABLE_KEY && vm.organization;
      }

      function changePlan() {
        return billingService.changePlan(vm.organization.id);
      }

      function createUser(emailAddress) {
        function onFailure(response) {
          if (response.status === 426) {
            return billingService.confirmUpgradePlan(response.data.message).then(function() {
              return createUser(emailAddress);
            });
          }

          var message = 'An error occurred while inviting the user.';
          if (response.data && response.data.message) {
            message += ' Message: ' + response.data.message;
          }

          notificationService.error(message);
        }

        return organizationService.addUser(_organizationId, emailAddress).catch(onFailure);
      }

      function get(data) {
        if (_ignoreRefresh) {
          return;
        }

        if (data && data.type === 'Organization' && data.deleted && data.id === _organizationId) {
          $state.go('app.dashboard');
          notificationService.error('The organization "' + _organizationId + '" was deleted.');
          return;
        }

        return getOrganization();
      }

      function getOrganization() {
        function onSuccess(response) {
          vm.organization = response.data.plain();
          vm.organization.usage = vm.organization.usage || [];
          vm.hasMonthlyUsage = vm.organization.max_events_per_month > 0;

          vm.chart.options.series[0].data = vm.organization.usage.map(function (item) {
            return {x: moment.utc(item.date).unix(), y: item.total - item.blocked - item.too_big, data: item};
          });

          vm.chart.options.series[1].data = vm.organization.usage.map(function (item) {
            return {x: moment.utc(item.date).unix(), y: item.blocked, data: item};
          });

          vm.chart.options.series[2].data = vm.organization.usage.map(function (item) {
            return {x: moment.utc(item.date).unix(), y: item.too_big, data: item};
          });

          vm.chart.options.series[3].data = vm.organization.usage.map(function (item) {
            return {x: moment.utc(item.date).unix(), y: item.limit, data: item};
          });
        }

        function onFailure() {
          $state.go('app.dashboard');
          notificationService.error('The organization "' + _organizationId + '" could not be found.');
        }

        return organizationService.getById(_organizationId, false).then(onSuccess, onFailure);
      }

      function getRemainingEventLimit() {
        if (!vm.organization.max_events_per_month) {
          return 0;
        }

        var bonusEvents = moment.utc().isBefore(moment.utc(vm.organization.bonus_expiration)) ? vm.organization.bonus_events_per_month : 0;
        var usage = vm.organization.usage && vm.organization.usage[vm.organization.usage.length - 1];
        if (usage && moment.utc(usage.date).isSame(moment.utc().startOf('month'))) {
          var remaining = usage.limit - (usage.total - usage.blocked - usage.too_big);
          return remaining > 0 ? remaining : 0;
        }

        return vm.organization.max_events_per_month + bonusEvents;
      }

      function hasAdminRole(user) {
        return userService.hasAdminRole(user);
      }

      function hasPremiumFeatures() {
        return vm.organization && vm.organization.has_premium_features;
      }
{'fraction_non_alphanumeric': 0.13105102485826428, 'fraction_numerical': 0.0028347143480157, 'mean_word_length': 2.678027265437049, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5993678', 'n_tokens_mistral': 2638, 'n_tokens_neox': 2490, 'n_words': 471}