<commit_before>/*global XMLHttpRequest, Blob*/
Polymer({
  is: 'bde-design-view',
  properties: {
    blobRegistry: {
      type: Object,
      notify: true
    },
    currentComponentMetadata: {
      type: Object,
      notify: true
    },
    lastGeneratedTemplateBlobDocTime: {
      type: Object
    },
    lastChangeTime: {
      type: Object
    },
    selectedCompound: {
      type: Object,
      value: null
    },
    compatibleTemplate: {
      type: Boolean,
      value: false
    },
    isVisible: {
      type: Boolean,
      value: false
    },
    disabled: {
      type: Boolean,
      value: false
    },
    lastEndpointId: {
      type: String
    }
  },
  listeners: {
    'iron-overlay-closed': 'confirmDialogCloseHandler',
    'no-compatible-template': 'noCompatibleTemplateHandler',
    'compatible-template': 'compatibleTemplateHandler',
    'new-compound-can-load': 'newCompoundCanLoadHandler'
  },
  observers: [
    'currentComponentMetadataChanged(currentComponentMetadata.*)'
  ],

  ready: function () {
    this.parentNode.addEventListener('iron-deselect', this.leaveHandler);
    this.parentNode.addEventListener('iron-select', this.openHandler);
  },

  compatibleTemplateHandler: function () {
    this.set('compatibleTemplate', true);
    this.set('disabled', false);
  },

  noCompatibleTemplateHandler: function () {
    this.set('compatibleTemplate', false);
    this.set('disabled', true);
    if (this.isVisible) {
      this.$.confirmEnablingDialog.open();
    }
  },

  currentComponentMetadataChanged: function () {
    if (!this.currentComponentMetadata || !this.currentComponentMetadata.manifest || !this.currentComponentMetadata.artifactId || !this.currentComponentMetadata.endpointId) {
      return;
    }
    if (this.isVisible && !this.disabled &&
      (!this.lastGeneratedTemplateBlobDocTime || this.lastGeneratedTemplateBlobDocTime < this.lastChangeTime)) {
      this.$.confirmKeepingDialog.open();
    } else {
      this.fire('new-compound-can-load');
    }
  },

  newCompoundCanLoadHandler: function () {
    var compoundComponents = this.currentComponentMetadata.manifest.artifacts.compoundComponents;
    compoundComponents.forEach(function (item) {
      if (item.artifactId === this.currentComponentMetadata.artifactId) {
        this.lastGeneratedTemplateBlobDocTime = new Date(0);
        this.selectedCompound = item;
        this.lastEndpointId = this.currentComponentMetadata.endpointId;
        this.loadHtmlResources();
      }
    }.bind(this));
  },

  openHandler: function (e) {
    var designView = e.detail.item;
    if (designView.id !== 'designView') {
      return;<commit_msg>[BDE-265] Enable design by by default when changing component<commit_after>/*global XMLHttpRequest, Blob*/
Polymer({
  is: 'bde-design-view',
  properties: {
    blobRegistry: {
      type: Object,
      notify: true
    },
    currentComponentMetadata: {
      type: Object,
      notify: true
    },
    lastGeneratedTemplateBlobDocTime: {
      type: Object
    },
    lastChangeTime: {
      type: Object
    },
    selectedCompound: {
      type: Object,
      value: null
    },
    compatibleTemplate: {
      type: Boolean,
      value: false
    },
    isVisible: {
      type: Boolean,
      value: false
    },
    disabled: {
      type: Boolean,
      value: false
    },
    lastEndpointId: {
      type: String
    }
  },
  listeners: {
    'iron-overlay-closed': 'confirmDialogCloseHandler',
    'no-compatible-template': 'noCompatibleTemplateHandler',
    'compatible-template': 'compatibleTemplateHandler',
    'new-compound-can-load': 'newCompoundCanLoadHandler'
  },
  observers: [
    'currentComponentMetadataChanged(currentComponentMetadata.*)'
  ],

  ready: function () {
    this.parentNode.addEventListener('iron-deselect', this.leaveHandler);
    this.parentNode.addEventListener('iron-select', this.openHandler);
  },

  compatibleTemplateHandler: function () {
    this.set('compatibleTemplate', true);
    this.set('disabled', false);
  },

  noCompatibleTemplateHandler: function () {
    this.set('compatibleTemplate', false);
    this.set('disabled', true);
    if (this.isVisible) {
      this.$.confirmEnablingDialog.open();
    }
  },

  currentComponentMetadataChanged: function () {
    if (!this.currentComponentMetadata || !this.currentComponentMetadata.manifest || !this.currentComponentMetadata.artifactId || !this.currentComponentMetadata.endpointId) {
      return;
    }
    if (this.isVisible && !this.disabled &&
      (!this.lastGeneratedTemplateBlobDocTime || this.lastGeneratedTemplateBlobDocTime < this.lastChangeTime)) {
      this.$.confirmKeepingDialog.open();
    } else {
      this.fire('new-compound-can-load');
    }
  },

  newCompoundCanLoadHandler: function () {
    this.disabled = false;
    var compoundComponents = this.currentComponentMetadata.manifest.artifacts.compoundComponents;
    compoundComponents.forEach(function (item) {
      if (item.artifactId === this.currentComponentMetadata.artifactId) {
        this.lastGeneratedTemplateBlobDocTime = new Date(0);
        this.selectedCompound = item;
        this.lastEndpointId = this.currentComponentMetadata.endpointId;
        this.loadHtmlResources();
      }
    }.bind(this));
  },

  openHandler: function (e) {
    var designView = e.detail.item;
    if (designView.id !== 'designView') {
      return;
{'fraction_non_alphanumeric': 0.1246521981079577, 'fraction_numerical': 0.0009274717121127806, 'mean_word_length': 3.2125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6439348', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1517, 'n_words': 257}