From c09ef89a8ca4ab75bbe2118b39dd457e040363ce Mon Sep 17 00:00:00 2001 From: Ernest Walzel Date: Fri, 11 Feb 2022 12:27:09 +0100 Subject: [PATCH 01/27] Add Tailwind to admin layout --- resources/views/layouts/admin.blade.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/views/layouts/admin.blade.php b/resources/views/layouts/admin.blade.php index 994fac8c8..5d4b5ae8b 100644 --- a/resources/views/layouts/admin.blade.php +++ b/resources/views/layouts/admin.blade.php @@ -17,6 +17,7 @@ + {!! Html::style('css/sb-admin.css') !!} {!! Html::style('css/ladda-themeless.min.css') !!} {!! Html::style('css/bootstrap-wysihtml5.css') !!} From d248d29ed0dd4acbb52a1844d29de4bf935ca91c Mon Sep 17 00:00:00 2001 From: Ernest Walzel Date: Fri, 11 Feb 2022 13:17:15 +0100 Subject: [PATCH 02/27] FeaturedArtwork resources (controller, views) --- .../Admin/FeaturedArtworkController.php | 70 ++++++++++++ .../views/featured_artworks/form.blade.php | 106 ++++++++++++++++++ .../views/featured_artworks/index.blade.php | 83 ++++++++++++++ routes/web.php | 1 + 4 files changed, 260 insertions(+) create mode 100644 app/Http/Controllers/Admin/FeaturedArtworkController.php create mode 100644 resources/views/featured_artworks/form.blade.php create mode 100644 resources/views/featured_artworks/index.blade.php diff --git a/app/Http/Controllers/Admin/FeaturedArtworkController.php b/app/Http/Controllers/Admin/FeaturedArtworkController.php new file mode 100644 index 000000000..1d2a6206d --- /dev/null +++ b/app/Http/Controllers/Admin/FeaturedArtworkController.php @@ -0,0 +1,70 @@ +with('media') + // ->get(); + + // return view('featured_pieces.index') + // ->with('featuredPieces', $featuredPieces); + // } + + public function create() + { + return view('featured_artworks.form'); + } + + // public function store(Request $request) + // { + // $request->validate(FeaturedPiece::$rules); + + // $featuredPiece = FeaturedPiece::create($request->input()); + // if ($request->hasFile('image')) { + // $featuredPiece + // ->addMediaFromRequest('image') + // ->toMediaCollection('image'); + // } + + // return redirect() + // ->route('featured-pieces.index') + // ->with('message', "Odporúčaný obsah \"{$featuredPiece->title}\" bol vytvorený"); + // } + + // public function edit(FeaturedPiece $featuredPiece) + // { + // return view('featured_artworks.form')->with('featuredPiece', $featuredPiece); + // } + + // public function update(Request $request, FeaturedPiece $featuredPiece) + // { + // $request->validate(FeaturedPiece::$rules); + + // $featuredPiece->update($request->input()); + // if ($request->hasFile('image')) { + // $featuredPiece + // ->addMediaFromRequest('image') + // ->toMediaCollection('image'); + // } + + // return redirect() + // ->route('featured-pieces.index') + // ->with('message', "Odporúčaný obsah \"{$featuredPiece->title}\" bol upravený"); + // } + + // public function destroy(FeaturedPiece $featuredPiece) + // { + // $featuredPiece->delete(); + + // return redirect() + // ->route('featured-pieces.index') + // ->with('message', 'Odporúčaný obsah bol zmazaný'); + // } +} diff --git a/resources/views/featured_artworks/form.blade.php b/resources/views/featured_artworks/form.blade.php new file mode 100644 index 000000000..62f70fc72 --- /dev/null +++ b/resources/views/featured_artworks/form.blade.php @@ -0,0 +1,106 @@ +@extends('layouts.admin') + +@section('content') +
+ + + +
+ + {{-- @if (isset($featuredPiece)) + {!! Form::model($featuredPiece, ['route' => ['featured-pieces.update', $featuredPiece], 'method' => 'patch', 'files' => true]) !!} +@else + {!! Form::open(['route' => 'featured-pieces.store', 'files' => true]) !!} +@endif + +
+ @if (Session::has('message')) +
{!! Session::get('message') !!}
+ @endif + + + @if ($errors->any()) +
+ × +
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif +
+ +
+
+ {{ Form::label('title', 'Nadpis') }} + {{ Form::textarea('title', null, ['class' => 'form-control', 'rows' => '2']) }} +
+
+ +
+
+ {{ Form::label('excerpt', 'Text') }} + {{ Form::textarea('excerpt', null, ['class' => 'form-control', 'rows' => '4']) }} +
+
+ +
+
+ {{ Form::label('url', 'URL') }} + {{ Form::text('url', null, ['class' => 'form-control', 'placeholder' => 'http://']) }} +
+
+ +
+
+ {{ Form::label('image', 'Obrázok') }} + @if (isset($featuredPiece) && $featuredPiece->hasMedia('image')) +
+ {{ $featuredPiece->getFirstMedia('image')->img()->attributes(['width' => '200', 'height' => null]) }} +
+ @endif + {{ Form::file('image') }} +

min. šírka 1200px

+
+
+ +
+
+ {{ Form::label('type', 'Typ') }} +
+ +
+
+ +
+
+
+ {{ Form::label('publish', 'Publikovaný') }}
+ {{ Form::hidden('publish', '0') }} + {{ Form::checkbox('publish', '1', null, ['class' => 'checkbox']) }} +
+
+ +
+ {{ Form::submit('Uložiť', ['class' => 'btn btn-primary']) }} + Zrušiť +
+ +{!! Form::close() !!} --}} + +@endsection diff --git a/resources/views/featured_artworks/index.blade.php b/resources/views/featured_artworks/index.blade.php new file mode 100644 index 000000000..6429fd9ba --- /dev/null +++ b/resources/views/featured_artworks/index.blade.php @@ -0,0 +1,83 @@ +@extends('layouts.admin') + +@section('title') +@parent +- Odporúčaný obsah +@endsection + +@section('content') +
+
+

