Skip to content

Commit

Permalink
Merge pull request #32 from WisdmLabs/dev
Browse files Browse the repository at this point in the history
Dev to master for v2.1.0
  • Loading branch information
wisdmyogeshshirsath authored Apr 11, 2022
2 parents 40eb944 + c0f588b commit 86dd62a
Show file tree
Hide file tree
Showing 27 changed files with 152 additions and 85 deletions.
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Change Log:
===========

Version 2.1.0
=============
Tweak - Improved Recommended plugins UI.
Tweak - If cron is not running frequently then show a warning on the Last 24 hours usage tab.
Tweak - Improved plugin performance.
Tweak - Logging system usage when live data is being fetched.
Fix - Validating context in services to avoid fatal errors.
Fix - Issue with Contact Us form.

Version 2.0.0
=============
Feature - Brand new live usage tab design.
Expand Down
1 change: 1 addition & 0 deletions amd/build/main.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions block_edwiser_site_monitor.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

defined('MOODLE_INTERNAL') || die();

use block_edwiser_site_monitor_usage as esmusage;
use block_edwiser_site_monitor\usage;
use block_edwiser_site_monitor\utility;

/**
* Edwiser Site Monitor Block
Expand Down Expand Up @@ -65,8 +66,7 @@ public function specialization() {
* @return string The block HTML.
*/
public function get_content() {
global $PAGE;
$usage = esmusage::get_instance();
$usage = usage::get_instance();
if ($this->content !== null) {
return $this->content;
}
Expand All @@ -75,19 +75,21 @@ public function get_content() {
return null;
}

utility::edwiser_site_monitor_log_usage();

$renderer = $this->page->get_renderer('block_edwiser_site_monitor');

$refreshrate = isset($this) && isset($this->config) && isset($this->config->refreshrate) ? $this->config->refreshrate : 5;

$stringmanager = get_string_manager();
$strings = $stringmanager->load_component_strings('block_edwiser_site_monitor', 'en');
$PAGE->requires->strings_for_js(array_keys($strings), 'block_edwiser_site_monitor');
$this->page->requires->strings_for_js(array_keys($strings), 'block_edwiser_site_monitor');

$PAGE->requires->data_for_js('refreshrate', $refreshrate);
$PAGE->requires->data_for_js('totalmemory', $usage->get_total_memory());
$PAGE->requires->data_for_js('totalstorage', $usage->get_total_storage());
$this->page->requires->data_for_js('refreshrate', $refreshrate);
$this->page->requires->data_for_js('totalmemory', $usage->get_total_memory());
$this->page->requires->data_for_js('totalstorage', $usage->get_total_storage());

$PAGE->requires->js_call_amd('block_edwiser_site_monitor/main', 'init');
$this->page->requires->js_call_amd('block_edwiser_site_monitor/main', 'init');

$this->content = new stdClass();
$this->content->footer = '';
Expand Down
31 changes: 22 additions & 9 deletions classes/externallib.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,28 @@
* @author Yogesh Shirsath
*/

namespace block_edwiser_site_monitor;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/blocks/edwiser_site_monitor/classes/utility.php');

use block_edwiser_site_monitor_usage as esmusage;
use block_edwiser_site_monitor_plugins as esmplugins;
use block_edwiser_site_monitor_utility as esmutility;
use external_function_parameters;
use external_single_structure;
use external_value;
use context_system;
use external_api;
use moodle_url;
use stdClass;

/**
* This class implements services for block_edwiser_site_monitor
*
* @copyright 2019 WisdmLabs <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_edwiser_site_monitor_externallib extends external_api {
class externallib extends external_api {

/**
* Describes the parameters for get blocks function
Expand All @@ -54,7 +61,9 @@ public static function get_live_status_parameters() {
* @return array
*/
public static function get_live_status() {
$usage = esmusage::get_instance();
self::validate_context(context_system::instance());
utility::edwiser_site_monitor_log_usage();
$usage = usage::get_instance();
return array(
"cpu" => $usage->get_cpu_usage(),
"memory" => $usage->get_memory_usage(),
Expand Down Expand Up @@ -99,6 +108,9 @@ public static function get_last_24_hours_usage_parameters() {
*/
public static function get_last_24_hours_usage($timestamp) {
global $DB;
self::validate_context(context_system::instance());
utility::edwiser_site_monitor_log_usage();

if ($timestamp == 0) {
$timestamp = strtotime(date('d-m-Y', time()));
}
Expand Down Expand Up @@ -155,8 +167,8 @@ public static function get_plugins_update_parameters() {
*/
public static function get_plugins_update() {
global $PAGE;
$PAGE->set_context(context_system::instance());
$plugins = new esmplugins();
self::validate_context(context_system::instance());
$plugins = new plugins();
$time = time();
return array(
'lasttimefetched' => get_string('checkforupdateslast', 'core_plugin', date('d F Y, h:i A e', $time)),
Expand Down Expand Up @@ -209,14 +221,15 @@ public static function send_contactus_email_parameters() {
* @return array status, header and message
*/
public static function send_contactus_email($firstname, $lastname, $email, $subject, $message) {
self::validate_context(context_system::instance());
$admin = get_admin();
$admin->email = $email;
$admin->firstname = $firstname;
$admin->lastname = $lastname;
$support = new stdClass;
$support->id = -99;
$support->email = ESM_SUPPORT_EMAIL;
$status = esmutility::edwiser_site_monitor_send_email(
$status = utility::edwiser_site_monitor_send_email(
$admin,
$support,
$subject,
Expand All @@ -230,7 +243,7 @@ public static function send_contactus_email($firstname, $lastname, $email, $subj
));
$admin->firstname = 'Edwiser';
$admin->lastname = '';
$status &= esmutility::edwiser_site_monitor_send_email(
$status &= utility::edwiser_site_monitor_send_email(
$admin,
$admin,
$subject,
Expand Down
8 changes: 5 additions & 3 deletions classes/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* @author Yogesh Shirsath
*/

namespace block_edwiser_site_monitor;

defined('MOODLE_INTERNAL') || die;

/**
Expand All @@ -31,7 +33,7 @@
* @copyright 2019 WisdmLabs <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_edwiser_site_monitor_notifications {
class notifications {

/**
* Check whether post is notified before
Expand Down Expand Up @@ -85,10 +87,10 @@ private function notify($admin, $subject, $message, $url, $urlname = '') {
public function check() {
global $DB;
$admin = get_admin();
if (!block_edwiser_site_monitor_utility::edwiser_site_monitor_notification_allowed($admin)) {
if (!utility::edwiser_site_monitor_notification_allowed($admin)) {
return false;
}
$posts = block_edwiser_site_monitor_utility::get_edwiser_news();
$posts = utility::get_edwiser_news();
if (empty($posts)) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions classes/output/contactus.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/blocks/edwiser_site_monitor/classes/utility.php');

use renderable;
use renderer_base;
use templatable;
Expand Down
13 changes: 13 additions & 0 deletions classes/output/last_24_hours_usage.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ public function export_for_template(renderer_base $output) {
}
}
$data->hasdates = count($data->dates) > 1;

$lastrun = $DB->get_field('task_scheduled', 'lastruntime', array(
'component' => 'local_edwiserreports',
'classname' => '\local_edwiserreports\task\site_access_data'
));
if ($lastrun == false || $lastrun < time() - (60 * 5)) {
$data->error = get_string(
'crontaskwarning',
'block_edwiser_site_monitor',
'https://docs.moodle.org/311/en/Cron'
);
}

$output = null;
return $data;
}
Expand Down
16 changes: 8 additions & 8 deletions classes/output/live_status.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
use renderable;
use templatable;
use renderer_base;
use block_edwiser_site_monitor_usage as esmusage;
use block_edwiser_site_monitor_utility as esmutility;
use block_edwiser_site_monitor\usage;
use block_edwiser_site_monitor\utility;

/**
* Renderable for live status tab
Expand All @@ -50,19 +50,19 @@ class live_status implements renderable, templatable {
* @return stdClass|array
*/
public function export_for_template(renderer_base $output) {
$usage = esmusage::get_instance();
$usage = usage::get_instance();
$data = [
"cpu" => $usage->get_cpu_usage(),
"memory" => $usage->get_memory_usage(),
"storage" => $usage->get_storage_usage(),
"liveusers" => $usage->get_live_users(),
"disabled" => $usage::$disabled
];
$data["cpucolor"] = esmutility::get_color_class_from_value($data["cpu"]);
$data["memorycolor"] = esmutility::get_color_class_from_value($data["memory"]);
$data["storagecolor"] = esmutility::get_color_class_from_value($data["storage"]);
$data["memoryvalues"] = esmutility::get_values_ratio($data["memory"], $usage->get_total_memory());
$data["storagevalues"] = esmutility::get_values_ratio($data["storage"], $usage->get_total_storage());
$data["cpucolor"] = utility::get_color_class_from_value($data["cpu"]);
$data["memorycolor"] = utility::get_color_class_from_value($data["memory"]);
$data["storagecolor"] = utility::get_color_class_from_value($data["storage"]);
$data["memoryvalues"] = utility::get_values_ratio($data["memory"], $usage->get_total_memory());
$data["storagevalues"] = utility::get_values_ratio($data["storage"], $usage->get_total_storage());
$data = array_merge($data, $usage->get_all_users());
$output = null;
return $data;
Expand Down
4 changes: 2 additions & 2 deletions classes/output/recommendation.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
use renderable;
use renderer_base;
use templatable;
use block_edwiser_site_monitor_utility as esmutility;
use block_edwiser_site_monitor\utility;

/**
* Renderable for recommendation tab
Expand Down Expand Up @@ -82,7 +82,7 @@ public function export_for_template(renderer_base $output) {
$data = [];
$data['plugins'] = [];
$data['has'] = false;
$plugins = esmutility::get_edwiser_plugin_list();
$plugins = utility::get_edwiser_plugin_list();
if (empty($plugins)) {
$data['error'] = get_string('invalidjsonfile', 'block_edwiser_site_monitor');
return $data;
Expand Down
18 changes: 12 additions & 6 deletions classes/output/renderer.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ class renderer extends plugin_renderer_base {
*
* @return string
*/
public function render_live_status(renderable $livestatus) {
return $this->render_from_template('block_edwiser_site_monitor/live_status', $livestatus->export_for_template($this));
public function render_live_status(live_status $livestatus) {
return $this->render_from_template(
'block_edwiser_site_monitor/live_status',
$livestatus->export_for_template($this)
);
}

/**
Expand All @@ -56,7 +59,7 @@ public function render_live_status(renderable $livestatus) {
*
* @return string
*/
public function render_last_24_hours_usage(renderable $last24hoursusage) {
public function render_last_24_hours_usage(last_24_hours_usage $last24hoursusage) {
return $this->render_from_template(
'block_edwiser_site_monitor/last_24_hours_usage',
$last24hoursusage->export_for_template($this)
Expand All @@ -70,7 +73,7 @@ public function render_last_24_hours_usage(renderable $last24hoursusage) {
*
* @return string
*/
public function render_recommendation(renderable $recommendation) {
public function render_recommendation(recommendation $recommendation) {
return $this->render_from_template(
'block_edwiser_site_monitor/recommendation',
$recommendation->export_for_template($this)
Expand All @@ -84,7 +87,10 @@ public function render_recommendation(renderable $recommendation) {
*
* @return string
*/
public function render_contactus(renderable $contactus) {
return $this->render_from_template('block_edwiser_site_monitor/contactus', $contactus->export_for_template($this));
public function render_contactus(contactus $contactus) {
return $this->render_from_template(
'block_edwiser_site_monitor/contactus',
$contactus->export_for_template($this)
);
}
}
Loading

0 comments on commit 86dd62a

Please sign in to comment.