Skip to content
Snippets Groups Projects
main.js 2.72 KiB
Newer Older
const axios = require('axios');
import Vue from 'vue';
Timothee P's avatar
Timothee P committed
import App from './App.vue';
import './registerServiceWorker';
import router from '@/router';
import store from '@/store';
import './assets/styles/base.css';
import './assets/resources/semantic-ui-2.4.2/semantic.min.css';
import '@fortawesome/fontawesome-free/css/all.css';
import '@fortawesome/fontawesome-free/js/all.js';
DESPRES Damien's avatar
DESPRES Damien committed
import 'ol/ol.css';
Florent Lavelle's avatar
Florent Lavelle committed
import '@/assets/styles/openlayers-custom.css';
import '@/assets/styles/sidebar-layers.css';
Florent's avatar
Florent committed
import { library } from '@fortawesome/fontawesome-svg-core';
import { fas } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
Florent's avatar
Florent committed
// Multiselect installation
import 'vue-multiselect/dist/vue-multiselect.min.css';
Florent's avatar
Florent committed

library.add(fas);
Florent's avatar
Florent committed

Timothee P's avatar
Timothee P committed
Vue.component(FontAwesomeIcon);
Florent's avatar
Florent committed

Vue.config.productionTip = false;
DESPRES Damien's avatar
DESPRES Damien committed
// gestion mise à jour du serviceWorker et du precache
var refreshing=false;
if(navigator.serviceWorker){
  navigator.serviceWorker.addEventListener('controllerchange', () => {
    // We'll also need to add 'refreshing' to our data originally set to false.
Florent Lavelle's avatar
Florent Lavelle committed
    if (refreshing) {
      return;
    }
    refreshing = true;
    // Here the actual reload of the page occurs
    window.location.reload();
  });
Florent Lavelle's avatar
Florent Lavelle committed
const onConfigLoaded = function(config){
  store.commit('SET_CONFIG', config);
  setInterval(() => { //* check if navigator is online
    store.commit('SET_IS_ONLINE', navigator.onLine);
  }, 2000);
DESPRES Damien's avatar
DESPRES Damien committed

  // set title and favico
Florent Lavelle's avatar
Florent Lavelle committed
  document.title = `${config.VUE_APP_APPLICATION_NAME} ${config.VUE_APP_APPLICATION_ABSTRACT}`;
Florent Lavelle's avatar
Florent Lavelle committed
  const link = document.createElement('link');
DESPRES Damien's avatar
DESPRES Damien committed
  link.id = 'dynamic-favicon';
  link.rel = 'shortcut icon';
  link.href = config.VUE_APP_APPLICATION_FAVICO;
  document.head.appendChild(link);

Timothee P's avatar
Timothee P committed
  window.proxy_url=config.VUE_APP_DJANGO_API_BASE+'proxy/';
Florent Lavelle's avatar
Florent Lavelle committed
  axios.all([
Timothee P's avatar
Timothee P committed
    store.dispatch('USER_INFO'),
    store.dispatch('projects/GET_PROJECTS'),
Timothee P's avatar
Timothee P committed
    store.dispatch('GET_STATIC_PAGES'),
    store.dispatch('GET_USER_LEVEL_PROJECTS'),
    store.dispatch('map/GET_AVAILABLE_LAYERS'),
    store.dispatch('GET_USER_LEVEL_PERMISSIONS'),
    store.dispatch('GET_LEVELS_PERMISSIONS'),
DESPRES Damien's avatar
DESPRES Damien committed
  ]).then(axios.spread(function () {
    new Vue({
      router,
      store,
      render: h => h(App)
    }).$mount('#app');
axios.get('./config/config.json')
DESPRES Damien's avatar
DESPRES Damien committed
  .catch((error)=>{
    console.error(error);
    console.log('try to get From Localstorage');
Florent Lavelle's avatar
Florent Lavelle committed
    const conf=localStorage.getItem('geontrib_conf');
    if (conf) {
      onConfigLoaded(JSON.parse(conf));
  .then((response) => {
    if (response && response.status === 200) {
      localStorage.setItem('geontrib_conf',JSON.stringify(response.data));
      onConfigLoaded(response.data);
DESPRES Damien's avatar
DESPRES Damien committed
    }
  })
  .catch((error) => {
    throw error;