Explorar el Código

added option to dismiss important messages

CauseFX hace 5 años
padre
commit
cf8a247d0a
Se han modificado 5 ficheros con 96 adiciones y 26 borrados
  1. 21 0
      api/classes/organizr.class.php
  2. 3 4
      api/config/default.php
  3. 25 0
      api/v2/routes/news.php
  4. 46 21
      js/functions.js
  5. 1 1
      js/news.json

+ 21 - 0
api/classes/organizr.class.php

@@ -2447,6 +2447,27 @@ class Organizr
 		return ($this->updateConfig($newItem)) ? true : false;
 	}
 	
+	public function ignoreNewsId($id)
+	{
+		if (!$id) {
+			$this->setAPIResponse('error', 'News id was not supplied', 409);
+			return false;
+		}
+		$id = array(intval($id));
+		$newsIds = $this->config['ignoredNewsIds'];
+		$newsIds = array_merge($newsIds, $id);
+		$newsIds = array_unique($newsIds);
+		$this->updateConfig(['ignoredNewsIds' => $newsIds]);
+		$this->setAPIResponse('success', 'News id is now ignored', 200, null);
+	}
+	
+	public function getNewsIds()
+	{
+		$newsIds = $this->config['ignoredNewsIds'];
+		$this->setAPIResponse('success', null, 200, $newsIds);
+		return $newsIds;
+	}
+	
 	public function testWizardPath($array)
 	{
 		if ($this->hasDB()) {

+ 3 - 4
api/config/default.php

@@ -439,9 +439,7 @@ return array(
 	'netdata5Enabled' => false,
 	'netdata6Enabled' => false,
 	'netdata7Enabled' => false,
-	'netdataCustom' => '{
-
-	}',
+	'netdataCustom' => '{}',
 	'homepageOctoprintEnabled' => false,
 	'homepageOctoprintAuth' => '1',
 	'homepageOctoprintRefresh' => 10000,
@@ -457,5 +455,6 @@ return array(
 	'breezometerToken' => 'd95ab607392d4fa5bf64bb26a5cb2a06',
 	'customForgotPasswordText' => '',
 	'disableRecoverPassword' => false,
-	'expandCategoriesByDefault' => false
+	'expandCategoriesByDefault' => false,
+	'ignoredNewsIds' => array()
 );

+ 25 - 0
api/v2/routes/news.php

@@ -0,0 +1,25 @@
+<?php
+$app->get('/news', function ($request, $response, $args) {
+	$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
+	if ($Organizr->checkRoute($request)) {
+		if ($Organizr->qualifyRequest(1, true)) {
+			$Organizr->getNewsIds();
+		}
+	}
+	$response->getBody()->write(jsonE($GLOBALS['api']));
+	return $response
+		->withHeader('Content-Type', 'application/json')
+		->withStatus($GLOBALS['responseCode']);
+});
+$app->post('/news/{id}', function ($request, $response, $args) {
+	$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
+	if ($Organizr->checkRoute($request)) {
+		if ($Organizr->qualifyRequest(1, true)) {
+			$Organizr->ignoreNewsId($args['id']);
+		}
+	}
+	$response->getBody()->write(jsonE($GLOBALS['api']));
+	return $response
+		->withHeader('Content-Type', 'application/json')
+		->withStatus($GLOBALS['responseCode']);
+});

+ 46 - 21
js/functions.js

@@ -3456,6 +3456,19 @@ function updateCheck(){
 		OrganizrApiError(xhr);
 	});
 }
+function ignoreNewsId(id){
+	organizrAPI2('POST','api/v2/news/' + id,{}).success(function(data) {
+		try {
+			let response = data.response;
+			message('News Item','Id now ignored',activeInfo.settings.notifications.position,"#FFF","success","5000");
+			newsLoad();
+		}catch(e) {
+			organizrCatchError(e,data);
+		}
+	}).fail(function(xhr) {
+		OrganizrApiError(xhr, 'News');
+	});
+}
 function newsLoad(){
     newsJSON().success(function(data) {
         try {
@@ -3463,27 +3476,39 @@ function newsLoad(){
             var items = [];
             var limit = 5;
             var count = 0;
-            $.each(response, function(i,v) {
-                count++;
-                let alertDefined = (typeof v.important !== 'undefined' || v.important === false);
-                let alert = (alertDefined) ? '<span class="animated loop-animation flash text-danger">&nbsp; <i class="ti-alert"></i>&nbsp; Important Message</span>' : '';
-                let heartBeat = (alertDefined) ? '<div class="notify pull-left"><span class="heartbit"></span><span class="point"></span></div>' : '';
-                let newBody = `
-                <h5 class="pull-left">`+moment(v.date).format('LLL')+`</h5>
-                <h5 class="pull-right">`+v.author+`</h5>
-                <div class="clearfix"></div>
-                `+((v.subTitle) ? '<h5>' + v.subTitle + alert + '</h5>' : '' )+`
-                <p>`+v.body+`</p>
-                `;
-                if(count <= limit){
-                    items[i] = {
-                        title:v.title + heartBeat,
-                        body:newBody
-                    }
-                }
-            });
-            var body = buildAccordion(items, true);
-            $('#organizrNewsPanel').html(body);
+	        organizrAPI2('get','api/v2/news').success(function(data) {
+		        try {
+			        let ignoredIds = data.response.data;
+			        ignoredIds = ignoredIds == null ? [] : ignoredIds;
+			        $.each(response, function(i,v) {
+				        count++;
+				        let ignore = ignoredIds.includes(v.id);
+				        let alertDefined = (typeof v.important !== 'undefined' || v.important === false);
+				        let alert = (alertDefined && ignore == false) ? `<span class="animated loop-animation flash text-danger mouse" onclick="ignoreNewsId('${v.id}')">&nbsp; <i class="ti-alert"></i>&nbsp; Important Message - Click me to Ignore</span>` : '';
+				        let heartBeat = (alertDefined && ignore == false) ? '<div class="notify pull-left"><span class="heartbit"></span><span class="point"></span></div>' : '';
+				        let newBody = `
+			                <h5 class="pull-left">`+moment(v.date).format('LLL')+`</h5>
+			                <h5 class="pull-right">`+v.author+`</h5>
+			                <div class="clearfix"></div>
+			                `+((v.subTitle) ? '<h5>' + v.subTitle + alert + '</h5>' : '' )+`
+			                <p>`+v.body+`</p>
+			                `;
+				        if(count <= limit){
+					        items[i] = {
+						        title:v.title + heartBeat,
+						        body:newBody
+					        }
+				        }
+			        });
+			        var body = buildAccordion(items, true);
+			        $('#organizrNewsPanel').html(body);
+		        }catch(e) {
+			        organizrCatchError(e,data);
+		        }
+	        }).fail(function(xhr) {
+		        OrganizrApiError(xhr, 'News');
+	        });
+
         }catch(e) {
 	        organizrCatchError(e,data);
         }

+ 1 - 1
js/news.json

@@ -3,7 +3,7 @@
     "title": "Important Messages - Each message can now be ignored using ignore button",
     "subTitle": "I know they were annoying to some people",
     "date": "2021-01-24 15:30",
-    "body": "Just make sure to click (Important Message - CLick me to Ignore)",
+    "body": "Just make sure to click (Important Message - Click me to Ignore)",
     "author": "CauseFX",
     "important": true,
     "id": 11