From 4640db5affac95cf93908f53b5e0f11ef3ee5d05 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Wed, 26 Jun 2024 14:17:44 +0200 Subject: [PATCH] adds a view components for the news if the content that gets loaded has the template_kurzbz news --- application/controllers/CisVue/Cms.php | 1 + .../controllers/api/frontend/v1/Cms.php | 11 +++--- public/js/components/Cis/Cms/Content.js | 9 +++-- .../components/Cis/Cms/Content_types/News.js | 38 +++++++++++++++++++ public/js/components/DashboardWidget/News.js | 24 ++++++++---- 5 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 public/js/components/Cis/Cms/Content_types/News.js diff --git a/application/controllers/CisVue/Cms.php b/application/controllers/CisVue/Cms.php index cf9519e28..d41dfc3db 100755 --- a/application/controllers/CisVue/Cms.php +++ b/application/controllers/CisVue/Cms.php @@ -51,6 +51,7 @@ class Cms extends FHC_Controller $this->terminateWithError(getError($content)); $content = getData($content); + if(NULL === $content) $this->terminateWithError("Content not found"); diff --git a/application/controllers/api/frontend/v1/Cms.php b/application/controllers/api/frontend/v1/Cms.php index f6c1ba7bf..50ce50805 100644 --- a/application/controllers/api/frontend/v1/Cms.php +++ b/application/controllers/api/frontend/v1/Cms.php @@ -48,9 +48,10 @@ class Cms extends FHCAPI_Controller private function fetchContent($content_id){ $content = $this->cmslib->getContent($content_id); - - if (isError($content)) - $this->terminateWithError(getError($content), self::ERROR_TYPE_GENERAL); + + if (isError($content)){ + $this->terminateWithError(getError($content), self::ERROR_TYPE_GENERAL); + } if(getData($content)){ return getData($content); @@ -79,7 +80,7 @@ class Cms extends FHCAPI_Controller $content = $this->fetchContent($content_id); - $this->terminateWithSuccess(getData($content)); + $this->terminateWithSuccess($content); } /** @@ -130,7 +131,7 @@ class Cms extends FHCAPI_Controller // collect the content of the news foreach($news as $news_element){ - $this->addMeta("asdfs",$news_element->content_id); + $this->addMeta("content_id",$news_element->content_id); $news_element->content_obj = $this->fetchContent($news_element->content_id); } diff --git a/public/js/components/Cis/Cms/Content.js b/public/js/components/Cis/Cms/Content.js index efd1de7e8..f724d13c7 100644 --- a/public/js/components/Cis/Cms/Content.js +++ b/public/js/components/Cis/Cms/Content.js @@ -1,4 +1,5 @@ import raum_contentmittitel from './Content_types/Raum_contentmittitel.js' +import news from './Content_types/News.js' export default { @@ -32,15 +33,17 @@ export default { }; }, created() { - console.log("this is the api", this.$fhcApi); this.$fhcApi.factory.cms.content(this.content_id,this.version, this.sprache, this.sichtbar).then(res =>{ this.content = res.data.content; - this.content_type = res.data.type; + this.content_type=res.data.content; }); + }, + mounted(){ + }, template: /*html*/ ` - +

No content is available to display

`, diff --git a/public/js/components/Cis/Cms/Content_types/News.js b/public/js/components/Cis/Cms/Content_types/News.js new file mode 100644 index 000000000..f29936dc1 --- /dev/null +++ b/public/js/components/Cis/Cms/Content_types/News.js @@ -0,0 +1,38 @@ + +export default { + props:{ + content:{ + type:String, + required:true, + }, + }, + mounted(){ + document.querySelectorAll("#cms [data-confirm]").forEach((el) => { + el.addEventListener("click", (evt) => { + evt.preventDefault(); + BsConfirm.popup(el.dataset.confirm) + .then(() => { + Axios.get(el.href) + .then((res) => { + // TODO(chris): check for success then show message and/or reload + location = location; + }) + .catch((err) => console.error("ERROR:", err)); + }) + .catch(() => {}); + }); + }); + document.querySelectorAll("#cms [data-href]").forEach((el) => { + el.href = el.dataset.href.replace( + /^ROOT\//, + FHC_JS_DATA_STORAGE_OBJECT.app_root + ); + }); + }, + template: /*html*/ ` + +
+

Content was not found

+ `, + }; + \ No newline at end of file diff --git a/public/js/components/DashboardWidget/News.js b/public/js/components/DashboardWidget/News.js index 01affc4f4..351dcb146 100755 --- a/public/js/components/DashboardWidget/News.js +++ b/public/js/components/DashboardWidget/News.js @@ -13,6 +13,9 @@ export default { AbstractWidget ], computed: { + + + newsList(){ //Return news amount depending on widget width and size let quantity = this.width; @@ -28,14 +31,18 @@ export default { } }, created(){ - console.log(MAX_LOADED_NEWS,"this are the max news"); - this.$fhcApi.factory.cms.news(MAX_LOADED_NEWS) - .then(res => { this.allNewsList = res.data }) - .catch(err => { console.error('ERROR: ', err.response.data) }); - + this.$fhcApi.factory.cms.news(MAX_LOADED_NEWS) + .then(res => { this.allNewsList = res.data }) + .catch(err => { console.error('ERROR: ', err.response.data) }); + + this.$emit('setConfig', false); }, methods: { + + contentURI: function(content_id){ + return FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/CisVue/Cms/content/' + content_id; + }, setSingleNews(singleNews){ this.singleNews = singleNews; this.$refs.newsModal.show(); @@ -53,7 +60,7 @@ export default { - - + +