mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-05 15:29:50 +00:00
make frontend news widget
This commit is contained in:
parent
efdc84930b
commit
6c93c8b8fa
@ -19,17 +19,17 @@ class DashboardApiController
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function indexApi()
|
||||||
|
{
|
||||||
|
return $this->getDashboardConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
// I dont understand why this method is needed, but if I do a cache clear without this method present, he gives an error saying it needs to be present.
|
||||||
public function setCrudConfig()
|
public function setCrudConfig()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Give the user dashboard configuration
|
|
||||||
*
|
|
||||||
* @Route("/api/1.0/main/dashboard-config-item.json", methods={"post"})
|
|
||||||
*/
|
|
||||||
public function getDashboardConfiguration(): JsonResponse
|
public function getDashboardConfiguration(): JsonResponse
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
|
@ -97,6 +97,8 @@ import MyNotifications from './MyNotifications';
|
|||||||
import MyWorkflows from './MyWorkflows.vue';
|
import MyWorkflows from './MyWorkflows.vue';
|
||||||
import TabCounter from './TabCounter';
|
import TabCounter from './TabCounter';
|
||||||
import { mapState } from "vuex";
|
import { mapState } from "vuex";
|
||||||
|
import { makeFetch } from "ChillMainAssets/lib/api/apiMethods";
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "App",
|
name: "App",
|
||||||
@ -112,7 +114,7 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
activeTab: 'MyCustoms'
|
activeTab: 'MyCustoms',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -131,7 +133,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$store.dispatch('getDashboardItems', {userId: 1})
|
|
||||||
for (const m of [
|
for (const m of [
|
||||||
'MyNotifications',
|
'MyNotifications',
|
||||||
'MyAccompanyingCourses',
|
'MyAccompanyingCourses',
|
||||||
|
@ -0,0 +1,106 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<h1>{{ $t('widget.news.title') }}</h1>
|
||||||
|
<ul class="scrollable">
|
||||||
|
<li v-for="item in newsItems" :key="item.id">
|
||||||
|
<h2>{{ item.title }}</h2>
|
||||||
|
<div class="content" v-if="shouldTruncate(item.content)">
|
||||||
|
{{ truncateContent(item.content) }}
|
||||||
|
<span class="read-more" @click="() => openModal(item)">Read more</span>
|
||||||
|
</div>
|
||||||
|
<div class="content" v-else>
|
||||||
|
{{ item.content }}
|
||||||
|
</div>
|
||||||
|
<modal v-if="showModal" @close="closeModal">
|
||||||
|
<template #header>{{ item.title }}</template>
|
||||||
|
<template #body>{{ item.content }}</template>
|
||||||
|
</modal>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
import {makeFetch} from "ChillMainAssets/lib/api/apiMethods";
|
||||||
|
import Modal from '../../_components/Modal.vue'; // Adjust the import path
|
||||||
|
|
||||||
|
|
||||||
|
const newsItems = ref([])
|
||||||
|
const selectedArticle = ref(null);
|
||||||
|
const showModal = ref(false);
|
||||||
|
|
||||||
|
const openModal = (item) => {
|
||||||
|
selectedArticle.value = item;
|
||||||
|
showModal.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeModal = () => {
|
||||||
|
selectedArticle.value = null;
|
||||||
|
showModal.value = false;
|
||||||
|
};;
|
||||||
|
|
||||||
|
const shouldTruncate = (content, maxLength = 100) => {
|
||||||
|
return content.length > maxLength;
|
||||||
|
};
|
||||||
|
|
||||||
|
const truncateContent = (content, maxLength = 100) => {
|
||||||
|
if (shouldTruncate(content, maxLength)) {
|
||||||
|
return content.slice(0, maxLength) + '...';
|
||||||
|
} else {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
makeFetch('GET', '/api/1.0/main/news.json')
|
||||||
|
.then((response) => {
|
||||||
|
newsItems.value = response.results
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Error fetching news items', error);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
ul {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
max-height: 100px; /* Adjust the max height as needed */
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scrollable {
|
||||||
|
overflow-y: auto;
|
||||||
|
max-height: 150px; /* Same as .content max-height */
|
||||||
|
margin-bottom: 10px; /* To give space for the scrollbar */
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: #3498db;
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.read-more {
|
||||||
|
color: #3498db; /* Adjust the color as needed */
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
</style>
|
@ -39,18 +39,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mbloc col col-lg-6 col-lg-4" v-if="this.dashboardItems">
|
||||||
<div class="mbloc col col-sm-6 col-lg-4">
|
<div v-for="dashboardItem in this.dashboardItems">
|
||||||
<div class="custom2">
|
<News v-if="dashboardItem.type ==='news'"/>
|
||||||
News
|
</div>
|
||||||
<MyWidget :chart-data="chartData" />
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="mbloc col col-sm-6 col-lg-4">
|
|
||||||
<div class="custom3">
|
|
||||||
Mon dashboard personnalisé
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -58,14 +51,20 @@
|
|||||||
<script>
|
<script>
|
||||||
import { mapGetters } from "vuex";
|
import { mapGetters } from "vuex";
|
||||||
import Masonry from 'masonry-layout/masonry';
|
import Masonry from 'masonry-layout/masonry';
|
||||||
|
import {makeFetch} from "ChillMainAssets/lib/api/apiMethods";
|
||||||
|
import News from './DashboardWidgets/News.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MyCustoms",
|
name: "MyCustoms",
|
||||||
|
components: {
|
||||||
|
News
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
counterClass: {
|
counterClass: {
|
||||||
counter: true //hack to pass class 'counter' in i18n-t
|
counter: true //hack to pass class 'counter' in i18n-t
|
||||||
},
|
},
|
||||||
|
dashboardItems: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -77,6 +76,15 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
const elem = document.querySelector('#dashboards');
|
const elem = document.querySelector('#dashboards');
|
||||||
const masonry = new Masonry(elem, {});
|
const masonry = new Masonry(elem, {});
|
||||||
|
//Fetch the dashboard items configured for user. Currently response is still hardcoded and no user id passed.
|
||||||
|
makeFetch('GET', '/api/1.0/main/dashboard-config-item.json')
|
||||||
|
.then((response) => {
|
||||||
|
this.dashboardItems = response;
|
||||||
|
console.log('dashboarditems', this.dashboardItems)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
throw error
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -24,7 +24,6 @@ const store = createStore({
|
|||||||
workflows: {},
|
workflows: {},
|
||||||
workflowsCc: {},
|
workflowsCc: {},
|
||||||
errorMsg: [],
|
errorMsg: [],
|
||||||
dashboardItems: {},
|
|
||||||
loading: false
|
loading: false
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
@ -98,24 +97,8 @@ const store = createStore({
|
|||||||
catchError(state, error) {
|
catchError(state, error) {
|
||||||
state.errorMsg.push(error);
|
state.errorMsg.push(error);
|
||||||
},
|
},
|
||||||
addDashboardItems(state, dashboardItems) {
|
|
||||||
state.dashboardItems = dashboardItems;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
getDashboardItems({commit, getters}, { userId }) {
|
|
||||||
const url = `/api/1.0/main/dashboard-item/${userId}.json`;
|
|
||||||
makeFetch('GET', url)
|
|
||||||
.then((response) => {
|
|
||||||
console.log('dashboardItems', response.results)
|
|
||||||
commit('addDashboardItems', response);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
commit('catchError', error);
|
|
||||||
throw error;
|
|
||||||
})
|
|
||||||
;
|
|
||||||
},
|
|
||||||
getByTab({ commit, getters }, { tab, param }) {
|
getByTab({ commit, getters }, { tab, param }) {
|
||||||
switch (tab) {
|
switch (tab) {
|
||||||
// case 'MyWorks':
|
// case 'MyWorks':
|
||||||
|
@ -51,7 +51,12 @@ const messages = {
|
|||||||
years_old: "1 an | {n} an | {n} ans",
|
years_old: "1 an | {n} an | {n} ans",
|
||||||
residential_address: "Adresse de résidence",
|
residential_address: "Adresse de résidence",
|
||||||
located_at: "réside chez"
|
located_at: "réside chez"
|
||||||
}
|
},
|
||||||
|
widget: {
|
||||||
|
news: {
|
||||||
|
title: "Actualités"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user