<commit_before><link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../../../bower_components/etools-content-panel/etools-content-panel.html">
<link rel="import" href="../../../bower_components/etools-ajax/etools-ajax-request-behavior.html">
<link rel="import" href="../../../bower_components/etools-data-table/etools-data-table.html">
<link rel="import" href="../../app-config/app-endpoints-behavior.html">
<link rel="import" href="../static-common-data/redux-behaviors/common-static-data-redux-behavior.html">

<link rel="import" href="../../../styles/grid-layout-styles.html">

<link rel="import" href="add-disaggregation-dialog.html">

<dom-module id="disaggregation-list">
  <template strip-whitespace>
    <style include="grid-layout-styles data-table-styles">
        [hidden] {
          display: none !important;
        }
    </style>

    <etools-content-panel panel-title="Disaggregations">
      <paper-icon-button slot="panel-btns"
                         icon="add-box"
                         on-tap="_addDisaggregation">
      </paper-icon-button>
      <div hidden$="[[_emptyList(disaggregations)]]">
        <etools-data-table-header no-collapse no-title>
          <etools-data-table-column class="col-4" field="name">
            Name
          </etools-data-table-column>
          <etools-data-table-column class="col-8" field="disaggregation_values">
            Disaggregation Groups
          </etools-data-table-column>
        </etools-data-table-header>
        <template is="dom-repeat" items="[[dataItems]]">
          <etools-data-table-row no-collapse>
            <div slot="row-data">
              <span class="col-data col-4">
                [[item.name]]
              </span>
              <span class="col-data col-8">
                [[_displayGroups(item.disaggregation_values)]]
              </span>
            </div>
          </etools-data-table-row>
        </template>

        <etools-data-table-footer
          page-size="[[pagination.pageSize]]"
          page-number="[[pagination.pageNumber]]"
          total-results="[[pagination.totalResults]]"
          on-page-size-changed="_pageSizeChanged"
          on-page-number-changed="_pageNumberChanged">
        </etools-data-table-footer>
      </div>
      <div class="row-padding" hidden$="[[!_emptyList(disaggregations)]]">
        <p>The are no disaggregations defined.</p>
      </div>
    </etools-content-panel>


 </template>

<script>
  (function() {
    'use strict';
    Polymer({
      is: 'disaggregation-list',

      behaviors: [
        EtoolsPmpApp.Behaviors.Endpoints,
        EtoolsPmpApp.Behaviors.EtoolsDataReduxStore,
        EtoolsAjaxRequestBehavior
      ],

      properties: {
        disaggregations: {
          type: Array,
          statePath: 'disaggregations',
          observer: '_disagregationsChanged'
        },
        dataItems: {
          type: Array
        },
        disaggregationModal: {
          type: Object
        },
        pagination: {
          type: Object,
          value: {
            pageSize: 10,
            pageNumber: 1,
            totalResults: null
          }
        }
      },
      observers: [
        'paginationChanged(pagination.pageNumber, pagination.pageSize, disaggregations)'
      ],

      ready: function() {
        this.editMode = true;
        this.disaggregationModal = document.createElement('add-disaggregation-dialog');
        this.disaggregationModal.setAttribute('id', 'disaggregationModal');
        document.querySelector('body').appendChild(this.disaggregationModal);
      },
      _emptyList: function() {
        return !this.disaggregations || !this.disaggregations.length;
      },
      _disagregationsChanged: function(disaggregs) {
        if (!disaggregs || !disaggregs.length) {
          this.dataItems = [];
          return;
        }
        this.set('pagination.totalResults', this.disaggregations.length);
      },
      _pageSizeChanged: function(ev) {
        this.set('pagination.pageNumber', 1);
        this.set('pagination.pageSize', parseInt(ev.detail.value));
      },
      _pageNumberChanged: function(ev) {
        this.set('pagination.pageNumber', parseInt(ev.detail.value));
      },
      paginationChanged: function(pageNumber, pageSize) {
        pageNumber = parseInt(pageNumber);
        pageSize = parseInt(pageSize);
        let startingIndex = (pageNumber - 1) * pageSize;
        this.dataItems = this.disaggregations.slice(startingIndex, startingIndex + pageSize);
      },
      detached: function() {
        if (this.disaggregationModal) {
          document.querySelector('body').removeChild(this.disaggregationModal);
        }
      },
      _openModal: function() {
        this.disaggregationModal.toastEventSource = this;
        this.disaggregationModal.resetValidations();
        this.disaggregationModal.open();
      },
      _displayGroups: function(groups) {
        if (!groups || !groups.length) {
          return '-';
        }
        return groups.map(function(g) {
          return g.value;
        }).join('; ');
      },
      _addDisaggregation: function() {
        this.disaggregationModal.initializeDisaggregation();
        this._openModal();
      }

    });
  })();
</script>

</dom-module>
<commit_msg>Fix disaggregations not displayed sometimes<commit_after><link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../../../bower_components/etools-content-panel/etools-content-panel.html">
<link rel="import" href="../../../bower_components/etools-ajax/etools-ajax-request-behavior.html">
<link rel="import" href="../../../bower_components/etools-data-table/etools-data-table.html">
<link rel="import" href="../../app-config/app-endpoints-behavior.html">
<link rel="import" href="../static-common-data/redux-behaviors/common-static-data-redux-behavior.html">
<link rel="import" href="../environment-flags/environment-flags-behavior.html">

