Skip to content

Commit

Permalink
media improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed May 10, 2024
1 parent a14686f commit 60cf15a
Show file tree
Hide file tree
Showing 27 changed files with 342 additions and 230 deletions.
376 changes: 192 additions & 184 deletions composer.lock

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion public/build/assets/app-2f30f4db.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/app-a1ae10d8.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/build/assets/chart-92c4939f.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion public/build/assets/chart-b2b6bf5e.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/dropdown-92c4939f.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion public/build/assets/dropdown-b2b6bf5e.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/editor-92c4939f.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion public/build/assets/editor-b2b6bf5e.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/media-manager-92c4939f.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion public/build/assets/media-manager-b2b6bf5e.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/repeater-92c4939f.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion public/build/assets/repeater-b2b6bf5e.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/table-92c4939f.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion public/build/assets/table-b2b6bf5e.js

This file was deleted.

16 changes: 8 additions & 8 deletions public/build/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,60 @@
"css": [
"assets/app-69baab43.css"
],
"file": "assets/app-85a0d71c.js",
"file": "assets/app-274d084e.js",
"isEntry": true,
"src": "resources/js/app.js"
},
"resources/js/chart.js": {
"file": "assets/chart-b2b6bf5e.js",
"file": "assets/chart-92c4939f.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/chart.js"
},
"resources/js/dropdown.js": {
"file": "assets/dropdown-b2b6bf5e.js",
"file": "assets/dropdown-92c4939f.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/dropdown.js"
},
"resources/js/editor.js": {
"file": "assets/editor-b2b6bf5e.js",
"file": "assets/editor-92c4939f.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/editor.js"
},
"resources/js/media-manager.js": {
"file": "assets/media-manager-b2b6bf5e.js",
"file": "assets/media-manager-92c4939f.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/media-manager.js"
},
"resources/js/repeater.js": {
"file": "assets/repeater-b2b6bf5e.js",
"file": "assets/repeater-92c4939f.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/repeater.js"
},
"resources/js/table.js": {
"file": "assets/table-b2b6bf5e.js",
"file": "assets/table-92c4939f.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/table.js"
},
"resources/sass/app.scss": {
"file": "assets/app-2f30f4db.js",
"file": "assets/app-a1ae10d8.js",
"imports": [
"resources/js/app.js"
],
Expand Down
19 changes: 19 additions & 0 deletions resources/js/media-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ document.addEventListener('alpine:init', () => {
selected(item) {
return this.selection.findIndex((selected) => selected.value === item.value) > -1;
},
destroy() {
this.processing = true;

const ids = this.selection.map((item) => item.value);

window.$http.delete(url, { data: { ids } }).then((response) => {
this.selection = [];

response.data.deleted.forEach((id) => {
let index = this.items.findIndex((item) => item.value === id);

this.items.splice(index, 1);
});
}).catch((error) => {
//
}).finally(() => {
this.processing = false;
});
}
};
});
});
5 changes: 1 addition & 4 deletions resources/views/filters/search.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<div class="search-form">
<x-root::icon name="search" class="search-form__icon" />
<input {{ $attrs }} value="{{ $value }}">
<button type="submit" class="search-form__submit">
<span class="sr-only">{{ $label }}</span>
<x-root::icon name="search" class="search-form__icon" />
</button>
</div>
32 changes: 24 additions & 8 deletions resources/views/media/manager.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,30 @@ class="media-list"
</template>
</ol>
<x-slot:footer class="modal__footer--space-between">
<input
type="file"
class="form-file"
accept="{{ $config['accept'] }}"
multiple
x-bind:disabled="processing"
x-on:change="queueFiles($event.target.files)"
>
<div class="modal__column">
<input
type="file"
class="form-file"
accept="{{ $config['accept'] }}"
multiple
x-bind:disabled="processing"
x-on:change="queueFiles($event.target.files)"
>
<button
type="button"
class="btn btn--delete"
x-show="selection.length > 0"
x-bind:disabled="selection.length == 0"
x-on:click="() => {
if (window.confirm('{{ __('Are you sure?') }}')) {
destroy();
}
}"
>
{{ __('Delete') }}
<span x-text="`(${selection.length})`"></span>
</button>
</div>
<div class="modal__column">
<button type="button" class="btn btn--primary" x-on:click="open = false">
{{ __('Close') }}
Expand Down
20 changes: 13 additions & 7 deletions src/Fields/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ protected function stored(Request $request, Model $model, string $path): array
MoveFile::withChain($medium->convertible() ? [new PerformConversions($medium)] : [])
->dispatch($medium, $path, false);

