Skip to content

Commit

Permalink
Add node manage
Browse files Browse the repository at this point in the history
  • Loading branch information
orvice committed Jul 3, 2017
1 parent e372242 commit ea5ada7
Show file tree
Hide file tree
Showing 31 changed files with 359 additions and 58,455 deletions.
69 changes: 69 additions & 0 deletions app/Controllers/Api/Admin/NodeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php


namespace App\Controllers\Api\Admin;

use Slim\Http\Request;
use Slim\Http\Response;
use App\Models\Node;
use App\Models\TrafficLog;
use App\Controllers\BaseController;

class NodeController extends BaseController
{

public function index(Request $req, Response $res, $args)
{
$pageNum = 1;
if (isset($req->getQueryParams()['page'])) {
$pageNum = $req->getQueryParams()['page'];
}
$traffic = Node::paginate(15, [
'*',
], 'page', $pageNum);
$traffic->setPath('/api/admin/nodes');
//return $this->echoJsonWithData($res,$traffic);
return $this->echoJson($res, $traffic);
}

private function saveModel(Response $response, Node $node, $arr)
{
foreach ($arr as $k => $v) {
$node->$k = $v;
}
$node->save();
return $this->echoJsonWithData($response, $node);
}

public function store(Request $req, Response $res, $args)
{
$input = file_get_contents("php://input");
$arr = json_decode($input, true);
return $this->saveModel($res, new Node(), $arr);
}

public function update(Request $req, Response $res, $args)
{
$input = file_get_contents("php://input");
$arr = json_decode($input, true);
return $this->saveModel($res, Node::find($args['id']), $arr);
}

public function trafficLogs(Request $req, Response $res, $args)
{
$pageNum = 1;
if (isset($req->getQueryParams()['page'])) {
$pageNum = $req->getQueryParams()['page'];
}
$traffic = TrafficLog::where('user_traffic_log.node_id', $args['id'])
->join('ss_node', 'user_traffic_log.node_id', '=', 'ss_node.id')
->orderBy('user_traffic_log.id', 'desc')
->paginate(15, [
'user_traffic_log.*',
'ss_node.name as name'
], 'page', $pageNum);
$traffic->setPath('/api/admin/trafficLogs');
//return $this->echoJsonWithData($res,$traffic);
return $this->echoJson($res, $traffic);
}
}
4 changes: 2 additions & 2 deletions mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/public/assets/js/app.js": "/public/assets/js/app.js",
"/public/assets/js/home.js": "/public/assets/js/home.js",
"/public/assets/js/admin.js": "/public/assets/js/admin.js"
"/public/assets/js/admin.js": "/public/assets/js/admin.js",
"/public/assets/js/home.js": "/public/assets/js/home.js"
}
Binary file added public/assets/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ea5ada7

Please sign in to comment.