Improved Performance and Layout of Vue Applications, enhanced caching aswell as using less code
This commit is contained in:
@@ -2,82 +2,18 @@
|
||||
|
||||
use phpseclib3\Net\SSH2;
|
||||
|
||||
class RaspberryDisplayController extends mfBaseController
|
||||
{
|
||||
class RaspberryDisplayController extends mfBaseController {
|
||||
private int $port = 22;
|
||||
private string $username = XINON_RASPBERRY_DISPLAY_SSH_USER;
|
||||
private string $password = XINON_RASPBERRY_DISPLAY_SSH_PASS;
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
protected function init(): void {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me", $me);
|
||||
}
|
||||
|
||||
protected function restartRaspberryPi($id) {
|
||||
$display = RaspberryDisplayModel::get($id);
|
||||
|
||||
$ssh = new SSH2($display->ip_address, $this->port);
|
||||
$ssh->login($this->username, $this->password);
|
||||
$ssh->exec('sudo reboot now');
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getDisplaysApi(): array
|
||||
{
|
||||
$displays = RaspberryDisplayModel::getAll();
|
||||
$result = [];
|
||||
foreach ($displays as $display) {
|
||||
$result[] = [
|
||||
"display_label" => $display->display_label,
|
||||
"hostname" => $display->hostname,
|
||||
"ip" => $display->ip_address,
|
||||
"display_url" => $display->display_url,
|
||||
"auto_refresh_enabled" => $display->auto_refresh_enabled === "1",
|
||||
"margin_hot_fix_enabled" => $display->margin_hot_fix_enabled === "1",
|
||||
"custom_style" => $display->custom_style,
|
||||
"id" => $display->id,
|
||||
];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function change()
|
||||
{
|
||||
$displayID = $this->request->displayID;
|
||||
$field = $this->request->field;
|
||||
$value = $this->request->value;
|
||||
$value = $value === "true" ? 1 : ($value === "false" ? 0 : $value);
|
||||
$display = RaspberryDisplayModel::get($displayID);
|
||||
if ($display === null) {
|
||||
return false;
|
||||
}
|
||||
$display->$field = $value;
|
||||
$display->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getConfig() {
|
||||
$hostname = $this->request->hostname;
|
||||
|
||||
$displays = RaspberryDisplayModel::getByHostname($hostname);
|
||||
|
||||
if ($displays === null) {
|
||||
die("No display found for this hostname and ip:" . $hostname . " X ");
|
||||
}
|
||||
|
||||
return array_map(function ($display) {
|
||||
return [
|
||||
"display_url" => $display->data->display_url,
|
||||
"auto_refresh_enabled" => $display->data->auto_refresh_enabled === "1",
|
||||
"margin_hot_fix_enabled" => $display->data->margin_hot_fix_enabled === "1",
|
||||
"id" => $display->id,
|
||||
];
|
||||
}
|
||||
, $displays);
|
||||
}
|
||||
protected function apiAction() {
|
||||
$do = $this->request->do;
|
||||
|
||||
@@ -111,7 +47,7 @@ class RaspberryDisplayController extends mfBaseController
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
if(!is_array($return) || !count($return)) {
|
||||
if (!is_array($return) || !count($return)) {
|
||||
$data = ["status" => "error"];
|
||||
$this->returnJson($data);
|
||||
}
|
||||
@@ -120,9 +56,77 @@ class RaspberryDisplayController extends mfBaseController
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
protected function indexAction(): void
|
||||
{
|
||||
$this->layout()->setTemplate("RaspberryDisplay/Index");
|
||||
protected function getDisplaysApi(): array {
|
||||
$displays = RaspberryDisplayModel::getAll();
|
||||
$result = [];
|
||||
foreach ($displays as $display) {
|
||||
$result[] = ["display_label" => $display->display_label,
|
||||
"hostname" => $display->hostname,
|
||||
"ip" => $display->ip_address,
|
||||
"display_url" => $display->display_url,
|
||||
"auto_refresh_enabled" => $display->auto_refresh_enabled === "1",
|
||||
"margin_hot_fix_enabled" => $display->margin_hot_fix_enabled === "1",
|
||||
"custom_style" => $display->custom_style,
|
||||
"id" => $display->id,];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function change() {
|
||||
$displayID = $this->request->displayID;
|
||||
$field = $this->request->field;
|
||||
$value = $this->request->value;
|
||||
$value = $value === "true" ? 1 : ($value === "false" ? 0 : $value);
|
||||
$display = RaspberryDisplayModel::get($displayID);
|
||||
if ($display === null) {
|
||||
return false;
|
||||
}
|
||||
$display->$field = $value;
|
||||
$display->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function restartRaspberryPi($id) {
|
||||
$display = RaspberryDisplayModel::get($id);
|
||||
|
||||
$ssh = new SSH2($display->ip_address, $this->port);
|
||||
$ssh->login($this->username, $this->password);
|
||||
$ssh->exec('sudo reboot now');
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getConfig() {
|
||||
$hostname = $this->request->hostname;
|
||||
|
||||
$displays = RaspberryDisplayModel::getByHostname($hostname);
|
||||
|
||||
if ($displays === null) {
|
||||
die("No display found for this hostname and ip:" . $hostname . " X ");
|
||||
}
|
||||
|
||||
return array_map(function ($display) {
|
||||
return ["display_url" => $display->data->display_url,
|
||||
"auto_refresh_enabled" => $display->data->auto_refresh_enabled === "1",
|
||||
"margin_hot_fix_enabled" => $display->data->margin_hot_fix_enabled === "1",
|
||||
"id" => $display->id,];
|
||||
}, $displays);
|
||||
}
|
||||
|
||||
protected function indexAction(): void {
|
||||
$JSGlobals = ["BASE_URL" => self::getUrl("RaspberryDisplay"),
|
||||
"DASHBOARD_URL" => self::getUrl("Dashboard"),
|
||||
"MFAPPNAME" => MFAPPNAME_SLUG,
|
||||
"PAGE_TITLE" => "Raspberry Displays",
|
||||
"PATH" => [
|
||||
["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")],
|
||||
["text" => "Raspberry Displays", "href" => self::getUrl("RaspberryDisplay")]
|
||||
]
|
||||
];
|
||||
|
||||
$this->layout()->set("vueViewName", "RaspberryDisplay");
|
||||
$this->layout()->set("JSGlobals", $JSGlobals);
|
||||
$this->layout()->set("additionalCSS", ["css/views/RaspberryDisplay.css"]);
|
||||
$this->layout()->setTemplate("VueViews/Vue");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user