<commit_before>// ==========================================================================
//  
//  Author:   jsandoe
//
//  Copyright (c) 2015 by The Concord Consortium, Inc. All rights reserved.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// ==========================================================================
/** @class  DG.CaseTableModel - The model for a slider. Holds onto a global value.

 @extends SC.Object
 */
DG.CaseTableModel = SC.Object.extend(/** @scope DG.CaseTableModel.prototype */ {
  /**
   @property { DG.DataContext }
   */
  context: null,

  id: null,
  idBinding: '*context.id',

  name: null,
  nameBinding: '*context.name',

  defaultTitle: function() {
    return this.getPath('context.defaultTitle');
  }.property(),

  defaultTitleDidChange: function () {
    return this.notifyPropertyChange('defaultTitle');
  }.observes('*context.defaultTitle'),

  /**
   * Attribute widths as requested by the user, keyed by attribute id.
   *
   * @property {Object} a hash of widths (pixels) keyed by attribute id.
   */
  preferredAttributeWidths: null,

  /**
   * Case table widths as requested by the user, keyed by caseTable id.
   *
   * @property {Object} a hash of widths (pixels) keyed by caseTable id.
   */
  preferredTableWidths: null,

  /**
   * A hash of case ids and their collapsed state and whether they are visible
   * or superseded by a collapsed case in a higher order table.
   * @type [{{isCollapsed: boolean, isHidden: boolean, collapsedCase: DG.Case}}]
   */
  collapsedNodes: null,

  init: function () {
    sc_super();
    this.preferredAttributeWidths = this.preferredAttributeWidths || {};
    this.preferredTableWidths = this.preferredTableWidths || {};
    this.collapsedNodes = this.collapsedNodes || [];
  },

  getPreferredAttributeWidth: function (attrID) {
    return this.preferredAttributeWidths[attrID];
  },

  setPreferredAttributeWidth: function(attrID, width) {
    this.preferredAttributeWidths[attrID] = width;
  },

  didDeleteCases: function (iCases) {
    iCases.forEach(function (iCase) {
      var id = iCase.get('id');
      delete this.collapsedNodes[id];
    }.bind(this));
  },
  /**
   * Whether node is collapsed and not hidden by another collapsed node.
   * @param iCase {DG.Case}
   * @returns {*|boolean}
   */
  isCollapsedNode: function (iCase) {
    var node = this.collapsedNodes[iCase.id];
    var isCollapsed = false;
    if (node) {
      isCollapsed = node.isCollapsed && !node.isHidden;
    }
    return isCollapsed;
  },

  /**
   * Whether the case is within a collapsed node.
   * @param iCase {DG.Case}
   */
  isHiddenNode: function (iCase) {
    var parent = iCase.get('parent');
    var isHidden = false;
    var parentCollapseState;
    if (parent) {
      parentCollapseState = this.collapsedNodes[parent.id];
      if (parentCollapseState && parentCollapseState.isCollapsed) {
        isHidden = true;
      } else {
        isHidden = this.isHiddenNode(parent);
      }
    }
    return isHidden;
  },

  /**
   * Marks a case as collapsed. In subordinate case tables the group of cases
   * descending from this case will appear only in summary.
   *
   * Will mark any collapsed cases that are descendents as hidden. The fact of
   * their collapsed state will be retained, but will have no effect unless this
   * case is expanded again.
   *
   * @param iCase {DG.Case}
   */
  collapseNode: function(iCase) {
    var collapseState = this.collapsedNodes[iCase.id];
    if (!collapseState) {
      collapseState = {
        collapsedCase: iCase
      };
      this.collapsedNodes[iCase.id] = collapseState;
    }
    collapseState.isCollapsed = true;
    this.collapsedNodes.forEach(function (cs) {
      cs.isHidden = this.isHiddenNode(cs.collapsedCase);
    }.bind(this));
  },

  /**
   * Marks a case as not collapsed.
   *
   * Will reset any hidden collapsed cases to their correct state.
   *
   * @param iCase {DG.Case}
   */
  expandNode: function (iCase) {
    var collapseState = this.collapsedNodes[iCase.id];
    if (!collapseState) {
      collapseState = {
        collapsedCase: iCase
      };
      this.collapsedNodes[iCase.id] = collapseState;
    }
    collapseState.isCollapsed = false;
    this.collapsedNodes.forEach(function (cs) {
      cs.isHidden = this.isHiddenNode(cs.collapsedCase);
    }.bind(this));
  }
});
<commit_msg>[#127238937] Fix bug: With case table open Ship Odyssey would cause a crash on Site transition.<commit_after>// ==========================================================================
//  
//  Author:   jsandoe
//
//  Copyright (c) 2015 by The Concord Consortium, Inc. All rights reserved.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// ==========================================================================
/** @class  DG.CaseTableModel - The model for a slider. Holds onto a global value.

 @extends SC.Object
 */
DG.CaseTableModel = SC.Object.extend(/** @scope DG.CaseTableModel.prototype */ {
  /**
   @property { DG.DataContext }
   */
  context: null,

  id: null,
  idBinding: '*context.id',

  name: null,
  nameBinding: '*context.name',

  defaultTitle: function() {
    return this.getPath('context.defaultTitle');
  }.property(),

  defaultTitleDidChange: function () {
    return this.notifyPropertyChange('defaultTitle');
  }.observes('*context.defaultTitle'),

  /**
   * Attribute widths as requested by the user, keyed by attribute id.
   *
   * @property {Object} a hash of widths (pixels) keyed by attribute id.
   */
  preferredAttributeWidths: null,

  /**
   * Case table widths as requested by the user, keyed by caseTable id.
   *
   * @property {Object} a hash of widths (pixels) keyed by caseTable id.
   */
  preferredTableWidths: null,

  /**
   * A hash of case ids and their collapsed state and whether they are visible
   * or superseded by a collapsed case in a higher order table.
   * @type [{{isCollapsed: boolean, isHidden: boolean, collapsedCase: DG.Case}}]
   */
  collapsedNodes: null,

  init: function () {
    sc_super();
    this.preferredAttributeWidths = this.preferredAttributeWidths || {};
    this.preferredTableWidths = this.preferredTableWidths || {};
    this.collapsedNodes = this.collapsedNodes || [];
  },

  getPreferredAttributeWidth: function (attrID) {
    return this.preferredAttributeWidths[attrID];
  },

  setPreferredAttributeWidth: function(attrID, width) {
    this.preferredAttributeWidths[attrID] = width;
  },

  didDeleteCases: function (iCases) {
    if (iCases) {
      iCases.forEach(function (iCase) {
        var id = iCase.get('id');
        delete this.collapsedNodes[id];
      }.bind(this));
    }
  },
  /**
   * Whether node is collapsed and not hidden by another collapsed node.
   * @param iCase {DG.Case}
   * @returns {*|boolean}
   */
  isCollapsedNode: function (iCase) {
    var node = this.collapsedNodes[iCase.id];
    var isCollapsed = false;
    if (node) {
      isCollapsed = node.isCollapsed && !node.isHidden;
    }
    return isCollapsed;
  },

  /**
   * Whether the case is within a collapsed node.
   * @param iCase {DG.Case}
   */
  isHiddenNode: function (iCase) {
    var parent = iCase.get('parent');
    var isHidden = false;
    var parentCollapseState;
    if (parent) {
      parentCollapseState = this.collapsedNodes[parent.id];
      if (parentCollapseState && parentCollapseState.isCollapsed) {
        isHidden = true;
      } else {
        isHidden = this.isHiddenNode(parent);
      }
    }
    return isHidden;
  },

  /**
   * Marks a case as collapsed. In subordinate case tables the group of cases
   * descending from this case will appear only in summary.
   *
   * Will mark any collapsed cases that are descendents as hidden. The fact of
   * their collapsed state will be retained, but will have no effect unless this
   * case is expanded again.
   *
   * @param iCase {DG.Case}
   */
  collapseNode: function(iCase) {
    var collapseState = this.collapsedNodes[iCase.id];
    if (!collapseState) {
      collapseState = {
        collapsedCase: iCase
      };
      this.collapsedNodes[iCase.id] = collapseState;
    }
    collapseState.isCollapsed = true;
    this.collapsedNodes.forEach(function (cs) {
      cs.isHidden = this.isHiddenNode(cs.collapsedCase);
    }.bind(this));
  },

  /**
   * Marks a case as not collapsed.
   *
   * Will reset any hidden collapsed cases to their correct state.
   *
   * @param iCase {DG.Case}
   */
  expandNode: function (iCase) {
    var collapseState = this.collapsedNodes[iCase.id];
    if (!collapseState) {
      collapseState = {
        collapsedCase: iCase
      };
      this.collapsedNodes[iCase.id] = collapseState;
    }
    collapseState.isCollapsed = false;
    this.collapsedNodes.forEach(function (cs) {
      cs.isHidden = this.isHiddenNode(cs.collapsedCase);
    }.bind(this));
  }
});

{'fraction_non_alphanumeric': 0.13989480072830265, 'fraction_numerical': 0.0025288286465709083, 'mean_word_length': 3.1041926110419262, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1079041', 'n_tokens_mistral': 2998, 'n_tokens_neox': 2886, 'n_words': 869}