Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
lanhktc committed Aug 28, 2019
1 parent cdc0ff8 commit b1ddd1c
Show file tree
Hide file tree
Showing 7,788 changed files with 789,609 additions and 18,136 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
10 changes: 9 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
PAYPAL_CLIENT_ID=
PAYPAL_SECRET=

ADMIN_ROUTE_PREFIX=system_admin
ADMIN_ROUTE_PREFIX=sc_admin

FILESYSTEM_DRIVER=public

MAIL_HOST=
MAIL_PORT=
MAIL_ENCRYPTION=
MAIL_USERNAME=
MAIL_PASSWORD=
32 changes: 32 additions & 0 deletions app/Admin/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Admin;

use App\Admin\Models\AdminMenu;
use Illuminate\Support\Facades\Auth;

/**
* Class Admin.
*/
class Admin
{

public static function user()
{
return Auth::guard('admin')->user();
}

public static function isLoginPage()
{
return (request()->route()->getName() == 'admin.login');
}

public static function isLogoutPage()
{
return (request()->route()->getName() == 'admin.logout');
}
public static function getMenu()
{
return AdminMenu::getList();
}
}
128 changes: 128 additions & 0 deletions app/Admin/Controllers/AdminConfigController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
#app/Http/Admin/Controllers/AdminConfigController.php
namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\AdminConfig;
use Illuminate\Http\Request;
use Validator;

class AdminConfigController extends Controller
{

public function index()
{

$data = [
'title' => trans('config.admin.list'),
'sub_title' => '',
'icon' => 'fa fa-indent',
'menu_left' => '',
'menu_right' => '',
'menu_sort' => '',
'script_sort' => '',
'menu_search' => '',
'script_search' => '',
'listTh' => '',
'dataTr' => '',
'pagination' => '',
'result_items' => '',
'url_delete_item' => '',
];

$obj = (new AdminConfig)->whereIn('code', ['config', 'display'])->orderBy('sort', 'desc')->get()->groupBy('code');
$data['configs'] = $obj;
//menu_right
$data['menu_right'] = '<div class="btn-group pull-right" style="margin-right: 10px">
<a href="' . route('admin_config.create') . '" class="btn btn-success btn-flat" title="New" id="button_create_new">
<i class="fa fa-plus"></i><span class="hidden-xs">' . trans('config.admin.add_new') . '</span>
</a>
</div>';
//=menu_right

return view('admin.screen.config')
->with($data);
}

/**
* Form create new order in admin
* @return [type] [description]
*/
public function create()
{
$data = [
'title' => trans('config.admin.add_new_title'),
'sub_title' => '',
'title_description' => trans('config.admin.add_new_des'),
'icon' => 'fa fa-plus',
];
return view('admin.screen.config_add')
->with($data);
}

/**
* Post create new order in admin
* @return [type] [description]
*/
public function postCreate()
{
$data = request()->all();
$dataOrigin = request()->all();
$validator = Validator::make($dataOrigin, [
'image' => 'image | max: ' . sc_config('upload_image_size', 2048),
'sort' => 'numeric|min:0',
'name' => 'required|string|max:100',
'url' => 'url|nullable',
]);

if ($validator->fails()) {
return redirect()->back()
->withErrors($validator)
->withInput();
}
$dataInsert = [
'image' => $data['image'],
'name' => $data['name'],
'url' => $data['url'],
'sort' => (int) $data['sort'],
];
$id = AdminConfig::insertGetId($dataInsert);

return redirect()->route('admin_config.index')->with('success', trans('config.admin.create_success'));

}

/*
Update value config
*/
public function updateInfo()
{
$stt = 0;
$data = request()->all();
$name = $data['name'];
$value = $data['value'];
$update = AdminConfig::where('key', $name)->update(['value' => $value]);
if ($update) {
$stt = 1;
}
return response()->json(['stt' => $stt]);

}

/*
Delete list item
Need mothod destroy to boot deleting in model
*/
public function deleteList()
{
if (!request()->ajax()) {
return response()->json(['error' => 1, 'msg' => 'Method not allow!']);
} else {
$ids = request('ids');
$arrID = explode(',', $ids);
AdminConfig::destroy($arrID);
return response()->json(['stt' => 1, 'msg' => '']);
}
}

}
158 changes: 158 additions & 0 deletions app/Admin/Controllers/AdminLogController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php
#app/Http/Admin/Controllers/AdminLogController.php
namespace App\Admin\Controllers;

