new library added

This commit is contained in:
Benjamin Takats
2022-12-05 19:04:57 +01:00
parent 5735158927
commit b9265c3ec9
39 changed files with 1482 additions and 115 deletions

View File

@@ -25,9 +25,16 @@ class CreateTags extends Command
*/
public function handle()
{
$tags = config('tags.tags');
$tags = config('tags.tags.course');
foreach ($tags as $tag) {
$t = Tag::findOrCreate($tag['de'], 'search');
$t = Tag::findOrCreate($tag['de'], 'course');
$t->icon = $tag['icon'];
$t->setTranslation('name', 'en', $tag['en']);
$t->save();
}
$tags = config('tags.tags.library_item');
foreach ($tags as $tag) {
$t = Tag::findOrCreate($tag['de'], 'library_item');
$t->icon = $tag['icon'];
$t->setTranslation('name', 'en', $tag['en']);
$t->save();

View File

@@ -12,6 +12,7 @@ class Header extends Component
public Country $country;
public $currentRouteName;
public string $c = 'de';
public bool $withGlobe = true;
public function rules()
{

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Livewire\Frontend;
use App\Models\Country;
use Livewire\Component;
class Library extends Component
{
public Country $country;
public $currentTab = 'Alle';
protected $queryString = [
'currentTab' => ['except' => 'alle'],
];
public function render()
{
return view('livewire.frontend.library', [
'libraries' => \App\Models\Library::get()
->prepend(\App\Models\Library::make([
'name' => 'Alle',
])),
]);
}
}

View File

@@ -18,6 +18,7 @@ class SearchByTag extends Component
{
return view('livewire.frontend.search-by-tag', [
'tags' => Tag::query()
->where('type', 'course')
->with([
'courses.lecturer',
])

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Livewire\Frontend;
use App\Models\Tag;
use Livewire\Component;
class SearchByTagInLibrary extends Component
{
public string $country = 'de';
public ?array $table = [];
protected $queryString = [
'table',
];
public function render()
{
return view('livewire.frontend.search-by-tag-in-library', [
'tags' => Tag::query()
->where('type', 'library_item')
->get(),
]);
}
}

View File

@@ -45,7 +45,7 @@ class CourseTable extends DataTableComponent
->toArray()
)
->filter(function (Builder $builder, array $values) {
$builder->withAnyTags($values, 'search');
$builder->withAnyTags($values, 'course');
}),
];
}

View File

@@ -55,6 +55,11 @@ class LecturerTable extends DataTableComponent
fn($row, Column $column) => $row->courses_count
)
->collapseOnMobile(),
Column::make('Inhalte')
->label(
fn($row, Column $column) => $row->library_items_count
)
->collapseOnMobile(),
Column::make('')
->label(
fn($row, Column $column) => view('columns.lectures.action')->withRow($row)
@@ -68,6 +73,7 @@ class LecturerTable extends DataTableComponent
return Lecturer::query()
->withCount([
'courses',
'libraryItems',
]);
}

View File

@@ -0,0 +1,61 @@
<?php
namespace App\Http\Livewire\Tables;
use App\Models\LibraryItem;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Columns\ImageColumn;
class LibraryItemTable extends DataTableComponent
{
protected $model = LibraryItem::class;
public function configure(): void
{
$this
->setPrimaryKey('id')
->setDefaultSort('order_column', 'asc');
}
public function columns(): array
{
return [
ImageColumn::make('Bild')
->location(
fn($row) => $row->getFirstMediaUrl('main', 'thumb')
)
->attributes(fn($row) => [
'class' => 'rounded h-16',
'alt' => $row->name.' Avatar',
])
->collapseOnMobile(),
Column::make('Dozent', "lecturer.name")
->label(
fn($row, Column $column) => view('columns.courses.lecturer')->withRow($row)
)
->sortable()
->collapseOnMobile(),
Column::make("Name", "name")
->sortable(),
Column::make("Art", "type")
->sortable(),
Column::make("Sprache", "language_code")
->sortable(),
Column::make('')
->label(
fn($row, Column $column) => view('columns.library_items.action')->withRow($row)
),
];
}
public function builder(): Builder
{
return LibraryItem::query()
->withCount([
'lecturer',
]);
}
}

View File

@@ -11,18 +11,17 @@ class Country extends Model
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'id' => 'integer',
'id' => 'integer',
'language_codes' => 'array',
];
public function cities(): \Illuminate\Database\Eloquent\Relations\HasMany

View File

@@ -73,4 +73,9 @@ class Lecturer extends Model implements HasMedia
{
return $this->hasMany(Course::class);
}
public function libraryItems(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(LibraryItem::class);
}
}

33
app/Models/Library.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Library extends Model
{
use HasFactory;
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'id' => 'integer',
'language_codes' => 'array',
];
public function libraryItems(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(LibraryItem::class);
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;
use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\Tags\HasTags;
class LibraryItem extends Model implements HasMedia, Sortable
{
use HasFactory;
use InteractsWithMedia;
use HasTags;
use SortableTrait;
/**
* The attributes that aren't mass assignable.
* @var array
*/
protected $guarded = [];
/**
* The attributes that should be cast to native types.
* @var array
*/
protected $casts = [
'id' => 'integer',
'lecturer_id' => 'integer',
'library_id' => 'integer',
];
public function registerMediaConversions(Media $media = null): void
{
$this
->addMediaConversion('preview')
->fit(Manipulations::FIT_CROP, 300, 300)
->nonQueued();
$this->addMediaConversion('thumb')
->fit(Manipulations::FIT_CROP, 130, 130)
->width(130)
->height(130);
}
public function registerMediaCollections(): void
{
$this->addMediaCollection('main')
->singleFile()
->useFallbackUrl(asset('img/einundzwanzig-cover-lesestunde.png'));
$this->addMediaCollection('single_file')
->acceptsMimeTypes(['application/pdf'])
->singleFile();
$this->addMediaCollection('images')
->useFallbackUrl(asset('img/einundzwanzig-cover-lesestunde.png'));
}
public function lecturer(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Lecturer::class);
}
public function library(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Library::class);
}
}

