mirror of
https://github.com/unraid/webgui.git
synced 2026-05-04 16:59:27 -05:00
System update
Make SelectCase using nchan
This commit is contained in:
@@ -249,7 +249,7 @@ form[name=boot]{display:none}
|
||||
<i id='mycase' class='fa fa-hdd-o'></i><br>
|
||||
<?endif;?>
|
||||
</span>
|
||||
<input type='button' value="_(Edit)_" style="margin-right:0" onclick='openBox("/webGui/include/SelectCase.php?file=<?=$myfile?>&csrf=<?=$var['csrf_token']?>","_(Select Case Model)_",700,980,true,"setCase");return false'>
|
||||
<input type='button' value="_(Edit)_" style="margin-right:0" onclick='openChanges("select_case <?=$myfile?>", "_(Select Case Model)_", "selectcase")'>
|
||||
</div>
|
||||
</td><td></td></tr>
|
||||
</tbody>
|
||||
@@ -731,7 +731,7 @@ function loadlist(init) {
|
||||
context.init({preventDoubleContext:false,left:true,above:false});
|
||||
});
|
||||
}
|
||||
function setCase() {
|
||||
function getCase() {
|
||||
$.post('/webGui/include/SelectCase.php',{mode:'get',file:'<?=$myfile?>'},function(model){
|
||||
if (!model) {
|
||||
$('#casing').html("<i id='mycase' class='fa fa-hdd-o'></i><br>");
|
||||
|
||||
@@ -283,7 +283,7 @@ function openPlugin(cmd,title,plg,func) {
|
||||
});
|
||||
}
|
||||
function startStopNchan(cmd, name='changes') {
|
||||
const channel = {nchan_changes,nchan_phistory,nchan_feedback,nchan_sysinfo};
|
||||
const channel = {nchan_changes,nchan_phistory,nchan_feedback,nchan_sysinfo,nchan_selectcase};
|
||||
switch (cmd) {
|
||||
case 'start':
|
||||
channel['nchan_'+name].start();
|
||||
@@ -807,6 +807,11 @@ nchan_sysinfo.on('message', function(data) {
|
||||
$('pre#body').html(data);
|
||||
});
|
||||
|
||||
var nchan_selectcase = new NchanSubscriber('/sub/selectcase',{subscriber:'websocket'});
|
||||
nchan_selectcase.on('message', function(data) {
|
||||
$('pre#body').html(data);
|
||||
});
|
||||
|
||||
var backtotopoffset = 250;
|
||||
var backtotopduration = 500;
|
||||
$(window).scroll(function() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2020, Lime Technology
|
||||
* Copyright 2012-2020, Bergware International.
|
||||
/* Copyright 2005-2022, Lime Technology
|
||||
* Copyright 2012-2022, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
@@ -11,119 +11,24 @@
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
// add translations
|
||||
$_SERVER['REQUEST_URI'] = 'dashboard';
|
||||
require_once "$docroot/webGui/include/Translations.php";
|
||||
$file = $_POST['file'];
|
||||
$model = $_POST['model'];
|
||||
$root = "/boot/config/plugins/dynamix";
|
||||
$name = "$root/$file";
|
||||
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
extract(parse_plugin_cfg('dynamix',true));
|
||||
|
||||
$boot = "/boot/config/plugins/dynamix";
|
||||
$file = unscript($_GET['file'] ?? $_POST['file']);
|
||||
$model = $_POST['model'] ?? false;
|
||||
$exist = file_exists("$boot/$file");
|
||||
|
||||
switch ($_POST['mode']) {
|
||||
case 'set':
|
||||
file_put_contents("$boot/$file",$model);
|
||||
exit;
|
||||
case 'get':
|
||||
if ($exist) echo file_get_contents("$boot/$file");
|
||||
exit;
|
||||
case 'del':
|
||||
if ($exist) unlink("$boot/$file");
|
||||
exit;
|
||||
case 'file':
|
||||
$name = 'case-model.png';
|
||||
file_put_contents("$boot/$file",$name);
|
||||
file_put_contents("$boot/$name",base64_decode(str_replace('data:image/png;base64,','',$_POST['data'])));
|
||||
exit;
|
||||
}
|
||||
$casemodel = $exist ? file_get_contents("$boot/$file") : '';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html <?=$display['rtl']?>lang="<?=strtok($locale,'_')?:'en'?>">
|
||||
<head>
|
||||
<title><?=_('Select Case Model')?></title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta http-equiv="Content-Security-Policy" content="block-all-mixed-content">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="viewport" content="width=1600">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<meta name="referrer" content="same-origin">
|
||||
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/default-fonts.css")?>">
|
||||
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/default-popup.css")?>">
|
||||
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/default-cases.css")?>">
|
||||
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/font-awesome.css")?>">
|
||||
<style>
|
||||
div.tab{float:left;margin-top:0}
|
||||
div.tab input[id^="tab"]{display:none}
|
||||
div.tab [type=radio]+label:hover{background-color:transparent;border:1px solid #ff8c2f;border-bottom:none;cursor:pointer;opacity:1}
|
||||
div.tab [type=radio]:checked+label{cursor:default;background-color:transparent;border:1px solid #ff8c2f;border-bottom:none;opacity:1}
|
||||
div.tab [type=radio]+label~.content{display:none}
|
||||
div.tab [type=radio]:checked+label~.content{display:inline}
|
||||
div.tab [type=radio]+label{position:relative;font-size:1.4rem;letter-spacing:1.8px;padding:4px 10px;margin-right:2px;border-top-left-radius:6px;border-top-right-radius:6px;border:1px solid #b2b2b2;border-bottom:none;background-color:#e2e2e2;opacity:0.5}
|
||||
div.tab [type=radio]+label img{padding-right:4px}
|
||||
div.content{position:absolute;top:0;left:0;width:100%}
|
||||
label+.content{margin-top:64px}
|
||||
div.case-list{float:left;padding:10px;margin-right:10px;margin-bottom:64px;height:128px;width:128px;text-align:center}
|
||||
div.case-list.left{margin-left:20px}
|
||||
div.case-list.right{margin-right:0;padding-right:0}
|
||||
div.case-list i{width:auto;max-width:128px;height:128px;font-size:128px}
|
||||
div.case-list i.fa{padding-top:16px;margin-bottom:-16px;max-width:80px;font-size:80px}
|
||||
div.case-list:hover{color:#f0000c}
|
||||
div.case-name{margin-top:8px;font-family:clear-sans!important}
|
||||
</style>
|
||||
<script src="<?autov('/webGui/javascript/dynamix.js')?>"></script>
|
||||
<script>
|
||||
function importFile(file) {
|
||||
if (file.name.split(".").pop().toLowerCase() !== "png") {
|
||||
alert("<?=_("Only PNG images are allowed!")?>");
|
||||
return;
|
||||
}
|
||||
var reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = function(e){$.post('/webGui/include/SelectCase.php',{mode:'file',file:'<?=$file?>',data:e.target.result,csrf_token:'<?=unscript($_GET["csrf"])?>'},function(){top.Shadowbox.close();})};
|
||||
}
|
||||
function setCase(model) {
|
||||
$.post('/webGui/include/SelectCase.php',{mode:'set',file:'<?=$file?>',model:model,csrf_token:'<?=unscript($_GET["csrf"])?>'},function(){top.Shadowbox.close();});
|
||||
}
|
||||
function deleteCase() {
|
||||
$.post('/webGui/include/SelectCase.php',{mode:'del',file:'<?=$file?>',csrf_token:'<?=unscript($_GET["csrf"])?>'},function(){top.Shadowbox.close();});
|
||||
}
|
||||
$(function() {
|
||||
$('#tab1').prop('checked',true);
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div style='margin:20px 0 0 30px'>
|
||||
<?
|
||||
$models = [];
|
||||
$cases = explode("\n",file_get_contents("$docroot/webGui/styles/default-cases.css"));
|
||||
foreach ($cases as $case) if (substr($case,0,6)=='.case-') $models[] = substr($case,1,strpos($case,':')-1);
|
||||
natsort($models);
|
||||
$tabs = floor((count($models)+2)/18)+1;
|
||||
for ($tab=1; $tab<=$tabs; $tab++) {
|
||||
echo "<div class='tab'><input type='radio' id='tab{$tab}' name='tabs'><label for='tab{$tab}'>$tab</label><div class='content'>";
|
||||
for ($i=($tab-1)*18; $i < $tab*18; $i++) {
|
||||
if ($i>=count($models)) break;
|
||||
$model = $models[$i];
|
||||
$name = substr($model,5);
|
||||
$title = str_replace('3u-avs-10-4','3u-avs-10/4',$name);
|
||||
$select = $name==$casemodel ? 'color:#e68a00' : '';
|
||||
echo "<a style='text-decoration:none;cursor:pointer;$select' onclick='setCase(\"$name\")'><div class='case-list".($i%6==0?' left':($i%6==5?' right':''))."' id='$name'><i class='$model'></i><div class='case-name'>$title</div></div></a>";
|
||||
if (realpath(dirname($name)) == $root) {
|
||||
switch ($_POST['mode']) {
|
||||
case 'set':
|
||||
if ($model) file_put_contents($name,$model);
|
||||
break;
|
||||
case 'get':
|
||||
if (is_file($name)) echo file_get_contents($name);
|
||||
break;
|
||||
case 'file':
|
||||
$case = 'case-model.png';
|
||||
file_put_contents($name,$case);
|
||||
file_put_contents("$root/$case",base64_decode(str_replace('data:image/png;base64,','',$_POST['data'])));
|
||||
break;
|
||||
}
|
||||
if ($tab==$tabs) {
|
||||
echo "<a style='text-decoration:none;cursor:pointer;$select' onclick='$(\"input#file\").trigger(\"click\")'><div class='case-list".($i%6==0?' left':($i%6==5?' right':''))."' id='Custom'><i class='fa fa-file-image-o'></i><div class='case-name'>"._('custom image')."</div></div></a>"; $i++;
|
||||
}
|
||||
echo "</div></div>";
|
||||
}
|
||||
$select = substr($casemodel,-4)=='.png' ? 'color:#e68a00' : '';
|
||||
?>
|
||||
<input type='file' id='file' accept='.png' onchange='importFile(this.files[0])' style='display:none'>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/php -q
|
||||
<?PHP
|
||||
/* Copyright 2005-2022, Lime Technology
|
||||
* Copyright 2012-2022, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
session_start();
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
|
||||
require_once "$docroot/webGui/include/Helpers.php";
|
||||
extract(parse_plugin_cfg('dynamix',true));
|
||||
|
||||
// add translations
|
||||
$_SERVER['REQUEST_URI'] = 'dashboard';
|
||||
$_SESSION['locale'] = $display['locale'];
|
||||
require_once "$docroot/webGui/include/Translations.php";
|
||||
|
||||
function write($message){
|
||||
$nchan = curl_init();
|
||||
curl_setopt_array($nchan,[
|
||||
CURLOPT_URL => 'http://localhost/pub/selectcase?buffer_length=0',
|
||||
CURLOPT_UNIX_SOCKET_PATH => '/var/run/nginx.socket',
|
||||
CURLOPT_POST => 1,
|
||||
CURLOPT_POSTFIELDS => $message,
|
||||
CURLOPT_RETURNTRANSFER => true
|
||||
]);
|
||||
curl_exec($nchan);
|
||||
curl_close($nchan);
|
||||
}
|
||||
|
||||
$boot = "/boot/config/plugins/dynamix";
|
||||
$file = $argv[1];
|
||||
$exist = is_file("$boot/$file");
|
||||
$cmodel = $exist ? file_get_contents("$boot/$file") : '';
|
||||
|
||||
$style = ["<style>"];
|
||||
$style[] = "div.case-list{float:left;padding:10px;margin:0 30px 64px 0;height:128px;width:128px;text-align:center}";
|
||||
$style[] = "div.case-list span{position:relative;top:64px;width:auto;max-width:128px;height:128px;font-size:128px;cursor:pointer}";
|
||||
$style[] = "div.case-list span.fa{top:24px;height:128px;width:auto;max-width:80px;font-size:80px;cursor:pointer}";
|
||||
$style[] = "div.case-list:hover{color:#f0000c}";
|
||||
$style[] = "div.case-name{position:relative;top:74px}";
|
||||
$style[] = "div.custom-name{position:relative;top:10px}";
|
||||
$style[] = "</style>";
|
||||
|
||||
$script = ["<script>"];
|
||||
$script[] = "function selectDone() {";
|
||||
$script[] = " nchan_selectcase.stop();";
|
||||
$script[] = " $('.sweet-alert').hide('fast').removeClass('nchan');";
|
||||
$script[] = " swal.close();";
|
||||
$script[] = " getCase();";
|
||||
$script[] = "}";
|
||||
$script[] = "function setCase(model) {";
|
||||
$script[] = " \$.post('/webGui/include/SelectCase.php',{mode:'set',file:'$file',model:model},function(){selectDone();});";
|
||||
$script[] = "}";
|
||||
$script[] = "function importFile(file) {";
|
||||
$script[] = " if (file.name.split('.').pop().toLowerCase() != 'png') return;";
|
||||
$script[] = " var reader = new FileReader();";
|
||||
$script[] = " reader.readAsDataURL(file);";
|
||||
$script[] = " reader.onload = function(e){\$.post('/webGui/include/SelectCase.php',{mode:'file',file:'$file',data:e.target.result},function(){selectDone();})};";
|
||||
$script[] = "}";
|
||||
$script[] = "</script>";
|
||||
|
||||
$html = ["<div>"];
|
||||
$cases = explode("\n",file_get_contents("$docroot/webGui/styles/default-cases.css"));
|
||||
foreach ($cases as $case) if (substr($case,0,6)=='.case-') $models[] = substr($case,1,strpos($case,':')-1);
|
||||
natsort($models);
|
||||
for ($i=0; $i < count($models); $i++) {
|
||||
$model = $models[$i];
|
||||
$name = substr($model,5);
|
||||
$title = str_replace('3u-avs-10-4','3u-avs-10/4',$name);
|
||||
$select = $name==$cmodel ? 'color:#e68a00' : '';
|
||||
$html[] = "<div id='$name' class='case-list' style='$select' onclick='setCase(\"$name\")'><span class='$model'></span><div class='case-name'>$title</div></div>";
|
||||
}
|
||||
$html[] = "<div id='Custom' class='case-list' style='$select' onclick='$(\"input#file\").trigger(\"click\")'><span class='fa fa-file-image-o'></span><div class='custom-name'>"._('custom image')."</div></div>";
|
||||
$i++;
|
||||
$html[] = "</div></div>";
|
||||
$select = substr($cmodel,-4)=='.png' ? 'color:#e68a00' : '';
|
||||
$html[] = "<input type='file' id='file' accept='.png' onchange='importFile(this.files[0])' style='display:none'>";
|
||||
$html[] = "</div>";
|
||||
|
||||
usleep(50000);
|
||||
write(implode($style).implode($script).implode($html));
|
||||
?>
|
||||
Reference in New Issue
Block a user