diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 0109c2a..3624743 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -13,6 +13,11 @@ use App\Models\{Address,Domain,Echomail,Setup}; class HomeController extends Controller { + public function home() + { + return redirect(Auth::check() ? 'dashboard' : 'about'); + } + public function network(Domain $o) { if (! $o->public && ! Gate::check('admin',$o)) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index aa1530c..3377868 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -9,11 +9,6 @@ use App\Models\User; class UserController extends Controller { - public function __construct() - { - $this->middleware('can:admin'); - } - /** * Add or edit a node */ @@ -53,6 +48,11 @@ class UserController extends Controller ->with('o',$o); } + public function dashboard() + { + return view('dashboard'); + } + public function home() { return view('user.home'); diff --git a/app/Models/Domain.php b/app/Models/Domain.php index db8f5f2..746eb66 100644 --- a/app/Models/Domain.php +++ b/app/Models/Domain.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Collection; use App\Traits\ScopeActive; @@ -49,4 +50,32 @@ class Domain extends Model { $this->attributes['homepage'] = base64_encode(gzcompress($value,9)); } + + /* METHODS */ + + public function stats(System $o=NULL): Collection + { + if (! $this->echoareas->count()) + return collect(); + + $where = collect(['echoarea_id'=>$this->echoareas->pluck('id')->toArray()]); + + if ($o) + $where->put('fftn_id',$o->addresses()->pluck('id')); + + $echostats = Echomail::countGroupBy('echoarea_id',$where->toArray()); + + return $this->echoareas->map(function($item) use ($echostats) { + $stats = $echostats->filter(function($x) use ($item) { + return $x->id->echoarea_id == $item->id; + }); + + $item->count = 0; + + foreach ($stats as $o) + $item->count += $o->count; + + return $item; + }); + } } \ No newline at end of file diff --git a/app/Models/User.php b/app/Models/User.php index 55dc333..88708e6 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -60,6 +60,13 @@ class User extends Authenticatable implements MustVerifyEmail protected $dates = ['last_on']; + /* RELATIONS */ + + public function systems() + { + return $this->belongsToMany(System::class); + } + /* GENERAL METHODS */ /** diff --git a/app/Traits/UseMongo.php b/app/Traits/UseMongo.php index eb78739..ca44bb7 100644 --- a/app/Traits/UseMongo.php +++ b/app/Traits/UseMongo.php @@ -5,6 +5,8 @@ */ namespace App\Traits; +use Illuminate\Database\Eloquent\Collection; + trait UseMongo { /** @@ -40,4 +42,41 @@ trait UseMongo { $this->attributes['subject'] = utf8_encode($value); } + + /* METHODS */ + + public static function countGroupBy(string $field,array $where=[]): Collection + { + $query = collect(); + + if (count($where)) { + $where_condition = []; + + foreach ($where as $key => $values) { + if (! is_array($values)) + throw new \Exception('Where values must be an array.'); + + $where_condition[$key] = ['$in' => $values]; + } + + $query->push([ + '$match' => $where_condition + ]); + } + + $query->push([ + '$group' => [ + '_id' => [$field=>'$'.$field], + 'count' => ['$sum' => 1] + ] + ]); + + return (new self) + ->groupBy($field) + ->raw(function($collection) use ($query) { + return $collection->aggregate( + $query->toArray() + ); + }); + } } \ No newline at end of file diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php new file mode 100644 index 0000000..ea58eec --- /dev/null +++ b/resources/views/dashboard.blade.php @@ -0,0 +1,220 @@ +@extends('layouts.app') +@section('htmlheader_title') + Dashboard +@endsection + +@section('content') +

{{ $user->name }}

+ +
+ @if($user->systems->count()) +
+
+
+ + +
+
+
+ + + + + + @foreach ($user->systems as $o) + + + + + @endforeach + +
System Addresses
{{ $o->name }}{!! $o->addresses->pluck('ftn')->join('
') !!}
+
+
+ +
+
+ + + + + + @foreach ($user->systems as $o) + + + + + @endforeach + +
Available Echos
{{ $o->name }}{!! $o->addresses->pluck('zone.domain.echoareas')->flatten()->pluck('name')->unique()->sort()->join(', ') !!}
+
+
+
+ @else +

You are not linked to any BBS systems.

+ @endif +
+@endsection + +@section('page-scripts') + + + + + + + + + + +@append \ No newline at end of file diff --git a/resources/views/layouts/partials/topmenu.blade.php b/resources/views/layouts/partials/topmenu.blade.php index c381a00..e9a7012 100644 --- a/resources/views/layouts/partials/topmenu.blade.php +++ b/resources/views/layouts/partials/topmenu.blade.php @@ -2,7 +2,7 @@

{{ $title ?? config('app.name') }}