use App\Admin\Models\AdminLog;
use App\Admin\Models\AdminUser;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class AdminLogController extends Controller
{

public function index()
{

$data = [
'title' => trans('log.admin.list'),
'sub_title' => '',
'icon' => 'fa fa-indent',
'menu_left' => '',
'menu_right' => '',
'menu_sort' => '',
'script_sort' => '',
'menu_search' => '',
'script_search' => '',
'listTh' => '',
'dataTr' => '',
'pagination' => '',
'result_items' => '',
'url_delete_item' => '',
];

$listTh = [
'check_row' => '',
'id' => trans('log.id'),
'user' => trans('log.user'),
'method' => trans('log.method'),
'path' => trans('log.path'),
'ip' => trans('log.ip'),
'user_agent' => trans('log.user_agent'),
'input' => trans('log.input'),
'created_at' => trans('log.created_at'),
'action' => trans('log.admin.action'),
];

$sort_order = request('sort_order') ?? 'id_desc';
$keyword = request('keyword') ?? '';
$arrSort = [
'id__desc' => trans('log.admin.sort_order.id_desc'),
'id__asc' => trans('log.admin.sort_order.id_asc'),
'user_id__desc' => trans('log.admin.sort_order.user_id_desc'),
'user_id__asc' => trans('log.admin.sort_order.user_id_asc'),
'path__desc' => trans('log.admin.sort_order.path_desc'),
'path__asc' => trans('log.admin.sort_order.path_asc'),
'user_agent__desc' => trans('log.admin.sort_order.user_agent_desc'),
'user_agent__asc' => trans('log.admin.sort_order.user_agent_asc'),
'method__desc' => trans('log.admin.sort_order.method_desc'),
'method__asc' => trans('log.admin.sort_order.method_asc'),
'ip__desc' => trans('log.admin.sort_order.ip_desc'),
'ip__asc' => trans('log.admin.sort_order.ip_asc'),

];
$obj = new AdminLog;

if ($sort_order && array_key_exists($sort_order, $arrSort)) {
$field = explode('__', $sort_order)[0];
$sort_field = explode('__', $sort_order)[1];
$obj = $obj->orderBy($field, $sort_field);

} else {
$obj = $obj->orderBy('id', 'desc');
}
$dataTmp = $obj->paginate(20);

$dataTr = [];
foreach ($dataTmp as $key => $row) {
$dataTr[] = [
'check_row' => '<input type="checkbox" class="grid-row-checkbox" data-id="' . $row['id'] . '">',
'id' => $row['id'],
'user_id' => ($user = AdminUser::find($row['user_id'])) ? $user->name : 'N/A',
'method' => '<span class="badge bg-' . (AdminLog::$methodColors[$row['method']] ?? '') . '">' . $row['method'] . '</span>',
'path' => '<code>' . $row['path'] . '</code>',
'ip' => $row['ip'],
'user_agent' => $row['user_agent'],
'input' => $row['input'],
'created_at' => $row['created_at'],
'action' => '
<span onclick="deleteItem(' . $row['id'] . ');" title="' . trans('log.admin.delete') . '" class="btn btn-flat btn-danger"><i class="fa fa-trash"></i></span>
',
];
}

$data['listTh'] = $listTh;
$data['dataTr'] = $dataTr;
$data['pagination'] = $dataTmp->appends(request()->except(['_token', '_pjax']))->links('admin.component.pagination');
$data['result_items'] = trans('log.admin.result_item', ['item_from' => $dataTmp->firstItem(), 'item_to' => $dataTmp->lastItem(), 'item_total' => $dataTmp->total()]);

//menu_left
$data['menu_left'] = '<div class="pull-left">
<a class="btn btn-flat btn-danger grid-trash" title="Delete"><i class="fa fa-trash-o"></i><span class="hidden-xs"> ' . trans('admin.delete') . '</span></a> &nbsp;
<a class="btn btn-flat btn-primary grid-refresh" title="Refresh"><i class="fa fa-refresh"></i><span class="hidden-xs"> ' . trans('log.admin.refresh') . '</span></a> &nbsp;
</div>';
//=menu_left

//menu_sort

$optionSort = '';
foreach ($arrSort as $key => $status) {
$optionSort .= '<option ' . (($sort_order == $key) ? "selected" : "") . ' value="' . $key . '">' . $status . '</option>';
}

$data['menu_sort'] = '
<div class="btn-group pull-left">
<div class="form-group">
<select class="form-control" id="order_sort">
' . $optionSort . '
</select>
</div>
</div>
<div class="btn-group pull-left">
<a class="btn btn-flat btn-primary" title="Sort" id="button_sort">
<i class="fa fa-sort-amount-asc"></i><span class="hidden-xs"> ' . trans('admin.sort') . '</span>
</a>
</div>';

$data['script_sort'] = "$('#button_sort').click(function(event) {
var url = '" . route('admin_log.index') . "?sort_order='+$('#order_sort option:selected').val();
$.pjax({url: url, container: '#pjax-container'})
});";

//=menu_sort

$data['url_delete_item'] = route('admin_log.delete');

return view('admin.screen.list')
->with($data);
}

/*
Delete list item
Need mothod destroy to boot deleting in model
*/
public function deleteList()
{
if (!request()->ajax()) {
return response()->json(['error' => 1, 'msg' => 'Method not allow!']);
} else {
$ids = request('ids');
$arrID = explode(',', $ids);
AdminLog::destroy($arrID);
return response()->json(['error' => 0, 'msg' => '']);
}
}

}
Loading

0 comments on commit b1ddd1c

Please sign in to comment.