<commit_before><template>
  <div class="pure-u-1 pure-u-lg-4-4">
    <aside
      v-if="checkFilters"
      class="gobierto-data-filters"
    >
      <div
        v-for="filter in filtersModify"
        :key="filter.title"
        :class="!filter.isToggle ? 'gobierto-data-filters-element-no-margin' : ''"
        class="gobierto-data-filters-element"
      >
        <Dropdown @is-content-visible="filter.isToggle = !filter.isToggle">
          <template v-slot:trigger>
            <!-- FIXME: remove inline styles in the next filters refactor -->
            <div
              class="gobierto-block-header"
              style="flex: 1;"
            >
              <strong class="gobierto-block-header--title">
                <Caret :rotate="filter.isToggle" />
                {{ filter.title }}</strong>
              <a
                class="gobierto-block-header--link"
                @click.stop="e => selectAllCheckbox_TEMP({ ...e, filter })"
              >{{
                filter.isEverythingChecked ? labelNone : labelAll
              }}</a>
            </div>
          </template>
          <div>
            <Checkbox
              v-for="{ id, title, isOptionChecked, counter } in filteredOptions(filter)"
              :id="id"
              :key="id"
              :title="title"
              :checked="isOptionChecked"
              :counter="counter"
              @checkbox-change="e => sendCheckboxStatus_TEMP({ ...e, filter })"
            />
          </div>
        </Dropdown>
      </div>
    </aside>
  </div>
</template>
<script>
import { Checkbox, Dropdown } from "lib/vue-components";
import Caret from "./../commons/Caret.vue";
export default {
  name: "SidebarCategories",
  components: {
    Dropdown,
    Caret,
    Checkbox
  },
  props: {
    activeTab: {
      type: Number,
      default: 0
    },
    filters: {
      type: Array,
      default: () => []
    },
    items: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      labelSets: I18n.t("gobierto_data.projects.sets") || '',
      labelQueries: I18n.t("gobierto_data.projects.queries") || '',
      labelCategories: I18n.t("gobierto_data.projects.categories") || '',
      labelAll: I18n.t("gobierto_common.vue_components.block_header.all") || '',
      labelNone: I18n.t("gobierto_common.vue_components.block_header.none") || ''
    }
  },
  computed: {
    checkFilters() {
      if (!this.filters.length) return false
      return ((this.filters[0] && (this.filters[0] || {}).count >= 1)
        || (this.filters[1] && (this.filters[1] || {}).count >= 1));
    },
    filtersModify() {
      return this.filters.length ? this.filters.map(d => ({ ...d, isToggle: true })) : []
    }
  },
  created() {
    if (this.$route.params.pathMatch !== undefined) {
      let paramsRouter = this.$route.params.pathMatch.split(':')
      this.selectedCheckbox(paramsRouter)
    }
  },
  methods: {
    //TODO temporary functions, waiting for the filter refactor
    sendCheckboxStatus_TEMP({ id, value, filter }) {
      this.$root.$emit("sendCheckbox_TEMP", { id, value, filter })
      if (!this.$route.params.pathMatch) {
        // eslint-disable-next-line no-unused-vars
        this.$router.push('/datos/').catch(err => {})
      }
      const { key } = filter
      if (key === 'category') {
        this.updateURLwithCategoriesSelected(filter)
      }
    },
    selectAllCheckbox_TEMP({ filter }) {
      this.$root.$emit("selectAll_TEMP", { filter })

      const { key } = filter
      if (key === 'category') {
        this.updateURLwithCategoriesSelected(filter)
      }
    },
    filteredOptions(filter) {
      return filter.options.filter(({ counter: element = 0 }) => element > 0 );
    },
    updateURLwithCategoriesSelected(values) {
      const { options: optionsChecked } = values
      const isItemSelected = optionsChecked.filter(({ isOptionChecked }) => isOptionChecked === true)
      const getIdFromItems = [...new Set(isItemSelected.map(({ id }) => id))]
      let routeItems = []
      for (let index = 0; index < getIdFromItems.length; index++) {
        let item = `${getIdFromItems[index]}:`
        routeItems.push(item)
      }
      routeItems = routeItems.toString().replace(/,/gi, '');
       history.pushState(
         {},
         null,
         `${this.$route.path}terms/${routeItems}`
       )
    },
    selectedCheckbox(values) {
      const categoriesSelected = values.filter(item => item).map(item => +item);
      let categories = this.filters.filter(({ key }) => key === 'category')
      categories = categories[0]
      categories.options.forEach((d) => {
        if (categoriesSelected.includes(d.id)) {
          d.isOptionChecked = true
        }
      })
      this.$root.$emit("selectChecboxPermalink_TEMP", categories)
    }
  }
};
</script><commit_msg>if all categories are unchecked, redirect to the origin<commit_after><template>
  <div class="pure-u-1 pure-u-lg-4-4">
    <aside
      v-if="checkFilters"
      class="gobierto-data-filters"
    >
      <div
        v-for="filter in filtersModify"
        :key="filter.title"
        :class="!filter.isToggle ? 'gobierto-data-filters-element-no-margin' : ''"
        class="gobierto-data-filters-element"
      >
        <Dropdown @is-content-visible="filter.isToggle = !filter.isToggle">
          <template v-slot:trigger>
            <!-- FIXME: remove inline styles in the next filters refactor -->
            <div
              class="gobierto-block-header"
              style="flex: 1;"
            >
              <strong class="gobierto-block-header--title">
                <Caret :rotate="filter.isToggle" />
                {{ filter.title }}</strong>
              <a
                class="gobierto-block-header--link"
                @click.stop="e => selectAllCheckbox_TEMP({ ...e, filter })"
              >{{
                filter.isEverythingChecked ? labelNone : labelAll
              }}</a>
            </div>
          </template>
          <div>
            <Checkbox
              v-for="{ id, title, isOptionChecked, counter } in filteredOptions(filter)"
              :id="id"
              :key="id"
              :title="title"
              :checked="isOptionChecked"
              :counter="counter"
              @checkbox-change="e => sendCheckboxStatus_TEMP({ ...e, filter })"
            />
          </div>
        </Dropdown>
      </div>
    </aside>
  </div>
