<commit_before><link rel="import" href="../../../scripts/lodash.html">
<script>
  'use strict';

  window.EtoolsPmpApp = window.EtoolsPmpApp || {};
  window.EtoolsPmpApp.Mixins = window.EtoolsPmpApp.Mixins || {};

  /**
   * PD/SSFA fields prepare for save functionality
   * @polymer
   * @mixinFunction
   */
  EtoolsPmpApp.Mixins.ModifiedInterventionFields = Polymer.dedupingMixin((superClass) => class extends superClass {

    _objectFieldIsModified(fieldName) {
      let isModified = JSON.stringify(this.originalIntervention[fieldName]) !==
          JSON.stringify(this.intervention[fieldName]);

      let dropdownArrayFields = ['partner_focal_points', 'unicef_focal_points', 'offices'];
      if (isModified && dropdownArrayFields.indexOf(fieldName) > -1) {
        // Covers dropdown arrays which can have same content but with changed order
        if (this._arraysAreEqual(this.originalIntervention[fieldName], this.intervention[fieldName])) {
          isModified = false;
        }
      }
      return isModified;
    }

    _arraysAreEqual(array1, array2) {
      let differencesArray = [];
      if ((!array1 && (array2 && array2.length)) || (!array2 && (array1 && array1.length))) {
        return false;
      }
      if (array1.length > array2.length) {
        differencesArray = _.difference(array1, array2);
      } else {
        differencesArray = _.difference(array2, array1);
      }
      return _.isEmpty(differencesArray);
    }<commit_msg>A solution to pl. visits, pl. budget seen as modified on Save when not the case<commit_after><link rel="import" href="../../../scripts/lodash.html">
<script>
  'use strict';

  window.EtoolsPmpApp = window.EtoolsPmpApp || {};
  window.EtoolsPmpApp.Mixins = window.EtoolsPmpApp.Mixins || {};

  /**
   * PD/SSFA fields prepare for save functionality
   * @polymer
   * @mixinFunction
   */
  EtoolsPmpApp.Mixins.ModifiedInterventionFields = Polymer.dedupingMixin((superClass) => class extends superClass {

    _objectFieldIsModified(fieldName) {
      let isModified = JSON.stringify(this.originalIntervention[fieldName], this.numbersToString) !==
          JSON.stringify(this.intervention[fieldName], this.numbersToString);

      let dropdownArrayFields = ['partner_focal_points', 'unicef_focal_points', 'offices'];
      if (isModified && dropdownArrayFields.indexOf(fieldName) > -1) {
        // Covers dropdown arrays which can have same content but with changed order
        if (this._arraysAreEqual(this.originalIntervention[fieldName], this.intervention[fieldName])) {
          isModified = false;
        }
      }
      return isModified;
    }
    /**
     * Covers the case when the object from bk (this.originalIntervention)
     * has numbers but this.interventions has strings,
     * so we convert everything to string before comparing
     */
    numbersToString(key, value) {
      if (typeof value === 'number') {
        return value.toString();
      }
      return value;
    }
    _arraysAreEqual(array1, array2) {
      let differencesArray = [];
      if ((!array1 && (array2 && array2.length)) || (!array2 && (array1 && array1.length))) {
        return false;
      }
      if (array1.length > array2.length) {
        differencesArray = _.difference(array1, array2);
      } else {
        differencesArray = _.difference(array2, array1);
      }
      return _.isEmpty(differencesArray);
    }
{'fraction_non_alphanumeric': 0.12338044758539458, 'fraction_numerical': 0.0088339222614841, 'mean_word_length': 3.1175757575757577, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '6081953', 'n_tokens_mistral': 1007, 'n_tokens_neox': 970, 'n_words': 212}