Odporúčaný obsah

+ + @if (session('message')) +
+ + {{ session('message') }} +
+ @endif + +
+
+ +
+
+
+ +
+ + + + + + + + + + + + + + @foreach($featuredPieces as $piece) + + + + + + + + + @endforeach + +
IDNáhľadNadpisVytvorenýPublikovanýPočet kliknutíAkcie
{{ $piece->id }} + @if($piece->hasMedia('image')) + {{ $piece->getFirstMedia('image')->img()->attributes(['width' => '100%', 'height' => 'auto']) }} + @endif + + {{ $piece->title }}
+ {{ $piece->excerpt }} +
+ @datetime($piece->created_at) + @if ($piece->publish) @endif + {{ $piece->click_count }} + + Upraviť + + Zmazať + +
+ +
+
+
+
+@endsection diff --git a/routes/web.php b/routes/web.php index 12ac950ac..fda02279d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -533,6 +533,7 @@ function() Route::group(['middleware' => ['auth', 'can:administer']], function () { Route::resource('featured-pieces', 'Admin\FeaturedPieceController'); + Route::resource('featured-artworks', 'Admin\FeaturedArtworkController'); Route::get('harvests/launch/{id}', 'SpiceHarvesterController@launch'); Route::get('harvests/harvestFailed/{id}', 'SpiceHarvesterController@harvestFailed'); Route::get('harvests/orphaned/{id}', 'SpiceHarvesterController@orphaned'); From de4035070292d861397e6cd5eb87f903ed593832 Mon Sep 17 00:00:00 2001 From: Ernest Walzel Date: Fri, 11 Feb 2022 13:17:53 +0100 Subject: [PATCH 03/27] Autocomplete component Combining Bloodhound and VueSelect --- package-lock.json | 21 +++++--- package.json | 1 + resources/js/admin.js | 1 + resources/js/components/Autocomplete.vue | 64 ++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 resources/js/components/Autocomplete.vue diff --git a/package-lock.json b/package-lock.json index 6726be1f6..685cbee98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2912,6 +2912,14 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, + "corejs-typeahead": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/corejs-typeahead/-/corejs-typeahead-1.3.1.tgz", + "integrity": "sha512-fyNlBNWJNL6EQUnJyAunEzBzRcwR2cEHtZXBi2pndHPOJ/wpOf3wbS+/Oh+kYYS5sKowQcs0LFwMSl6Y2Xeqkw==", + "requires": { + "jquery": ">=1.11" + } + }, "cosmiconfig": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz", @@ -4688,7 +4696,6 @@ "minipass": { "version": "2.9.0", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -4893,8 +4900,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -4984,8 +4990,7 @@ }, "yallist": { "version": "3.1.1", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -6879,7 +6884,7 @@ }, "mkdirp": { "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, "optional": true, @@ -6889,7 +6894,7 @@ "dependencies": { "minimist": { "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true, "optional": true @@ -8315,7 +8320,7 @@ "dependencies": { "jsesc": { "version": "0.5.0", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", + "resolved": "http://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=", "dev": true } diff --git a/package.json b/package.json index 4c4461933..6d5bff9dd 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "dependencies": { "bootstrap": "^3.4.1", "clipboard": "^2.0.6", + "corejs-typeahead": "^1.3.1", "date-fns": "^2.25.0", "debounce": "1.2.0", "flickity": "^2.2.1", diff --git a/resources/js/admin.js b/resources/js/admin.js index 1fbc4b3a2..ae9a5a7f0 100644 --- a/resources/js/admin.js +++ b/resources/js/admin.js @@ -3,5 +3,6 @@ window.Vue = require('vue').default; Vue.component('linked-combos', require('./components/vue/linked-combos').default); Vue.component('admin-links-input', require('./components/admin/LinksInput.vue').default); +Vue.component('autocomplete', require('./components/Autocomplete.vue').default); new Vue({ el: '#wrapper' }) diff --git a/resources/js/components/Autocomplete.vue b/resources/js/components/Autocomplete.vue new file mode 100644 index 000000000..f59698a20 --- /dev/null +++ b/resources/js/components/Autocomplete.vue @@ -0,0 +1,64 @@ + + + From 01acb2c394d5aec2430c2ad0b5bcf782cafff89e Mon Sep 17 00:00:00 2001 From: Ernest Walzel Date: Thu, 17 Feb 2022 13:32:57 +0100 Subject: [PATCH 04/27] Add Livewire to admin layout --- resources/js/admin.js | 8 ++++++-- resources/views/layouts/admin.blade.php | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/resources/js/admin.js b/resources/js/admin.js index ae9a5a7f0..7a75556a9 100644 --- a/resources/js/admin.js +++ b/resources/js/admin.js @@ -1,8 +1,12 @@ +import Vue from 'vue' +import 'livewire-vue' + +window.Vue = Vue window.debounce = require('debounce'); -window.Vue = require('vue').default; -Vue.component('linked-combos', require('./components/vue/linked-combos').default); Vue.component('admin-links-input', require('./components/admin/LinksInput.vue').default); Vue.component('autocomplete', require('./components/Autocomplete.vue').default); +Vue.component('linked-combos', require('./components/vue/linked-combos').default); +Vue.component('livewire-vue-adaptor', require('./components/LivewireVueAdaptor.vue').default); new Vue({ el: '#wrapper' }) diff --git a/resources/views/layouts/admin.blade.php b/resources/views/layouts/admin.blade.php index 5d4b5ae8b..a6a22527d 100644 --- a/resources/views/layouts/admin.blade.php +++ b/resources/views/layouts/admin.blade.php @@ -28,6 +28,7 @@ {!! Html::style('css/jquery-ui/jquery-ui.css') !!} {!! Html::style('/css/vue/vue-select.css') !!} {!! Html::style(mix('/css/admin.css')) !!} + @livewireStyles @@ -191,6 +192,7 @@ + @livewireScripts {!! Html::script('js/bootstrap.min.js') !!} From 5144a79f63f6a191d815831520e606b846c9a678 Mon Sep 17 00:00:00 2001 From: Ernest Walzel Date: Thu, 17 Feb 2022 13:33:27 +0100 Subject: [PATCH 05/27] Make LivewireVueAdaptor renderless and make it accept instanceId --- .../js/components/LivewireVueAdaptor.vue | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/resources/js/components/LivewireVueAdaptor.vue b/resources/js/components/LivewireVueAdaptor.vue index 9cc4ca8a1..79055a95b 100644 --- a/resources/js/components/LivewireVueAdaptor.vue +++ b/resources/js/components/LivewireVueAdaptor.vue @@ -1,24 +1,24 @@ - - \ No newline at end of file + From 4dfb0c061381211ed534658f01ed0f6e2c189433 Mon Sep 17 00:00:00 2001 From: Ernest Walzel Date: Thu, 17 Feb 2022 18:48:07 +0100 Subject: [PATCH 06/27] Item#authors_with_authorities returns a structured collection --- app/Item.php | 18 ++++++++++++++++ .../views/components/item_author.blade.php | 14 ++++++------- resources/views/dielo.blade.php | 8 +------ tests/Models/ItemTest.php | 21 +++++++++++++++++++ 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/app/Item.php b/app/Item.php index fd335f744..b4e657242 100644 --- a/app/Item.php +++ b/app/Item.php @@ -351,6 +351,24 @@ public function getAuthorsWithoutAuthority() ->keys(); } + public function getAuthorsWithAuthoritiesAttribute() + { + $authorities = $this + ->authorities + ->map(fn ($authority) => (object) [ + 'name' => $authority->name, + 'authority' => $authority + ]); + + $authors = $this + ->getAuthorsWithoutAuthority() + ->map(fn ($author) => (object) [ + 'name' => $author + ]); + + return $authorities->concat($authors); + } + public function getFirstAuthorAttribute($value) { $authors_array = $this->makeArray($this->author); diff --git a/resources/views/components/item_author.blade.php b/resources/views/components/item_author.blade.php index 8fd7a990b..a57e72f3c 100644 --- a/resources/views/components/item_author.blade.php +++ b/resources/views/components/item_author.blade.php @@ -1,13 +1,13 @@ {{-- comments kept for code indentation without whitespace --}} -@if (is_string($author)) - {{ formatName($author) }}{{-- ---}}@elseif ($author->pivot->role === 'autor/author') +@empty ($author->authority) + {{ formatName($author->name) }}{{-- +--}}@elseif ($author->authority->pivot->role === 'autor/author') - - {{ formatName($author->name) }}{{-- + + {{ formatName($author->authority->name) }}{{-- --}}{{-- --}}{{-- --}}@else - {{ formatName($author->name) }} - – {{ $author::formatMultiAttribute($author->pivot->role) }}{{-- + {{ formatName($author->authority->name) }} + – {{ $author->authority::formatMultiAttribute($author->authority->pivot->role) }}{{-- --}}@endif \ No newline at end of file diff --git a/resources/views/dielo.blade.php b/resources/views/dielo.blade.php index d8d15d84b..8c1ebf188 100644 --- a/resources/views/dielo.blade.php +++ b/resources/views/dielo.blade.php @@ -51,13 +51,7 @@

{{ $item->title }}

- @php - $authors = $item->authorities - ->toBase() - ->merge($item->getAuthorsWithoutAuthority()); - @endphp - - @foreach($authors as $author) + @foreach($item->authors_with_authorities as $author) @include('components.item_author')@if (!$loop->last), @endif @endforeach

diff --git a/tests/Models/ItemTest.php b/tests/Models/ItemTest.php index abef4ced0..bdc521dda 100644 --- a/tests/Models/ItemTest.php +++ b/tests/Models/ItemTest.php @@ -148,6 +148,27 @@ public function testMergedAuthorityNamesAndAuthors() $this->assertEquals('Philips Wouwerman', $data['author'][1]); } + public function testAuthorsWithAuthoritiesAttribute() + { + $item = factory(Item::class)->make([ + 'author' => 'Philips Wouwerman; Vladimír Boudník; Mikuláš Galanda' + ]); + $authority = factory(Authority::class)->create([ + 'name' => 'Boudník, Vladimír', + ]); + $item->authorities()->attach($authority); + + $data = $item->authors_with_authorities; + $this->assertCount(3, $data); + + $this->assertEquals('Boudník, Vladimír', $data[0]->name); + $this->assertInstanceOf(Authority::class, $data[0]->authority); + $this->assertEquals($authority->id, $data[0]->authority->id); + + $this->assertEquals('Philips Wouwerman', $data[1]->name); + $this->assertObjectNotHasAttribute('authority', $data[1]); + } + protected function createFreeItem() { return factory(Item::class)->make([ 'gallery' => 'Slovenská národná galéria, SNG', From 0703cff53dd89a93240d0eca0fcdc589f0cf1252 Mon Sep 17 00:00:00 2001 From: Ernest Walzel Date: Thu, 17 Feb 2022 19:04:23 +0100 Subject: [PATCH 07/27] Define 2 shades of blue ("sky") --- tailwind.config.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tailwind.config.js b/tailwind.config.js index 713e9cf79..b47c5c199 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -26,6 +26,10 @@ module.exports = { 600: '#777', 800: '#333', }, + sky: { + 300: '#66ccf4', + 400: '#37bcf1' + } }, spacing: { '104': '26rem', From cca72efe8ade15ccc41593174c9b93307ab0c1fd Mon Sep 17 00:00:00 2001 From: Ernest Walzel Date: Fri, 18 Feb 2022 06:32:34 +0100 Subject: [PATCH 08/27] Admin\Form component --- app/View/Components/Admin/Form.php | 59 +++++++++++++++++++ .../views/components/admin/form.blade.php | 3 + 2 files changed, 62 insertions(+) create mode 100644 app/View/Components/Admin/Form.php create mode 100644 resources/views/components/admin/form.blade.php diff --git a/app/View/Components/Admin/Form.php b/app/View/Components/Admin/Form.php new file mode 100644 index 000000000..7511f5af4 --- /dev/null +++ b/app/View/Components/Admin/Form.php @@ -0,0 +1,59 @@ +model = $model; + $this->url = $this->buildUrl($url); + $this->method = $this->buildMethod($method); + } + + private function buildUrl(?string $url): string { + if ($url) return $url; + + // Try to guess url from model class + $routeName = Str::of(class_basename($this->model))->plural()->kebab(); + + if ($this->model->exists) { + return route("$routeName.update", [$this->model]); + } + + return route("$routeName.store"); + } + + private function buildMethod(?string $method): string { + if ($method) return $method; + + if ($this->model->exists) return 'patch'; + + return 'post'; + } + + /** + * Get the view / contents that represent the component. + * + * @return \Illuminate\Contracts\View\View|\Closure|string + */ + public function render() + { + return view('components.admin.form'); + } +} diff --git a/resources/views/components/admin/form.blade.php b/resources/views/components/admin/form.blade.php new file mode 100644 index 000000000..caa2bb797 --- /dev/null +++ b/resources/views/components/admin/form.blade.php @@ -0,0 +1,3 @@ +{!! Form::model($model, compact('url', 'method')) !!} + {{ $slot }} +{!! Form::close() !!} From 4b346db047b4f16f3358b0d54b826a33b5461241 Mon Sep 17 00:00:00 2001 From: Ernest Walzel Date: Fri, 18 Feb 2022 07:06:00 +0100 Subject: [PATCH 09/27] Make Autocomplete work with other components --- resources/js/components/Autocomplete.vue | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/js/components/Autocomplete.vue b/resources/js/components/Autocomplete.vue index f59698a20..e0c011421 100644 --- a/resources/js/components/Autocomplete.vue +++ b/resources/js/components/Autocomplete.vue @@ -4,6 +4,9 @@ :options="options" :filterable="false" :label="optionLabel" + :clearable="false" + :value="value" + v-on:input="(value) => $emit('input', value)" >