<commit_before>(function($, _, c, global) {
  "use strict";

  function PluginInfos() {
    var plugins = [];

    this.list = function list() { return [].slice.call(plugins); };

    this.init = function init() {
      new XhrPromise({
        url: Routes.apiv4AdminPluginInfoIndexPath(),
        type: "GET",
        responseType: "json",
        headers: {
          Accept: "application/vnd.go.cd.v4+json"
        }
      }).then(function (res) {
        plugins = _.filter(res.data._embedded.plugin_info, function(el) {
          return "active" === el.status.state && !!_.find(el.extensions, function(ex) {
            return "configrepo" === ex.type
          })
        });
      }).catch(function (res) {
        console.error(res.error.message);
      });
    };
  }

  var pluginInfos = new PluginInfos(); // a private singleton

  function createPluginListOption(p) {
    return c("li", c("a", {class: "plugin-choice", "data-plugin-id": p.id}, p.about.name));
  }

  global.ExportAdapter = {
    init: function init() {
      pluginInfos.init();
    },

    downloadAsFile: function downloadAsFile(blobUrl, name) {
      var a = c("a", {href: blobUrl, download: name, style: "display: none"});

      document.body.appendChild(a); // Firefox requires this to be added to the DOM before click()
      a.click();
      document.body.removeChild(a);
    },

    showExportOptions: function showExportOptions(panel, el) {
      panel.innerHTML = "";
      var dropdown = c("ul", {class: "export-plugins-dropdown"}, _.map(pluginInfos.list(), createPluginListOption));
      panel.appendChild(dropdown);

      $(dropdown).on("click", ".plugin-choice", function downloadExport(ev) {
        ev.preventDefault();
        ev.stopPropagation();

        new XhrPromise({
          url: el.getAttribute("href") + "&pluginId=" + encodeURIComponent($(ev.currentTarget).data("plugin-id")),
          responseType: "blob",
          headers: {
            Accept: "application/vnd.go.cd.v7+json"
          }
        }).then(function (res) {
          startClientDownload(res.data, res.xhr);
        }).catch(function (res) {
          handleError(res.xhr.status, new FileReader().readAsText(res.error))
        }).finally(function() {
          // hide loading indicator
        });

        function startClientDownload(responseBlob, xhr) {
          var name = xhr.getResponseHeader("Content-Disposition").replace(/^attachment; filename=/, "").replace(/^(")(.+)(\1)/, "$2");
          ExportAdapter.downloadAsFile(URL.createObjectURL(responseBlob), name);
        }

        function handleError(status, responseText) {
          console.error(JSON.parse(responseText).message)
        }<commit_msg>Show errors in a flash message<commit_after>(function($, _, c, global) {
  "use strict";

  function flash() {
    return document.getElementById("message_pane");
  }

  function clear(el) {
    while (el.firstChild) { el.removeChild(el.firstChild); }
    return el;
  }

  var Flash = {
    clear: function () {
      clear(flash());
    },
    error: function (message) {
      clear(flash()).appendChild(c("p", {class: "error"}, message));
    },
    success: function (message) {
      clear(flash()).appendChild(c("p", {class: "success"}, message));
    }
  }

  function PluginInfos() {
    var plugins = [];

    this.list = function list() { return [].slice.call(plugins); };

    this.init = function init() {
      new XhrPromise({
        url: Routes.apiv4AdminPluginInfoIndexPath(),
        type: "GET",
        responseType: "json",
        headers: {
          Accept: "application/vnd.go.cd.v4+json"
        }
      }).then(function (res) {
        plugins = _.filter(res.data._embedded.plugin_info, function(el) {
          return "active" === el.status.state && !!_.find(el.extensions, function(ex) {
            return "configrepo" === ex.type
          })
        });
      }).catch(function (res) {
        Flash.error(res.error.message);
      });
    };
  }

  var pluginInfos = new PluginInfos(); // a private singleton

  function createPluginListOption(p) {
    return c("li", c("a", {class: "plugin-choice", "data-plugin-id": p.id}, p.about.name));
  }

  global.ExportAdapter = {
    init: function init() {
      pluginInfos.init();
    },

    downloadAsFile: function downloadAsFile(blobUrl, name) {
      var a = c("a", {href: blobUrl, download: name, style: "display: none"});

      document.body.appendChild(a); // Firefox requires this to be added to the DOM before click()
      a.click();
      document.body.removeChild(a);
    },

    showExportOptions: function showExportOptions(panel, el) {
      var dropdown = c("ul", {class: "export-plugins-dropdown"}, _.map(pluginInfos.list(), createPluginListOption));
      clear(panel).appendChild(dropdown);

      $(dropdown).on("click", ".plugin-choice", function downloadExport(ev) {
        ev.preventDefault();
        ev.stopPropagation();

        new XhrPromise({
          url: el.getAttribute("href") + "&pluginId=" + encodeURIComponent($(ev.currentTarget).data("plugin-id")),
          responseType: "blob",
          headers: {
            Accept: "application/vnd.go.cd.v7+json"
          },
          beforeSend: function() {
            Flash.clear();
          }
        }).then(function (res) {
          startClientDownload(res.data, res.xhr);
        }).catch(function (res) {
          handleError(res.xhr.status, new FileReader().readAsText(res.error))
        }).finally(function() {
          // hide loading indicator
        });

        function startClientDownload(responseBlob, xhr) {
          var name = xhr.getResponseHeader("Content-Disposition").replace(/^attachment; filename=/, "").replace(/^(")(.+)(\1)/, "$2");
          ExportAdapter.downloadAsFile(URL.createObjectURL(responseBlob), name);
        }

        function handleError(status, responseText) {
          Flash.error(JSON.parse(responseText).message);
        }
{'fraction_non_alphanumeric': 0.16156176371592057, 'fraction_numerical': 0.001682935038707506, 'mean_word_length': 2.6215722120658134, 'pattern_counts': {'":': 2, '<': 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': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4671026', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1723, 'n_words': 341}