<commit_before>'use strict';

var fs = require('fs');

var template = fs.readFileSync(__dirname + '/process-definitions.html', 'utf8');

module.exports = [ 'ViewsProvider', function(ViewsProvider) {
  ViewsProvider.registerDefaultView('cockpit.processes.dashboard', {
    id: 'process-definition',
    label: 'Deployed Process Definitions',
    template: template,
    controller: [
      '$scope',
      'Views',
      'camAPI',
      function($scope, Views, camAPI) {

        var getPDIncidentsCount = function(incidents) {
          if(!incidents) {
            return 0;
          }

          return incidents.reduce(function(sum, incident) {
            return sum + incident.incidentCount;
          }, 0);
        };

        var processInstancePlugins = Views.getProviders({ component: 'cockpit.processInstance.view' });
        $scope.hasHistoryPlugin = processInstancePlugins.filter(function(plugin) {
          return plugin.id === 'history';
        }).length > 0;

        var processData = $scope.processData.newChild($scope);

        $scope.hasReportPlugin = Views.getProviders({ component: 'cockpit.report' }).length > 0;

        var processDefinitionService = camAPI.resource('process-definition');
        $scope.loadingState = 'LOADING';

        processDefinitionService.list({
          latest: true
        }, function(err, data) {
          $scope.processDefinitionData = data.items;
          $scope.processDefinitionsCount = data.items.length;
          if (err) {
            $scope.loadingState = 'ERROR';
          }

          $scope.loadingState = 'LOADED';

          processData.observe('processDefinitionStatistics', function(processDefinitionStatistics) {
            $scope.statistics = processDefinitionStatistics;

            $scope.statistics.forEach(function(statistic) {
              var processDefId = statistic.definition.id;
              var foundIds = $scope.processDefinitionData.filter(function(pd) {
                return pd.id === processDefId;
              });

              var foundObject = foundIds[0];
              if(foundObject) {
                foundObject.incidents = statistic.incidents;
                foundObject.incidentCount = getPDIncidentsCount(foundObject.incidents);
                foundObject.instances = statistic.instances;
              }
            });
          });
        });

        $scope.processesActions = Views.getProviders({ component: 'cockpit.processes.action'});
        $scope.hasActionPlugin = $scope.processesActions.length > 0;
        $scope.definitionVars = { read: [ 'pd' ] };

        var removeActionDeleteListener = $scope.$on('processes.action.delete', function(event, definitionId) {

          var definitions = $scope.processDefinitionData;

          for (var i = 0; i < definitions.length; i++) {
            if (definitions[i].id === definitionId) {
              definitions.splice(i, 1);
              break;
            }
          }

          $scope.processDefinitionsCount = definitions.length;
        });

        $scope.$on('$destroy', function() {
          removeActionDeleteListener();
        });

        $scope.activeTab = 'list';
        $scope.tabActive = true;

        $scope.selectTab = function(tab) {
          $scope.activeTab = tab;
        };

        $scope.toggleSection = function toggleSection() {
          $scope.tabActive = !$scope.tabActive;
        };
      }],

    priority: 0
  });
}];<commit_msg>fix(cockpit): make hiding processes dashboard section persistent<commit_after>'use strict';

var fs = require('fs');

var template = fs.readFileSync(__dirname + '/process-definitions.html', 'utf8');

module.exports = [ 'ViewsProvider', function(ViewsProvider) {
  ViewsProvider.registerDefaultView('cockpit.processes.dashboard', {
    id: 'process-definition',
    label: 'Deployed Process Definitions',
    template: template,
    controller: [
      '$scope',
      'Views',
      'camAPI',
      'localConf',
      function($scope, Views, camAPI, localConf) {

        var getPDIncidentsCount = function(incidents) {
          if(!incidents) {
            return 0;
          }

          return incidents.reduce(function(sum, incident) {
            return sum + incident.incidentCount;
          }, 0);
        };

        var processInstancePlugins = Views.getProviders({ component: 'cockpit.processInstance.view' });
        $scope.hasHistoryPlugin = processInstancePlugins.filter(function(plugin) {
          return plugin.id === 'history';
        }).length > 0;

        var processData = $scope.processData.newChild($scope);

        $scope.hasReportPlugin = Views.getProviders({ component: 'cockpit.report' }).length > 0;

        var processDefinitionService = camAPI.resource('process-definition');
        $scope.loadingState = 'LOADING';

        processDefinitionService.list({
          latest: true
        }, function(err, data) {
          $scope.processDefinitionData = data.items;
          $scope.processDefinitionsCount = data.items.length;
          if (err) {
            $scope.loadingState = 'ERROR';
          }

          $scope.loadingState = 'LOADED';

          processData.observe('processDefinitionStatistics', function(processDefinitionStatistics) {
            $scope.statistics = processDefinitionStatistics;

            $scope.statistics.forEach(function(statistic) {
              var processDefId = statistic.definition.id;
              var foundIds = $scope.processDefinitionData.filter(function(pd) {
                return pd.id === processDefId;
              });

              var foundObject = foundIds[0];
              if(foundObject) {
                foundObject.incidents = statistic.incidents;
                foundObject.incidentCount = getPDIncidentsCount(foundObject.incidents);
                foundObject.instances = statistic.instances;
              }
            });
          });
        });

        $scope.processesActions = Views.getProviders({ component: 'cockpit.processes.action'});
        $scope.hasActionPlugin = $scope.processesActions.length > 0;
        $scope.definitionVars = { read: [ 'pd' ] };

        var removeActionDeleteListener = $scope.$on('processes.action.delete', function(event, definitionId) {

          var definitions = $scope.processDefinitionData;

          for (var i = 0; i < definitions.length; i++) {
            if (definitions[i].id === definitionId) {
              definitions.splice(i, 1);
              break;
            }
          }

          $scope.processDefinitionsCount = definitions.length;
        });

        $scope.$on('$destroy', function() {
          removeActionDeleteListener();
        });

        $scope.activeTab = 'list';
        $scope.tabActive = localConf.get('processesDashboardActive', true);

        $scope.selectTab = function(tab) {
          $scope.activeTab = tab;
        };

        $scope.toggleSection = function toggleSection() {
          $scope.tabActive = !$scope.tabActive;
          localConf.set('processesDashboardActive', $scope.tabActive);
        };
      }],

    priority: 0
  });
}];
{'fraction_non_alphanumeric': 0.12233967582804792, 'fraction_numerical': 0.0028188865398167725, 'mean_word_length': 2.2685398433901427, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '5835470', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1831, 'n_words': 327}