Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 0f83bb0

Browse files
OliverOliver
Oliver
authored and
Oliver
committed
Redis Datenbakverwaltung implementiert Issue #21
1 parent 80596b3 commit 0f83bb0

File tree

11 files changed

+218
-6
lines changed

11 files changed

+218
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace RWF\Template\Plugin;
4+
5+
//Imports
6+
use RWF\Template\TemplateFunction;
7+
use RWF\Template\Template;
8+
use RWF\Util\TimeUtil;
9+
10+
11+
/**
12+
* formatiert einen Zeitwert in Sekunden in einen lesbaren Zeitabstand
13+
*
14+
* @author Oliver Kleditzsch
15+
* @copyright Copyright (c) 2014, Oliver Kleditzsch
16+
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
17+
* @since 2.0.0-0
18+
* @version 2.0.0-0
19+
*/
20+
class SecondsFunction implements TemplateFunction {
21+
22+
/**
23+
* Template Funktion
24+
*
25+
* @param Array $value Werte
26+
* @param \RWF\Template\Template $tpl Template Objekt
27+
* @return String
28+
*/
29+
public static function execute(array $value, Template $tpl) {
30+
31+
if (isset($value[1]) && $value[1] == 1) {
32+
33+
return TimeUtil::formatTimefromSeconds($value[0], true);
34+
}
35+
return TimeUtil::formatTimefromSeconds($value[0], false);
36+
}
37+
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace SHC\Command\Web;
4+
5+
//Imports
6+
use RWF\Date\DateTime;
7+
use RWF\Request\Commands\AjaxCommand;
8+
use RWF\Request\Request;
9+
use RWF\Util\Message;
10+
use SHC\Core\SHC;
11+
12+
/**
13+
* Datenbankverwaltung
14+
*
15+
* @author Oliver Kleditzsch
16+
* @copyright Copyright (c) 2014, Oliver Kleditzsch
17+
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
18+
* @since 2.0.0-0
19+
* @version 2.0.0-0
20+
*/
21+
class DatabaseAjax extends AjaxCommand {
22+
23+
protected $premission = 'shc.acp.databaseManagement';
24+
25+
/**
26+
* Sprachpakete die geladen werden sollen
27+
*
28+
* @var Array
29+
*/
30+
protected $languageModules = array('acpindex', 'database');
31+
32+
/**
33+
* Daten verarbeiten
34+
*/
35+
public function processData() {
36+
37+
$tpl = SHC::getTemplate();
38+
$db = SHC::getDatabase();
39+
40+
if($this->request->issetParam('dump', Request::GET)) {
41+
42+
$message = new Message();
43+
if($db->bgsave()) {
44+
45+
$message->setType(Message::SUCCESSFULLY);
46+
$message->setMessage(SHC::getLanguage()->get('acp.database.dump.success'));
47+
} else {
48+
49+
$message->setType(Message::ERROR);
50+
$message->setMessage(SHC::getLanguage()->get('acp.database.dump.error'));
51+
}
52+
$tpl->assign('message', $message);
53+
}
54+
55+
$info = $db->info();
56+
$lastSave = $info['rdb_last_save_time'];
57+
$lastSaveDate = DateTime::now();
58+
$lastSaveDate->setTimestamp($lastSave);
59+
60+
$tpl->assign('info', $info);
61+
$tpl->assign('lastSaveDate', $lastSaveDate);
62+
63+
$this->data = $tpl->fetchString('database.html');
64+
}
65+
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<div>
2+
<div class="shc-view-content">
3+
{if $message|isset}
4+
{$message->fetchHTML()}
5+
{/if}
6+
<table class="shc-view-contentTable">
7+
<tbody>
8+
<tr>
9+
<td style="width: 25%; font-weight: bold;">{lang var='acp.database.version'}</td>
10+
<td style="width: 25%;">{#$info.redis_version}</td>
11+
<td style="width: 25%; font-weight: bold;">{lang var='acp.database.mode'}</td>
12+
<td style="width: 25%;">{#$info.redis_mode}</td>
13+
</tr>
14+
<tr>
15+
<td style="font-weight: bold;">{lang var='acp.database.version'}</td>
16+
<td>{#$info.uptime_in_seconds|seconds:1}</td>
17+
<td style="font-weight: bold;">{lang var='acp.database.config'}</td>
18+
<td>{#$info.config_file}</td>
19+
</tr>
20+
<tr>
21+
<td style="font-weight: bold;">{lang var='acp.database.memory'}</td>
22+
<td>{#$info.used_memory|filesizebinary}</td>
23+
<td style="font-weight: bold;">{lang var='acp.database.memoryPeak'}</td>
24+
<td>{#$info.used_memory_peak|filesizebinary}</td>
25+
</tr>
26+
<tr>
27+
<td style="font-weight: bold;">{lang var='acp.database.lastSave'}</td>
28+
<td>{#$lastSaveDate|timeline}</td>
29+
<td style="font-weight: bold;">{lang var='acp.database.lastSaveState'}</td>
30+
<td>{#$info.rdb_last_bgsave_status}</td>
31+
</tr>
32+
<tr>
33+
<td style="font-weight: bold;">{lang var='acp.database.input'}</td>
34+
<td>{#$info.total_net_input_bytes|filesizebinary}</td>
35+
<td style="font-weight: bold;">{lang var='acp.database.output'}</td>
36+
<td>{#$info.total_net_output_bytes|filesizebinary}</td>
37+
</tr>
38+
</tbody>
39+
</table>
40+
</div>
41+
</div>
42+
<div class="shc-view-buttons">
43+
<div class="shc-view-buttonSet">
44+
{acpbackbutton location="index.php?app=shc&page=acp"}
45+
<button id="shc-view-button-dump">{lang var="acp.database.buttons.dump"}</button>
46+
</div>
47+
</div>
48+
<script type="text/javascript">
49+
function onLoad() {
50+
51+
$('#shc-view-acp-contentBox .shc-contentbox-header').first().text('{lang var="acp.database.title"}');
52+
$('.shc-view-buttonSet').buttonset();
53+
54+
$('#shc-view-button-dump').unbind( "click" );
55+
$('#shc-view-button-dump').click(function() {
56+
$.get("index.php?app=shc&ajax=database&dump=1&hash=" + Math.floor(Math.random() * 11), function(data, textStatus, jqXHR) {
57+
$('#shc-view-acp-contentBox div.shc-contentbox-inner').html(data);
58+
onLoad();
59+
});
60+
});
61+
}
62+
$(onLoad);
63+
</script>

shc/data/commands/web/acp/templates/acppage.html

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ <h2>{lang var='acpindex.menu.group.main'}</h2>
2222
<div class="shc-view-acp-menuGroup-body">
2323
{acpmenuitem text='acpindex.menu.users' icon='shc-view-acp-menu-usermanagement' link='index.php?app=shc&ajax=listusers' premission='shc.acp.userManagement'}
2424
{acpmenuitem text='acpindex.menu.settings' icon='shc-view-acp-menu-settings' link='index.php?app=shc&ajax=settingsform' premission='shc.acp.settings'}
25+
{acpmenuitem text='acpindex.menu.database' icon='shc-view-acp-menu-database' link='index.php?app=shc&ajax=database' premission='shc.acp.databaseManagement'}
2526
{acpmenuitem text='acpindex.menu.backup' icon='shc-view-acp-menu-backup' link='index.php?app=shc&ajax=listbackups' premission='shc.acp.backupsManagement'}
2627
</div>
2728
</div>

shc/data/lang/de/acp/acpindex.lang.php

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
$l['acpindex.menu.users'] = 'Benutzer';
3030
$l['acpindex.menu.settings'] = 'Einstellungen';
3131
$l['acpindex.menu.backup'] = 'Backup';
32+
$l['acpindex.menu.database'] = 'Dantenbank';
3233

3334
$l['acpindex.menu.group.smartHome'] = 'Smart Home';
3435
$l['acpindex.menu.rooms'] = 'Räume';
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/**
4+
* Datenbank Sprachvariablen
5+
*
6+
* @author Oliver Kleditzsch
7+
* @copyright Copyright (c) 2014, Oliver Kleditzsch
8+
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
9+
* @since 2.0.0-0
10+
* @version 2.0.0-0
11+
*/
12+
$l = array();
13+
14+
//Titel
15+
$l['acp.database.title'] = 'Datenbank';
16+
17+
//buttons
18+
$l['acp.database.buttons.dump'] = 'Datenbank speichern';
19+
20+
//Tabelle
21+
$l['acp.database.version'] = 'Version';
22+
$l['acp.database.mode'] = 'Modus';
23+
$l['acp.database.uptime'] = 'Laufzeit';
24+
$l['acp.database.config'] = 'Konfig. Datei';
25+
$l['acp.database.memory'] = 'Speicherbedarf';
26+
$l['acp.database.memoryPeak'] = 'Speicherbedarf spitze';
27+
$l['acp.database.lastSave'] = 'letzte Speicherung';
28+
$l['acp.database.lastSaveState'] = 'Speicherstatus';
29+
$l['acp.database.input'] = 'Empfangen';
30+
$l['acp.database.output'] = 'Gesendet';
31+
32+
//Meldungen
33+
$l['acp.database.dump.success'] = 'Die Datenbank wurde erfolgreich gespeichert';
34+
$l['acp.database.dump.error'] = 'Die Datenbank konnte nicht gespeichert werden';

shc/data/lang/de/acp/usermanagement.lang.php

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
$l['acp.userManagement.premissions.shc.acp.userManagement.description'] = 'Benutzer und Gruppen erstellen, bearbeiten und löschen';
100100
$l['acp.userManagement.premissions.shc.acp.settings'] = 'Einstellungen';
101101
$l['acp.userManagement.premissions.shc.acp.settings.description'] = 'Der Benutzer kann die Einstellungen des SHC bearbeiten';
102+
$l['acp.userManagement.premissions.shc.acp.databaseManagement'] = 'Datenbank';
103+
$l['acp.userManagement.premissions.shc.acp.databaseManagement.description'] = 'Datenbank überwachen';
102104
$l['acp.userManagement.premissions.shc.acp.backupsManagement'] = 'Backups';
103105
$l['acp.userManagement.premissions.shc.acp.backupsManagement.description'] = 'Backups erstellen, löschen und herunterladen';
104106
$l['acp.userManagement.premissions.shc.acp.roomManagement'] = 'Räume verwalten';

shc/inc/img/acpmenue/database.png

2.55 KB
Loading

shc/inc/style/web/all/9-icons.css

+6-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ span.shc-icon-shutdown {
118118
span.shc-icon-high {
119119
display: inline-block;
120120
width: 48px;
121-
heigt: 48px;
121+
height: 48px;
122122
border: #006907 solid 1px;
123123
background-color: #006907;;
124124
border-radius: 24px;
@@ -127,7 +127,7 @@ span.shc-icon-high {
127127
span.shc-icon-low {
128128
display: inline-block;
129129
width: 48px;
130-
heigt: 48px;
130+
height: 48px;
131131
border: #d00101 solid 1px;
132132
background-color: #d00101;;
133133
border-radius: 24px;
@@ -146,6 +146,10 @@ span#shc-view-acp-menu-backup {
146146
background-image: url(../../../img/acpmenue/backup.png);
147147
}
148148

149+
span#shc-view-acp-menu-database {
150+
background-image: url(../../../img/acpmenue/database.png);
151+
}
152+
149153
span#shc-view-acp-menu-rooms {
150154
background-image: url(../../../img/acpmenue/rooms.png);
151155
}

shc/lib/template/plugin/acpmenuitemcompilerplugin.class.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function execute(array $args, TemplateCompiler $compiler) {
4141

4242
if(!isset($args['link'])) {
4343

44-
throw new TemplateCompilationException('missing "icon" attribute in premission tag', $compiler->getTemplateName(), $compiler->getCurrentLine());
44+
throw new TemplateCompilationException('missing "link" attribute in premission tag', $compiler->getTemplateName(), $compiler->getCurrentLine());
4545
}
4646

4747
$premission = '';
@@ -68,15 +68,15 @@ public function execute(array $args, TemplateCompiler $compiler) {
6868
}
6969

7070
//HTML
71-
$html .= '<div class="shc-view-acp-menuItem" id="'. $randomStr .'">';
71+
$html .= '<div class="shc-view-acp-menuItem" id="a'. $randomStr .'">';
7272
$html .= '<span class="shc-view-acp-menuItem-icon" id='. $args['icon'] .'></span>';
7373
$html .= '<span class="shc-view-acp-menuItem-text"><?php echo \\RWF\\Core\\RWF::getLanguage()->get('. $args['text'] .'); ?></span>';
7474
$html .= '</div>';
7575
$html .= '<script type="text/javascript">';
7676
$html .= '$(function() {';
77-
$html .= '$(\'#'. $randomStr .'\').click(function() {';
77+
$html .= '$(\'#a'. $randomStr .'\').click(function() {';
7878
$html .= '$.get('. $args['link'] .', function(data, textStatus, jqXHR) {';
79-
$html .= '$(\'#shc-view-acp-contentBox div.shc-contentbox-body\').html(data);';
79+
$html .= '$(\'#shc-view-acp-contentBox div.shc-contentbox-inner\').html(data);';
8080
$html .= '});';
8181
$html .= '});';
8282
$html .= '});';

templateTags.txt

+3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ $Zeitobjekt|time[:'format']
108108
$Zeitobjekt|date[:'format'] //Formatiert ein Datum
109109
$Zeitobjekt|datetime[:'format'] //Formatiert Datum und Zeit
110110
$Zeitobjekt|timeline[:'format'] //Formatiert eine Zeitschiene
111+
$Zeitobjekt|seconds[:0|1] //Formatiert einen Wert aus Sekunden in ein lesbares Format
112+
$bytes|filesize //Formatiert einen Wert aus Bytes in ein lesbares Format Basis 1000
113+
$bytes|filesizebinary //Formatiert einen Wert aus Bytes in ein lesbares Format Basis 1024
111114

112115
-----------------------------------------------------------------------------------------------------------------------------------------
113116
Block Plugins

0 commit comments

Comments
 (0)