frontend/src/main.js
/*
* Project Puerto Rico
* Copyright (C) 2018 Thomas Pötzsch, Stephan Stroh
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router';
import store from './store';
import './assets/css/fontawesome.min.css';
require('./assets/css/main.css');
Vue.config.productionTip = false;
// eslint-disable-next-line func-names
const filter = function (text, length, clamp) {
const compClamp = clamp || '...';
const node = document.createElement('div');
node.innerHTML = text;
const content = node.textContent;
return content.length > length ? content.slice(0, length) + compClamp : content;
};
Vue.filter('truncate', filter);
router.beforeEach((to, from, next) => {
const noAuthRequired = to.matched.some(route => route.meta.noAuth);
const authed = !!store.state.userdata;
if (!noAuthRequired && !authed) {
next('/login');
} else {
next();
}
});
router.beforeEach((to, from, next) => {
document.title = to.meta.title;
next();
});
/* eslint-disable no-new */
new Vue({
store,
el: '#app',
router,
components: { App },
template: '<App/>',
});