From 39ffd6bdb97b46b626986136900a621326350997 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 6 Dec 2024 09:59:58 +0100 Subject: [PATCH] fix(news Widget api): readds the removed api call from the news widget because it differs from the getNews api call that is used in the News View --- .../controllers/api/frontend/v1/Cms.php | 1 - public/js/api/cms.js | 11 +++++++ public/js/components/DashboardWidget/News.js | 31 ++++++++++--------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/application/controllers/api/frontend/v1/Cms.php b/application/controllers/api/frontend/v1/Cms.php index f0d009534..50628bd4f 100644 --- a/application/controllers/api/frontend/v1/Cms.php +++ b/application/controllers/api/frontend/v1/Cms.php @@ -106,7 +106,6 @@ class Cms extends FHCAPI_Controller $this->terminateWithSuccess($content_id); } - //todo: there is the method news and getNews but only one should exist public function news() { diff --git a/public/js/api/cms.js b/public/js/api/cms.js index b80bb5cde..94ce24862 100644 --- a/public/js/api/cms.js +++ b/public/js/api/cms.js @@ -11,6 +11,7 @@ export default { ); }, + //api function used for the news View that renders the html getNews(page = 1, page_size = 10) { return this.$fhcApi.get( "/api/frontend/v1/Cms/getNews", @@ -21,6 +22,16 @@ export default { ); }, + //api function used for the widget component + news(limit) { + return this.$fhcApi.get( + "/api/frontend/v1/Cms/news", + { + limit: limit + } + ); + }, + getNewsRowCount: function () { return this.$fhcApi.get( "/api/frontend/v1/Cms/getNewsRowCount", diff --git a/public/js/components/DashboardWidget/News.js b/public/js/components/DashboardWidget/News.js index f774f0934..dcc721cd5 100644 --- a/public/js/components/DashboardWidget/News.js +++ b/public/js/components/DashboardWidget/News.js @@ -40,21 +40,6 @@ export default { return this.allNewsList.find(news => news.minimized === false) ?? this.allNewsList[0] ?? null } }, - created() { - this.$fhcApi.factory.cms - .news(MAX_LOADED_NEWS) - .then((res) => { - this.allNewsList = Array.from(Object.values(res.data)); - - this.selected = this.allNewsList.length ? this.allNewsList[0] : null - - }) - .catch((err) => { - console.error("ERROR: ", err.response.data); - }); - - this.$emit("setConfig", false); - }, methods: { setNext(){ const thisIndex = this.allNewsList.findIndex(n=>n.news_id == this.selected.news_id) @@ -133,6 +118,22 @@ export default { this.$refs.newsModal.show(); }, }, + created() { + this.$fhcApi.factory.cms + .news(MAX_LOADED_NEWS) + .then(res => res.data) + .then((news) => { + this.allNewsList = Array.from(Object.values(news)); + + this.selected = this.allNewsList.length ? this.allNewsList[0] : null + + }) + .catch((err) => { + console.error("ERROR: ", err.response.data); + }); + + this.$emit("setConfig", false); + }, template: /*html*/ `