List.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <h1 id="news-anchor" class="title mt-12 mb-12">
  3. Toutes les news
  4. </h1>
  5. <div v-if="pending">
  6. <v-row class="justify-center progress">
  7. <v-progress-circular
  8. indeterminate
  9. color="grey"
  10. />
  11. </v-row>
  12. </div>
  13. <div>
  14. <v-row
  15. v-for="(newsItem, index) in newsItems"
  16. :key="index"
  17. class="news d-flex align-center mr-10"
  18. >
  19. <v-card class="alt-theme">
  20. <v-card-item>
  21. <v-container fluid>
  22. <v-row align="center">
  23. <v-col cols="3">
  24. <v-img
  25. v-if="newsItem.attachment"
  26. :src="getImageUrl(newsItem.attachment)"
  27. alt="poster"
  28. height="200"
  29. width="400"
  30. />
  31. </v-col>
  32. <v-col cols="9">
  33. <div class="details">
  34. <NuxtLink
  35. :to="`/actualites/${newsItem.id}`"
  36. class="text-decoration-none"
  37. >
  38. <v-card-title>
  39. {{ newsItem.title }}
  40. <v-icon
  41. v-if="newsItem.featured"
  42. size="16"
  43. icon="star fas fa-star"
  44. />
  45. </v-card-title>
  46. </NuxtLink>
  47. <v-card-text>
  48. <div class="flex-container">
  49. <div class="text-container">
  50. <table>
  51. <tr>
  52. <td>
  53. {{ newsItem.leadText }}
  54. </td>
  55. </tr>
  56. </table>
  57. </div>
  58. <div class="button-container">
  59. <v-card-actions class="justify-end">
  60. <v-btn
  61. :to="`/actualites/${newsItem.id}`"
  62. prepend-icon="fas fa-info"
  63. class="btn mr-2 mb-1"
  64. >
  65. En savoir plus
  66. </v-btn>
  67. </v-card-actions>
  68. </div>
  69. </div>
  70. </v-card-text>
  71. </div>
  72. </v-col>
  73. </v-row>
  74. </v-container>
  75. </v-card-item>
  76. </v-card>
  77. </v-row>
  78. <v-row>
  79. <v-col cols="12">
  80. <v-pagination
  81. v-if="lastPage"
  82. :model-value="page"
  83. :length="lastPage"
  84. rounded="circle"
  85. max="10"
  86. class="mt-4"
  87. @update:model-value="pageUpdated"
  88. />
  89. </v-col>
  90. </v-row>
  91. </div>
  92. </template>
  93. <script setup lang="ts">
  94. import { ComputedRef } from "vue";
  95. import { useEntityFetch } from "~/composables/data/useEntityFetch";
  96. import News from "~/models/Maestro/News";
  97. const i18n = useI18n();
  98. const config = useRuntimeConfig();
  99. const { fetchCollection } = useEntityFetch()
  100. const getImageUrl = (attachment: string) =>
  101. `${config.public.apiBaseUrl}/uploads/news/${attachment}`;
  102. const page: Ref<number> = ref(1);
  103. const updatePage = (newPage: number) => {
  104. console.log("updatePage", newPage);
  105. page.value = newPage;
  106. };
  107. const query: ComputedRef<Record<string, string | number>> = computed(() => {
  108. return {
  109. page: page.value,
  110. type: "ENTREPRISE",
  111. };
  112. });
  113. const { data: newsCollection, pending, refresh } = fetchCollection(News, null, query)
  114. const filterNews = (items: News[]): News[] => {
  115. const results = []
  116. const currentDate = new Date();
  117. for (const item of items) {
  118. if (
  119. item.startPublication &&
  120. currentDate < new Date(item.startPublication)
  121. ) {
  122. continue
  123. }
  124. if (
  125. item.endPublication &&
  126. currentDate > new Date(item.endPublication)
  127. ) {
  128. continue
  129. }
  130. if (item.type === "ENTREPRISE") {
  131. results.push(item)
  132. }
  133. }
  134. return results
  135. }
  136. const sortNews = (items: News[]): News[] => {
  137. return items.sort((a, b) => {
  138. if (a.featured !== b.featured) {
  139. return a.featured ? -1 : 1; // placer les objets "featured" en premier
  140. } else {
  141. //@ts-ignore
  142. return b.id - a.id;
  143. }
  144. })
  145. }
  146. // TODO: voir pourquoi on se retrouve obligé de passer par ce computed pour avoir le type TS correct?
  147. const newsItems: ComputedRef<News[]> = computed(() => {
  148. if (newsCollection.value === null) {
  149. return [];
  150. }
  151. const items = newsCollection.value.items as News[]
  152. // TODO: ça va pas, faut faire le tri et le filtre côté api (sinon ça trie et filtre que la page en cours...)
  153. return sortNews(filterNews(items))
  154. })
  155. const lastPage: ComputedRef<number | null> = computed(() => {
  156. return newsCollection.value !== null && newsCollection.value.pagination ?
  157. newsCollection.value.pagination.last ?? null :
  158. null
  159. })
  160. const pageUpdated = async (newVal: number): Promise<void> => {
  161. // TODO: factoriser, puisque on retrouve la même logique dans le component JoinUsMissions
  162. page.value = newVal
  163. pending.value = true
  164. await refresh()
  165. setTimeout(
  166. async () => await navigateTo({ path: '', hash: '#news-anchor' }),
  167. 200
  168. )
  169. }
  170. </script>
  171. <style scoped lang="scss">
  172. .v-container {
  173. padding: 0 !important;
  174. }
  175. h1 {
  176. color: #d1cdc7; /* TODO: pqoi cette couleur ici? */
  177. margin-left: 3rem;
  178. margin-top: 2rem;
  179. font-family: Barlow, serif;
  180. font-size: 4rem;
  181. font-style: normal;
  182. font-weight: 600;
  183. line-height: 42px;
  184. }
  185. .news {
  186. .v-card {
  187. border-radius: 10px;
  188. min-width: 100%;
  189. margin-bottom: 1rem;
  190. margin-left: 2rem;
  191. margin-right: 2rem;
  192. padding-top: 0.2rem;
  193. padding-bottom: 0.2rem;
  194. height: 60%;
  195. .v-card-text {
  196. letter-spacing: 0 !important;
  197. padding: 0 !important;
  198. }
  199. .v-card-item {
  200. padding: 0 !important;
  201. }
  202. }
  203. .v-img {
  204. width: 80%;
  205. margin-left: auto;
  206. margin-right: auto;
  207. }
  208. .details {
  209. border: 1px solid white !important;
  210. padding: 9px;
  211. border-radius: 20px;
  212. width: 99%;
  213. .v-card-title {
  214. color: #fff;
  215. font-family: Barlow, serif;
  216. font-size: 36px;
  217. font-style: normal;
  218. font-weight: 600;
  219. line-height: 39px;
  220. }
  221. .star {
  222. color: yellow !important;
  223. }
  224. .v-card-text {
  225. td {
  226. color: #fff;
  227. font-family: Barlow, serif;
  228. font-size: 22px;
  229. font-style: normal;
  230. font-weight: 500;
  231. line-height: 26px;
  232. margin-left: 1rem;
  233. }
  234. }
  235. .v-btn {
  236. background: var(--secondary-color);
  237. color: var(--on-secondary-color);
  238. display: flex;
  239. left: 0;
  240. padding: 25px 28px;
  241. align-items: center;
  242. gap: 9px;
  243. font-family: Barlow, serif;
  244. font-size: 0.9rem;
  245. border-radius: 5px;
  246. font-style: normal;
  247. font-weight: 700;
  248. line-height: 15px;
  249. letter-spacing: 1.3px;
  250. text-transform: uppercase;
  251. margin-bottom: -1rem;
  252. }
  253. }
  254. }
  255. </style>