Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/7707 #687

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
7707
Rename and move constants
  • Loading branch information
xguiboud committed Nov 25, 2024
commit 17d0a769cf34981c2864775fdeb9dc66e13f8852
22 changes: 10 additions & 12 deletions pages/preferences.php
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
use Combodo\iTop\Application\WebPage\ErrorPage;
use Combodo\iTop\Application\WebPage\iTopWebPage;
use Combodo\iTop\Application\WebPage\WebPage;
use Combodo\iTop\Controller\Newsroom\iTopNewsroomController;
use Combodo\iTop\Controller\Notifications\NotificationsCenterController;
use Combodo\iTop\Service\InterfaceDiscovery\InterfaceDiscovery;
use Combodo\iTop\Service\Router\Router;
@@ -33,9 +34,6 @@
require_once(APPROOT.'/application/startup.inc.php');
IssueLog::Trace('----- Request: '.utils::GetRequestUri(), LogChannels::WEB_REQUEST);

const MAX_NEWSROOM_DISPLAY_SIZE = 20;
const MIN_NEWSROOM_DISPLAY_SIZE = 1;
const DEFAULT_NEWSROOM_DISPLAY_SIZE = 7;

/**
* Displays the user's changeable preferences
@@ -273,10 +271,10 @@ function ValidateOtherSettings()

$sNewsroomHtml = '';
$sNewsroomHtml .= '<form method="post">';
$iNewsroomDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', DEFAULT_NEWSROOM_DISPLAY_SIZE);
$iNewsroomDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', iTopNewsroomController::DEFAULT_NEWSROOM_DISPLAY_SIZE);

if ($iNewsroomDisplaySize < MIN_NEWSROOM_DISPLAY_SIZE) $iNewsroomDisplaySize = MIN_NEWSROOM_DISPLAY_SIZE;
if ($iNewsroomDisplaySize > MAX_NEWSROOM_DISPLAY_SIZE) $iNewsroomDisplaySize = MAX_NEWSROOM_DISPLAY_SIZE;
if ($iNewsroomDisplaySize < iTopNewsroomController::DEFAULT_NEWSROOM_MIN_DISPLAY_SIZE) $iNewsroomDisplaySize = iTopNewsroomController::DEFAULT_NEWSROOM_MIN_DISPLAY_SIZE;
if ($iNewsroomDisplaySize > iTopNewsroomController::DEFAULT_NEWSROOM_MAX_DISPLAY_SIZE) $iNewsroomDisplaySize = iTopNewsroomController::DEFAULT_NEWSROOM_MAX_DISPLAY_SIZE;
$sInput = '<input min="1" max="20" id="newsroom_display_size" type="number" size="2" name="newsroom_display_size" value="'.$iNewsroomDisplaySize.'">';
$sIcon = '<i id="newsroom_menu_icon" class="top-right-icon icon-additional-arrow fas fa-bell" style="top: 0;"></i>';
$sNewsroomHtml .= Dict::Format('UI:Newsroom:DisplayAtMost_X_Messages', $sInput, $sIcon);
@@ -870,14 +868,14 @@ function GetToastsPositionFieldBlock(): iUIBlock
}
$bNewsroomEnabled = (MetaModel::GetConfig()->Get('newsroom_enabled') !== false);
if ($bNewsroomEnabled && ($iCountProviders > 0)) {
$iNewsroomDisplaySize = (int)utils::ReadParam('newsroom_display_size', DEFAULT_NEWSROOM_DISPLAY_SIZE);
if ($iNewsroomDisplaySize < MIN_NEWSROOM_DISPLAY_SIZE) {
$iNewsroomDisplaySize = MIN_NEWSROOM_DISPLAY_SIZE;
$iNewsroomDisplaySize = (int)utils::ReadParam('newsroom_display_size', iTopNewsroomController::DEFAULT_NEWSROOM_DISPLAY_SIZE);
if ($iNewsroomDisplaySize < iTopNewsroomController::DEFAULT_NEWSROOM_MIN_DISPLAY_SIZE) {
$iNewsroomDisplaySize = iTopNewsroomController::DEFAULT_NEWSROOM_MIN_DISPLAY_SIZE;
}
if ($iNewsroomDisplaySize > MAX_NEWSROOM_DISPLAY_SIZE) {
$iNewsroomDisplaySize = MAX_NEWSROOM_DISPLAY_SIZE;
if ($iNewsroomDisplaySize > iTopNewsroomController::DEFAULT_NEWSROOM_MAX_DISPLAY_SIZE) {
$iNewsroomDisplaySize = iTopNewsroomController::DEFAULT_NEWSROOM_MAX_DISPLAY_SIZE;
}
$iCurrentDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', DEFAULT_NEWSROOM_DISPLAY_SIZE);
$iCurrentDisplaySize = (int)appUserPreferences::GetPref('newsroom_display_size', iTopNewsroomController::DEFAULT_NEWSROOM_DISPLAY_SIZE);
if ($iCurrentDisplaySize != $iNewsroomDisplaySize) {
// Save the preference only if it differs from the current (or default) value
appUserPreferences::SetPref('newsroom_display_size', $iNewsroomDisplaySize);
4 changes: 4 additions & 0 deletions sources/Controller/Newsroom/iTopNewsroomController.php
Original file line number Diff line number Diff line change
@@ -48,6 +48,10 @@
class iTopNewsroomController extends Controller
{
public const ROUTE_NAMESPACE = 'itopnewsroom';
public const DEFAULT_NEWSROOM_DISPLAY_SIZE = 7;
public const DEFAULT_NEWSROOM_MIN_DISPLAY_SIZE = 1;
public const DEFAULT_NEWSROOM_MAX_DISPLAY_SIZE = 20;


/**
* @return iTopWebPage