return $this->toOption($request, $model, $medium);
$option = $this->toOption($request, $model, $medium);

return array_merge($option, [
'html' => View::make('root::fields.file-option', $option)->render(),
]);
}

/**
Expand Down Expand Up @@ -229,20 +233,22 @@ public function persist(Request $request, Model $model, mixed $value): void
/**
* Prune the related models.
*/
public function prune(Request $request, Model $model, array $keys): int
public function prune(Request $request, Model $model, array $keys): array
{
$count = 0;
$deleted = [];

$this->resolveRelatableQuery($request, $model)
->whereIn('id', $keys)
->cursor()
->each(static function (Medium $medium) use (&$count): void {
$medium->delete();
->each(static function (Medium $medium) use ($request, &$deleted): void {
if ($request->user()->can('delete', $medium)) {
$medium->delete();

$count++;
$deleted[] = $medium->getKey();
}
});

return $count;
return $deleted;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Filters/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public function toField(): SearchField
{
return SearchField::make($this->getName(), $this->getRequestKey())
->value(fn (Request $request): ?string => $this->getValue($request))
->placeholder($this->getName().'...');
->placeholder(sprintf('%s...', $this->getName()));
}
}
2 changes: 1 addition & 1 deletion src/Filters/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public function __construct(string $label, Closure|string|null $modelAttribute =
{
parent::__construct($label, $modelAttribute);

$this->class(['search-form__control']);
$this->classList()->replace('form-control', 'search-form__control');
}
}
13 changes: 5 additions & 8 deletions src/Models/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,10 @@ public function scopeSearch(Builder $query, ?string $value = null): Builder
*/
public function scopeType(Builder $query, string $value): Builder
{
switch ($value) {
case 'image':
return $query->where($query->qualifyColumn('mime_type'), 'like', 'image%');
case 'file':
return $query->where($query->qualifyColumn('mime_type'), 'not like', 'image%');
default:
return $query;
}
return match ($value) {
'image' => $query->where($query->qualifyColumn('mime_type'), 'like', 'image%'),
'file' => $query->where($query->qualifyColumn('mime_type'), 'not like', 'image%'),
default => $query,
};
}
}
65 changes: 65 additions & 0 deletions src/Policies/MediumPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Cone\Root\Policies;

use App\Models\User;
use Cone\Root\Models\Medium;

class MediumPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return true;
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, Medium $medium): bool
{
return true;
}

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return true;
}

/**
* Determine whether the user can update the model.
*/
public function update(User $user, Medium $medium): bool
{
return true;
}

/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Medium $medium): bool
{
return true;
}

/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Medium $medium): bool
{
return true;
}

/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Medium $medium): bool
{
return true;
}
}
2 changes: 1 addition & 1 deletion src/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Root
*
* @var string
*/
public const VERSION = '2.2.16';
public const VERSION = '2.2.17';

/**
* The registered booting callbacks.
Expand Down
4 changes: 4 additions & 0 deletions src/RootServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Cone\Root;

use Cone\Root\Exceptions\SaveFormDataException;
use Cone\Root\Models\Medium;
use Cone\Root\Models\User;
use Cone\Root\Policies\MediumPolicy;
use Cone\Root\Resources\Resource;
use Cone\Root\Support\Alert;
use Illuminate\Cache\RateLimiting\Limit;
Expand Down Expand Up @@ -223,6 +225,8 @@ protected function registerAuth(): void
Gate::define('viewRoot', static function (User $user): bool {
return Root::instance()->authorized($user);
});

Gate::policy(Medium::getProxiedClass(), MediumPolicy::class);
}

/**
Expand Down

0 comments on commit 60cf15a

Please sign in to comment.