diff --git a/app/Http/Controllers/NoteController.php b/app/Http/Controllers/NoteController.php new file mode 100644 index 0000000..038b84d --- /dev/null +++ b/app/Http/Controllers/NoteController.php @@ -0,0 +1,124 @@ +validate([ + 'service_id' => 'required|string|size:8', + 'note' => 'required|string', + ]); + + try { + $note_id = Str::random(8); + + $a = Note::create([ + 'id' => $note_id, + 'service_id' => $request->service_id, + 'note' => $request->note + ]); + + } catch (\Exception $e) { + + if ($e->getCode() === "23000") { + $message = "A note already exists for this service"; + } else { + $message = "Error inserting note"; + } + + return redirect()->route('notes.create') + ->withInput($request->input())->with('error', $message); + } + + Cache::forget('all_notes'); + + return redirect()->route('notes.index') + ->with('success', 'Note created successfully.'); + } + + public function edit(Note $note) + { + $note = Note::note($note->service_id); + $servers = Server::all(); + $shareds = Shared::all(); + $resellers = Reseller::all(); + $domains = Domains::all(); + $dns = DNS::all(); + $ips = IPs::all(); + + return view('notes.edit', compact(['note', 'servers', 'shareds', 'resellers', 'domains', 'dns', 'ips'])); + } + + public function update(Request $request, Note $note) + { + $request->validate([ + 'service_id' => 'required|string|size:8', + 'note' => 'required|string' + ]); + + $note->update([ + 'service_id' => $request->service_id, + 'note' => $request->note + ]); + + Cache::forget('all_notes'); + Cache::forget("note.$note->service_id"); + + return redirect()->route('notes.index') + ->with('success', 'Note was updated successfully.'); + } + + public function show(Note $note) + { + $note = Note::note($note->service_id); + return view('notes.show', compact(['note'])); + } + + public function destroy(Note $note) + { + if ($note->delete()) { + Cache::forget("all_notes"); + Cache::forget("note.$note->service_id"); + + return redirect()->route('notes.index') + ->with('success', 'Note was deleted successfully.'); + } + + return redirect()->route('notes.index') + ->with('error', 'Note was not deleted.'); + + } + +} diff --git a/app/Models/DNS.php b/app/Models/DNS.php index 6cb1df2..ac52e82 100644 --- a/app/Models/DNS.php +++ b/app/Models/DNS.php @@ -25,4 +25,10 @@ class DNS extends Model return DB::table('d_n_s')->count(); }); } + + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/app/Models/Domains.php b/app/Models/Domains.php index 5172992..59127eb 100644 --- a/app/Models/Domains.php +++ b/app/Models/Domains.php @@ -56,4 +56,9 @@ class Domains extends Model return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); } + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/app/Models/IPs.php b/app/Models/IPs.php index 1dbb5eb..c5beddb 100644 --- a/app/Models/IPs.php +++ b/app/Models/IPs.php @@ -47,4 +47,9 @@ class IPs extends Model }); } + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/app/Models/Note.php b/app/Models/Note.php new file mode 100644 index 0000000..6ab7d6d --- /dev/null +++ b/app/Models/Note.php @@ -0,0 +1,66 @@ +addMonth(1), function () use ($service_id) { + return self::where('service_id', $service_id)->with(['server', 'shared', 'reseller', 'domain', 'dns', 'ip'])->first(); + }); + } + + public static function allNotes() + { + return Cache::remember("all_notes", now()->addMonth(1), function () { + return self::with(['server', 'shared', 'reseller', 'domain', 'dns', 'ip'])->orderBy('created_at', 'desc')->get(); + }); + } + + public function server(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Server::class, 'service_id', 'id'); + } + + public function shared(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Shared::class, 'service_id', 'id'); + } + + public function reseller(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Reseller::class, 'service_id', 'id'); + } + + public function domain(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Domains::class, 'service_id', 'id'); + } + + public function dns(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(DNS::class, 'service_id', 'id'); + } + + public function ip(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(IPs::class, 'service_id', 'id'); + } + +} diff --git a/app/Models/Reseller.php b/app/Models/Reseller.php index fb5c6c6..54c9d47 100644 --- a/app/Models/Reseller.php +++ b/app/Models/Reseller.php @@ -78,4 +78,9 @@ class Reseller extends Model return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); } + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/app/Models/Server.php b/app/Models/Server.php index 16ad201..e424358 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -234,4 +234,9 @@ class Server extends Model return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); } + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/app/Models/Shared.php b/app/Models/Shared.php index 3cca635..f26e86b 100644 --- a/app/Models/Shared.php +++ b/app/Models/Shared.php @@ -78,4 +78,9 @@ class Shared extends Model return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); } + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/resources/views/dns/show.blade.php b/resources/views/dns/show.blade.php index 57329e9..0d267e1 100644 --- a/resources/views/dns/show.blade.php +++ b/resources/views/dns/show.blade.php @@ -88,6 +88,12 @@ +
+ @if(isset($dns->note)) +

