Просмотр исходного кода

Improve notification timestamp format (#4237)

Alec Rust 2 лет назад
Родитель
Сommit
3ec4d12e35

+ 1 - 1
bin/v-list-user-notifications

@@ -4,7 +4,7 @@
 #
 #
 # example: v-list-user-notifications admin
 # example: v-list-user-notifications admin
 #
 #
-# This function for getting the list notifications
+# This function for getting the notifications list
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                Variables & Functions                     #
 #                Variables & Functions                     #

+ 1 - 1
docs/docs/user-guide/notifications.md

@@ -2,4 +2,4 @@
 
 
 To view your notifications, click the <i class="fas fa-lg fa-fw fa-bell"><span class="visually-hidden">notification</span></i> icon in the top right.
 To view your notifications, click the <i class="fas fa-lg fa-fw fa-bell"><span class="visually-hidden">notification</span></i> icon in the top right.
 
 
-You can dismiss a notification by clicking the small red circle on its right.
+You can delete a notification by clicking the small red "X" on the top right.

+ 14 - 2
web/list/notifications/index.php

@@ -2,16 +2,28 @@
 // Main include
 // Main include
 include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
 include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
 
 
+function formatNotificationTimestamps(&$note) {
+	$dateTime = DateTime::createFromFormat("Y-m-d H:i:s", $note["DATE"] . " " . $note["TIME"]);
+	$note["TIMESTAMP_TEXT"] = $dateTime->format("d M Y, H:i");
+	$note["TIMESTAMP_ISO"] = $dateTime->format(DateTime::ATOM); // ISO 8601 format
+	$note["TIMESTAMP_TITLE"] = $dateTime->format("d F Y, H:i:s");
+}
+
 if ($_REQUEST["ajax"] == 1 && $_REQUEST["token"] == $_SESSION["token"]) {
 if ($_REQUEST["ajax"] == 1 && $_REQUEST["token"] == $_SESSION["token"]) {
 	// Data
 	// Data
 	exec(HESTIA_CMD . "v-list-user-notifications $user json", $output, $return_var);
 	exec(HESTIA_CMD . "v-list-user-notifications $user json", $output, $return_var);
 	$data = json_decode(implode("", $output), true);
 	$data = json_decode(implode("", $output), true);
 
 
-	function sort_priorty_id($element1, $element2) {
+	foreach ($data as $key => &$note) {
+		formatNotificationTimestamps($note);
+	}
+	unset($note);
+
+	function sort_priority_id($element1, $element2) {
 		return $element2["PRIORITY"] <=> $element1["PRIORITY"];
 		return $element2["PRIORITY"] <=> $element1["PRIORITY"];
 	}
 	}
 	$data = array_reverse($data, true);
 	$data = array_reverse($data, true);
-	usort($data, sort_priorty_id(...));
+	usort($data, "sort_priority_id");
 
 
 	foreach ($data as $key => $note) {
 	foreach ($data as $key => $note) {
 		$note["ID"] = $key;
 		$note["ID"] = $key;

+ 3 - 2
web/templates/includes/panel.php

@@ -114,8 +114,9 @@
 											<div class="top-bar-notification-content" x-html="notification.NOTICE"></div>
 											<div class="top-bar-notification-content" x-html="notification.NOTICE"></div>
 											<p class="top-bar-notification-timestamp">
 											<p class="top-bar-notification-timestamp">
 												<time
 												<time
-													:datetime="`${notification.DATE}T${notification.TIME}`"
-													x-text="`${notification.TIME} ${notification.DATE}`"
+													:datetime="`${notification.TIMESTAMP_ISO}`"
+													x-bind:title="`${notification.TIMESTAMP_TITLE}`"
+													x-text="`${notification.TIMESTAMP_TEXT}`"
 												></time>
 												></time>
 											</p>
 											</p>
 										</li>
 										</li>

+ 4 - 5
web/templates/pages/add_cron.php

@@ -25,11 +25,10 @@
 			<div class="u-side-by-side-tablet u-mb20">
 			<div class="u-side-by-side-tablet u-mb20">
 				<h1><?= _("Add Cron Job") ?></h1>
 				<h1><?= _("Add Cron Job") ?></h1>
 				<p>
 				<p>
-					<?= _('System time') ?>: <span class="u-text-bold">
-						<time datetime="<?= date("c", $current_timestamp) ?>">
-							<?= date("d M Y, H:i", $current_timestamp) ?>
-						</time>
-					</span>
+					<?= _('System time') ?>:
+					<time datetime="<?= date("c", $current_timestamp) ?>" class="u-text-bold">
+						<?= date("d M Y, H:i", $current_timestamp) ?>
+					</time>
 				</p>
 				</p>
 			</div>
 			</div>
 			<?php show_alert_message($_SESSION); ?>
 			<?php show_alert_message($_SESSION); ?>

+ 4 - 5
web/templates/pages/edit_cron.php

@@ -25,11 +25,10 @@
 			<div class="u-side-by-side-tablet u-mb20">
 			<div class="u-side-by-side-tablet u-mb20">
 				<h1><?= _("Edit Cron Job") ?></h1>
 				<h1><?= _("Edit Cron Job") ?></h1>
 				<p>
 				<p>
-					<?= _('System time') ?>: <span class="u-text-bold">
-						<time datetime="<?= date("c", $current_timestamp) ?>">
-							<?= date("d M Y, H:i", $current_timestamp) ?>
-						</time>
-					</span>
+					<?= _('System time') ?>:
+					<time datetime="<?= date("c", $current_timestamp) ?>" class="u-text-bold">
+						<?= date("d M Y, H:i", $current_timestamp) ?>
+					</time>
 				</p>
 				</p>
 			</div>
 			</div>
 			<?php show_alert_message($_SESSION); ?>
 			<?php show_alert_message($_SESSION); ?>