View File

@@ -2,30 +2,28 @@
namespace App\Nova;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\MultiSelect;
use Laravel\Nova\Fields\Text;
class Country extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = \App\Models\Country::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'name';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
@@ -37,22 +35,27 @@ class Country extends Resource
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()->sortable(),
ID::make()
->sortable(),
Text::make('Name')
->rules('required', 'string'),
MultiSelect::make('Languages', 'language_codes')
->options(
config('languages.languages'),
),
Text::make('Code')
->rules('required', 'string'),
HasMany::make('Cities'),
];
}
@@ -60,6 +63,7 @@ class Country extends Resource
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function cards(Request $request)
@@ -71,6 +75,7 @@ class Country extends Resource
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function filters(Request $request)
@@ -82,6 +87,7 @@ class Country extends Resource
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function lenses(Request $request)
@@ -93,6 +99,7 @@ class Country extends Resource
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)

View File

@@ -66,7 +66,7 @@ class Course extends Resource
->conversionOnIndexView('thumb')
->help('Lade hier Bilder hoch, um sie eventuell später in der Markdown Description einzufügen. Du musst vorher aber Speichern.'),
Tags::make('Tags')->type('search')->withLinkToTagResource(Tag::class),
Tags::make('Tags')->type('course')->withLinkToTagResource(Tag::class),
Text::make('Name')
->rules('required', 'string'),

106
app/Nova/Library.php Normal file
View File

@@ -0,0 +1,106 @@
<?php
namespace App\Nova;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\BelongsToMany;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\MultiSelect;
use Laravel\Nova\Fields\Text;
class Library extends Resource
{
/**
* The model the resource corresponds to.
* @var string
*/
public static $model = \App\Models\Library::class;
/**
* The single value that should be used to represent the resource when being displayed.
* @var string
*/
public static $title = 'name';
/**
* The columns that should be searched.
* @var array
*/
public static $search = [
'id',
'name',
];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()
->sortable(),
Text::make('Name')
->rules('required', 'string'),
MultiSelect::make('Languages', 'language_codes')
->options(
config('languages.languages'),
),
BelongsToMany::make('Library Items'),
];
}
/**
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function cards(Request $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function filters(Request $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function lenses(Request $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)
{
return [];
}
}

146
app/Nova/LibraryItem.php Normal file
View File

@@ -0,0 +1,146 @@
<?php
namespace App\Nova;
use Ebess\AdvancedNovaMediaLibrary\Fields\Files;
use Ebess\AdvancedNovaMediaLibrary\Fields\Images;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\BelongsToMany;
use Laravel\Nova\Fields\Code;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Spatie\TagsField\Tags;
class LibraryItem extends Resource
{
/**
* The model the resource corresponds to.
* @var string
*/
public static $model = \App\Models\LibraryItem::class;
/**
* The single value that should be used to represent the resource when being displayed.
* @var string
*/
public static $title = 'name';
/**
* The columns that should be searched.
* @var array
*/
public static $search = [
'id',
'name',
];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()
->sortable(),
Images::make('Main picture', 'main')
->conversionOnIndexView('thumb'),
Images::make('Images', 'images')
->conversionOnIndexView('thumb')
->help('Lade hier Bilder hoch, um sie eventuell später in der Markdown Description einzufügen. Du musst vorher aber Speichern.'),
Files::make('Downloadable File', 'single_file')
->help('Für neue Datei-Typen bitte bei den Admins melden. (Derzeit: PDF)'),
Select::make('Language Code', 'language_code')
->options(
config('languages.languages')
)
->rules('required', 'string'),
Tags::make('Tags')
->type('library_item')
->withLinkToTagResource(Tag::class),
Text::make('Name')
->rules('required', 'string'),
Select::make('Type')
->options(
[
'book' => 'book',
'blog_article' => 'blog_article',
'markdown_article' => 'markdown_article',
'youtube_video' => 'youtube_video',
'vimeo_video' => 'vimeo_video',
'downloadable_file' => 'downloadable_file',
]
)
->rules('required', 'string'),
Code::make('Value')
->rules('required', 'string')
->help('Hier bitte die URL zum Video einfügen, oder den Link zum Blog-Artikel, oder den Link zum Buch, oder das Markdown selbst einfügen.'),
BelongsTo::make('Lecturer'),
BelongsToMany::make('Library'),
];
}
/**
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function cards(Request $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function filters(Request $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function lenses(Request $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)
{
return [];
}
}

View File

@@ -28,7 +28,8 @@ class Tag extends Resource
Select::make('Type')
->options([
'search' => 'search',
'course' => 'course',
'library_item' => 'library_item',
]),
];

View File

@@ -9,6 +9,8 @@ use App\Nova\Course;
use App\Nova\Dashboards\Main;
use App\Nova\Event;
use App\Nova\Lecturer;
use App\Nova\Library;
use App\Nova\LibraryItem;
use App\Nova\Participant;
use App\Nova\Registration;
use App\Nova\Tag;
@@ -50,6 +52,13 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
->icon('academic-cap')
->collapsable(),
MenuSection::make('Bibliothek', [
MenuItem::resource(Library::class),
MenuItem::resource(LibraryItem::class),
])
->icon('library')
->collapsable(),
MenuSection::make('Admin', [
MenuItem::resource(Category::class),
MenuItem::resource(Country::class),