Source

components/location/LocationSidebar.vue

<template lang="pug">
SearchWrapper(
  @search-view-change="onSearchModuleViewChange"
)
  template(v-slot:search-module-form-bottom)
    .row.m-0.p-0.mt-2
      .col-md-12.m-0(style="display: flex;flex-direction: row;justify-content: flex-end;")
        LocationExportKMLButton(
          v-show="$store.getters['search_module/isCurrentTabVehicles'] && $store.getters['location_module/isRealtimeSearch']"
          @click="$store.dispatch('location_module/exportRealtimeKML')"
        )
        LocationExportKMLButton(
          v-show="!$store.getters['location_module/isRealtimeSearch'] && $store.getters['search_module/isCurrentTabAnyOf'](['driver','vehicle'])"
          @click="$store.dispatch('location_module/exportHistoryKML')"
        )
  template(v-slot:search-module-results)
    LocationResults
  template(v-slot:search-module-validate-button-form="slotProps")
    b-button(v-show="!slotProps.isViewResults" variant="primary" class="btn btn-block btn-primary mt-2" size="sm" @click="slotProps.clickSearch"
    style="min-width: fit-content;"
    )
      span(v-show="!$store.state.search_module.isSearchInProgress && !$store.getters['search_module/hasSelectedDates']") {{ $t("location.search_button.realtime") }}
      span(v-show="!$store.state.search_module.isSearchInProgress && $store.getters['search_module/hasSelectedDates']") {{ $t("location.search_button.history") }}
      span(v-show="$store.state.search_module.isSearchInProgress")
        b-spinner(class="loader" variant="info" style="width: 1rem; height: 1rem; margin: 0 auto; display: block")
</template>
<script>
import SearchWrapper from '@c/shared/SearchModule/SearchWrapper/SearchWrapper.vue'
import LocationResults from '@c/location/LocationResults/LocationResults.vue'
import LocationExportKMLButton from '@c/location/LocationExportKMLButton.vue'
import Vue from 'vue'
export default {
  components: {
    SearchWrapper,
    LocationResults,
    LocationExportKMLButton,
  },
  mixins: [Vue.$mixins.userRightsMixin],
  provide() {
    let self = this

    let blacklistedSearchModuleFormTabs = []
    ;[
      ['location_search_realtime_driver', 'driver'],
      ['location_search_realtime_circuit', 'circuit'],
      ['location_search_realtime_vehicle', 'vehicle'],
    ].forEach((arr) => {
      if (!self.hasFeatureRight(arr[0])) {
        blacklistedSearchModuleFormTabs.push(arr[1])
      }
    })

    return {
      /**
       * Some clients do not have right to history mode on certain tab (i.g circuit)
       */
      isSearchModuleDatePickerDisabledHandler: () => {
        return (
          ['vehicle', 'driver', 'circuit'].findIndex((type) => {
            return (
              this.$store.getters['search_module/activeSearchFormTabName'] ===
                type && !self.hasFeatureRight('location_search_history_' + type)
            )
          }) > -1
        )
      },
      /**
       * Some clients do not have right to perform a search realtime/history ib certain tab (i.g driver)
       */
      blacklistedSearchModuleFormTabs,
      /**
       * Some clients do not have right to history mode at all
       */
      isSearchModuleDatePickerEnabled() {
        return self.hasFeatureRight('location_history_mode')
      },
    }
  },
  methods: {
    onSearchModuleViewChange(viewName) {
      if (viewName === 'selection') {
        Vue.$locationModuleSearchManager.cancelAnySearchInProgress()

        this.$store.dispatch('app/changeLayout', {
          right_menu: false,
          right_menu_bottom: false,
        })
        setTimeout(() => {
          this.$store.dispatch('app/changeLayout', {
            sub_menu: false,
          })
        }, 500)
      }
    },
  },
}
</script>