</template>
<script>
import { Checkbox, Dropdown } from "lib/vue-components";
import Caret from "./../commons/Caret.vue";
export default {
  name: "SidebarCategories",
  components: {
    Dropdown,
    Caret,
    Checkbox
  },
  props: {
    activeTab: {
      type: Number,
      default: 0
    },
    filters: {
      type: Array,
      default: () => []
    },
    items: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      labelSets: I18n.t("gobierto_data.projects.sets") || '',
      labelQueries: I18n.t("gobierto_data.projects.queries") || '',
      labelCategories: I18n.t("gobierto_data.projects.categories") || '',
      labelAll: I18n.t("gobierto_common.vue_components.block_header.all") || '',
      labelNone: I18n.t("gobierto_common.vue_components.block_header.none") || '',
      isPermalinkActive: false
    }
  },
  computed: {
    checkFilters() {
      if (!this.filters.length) return false
      return ((this.filters[0] && (this.filters[0] || {}).count >= 1)
        || (this.filters[1] && (this.filters[1] || {}).count >= 1));
    },
    filtersModify() {
      return this.filters.length ? this.filters.map(d => ({ ...d, isToggle: true })) : []
    }
  },
  created() {
    if (this.$route.params.pathMatch !== undefined) {
      let paramsRouter = this.$route.params.pathMatch.split(':')
      this.isPermalinkActive = true
      this.selectedCheckbox(paramsRouter)
    }
  },
  methods: {
    //TODO temporary functions, waiting for the filter refactor
    sendCheckboxStatus_TEMP({ id, value, filter }) {
      this.$root.$emit("sendCheckbox_TEMP", { id, value, filter })

      // eslint-disable-next-line no-unused-vars
      this.$router.push('/datos/').catch(err => {})

      this.updateURLwithCategoriesSelected(filter)
      this.checkSelectedCheckbox(filter)
    },
    selectAllCheckbox_TEMP({ filter }) {
      this.$root.$emit("selectAll_TEMP", { filter })

      const { key } = filter
      if (key === 'category') {
        this.updateURLwithCategoriesSelected(filter)
      }
    },
    filteredOptions(filter) {
      return filter.options.filter(({ counter: element = 0 }) => element > 0 );
    },
    updateURLwithCategoriesSelected(values) {
      const { options: optionsChecked } = values
      const isItemSelected = optionsChecked.filter(({ isOptionChecked }) => isOptionChecked === true)
      const getIdFromItems = [...new Set(isItemSelected.map(({ id }) => id))]
      let routeItems = []
      for (let index = 0; index < getIdFromItems.length; index++) {
        let item = `${getIdFromItems[index]}:`
        routeItems.push(item)
      }
      let urlTerms = this.isPermalinkActive ? `${location.origin}/datos/terms/` : `${this.$route.path}terms/`
      routeItems = routeItems.toString().replace(/,/gi, '');
      urlTerms = routeItems.length === 0 ? `${this.$route.path}` : urlTerms
      history.pushState(
        {},
        null,
        `${urlTerms}${routeItems}`
      )
    },
    selectedCheckbox(values) {
      const categoriesSelected = values.filter(item => item).map(item => +item);
      let categories = this.filters.filter(({ key }) => key === 'category')
      categories = categories[0]
      categories.options.forEach((d) => {
        if (categoriesSelected.includes(d.id)) {
          d.isOptionChecked = true
        }
      })
      this.$root.$emit("selectChecboxPermalink_TEMP", categories)
    },
    checkSelectedCheckbox(values) {
      const isItemSelected = values.options.filter(({ isOptionChecked }) => isOptionChecked)
      if (isItemSelected.length === 0) {
        // eslint-disable-next-line no-unused-vars
        this.$router.push('/datos/').catch(err => {})
      }
    }
  }
};
</script>
{'fraction_non_alphanumeric': 0.15971265498917536, 'fraction_numerical': 0.005117102932493603, 'mean_word_length': 2.1999370277078087, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 87, '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': '3023058', 'n_tokens_mistral': 3101, 'n_tokens_neox': 3078, 'n_words': 534}