Skip to content

Commit

Permalink
Merge pull request #46 from mostafaznv/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mostafaznv committed May 5, 2023
2 parents 1ac986c + b1de589 commit 3b02bd4
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"require": {
"php": "^8.0.2",
"intervention/image": "^2.5",
"mostafaznv/nova-video": "^3.0|^4.0",
"mostafaznv/nova-video": "^3.0|^4.0|^5.0",
"laravel/framework": "^8.40.0|^9.0|^10.0",
"laravel/nova": "^4.13",
"nova-kit/nova-packages-tool": "^1.2",
Expand Down
2 changes: 1 addition & 1 deletion dist/css/field.css

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

2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions dist/js/field.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

/**
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
Expand Down
8 changes: 8 additions & 0 deletions resources/js/ckeditor/config/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ export default {
},
toolbar: [
'imageBrowser',
'|',
'imageStyle:full',
'imageStyle:alignLeft',
'imageStyle:alignCenter',
'imageStyle:alignRight',
'|',
'imageTextAlternative',
'toggleImageCaption',
'|',
'imageStyle:block',
'imageStyle:side',
'|',
'linkImage'
],
styles: [
'full',
Expand Down
12 changes: 11 additions & 1 deletion src/FieldServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Mostafaznv\NovaCkEditor;

use Composer\InstalledVersions;
use Laravel\Nova\Nova;
use Illuminate\Support\Facades\App;
use Laravel\Nova\Events\ServingNova;
Expand Down Expand Up @@ -44,6 +45,8 @@ public function boot(): void

protected function publish(): void
{
$videoStub = $this->isLegacy() ? 'Video.legacy.stub' : 'Video.stub';

$this->publishes([
__DIR__ . '/../config/nova-ckeditor.php' => config_path('nova-ckeditor.php')
], 'nova-ckeditor-config');
Expand All @@ -58,11 +61,18 @@ protected function publish(): void

# models
__DIR__ . '/../stubs/models/Image.stub' => app_path('Models/Image.php'),
__DIR__ . '/../stubs/models/Video.stub' => app_path('Models/Video.php'),
__DIR__ . "/../stubs/models/$videoStub" => app_path('Models/Video.php'),

# resources
__DIR__ . '/../stubs/resources/Image.stub' => app_path('Nova/Resources/Image.php'),
__DIR__ . '/../stubs/resources/Video.stub' => app_path('Nova/Resources/Video.php')
], 'nova-ckeditor-stubs');
}

private function isLegacy(): bool
{
$larupload = InstalledVersions::getVersion('mostafaznv/larupload');

return version_compare($larupload, '1.0.0', '<');
}
}
44 changes: 44 additions & 0 deletions stubs/models/Video.legacy.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mostafaznv\Larupload\LaruploadEnum;
use Mostafaznv\Larupload\Storage\Attachment;
use Mostafaznv\Larupload\Traits\Larupload;
use Exception;

class Video extends Model
{
use Larupload;

protected $fillable = ['name', 'file', 'disk'];

protected static function boot()
{
parent::boot();

self::saving(function($model) {
$hasLaruploadTrait = method_exists(self::class, 'bootLarupload');

if (!$model->name) {
$name = $hasLaruploadTrait ? $model->file->meta('name') : $model->file;

$model->name = pathinfo($name, PATHINFO_FILENAME);
}
});
}

/**
* @throws Exception
*/
public function attachments(): array
{
return [
Attachment::make('file')
->disk('video')
->namingMethod(LaruploadEnum::HASH_FILE_NAMING_METHOD)
->coverStyle(852, 480, LaruploadEnum::AUTO_STYLE_MODE),
];
}
}
11 changes: 4 additions & 7 deletions stubs/models/Video.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mostafaznv\Larupload\LaruploadEnum;
use Mostafaznv\Larupload\Enums\LaruploadMediaStyle;
use Mostafaznv\Larupload\Enums\LaruploadNamingMethod;
use Mostafaznv\Larupload\Storage\Attachment;
use Mostafaznv\Larupload\Traits\Larupload;
use Exception;

class Video extends Model
{
Expand All @@ -29,16 +29,13 @@ class Video extends Model
});
}

/**
* @throws Exception
*/
public function attachments(): array
{
return [
Attachment::make('file')
->disk('video')
->namingMethod(LaruploadEnum::HASH_FILE_NAMING_METHOD)
->coverStyle(852, 480, LaruploadEnum::AUTO_STYLE_MODE),
->namingMethod(LaruploadNamingMethod::HASH_FILE)
->coverStyle('cover', 852, 480, LaruploadMediaStyle::CROP),
];
}
}

0 comments on commit 3b02bd4

Please sign in to comment.