<commit_before><link rel="import" href="../../../../bower_components/polymer/polymer-element.html">
<link rel="import" href="../../../../bower_components/iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../../../../bower_components/etools-file/etools-file.html">
<link rel="import" href="../../mixins/common-mixin.html">
<link rel="import" href="../../styles/file-styles.html">
<link rel="import" href="../../styles/required-field-styles.html">

<dom-module id="etools-single-file">
  <template>
    <style include="file-styles required-field-starred-styles">
      :host {
        @apply --layout-horizontal;
        width: 100%;
        min-height: 62px;
      }

      #file-wrapper {
        width: 100%;
      }
    </style>
    <div id="file-wrapper" class="file-container">
      <etools-file id="files"
                   files="{{attachments}}"
                   label="[[label]]"
                   accept="[[accept]]"
                   readonly$="[[readonly]]"
                   invalid$="[[invalid]]"
                   error-message=[[errorMessage]]
                   hide-delete-btn="[[hideDeleteBtn]]"
                   on-blur="_fileInputFocused"
                   target="_blank">
      </etools-file>
    </div>
  </template>

  <script>
    'use strict';

    /**
     * @polymer
     * @customElement
     * @appliesMixin EtoolsPmpApp.Mixins.Common
     */
    class EtoolsSingleFile extends EtoolsPmpApp.Mixins.Common(Polymer.Element) {

      static get is() {
        return 'etools-single-file';
      }

      static get properties() {
        return {
          attachments: {
            type: Array,
            value: function() {
              return [];
            }
          },
          readonly: {
            type: Boolean,
            value: false
          },
          required: {
            type: Boolean,
            value: false,
            observer: '_requiredChanged'
          },
          autoValidate: Boolean,
          accept: String,
          label: String,
          file: {
            type: Object,
            notify: true,
            observer: '_fileChanged'
          },
          internalFile: {
            type: Object,
            observer: '_internalFileChanged'
          },
          elemAttached: {
            type: Boolean,
            value: false
          },
          invalid: {
            type: Boolean,
            value: false
          },
          errorMessage: {
            type: String,
            value: 'Please select a file'
          },
          hideDeleteBtn: {
            type: Boolean,
            reflectToAttribute: true
          }
        };
      }

      static get observers() {
        return [
          '_attachmentChanged(attachments.length)',
          '_fileReplaced(attachments.*)',
          '_refreshStyles(readonly, required)'
        ];
      }

      connectedCallback() {
        super.connectedCallback();
        this.elemAttached = true;
      }

      _internalFileChanged(intr) {
        if (typeof intr === 'undefined') {
          return;
        }
        if (this.internalFile) {
          this.set('attachments', this.prepareEtoolsFileDataFromUrl(this.internalFile));
        } else {
          this.set('attachments', []);
        }
      }

      _attachmentChanged(filesLength) {
        if (typeof filesLength === 'undefined') {
          return;
        }
        if (filesLength > 0) {
          if (this.attachments[0].raw instanceof File) {
            this.set('file', this.attachments[0].raw);
          } else if (typeof this.internalFile === 'string' && !!this.internalFile.length) {
            this.set('file', this.internalFile);
          } else {
            this.set('file', null);
          }
        } else {
          this.set('file', null);
        }
      }

      _fileReplaced(data) {
        if (typeof data === 'undefined') {
          return;
        }
        if ((data.path.indexOf('attachments.#') > -1)) {
          // file changed
          this._attachmentChanged(this.attachments.length);
        }
      }

      validate() {
        if (this.required && !this.readonly && this.file instanceof File === false &&
            (typeof this.file === 'string' ? !this.file.length : true)) {
          this.set('invalid', true);
          return false;
        }
        this.set('invalid', false);
        return true;
      }

      _fileChanged(file) {
        if (typeof file === 'undefined') {
          return;
        }
        if (file === null) {
          //reset previous value here as observer on internalFile is not triggered on one way binding
          this.set('attachments', []);
        }
        // elemAttached condition is to prevent eager validation
        if (this.autoValidate && this.elemAttached) {
          this.validate();
        }
      }

      _refreshStyles(readonly, required) {
        if (typeof readonly === 'undefined' && typeof required === 'undefined') {
          return;
        }
        this.updateStyles();
      }

      _requiredChanged(req) {
        if (typeof req === 'undefined') {
          return;
        }
        if (req === false) {
          this.validate();
        }
      }

      // covers the case when the users cancels file upload
      _fileInputFocused() {
        this._fileChanged(this.file);
      }<commit_msg>Lint fix<commit_after><link rel="import" href="../../../../bower_components/polymer/polymer-element.html">
<link rel="import" href="../../../../bower_components/iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../../../../bower_components/etools-file/etools-file.html">
<link rel="import" href="../../mixins/common-mixin.html">
<link rel="import" href="../../styles/file-styles.html">
<link rel="import" href="../../styles/required-field-styles.html">

<dom-module id="etools-single-file">
  <template>
    <style include="file-styles required-field-starred-styles">
      :host {
        @apply --layout-horizontal;
        width: 100%;
        min-height: 62px;
      }

      #file-wrapper {
        width: 100%;
      }
    </style>
    <div id="file-wrapper" class="file-container">
      <etools-file id="files"
                   files="{{attachments}}"
                   label="[[label]]"
                   accept="[[accept]]"
                   readonly$="[[readonly]]"
                   invalid$="[[invalid]]"
                   error-message=[[errorMessage]]
                   hide-delete-btn="[[hideDeleteBtn]]"
                   on-blur="_fileInputFocused"
                   target="_blank">
      </etools-file>
    </div>
  </template>

  <script>
    'use strict';

    /**
     * @polymer
     * @customElement
     * @appliesMixin EtoolsPmpApp.Mixins.Common
     */
    class EtoolsSingleFile extends EtoolsPmpApp.Mixins.Common(Polymer.Element) {

      static get is() {
        return 'etools-single-file';
      }

      static get properties() {
        return {
          attachments: {
            type: Array,
            value: function() {
              return [];
            }
          },
          readonly: {
            type: Boolean,
            value: false
          },
          required: {
            type: Boolean,
            value: false,
            observer: '_requiredChanged'
          },
          autoValidate: Boolean,
          accept: String,
          label: String,
          file: {
            type: Object,
            notify: true,
            observer: '_fileChanged'
          },
          internalFile: {
            type: Object,
            observer: '_internalFileChanged'
          },
          elemAttached: {
            type: Boolean,
            value: false
          },
          invalid: {
            type: Boolean,
            value: false
          },
          errorMessage: {
            type: String,
            value: 'Please select a file'
          },
          hideDeleteBtn: {
            type: Boolean,
            reflectToAttribute: true
          }
        };
      }

      static get observers() {
        return [
          '_attachmentChanged(attachments.length)',
          '_fileReplaced(attachments.*)',
          '_refreshStyles(readonly, required)'
        ];
      }

      connectedCallback() {
        super.connectedCallback();
        this.elemAttached = true;
      }

      _internalFileChanged(intr) {
        if (typeof intr === 'undefined') {
          return;
        }
        if (this.internalFile) {
          this.set('attachments', this.prepareEtoolsFileDataFromUrl(this.internalFile));
        } else {
          this.set('attachments', []);
        }
      }

      _attachmentChanged(filesLength) {
        if (typeof filesLength === 'undefined') {
          return;
        }
        if (filesLength > 0) {
          if (this.attachments[0].raw instanceof File) {
            this.set('file', this.attachments[0].raw);
          } else if (typeof this.internalFile === 'string' && !!this.internalFile.length) {
            this.set('file', this.internalFile);
          } else {
            this.set('file', null);
          }
        } else {
          this.set('file', null);
        }
      }

      _fileReplaced(data) {
        if (typeof data === 'undefined') {
          return;
        }
        if ((data.path.indexOf('attachments.#') > -1)) {
          // file changed
          this._attachmentChanged(this.attachments.length);
        }
      }

      validate() {
        if (this.required && !this.readonly && this.file instanceof File === false &&
            (typeof this.file === 'string' ? !this.file.length : true)) {
          this.set('invalid', true);
          return false;
        }
        this.set('invalid', false);
        return true;
      }

      _fileChanged(file) {
        if (typeof file === 'undefined') {
          return;
        }
        if (file === null) {
          // reset previous value here as observer on internalFile is not triggered on one way binding
          this.set('attachments', []);
        }
        // elemAttached condition is to prevent eager validation
        if (this.autoValidate && this.elemAttached) {
          this.validate();
        }
      }

      _refreshStyles(readonly, required) {
        if (typeof readonly === 'undefined' && typeof required === 'undefined') {
          return;
        }
        this.updateStyles();
      }

      _requiredChanged(req) {
        if (typeof req === 'undefined') {
          return;
        }
        if (req === false) {
          this.validate();
        }
      }

      // covers the case when the users cancels file upload
      _fileInputFocused() {
        this._fileChanged(this.file);
      }
{'fraction_non_alphanumeric': 0.13792459873086974, 'fraction_numerical': 0.0022396416573348264, 'mean_word_length': 1.5317741554453106, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 39, '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': '7316261', 'n_tokens_mistral': 2909, 'n_tokens_neox': 2821, 'n_words': 571}