Skip to content

Commit

Permalink
fix: correct data from axios, actual usage of plugins and fixed the s…
Browse files Browse the repository at this point in the history
…css issue

- the store is initialized in plugins/init.js like it was before, using the env object
- this env is set to empty if not retrieved
- import '../styles/settings.scss' is now valid, node 20 bug apparently, more info here :
  * vuejs/vitepress#3102
  * sass/dart-sass#2127
  * dart-lang/sdk#53784
- the data is set to data.data as soon as we get it from axios, removing further problems
  • Loading branch information
EDM115 committed Jan 24, 2024
1 parent a85bf3b commit 0062630
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
21
3 changes: 1 addition & 2 deletions src/assets/chart-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export default function prepareData(config, data) {
else return prepareAggData(config, data)
}

function prepareLinesData(config, olddata) {
const data = olddata.data
function prepareLinesData(config, data) {
if (config.chartType.type === 'pie' && config.dataType.valuesFields.length > 1) {
throw new Error('La visualisation camembert ne supporte pas d\'afficher plusieurs niveaux.')
}
Expand Down
9 changes: 7 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'
import vuetify from './plugins/vuetify'
import StorePlugin from './plugins/init'

const app = createApp(App)
let env = import.meta.env

app.use(createPinia())
if (env === undefined) {
env = {}
}

app.use(StorePlugin, { environement: env })
app.use(router)
app.use(vuetify)

Expand Down
20 changes: 16 additions & 4 deletions src/plugins/init.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { createPinia } from 'pinia'
import useMainStore from '@/stores/useMainStore'
import 'url-polyfill'

export function useInit(env, router) {
const store = useMainStore()
window.vIframeOptions = { router, reactiveParams: true }
store.init(env)
const StorePlugin = {
install(app, options) {
const pinia = createPinia()
app.use(pinia)

const store = useMainStore()
store.init(options.environement)

window.vIframeOptions = { router: app.config.globalProperties.$router, reactiveParams: true }
app.provide('mainStore', store)

app.config.globalProperties.$mainStore = store
}
}

export default StorePlugin
1 change: 0 additions & 1 deletion src/plugins/moment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// main.js or specific component file
import moment from 'moment'
import 'moment/locale/fr'

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vuetify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
import colors from 'vuetify/lib/util/colors'

// import '../styles/settings.scss'
import '../styles/settings.scss'

const vuetify = createVuetify({
components,
Expand Down
5 changes: 2 additions & 3 deletions src/stores/useMainStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ const useMainStore = defineStore('main', {
this.setAny({ env })

if (this.application) {
router.options.base = router.history.base = new URL(this.application.exposedUrl).pathname

const config = this.config
if (config && config.dynamicFilters) {
config.dynamicFilters.forEach(f => {
Expand Down Expand Up @@ -120,7 +118,8 @@ const useMainStore = defineStore('main', {
}

try {
const data = await axios.get(config.datasets[0].href + '/lines', { params })
let data = await axios.get(config.datasets[0].href + '/lines', { params })
data = data.data
this.setAny({ data })
} catch (err) {
this.setError((err.response && err.response.data) || err.message)
Expand Down
7 changes: 0 additions & 7 deletions vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ export default defineConfig({
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@import "@/styles/settings.scss";'
}
}
},
server: {
port: 3000,
hmr: {
Expand Down

0 comments on commit 0062630

Please sign in to comment.