Skip to content

Commit

Permalink
adds sathi and activity for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitkataria authored and fristonio committed Feb 7, 2018
1 parent e7b6c7a commit e66bbcd
Show file tree
Hide file tree
Showing 8 changed files with 447 additions and 134 deletions.
306 changes: 172 additions & 134 deletions central-server/app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,185 +13,223 @@

class UserController extends Controller
{


function index()
{
dd($this->userList());
}

function registerMAC(Request $request)
{
$user = Auth::user();
$data = $request->all();
function registerMAC(Request $request)
{
$user = Auth::user();
$data = $request->all();

if($user == null)
abort(401, 'Unautorized');
if($user == null)
abort(401, 'Unautorized');

$validator = Validator::make($data, [
'mac_address' => 'required|regex:/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/',
'image' => 'required|image'
]);
$validator = Validator::make($data, [
'mac_address' => 'required|regex:/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/',
'image' => 'required|image'
]);

if($validator->fails()){
dd($validator);
return view('dashboard', ['user'=> $user, 'error' => 'Incorrect Format', 'message'=>'']);
if($validator->fails()){
return view('dashboard', ['user'=> $user, 'error' => 'Incorrect Format', 'message'=>'']);
}
$user->mac_address = $data['mac_address'];
$file = Input::file('image');
$user->profile_pic = $file->getClientOriginalName();
$user->mac_address = $data['mac_address'];
$file = Input::file('image');
$user->profile_pic = $file->getClientOriginalName();
$file->move(public_path().'/uploads', $file->getClientOriginalName());
$user->save();
$user->save();

return view('dashboard', ['user'=> $user, 'error' => '', 'message'=>'Successful']);
}
return view('dashboard', ['user'=> $user, 'error' => '', 'message'=>'Successful']);
}

function barGraph()
{
$user = Auth::user();
function barGraph()
{
$user = Auth::user();

if($user == null)
abort(401,'Unautorized');
if($user == null)
abort(401,'Unautorized');

$all = json_decode($this->parseGraph($user->id));
$data = $all[0];
$date = $all[1];
$total = $all[2];
$all = json_decode($this->parseGraph($user->id));
$data = $all[0];
$date = $all[1];
$total = $all[2];

return view('dashboard_bar', ['total' => $total, 'data' => $data, 'date' => $date, 'message' => '', 'error' => '']);
}
return view('dashboard_bar', ['total' => $total, 'data' => $data, 'date' => $date, 'message' => '', 'error' => '']);
}

function lineGraph()
{
$user = Auth::user();
function lineGraph()
{
$user = Auth::user();

if($user == null)
abort(401,'Unautorized');
if($user == null)
abort(401,'Unautorized');

$all = json_decode($this->parseGraph($user->id));
$data = $all[0];
$date = $all[1];
$total = $all[2];
$all = json_decode($this->parseGraph($user->id));
$data = $all[0];
$date = $all[1];
$total = $all[2];

return view('dashboard_line', ['total' => $total, 'data' => $data, 'date' => $date, 'message' => '', 'error' => '']);
}
return view('dashboard_line', ['total' => $total, 'data' => $data, 'date' => $date, 'message' => '', 'error' => '']);
}

function pieGraph()
{
$user = Auth::user();
function pieGraph()
{
$user = Auth::user();

if($user == null)
abort(401,'Unautorized');
if($user == null)
abort(401,'Unautorized');

$all = json_decode($this->parseGraph($user->id));
$data = $all[0];
$date = $all[1];
$total = $all[2];
$all = json_decode($this->parseGraph($user->id));
$data = $all[0];
$date = $all[1];
$total = $all[2];

return view('dashboard_pie', ['total' => $total, 'data' => $data, 'date' => $date, 'message' => '', 'error' => '']);
}
return view('dashboard_pie', ['total' => $total, 'data' => $data, 'date' => $date, 'message' => '', 'error' => '']);
}

function image(Request $request)
{
$data = $request->all();
$email = $data['email'];
function image(Request $request)
{
$data = $request->all();
$email = $data['email'];

$user = User::where('email',$email)->first();
$user = User::where('email',$email)->first();

if($user === null)
abort(404, "Not found");
if($user === null)
abort(404, "Not found");

if(!$user->profile_pic)
abort(404, "Not found");
if(!$user->profile_pic)
abort(404, "Not found");

return json_encode(['image' => $user->profile_pic]);
}
return json_encode(['image' => $user->profile_pic]);
}

function leaderboard()
{
$orders = DB::table('logs')
->select('logs.mac_address', DB::raw('COUNT(*) as minutes'))
->groupBy('mac_address')
->limit(10)
->get()
->sortBy(function($log) {
return $log->minutes;
})->reverse();

return json_encode($this->getUsernames($orders));

}

function allOnline()
{
$recent = Carbon::now('Asia/Kolkata')->subMinutes(500);
$online = Log::where('timestamp','>', $recent)->get();

function leaderboard()
return json_encode($this->getUsernames($online));
}

function getUsernames($orders)
{
$macs = array();
foreach($orders as $order)
{
$orders = DB::table('logs')
->select('logs.mac_address', DB::raw('COUNT(*) as minutes'))
->groupBy('mac_address')
->limit(10)
->get()
->sortBy(function($log) {
return $log->minutes;
})->reverse();

return json_encode($this->getUsernames($orders));

array_push($macs,$order->mac_address);
}

function allOnline()
{
$recent = Carbon::now('Asia/Kolkata')->subMinutes(5);
$online = Log::where('timestamp','>', $recent)->get();
$userNames = User::whereIn('mac_address', $macs)->get();

foreach($orders as $order)
{
foreach($userNames as $user)
{
$userNames = User::whereIn('mac_address',$macs)->get();

if($user->mac_address == $order->mac_address)
{
$order->username = $user->username;
$order->name = $user->name;
$order->id = $user->id;
break;
}
else
$order->username = "Not Registered";

}
}

return ($orders);
}

function parseGraph($id)
{
$user = User::where('id',$id)->first();
$data = $user->hoursActiveInAWeek(Carbon::today('Asia/Kolkata'));
$date = $user->daysOfAWeek();

return json_encode($this->getUsernames($online));
$total = 0;
foreach( $data as $time){
$total += $time;
}

function getUsernames($orders)
return json_encode([$data,$date,$total]);
}

function userList()
{
$users = User::get();

$json = array();

foreach($users as $user)
{
$temp = [];
$temp['id'] = $user->id;
$temp['username'] = $user->username;
$temp['name'] = $user->name;
array_push($json, $temp);
}

$macs = array();
return (json_encode($json));
}

foreach($orders as $order)
{
array_push($macs,$order->mac_address);
}
function adminIndex()
{
$this->check_admin();

$userNames = User::whereIn('mac_address', $macs)->get();
$allOnline = json_decode($this->allOnline());

foreach($orders as $order)
{
foreach($userNames as $user)
{
$userNames = User::whereIn('mac_address',$macs)->get();

if($user->mac_address == $order->mac_address)
{
$order->username = $user->username;
$order->name = $user->name;
break;
}
else
$order->username = "Not Registered";

}
}

return ($orders);
}
$leaderboard = json_decode($this->leaderboard());

function parseGraph($id)
{
$user = User::where('id',$id)->first();
$data = $user->hoursActiveInAWeek(Carbon::today('Asia/Kolkata'));
$date = $user->daysOfAWeek();
// dd($leaderboard);
return view('admin',['message'=>'','error'=>'', 'allOnline' => $allOnline, 'leaderboard' => $leaderboard]);
}

$total = 0;
foreach( $data as $time){
$total += $time;
}
function adminLine()
{
$this->check_admin();
$leaderboard = json_decode($this->leaderboard());

return json_encode([$data,$date,$total]);
}
return view('admin_line', ['message'=>'', 'error'=>'']);

function userList()
{
$users = User::get();
}

$json = array();
function check_admin()
{
$user = Auth::user();

foreach($users as $user)
{
$temp = [];
$temp['id'] = $user->id;
$temp['username'] = $user->username;
$temp['name'] = $user->name;
array_push($json, $temp);
}
if($user === null)
return redirect('/dashboard');

if($user->role !== 'admin')
abort(401, "Unauthorized Entry");

return;
}

function sathi()
{
$this->check_admin();
return view('admin_sathi',['message'=>'','error'=>'']);
}

return (json_encode($json));
}
}
19 changes: 19 additions & 0 deletions central-server/public/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,22 @@ main {
padding-right: 0.5rem;
font-size: 2.0rem;
}

.super-table-wrapper {
justify-content: space-around;
display: flex;
}

.admin-table-head {
text-align: center;
font-size: 1.4rem;
font-family: 'Ubuntu', sans-serif ;
margin-bottom: 2rem;
}

.admin-table td, .admin-table th{
padding: 1rem 1.2rem !important;
font-family: 'Ubuntu', sans-serif;
text-align: center;

}
Loading

0 comments on commit e66bbcd

Please sign in to comment.