From 271f0666678ca7798cfe3b9baab291c9bfd5a8dd Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 29 Aug 2021 11:48:27 +1000 Subject: [PATCH] Added echomail search and display --- app/Http/Controllers/EchomailController.php | 19 +++++++++ app/Http/Controllers/HomeController.php | 12 +++++- app/Models/Address.php | 5 +++ app/Models/Echomail.php | 13 +++++++ resources/views/echomail/view.blade.php | 7 ++++ resources/views/widgets/message.blade.php | 43 +++++++++++++++++++++ routes/web.php | 2 + 7 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/EchomailController.php create mode 100644 resources/views/echomail/view.blade.php create mode 100644 resources/views/widgets/message.blade.php diff --git a/app/Http/Controllers/EchomailController.php b/app/Http/Controllers/EchomailController.php new file mode 100644 index 0000000..74d92d4 --- /dev/null +++ b/app/Http/Controllers/EchomailController.php @@ -0,0 +1,19 @@ +middleware('auth'); + } + + public function view(Echomail $o) + { + return view('echomail.view') + ->with('o',$o); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index ab0be4f..0109c2a 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -9,7 +9,7 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Gate; use App\Classes\FTN\Packet; -use App\Models\{Address,Domain,Setup}; +use App\Models\{Address,Domain,Echomail,Setup}; class HomeController extends Controller { @@ -86,7 +86,7 @@ class HomeController extends Controller list($zone_id,$host_id,$node_id,$point_id,$domain) = sscanf($request->query('term'),'%d:%d/%d.%d@%s'); - # Look for Opportunities + # Look for Systems foreach (Address::select(['systems.name',DB::raw('systems.id AS system_id'),'zones.zone_id','region_id','host_id','node_id','point_id']) ->join('zones',['zones.id'=>'addresses.zone_id']) ->rightjoin('systems',['systems.id'=>'addresses.system_id']) @@ -113,6 +113,14 @@ class HomeController extends Controller $result->push(['id'=>$o->system_id,'name'=>$o->name.($ftn ? ' '.$ftn : ''),'value'=>url('ftn/system/addedit',[$o->system_id]),'category'=>'Systems']); } + # Look for Messages + foreach (Echomail::select(['id','fftn_id','from']) + ->where('msgid','like','%'.$request->query('term').'%') + ->get() as $o) + { + $result->push(['id'=>$o->id,'name'=>sprintf('%s (%s)',$o->from,$o->fftn->ftn3d),'value'=>url('echomail/view',[$o->id]),'category'=>'Echomail']); + } + return $result->unique(['id'])->take(10)->values(); } diff --git a/app/Models/Address.php b/app/Models/Address.php index 620d943..25f4292 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -207,6 +207,11 @@ class Address extends Model return sprintf('%s@%s',$this->getFTN4DAttribute(),$this->zone->domain->name); } + public function getFTN2DAttribute(): string + { + return sprintf('%d/%d',$this->host_id ?: $this->region_id,$this->node_id); + } + public function getFTN3DAttribute(): string { return sprintf('%d:%d/%d',$this->zone->zone_id,$this->host_id ?: $this->region_id,$this->node_id); diff --git a/app/Models/Echomail.php b/app/Models/Echomail.php index 2beb78a..48ed781 100644 --- a/app/Models/Echomail.php +++ b/app/Models/Echomail.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Support\Collection; use Jenssegers\Mongodb\Eloquent\Model; use Jenssegers\Mongodb\Eloquent\SoftDeletes; @@ -32,6 +33,18 @@ class Echomail extends Model implements Packet ->withTrashed(); } + /* ATTRIBUTES */ + + public function getPathAttribute($value): Collection + { + return Address::whereIn('id',$value)->get()->pluck('ftn3d'); + } + + public function getSeenByAttribute($value): Collection + { + return Address::whereIn('id',$value)->get()->pluck('ftn2d'); + } + /* METHODS */ public function jsonSerialize(): array diff --git a/resources/views/echomail/view.blade.php b/resources/views/echomail/view.blade.php new file mode 100644 index 0000000..d431369 --- /dev/null +++ b/resources/views/echomail/view.blade.php @@ -0,0 +1,7 @@ +@extends('layouts.app') + +@section('content') +

Echomail

+ + @include('widgets.message',['msg'=>$o]) +@endsection \ No newline at end of file diff --git a/resources/views/widgets/message.blade.php b/resources/views/widgets/message.blade.php new file mode 100644 index 0000000..155e28f --- /dev/null +++ b/resources/views/widgets/message.blade.php @@ -0,0 +1,43 @@ +
+
+ DATE: {{ $msg->datetime->format('Y-m-d H:i:s') }} +
+
+ MSGID: {{ $msg->msgid }}@if($x=\App\Models\Echomail::where('reply',$msg->msgid)->count()) ({{$x}} replies)@endif @if($msg->reply)
REPLY: {{ $msg->reply }}@endif +
+
+ +
+
+ FROM: {{ $msg->from }} ({{ $msg->fftn->ftn }}) +
+
+ TO: {{ $msg->to }} +
+
+ +
+
+ SUBJECT: {!! \App\Classes\FTN\Message::tr($msg->subject) !!} +
+
+ +
+
+
+
{!! \App\Classes\FTN\Message::tr($msg->msg).($msg->origin ? sprintf("\r * Origin: %s",$msg->origin) : '') !!}
+
+
+
+ +
+
+ SEENBY:
{!! $msg->seenby->join(', ') !!} +
+
+ +
+
+ PATH:
{!! $msg->path->join(' -> ') !!} +
+
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 8f6520a..d555c2e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\{HomeController, DomainController, EchoareaController, + EchomailController, FileareaController, SystemController, UserController, @@ -83,6 +84,7 @@ Route::get('search',[HomeController::class,'search']); Route::middleware(['auth','can:admin'])->group(function () { Route::match(['get','post'],'setup',[HomeController::class,'setup']); + Route::get('echomail/view/{o}',[EchomailController::class,'view']); Route::get('user/list',[UserController::class,'home']); Route::match(['get','post'],'user/addedit/{o?}',[UserController::class,'add_edit']) ->where('o','[0-9]+');