feat: Implement Document Module with Dropzone file upload functionality
- Added DocumentController for handling document uploads and management. - Created Document model with necessary attributes and relationships. - Implemented DocumentService for business logic related to documents. - Set up routes for document management in both web and API contexts. - Developed views for document upload using Dropzone for file handling. - Included necessary assets and styles for the Document module. - Created migration for documents table with appropriate fields. - Added configuration and service provider for the Document module.
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Modules\CCMS\Traits\UpdateCustomFields;
|
use Modules\CCMS\Traits\UpdateCustomFields;
|
||||||
|
use Modules\Document\Models\Document;
|
||||||
|
|
||||||
class Country extends Model
|
class Country extends Model
|
||||||
{
|
{
|
||||||
@@ -96,4 +97,9 @@ class Country extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Country::class, 'parent_id');
|
return $this->hasMany(Country::class, 'parent_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function documents()
|
||||||
|
{
|
||||||
|
return $this->morphMany(Document::class, 'documentable');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Modules\CCMS\Traits\UpdateCustomFields;
|
use Modules\CCMS\Traits\UpdateCustomFields;
|
||||||
|
use Modules\Document\Models\Document;
|
||||||
|
|
||||||
class Service extends Model
|
class Service extends Model
|
||||||
{
|
{
|
||||||
@@ -100,4 +101,9 @@ class Service extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Service::class, 'parent_id');
|
return $this->belongsTo(Service::class, 'parent_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function documents()
|
||||||
|
{
|
||||||
|
return $this->morphMany(Document::class, 'documentable');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Modules\CCMS\Traits\UpdateCustomFields;
|
use Modules\CCMS\Traits\UpdateCustomFields;
|
||||||
|
use Modules\Document\Models\Document;
|
||||||
|
|
||||||
// use Modules\CCMS\Database\Factories\TestFactory;
|
// use Modules\CCMS\Database\Factories\TestFactory;
|
||||||
|
|
||||||
class Test extends Model
|
class Test extends Model
|
||||||
@@ -92,4 +94,9 @@ class Test extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Test::class, 'parent_id');
|
return $this->belongsTo(Test::class, 'parent_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function documents()
|
||||||
|
{
|
||||||
|
return $this->morphMany(Document::class, 'documentable');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
0
Modules/Document/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Document/app/Http/Controllers/.gitkeep
Normal file
71
Modules/Document/app/Http/Controllers/DocumentController.php
Normal file
71
Modules/Document/app/Http/Controllers/DocumentController.php
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Document\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Modules\CCMS\Models\Country;
|
||||||
|
use Modules\CCMS\Models\Service;
|
||||||
|
use Modules\CCMS\Models\Test;
|
||||||
|
use Modules\Document\Services\DocumentService;
|
||||||
|
use Yajra\DataTables\Facades\DataTables;
|
||||||
|
|
||||||
|
class DocumentController extends Controller
|
||||||
|
{
|
||||||
|
protected $documentService;
|
||||||
|
|
||||||
|
public function __construct(DocumentService $documentService)
|
||||||
|
{
|
||||||
|
$this->documentService = $documentService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$title = 'Upload Documents';
|
||||||
|
$countryOptions = Country::whereNull('parent_id')->pluck('title', 'id')->mapWithKeys(fn($title, $id) => ["Country:$id" => "Country - $title"]);
|
||||||
|
$serviceOptions = Service::whereNull('parent_id')->pluck('title', 'id')->mapWithKeys(fn($title, $id) => ["Service:$id" => "Service - $title"]);
|
||||||
|
$testOptions = Test::whereNull('parent_id')->pluck('title', 'id')->mapWithKeys(fn($title, $id) => ["Test:$id" => "Test - $title"]);
|
||||||
|
|
||||||
|
$modelOptions = $countryOptions->merge($serviceOptions)->merge($testOptions);
|
||||||
|
|
||||||
|
return view('document::document.index', compact('modelOptions', 'title'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function dropzoneUpload(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'model' => 'required|string',
|
||||||
|
'file' => 'required|array',
|
||||||
|
'file.*' => 'file|mimes:pdf,doc,docx,jpg,png|max:5120',
|
||||||
|
'title' => 'nullable|string',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$parts = explode(':', $request->model);
|
||||||
|
|
||||||
|
if (count($parts) !== 2) {
|
||||||
|
return response()->json(['error' => 'Invalid model format.'], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
[$modelType, $modelId] = $parts;
|
||||||
|
$modelClass = "App\\Models\\$modelType";
|
||||||
|
|
||||||
|
if (!class_exists($modelClass)) {
|
||||||
|
return response()->json(['error' => 'Invalid model selected.'], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
$model = $modelClass::findOrFail($modelId);
|
||||||
|
|
||||||
|
foreach ($request->file('file') as $uploadedFile) {
|
||||||
|
$path = $uploadedFile->store('documents');
|
||||||
|
|
||||||
|
$model->documents()->create([
|
||||||
|
'title' => $request->title ?? 'Untitled',
|
||||||
|
'file_path' => $path,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(['success' => 'Files uploaded successfully']);
|
||||||
|
}
|
||||||
|
}
|
69
Modules/Document/app/Models/Document.php
Normal file
69
Modules/Document/app/Models/Document.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Document\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class Document extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = ['title', 'file_path'];
|
||||||
|
|
||||||
|
|
||||||
|
public function documentable(): MorphTo
|
||||||
|
{
|
||||||
|
return $this->morphTo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrl()
|
||||||
|
{
|
||||||
|
$path = $this->document_path;
|
||||||
|
return Storage::disk('public')->url($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSize()
|
||||||
|
{
|
||||||
|
$path = $this->document_path;
|
||||||
|
|
||||||
|
if (Storage::disk('public')->exists($path)) {
|
||||||
|
$sizeInBytes = Storage::disk('public')->size($path);
|
||||||
|
return round($sizeInBytes / 1024, 2) . " KB";
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getExtension()
|
||||||
|
{
|
||||||
|
return pathinfo($this->document_path, PATHINFO_EXTENSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isImageFile()
|
||||||
|
{
|
||||||
|
$imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp', 'tiff', 'tif', 'ico'];
|
||||||
|
$extension = pathinfo($this->document_path, PATHINFO_EXTENSION);
|
||||||
|
return in_array(Str::lower($extension), $imageExtensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function documentPath(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: function (mixed $value, array $attributes) {
|
||||||
|
$collectionName = $attributes['collection_name'];
|
||||||
|
$path = $attributes['document_path'];
|
||||||
|
return "{$collectionName}/{$path}";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeActive($query, int $status = 1)
|
||||||
|
{
|
||||||
|
return $query->where('status', $status);
|
||||||
|
}
|
||||||
|
}
|
0
Modules/Document/app/Models/Scopes/.gitkeep
Normal file
0
Modules/Document/app/Models/Scopes/.gitkeep
Normal file
0
Modules/Document/app/Providers/.gitkeep
Normal file
0
Modules/Document/app/Providers/.gitkeep
Normal file
135
Modules/Document/app/Providers/DocumentServiceProvider.php
Normal file
135
Modules/Document/app/Providers/DocumentServiceProvider.php
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Document\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Nwidart\Modules\Traits\PathNamespace;
|
||||||
|
use RecursiveDirectoryIterator;
|
||||||
|
use RecursiveIteratorIterator;
|
||||||
|
|
||||||
|
class DocumentServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
use PathNamespace;
|
||||||
|
|
||||||
|
protected string $name = 'Document';
|
||||||
|
|
||||||
|
protected string $nameLower = 'document';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Boot the application events.
|
||||||
|
*/
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
$this->registerCommands();
|
||||||
|
$this->registerCommandSchedules();
|
||||||
|
$this->registerTranslations();
|
||||||
|
$this->registerConfig();
|
||||||
|
$this->registerViews();
|
||||||
|
$this->loadMigrationsFrom(module_path($this->name, 'database/migrations'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the service provider.
|
||||||
|
*/
|
||||||
|
public function register(): void
|
||||||
|
{
|
||||||
|
$this->app->register(EventServiceProvider::class);
|
||||||
|
$this->app->register(RouteServiceProvider::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register commands in the format of Command::class
|
||||||
|
*/
|
||||||
|
protected function registerCommands(): void
|
||||||
|
{
|
||||||
|
// $this->commands([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register command Schedules.
|
||||||
|
*/
|
||||||
|
protected function registerCommandSchedules(): void
|
||||||
|
{
|
||||||
|
// $this->app->booted(function () {
|
||||||
|
// $schedule = $this->app->make(Schedule::class);
|
||||||
|
// $schedule->command('inspire')->hourly();
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register translations.
|
||||||
|
*/
|
||||||
|
public function registerTranslations(): void
|
||||||
|
{
|
||||||
|
$langPath = resource_path('lang/modules/'.$this->nameLower);
|
||||||
|
|
||||||
|
if (is_dir($langPath)) {
|
||||||
|
$this->loadTranslationsFrom($langPath, $this->nameLower);
|
||||||
|
$this->loadJsonTranslationsFrom($langPath);
|
||||||
|
} else {
|
||||||
|
$this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->nameLower);
|
||||||
|
$this->loadJsonTranslationsFrom(module_path($this->name, 'lang'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register config.
|
||||||
|
*/
|
||||||
|
protected function registerConfig(): void
|
||||||
|
{
|
||||||
|
$relativeConfigPath = config('modules.paths.generator.config.path');
|
||||||
|
$configPath = module_path($this->name, $relativeConfigPath);
|
||||||
|
|
||||||
|
if (is_dir($configPath)) {
|
||||||
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));
|
||||||
|
|
||||||
|
foreach ($iterator as $file) {
|
||||||
|
if ($file->isFile() && $file->getExtension() === 'php') {
|
||||||
|
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
|
||||||
|
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
|
||||||
|
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;
|
||||||
|
|
||||||
|
$this->publishes([$file->getPathname() => config_path($relativePath)], 'config');
|
||||||
|
$this->mergeConfigFrom($file->getPathname(), $key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register views.
|
||||||
|
*/
|
||||||
|
public function registerViews(): void
|
||||||
|
{
|
||||||
|
$viewPath = resource_path('views/modules/'.$this->nameLower);
|
||||||
|
$sourcePath = module_path($this->name, 'resources/views');
|
||||||
|
|
||||||
|
$this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']);
|
||||||
|
|
||||||
|
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower);
|
||||||
|
|
||||||
|
$componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path')));
|
||||||
|
Blade::componentNamespace($componentNamespace, $this->nameLower);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the services provided by the provider.
|
||||||
|
*/
|
||||||
|
public function provides(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getPublishableViewPaths(): array
|
||||||
|
{
|
||||||
|
$paths = [];
|
||||||
|
foreach (config('view.paths') as $path) {
|
||||||
|
if (is_dir($path.'/modules/'.$this->nameLower)) {
|
||||||
|
$paths[] = $path.'/modules/'.$this->nameLower;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $paths;
|
||||||
|
}
|
||||||
|
}
|
30
Modules/Document/app/Providers/EventServiceProvider.php
Normal file
30
Modules/Document/app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Document\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||||
|
|
||||||
|
class EventServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The event handler mappings for the application.
|
||||||
|
*
|
||||||
|
* @var array<string, array<int, string>>
|
||||||
|
*/
|
||||||
|
protected $listen = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if events should be discovered.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected static $shouldDiscoverEvents = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the proper event listeners for email verification.
|
||||||
|
*/
|
||||||
|
protected function configureEmailVerification(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
50
Modules/Document/app/Providers/RouteServiceProvider.php
Normal file
50
Modules/Document/app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Document\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||||
|
|
||||||
|
class RouteServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
protected string $name = 'Document';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called before routes are registered.
|
||||||
|
*
|
||||||
|
* Register any model bindings or pattern based filters.
|
||||||
|
*/
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the routes for the application.
|
||||||
|
*/
|
||||||
|
public function map(): void
|
||||||
|
{
|
||||||
|
$this->mapApiRoutes();
|
||||||
|
$this->mapWebRoutes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the "web" routes for the application.
|
||||||
|
*
|
||||||
|
* These routes all receive session state, CSRF protection, etc.
|
||||||
|
*/
|
||||||
|
protected function mapWebRoutes(): void
|
||||||
|
{
|
||||||
|
Route::middleware('web')->group(module_path($this->name, '/routes/web.php'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the "api" routes for the application.
|
||||||
|
*
|
||||||
|
* These routes are typically stateless.
|
||||||
|
*/
|
||||||
|
protected function mapApiRoutes(): void
|
||||||
|
{
|
||||||
|
Route::middleware('api')->prefix('api')->name('api.')->group(module_path($this->name, '/routes/api.php'));
|
||||||
|
}
|
||||||
|
}
|
0
Modules/Document/app/Services/.gitkeep
Normal file
0
Modules/Document/app/Services/.gitkeep
Normal file
49
Modules/Document/app/Services/DocumentService.php
Normal file
49
Modules/Document/app/Services/DocumentService.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Document\Services;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Modules\Document\Models\Document;
|
||||||
|
|
||||||
|
class DocumentService
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getAllCategories()
|
||||||
|
{
|
||||||
|
$query = Document::query();
|
||||||
|
return $query->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function storeDocument(array $documentData): Document
|
||||||
|
{
|
||||||
|
return DB::transaction(function () use ($documentData) {
|
||||||
|
$document = Document::create($documentData);
|
||||||
|
|
||||||
|
return $document;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDocumentById(int $id)
|
||||||
|
{
|
||||||
|
return Document::findOrFail($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateDocument(int $id, array $documentData)
|
||||||
|
{
|
||||||
|
$document = $this->getDocumentById($id);
|
||||||
|
|
||||||
|
return DB::transaction(function () use ($document, $documentData) {
|
||||||
|
$document->update($documentData);
|
||||||
|
return $document;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteDocument(int $id)
|
||||||
|
{
|
||||||
|
return DB::transaction(function () use ($id) {
|
||||||
|
$document = $this->getDocumentById($id);
|
||||||
|
$document->delete();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
30
Modules/Document/composer.json
Normal file
30
Modules/Document/composer.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "nwidart/document",
|
||||||
|
"description": "",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Nicolas Widart",
|
||||||
|
"email": "n.widart@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extra": {
|
||||||
|
"laravel": {
|
||||||
|
"providers": [],
|
||||||
|
"aliases": {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Modules\\Document\\": "app/",
|
||||||
|
"Modules\\Document\\Database\\Factories\\": "database/factories/",
|
||||||
|
"Modules\\Document\\Database\\Seeders\\": "database/seeders/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"Modules\\Document\\Tests\\": "tests/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
0
Modules/Document/config/.gitkeep
Normal file
0
Modules/Document/config/.gitkeep
Normal file
5
Modules/Document/config/config.php
Normal file
5
Modules/Document/config/config.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => 'Document',
|
||||||
|
];
|
0
Modules/Document/database/factories/.gitkeep
Normal file
0
Modules/Document/database/factories/.gitkeep
Normal file
0
Modules/Document/database/migrations/.gitkeep
Normal file
0
Modules/Document/database/migrations/.gitkeep
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('documents', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('title');
|
||||||
|
$table->string('file_path');
|
||||||
|
$table->unsignedBigInteger('documentable_id');
|
||||||
|
$table->string('documentable_type');
|
||||||
|
$table->index(['documentable_type', 'documentable_id']);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('documents');
|
||||||
|
}
|
||||||
|
};
|
0
Modules/Document/database/seeders/.gitkeep
Normal file
0
Modules/Document/database/seeders/.gitkeep
Normal file
16
Modules/Document/database/seeders/DocumentDatabaseSeeder.php
Normal file
16
Modules/Document/database/seeders/DocumentDatabaseSeeder.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Document\Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class DocumentDatabaseSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
// $this->call([]);
|
||||||
|
}
|
||||||
|
}
|
11
Modules/Document/module.json
Normal file
11
Modules/Document/module.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "Document",
|
||||||
|
"alias": "document",
|
||||||
|
"description": "",
|
||||||
|
"keywords": [],
|
||||||
|
"priority": 0,
|
||||||
|
"providers": [
|
||||||
|
"Modules\\Document\\Providers\\DocumentServiceProvider"
|
||||||
|
],
|
||||||
|
"files": []
|
||||||
|
}
|
15
Modules/Document/package.json
Normal file
15
Modules/Document/package.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vite build"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"axios": "^1.1.2",
|
||||||
|
"laravel-vite-plugin": "^0.7.5",
|
||||||
|
"sass": "^1.69.5",
|
||||||
|
"postcss": "^8.3.7",
|
||||||
|
"vite": "^4.0.0"
|
||||||
|
}
|
||||||
|
}
|
0
Modules/Document/resources/assets/js/app.js
Normal file
0
Modules/Document/resources/assets/js/app.js
Normal file
0
Modules/Document/resources/assets/sass/app.scss
Normal file
0
Modules/Document/resources/assets/sass/app.scss
Normal file
0
Modules/Document/resources/views/.gitkeep
Normal file
0
Modules/Document/resources/views/.gitkeep
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
@props(['dropzoneId', 'uploadUrl', 'inputName', 'message' => 'Drop files here or click to upload.', 'formId'])
|
||||||
|
<div class="row g-3">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="needsclick dropzone" id="{{ $dropzoneId }}">
|
||||||
|
<div class="dz-message">
|
||||||
|
<div class="mb-3">
|
||||||
|
<i class="display-5 text-muted ri-upload-cloud-2-fill"></i>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="fs-14">{{ $message }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@push('js')
|
||||||
|
<script>
|
||||||
|
Dropzone.autoDiscover = false;
|
||||||
|
window.uploadedDocumentMap = window.uploadedDocumentMap || {};
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
let myDropzone = new Dropzone("#{{ $dropzoneId }}", {
|
||||||
|
url: '{{ $uploadUrl }}',
|
||||||
|
maxFilesize: 5,
|
||||||
|
acceptedFiles: '.pdf,.jpeg,.jpg,.png,.gif',
|
||||||
|
addRemoveLinks: true,
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': "{{ csrf_token() }}"
|
||||||
|
},
|
||||||
|
success: function(file, response) {
|
||||||
|
$('#{{ $formId }}').append(
|
||||||
|
'<input type="hidden" name="{{ $inputName }}[]" value="' + response
|
||||||
|
.name + '">');
|
||||||
|
uploadedDocumentMap[file.name] = response.name;
|
||||||
|
},
|
||||||
|
removedfile: function(file) {
|
||||||
|
file.previewElement.remove();
|
||||||
|
var name = uploadedDocumentMap[file.name] || file.file_name;
|
||||||
|
$('#{{ $formId }}').find('input[name="{{ $inputName }}[]"][value="' +
|
||||||
|
name + '"]').remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endpush
|
88
Modules/Document/resources/views/document/form.blade.php
Normal file
88
Modules/Document/resources/views/document/form.blade.php
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<div class="card-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
|
||||||
|
<form method="POST" action="{{ route('documents.dropzone.upload') }}" class="dropzone" id="mainForm"
|
||||||
|
enctype="multipart/form-data">
|
||||||
|
@csrf
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
{{ html()->label('Title')->for('title') }}
|
||||||
|
{{ html()->span('*')->class('text-danger') }}
|
||||||
|
{{ html()->text('title')->id('docTitle')->class('form-control')->placeholder('Enter Title')->required() }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
{{ html()->label('Select Model')->class('form-label')->for('model') }}
|
||||||
|
{{ html()->span('*')->class('text-danger') }}
|
||||||
|
{{ html()->select('model')->id('modelSelect')->class('form-select')->required()->options(['' => '-- Select --'] + $modelOptions->toArray()) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="dropzone-previews mb-3"></div>
|
||||||
|
|
||||||
|
<div class="dz-message mb-3">
|
||||||
|
<p class="fs-14">Drop files here or click to upload.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="button" class="btn btn-primary" id="submitAll">Submit</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@push('js')
|
||||||
|
<script>
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
Dropzone.autoDiscover = false;
|
||||||
|
|
||||||
|
const myDropzone = new Dropzone("#mainForm", {
|
||||||
|
url: "{{ route('documents.dropzone.upload') }}",
|
||||||
|
autoProcessQueue: false,
|
||||||
|
uploadMultiple: true,
|
||||||
|
parallelUploads: 5,
|
||||||
|
maxFilesize: 5,
|
||||||
|
addRemoveLinks: true,
|
||||||
|
acceptedFiles: ".pdf,.doc,.docx,.jpg,.png",
|
||||||
|
paramName: "file[]",
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': document.querySelector('input[name="_token"]').value
|
||||||
|
},
|
||||||
|
init: function() {
|
||||||
|
const dz = this;
|
||||||
|
|
||||||
|
document.getElementById("submitAll").addEventListener("click", function(e) {
|
||||||
|
const title = document.getElementById('docTitle').value;
|
||||||
|
const model = document.getElementById('modelSelect').value;
|
||||||
|
|
||||||
|
if (!title || !model) {
|
||||||
|
alert("Please fill in both Title and Model.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dz.getQueuedFiles().length > 0) {
|
||||||
|
dz.processQueue();
|
||||||
|
} else {
|
||||||
|
alert("Please select at least one file.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dz.on("sending", function(file, xhr, formData) {
|
||||||
|
formData.append("title", document.getElementById('docTitle').value);
|
||||||
|
formData.append("model", document.getElementById('modelSelect').value);
|
||||||
|
});
|
||||||
|
|
||||||
|
dz.on("successmultiple", function(files, response) {
|
||||||
|
alert("Files uploaded successfully.");
|
||||||
|
dz.removeAllFiles();
|
||||||
|
document.getElementById('mainForm').reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
dz.on("errormultiple", function(files, response) {
|
||||||
|
alert("An error occurred during upload.");
|
||||||
|
console.error(response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endpush
|
50
Modules/Document/resources/views/document/index.blade.php
Normal file
50
Modules/Document/resources/views/document/index.blade.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="container-fluid">
|
||||||
|
<x-dashboard.breadcumb :title="$title" />
|
||||||
|
@if ($errors->any())
|
||||||
|
<x-flash-message type="danger" :messages="$errors->all()" />
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-6 col-xl-6">
|
||||||
|
<div class="card profile-card">
|
||||||
|
@include('document::document.form')
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- <div class="col-lg-xl-8 col-lg-9">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
@php
|
||||||
|
$columns = [
|
||||||
|
[
|
||||||
|
'title' => '<input type="checkbox" id="select-all">',
|
||||||
|
'data' => 'checkbox',
|
||||||
|
'name' => 'checkbox',
|
||||||
|
'orderable' => false,
|
||||||
|
'searchable' => false,
|
||||||
|
'printable' => false,
|
||||||
|
'exportable' => false,
|
||||||
|
],
|
||||||
|
['title' => 'Document', 'data' => 'name', 'name' => 'name'],
|
||||||
|
['title' => 'Type', 'data' => 'type', 'name' => 'type'],
|
||||||
|
['title' => 'Size', 'data' => 'size', 'name' => 'size'],
|
||||||
|
['title' => 'Upload Date', 'data' => 'created_at', 'name' => 'created_at'],
|
||||||
|
[
|
||||||
|
'title' => 'Action',
|
||||||
|
'data' => 'action',
|
||||||
|
'orderable' => false,
|
||||||
|
'searchable' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
<x-data-table-script :route="route('gallery.index')" :reorder="route('gallery.reorder')" :columns="$columns" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div> --}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
7
Modules/Document/resources/views/index.blade.php
Normal file
7
Modules/Document/resources/views/index.blade.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
@extends('document::layouts.master')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<h1>Hello World</h1>
|
||||||
|
|
||||||
|
<p>Module: {!! config('document.name') !!}</p>
|
||||||
|
@endsection
|
29
Modules/Document/resources/views/layouts/master.blade.php
Normal file
29
Modules/Document/resources/views/layouts/master.blade.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
|
||||||
|
<title>Document Module - {{ config('app.name', 'Laravel') }}</title>
|
||||||
|
|
||||||
|
<meta name="description" content="{{ $description ?? '' }}">
|
||||||
|
<meta name="keywords" content="{{ $keywords ?? '' }}">
|
||||||
|
<meta name="author" content="{{ $author ?? '' }}">
|
||||||
|
|
||||||
|
<!-- Fonts -->
|
||||||
|
<link rel="preconnect" href="https://fonts.bunny.net">
|
||||||
|
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
|
||||||
|
|
||||||
|
{{-- Vite CSS --}}
|
||||||
|
{{-- {{ module_vite('build-document', 'resources/assets/sass/app.scss', storage_path('vite.hot')) }} --}}
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
@yield('content')
|
||||||
|
|
||||||
|
{{-- Vite JS --}}
|
||||||
|
{{-- {{ module_vite('build-document', 'resources/assets/js/app.js', storage_path('vite.hot')) }} --}}
|
||||||
|
</body>
|
0
Modules/Document/routes/.gitkeep
Normal file
0
Modules/Document/routes/.gitkeep
Normal file
19
Modules/Document/routes/api.php
Normal file
19
Modules/Document/routes/api.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Modules\Document\Http\Controllers\DocumentController;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
* API Routes
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Here is where you can register API routes for your application. These
|
||||||
|
* routes are loaded by the RouteServiceProvider within a group which
|
||||||
|
* is assigned the "api" middleware group. Enjoy building your API!
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
|
||||||
|
Route::apiResource('document', DocumentController::class)->names('document');
|
||||||
|
});
|
20
Modules/Document/routes/web.php
Normal file
20
Modules/Document/routes/web.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Modules\Document\Http\Controllers\DocumentController;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Web Routes
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here is where you can register web routes for your application. These
|
||||||
|
| routes are loaded by the RouteServiceProvider within a group which
|
||||||
|
| contains the "web" middleware group. Now create something great!
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
Route::group(['middleware' => ['web', 'auth', 'permission'], 'prefix' => 'admin/'], function () {
|
||||||
|
Route::get('/documents', [DocumentController::class, 'index'])->name('documents.index');
|
||||||
|
Route::post('/documents/dropzone-upload', [DocumentController::class, 'dropzoneUpload'])->name('documents.dropzone.upload');
|
||||||
|
});
|
57
Modules/Document/vite.config.js
Normal file
57
Modules/Document/vite.config.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import { defineConfig } from 'vite';
|
||||||
|
import laravel from 'laravel-vite-plugin';
|
||||||
|
import { readdirSync, statSync } from 'fs';
|
||||||
|
import { join,relative,dirname } from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
build: {
|
||||||
|
outDir: '../../public/build-document',
|
||||||
|
emptyOutDir: true,
|
||||||
|
manifest: true,
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
laravel({
|
||||||
|
publicDirectory: '../../public',
|
||||||
|
buildDirectory: 'build-document',
|
||||||
|
input: [
|
||||||
|
__dirname + '/resources/assets/sass/app.scss',
|
||||||
|
__dirname + '/resources/assets/js/app.js'
|
||||||
|
],
|
||||||
|
refresh: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
// Scen all resources for assets file. Return array
|
||||||
|
//function getFilePaths(dir) {
|
||||||
|
// const filePaths = [];
|
||||||
|
//
|
||||||
|
// function walkDirectory(currentPath) {
|
||||||
|
// const files = readdirSync(currentPath);
|
||||||
|
// for (const file of files) {
|
||||||
|
// const filePath = join(currentPath, file);
|
||||||
|
// const stats = statSync(filePath);
|
||||||
|
// if (stats.isFile() && !file.startsWith('.')) {
|
||||||
|
// const relativePath = 'Modules/Document/'+relative(__dirname, filePath);
|
||||||
|
// filePaths.push(relativePath);
|
||||||
|
// } else if (stats.isDirectory()) {
|
||||||
|
// walkDirectory(filePath);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// walkDirectory(dir);
|
||||||
|
// return filePaths;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//const __filename = fileURLToPath(import.meta.url);
|
||||||
|
//const __dirname = dirname(__filename);
|
||||||
|
|
||||||
|
//const assetsDir = join(__dirname, 'resources/assets');
|
||||||
|
//export const paths = getFilePaths(assetsDir);
|
||||||
|
|
||||||
|
|
||||||
|
//export const paths = [
|
||||||
|
// 'Modules/Document/resources/assets/sass/app.scss',
|
||||||
|
// 'Modules/Document/resources/assets/js/app.js',
|
||||||
|
//];
|
@@ -226,6 +226,13 @@ return [
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'text' => 'Documents',
|
||||||
|
'url' => 'admin/document',
|
||||||
|
'icon' => 'ri-file-text-line',
|
||||||
|
'module' => 'Document',
|
||||||
|
'can' => ['document.index'],
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'text' => 'Resume Builder',
|
'text' => 'Resume Builder',
|
||||||
'url' => 'admin/resume',
|
'url' => 'admin/resume',
|
||||||
|
@@ -16,5 +16,6 @@
|
|||||||
"Template": true,
|
"Template": true,
|
||||||
"Admin": true,
|
"Admin": true,
|
||||||
"Drive": true,
|
"Drive": true,
|
||||||
"Sitemap": true
|
"Sitemap": true,
|
||||||
|
"Document": true
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
@@ -29,6 +29,8 @@
|
|||||||
<link href="{{ asset('assets/css/app.min.css') }}" rel="stylesheet" type="text/css" />
|
<link href="{{ asset('assets/css/app.min.css') }}" rel="stylesheet" type="text/css" />
|
||||||
<!-- custom Css-->
|
<!-- custom Css-->
|
||||||
<link href="{{ asset('assets/css/custom.min.css') }}" rel="stylesheet" type="text/css" />
|
<link href="{{ asset('assets/css/custom.min.css') }}" rel="stylesheet" type="text/css" />
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.css" />
|
||||||
|
|
||||||
@livewireStyles
|
@livewireStyles
|
||||||
|
|
||||||
@@ -117,6 +119,7 @@
|
|||||||
<script>
|
<script>
|
||||||
const app_url = "{{ config('app.url') }}";
|
const app_url = "{{ config('app.url') }}";
|
||||||
</script>
|
</script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.js"></script>
|
||||||
<script src="{{ asset('assets/libs/jquery/jquery-3.7.1.min.js') }}"></script>
|
<script src="{{ asset('assets/libs/jquery/jquery-3.7.1.min.js') }}"></script>
|
||||||
<script src="{{ asset('assets/libs/bootstrap/js/bootstrap.bundle.min.js') }}"></script>
|
<script src="{{ asset('assets/libs/bootstrap/js/bootstrap.bundle.min.js') }}"></script>
|
||||||
<script src="{{ asset('assets/libs/simplebar/simplebar.min.js') }}"></script>
|
<script src="{{ asset('assets/libs/simplebar/simplebar.min.js') }}"></script>
|
||||||
|
Reference in New Issue
Block a user