<commit_before>import Vue from 'vue'

import colors from '@/lib/colors'

import assetStore from '@/store/modules/assets'
import shotStore from '@/store/modules/shots'

export const entityListMixin = {

  created () {
    this.initHiddenColumns(this.validationColumns, this.hiddenColumns)
  },

  mounted () {
    if (this.resizeHeaders) this.resizeHeaders()
    window.addEventListener('keydown', this.onKeyDown, false)
    window.addEventListener('keyup', this.onKeyUp, false)
  },

  beforeDestroy () {
    window.removeEventListener('keydown', this.onKeyDown)
    window.removeEventListener('keyup', this.onKeyUp)
  },

  data () {
    return {
      columnSelectorDisplayed: false
    }
  },

  computed: {
    visibleMetadataDescriptors () {
      return this.metadataDescriptors.filter(
        descriptor => {
          const header = this.metadataDisplayHeaders[descriptor.field_name]
          return header === undefined || header
        }
      )
    },

    nonStickedVisibleMetadataDescriptors () {
      return this.visibleMetadataDescriptors.filter(
        descriptor => !this.stickedColumns[descriptor.id] &&
        this.metadataDescriptorIsInDepartmentFilter(descriptor)
      )
    },

    stickedVisibleMetadataDescriptors () {
      return this.visibleMetadataDescriptors.filter(
        descriptor => this.stickedColumns[descriptor.id] &&
        this.metadataDescriptorIsInDepartmentFilter(descriptor)
      )
    },

    nonStickedDisplayedValidationColumns () {
      return this.displayedValidationColumns.filter(
        columnId => !this.stickedColumns[columnId] &&
        this.validationColumnsIsInDepartmentFilter(columnId)
      )
    },

    stickedDisplayedValidationColumns () {
      return this.displayedValidationColumns.filter(
        columnId => this.stickedColumns[columnId] &&
        this.validationColumnsIsInDepartmentFilter(columnId)
      )
    }
  },

  methods: {
    getBackground (color) {
      return colors.hexToRGBa(color, 0.08)
    },

    buildHideKey (columnId) {
      return `column-${this.currentProduction.id}-${columnId}`
    },

    initHiddenColumns (validationColumns, hiddenColumns) {
      if (validationColumns && hiddenColumns) {
        validationColumns.forEach((columnId) => {
          const key = this.buildHideKey(columnId)
          Vue.set(
            hiddenColumns,
            columnId,
            localStorage.getItem(key) === 'true'
          )
        })
      }
    },

    hideColumn (columnId) {
      const key = this.buildHideKey(columnId)
      let isColumnHidden = true
      if (localStorage.getItem(key) === 'true') {
        isColumnHidden = false
      }
      localStorage.setItem(key, isColumnHidden)
      Vue.set(this.hiddenColumns, columnId, isColumnHidden)
      this.hiddenColumns[columnId] = isColumnHidden
      return isColumnHidden
    },

    setScrollPosition (scrollPosition) {
      if (this.$refs.body) {
        this.$refs.body.scrollTop = scrollPosition
      }
    },

    setScrollLeftPosition (scrollPosition) {
      if (this.$refs.body) {
        this.$refs.body.scrollLeft = scrollPosition
      }
    },

    getValidationStyle (columnId) {
      const taskType = this.taskTypeMap.get(columnId)
      return {
        'border-left': `1px solid ${taskType.color}`,
        background: this.getBackground(taskType.color)
      }
    },

    onTaskSelected (validationInfo, sticked) {
      const columnOffset = this.stickedDisplayedValidationColumns.length
      const selection = []
      if (!sticked) {
        validationInfo = { ...validationInfo }
        validationInfo.y += columnOffset
      }
      if (validationInfo.isShiftKey) {
        if (this.lastSelection) {
          let startX = this.lastSelection.x
          let endX = validationInfo.x
          let startY = this.lastSelection.y
          if (!sticked) startY += columnOffset
          let endY = validationInfo.y
          let grid = this.assetSelectionGrid
          if (!grid) grid = this.shotSelectionGrid

          if (validationInfo.x < this.lastSelection.x) {
            startX = validationInfo.x
            endX = this.lastSelection.x
          }
          if (validationInfo.y < this.lastSelection.y) {
            startY = validationInfo.y
            endY = this.lastSelection.y
            if (!sticked) endY += columnOffset
          }

          for (let i = startX; i <= endX; i++) {
            for (let j = startY; j <= endY; j++) {
              const ref = 'validation-' + i + '-' + j
              const validationCell = this.$refs[ref][0]
              if (!grid[i][j]) {
                let y = validationCell.columnY
                if (!sticked) y += columnOffset

                // Check if cell is selectable based on asset types list from entity's task type
                const isSelectable = validationCell.entity.task_types.includes(validationCell.column.task_type_id)

                // Add cell to selection
                if (isSelectable) {
                  selection.push({
                    entity: validationCell.entity,
                    column: validationCell.column,
                    task: validationCell.task,
                    x: validationCell.rowX,
                    y
                  })
                }
              }
            }
          }
          this.$store.commit('ADD_SELECTED_TASK', validationInfo)
        }
      } else if (!validationInfo.isCtrlKey) {
        this.$store.commit('CLEAR_SELECTED_TASKS')
      }
      if (selection.length === 0) {
        this.$nextTick(() => {
          this.$store.commit('ADD_SELECTED_TASK', validationInfo)
        })
      } else {
        this.$store.commit('ADD_SELECTED_TASKS', selection)
      }

      if (!validationInfo.isShiftKey && validationInfo.isUserClick) {<commit_msg>[qa] fix selection<commit_after>import Vue from 'vue'

import colors from '@/lib/colors'

import assetStore from '@/store/modules/assets'
import shotStore from '@/store/modules/shots'

export const entityListMixin = {

  created () {
    this.initHiddenColumns(this.validationColumns, this.hiddenColumns)
  },

  mounted () {
    if (this.resizeHeaders) this.resizeHeaders()
    window.addEventListener('keydown', this.onKeyDown, false)
    window.addEventListener('keyup', this.onKeyUp, false)
  },

  beforeDestroy () {
    window.removeEventListener('keydown', this.onKeyDown)
    window.removeEventListener('keyup', this.onKeyUp)
  },

  data () {
    return {
      columnSelectorDisplayed: false
    }
  },

  computed: {
    visibleMetadataDescriptors () {
      return this.metadataDescriptors.filter(
        descriptor => {
          const header = this.metadataDisplayHeaders[descriptor.field_name]
          return header === undefined || header
        }
      )
    },

    nonStickedVisibleMetadataDescriptors () {
      return this.visibleMetadataDescriptors.filter(
        descriptor => !this.stickedColumns[descriptor.id] &&
        this.metadataDescriptorIsInDepartmentFilter(descriptor)
      )
    },

    stickedVisibleMetadataDescriptors () {
      return this.visibleMetadataDescriptors.filter(
        descriptor => this.stickedColumns[descriptor.id] &&
        this.metadataDescriptorIsInDepartmentFilter(descriptor)
      )
    },

    nonStickedDisplayedValidationColumns () {
      return this.displayedValidationColumns.filter(
        columnId => !this.stickedColumns[columnId] &&
        this.validationColumnsIsInDepartmentFilter(columnId)
      )
    },

    stickedDisplayedValidationColumns () {
      return this.displayedValidationColumns.filter(
        columnId => this.stickedColumns[columnId] &&
        this.validationColumnsIsInDepartmentFilter(columnId)
      )
    }
  },

  methods: {
    getBackground (color) {
      return colors.hexToRGBa(color, 0.08)
    },

    buildHideKey (columnId) {
      return `column-${this.currentProduction.id}-${columnId}`
    },

    initHiddenColumns (validationColumns, hiddenColumns) {
      if (validationColumns && hiddenColumns) {
        validationColumns.forEach((columnId) => {
          const key = this.buildHideKey(columnId)
          Vue.set(
            hiddenColumns,
            columnId,
            localStorage.getItem(key) === 'true'
          )
        })
      }
    },

    hideColumn (columnId) {
      const key = this.buildHideKey(columnId)
      let isColumnHidden = true
      if (localStorage.getItem(key) === 'true') {
        isColumnHidden = false
      }
      localStorage.setItem(key, isColumnHidden)
      Vue.set(this.hiddenColumns, columnId, isColumnHidden)
      this.hiddenColumns[columnId] = isColumnHidden
      return isColumnHidden
    },

    setScrollPosition (scrollPosition) {
      if (this.$refs.body) {
        this.$refs.body.scrollTop = scrollPosition
      }
    },

    setScrollLeftPosition (scrollPosition) {
      if (this.$refs.body) {
        this.$refs.body.scrollLeft = scrollPosition
      }
    },

    getValidationStyle (columnId) {
      const taskType = this.taskTypeMap.get(columnId)
      return {
        'border-left': `1px solid ${taskType.color}`,
        background: this.getBackground(taskType.color)
      }
    },

    onTaskSelected (validationInfo, sticked) {
      const columnOffset = this.stickedDisplayedValidationColumns.length
      const selection = []
      if (!sticked) {
        validationInfo = { ...validationInfo }
        validationInfo.y += columnOffset
      }
      if (validationInfo.isShiftKey) {
        if (this.lastSelection) {
          let startX = this.lastSelection.x
          let endX = validationInfo.x
          let startY = this.lastSelection.y
          if (!sticked) startY += columnOffset
          let endY = validationInfo.y
          let grid = this.assetSelectionGrid
          if (!grid) grid = this.shotSelectionGrid

          if (validationInfo.x < this.lastSelection.x) {
            startX = validationInfo.x
            endX = this.lastSelection.x
          }
          if (validationInfo.y < this.lastSelection.y) {
            startY = validationInfo.y
            endY = this.lastSelection.y
            if (!sticked) endY += columnOffset
          }

          for (let i = startX; i <= endX; i++) {
            for (let j = startY; j <= endY; j++) {
              const ref = 'validation-' + i + '-' + j
              const validationCell = this.$refs[ref][0]
              if (!grid[i][j]) {
                let y = validationCell.columnY
                if (!sticked) y += columnOffset

                // Add cell to selection
                if (validationCell.selectable) {
                  selection.push({
                    entity: validationCell.entity,
                    column: validationCell.column,
                    task: validationCell.task,
                    x: validationCell.rowX,
                    y
                  })
                }
              }
            }
          }
          this.$store.commit('ADD_SELECTED_TASK', validationInfo)
        }
      } else if (!validationInfo.isCtrlKey) {
        this.$store.commit('CLEAR_SELECTED_TASKS')
      }
      if (selection.length === 0) {
        this.$nextTick(() => {
          this.$store.commit('ADD_SELECTED_TASK', validationInfo)
        })
      } else {
        this.$store.commit('ADD_SELECTED_TASKS', selection)
      }

      if (!validationInfo.isShiftKey && validationInfo.isUserClick) {
{'fraction_non_alphanumeric': 0.10492148434073165, 'fraction_numerical': 0.0010527239231511536, 'mean_word_length': 2.160521208760743, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '3382115', 'n_tokens_mistral': 3153, 'n_tokens_neox': 3073, 'n_words': 563}