<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, XM:true, XV:true, _:true, enyo:true, Globalize:true*/

(function () {

  var FIRST_FETCH = 20;
  var FETCH_TRIGGER = 5;
  
  /**
    @class

    List to attach to workspaces to present related data.

    @extends enyo.List
  */
  enyo.kind({
    name: "XV.ListRelations",
    kind: "List",
    classes: "xv-list",
    fixedHeight: true,
    toggleSelected: true,
    published: {
      attr: null,
      value: null,
      parentKey: "",
      orderBy: null
    },
    handlers: {
      onSetupItem: "setupItem"
    },
    destroy: function () {
      // Clear all bindings
      var value = this.getValue(),
        models = value ? value.models : null;
      if (models) {
        _.each(models, function (model) {
          model.off('statusChange', this.statusChanged, this);
        });
      }
      if (value) {
        value.off("add", this.modelAdded, this);
        value.off("remove", this.lengthChanged, this);
      }
      this.inherited(arguments);
    },
    getFirstSelected: function () {
      var selected = this.getSelection().selected,
        prop;
      for (prop in selected) {
        if (selected.hasOwnProperty(prop)) {
          return prop;
        }
      }
    },
    getModel: function (index) {
      return this.readyModels()[index];
    },
    getParent: function () {
      var key = this.getParentKey(),
        value = this.getValue();
      return key && value ? value[key] : null;
    },
    fetchRelated: function (max) {
      var parent = this.getParent(),
        attr = this.getAttr(),
        options = { max: max || FIRST_FETCH };
      if (this.hasMore()) {
        parent.fetchRelated(attr, options);
      }
    },
    hasMore: function () {
      var parent = this.getParent(),
        value = this.getValue(),
        count = value ? value.length : 0,
        attr = this.getAttr(),
        relation = parent && attr ? parent.getRelation(attr) : null,
        keyContents = relation && relation.keyContents ? relation.keyContents : [];
      return count < keyContents.length;
    },
    lengthChanged: function () {
      var count = this.readyModels().length,
        value = this.getValue(),
        rowsPerPage;
      if (count === this.count) { return; }
        
      // Hack: Solves scroll problem for small number of rows
      // but doesn't seem quite right
      rowsPerPage = count && 50 > count ? count : 50;
      if (rowsPerPage !== this.rowsPerPage) {
        this.setRowsPerPage(rowsPerPage);
      }
      if (value.comparator) { value.sort(); }
      this.setCount(count);
      this.refresh();
    },
    modelAdded: function (model) {
      var status = model.getStatus(),
        K = XM.Model;
      if (status === K.READY_CLEAN ||
          status === K.READY_NEW) {
        this.lengthChanged();
      } else {
        model.on('statusChange', this.statusChanged, this);
      }
    },
    orderByChanged: function () {
      var orderBy = this.getOrderBy() || [],
        value = this.getValue();
      if (value && orderBy.length) {
        value.comparator = function (a, b) {
          var aval,
            bval,
            attr,
            i;
          for (i = 0; i < orderBy.length; i++) {
            attr = orderBy[i].attribute;
            aval = orderBy[i].descending ? b.getValue(attr) : a.getValue(attr);
            bval = orderBy[i].descending ? a.getValue(attr) : b.getValue(attr);
            aval = !isNaN(aval) ? aval - 0 : aval;
            bval = !isNaN(aval) ? bval - 0 : bval;
            if (aval !== bval) {
              return aval > bval ? 1 : -1;
            }
          }
          return 0;
        };
      }
    },
    readyModels: function () {
      return _.filter(this.value.models, function (model) {
        var status = model.getStatus(),
          K = XM.Model;
        // Avoiding bitwise because performance matters here
        return (status === K.READY_CLEAN ||
                status === K.READY_DIRTY ||
                status === K.READY_NEW);
      });
    },
    scroll: function (inSender, inEvent) {
      var r = this.inherited(arguments),
        bounds = this.getScrollBounds(),
        lastShowing = this._lastShowing || 0,
        totalRows = this.value.length,
        rowsPerPage = bounds.clientHeight / this.rowHeight,
        showingRows = Math.floor(bounds.top / this.rowHeight + rowsPerPage),
        fetch =  showingRows > lastShowing &&
          totalRows - showingRows - FETCH_TRIGGER < 0 &&
          this.hasMore();
          
      // Manage lazy loading
      if (fetch) {
        this._lastShowing = showingRows;
        this.fetchRelated(1);
      }
      return r;
    },
    setupItem: function (inSender, inEvent) {
      var index = inEvent.index,
        isSelected = inEvent.originator.isSelected(index),
        model = this.readyModels()[index],<commit_msg>issue #18441: issue #18510: Fix problems navigating to workspace on iPad.<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, XM:true, XV:true, _:true, enyo:true, Globalize:true*/

(function () {

  var FIRST_FETCH = 20;
  var FETCH_TRIGGER = 5;
  
  /**
    @class

    List to attach to workspaces to present related data.

    @extends enyo.List
  */
  enyo.kind({
    name: "XV.ListRelations",
    kind: "List",
    classes: "xv-list",
    fixedHeight: true,
    toggleSelected: true,
    published: {
      attr: null,
      value: null,
      parentKey: "",
      orderBy: null
    },
    handlers: {
      onSetupItem: "setupItem"
    },
    destroy: function () {
      // Clear all bindings
      var value = this.getValue(),
        models = value ? value.models : null;
      if (models) {
        _.each(models, function (model) {
          model.off('statusChange', this.statusChanged, this);
        });
      }
      if (value) {
        value.off("add", this.modelAdded, this);
        value.off("remove", this.lengthChanged, this);
      }
      this.inherited(arguments);
    },
    getFirstSelected: function () {
      var selected = this.getSelection().selected,
        prop;
      for (prop in selected) {
        if (selected.hasOwnProperty(prop)) {
          return prop;
        }
      }
    },
    getModel: function (index) {
      return this.readyModels()[index];
    },
    getParent: function () {
      var key = this.getParentKey(),
        value = this.getValue();
      return key && value ? value[key] : null;
    },
    fetchRelated: function (max) {
      var parent = this.getParent(),
        attr = this.getAttr(),
        options = { max: max || FIRST_FETCH };
      if (this.hasMore()) {
        parent.fetchRelated(attr, options);
      }
    },
    hasMore: function () {
      var parent = this.getParent(),
        value = this.getValue(),
        count = value ? value.length : 0,
        attr = this.getAttr(),
        relation = parent && attr ? parent.getRelation(attr) : null,
        keyContents = relation && relation.keyContents ? relation.keyContents : [];
      return count < keyContents.length;
    },
    lengthChanged: function () {
      var count = this.readyModels().length,
        value = this.getValue(),
        rowsPerPage;
      if (count === this.count) { return; }
        
      // Hack: Solves scroll problem for small number of rows
      // but doesn't seem quite right
      rowsPerPage = count && 50 > count ? count : 50;
      if (rowsPerPage !== this.rowsPerPage) {
        this.setRowsPerPage(rowsPerPage);
      }
      if (value.comparator) { value.sort(); }
      this.setCount(count);
      this.refresh();
    },
    modelAdded: function (model) {
      var status = model.getStatus(),
        K = XM.Model;
      if (status === K.READY_CLEAN ||
          status === K.READY_NEW) {
        this.lengthChanged();
      } else {
        model.on('statusChange', this.statusChanged, this);
      }
    },
    orderByChanged: function () {
      var orderBy = this.getOrderBy() || [],
        value = this.getValue();
      if (value && orderBy.length) {
        value.comparator = function (a, b) {
          var aval,
            bval,
            attr,
            i;
          for (i = 0; i < orderBy.length; i++) {
            attr = orderBy[i].attribute;
            aval = orderBy[i].descending ? b.getValue(attr) : a.getValue(attr);
            bval = orderBy[i].descending ? a.getValue(attr) : b.getValue(attr);
            aval = !isNaN(aval) ? aval - 0 : aval;
            bval = !isNaN(aval) ? bval - 0 : bval;
            if (aval !== bval) {
              return aval > bval ? 1 : -1;
            }
          }
          return 0;
        };
      }
    },
    readyModels: function () {
      return _.filter(this.value.models, function (model) {
        var status = model.getStatus(),
          K = XM.Model;
        // Avoiding bitwise because performance matters here
        return (status === K.READY_CLEAN ||
                status === K.READY_DIRTY ||
                status === K.READY_NEW);
      });
    },
    scroll: function (inSender, inEvent) {
      var r = this.inherited(arguments),
        bounds = this.getScrollBounds(),
        lastShowing = this._lastShowing || 0,
        totalRows = this.value ? this.value.length : 0,
        rowsPerPage = bounds.clientHeight / this.rowHeight,
        showingRows = Math.floor(bounds.top / this.rowHeight + rowsPerPage),
        fetch =  showingRows > lastShowing &&
          totalRows - showingRows - FETCH_TRIGGER < 0 &&
          this.hasMore();
          
      // Manage lazy loading
      if (fetch) {
        this._lastShowing = showingRows;
        this.fetchRelated(1);
      }
      return r;
    },
    setupItem: function (inSender, inEvent) {
      var index = inEvent.index,
        isSelected = inEvent.originator.isSelected(index),
        model = this.readyModels()[index],
{'fraction_non_alphanumeric': 0.1326338711273879, 'fraction_numerical': 0.00465208353954271, 'mean_word_length': 1.98493353028065, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4605698', 'n_tokens_mistral': 3101, 'n_tokens_neox': 3014, 'n_words': 711}