<commit_before>/** @jsx React.DOM */

App.Pages.AppOverview = React.createClass({
  mixins: [
    React.addons.LinkedStateMixin,
    App.Mixins.SortableTable("apps.overview", "name")
  ],

  getInitialState: function () {
    return {
      search: "",
      radioButtonFacets: ["connection", "used_by_idp", "published_edugain"],
      activeFacets: App.store.activeFacets || {},
      hiddenFacets: App.store.hiddenFacets || {}
    }
  },

  render: function () {
    var filteredApps = this.filterAppsForExclusiveFilters(this.props.apps);

    if (App.currentUser.dashboardAdmin) {
      var connect = (
        <th className="percent_10 right">
          {I18n.t("apps.overview.connect")}
        </th>
      );
    }

    var facets = this.staticFacets().concat(this.props.facets);
    this.addNumbers(filteredApps, facets);
    filteredApps = this.filterAppsForInclusiveFilters(filteredApps);

    return (
      <div className="l-main">
        <div className="l-left">
          <App.Components.Facets
            facets={facets}
            selectedFacets={this.state.activeFacets}
            hiddenFacets={this.state.hiddenFacets}
            filteredCount={filteredApps.length}
            totalCount={this.props.apps.length}
            onChange={this.handleFacetChange}
            onHide={this.handleFacetHide}
            onReset={this.handleResetFilters}
            onDownload={this.handleDownloadOverview}/>
        </div>
        <div className="l-right">
          <div className="mod-app-search">
            <fieldset>
              <i className="fa fa-search"/>
              <input
                type="search"
                valueLink={this.linkState("search")}
                placeholder={I18n.t("apps.overview.search_hint")}/>

              <button type="submit">{I18n.t("apps.overview.search")}</button>
            </fieldset>
          </div>
          <div className="mod-app-list">
            <table>
              <thead>
              <tr>
                {this.renderSortableHeader("percent_25", "name")}
                {this.renderSortableHeader("percent_15", "license")}
                {this.renderSortableHeader("percent_15", "connected")}
                {connect}
              </tr>
              </thead>
              <tbody>
              {filteredApps.length > 0 ? this.sort(filteredApps).map(this.renderApp) : this.renderEmpty()}
              </tbody>
            </table>
          </div>
        </div>
      </div>
    );
  },

  renderEmpty: function () {
    return <td className="empty" colSpan="4">{I18n.t("apps.overview.no_results")}</td>;
  },

  renderApp: function (app) {
    if (App.currentUser.dashboardAdmin) {
      var connect = (
        <td className="right">
          {this.renderConnectButton(app)}
        </td>
      );
    }

    return (
      <tr key={app.id} onClick={this.handleShowAppDetail(app)}>
        <td><a href={page.uri("/apps/:id", {id: app.id})}>{app.name}</a></td>
        {this.renderLicenseStatus(app)}
        {App.renderYesNo(app.connected)}
        {connect}
      </tr>
    );
  },

  licenseStatusClassName: function (app) {
    switch (app.licenseStatus) {
      case "HAS_LICENSE_SURFMARKET":
      case "HAS_LICENSE_SP":
        return "yes"
      case "NO_LICENSE":
        return "no";
      default:
        return "";
    }
  },

  renderLicenseStatus: function (app) {
    return (
      <td
        className={this.licenseStatusClassName(app)}>{I18n.t("facets.static.license." + app.licenseStatus.toLowerCase())}</td>
    );
  },

  renderConnectButton: function (app) {
    if (!app.connected) {
      return <a onClick={this.handleShowHowToConnect(app)}
                className="c-button narrow">{I18n.t("apps.overview.connect_button")}</a>;
    }
  },

  handleShowAppDetail: function (app) {
    return function (e) {
      e.preventDefault();
      e.stopPropagation();
      page("/apps/:id", {id: app.id});
    }
  },

  handleShowHowToConnect: function (app) {
    return function (e) {<commit_msg>Disable connect button for super user, not allowed<commit_after>/** @jsx React.DOM */

App.Pages.AppOverview = React.createClass({
  mixins: [
    React.addons.LinkedStateMixin,
    App.Mixins.SortableTable("apps.overview", "name")
  ],

  getInitialState: function () {
    return {
      search: "",
      radioButtonFacets: ["connection", "used_by_idp", "published_edugain"],
      activeFacets: App.store.activeFacets || {},
      hiddenFacets: App.store.hiddenFacets || {}
    }
  },

  render: function () {
    var filteredApps = this.filterAppsForExclusiveFilters(this.props.apps);

    if (App.currentUser.dashboardAdmin) {
      var connect = (
        <th className="percent_10 right">
          {I18n.t("apps.overview.connect")}
        </th>
      );
    }

    var facets = this.staticFacets().concat(this.props.facets);
    this.addNumbers(filteredApps, facets);
    filteredApps = this.filterAppsForInclusiveFilters(filteredApps);

    return (
      <div className="l-main">
        <div className="l-left">
          <App.Components.Facets
            facets={facets}
            selectedFacets={this.state.activeFacets}
            hiddenFacets={this.state.hiddenFacets}
            filteredCount={filteredApps.length}
            totalCount={this.props.apps.length}
            onChange={this.handleFacetChange}
            onHide={this.handleFacetHide}
            onReset={this.handleResetFilters}
            onDownload={this.handleDownloadOverview}/>
        </div>
        <div className="l-right">
          <div className="mod-app-search">
            <fieldset>
              <i className="fa fa-search"/>
              <input
                type="search"
                valueLink={this.linkState("search")}
                placeholder={I18n.t("apps.overview.search_hint")}/>

              <button type="submit">{I18n.t("apps.overview.search")}</button>
            </fieldset>
          </div>
          <div className="mod-app-list">
            <table>
              <thead>
              <tr>
                {this.renderSortableHeader("percent_25", "name")}
                {this.renderSortableHeader("percent_15", "license")}
                {this.renderSortableHeader("percent_15", "connected")}
                {connect}
              </tr>
              </thead>
              <tbody>
              {filteredApps.length > 0 ? this.sort(filteredApps).map(this.renderApp) : this.renderEmpty()}
              </tbody>
            </table>
          </div>
        </div>
      </div>
    );
  },

  renderEmpty: function () {
    return <td className="empty" colSpan="4">{I18n.t("apps.overview.no_results")}</td>;
  },

  renderApp: function (app) {
    if (App.currentUser.dashboardAdmin) {
      var connect = (
        <td className="right">
          {this.renderConnectButton(app)}
        </td>
      );
    }

    return (
      <tr key={app.id} onClick={this.handleShowAppDetail(app)}>
        <td><a href={page.uri("/apps/:id", {id: app.id})}>{app.name}</a></td>
        {this.renderLicenseStatus(app)}
        {App.renderYesNo(app.connected)}
        {connect}
      </tr>
    );
  },

  licenseStatusClassName: function (app) {
    switch (app.licenseStatus) {
      case "HAS_LICENSE_SURFMARKET":
      case "HAS_LICENSE_SP":
        return "yes"
      case "NO_LICENSE":
        return "no";
      default:
        return "";
    }
  },

  renderLicenseStatus: function (app) {
    return (
      <td
        className={this.licenseStatusClassName(app)}>{I18n.t("facets.static.license." + app.licenseStatus.toLowerCase())}</td>
    );
  },

  renderConnectButton: function (app) {
    if (!app.connected) {
      return App.currentUser.superUser ?
         <a href="#" className={"c-button disabled"}>{I18n.t("apps.overview.connect_button")}</a> :
         <a onClick={this.handleShowHowToConnect(app)} className="c-button narrow">{I18n.t("apps.overview.connect_button")}</a>;
    }
  },

  handleShowAppDetail: function (app) {
    return function (e) {
      e.preventDefault();
      e.stopPropagation();
      page("/apps/:id", {id: app.id});
    }
  },

  handleShowHowToConnect: function (app) {
    return function (e) {
{'fraction_non_alphanumeric': 0.15043923865300146, 'fraction_numerical': 0.005612493899463153, 'mean_word_length': 2.204456606724003, 'pattern_counts': {'":': 6, '<': 87, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6960965', 'n_tokens_mistral': 2557, 'n_tokens_neox': 2482, 'n_words': 368}