Skip to content
Snippets Groups Projects
main.js 2.64 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 'leaflet/dist/leaflet.css';
import 'leaflet-draw/dist/leaflet.draw.css';
import '@/assets/resources/leaflet-control-geocoder-1.13.0/Control.Geocoder.css';
import '@fortawesome/fontawesome-free/css/all.css';
import '@fortawesome/fontawesome-free/js/all.js';
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.
    if (refreshing) return;
    refreshing = true;
    // Here the actual reload of the page occurs
    window.location.reload();
  });
DESPRES Damien's avatar
DESPRES Damien committed


let onConfigLoaded = function(config){
  store.commit('SET_CONFIG', config);
  setInterval(() => { //* check if navigator is online
    store.commit('SET_IS_ONLINE', navigator.onLine);
  }, 1000);
DESPRES Damien's avatar
DESPRES Damien committed

  // set title and favico
  document.title= config.VUE_APP_APPLICATION_NAME+' '+config.VUE_APP_APPLICATION_ABSTRACT;
  let link = document.createElement('link');
  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');
    let conf=localStorage.getItem('geontrib_conf');
DESPRES Damien's avatar
DESPRES Damien committed
    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;