Skip to content

Commit

Permalink
Issue #12: edit data, begin work
Browse files Browse the repository at this point in the history
  • Loading branch information
ukko committed Mar 5, 2012
1 parent 7ea59fd commit e8f1a0b
Show file tree
Hide file tree
Showing 19 changed files with 727 additions and 45 deletions.
9 changes: 1 addition & 8 deletions application/classes/Command/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ class Command_Strings
{
public function get( $key )
{
$data = array(
'key' => $key,
'value' => R::factory()->get( $key ),
'cmd' => 'GET ' . $key,
);
return View::factory('tables/get', $data);


return R::factory()->get( $key );
}
}
12 changes: 9 additions & 3 deletions application/classes/Controller/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ public function move( $args )
*/
public function get( $key )
{
return Command_Strings::get( $key );
$data = array(
'key' => $key,
'value' => Command_Strings::get( $key ),
'cmd' => 'GET ' . $key,
);

return View::factory('tables/get', $data);
}

public function hgetall( $key )
Expand Down Expand Up @@ -205,7 +211,7 @@ public function zRangeByScore( $args )
return Command_ZSets::zRangeByScore( $key, $min, $max, $limit, $offset );
}

public function zrem( $key, $member )
public function zrem( $args )
{
$key = '';
$member = '';
Expand Down Expand Up @@ -240,7 +246,7 @@ public function lrange( $args )
return Command_Lists::lrange( $key, $start, $end );
}

public function lrem( $key, $count, $member )
public function lrem( $args )
{
$key = '';
$count = '';
Expand Down
20 changes: 20 additions & 0 deletions application/classes/Controller/CommandRaw.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright (c) 2011 Max Kamashev <[email protected]>
* Distributed under the GNU GPL v3. For full terms see the file COPYING.
*/
class Controller_CommandRaw extends Controller_Base
{
/**
* Get string value
*
* @param $key
* @return void
*/
public function get( $key )
{
return Command_Strings::get( $key );
}


}
25 changes: 20 additions & 5 deletions application/classes/Controller/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ public function action_index()
'history' => History::getLast($_SESSION['login']),
);

if ( Request::factory()->getAjax() )
if ( Request::factory()->getFormat() == Request::FORMAT_RAW )
{
header('Content-Type: application/json');
echo json_encode( $data );
echo "" . $data['content'];
}
else
{
echo View::factory('layout', $data);
if ( Request::factory()->getAjax() )
{
header('Content-Type: application/json');
echo json_encode( $data );
}
else
{
echo View::factory('layout', $data);
}
}
}

Expand All @@ -45,7 +52,15 @@ private function executeCommand()
$args = array();
}

$command = new Controller_Command();
if ( Request::factory()->getFormat() == Request::FORMAT_RAW )
{
$command = new Controller_CommandRaw();
}
else
{
$command = new Controller_Command();
}


if ( method_exists( $command, $method ) )
{
Expand Down
6 changes: 2 additions & 4 deletions application/classes/Helper/Hashes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public static function anchorActionDelete( $key, $field )
'back' => Request::factory()->getBack(),
);

$url = 'http://' . Request::factory()->getServerName() . '/?' . http_build_query( $params );
$title = 'HDEL ' . htmlspecialchars($key) . ' ' . htmlspecialchars($field);

return '<a class="cmd delete" href="' . $url . '" title="' . $title . '"><i class="icon-trash"></i> Delete</a>';
$url = Helper_Url::create() . '/?' . http_build_query( $params );
return Helper_Url::anchor($url, '<i class="icon-trash"></i> Delete', array('cmd', 'delete'));
}

public static function anchorActionEdit( $key, $field )
Expand Down
16 changes: 15 additions & 1 deletion application/classes/Helper/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ public static function anchorActionDelete( $key )
$url = 'http://' . Request::factory()->getServerName() . '/?' . http_build_query( $params );
$title = 'DEL ' . htmlspecialchars($key);

return '<a class="cmd delete" href="' . $url . '" title="' . $title . '">Delete</a>';
return '<a class="cmd delete" href="' . $url . '" title="' . $title . '"><i class="icon-trash"></i> Delete</a>';
}