<link rel="import" href="../../../styles/grid-layout-styles.html">

<link rel="import" href="add-disaggregation-dialog.html">

<dom-module id="disaggregation-list">
  <template strip-whitespace>
    <style include="grid-layout-styles data-table-styles">
        [hidden] {
          display: none !important;
        }
    </style>

    <etools-content-panel panel-title="Disaggregations">
      <paper-icon-button slot="panel-btns"
                         icon="add-box"
                         on-tap="_addDisaggregation">
      </paper-icon-button>
      <div hidden$="[[_emptyList(disaggregations)]]">
        <etools-data-table-header no-collapse no-title>
          <etools-data-table-column class="col-4" field="name">
            Name
          </etools-data-table-column>
          <etools-data-table-column class="col-8" field="disaggregation_values">
            Disaggregation Groups
          </etools-data-table-column>
        </etools-data-table-header>
        <template is="dom-repeat" items="[[dataItems]]">
          <etools-data-table-row no-collapse>
            <div slot="row-data">
              <span class="col-data col-4">
                [[item.name]]
              </span>
              <span class="col-data col-8">
                [[_displayGroups(item.disaggregation_values)]]
              </span>
            </div>
          </etools-data-table-row>
        </template>

        <etools-data-table-footer
          page-size="[[pagination.pageSize]]"
          page-number="[[pagination.pageNumber]]"
          total-results="[[pagination.totalResults]]"
          on-page-size-changed="_pageSizeChanged"
          on-page-number-changed="_pageNumberChanged">
        </etools-data-table-footer>
      </div>
      <div class="row-padding" hidden$="[[!_emptyList(disaggregations)]]">
        <p>The are no disaggregations defined.</p>
      </div>
    </etools-content-panel>


 </template>

<script>
  (function() {
    'use strict';
    Polymer({
      is: 'disaggregation-list',

      behaviors: [
        EtoolsPmpApp.Behaviors.Endpoints,
        EtoolsPmpApp.Behaviors.EtoolsDataReduxStore,
        EtoolsAjaxRequestBehavior,
        EtoolsPmpApp.Behaviors.EnvironmentFlags
      ],

      properties: {
        disaggregations: {
          type: Array,
          statePath: 'disaggregations',
        },
        dataItems: {
          type: Array
        },
        disaggregationModal: {
          type: Object
        },
        pagination: {
          type: Object,
          value: {
            pageSize: 10,
            pageNumber: 1,
            totalResults: null
          }
        }
      },
      observers: [
        'paginationChanged(pagination.pageNumber, pagination.pageSize, disaggregations)',
        '_disagregationsChanged(disaggregations, environmentFlags)'
      ],

      ready: function() {
        this.editMode = true;
        this.disaggregationModal = document.createElement('add-disaggregation-dialog');
        this.disaggregationModal.setAttribute('id', 'disaggregationModal');
        document.querySelector('body').appendChild(this.disaggregationModal);
      },
      _emptyList: function() {
        return !this.disaggregations || !this.disaggregations.length;
      },
      _disagregationsChanged: function(disaggregs, envFlags) {
        if (!disaggregs || !disaggregs.length) {
          this.dataItems = [];
          return;
        }
        this.set('pagination.totalResults', this.disaggregations.length);
      },
      _pageSizeChanged: function(ev) {
        this.set('pagination.pageNumber', 1);
        this.set('pagination.pageSize', parseInt(ev.detail.value));
      },
      _pageNumberChanged: function(ev) {
        this.set('pagination.pageNumber', parseInt(ev.detail.value));
      },
      paginationChanged: function(pageNumber, pageSize, disaggregations) {
        pageNumber = parseInt(pageNumber);
        pageSize = parseInt(pageSize);
        let startingIndex = (pageNumber - 1) * pageSize;
        this.dataItems = this.disaggregations.slice(startingIndex, startingIndex + pageSize);
      },
      detached: function() {
        if (this.disaggregationModal) {
          document.querySelector('body').removeChild(this.disaggregationModal);
        }
      },
      _openModal: function() {
        this.disaggregationModal.toastEventSource = this;
        this.disaggregationModal.resetValidations();
        this.disaggregationModal.open();
      },
      _displayGroups: function(groups) {
        if (!groups || !groups.length) {
          return '-';
        }
        return groups.map(function(g) {
          return g.value;
        }).join('; ');
      },
      _addDisaggregation: function() {
        this.disaggregationModal.initializeDisaggregation();
        this._openModal();
      }

    });
  })();
</script>

</dom-module>

{'fraction_non_alphanumeric': 0.1482758620689655, 'fraction_numerical': 0.001633393829401089, 'mean_word_length': 2.324585218702866, 'pattern_counts': {'":': 0, '<': 94, '<?xml version=': 0, '>': 94, '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': '929300', 'n_tokens_mistral': 3241, 'n_tokens_neox': 3172, 'n_words': 446}