Compare commits

..

No commits in common. "1c410ce074ffdf46aa1773424d844bdf913d171e" and "b2dd20a624fb38581ca27f63ee0bed5c1234189c" have entirely different histories.

11 changed files with 34 additions and 150 deletions

View File

@ -15,7 +15,7 @@ class BookmarkController extends Controller
{
return view(
'bookmarks.index', [
'bookmarks' => Bookmark::orderByDesc('created_at')->paginate(20),
'bookmarks' => Bookmark::paginate(20),
]
);
}
@ -25,7 +25,7 @@ class BookmarkController extends Controller
*/
public function create()
{
return view('bookmarks.edit', ['bookmark' => null]);
//
}
/**
@ -33,19 +33,7 @@ class BookmarkController extends Controller
*/
public function store(Request $request)
{
$bookmark = new Bookmark;
$bookmark->title = $request->post('title');
$bookmark->description = $request->post('description', '');
$bookmark->href = $request->post('href');
$bookmark->save();
$bookmark->syncTagsFromString($request->post('tags', ''));
return redirect()->action(
[self::class, "show"], [
"bookmark" => $bookmark,
]
);
//
}
/**
@ -67,6 +55,7 @@ class BookmarkController extends Controller
{
return view(
'bookmarks.edit', [
'edit' => true,
'bookmark' => $bookmark,
]
);
@ -82,7 +71,16 @@ class BookmarkController extends Controller
$bookmark->href = $request->post('href');
$bookmark->save();
$bookmark->syncTagsFromString($request->post('tags', ''));
$tags_input = trim($request->post('tags', ''));
$tags_input = preg_split('/\s+/', $tags_input);
$tags = [];
foreach ($tags_input as $tag_input) {
$tag = Tag::firstOrCreate(['name' => $tag_input]);
$tags[$tag->id] = true;
}
$bookmark->tags()->sync(array_keys($tags));
return redirect()->action(
[self::class, "show"], [

View File

@ -2,7 +2,6 @@
namespace App\Http\Controllers;
use App\Models\Bookmark;
use App\Models\Tag;
use Illuminate\Http\Request;
@ -37,13 +36,7 @@ class TagController extends Controller
*/
public function show(Tag $tag)
{
return view(
'tag.show', [
'tag' => $tag,
'tag_count' => $tag->bookmarks()->count(),
'bookmarks' => $tag->bookmarks()->latest()->paginate(20),
]
);
return view('tag.show', [ 'tag' => $tag, ]);
}
/**

View File

@ -13,22 +13,6 @@ class Bookmark extends Model
protected $table = 'bookmarks';
protected $with = ['tags'];
public function syncTagsFromString(string $tags_string): array
{
$tags_input = trim($tags_string);
$tags_input = preg_split('/\s+/', $tags_input);
$tags = [];
foreach ($tags_input as $tag_input) {
$tag = Tag::firstOrCreate(['name' => $tag_input]);
$tags[$tag->id] = true;
}
return $this->tags()->sync(array_keys($tags));
}
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class);

View File

@ -10,6 +10,8 @@ class BookmarkTag extends Pivot
{
use HasFactory;
protected $table = 'bookmarks_tags';
public function parent()
{
return $this->belongsTo(Bookmark::class, 'bookmark_id');

View File

@ -1,70 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Get the migration connection name.
*/
public function getConnection(): ?string
{
return config('telescope.storage.database.connection');
}
/**
* Run the migrations.
*/
public function up(): void
{
$schema = Schema::connection($this->getConnection());
$schema->create('telescope_entries', function (Blueprint $table) {
$table->bigIncrements('sequence');
$table->uuid('uuid');
$table->uuid('batch_id');
$table->string('family_hash')->nullable();
$table->boolean('should_display_on_index')->default(true);
$table->string('type', 20);
$table->longText('content');
$table->dateTime('created_at')->nullable();
$table->unique('uuid');
$table->index('batch_id');
$table->index('family_hash');
$table->index('created_at');
$table->index(['type', 'should_display_on_index']);
});
$schema->create('telescope_entries_tags', function (Blueprint $table) {
$table->uuid('entry_uuid');
$table->string('tag');
$table->primary(['entry_uuid', 'tag']);
$table->index('tag');
$table->foreign('entry_uuid')
->references('uuid')
->on('telescope_entries')
->onDelete('cascade');
});
$schema->create('telescope_monitoring', function (Blueprint $table) {
$table->string('tag')->primary();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
$schema = Schema::connection($this->getConnection());
$schema->dropIfExists('telescope_entries_tags');
$schema->dropIfExists('telescope_entries');
$schema->dropIfExists('telescope_monitoring');
}
};

View File

@ -12,13 +12,11 @@ body {
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Adjusted", "Segoe UI", "Liberation Sans", sans-serif;
background-color: #335C67;
color: #fff;
}
@import 'components/bookmark';
@import 'components/forms';
@import 'components/header';
@import 'components/pagination';
@import 'components/forms';
a {
&,
@ -32,6 +30,12 @@ a {
}
}
h1 {
color: #FFF3B0;
text-align: center;
}
.container {
max-width: 40rem;
margin: 1em auto;

View File

@ -9,8 +9,6 @@
"date tags"
"actions actions";
color: #000;
form & {
grid-template-areas:
"title"

View File

@ -1,18 +0,0 @@
header {
display: flex;
margin: 1em 0;
> h1 {
flex: 1;
margin: 0;
color: #FFF3B0;
text-align: left;
font-size: 2rem;
}
> a {
flex: 0;
font-size: 2rem;
text-decoration: none;
}
}

View File

@ -1,40 +1,39 @@
@extends('layouts.app')
@section('content')
<h2>{{ $bookmark ? "Edit Bookmark" : "Add Bookmark" }}</h2>
<p>
<a href="{{ action('BookmarkController@index') }}">&larr; Back</a>
</p>
<form method="post" class="form" action="{{ $bookmark ? action('BookmarkController@update', ['bookmark' => $bookmark]) : action('BookmarkController@store') }}">
<form method="post" class="form" action="{{ action('BookmarkController@update', ['bookmark' => $bookmark]) }}">
@csrf
<div class="bookmark">
<div class="bookmark-title form-row">
<div class="bookmark-title form-row"g>
<label class="form-label" for="title">
Title:
</label>
<input type="text" class="form-input" name="title" value="{{ $bookmark?->title }}" tabindex="1">
<input type="text" class="form-input" name="title" value="{{ $bookmark->title }}">
</div>
<div class="bookmark-href form-row form-row-stacked">
<label class="form-label" for="href">
URL:
</label>
<input type="text" class="form-input" name="href" value="{{ $bookmark?->href }}" tabindex="3">
<input type="text" class="form-input" name="href" value="{{ $bookmark->href }}">
</div>
<div class="bookmark-description form-row form-row-stacked">
<label class="form-label" for="description">
Description:
</label>
<textarea name="description" class="form-textarea" tabindex="2">{{ $bookmark?->description }}</textarea>
<textarea name="description" class="form-textarea">{{ $bookmark->description }}</textarea>
</div>
<div class="bookmark-tags form-row form-row-stacked">
<label class="form-label" for="description">
Tags:
</label>
<input type="text" class="form-input" name="tags" tabindex="4" value="@foreach ($bookmark?->tags ?? [] as $tag){{ $tag->name }} @endforeach">
<input type="text" class="form-input" name="tags" value="@foreach ($bookmark->tags as $tag){{ $tag->name }} @endforeach">
</div>
<div class="form-row align-right bookmark-actions">
<a class="form-button" tabindex="5" href="{{ $bookmark ? action('BookmarkController@show', ['bookmark' => $bookmark]) : action('BookmarkController@index') }}">Cancel</a>
<input type="submit" tabindex="6" class="form-button" value="Save">
<a class="form-button" href="{{ action('BookmarkController@show', ['bookmark' => $bookmark]) }}">Cancel</a>
<input type="submit" class="form-button" value="Save">
</div>
</div>
</form>

View File

@ -6,10 +6,7 @@
</head>
<body>
<div class="container">
<header>
<h1><a href="{{ url("/") }}">url snail</a></h1>
<a href="{{ action('BookmarkController@create') }}">+</a>
</header>
<h1><a href="{{ url("/") }}">url snail</a></h1>
@yield('content')
</div>
</body>

View File

@ -1,12 +1,9 @@
@extends('layouts.app')
@section('content')
<h2>Tag: {{ $tag->name }} ({{ $tag_count }})</h2>
{{ $bookmarks->links() }}
<div>
@foreach ($bookmarks as $bookmark)
@foreach ($tag->bookmarks as $bookmark)
<x-bookmark :bookmark="$bookmark" />
@endforeach
</div>
{{ $bookmarks->links() }}
@endsection