public static function anchorActionEdit( $key )
{
$params = array(
'db' => Request::factory()->getDb(),
'cmd' => 'DEL ' . urlencode( $key ),
'back' => Request::factory()->getBack(),
);

$url = 'http://' . Request::factory()->getServerName() . '/?' . http_build_query( $params );
$title = 'DEL ' . htmlspecialchars($key);

return '<a class="cmd delete" href="' . $url . '" title="' . $title . '"><i class="icon-trash"></i> Delete</a>';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@ public static function create( $base = '', array $args = array() )
{
return 'http://' . $_SERVER['SERVER_NAME'];// . http_build_query( $args, $base );
}

/**
* Create anchor
*
* @param string $url
* @param string $value
* @param array $classes
* @return string
*/
public static function anchor( $url, $value, array $classes = array() )
{
return '<a href="' . $url . '"'
. ( ! empty( $classes ) ? ' class="' . implode(' ', $classes) . '"' : '' ) . '>' . $value . '</a>';
}
}
22 changes: 17 additions & 5 deletions application/classes/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ class Request
protected $cmd = null;
protected $serverName = null;
protected $page = null;
protected $limit = null;
protected $format = null;

protected $back = null;

protected static $instance = null;

const FORMAT_RAW = 'raw';
const FORMAT_HTML = 'html';

private function __construct() {}

private function before()
Expand Down Expand Up @@ -87,6 +90,15 @@ private function before()
{
$this->setBack( filter_input( INPUT_GET, 'back', FILTER_SANITIZE_STRING ) );
}

if ( filter_input( INPUT_POST, 'format' ) == self::FORMAT_RAW || filter_input( INPUT_GET, 'format' ) == self::FORMAT_RAW)
{
$this->setFormat( self::FORMAT_RAW );
}
else
{
$this->setFormat( self::FORMAT_HTML );
}
}

/**
Expand Down Expand Up @@ -237,13 +249,13 @@ public function getServerName()
return $this->serverName;
}

public function setLimit($limit)
public function setFormat($format)
{
$this->limit = $limit;
$this->format = $format;
}

public function getLimit()
public function getFormat()
{
return $this->limit;
return $this->format;
}
}
2 changes: 1 addition & 1 deletion application/view/exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="<?php echo Helper_URL::create() ?>">Re:admin</a>
<a class="brand" href="<?php echo Helper_Url::create() ?>">Re:admin</a>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions application/view/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<script src="/js/bootstrap-button.js"></script>
<script src="/js/jquery.history.js"></script>
<script src="/js/jquery.jeditable.js"></script>
<script src="/js/jquery.autogrow.js"></script>
<script src="/js/jquery.jeditable.autogrow.js"></script>
<script src="/js/jquery-ui-1.8.17.custom.min.js"></script>
Expand Down
7 changes: 1 addition & 6 deletions application/view/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="<?php echo Helper_URL::create() ?>">Re:admin</a>
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="<?php echo Helper_Url::create() ?>">Re:admin</a>
</div>
</div>
</div>
Expand Down
26 changes: 18 additions & 8 deletions application/view/tables/get.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
<h5>GET <?php echo htmlspecialchars($key, ENT_QUOTES) ?></h5>
<h5 var-cmd="<?php echo $cmd ?>">GET <?php echo htmlspecialchars($key, ENT_QUOTES) ?></h5>
<table class="table table-striped table-bordered">
<thead>
<tr>
<td class="span11">Value</td>
<td class="span1">Action</td>
<th class="span10">Value</th>
<th class="action">Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="span10" style="overflow:auto;">
<?php echo htmlspecialchars($value, ENT_QUOTES) ?>
</div>
<div class="span9 overflow edit"
cmd="<?php echo $key ?>"
data-key="<?php echo htmlspecialchars($key, ENT_QUOTES) ?>"
data-load="/?db=0&format=raw&cmd=GET+test.s"
data-save="/?db=0&cmd=SET+test.s">
<?php echo htmlspecialchars($value, ENT_QUOTES) ?>
</div>
</td>
<td>
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-pencil"></i> <span class="caret"></span></a>
<a class="btn " data-toggle="dropdown" href="#">
<i class="icon-pencil"></i>
</a>
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<?php echo Helper_Strings::anchorActionDelete( $key ) ?>
<li><?php echo Helper_Strings::anchorActionDelete( $key ) ?></li>
</ul>
</div>

</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion application/view/tables/keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<tr>
<th class="chckbox"><input type="checkbox"></th>
<th class="span1">Type</th>
<th>Key</th>
<th class="span8">Key</th>
<th class="action">Action</th>
</tr>
</thead>
Expand Down
2 changes: 1 addition & 1 deletion application/view/topbar.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="<?php echo Helper_URL::create() ?>">Re:admin</a>
<a class="brand" href="<?php echo Helper_Url::create() ?>">Re:admin</a>

<div class="nav-collapse">
<ul class="nav pull-right">
Expand Down
2 changes: 1 addition & 1 deletion www/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ span.small {

table th.action
{
width: 70px;
width: 80px;
}

table th.chckbox
Expand Down
Loading

0 comments on commit e8f1a0b

Please sign in to comment.