Note:

+

{{$dns->note->note}}

+ @endif +
diff --git a/resources/views/domains/show.blade.php b/resources/views/domains/show.blade.php index 883cc16..a4eda55 100644 --- a/resources/views/domains/show.blade.php +++ b/resources/views/domains/show.blade.php @@ -85,6 +85,12 @@ +
+ @if(isset($domain_info->note)) +

Note:

+

{{$domain_info->note->note}}

+ @endif +
{{ route('domains.index') }} diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index b7be5eb..871db2f 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -38,6 +38,7 @@
  • Providers
  • Seedboxes
  • YABS
  • +
  • Notes
  • Settings
  • Account
  • diff --git a/resources/views/notes/create.blade.php b/resources/views/notes/create.blade.php new file mode 100644 index 0000000..99f32d6 --- /dev/null +++ b/resources/views/notes/create.blade.php @@ -0,0 +1,67 @@ +@section("title", "Add a note") + + + {{ __('Create a note') }} + +
    + + + {{ route('notes.index') }} + Go back + + +
    + @csrf +
    +
    + +
    +
    +
    +

    This note is for:

    +
    +
    +
    Service
    +
    +
    +
    +
    +
    + Create note +
    +
    +
    +
    +
    +
    diff --git a/resources/views/notes/edit.blade.php b/resources/views/notes/edit.blade.php new file mode 100644 index 0000000..60f0196 --- /dev/null +++ b/resources/views/notes/edit.blade.php @@ -0,0 +1,74 @@ +@section("title", "Edit note") + + + {{ __('Edit note') }} + +
    + + + {{ route('notes.index') }} + Go back + + +
    + @csrf + @method('PUT') +
    +
    + +
    +
    +
    +

    This note is for:

    +
    +
    +
    Service
    +
    +
    +
    +
    +
    + Update note +
    +
    +
    +
    +
    +
    diff --git a/resources/views/notes/index.blade.php b/resources/views/notes/index.blade.php new file mode 100644 index 0000000..ba897e0 --- /dev/null +++ b/resources/views/notes/index.blade.php @@ -0,0 +1,90 @@ +@section('title', 'Notes') + + + {{ __('Notes') }} + +
    + + + Add a note + +
    + + + + + + + + + + + @if(!empty($notes[0])) + @foreach($notes as $n) + + + + + + + @endforeach + @else + + + + + + + @endif + +
    ServiceTypeNote PreviewActions
    + @if(!is_null($n->server)) + {{$n->server->hostname}} + @elseif(!is_null($n->shared)) + {{$n->shared->main_domain}} + @elseif(!is_null($n->reseller)) + {{$n->reseller->main_domain}} + @elseif(!is_null($n->domain)) + {{$n->domain->domain}}.{{$n->domain->extension}} + @elseif(!is_null($n->dns)) + {{$n->dns->dns_type}} {{$n->dns->hostname}} + @elseif(!is_null($n->ip)) + {{$n->ip->address}} + @endif + + @if(!is_null($n->server)) + SERVER + @elseif(!is_null($n->shared)) + SHARED + @elseif(!is_null($n->reseller)) + RESELLER + @elseif(!is_null($n->domain)) + DOMAIN + @elseif(!is_null($n->dns)) + DNS + @elseif(!is_null($n->ip)) + IP + @endif + {{strlen($n->note) > 80 ? substr($n->note,0,80)."…" : $n->note}} +
    + + + + + @csrf + @method('DELETE') + note}}"> +
    +
    No notes found.
    +
    +
    + +
    + + notes + +
    diff --git a/resources/views/notes/show.blade.php b/resources/views/notes/show.blade.php new file mode 100644 index 0000000..e1a1b69 --- /dev/null +++ b/resources/views/notes/show.blade.php @@ -0,0 +1,40 @@ +@section("title", "Note $note->id") + + + {{ __('Note') }} + +
    + +
    +
    +

    + @if(!is_null($note->server)) + {{$note->server->hostname}} (server) + @elseif(!is_null($note->shared)) + {{$note->shared->main_domain}} (shared) + @elseif(!is_null($note->reseller)) + {{$note->reseller->main_domain}} (reseller) + @elseif(!is_null($note->domain)) + {{$note->domain->domain}}.{{$note->domain->extension}} (domain) + @elseif(!is_null($note->dns)) + {{$note->dns->dns_type}} {{$note->dns->hostname}} (DNS) + @elseif(!is_null($note->ip)) + {{$note->ip->address}} (IP) + @endif +

    +
    +
    +
    +
    + {{$note->note}} +
    +
    + + {{ route('notes.index') }} + + + {{ route('notes.edit', $note->id) }} + +
    +
    +
    diff --git a/resources/views/reseller/show.blade.php b/resources/views/reseller/show.blade.php index 7f2b590..74e0a8d 100644 --- a/resources/views/reseller/show.blade.php +++ b/resources/views/reseller/show.blade.php @@ -133,6 +133,12 @@ FTP Limit {{$reseller->ftp_limit}} + @if(isset($reseller->note)) + + Note: + {{$reseller->note->note}} + + @endif diff --git a/resources/views/servers/show.blade.php b/resources/views/servers/show.blade.php index bb75ebd..e6afdf0 100644 --- a/resources/views/servers/show.blade.php +++ b/resources/views/servers/show.blade.php @@ -210,6 +210,10 @@ @endif

    curl -sL yabs.sh | bash -s -- -s "{{route('api.store-yabs', [$server_data->id, \Illuminate\Support\Facades\Auth::user()->api_token])}}"

    + @if(isset($server_data->note)) +

    Note:

    +

    {{$server_data->note->note}}

    + @endif diff --git a/resources/views/shared/show.blade.php b/resources/views/shared/show.blade.php index c228262..f15f4ac 100644 --- a/resources/views/shared/show.blade.php +++ b/resources/views/shared/show.blade.php @@ -20,7 +20,7 @@
    -
    +
    @@ -97,7 +97,7 @@
    -
    +
    @@ -128,6 +128,12 @@ + @if(isset($shared->note)) + + + + + @endif
    FTP Limit {{$shared->ftp_limit}}
    Note:{{$shared->note->note}}
    diff --git a/routes/web.php b/routes/web.php index f8cbf3f..e02dbf0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -7,6 +7,7 @@ use App\Http\Controllers\IPsController; use App\Http\Controllers\LabelsController; use App\Http\Controllers\LocationsController; use App\Http\Controllers\MiscController; +use App\Http\Controllers\NoteController; use App\Http\Controllers\OsController; use App\Http\Controllers\ProvidersController; use App\Http\Controllers\ResellerController; @@ -64,6 +65,8 @@ Route::resource('shared', SharedController::class)->middleware(['auth']); Route::resource('yabs', YabsController::class)->middleware(['auth']); +Route::resource('notes', NoteController::class)->middleware(['auth']); + Route::get('yabs/{yab}/json', 'App\Http\Controllers\YabsController@yabsToJson')->middleware(['auth'])->name('yabs.json'); Route::get('yabs-compare-choose', 'App\Http\Controllers\YabsController@chooseYabsCompare')->middleware(['auth'])->name('yabs.compare-choose');