diff --git a/frontend/src/__apps/painel/main.js b/frontend/src/__apps/painel/main.js index fdf4e5dbd..6c7d53b5d 100644 --- a/frontend/src/__apps/painel/main.js +++ b/frontend/src/__apps/painel/main.js @@ -1 +1,54 @@ import './scss/painel.scss' +import Vue from 'vue' +import axios from 'axios' + +axios.defaults.xsrfCookieName = 'csrftoken' +axios.defaults.xsrfHeaderName = 'X-CSRFToken' + +const v = new Vue({ // eslint-disable-line + delimiters: ['[[', ']]'], + el: '#app-painel', + data () { + return { + message: 'Hello VueJUS', // TODO: remove when porting to VueJS is done + polling: null, + painel_aberto: false, + sessao_plenaria: '', + sessao_plenaria_data: '', + sessao_plenaria_hora_inicio: '', + brasao: '', + sessao_solene: false, + sessao_solene_tema: '' + } + }, + methods: { + fetchData () { + // TODO: how to get no hardcoded URL? + $.get('/painel/704/dados', function (response) { + this.brasao = response.brasao + this.painel_aberto = response.status_painel + this.sessao_plenaria = response.sessao_plenaria + this.sessao_plenaria_data = 'Data Início: ' + response.sessao_plenaria_data + this.sessao_plenaria_hora_inicio = 'Hora Início: ' + response.sessao_plenaria_hora_inicio + this.sessao_solene = response.sessao_solene + this.sessao_solene_tema = response.sessao_solene_tema + }.bind(this)) + }, + pollData () { + this.fetchData() + + this.polling = setInterval(() => { + console.info('Fetching data from backend') + this.fetchData() + }, 5000) + } + }, + beforeDestroy () { + console.info('Destroying polling.') + clearInterval(this.polling) + }, + created () { + console.info('Start polling data...') + this.pollData() + } +}) diff --git a/sapl/templates/painel/index.html b/sapl/templates/painel/index.html index 1cb2e2c83..ad30a11f3 100644 --- a/sapl/templates/painel/index.html +++ b/sapl/templates/painel/index.html @@ -35,28 +35,29 @@
+