<commit_before>App.Controllers.Apps = {

  initialize: function() {
    page("/apps",
      this.loadFacets.bind(this),
      this.loadApps.bind(this),
      this.overview.bind(this)
    );

    page("/apps/:id/:active_panel?",
      this.loadApp.bind(this),
      this.detail.bind(this)
    );
  },

  loadApps: function(ctx, next) {
    $.get(App.apiUrl("/services"), function(data) {
      ctx.apps = data.payload;
      next();
    });
  },

  loadApp: function(ctx, next) {
    $.get(App.apiUrl("/services/id/" + ctx.params.id), function(data) {
      ctx.app = data.payload;
      $.get(App.apiUrl("/services/idps", {spEntityId: ctx.app.spEntityId} ), function(data) {
        ctx.institutions = data.payload;
        next();
      });
    });
  },

  loadFacets: function(ctx, next) {
    $.get(App.apiUrl("/facets"), function(data) {
      ctx.facets = data.payload;
      next();
    });
  },

  overview: function(ctx) {
    // We need to sanitize the categories data for each app to ensure facet search works
    ctx.apps.forEach(function(app){
      ctx.facets.forEach(function(facet){
        app.categories = app.categories || [];
        var appCategory = app.categories.filter(function(category){
          return category.name === facet.name;
        });
        if (appCategory.length === 0) {
          app.categories.push({name:facet.name, values:[{value: I18n.t("facets.unknown")}]});
          facet.values.push({value: I18n.t("facets.unknown")});
        }
      });
    });
    App.render(App.Pages.AppOverview({key: "apps", apps: ctx.apps, facets: ctx.facets}));
  },

  detail: function(ctx) {
    App.render(App.Pages.AppDetail({key: "apps", apps: ctx.apps, app: ctx.app, institutions: ctx.institutions, activePanel: ctx.params.active_panel}));
  },

  makeConnection: function(app, comments, callback) {
    if (App.currentUser.dashboardAdmin) {
      $.post(
        App.apiUrl("/services/id/" + app.id + "/connect"),
        {comments: comments, spEntityId: app.spEntityId},
        function() {
          if (callback) callback();
        });
    }
  },

  disconnect: function(app, comments, callback) {
    if (App.currentUser.dashboardAdmin) {
      $.post(App.apiUrl("/services/id/" + app.id + "/disconnect"), {
        comments: comments,
        spEntityId: app.spEntityId
      }, function() {
        if (callback) callback();
      });
    }<commit_msg>Bugfix for multiple unknowns in the facetValues for a facet<commit_after>App.Controllers.Apps = {

  initialize: function() {
    page("/apps",
      this.loadFacets.bind(this),
      this.loadApps.bind(this),
      this.overview.bind(this)
    );

    page("/apps/:id/:active_panel?",
      this.loadApp.bind(this),
      this.detail.bind(this)
    );
  },

  loadApps: function(ctx, next) {
    $.get(App.apiUrl("/services"), function(data) {
      ctx.apps = data.payload;
      next();
    });
  },

  loadApp: function(ctx, next) {
    $.get(App.apiUrl("/services/id/" + ctx.params.id), function(data) {
      ctx.app = data.payload;
      $.get(App.apiUrl("/services/idps", {spEntityId: ctx.app.spEntityId} ), function(data) {
        ctx.institutions = data.payload;
        next();
      });
    });
  },

  loadFacets: function(ctx, next) {
    $.get(App.apiUrl("/facets"), function(data) {
      ctx.facets = data.payload;
      next();
    });
  },

  overview: function(ctx) {
    // We need to sanitize the categories data for each app to ensure the facet totals are correct
    var unknown = {value: I18n.t("facets.unknown")};
    ctx.facets.forEach(function(facet){
      ctx.apps.forEach(function(app){
        app.categories = app.categories || [];
        var appCategory = app.categories.filter(function(category){
          return category.name === facet.name;
        });
        if (appCategory.length === 0) {
          app.categories.push({name:facet.name, values:[unknown]});
          var filtered = facet.values.filter(function(facetValue){
            return facetValue.value === unknown.value;
          });
      //    if (filtered.length === -1) {
            facet.values.push(unknown);
      //    }
        }
      });
    });
    App.render(App.Pages.AppOverview({key: "apps", apps: ctx.apps, facets: ctx.facets}));
  },

  detail: function(ctx) {
    App.render(App.Pages.AppDetail({key: "apps", apps: ctx.apps, app: ctx.app, institutions: ctx.institutions, activePanel: ctx.params.active_panel}));
  },

  makeConnection: function(app, comments, callback) {
    if (App.currentUser.dashboardAdmin) {
      $.post(
        App.apiUrl("/services/id/" + app.id + "/connect"),
        {comments: comments, spEntityId: app.spEntityId},
        function() {
          if (callback) callback();
        });
    }
  },

  disconnect: function(app, comments, callback) {
    if (App.currentUser.dashboardAdmin) {
      $.post(App.apiUrl("/services/id/" + app.id + "/disconnect"), {
        comments: comments,
        spEntityId: app.spEntityId
      }, function() {
        if (callback) callback();
      });
    }
{'fraction_non_alphanumeric': 0.1711336112765535, 'fraction_numerical': 0.001786777843954735, 'mean_word_length': 2.5579096045197742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6646595', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1594, 'n_words': 280}