<commit_before>/**
 * @module Karaf
 */
module Karaf {

  export function FeaturesController($scope, $location, workspace, jolokia) {

    $scope.hasFabric = Fabric.hasFabric(workspace);
    $scope.responseJson = '';
    $scope.filter = '';

    $scope.installedFeatures = [];

    $scope.features = [];
    $scope.repositories = [];
    $scope.selectedRepositoryId = '';
    $scope.selectedRepository = {};


    $scope.init = () => {

      var selectedRepositoryId = $location.search()['repositoryId'];
      if (selectedRepositoryId) {
        $scope.selectedRepositoryId = selectedRepositoryId;
      }

      var filter = $location.search()['filter'];
      if (filter) {
        $scope.filter = filter;
      }

    };

    $scope.init();

    $scope.$watch('selectedRepository', (newValue, oldValue) => {
      console.log("selectedRepository: ", $scope.selectedRepository);
      if (newValue !== oldValue) {
        if (!newValue) {
          $scope.selectedRepositoryId = '';
        } else {
          $scope.selectedRepositoryId = newValue['repository'];
        }
        $location.search('repositoryId', $scope.selectedRepositoryId);
      }
    }, true);

    $scope.$watch('filter', (newValue, oldValue) => {
      if (newValue !== oldValue) {
        $location.search('filter', newValue);
      }
    });

    var featuresMBean = Karaf.getSelectionFeaturesMBean(workspace);

    log.debug("Features mbean: ", featuresMBean);

    if (featuresMBean) {
      Core.register(jolokia, $scope, {
        type: 'read', mbean: featuresMBean
      }, onSuccess(render));
    }

    $scope.triggerRefresh = () => {
      jolokia.request({
        type: 'read',
        method: 'POST',
        mbean: featuresMBean
      }, onSuccess(render));
    };

    $scope.install = (feature) => {
      //$('.popover').remove();
      notification('info', 'Installing feature ' + feature.Name);
      installFeature(workspace, jolokia, feature.Name, feature.Version, () => {
        notification('success', 'Installed feature ' + feature.Name);
        $scope.installedFeatures.add(feature);
        $scope.triggerRefresh();
        Core.$apply($scope);
      }, (response) => {
        log.error('Failed to install feature ', feature.Name, ' due to ', response.error);
        log.info('stack trace: ', response.stacktrace);
        Core.$apply($scope);
      });
    };

    $scope.uninstall = (feature) => {
      //$('.popover').remove();
      notification('info', 'Uninstalling feature ' + feature.Name);
      uninstallFeature(workspace, jolokia, feature.Name, feature.Version, () => {
        notification('success', 'Uninstalled feature ' + feature.Name);
        $scope.installedFeatures.remove(feature);
        $scope.triggerRefresh();
        Core.$apply($scope);
      }, (response) => {
        log.error('Failed to uninstall feature ', feature.Name, ' due to ', response.error);
        log.info('stack trace: ', response.stacktrace);
        Core.$apply($scope);
      });
    };

    $scope.filteredRows = ['Bundles', 'Configurations', 'Configuration Files', 'Dependencies'];

    $scope.showRow = (key, value) => {

      if ($scope.filteredRows.any(key)) {
        return false;
      }

      if (angular.isArray(value)) {
        if (value.length === 0) {
          return false;
        }
      }

      if (angular.isString(value)) {
        if (Core.isBlank(value)) {
          return false;
        }
      }

      if (angular.isObject(value)) {
        if (!value || Object.equal(value, {})) {
          return false;
        }
      }

      return true;
    };

    $scope.installed = (installed) => {
      var answer = Core.parseBooleanValue(installed);

      if ($scope.hasFabric) {
        return !answer;
      }

      return answer;
    };

    $scope.showValue = (value) => {
      if (angular.isArray(value)) {
        var answer = ['<ul class="zebra-list">']
        value.forEach((v) => { answer.push('<li>' + v + '</li>')});
        answer.push('</ul>');
        return answer.join('\n');
      }
      if (angular.isObject(value)) {
        var answer = ['<table class="table">', '<tbody>']

        angular.forEach(value, (value, key) => {
          answer.push('<tr>');
          answer.push('<td>' + key + '</td>')
          answer.push('<td>' + value + '</td>')
          answer.push('</tr>');
        });

        answer.push('</tbody>');
        answer.push('</table>');

        return answer.join('\n');
      }
      return "" + value;
    };

    $scope.getStateStyle = (feature) => {
      if (Core.parseBooleanValue(feature.Installed)) {
        return "badge badge-success";
      }
      return "badge";
    };

    $scope.filterFeature = (feature) => {
      if (Core.isBlank($scope.filter)) {
        return true;
      }
      if (feature.Id.has($scope.filter)) {
        return true;
      }
      return false;
    };

    function render(response) {
      var responseJson = angular.toJson(response.value);
      if ($scope.responseJson !== responseJson) {
        $scope.responseJson = responseJson;
        //log.debug("Got response: ", response.value);

        var features = [];
        var repositories = [];

        populateFeaturesAndRepos(response.value, features, repositories);

        var installedFeatures = features.filter((f) => { return Core.parseBooleanValue(f.Installed); });
        var uninstalledFeatures = features.filter((f) => { return !Core.parseBooleanValue(f.Installed); });

        //log.debug("repositories: ", repositories);

        $scope.installedFeatures = installedFeatures.sortBy((f) => { return f['Name'] });
        uninstalledFeatures = uninstalledFeatures.sortBy((f) => { return f['Name'] });

        repositories.sortBy('id').map((r) => { return r['id'] }).forEach((repo) => {
          $scope.repositories.push({
            repository: repo,
            features: uninstalledFeatures.filter((f) => { return f['RepositoryName'] === repo })
          });
        });

        if (Core.isBlank($scope.selectedRepositoryId)) {
          $scope.selectedRepository = $scope.repositories.first();
        } else {
          $scope.selectedRepository = $scope.repositories.find((r) => { return r.repository === $scope.selectedRepositoryId });
        }

        Core.$apply($scope);<commit_msg>Fix #909<commit_after>/**
 * @module Karaf
 */
module Karaf {

  export function FeaturesController($scope, $location, workspace, jolokia) {

    $scope.hasFabric = Fabric.hasFabric(workspace);
    $scope.responseJson = '';
    $scope.filter = '';

    $scope.installedFeatures = [];

    $scope.features = [];
    $scope.repositories = [];
    $scope.selectedRepositoryId = '';
    $scope.selectedRepository = {};


    $scope.init = () => {

      var selectedRepositoryId = $location.search()['repositoryId'];
      if (selectedRepositoryId) {
        $scope.selectedRepositoryId = selectedRepositoryId;
      }

      var filter = $location.search()['filter'];
      if (filter) {
        $scope.filter = filter;
      }

    };

    $scope.init();

    $scope.$watch('selectedRepository', (newValue, oldValue) => {
      log.info("selectedRepository: ", $scope.selectedRepository);
      if (newValue !== oldValue) {
        if (!newValue) {
          $scope.selectedRepositoryId = '';
        } else {
          $scope.selectedRepositoryId = newValue['repository'];
        }
        $location.search('repositoryId', $scope.selectedRepositoryId);
      }
    }, true);

    $scope.$watch('filter', (newValue, oldValue) => {
      if (newValue !== oldValue) {
        $location.search('filter', newValue);
      }
    });

    var featuresMBean = Karaf.getSelectionFeaturesMBean(workspace);

    log.debug("Features mbean: ", featuresMBean);

    if (featuresMBean) {
      Core.register(jolokia, $scope, {
        type: 'read', mbean: featuresMBean
      }, onSuccess(render));
    }

    $scope.triggerRefresh = () => {
      jolokia.request({
        type: 'read',
        method: 'POST',
        mbean: featuresMBean
      }, onSuccess(render));
    };

    $scope.install = (feature) => {
      //$('.popover').remove();
      notification('info', 'Installing feature ' + feature.Name);
      installFeature(workspace, jolokia, feature.Name, feature.Version, () => {
        notification('success', 'Installed feature ' + feature.Name);
        $scope.installedFeatures.add(feature);
        $scope.responseJson = null;
        $scope.triggerRefresh();
        //Core.$apply($scope);
      }, (response) => {
        log.error('Failed to install feature ', feature.Name, ' due to ', response.error);
        log.info('stack trace: ', response.stacktrace);
        Core.$apply($scope);
      });
    };

    $scope.uninstall = (feature) => {
      //$('.popover').remove();
      notification('info', 'Uninstalling feature ' + feature.Name);
      uninstallFeature(workspace, jolokia, feature.Name, feature.Version, () => {
        notification('success', 'Uninstalled feature ' + feature.Name);
        $scope.installedFeatures.remove(feature);
        $scope.responseJson = null;
        $scope.triggerRefresh();
        //Core.$apply($scope);
      }, (response) => {
        log.error('Failed to uninstall feature ', feature.Name, ' due to ', response.error);
        log.info('stack trace: ', response.stacktrace);
        Core.$apply($scope);
      });
    };

    $scope.filteredRows = ['Bundles', 'Configurations', 'Configuration Files', 'Dependencies'];

    $scope.showRow = (key, value) => {

      if ($scope.filteredRows.any(key)) {
        return false;
      }

      if (angular.isArray(value)) {
        if (value.length === 0) {
          return false;
        }
      }

      if (angular.isString(value)) {
        if (Core.isBlank(value)) {
          return false;
        }
      }

      if (angular.isObject(value)) {
        if (!value || Object.equal(value, {})) {
          return false;
        }
      }

      return true;
    };

    $scope.installed = (installed) => {
      var answer = Core.parseBooleanValue(installed);

      if ($scope.hasFabric) {
        return !answer;
      }

      return answer;
    };

    $scope.showValue = (value) => {
      if (angular.isArray(value)) {
        var answer = ['<ul class="zebra-list">']
        value.forEach((v) => { answer.push('<li>' + v + '</li>')});
        answer.push('</ul>');
        return answer.join('\n');
      }
      if (angular.isObject(value)) {
        var answer = ['<table class="table">', '<tbody>']

        angular.forEach(value, (value, key) => {
          answer.push('<tr>');
          answer.push('<td>' + key + '</td>')
          answer.push('<td>' + value + '</td>')
          answer.push('</tr>');
        });

        answer.push('</tbody>');
        answer.push('</table>');

        return answer.join('\n');
      }
      return "" + value;
    };

    $scope.getStateStyle = (feature) => {
      if (Core.parseBooleanValue(feature.Installed)) {
        return "badge badge-success";
      }
      return "badge";
    };

    $scope.filterFeature = (feature) => {
      if (Core.isBlank($scope.filter)) {
        return true;
      }
      if (feature.Id.has($scope.filter)) {
        return true;
      }
      return false;
    };

    function render(response) {
      var responseJson = angular.toJson(response.value);
      if ($scope.responseJson !== responseJson) {
        $scope.responseJson = responseJson;
        //log.debug("Got response: ", response.value);

        $scope.features = [];
        $scope.repositories = [];

        var features = [];
        var repositories = [];

        populateFeaturesAndRepos(response.value, features, repositories);

        var installedFeatures = features.filter((f) => { return Core.parseBooleanValue(f.Installed); });
        var uninstalledFeatures = features.filter((f) => { return !Core.parseBooleanValue(f.Installed); });

        //log.debug("repositories: ", repositories);

        $scope.installedFeatures = installedFeatures.sortBy((f) => { return f['Name'] });
        uninstalledFeatures = uninstalledFeatures.sortBy((f) => { return f['Name'] });

        repositories.sortBy('id').map((r) => { return r['id'] }).forEach((repo) => {
          $scope.repositories.push({
            repository: repo,
            features: uninstalledFeatures.filter((f) => { return f['RepositoryName'] === repo })
          });
        });

        if (Core.isBlank($scope.selectedRepositoryId)) {
          $scope.selectedRepository = $scope.repositories.first();
        } else {
          $scope.selectedRepository = $scope.repositories.find((r) => { return r.repository === $scope.selectedRepositoryId });
        }

        Core.$apply($scope);
{'fraction_non_alphanumeric': 0.16953548691346382, 'fraction_numerical': 0.00039298907490371767, 'mean_word_length': 2.3921620901093044, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 81, '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': '6340021', 'n_tokens_mistral': 3758, 'n_tokens_neox': 3597, 'n_words': 638}