<commit_before>/*jshint bitwise:true, indent:2, curly:true eqeqeq:true, immed:true,
latedef:true, newcap:true, noarg:true, regexp:true, undef:true,
trailing:true white:true*/
/*global XT:true, XV:true, XM:true, _:true, enyo:true*/

(function () {
  var MODULE_MENU = 0;
  var PANEL_MENU = 1;

  enyo.kind({
    name: "XV.Navigator",
    kind: "Panels",
    classes: "app enyo-unselectable",
    published: {
      modules: []
    },
    events: {
      onListAdded: "",
      onNavigatorEvent: "",
      onWorkspace: ""
    },
    handlers: {
      onParameterChange: "requery",
      onItemTap: "itemTap"
    },
    showPullout: true,
    arrangerKind: "CollapsingArranger",
    components: [
      {kind: "FittableRows", classes: "left", components: [
        {kind: "onyx.Toolbar", classes: "onyx-menu-toolbar", components: [
          {kind: "onyx.Button", name: "backButton", content: "_logout".loc(),
            ontap: "backTapped"},
          {kind: "Group", name: "iconButtonGroup",
            defaultKind: "onyx.IconButton", tag: null, components: [
            {name: "historyIconButton", src: "assets/menu-icon-bookmark.png",
              ontap: "showHistory"},
            {name: "searchIconButton", src: "assets/menu-icon-search.png",
              ontap: "showParameters", showing: false},
            {name: "myAccountButton", src: "assets/menu-icon-gear.png",
              ontap: "showMyAccount"},
            {name: "myAccountPopup", kind: "XV.MyAccountPopup"}
          ]},
          {kind: "onyx.Popup", name: "logoutPopup", centered: true,
            modal: true, floating: true, scrim: true, components: [
            {content: "_logoutConfirmation".loc() },
            {tag: "br"},
            {kind: "onyx.Button", content: "_ok".loc(), ontap: "logout",
              classes: "xv-popup-button"},
            {kind: "onyx.Button", content: "_cancel".loc(),
              ontap: "closeLogoutPopup",
              classes: "onyx-blue xv-popup-button"}
          ]}
        ]},
        {name: "menuPanels", kind: "Panels", draggable: false, fit: true,
          margin: 0, components: [
          {name: "moduleMenu", kind: "List", touch: true,
              onSetupItem: "setupModuleMenuItem",
              components: [
            {name: "moduleItem", classes: "item enyo-border-box"}
          ]},
          {name: "panelMenu", kind: "List", touch: true,
             onSetupItem: "setupPanelMenuItem", components: [
            {name: "listItem", classes: "item enyo-border-box"}
          ]},
          {} // Why do panels only work when there are 3+ objects?
        ]}
      ]},
      {kind: "FittableRows", components: [
        {kind: "onyx.MoreToolbar", name: "contentToolbar", components: [
          {name: "search", kind: "onyx.InputDecorator", style: "float: right;",
            showing: false, components: [
            {name: 'searchInput', kind: "onyx.Input", style: "width: 200px;",
              placeholder: "_search".loc(), onchange: "inputChanged"},
            {kind: "Image", src: "assets/search-input-search.png"}
          ]},
          {name: "newButton", kind: "onyx.Button", content: "_new".loc(),
            ontap: "newRecord", style: "float: right;", showing: false},
          {name: "exportButton", kind: "onyx.Button", content: "_export".loc(),
            ontap: "exportList", style: "float: right;", showing: false},
                                 // AWFUL UGLY HEINOUS HACK SHOULD NOT BE NECESSARY
          {kind: "onyx.Grabber", style: "height: 27px !important;"},
          {name: "rightLabel", style: "text-align: center"}
        ]},
        {name: "header", content: "", classes: "xv-navigator-header"},
        {name: "contentPanels", kind: "Panels", margin: 0, fit: true,
          draggable: false, panelCount: 0},
        {kind: "onyx.Popup", name: "errorPopup", centered: true,
          modal: true, floating: true, scrim: true, components: [
          {name: "errorMessage", content: "_error".loc()},
          {tag: "br"},
          {kind: "onyx.Button", content: "_ok".loc(), ontap: "errorOk",
            classes: "onyx-blue xv-popup-button"}
        ]}
      ]}
    ],
    fetched: {},
    activate: function () {
      this.setMenuPanel(MODULE_MENU);
    },
    backTapped: function () {
      var index = this.$.menuPanels.getIndex();
      if (index === MODULE_MENU) {
        this.warnLogout();
      } else {
        this.setHeaderContent("");
        this.setMenuPanel(MODULE_MENU);
      }
    },
    getSelectedModule: function (index) {
      return this._selectedModule;
    },
    exportList: function (inSender, inEvent) {
      var list = this.$.contentPanels.getActive(),
        coll = list.getValue(),
        recordType = coll.model.prototype.recordType,
        success = function (result) {
          var cacheId = result.cacheId;
          window.location = "https://localtest.com/export?cacheId=" + cacheId;
        },
        error = function (result) {
          XT.log("error");
          XT.log(result);
        },
        options = {responseType: "csv", success: success, error: error};

      // XXX I should be using some new datasource function here, not configure
      XT.dataSource.configure("createCSV", {"recordType": recordType}, options);
    },
    errorOk: function () {
      this.$.errorPopup.hide();
    },
    fetch: function (options) {
      options = options ? _.clone(options) : {};
      var index = options.index || this.$.contentPanels.getIndex(),
        list = this.$.contentPanels.getPanels()[index],
        name = list ? list.name : "",
        query,
        input,
        parameterWidget,
        parameters,
        filterDescription;
      if (list instanceof XV.List === false) { return; }
      this.fetched[index] = true;
      query = list.getQuery() || {};
      input = this.$.searchInput.getValue();
      parameterWidget = XT.app ? XT.app.getPullout().getItem(name) : null;
      parameters = parameterWidget ? parameterWidget.getParameters() : [];
      options.showMore = _.isBoolean(options.showMore) ?
        options.showMore : false;

      filterDescription = this.formatQuery(parameterWidget ? parameterWidget.getSelectedValues() : null, input);
      list.setFilterDescription(filterDescription);
      this.setHeaderContent(filterDescription);

      // Build parameters<commit_msg>export to CSV working fully the new way<commit_after>/*jshint bitwise:true, indent:2, curly:true eqeqeq:true, immed:true,
latedef:true, newcap:true, noarg:true, regexp:true, undef:true,
trailing:true white:true*/
/*global XT:true, XV:true, XM:true, _:true, enyo:true*/

(function () {
  var MODULE_MENU = 0;
  var PANEL_MENU = 1;

  enyo.kind({
    name: "XV.Navigator",
    kind: "Panels",
    classes: "app enyo-unselectable",
    published: {
      modules: []
    },
    events: {
      onListAdded: "",
      onNavigatorEvent: "",
      onWorkspace: ""
    },
    handlers: {
      onParameterChange: "requery",
      onItemTap: "itemTap"
    },
    showPullout: true,
    arrangerKind: "CollapsingArranger",
    components: [
      {kind: "FittableRows", classes: "left", components: [
        {kind: "onyx.Toolbar", classes: "onyx-menu-toolbar", components: [
          {kind: "onyx.Button", name: "backButton", content: "_logout".loc(),
            ontap: "backTapped"},
          {kind: "Group", name: "iconButtonGroup",
            defaultKind: "onyx.IconButton", tag: null, components: [
            {name: "historyIconButton", src: "assets/menu-icon-bookmark.png",
              ontap: "showHistory"},
            {name: "searchIconButton", src: "assets/menu-icon-search.png",
              ontap: "showParameters", showing: false},
            {name: "myAccountButton", src: "assets/menu-icon-gear.png",
              ontap: "showMyAccount"},
            {name: "myAccountPopup", kind: "XV.MyAccountPopup"}
          ]},
          {kind: "onyx.Popup", name: "logoutPopup", centered: true,
            modal: true, floating: true, scrim: true, components: [
            {content: "_logoutConfirmation".loc() },
            {tag: "br"},
            {kind: "onyx.Button", content: "_ok".loc(), ontap: "logout",
              classes: "xv-popup-button"},
            {kind: "onyx.Button", content: "_cancel".loc(),
              ontap: "closeLogoutPopup",
              classes: "onyx-blue xv-popup-button"}
          ]}
        ]},
        {name: "menuPanels", kind: "Panels", draggable: false, fit: true,
          margin: 0, components: [
          {name: "moduleMenu", kind: "List", touch: true,
              onSetupItem: "setupModuleMenuItem",
              components: [
            {name: "moduleItem", classes: "item enyo-border-box"}
          ]},
          {name: "panelMenu", kind: "List", touch: true,
             onSetupItem: "setupPanelMenuItem", components: [
            {name: "listItem", classes: "item enyo-border-box"}
          ]},
          {} // Why do panels only work when there are 3+ objects?
        ]}
      ]},
      {kind: "FittableRows", components: [
        {kind: "onyx.MoreToolbar", name: "contentToolbar", components: [
          {name: "search", kind: "onyx.InputDecorator", style: "float: right;",
            showing: false, components: [
            {name: 'searchInput', kind: "onyx.Input", style: "width: 200px;",
              placeholder: "_search".loc(), onchange: "inputChanged"},
            {kind: "Image", src: "assets/search-input-search.png"}
          ]},
          {name: "newButton", kind: "onyx.Button", content: "_new".loc(),
            ontap: "newRecord", style: "float: right;", showing: false},
          {name: "exportButton", kind: "onyx.Button", content: "_export".loc(),
            ontap: "exportList", style: "float: right;", showing: false},
                                 // AWFUL UGLY HEINOUS HACK SHOULD NOT BE NECESSARY
          {kind: "onyx.Grabber", style: "height: 27px !important;"},
          {name: "rightLabel", style: "text-align: center"}
        ]},
        {name: "header", content: "", classes: "xv-navigator-header"},
        {name: "contentPanels", kind: "Panels", margin: 0, fit: true,
          draggable: false, panelCount: 0},
        {kind: "onyx.Popup", name: "errorPopup", centered: true,
          modal: true, floating: true, scrim: true, components: [
          {name: "errorMessage", content: "_error".loc()},
          {tag: "br"},
          {kind: "onyx.Button", content: "_ok".loc(), ontap: "errorOk",
            classes: "onyx-blue xv-popup-button"}
        ]}
      ]}
    ],
    fetched: {},
    activate: function () {
      this.setMenuPanel(MODULE_MENU);
    },
    backTapped: function () {
      var index = this.$.menuPanels.getIndex();
      if (index === MODULE_MENU) {
        this.warnLogout();
      } else {
        this.setHeaderContent("");
        this.setMenuPanel(MODULE_MENU);
      }
    },
    getSelectedModule: function (index) {
      return this._selectedModule;
    },
    exportList: function (inSender, inEvent) {
      var list = this.$.contentPanels.getActive(),
        coll = list.getValue(),
        recordType = coll.model.prototype.recordType;

      window.location = "/export?details={\"requestType\":\"fetch\",\"query\":{\"recordType\":\"" + recordType + "\"}}";


        /*
        success = function (result) {
          var cacheId = result.cacheId;
          window.location = "https://localtest.com/export?cacheId=" + cacheId;
        },
        error = function (result) {
          XT.log("error");
          XT.log(result);
        },
        options = {responseType: "csv", success: success, error: error};

      // XXX I should be using some new datasource function here, not configure
      XT.dataSource.configure("createCSV", {"recordType": recordType}, options);
    */
    },
    errorOk: function () {
      this.$.errorPopup.hide();
    },
    fetch: function (options) {
      options = options ? _.clone(options) : {};
      var index = options.index || this.$.contentPanels.getIndex(),
        list = this.$.contentPanels.getPanels()[index],
        name = list ? list.name : "",
        query,
        input,
        parameterWidget,
        parameters,
        filterDescription;
      if (list instanceof XV.List === false) { return; }
      this.fetched[index] = true;
      query = list.getQuery() || {};
      input = this.$.searchInput.getValue();
      parameterWidget = XT.app ? XT.app.getPullout().getItem(name) : null;
      parameters = parameterWidget ? parameterWidget.getParameters() : [];
      options.showMore = _.isBoolean(options.showMore) ?
        options.showMore : false;

      filterDescription = this.formatQuery(parameterWidget ? parameterWidget.getSelectedValues() : null, input);
      list.setFilterDescription(filterDescription);
      this.setHeaderContent(filterDescription);

      // Build parameters
{'fraction_non_alphanumeric': 0.1569450925493856, 'fraction_numerical': 0.0018665422305179655, 'mean_word_length': 2.405455508474576, 'pattern_counts': {'":': 5, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5422113', 'n_tokens_mistral': 3903, 'n_tokens_neox': 3851, 'n_words': 871}