diff --git a/README.md b/README.md index f280bb6..0183548 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # Files Module -Multi-provider files manager. +Powerful asset management made easy. diff --git a/composer.json b/composer.json index 7432c42..3497871 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,11 @@ { "name": "anomaly/files-module", "type": "streams-addon", - "description": "Multi-provider files manager.", + "description": "Powerful asset management made easy.", "keywords": [ - "streams module", - "streams addon", - "module" + "files", + "module", + "streams" ], "homepage": "http://anomaly.is/", "license": "MIT", @@ -24,10 +24,5 @@ "psr-4": { "Anomaly\\FilesModule\\": "src/" } - }, - "extra": { - "branch-alias": { - "dev-1.1/master": "1.1.x-dev" - } } } diff --git a/migrations/2015_03_05_021725_anomaly.module.files__create_files_fields.php b/migrations/2015_03_05_021725_anomaly.module.files__create_files_fields.php index a032f11..e859185 100644 --- a/migrations/2015_03_05_021725_anomaly.module.files__create_files_fields.php +++ b/migrations/2015_03_05_021725_anomaly.module.files__create_files_fields.php @@ -33,12 +33,6 @@ class AnomalyModuleFilesCreateFilesFields extends Migration 'search' => 'anomaly.module.files::adapter.*' ] ], - 'parent' => [ - 'type' => 'anomaly.field_type.relationship', - 'config' => [ - 'related' => 'Anomaly\FilesModule\Folder\FolderModel' - ] - ], 'folder' => [ 'type' => 'anomaly.field_type.relationship', 'config' => [ @@ -51,11 +45,12 @@ class AnomalyModuleFilesCreateFilesFields extends Migration 'related' => 'Anomaly\FilesModule\Disk\DiskModel' ] ], + 'filename' => 'anomaly.field_type.text', 'entry' => 'anomaly.field_type.polymorphic', 'description' => 'anomaly.field_type.textarea', 'path' => 'anomaly.field_type.text', 'keywords' => 'anomaly.field_type.tags', - 'alt_text' => 'anomaly.field_type.text', + 'title' => 'anomaly.field_type.text', 'extension' => 'anomaly.field_type.text', 'width' => 'anomaly.field_type.text', 'height' => 'anomaly.field_type.text', diff --git a/migrations/2015_06_09_031343_anomaly.module.files__create_folders_stream.php b/migrations/2015_06_09_031343_anomaly.module.files__create_folders_stream.php index c8b3415..8bd371a 100644 --- a/migrations/2015_06_09_031343_anomaly.module.files__create_folders_stream.php +++ b/migrations/2015_06_09_031343_anomaly.module.files__create_folders_stream.php @@ -19,7 +19,8 @@ class AnomalyModuleFilesCreateFoldersStream extends Migration */ protected $stream = [ 'slug' => 'folders', - 'title_column' => 'name' + 'title_column' => 'name', + 'translatable' => true ]; /** @@ -29,15 +30,16 @@ class AnomalyModuleFilesCreateFoldersStream extends Migration */ protected $assignments = [ 'name' => [ - 'required' => true + 'required' => true, + 'translatable' => true ], - 'disk' => [ - 'required' => true + 'slug' => [ + 'required' => true, + 'unique' => true ], - 'path' => [ + 'disk' => [ 'required' => true - ], - 'parent' + ] ]; } diff --git a/migrations/2015_06_09_031351_anomaly.module.files__create_files_stream.php b/migrations/2015_06_09_031351_anomaly.module.files__create_files_stream.php index 32ed937..5fae6ee 100644 --- a/migrations/2015_06_09_031351_anomaly.module.files__create_files_stream.php +++ b/migrations/2015_06_09_031351_anomaly.module.files__create_files_stream.php @@ -19,7 +19,7 @@ class AnomalyModuleFilesCreateFilesStream extends Migration */ protected $stream = [ 'slug' => 'files', - 'title_column' => 'name' + 'title_column' => 'filename' ]; /** @@ -28,12 +28,15 @@ class AnomalyModuleFilesCreateFilesStream extends Migration * @var array */ protected $assignments = [ - 'name' => [ + 'filename' => [ 'required' => true ], 'disk' => [ 'required' => true ], + 'folder' => [ + 'required' => true + ], 'extension' => [ 'required' => true ], @@ -51,8 +54,7 @@ class AnomalyModuleFilesCreateFilesStream extends Migration ], 'description', 'keywords', - 'alt_text', - 'folder' + 'title' ]; } diff --git a/resources/lang/en/addon.php b/resources/lang/en/addon.php index b6db040..7199cc6 100644 --- a/resources/lang/en/addon.php +++ b/resources/lang/en/addon.php @@ -5,9 +5,10 @@ 'name' => 'Files Module', 'description' => 'Multi-provider files manager.', 'section' => [ + 'files' => 'Files', 'disks' => 'Disks', 'fields' => 'Fields', - 'browser' => 'Browser', + 'folders' => 'Folders', 'adapters' => 'Adapters', 'settings' => 'Settings' ] diff --git a/resources/lang/en/field.php b/resources/lang/en/field.php index 14a42b2..fb7bf13 100644 --- a/resources/lang/en/field.php +++ b/resources/lang/en/field.php @@ -1,23 +1,26 @@ [ - 'name' => 'Alt Text' - ], 'title' => [ 'name' => 'Title' ], 'name' => [ 'name' => 'Name' ], + 'filename' => [ + 'name' => 'Filename' + ], 'slug' => [ 'name' => 'Slug' ], 'size' => [ 'name' => 'Size' ], - 'caption' => [ - 'name' => 'Caption' + 'disk' => [ + 'name' => 'Disk' + ], + 'folder' => [ + 'name' => 'Folder' ], 'adapter' => [ 'name' => 'Adapter' diff --git a/resources/lang/en/message.php b/resources/lang/en/message.php index 11f05e6..370c7fc 100644 --- a/resources/lang/en/message.php +++ b/resources/lang/en/message.php @@ -1,6 +1,7 @@ 'Preview', 'new_folder' => 'New Folder', 'upload_files' => 'Upload Files', 'choose_field' => 'What field would you like to add?', diff --git a/src/Browser/Command/AddDiskBreadcrumb.php b/src/Browser/Command/AddDiskBreadcrumb.php deleted file mode 100644 index 683ca7f..0000000 --- a/src/Browser/Command/AddDiskBreadcrumb.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @author Ryan Thompson - * @package Anomaly\FilesModule\Browser\Command - */ -class AddDiskBreadcrumb implements SelfHandling -{ - - /** - * The disk interface. - * - * @var DiskInterface - */ - protected $disk; - - /** - * Create a new AddDiskBreadcrumb instance. - * - * @param DiskInterface $disk - */ - public function __construct(DiskInterface $disk) - { - $this->disk = $disk; - } - - /** - * Handle the command. - * - * @param BreadcrumbCollection $breadcrumbs - */ - public function handle(BreadcrumbCollection $breadcrumbs) - { - $breadcrumbs->add($this->disk->getName(), 'admin/files/browser/' . $this->disk->getSlug()); - } -} diff --git a/src/Browser/Table/BrowserTableBuilder.php b/src/Browser/Table/BrowserTableBuilder.php deleted file mode 100644 index bedfc90..0000000 --- a/src/Browser/Table/BrowserTableBuilder.php +++ /dev/null @@ -1,73 +0,0 @@ - - * @author Ryan Thompson - * @package Anomaly\FilesModule\Browser - */ -class BrowserTableBuilder extends MultipleTableBuilder -{ - - /** - * The table columns. - * - * @var array - */ - protected $columns = [ - [ - 'column' => 'Anomaly\FilesModule\Browser\Table\Column\PreviewColumn' - ], - [ - 'sortable' => true, - 'sort_column' => 'name', - 'heading' => 'anomaly.module.files::field.name.name', - 'column' => 'Anomaly\FilesModule\Browser\Table\Column\NameColumn' - ], - [ - 'heading' => 'anomaly.module.files::field.size.name', - 'column' => 'Anomaly\FilesModule\Browser\Table\Column\SizeColumn' - ], - [ - 'heading' => 'anomaly.module.files::field.mime_type.name', - 'column' => 'Anomaly\FilesModule\Browser\Table\Column\MimeTypeColumn' - ] - ]; - - /** - * The table buttons. - * - * @var array - */ - protected $buttons = [ - [ - 'button' => 'Anomaly\FilesModule\Browser\Table\Button\EditButton', - 'href' => 'admin/files/edit/{entry.id}' - ] - ]; - - /** - * The table actions. - * - * @var array - */ - protected $actions = [ - 'delete' - ]; - - /** - * The table options. - * - * @var array - */ - protected $options = [ - 'attributes' => [ - 'id' => 'browser' - ] - ]; - -} diff --git a/src/Browser/Table/BrowserTableFilters.php b/src/Browser/Table/BrowserTableFilters.php deleted file mode 100644 index 55a10c4..0000000 --- a/src/Browser/Table/BrowserTableFilters.php +++ /dev/null @@ -1,60 +0,0 @@ - - * @author Ryan Thompson - * @package Anomaly\FilesModule\Browser\Table - */ -class BrowserTableFilters -{ - - /** - * Handle the filters. - * - * @param BrowserTableBuilder $builder - */ - public function handle(BrowserTableBuilder $builder) - { - $builder->setFilters( - [ - 'name' => [ - 'filter' => 'input', - 'placeholder' => 'Name', - 'query' => function (Builder $query, FilterInterface $filter) { - $query->where('name', 'LIKE', '%' . $filter->getValue() . '%'); - } - ], - 'keywords' => [ - 'filter' => 'input', - 'placeholder' => 'Keywords', - 'query' => function (Builder $query, FilterInterface $filter, TableBuilder $builder) { - if ($builder instanceof FileTableBuilder) { - $query->where('keywords', 'LIKE', '%"' . $filter->getValue() . '"%'); - } else { - $query->where('id', 0); - } - } - ], - 'mime_type' => [ - 'filter' => 'input', - 'placeholder' => 'Mime Type', - 'query' => function (Builder $query, FilterInterface $filter, TableBuilder $builder) { - if ($builder instanceof FileTableBuilder) { - $query->where('mime_type', 'LIKE', '%' . $filter->getValue() . '%'); - } else { - $query->where('id', 0); - } - } - ] - ] - ); - } -} diff --git a/src/Browser/Table/Button/EditButton.php b/src/Browser/Table/Button/EditButton.php deleted file mode 100644 index f83c859..0000000 --- a/src/Browser/Table/Button/EditButton.php +++ /dev/null @@ -1,48 +0,0 @@ - - * @author Ryan Thompson - * @package Anomaly\FilesModule\Browser\Table\Button - */ -class EditButton extends Button -{ - - /** - * The button text. - * - * @var null|string - */ - protected $text = 'streams::button.edit'; - - /** - * The button icon. - * - * @var null|string - */ - protected $icon = 'pencil'; - - /** - * The button type. - * - * @var string - */ - protected $type = 'warning'; - - /** - * Return the enabled flag. - * - * @return bool - */ - public function isEnabled() - { - return $this->entry instanceof FileInterface || $this->entry instanceof FolderInterface; - } -} diff --git a/src/Browser/Table/Column/MimeTypeColumn.php b/src/Browser/Table/Column/MimeTypeColumn.php deleted file mode 100644 index 0d2f72f..0000000 --- a/src/Browser/Table/Column/MimeTypeColumn.php +++ /dev/null @@ -1,33 +0,0 @@ - - * @author Ryan Thompson - * @package Anomaly\FilesModule\Browser\Table\Column - */ -class MimeTypeColumn extends Column -{ - - /** - * Get the value. - * - * @return string - */ - public function getValue() - { - if ($this->entry instanceof FolderInterface) { - return '-'; - } - - if ($this->entry instanceof FileInterface) { - return $this->entry->getMimeType(); - } - } -} diff --git a/src/Browser/Table/Column/NameColumn.php b/src/Browser/Table/Column/NameColumn.php deleted file mode 100644 index b9fafc3..0000000 --- a/src/Browser/Table/Column/NameColumn.php +++ /dev/null @@ -1,63 +0,0 @@ - - * @author Ryan Thompson - * @package Anomaly\FilesModule\Browser\Table\Column - */ -class NameColumn extends Column -{ - - /** - * The decorator. - * - * @var Decorator - */ - protected $decorator; - - /** - * Create a new NameColumn instance. - * - * @param Decorator $decorator - */ - public function __construct(Decorator $decorator) - { - $this->decorator = $decorator; - } - - /** - * Get the value. - * - * @return string - */ - public function getValue() - { - /* @var EntryPresenter $object */ - $object = $this->decorator->decorate($this->entry); - - if ($this->entry instanceof FileInterface) { - - $value = $object->viewLink(); - - if ($alt = $this->entry->getAlt()) { - $value .= ' (' . $alt . ')'; - } - - if ($description = $this->entry->getDescription()) { - $value .= '
— ' . $description; - } - - return $value; - } - - return $object->viewLink(); - } -} diff --git a/src/Browser/Table/Column/PreviewColumn.php b/src/Browser/Table/Column/PreviewColumn.php deleted file mode 100644 index eee72e1..0000000 --- a/src/Browser/Table/Column/PreviewColumn.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @author Ryan Thompson - * @package Anomaly\FilesModule\Browser\Table\Column - */ -class PreviewColumn extends Column -{ - - /** - * The icon registry. - * - * @var IconRegistry - */ - protected $icons; - - /** - * Create a new PreviewColumn instance. - * - * @param IconRegistry $icons - */ - public function __construct(IconRegistry $icons) - { - $this->icons = $icons; - } - - /** - * Get the value. - * - * @return string - */ - public function getValue() - { - if ($this->entry instanceof DiskInterface) { - return ''; - } - - if ($this->entry instanceof FolderInterface) { - return ''; - } - - if ($this->entry instanceof FileInterface) { - return ''; - } - } -} diff --git a/src/Browser/Table/Column/SizeColumn.php b/src/Browser/Table/Column/SizeColumn.php deleted file mode 100644 index 64ff2a5..0000000 --- a/src/Browser/Table/Column/SizeColumn.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @author Ryan Thompson - * @package Anomaly\FilesModule\Browser\Table\Column - */ -class SizeColumn extends Column -{ - - /** - * The decorator. - * - * @var Decorator - */ - protected $decorator; - - /** - * Create a new SizeColumn instance. - * - * @param Decorator $decorator - */ - public function __construct(Decorator $decorator) - { - $this->decorator = $decorator; - } - - /** - * Get the value. - * - * @return string - */ - public function getValue() - { - $object = $this->decorator->decorate($this->entry); - - if ($object instanceof FolderPresenter) { - return '-'; - } - - if ($object instanceof FilePresenter) { - return $object->readableSize(); - } - } -} diff --git a/src/Disk/Contract/DiskInterface.php b/src/Disk/Contract/DiskInterface.php index c2c40df..dc2791f 100644 --- a/src/Disk/Contract/DiskInterface.php +++ b/src/Disk/Contract/DiskInterface.php @@ -3,6 +3,8 @@ use Anomaly\FilesModule\Adapter\AdapterExtension; use Anomaly\FilesModule\Adapter\AdapterFilesystem; use Anomaly\FilesModule\Adapter\Contract\AdapterInterface; +use Anomaly\Streams\Platform\Addon\Extension\Extension; +use Anomaly\Streams\Platform\Entry\Contract\EntryInterface; use Anomaly\Streams\Platform\Stream\Contract\StreamInterface; /** @@ -13,25 +15,9 @@ * @author Ryan Thompson * @package Anomaly\FilesModule\Disk\Contract */ -interface DiskInterface +interface DiskInterface extends EntryInterface { - /** - * Return the disk's path. - * - * @param null $path - * @return string - */ - public function path($path = null); - - /** - * Return the disk's browser path. - * - * @param null $path - * @return string - */ - public function browserPath($path = null); - /** * Return the disk's filesystem. * @@ -39,13 +25,6 @@ public function browserPath($path = null); */ public function filesystem(); - /** - * Get the ID. - * - * @return int - */ - public function getId(); - /** * Get the name. * @@ -63,7 +42,7 @@ public function getSlug(); /** * Get the adapter. * - * @return AdapterInterface + * @return AdapterInterface|Extension */ public function getAdapter(); diff --git a/src/Disk/DiskModel.php b/src/Disk/DiskModel.php index db13d4f..5fe8553 100644 --- a/src/Disk/DiskModel.php +++ b/src/Disk/DiskModel.php @@ -5,6 +5,7 @@ use Anomaly\FilesModule\Adapter\Contract\AdapterInterface; use Anomaly\FilesModule\Disk\Command\GetDiskEntriesStream; use Anomaly\FilesModule\Disk\Contract\DiskInterface; +use Anomaly\Streams\Platform\Addon\Extension\Extension; use Anomaly\Streams\Platform\Model\Files\FilesDisksEntryModel; use Anomaly\Streams\Platform\Stream\Contract\StreamInterface; @@ -36,28 +37,6 @@ protected static function boot() parent::boot(); } - /** - * Return the disk's path. - * - * @param null $path - * @return string - */ - public function path($path = null) - { - return trim($this->getSlug() . '://' . ($path ? $path : $path), '/'); - } - - /** - * Return the disk's browser path. - * - * @param null $path - * @return string - */ - public function browserPath($path = null) - { - return trim($this->getSlug() . '/' . ($path ? $path : $path), '/'); - } - /** * Return the disk's filesystem. * @@ -91,7 +70,7 @@ public function getSlug() /** * Get the adapter. * - * @return AdapterInterface + * @return AdapterInterface|Extension */ public function getAdapter() { diff --git a/src/File/Contract/FileInterface.php b/src/File/Contract/FileInterface.php index 80cb021..399f68c 100644 --- a/src/File/Contract/FileInterface.php +++ b/src/File/Contract/FileInterface.php @@ -19,13 +19,6 @@ interface FileInterface extends EntryInterface { - /** - * Return a hash of the file. - * - * @return string - */ - public function hash(); - /** * Return the type of the file. * @@ -33,49 +26,6 @@ public function hash(); */ public function type(); - /** - * Return the file's path. - * - * @return string - */ - public function path(); - - /** - * Return the file's path on it's disk. - * - * @return string - */ - public function diskPath(); - - /** - * Return the file's public path. - * - * @return string - */ - public function publicPath(); - - /** - * Return the file's image path. - * - * @param array $parameters - * @return string - */ - public function imagePath(array $parameters = []); - - /** - * Return the file's stream path. - * - * @return string - */ - public function streamPath(); - - /** - * Return the file's download path. - * - * @return string - */ - public function downloadPath(); - /** * Return the file resource. * @@ -91,25 +41,18 @@ public function resource(); public function image(); /** - * Return the last modified datetime. - * - * @return Carbon - */ - public function lastModified(); - - /** - * Get the alt attribute. + * Get the title. * * @return string */ - public function getAlt(); + public function getTitle(); /** - * Get the name. + * Get the filename. * * @return string */ - public function getName(); + public function getFilename(); /** * Get the related disk. diff --git a/src/File/Contract/FileRepositoryInterface.php b/src/File/Contract/FileRepositoryInterface.php index 1eaec34..6fdeef5 100644 --- a/src/File/Contract/FileRepositoryInterface.php +++ b/src/File/Contract/FileRepositoryInterface.php @@ -2,7 +2,7 @@ use Anomaly\FilesModule\Disk\Contract\DiskInterface; use Anomaly\FilesModule\Folder\Contract\FolderInterface; -use Anomaly\Streams\Platform\Model\EloquentModel; +use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface; /** * Interface FileRepositoryInterface @@ -12,40 +12,16 @@ * @author Ryan Thompson * @package Anomaly\FilesModule\File\Contract */ -interface FileRepositoryInterface +interface FileRepositoryInterface extends EntryRepositoryInterface { /** - * Create a new file. + * Find a file by it's filename. * - * @param array $attributes - * @return FileInterface - */ - public function create(array $attributes); - - /** - * Find a file by it's ID. - * - * @param $id - * @return null|FileInterface - */ - public function find($id); - - /** - * Find a file by it's name. - * - * @param $name + * @param $filename * @param DiskInterface $disk * @param FolderInterface $folder * @return null|FileInterface */ - public function findByName($name, DiskInterface $disk, FolderInterface $folder = null); - - /** - * Delete a file. - * - * @param FileInterface|EloquentModel $file - * @return bool - */ - public function delete(FileInterface $file); + public function findByFilename($filename, DiskInterface $disk, FolderInterface $folder = null); } diff --git a/src/File/FileDownloader.php b/src/File/FileDownloader.php index fe0aa27..7259b25 100644 --- a/src/File/FileDownloader.php +++ b/src/File/FileDownloader.php @@ -37,7 +37,7 @@ public function make(FileInterface $file) { $response = parent::make($file); - $response->headers->set('Content-disposition', 'attachment; filename=' . $file->getName()); + $response->headers->set('Content-disposition', 'attachment; filename=' . $file->getFilename()); return $response->setContent($this->manager->read($file->diskPath())); } diff --git a/src/File/FileLocator.php b/src/File/FileLocator.php index bc68099..a800dff 100644 --- a/src/File/FileLocator.php +++ b/src/File/FileLocator.php @@ -67,7 +67,7 @@ public function locate($disk, $path) $folder = dirname($path) !== '.' ? $this->folders->findByPath(dirname($path), $disk) : null; - if (!$file = $this->files->findByName(basename($path), $disk, $folder)) { + if (!$file = $this->files->findByFilename(basename($path), $disk, $folder)) { return null; } diff --git a/src/File/FileModel.php b/src/File/FileModel.php index 5735c9f..d27ff15 100644 --- a/src/File/FileModel.php +++ b/src/File/FileModel.php @@ -6,7 +6,6 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryInterface; use Anomaly\Streams\Platform\Image\Image; use Anomaly\Streams\Platform\Model\Files\FilesFilesEntryModel; -use Carbon\Carbon; use League\Flysystem\File; use League\Flysystem\MountManager; @@ -48,16 +47,6 @@ protected static function boot() self::observe('Anomaly\FilesModule\File\FileObserver'); } - /** - * Return a hash of the file. - * - * @return string - */ - public function hash() - { - return md5(json_encode($this->getAttributes())); - } - /** * Return the type of the file. * @@ -70,100 +59,6 @@ public function type() return array_shift($parts); } - /** - * Return the file's path. - * - * @return string - */ - public function path() - { - if ($folder = $this->getFolder()) { - return $folder->path($this->getName()); - } - - return $this->getName(); - } - - /** - * Return the file's path on it's disk. - * - * @return string - */ - public function diskPath() - { - $disk = $this->getDisk(); - - if ($folder = $this->getFolder()) { - return $disk->path($folder->path($this->getName())); - } - - return $disk->path($this->getName()); - } - - /** - * Return the file's public path. - * - * @return string - */ - public function publicPath() - { - $disk = $this->getDisk(); - $path = $this->path(); - - return 'files/get/' . $disk->getSlug() . '/' . $path; - } - - /** - * Return the file's image path. - * - * @param array $parameters - * @return string - */ - public function imagePath(array $parameters = []) - { - $disk = $this->getDisk(); - $path = $this->path(); - - $query = http_build_query( - array_map( - function ($value) { - return implode(',', (array)$value); - }, - $parameters - ), - '', - '&' - ); - - return 'files/image/' . $disk->getSlug() . '/' . $path . ($query ? '?' . $query : null); - } - - /** - * Return the file's stream path. - * - * @return string - */ - public function streamPath() - { - $disk = $this->getDisk(); - $path = $this->path(); - - return 'files/stream/' . $disk->getSlug() . '/' . $path; - } - - /** - * Return the file's download path. - * - * @return string - */ - public function downloadPath() - { - $disk = $this->getDisk(); - $path = $this->path(); - - return 'files/download/' . $disk->getSlug() . '/' . $path; - } - /** * Return the file resource. * @@ -171,16 +66,19 @@ public function downloadPath() */ public function resource() { - $disk = $this->getDisk(); + $disk = $this->getDisk(); + $folder = $this->getFolder(); + + $path = $disk->getSlug() . '://' . $folder->getSlug() . '/' . $this->getFilename(); /* @var MountManager $manager */ $manager = app('League\Flysystem\MountManager'); - if (!$manager->has($disk->path($this->path()))) { + if (!$manager->has($path)) { return null; } - return $manager->get($disk->path($this->path())); + return $manager->get($path); } /** @@ -190,40 +88,35 @@ public function resource() */ public function image() { + $disk = $this->getDisk(); + $folder = $this->getFolder(); + + $path = $disk->getSlug() . '://' . $folder->getSlug() . '/' . $this->getFilename(); + /* @var Image $image */ $image = app('Anomaly\Streams\Platform\Image\Image'); - return $image->make($this->diskPath())->setOutput('image'); - } - - /** - * Return the last modified datetime. - * - * @return Carbon - */ - public function lastModified() - { - return $this->last_modified ?: $this->created_at; + return $image->make($path)->setOutput('image'); } /** - * Get the alt attribute. + * Get the title. * * @return string */ - public function getAlt() + public function getTitle() { - return $this->alt; + return $this->title; } /** - * Get the name. + * Get the filename. * * @return string */ - public function getName() + public function getFilename() { - return $this->name; + return $this->filename; } /** diff --git a/src/File/FilePresenter.php b/src/File/FilePresenter.php index 3310e3a..a2dab4a 100644 --- a/src/File/FilePresenter.php +++ b/src/File/FilePresenter.php @@ -77,32 +77,22 @@ public function readableSize($decimals = 2) */ public function thumbnail($width = 48, $height = 48) { - return $this->object->image()->fit($width, $height); + return $this->object->image()->fit($width, $height)->class('img-rounded'); } /** - * Return the view link. + * Return a file preview. * * @return string */ - public function viewLink() + public function preview() { - return app('html')->link($this->object->publicPath(), $this->object->getName(), ['target' => '_blank']); - } + $output = ''; - /** - * Return the URL for the file. - * - * @param array $attributes - * @param null $secure - * @return string - */ - public function url(array $attributes = [], $secure = null) - { - if ($secure === null) { - $secure = $this->request->isSecure(); + if ($this->object->type() == 'image') { + $output = $this->thumbnail(32, 32); } - return $this->url->to($this->object->publicPath(), $attributes, $secure); + return $output; } } diff --git a/src/File/FileRepository.php b/src/File/FileRepository.php index d759f3e..13b8115 100644 --- a/src/File/FileRepository.php +++ b/src/File/FileRepository.php @@ -4,7 +4,7 @@ use Anomaly\FilesModule\File\Contract\FileInterface; use Anomaly\FilesModule\File\Contract\FileRepositoryInterface; use Anomaly\FilesModule\Folder\Contract\FolderInterface; -use Anomaly\Streams\Platform\Model\EloquentModel; +use Anomaly\Streams\Platform\Entry\EntryRepository; /** * Class FileRepository @@ -14,7 +14,7 @@ * @author Ryan Thompson * @package Anomaly\FilesModule\File */ -class FileRepository implements FileRepositoryInterface +class FileRepository extends EntryRepository implements FileRepositoryInterface { /** @@ -35,52 +35,19 @@ function __construct(FileModel $model) } /** - * Create a new file. + * Find a file by it's filename. * - * @param array $attributes - * @return FileInterface - */ - public function create(array $attributes) - { - return $this->model->create($attributes); - } - - /** - * Find a file by it's ID. - * - * @param $id - * @return null|FileInterface - */ - public function find($id) - { - return $this->model->find($id); - } - - /** - * Find a file by it's name. - * - * @param $name + * @param $filename * @param DiskInterface $disk * @param FolderInterface $folder * @return null|FileInterface */ - public function findByName($name, DiskInterface $disk, FolderInterface $folder = null) + public function findByFilename($filename, DiskInterface $disk, FolderInterface $folder = null) { return $this->model - ->where('name', $name) + ->where('filename', $filename) ->where('disk_id', $disk->getId()) ->where('folder_id', $folder ? $folder->getId() : null) ->first(); } - - /** - * Delete a file. - * - * @param FileInterface|EloquentModel $file - * @return bool - */ - public function delete(FileInterface $file) - { - return $file->delete(); - } } diff --git a/src/File/FileSynchronizer.php b/src/File/FileSynchronizer.php index 967bb49..8274aa1 100644 --- a/src/File/FileSynchronizer.php +++ b/src/File/FileSynchronizer.php @@ -55,10 +55,10 @@ public function sync(File $resource, DiskInterface $disk) { $folder = $this->syncFolder($resource, $disk); - if (!$file = $this->files->findByName(basename($resource->getPath()), $disk, $folder)) { + if (!$file = $this->files->findByFilename(basename($resource->getPath()), $disk, $folder)) { $file = $this->files->create( [ - 'name' => basename($resource->getPath()), + 'filename' => basename($resource->getPath()), 'folder_id' => $folder ? $folder->getId() : null, 'disk_id' => $disk->getId(), 'size' => $resource->getSize(), @@ -91,7 +91,7 @@ protected function syncFolder(File $resource, DiskInterface $disk) $folder = null; foreach (explode('/', $path) as $name) { - if (!$folder = $this->folders->findByName($name, $disk, $parent)) { + if (!$folder = $this->folders->findBySlug($name)) { $folder = $this->folders->create( [ 'name' => $name, diff --git a/src/File/Form/FileEntryFormSections.php b/src/File/Form/FileEntryFormSections.php index e163017..a5fc4e1 100644 --- a/src/File/Form/FileEntryFormSections.php +++ b/src/File/Form/FileEntryFormSections.php @@ -24,9 +24,7 @@ public function handle(FileEntryFormBuilder $builder) $fileForm = $builder->getChildForm('file'); /* @var EntryInterface $entry */ - /* @var EntryInterface $file */ $entry = $entryForm->getFormEntry(); - $file = $fileForm->getFormEntry(); $builder->setSections( [ @@ -34,12 +32,12 @@ public function handle(FileEntryFormBuilder $builder) 'tabs' => [ 'file' => [ 'title' => 'anomaly.module.files::tab.file', - 'fields' => function () use ($file) { + 'fields' => function () use ($fileForm) { return array_map( - function ($slug) { - return 'file_' . $slug; + function ($field) { + return 'file_' . $field['field']; }, - $file->getAssignmentFieldSlugs() + $fileForm->getFields() ); } ], diff --git a/src/File/Form/FileFormBuilder.php b/src/File/Form/FileFormBuilder.php index e747579..9cc3523 100644 --- a/src/File/Form/FileFormBuilder.php +++ b/src/File/Form/FileFormBuilder.php @@ -20,8 +20,7 @@ class FileFormBuilder extends FormBuilder */ protected $fields = [ 'title', - 'alt_text', - 'name' => [ + 'filename' => [ 'disabled' => true ], 'keywords', diff --git a/src/File/Table/FileTableBuilder.php b/src/File/Table/FileTableBuilder.php index a4723e8..f37a905 100644 --- a/src/File/Table/FileTableBuilder.php +++ b/src/File/Table/FileTableBuilder.php @@ -1,9 +1,6 @@ [ - 'name' => 'ASC' - ] + protected $filters = [ + 'folder', + 'filename', + 'title', + 'keywords' ]; /** - * Fired when the table is ready to build. + * The table columns. * - * @throws \Exception - */ - public function onReady() - { - if (!$this->getDisk()) { - throw new \Exception('The $disk parameter is required.'); - } - } - - /** - * Fired just before querying. - * - * @param Builder $query - */ - public function onQuerying(Builder $query) - { - $disk = $this->getDisk(); - - // Limit results to the desired disk. - $query->where('disk_id', $disk->getId()); - - // Limit results to the desired folder if any. - if ($folder = $this->getFolder()) { - $query->where('folder_id', $folder->getId()); - } else { - $query->where('folder_id', null); - } - } - - /** - * Get the disk. - * - * @return DiskInterface - */ - public function getDisk() - { - return $this->disk; - } - - /** - * Set the disk interface. - * - * @param DiskInterface $disk - * @return $this + * @var array */ - public function setDisk(DiskInterface $disk) - { - $this->disk = $disk; - - return $this; - } + protected $columns = [ + 'entry.preview' => [ + 'heading' => 'anomaly.module.files::message.preview' + ], + 'entry.edit_link', + 'folder', + 'title', + 'size' => [ + 'value' => 'entry.readable_size' + ], + 'mime_type', + 'entry.keywords.labels' + ]; /** - * Get the folder. + * The table buttons. * - * @return FolderInterface + * @var array */ - public function getFolder() - { - return $this->folder; - } + protected $buttons = [ + 'view' + ]; /** - * Set the folder. + * The table buttons. * - * @param FolderInterface $folder - * @return $this + * @var array */ - public function setFolder(FolderInterface $folder) - { - $this->folder = $folder; + protected $actions = [ + 'delete', + 'edit' + ]; - return $this; - } } diff --git a/src/File/Upload/UploadFormFields.php b/src/File/Upload/UploadFormFields.php index cfd1224..15256ae 100644 --- a/src/File/Upload/UploadFormFields.php +++ b/src/File/Upload/UploadFormFields.php @@ -27,7 +27,7 @@ public function handle(UploadFormBuilder $builder) 'type' => 'anomaly.field_type.files', 'config' => [ 'disk' => $disk->getSlug(), - 'path' => $folder ? $folder->path() : null, + 'path' => $folder->getSlug(), 'max' => 32 ] ] diff --git a/src/FilesModule.php b/src/FilesModule.php index 11c5281..21279c6 100644 --- a/src/FilesModule.php +++ b/src/FilesModule.php @@ -26,25 +26,24 @@ class FilesModule extends Module * @var array */ protected $sections = [ - 'browser' => [ + 'files' => [ 'buttons' => [ - 'upload' => [ - 'button' => 'success', - 'icon' => 'upload', + 'upload' => [ 'data-toggle' => 'modal', + 'icon' => 'upload', + 'button' => 'success', 'data-target' => '#modal-large', - 'href' => 'admin/files/upload{request.route.compiled.parameters_suffix}', 'text' => 'module::button.upload', - 'enabled' => 'admin/files/browser/*' - ], - 'new_folder' => [ - 'data-toggle' => 'modal', - 'data-target' => '#modal', - 'enabled' => 'admin/files/browser/*', - 'href' => 'admin/files/folders/create{request.route.compiled.parameters_suffix}' + 'href' => 'admin/files/upload/local/test', + 'disabled' => 'Anomaly\FilesModule\FilesModuleUploadable@handle', ] ] ], + 'folders' => [ + 'buttons' => [ + 'new_folder' + ] + ], 'disks' => [ 'buttons' => [ 'new_disk' => [ diff --git a/src/FilesModuleServiceProvider.php b/src/FilesModuleServiceProvider.php index 62f08bc..45de2a0 100644 --- a/src/FilesModuleServiceProvider.php +++ b/src/FilesModuleServiceProvider.php @@ -41,6 +41,30 @@ class FilesModuleServiceProvider extends AddonServiceProvider * @var array */ protected $routes = [ + 'admin/files' => 'Anomaly\FilesModule\Http\Controller\Admin\FilesController@index', + 'admin/files/edit/{id}' => 'Anomaly\FilesModule\Http\Controller\Admin\FilesController@edit', + 'admin/files/folders' => 'Anomaly\FilesModule\Http\Controller\Admin\FoldersController@index', + 'admin/files/folders/create' => 'Anomaly\FilesModule\Http\Controller\Admin\FoldersController@create', + 'admin/files/folders/edit/{id}' => 'Anomaly\FilesModule\Http\Controller\Admin\FoldersController@edit', + 'admin/files/disks' => 'Anomaly\FilesModule\Http\Controller\Admin\DisksController@index', + 'admin/files/disks/choose' => 'Anomaly\FilesModule\Http\Controller\Admin\DisksController@choose', + 'admin/files/disks/create' => 'Anomaly\FilesModule\Http\Controller\Admin\DisksController@create', + 'admin/files/disks/edit/{id}' => 'Anomaly\FilesModule\Http\Controller\Admin\DisksController@edit', + 'admin/files/fields' => 'Anomaly\FilesModule\Http\Controller\Admin\FieldsController@index', + 'admin/files/fields/choose' => 'Anomaly\FilesModule\Http\Controller\Admin\FieldsController@choose', + 'admin/files/fields/create' => 'Anomaly\FilesModule\Http\Controller\Admin\FieldsController@create', + 'admin/files/fields/edit/{id}' => 'Anomaly\FilesModule\Http\Controller\Admin\FieldsController@edit', + 'admin/files/disks/assignments/{id}' => 'Anomaly\FilesModule\Http\Controller\Admin\AssignmentsController@index', + 'admin/files/disks/assignments/{id}/choose' => 'Anomaly\FilesModule\Http\Controller\Admin\AssignmentsController@choose', + 'admin/files/disks/assignments/{id}/create/{field}' => 'Anomaly\FilesModule\Http\Controller\Admin\AssignmentsController@create', + 'admin/files/disks/assignments/{id}/edit/{assignment}' => 'Anomaly\FilesModule\Http\Controller\Admin\AssignmentsController@edit', + 'admin/files/upload/{disk}/{path?}' => [ + 'uses' => 'Anomaly\FilesModule\Http\Controller\Admin\FilesController@upload', + 'constraints' => [ + 'disk' => '^[a-z0-9_]+$', + 'path' => '(.*)' + ] + ], 'files/get/{disk}/{path}' => [ 'uses' => 'Anomaly\FilesModule\Http\Controller\FilesController@read', 'constraints' => [ @@ -68,49 +92,7 @@ class FilesModuleServiceProvider extends AddonServiceProvider 'disk' => '^[a-z0-9_]+$', 'path' => '(.*)' ] - ], - 'admin/files' => 'Anomaly\FilesModule\Http\Controller\Admin\BrowserController@index', - 'admin/files/browser/{disk?}/{path?}' => [ - 'uses' => 'Anomaly\FilesModule\Http\Controller\Admin\BrowserController@index', - 'constraints' => [ - 'disk' => '^[a-z0-9_]+$', - 'path' => '(.*)' - ] - ], - 'admin/files/view/{disk}/{path}' => [ - 'uses' => 'Anomaly\FilesModule\Http\Controller\Admin\BrowserController@view', - 'constraints' => [ - 'disk' => '^[a-z0-9_]+$', - 'path' => '(.*)' - ] - ], - 'admin/files/folders/create/{disk}/{path?}' => [ - 'uses' => 'Anomaly\FilesModule\Http\Controller\Admin\FoldersController@create', - 'constraints' => [ - 'disk' => '^[a-z0-9_]+$', - 'path' => '(.*)' - ] - ], - 'admin/files/upload/{disk}/{path?}' => [ - 'uses' => 'Anomaly\FilesModule\Http\Controller\Admin\FilesController@upload', - 'constraints' => [ - 'disk' => '^[a-z0-9_]+$', - 'path' => '(.*)' - ] - ], - 'admin/files/edit/{id}' => 'Anomaly\FilesModule\Http\Controller\Admin\FilesController@edit', - 'admin/files/disks' => 'Anomaly\FilesModule\Http\Controller\Admin\DisksController@index', - 'admin/files/disks/choose' => 'Anomaly\FilesModule\Http\Controller\Admin\DisksController@choose', - 'admin/files/disks/create' => 'Anomaly\FilesModule\Http\Controller\Admin\DisksController@create', - 'admin/files/disks/edit/{id}' => 'Anomaly\FilesModule\Http\Controller\Admin\DisksController@edit', - 'admin/files/fields' => 'Anomaly\FilesModule\Http\Controller\Admin\FieldsController@index', - 'admin/files/fields/choose' => 'Anomaly\FilesModule\Http\Controller\Admin\FieldsController@choose', - 'admin/files/fields/create' => 'Anomaly\FilesModule\Http\Controller\Admin\FieldsController@create', - 'admin/files/fields/edit/{id}' => 'Anomaly\FilesModule\Http\Controller\Admin\FieldsController@edit', - 'admin/files/disks/assignments/{id}' => 'Anomaly\FilesModule\Http\Controller\Admin\AssignmentsController@index', - 'admin/files/disks/assignments/{id}/choose' => 'Anomaly\FilesModule\Http\Controller\Admin\AssignmentsController@choose', - 'admin/files/disks/assignments/{id}/create/{field}' => 'Anomaly\FilesModule\Http\Controller\Admin\AssignmentsController@create', - 'admin/files/disks/assignments/{id}/edit/{assignment}' => 'Anomaly\FilesModule\Http\Controller\Admin\AssignmentsController@edit', + ] ]; } diff --git a/src/FilesModuleUploadable.php b/src/FilesModuleUploadable.php new file mode 100644 index 0000000..e808fcf --- /dev/null +++ b/src/FilesModuleUploadable.php @@ -0,0 +1,24 @@ + + * @author Ryan Thompson + * @package Anomaly\FilesModule + */ +class FilesModuleUploadable +{ + + /** + * @param Request $request + * @return mixed + */ + public function handle(Request $request) + { + return !(bool)$request->get('filter_folder'); + } +} diff --git a/src/Browser/Command/AddFolderBreadcrumbs.php b/src/Folder/Command/DeleteDirectory.php similarity index 51% rename from src/Browser/Command/AddFolderBreadcrumbs.php rename to src/Folder/Command/DeleteDirectory.php index 76546d6..72560d5 100644 --- a/src/Browser/Command/AddFolderBreadcrumbs.php +++ b/src/Folder/Command/DeleteDirectory.php @@ -1,18 +1,18 @@ - * @author Ryan Thompson - * @package Anomaly\FilesModule\Browser\Command + * @package Anomaly\FilesModule\Folder\Command */ -class AddFolderBreadcrumbs implements SelfHandling +class DeleteDirectory implements SelfHandling { /** @@ -23,7 +23,7 @@ class AddFolderBreadcrumbs implements SelfHandling protected $folder; /** - * Create a new AddFolderBreadcrumbs instance. + * Create a new DeleteDirectory instance. * * @param FolderInterface $folder */ @@ -35,16 +35,12 @@ public function __construct(FolderInterface $folder) /** * Handle the command. * - * @param BreadcrumbCollection $breadcrumbs + * @param MountManager $manager */ - public function handle(BreadcrumbCollection $breadcrumbs) + public function handle(MountManager $manager) { $disk = $this->folder->getDisk(); - $uri = 'admin/files/browser/' . $disk->getSlug(); - - foreach (explode('/', $this->folder->path()) as $name) { - $breadcrumbs->add($name, $uri = $uri . '/' . $name); - } + $manager->deleteDir($disk->getSlug() . '://' . $this->folder->getSlug()); } } diff --git a/src/Folder/Command/DeleteFiles.php b/src/Folder/Command/DeleteFiles.php new file mode 100644 index 0000000..f2a202a --- /dev/null +++ b/src/Folder/Command/DeleteFiles.php @@ -0,0 +1,46 @@ + + * @author Ryan Thompson + * @package Anomaly\FilesModule\Folder\Command + */ +class DeleteFiles implements SelfHandling +{ + + /** + * The folder interface. + * + * @var FolderInterface + */ + protected $folder; + + /** + * Create a new DeleteFiles instance. + * + * @param FolderInterface $folder + */ + public function __construct(FolderInterface $folder) + { + $this->folder = $folder; + } + + /** + * Handle the command. + * + * @param FileRepositoryInterface $files + */ + public function handle(FileRepositoryInterface $files) + { + foreach ($this->folder->getFiles() as $file) { + $files->delete($file); + } + } +} diff --git a/src/Folder/Contract/FolderInterface.php b/src/Folder/Contract/FolderInterface.php index 13bd97e..86d44a2 100644 --- a/src/Folder/Contract/FolderInterface.php +++ b/src/Folder/Contract/FolderInterface.php @@ -2,7 +2,7 @@ use Anomaly\FilesModule\Disk\Contract\DiskInterface; use Anomaly\FilesModule\File\FileCollection; -use Anomaly\FilesModule\Folder\FolderCollection; +use Anomaly\Streams\Platform\Entry\Contract\EntryInterface; use Illuminate\Database\Eloquent\Relations\HasMany; /** @@ -13,37 +13,22 @@ * @author Ryan Thompson * @package Anomaly\FilesModule\Folder\Contract */ -interface FolderInterface +interface FolderInterface extends EntryInterface { /** - * Return the folder's path. - * - * @param null $path - * @return string - */ - public function path($path = null); - - /** - * Return the folders's path on it's disk. + * Get the name. * * @return string */ - public function diskPath(); - - /** - * Get the ID. - * - * @return int - */ - public function getId(); + public function getName(); /** - * Get the name. + * Get the slug. * * @return string */ - public function getName(); + public function getSlug(); /** * Get the related disk. @@ -59,31 +44,10 @@ public function getDisk(); */ public function getFiles(); - /** - * Get the related parent folder. - * - * @return null|FolderInterface - */ - public function getParent(); - - /** - * Get related folders. - * - * @return FolderCollection - */ - public function getChildren(); - /** * Return the files relation. * * @return HasMany */ public function files(); - - /** - * Return folders relation. - * - * @return HasMany - */ - public function children(); } diff --git a/src/Folder/Contract/FolderRepositoryInterface.php b/src/Folder/Contract/FolderRepositoryInterface.php index a338224..fa2651f 100644 --- a/src/Folder/Contract/FolderRepositoryInterface.php +++ b/src/Folder/Contract/FolderRepositoryInterface.php @@ -1,7 +1,6 @@ * @package Anomaly\FilesModule\Folder\Contract */ -interface FolderRepositoryInterface +interface FolderRepositoryInterface extends EntryRepositoryInterface { /** - * Create a new folder. + * Find a folder by it's slug. * - * @param array $attributes - * @return FolderInterface - */ - public function create(array $attributes); - - /** - * Find a folder by it's path. - * - * @param $path - * @param DiskInterface $disk + * @param $slug * @return null|FolderInterface */ - public function findByPath($path, DiskInterface $disk); - - /** - * Find a folder by it's name and parent folder. - * - * @param $name - * @param DiskInterface $disk - * @param FolderInterface $parent - * @return null|FolderInterface - */ - public function findByName($name, DiskInterface $disk, FolderInterface $parent = null); - - /** - * Delete a folder. - * - * @param FolderInterface|EloquentModel $folder - * @return bool - */ - public function delete(FolderInterface $folder); + public function findBySlug($slug); } diff --git a/src/Folder/FolderModel.php b/src/Folder/FolderModel.php index 71813ac..9c60992 100644 --- a/src/Folder/FolderModel.php +++ b/src/Folder/FolderModel.php @@ -30,8 +30,7 @@ class FolderModel extends FilesFoldersEntryModel implements FolderInterface * @var array */ protected $with = [ - 'disk', - 'parent' + 'disk' ]; /** @@ -45,47 +44,23 @@ protected static function boot() } /** - * Return the folder's path. - * - * @param null $path - * @return string - */ - public function path($path = null) - { - $path = $this->getName() . ($path ? '/' . $path : $path); - - if ($parent = $this->getParent()) { - return $parent->path($path); - } - - return $path; - } - - /** - * Return the folders's path on it's disk. + * Get the name. * - * @param null $path * @return string */ - public function diskPath($path = null) + public function getName() { - if ($parent = $this->getParent()) { - return $parent->diskPath($this->getName() . ($path ? '/' . $path : $path)); - } - - $disk = $this->getDisk(); - - return $disk->path($this->getName() . ($path ? '/' . $path : $path)); + return $this->name; } /** - * Get the name. + * Get the slug. * * @return string */ - public function getName() + public function getSlug() { - return $this->name; + return $this->slug; } /** @@ -108,26 +83,6 @@ public function getFiles() return $this->files; } - /** - * Get the related parent folder. - * - * @return null|FolderInterface - */ - public function getParent() - { - return $this->parent; - } - - /** - * Get related folders. - * - * @return FolderCollection - */ - public function getChildren() - { - return $this->children; - } - /** * Return the files relation. * @@ -137,14 +92,4 @@ public function files() { return $this->hasMany('Anomaly\FilesModule\File\FileModel', 'folder_id'); } - - /** - * Return the folder relation. - * - * @return HasMany - */ - public function children() - { - return $this->hasMany('Anomaly\FilesModule\Folder\FolderModel', 'parent_id'); - } } diff --git a/src/Folder/FolderObserver.php b/src/Folder/FolderObserver.php index 1ed69da..593388a 100644 --- a/src/Folder/FolderObserver.php +++ b/src/Folder/FolderObserver.php @@ -1,13 +1,10 @@ files = $files; - $this->folders = $folders; - $this->manager = $manager; - - parent::__construct($events, $commands); - } - - /** - * Fire just before saving a folder. - * - * @param EntryInterface|FolderInterface $entry - * @return bool - */ - public function saving(EntryInterface $entry) - { - $disk = $entry->getDisk(); - - /** - * If the folder already exists then - * skip it because even if it does not - * exist on the server it'll be written - * automatically soon. - */ - if ($this->folders->findByName($entry->getName(), $disk, $entry->getParent())) { - return false; - } - - return parent::saving($entry); - } - - /** - * Fire just before saving a folder. + * Fire just before deleting a folder. * * @param EntryInterface|FolderInterface $entry */ public function deleting(EntryInterface $entry) { - $this->manager->deleteDir($entry->diskPath()); - - // Delete contained files. - foreach ($entry->getFiles() as $file) { - $this->files->delete($file); - } - - // Delete contained folders. - foreach ($entry->getChildren() as $folder) { - $this->folders->delete($folder); - } + $this->dispatch(new DeleteFiles($entry)); + $this->dispatch(new DeleteDirectory($entry)); } } diff --git a/src/Folder/FolderPresenter.php b/src/Folder/FolderPresenter.php index fef499d..afeeea2 100644 --- a/src/Folder/FolderPresenter.php +++ b/src/Folder/FolderPresenter.php @@ -22,27 +22,4 @@ class FolderPresenter extends EntryPresenter */ protected $object; - /** - * Return the browser link. - * - * @return string - */ - public function viewLink() - { - return app('html')->link( - implode( - '/', - array_filter( - [ - 'admin', - 'files', - 'browser', - $this->object->getDisk()->getSlug(), - $this->object->path() - ] - ) - ), - $this->object->getName() - ); - } } diff --git a/src/Folder/FolderRepository.php b/src/Folder/FolderRepository.php index d5dfa40..3218dfa 100644 --- a/src/Folder/FolderRepository.php +++ b/src/Folder/FolderRepository.php @@ -1,9 +1,8 @@ * @package Anomaly\FilesModule\Folder */ -class FolderRepository implements FolderRepositoryInterface +class FolderRepository extends EntryRepository implements FolderRepositoryInterface { /** @@ -34,64 +33,13 @@ function __construct(FolderModel $model) } /** - * Create a new folder. + * Find a folder by it's slug. * - * @param array $attributes - * @return FolderInterface - */ - public function create(array $attributes) - { - return $this->model->create($attributes); - } - - /** - * Find a folder by it's path. - * - * @param $path - * @param DiskInterface $disk + * @param $slug * @return null|FolderInterface */ - public function findByPath($path, DiskInterface $disk) - { - $folder = null; - - foreach (explode('/', $path) as $name) { - - $folder = $this->findByName($name, $disk, $folder); - - if (!$folder) { - return null; - } - } - - return $folder; - } - - /** - * Find a folder by it's name and parent folder. - * - * @param $name - * @param DiskInterface $disk - * @param FolderInterface $parent - * @return null|FolderInterface - */ - public function findByName($name, DiskInterface $disk, FolderInterface $parent = null) - { - return $this->model - ->where('name', $name) - ->where('disk_id', $disk->getId()) - ->where('parent_id', $parent ? $parent->getId() : null) - ->first(); - } - - /** - * Delete a folder. - * - * @param FolderInterface|EloquentModel $folder - * @return bool - */ - public function delete(FolderInterface $folder) + public function findBySlug($slug) { - return $folder->delete(); + return $this->model->where('slug', $slug)->first(); } } diff --git a/src/Folder/Form/FolderFormBuilder.php b/src/Folder/Form/FolderFormBuilder.php index b9c2665..11563b9 100644 --- a/src/Folder/Form/FolderFormBuilder.php +++ b/src/Folder/Form/FolderFormBuilder.php @@ -1,7 +1,5 @@ [ - 'rules' => [ - 'regex:/^[a-zA-Z0-9_\s]+$/' - ] - ] - ]; - - /** - * The form actions. - * - * @var array - */ - protected $actions = [ - 'save' => [ - 'redirect' => '{url.previous}' + 'name', + 'slug' => [ + 'disabled' => 'edit' + ], + 'disk' => [ + 'disabled' => 'edit' ] ]; - /** - * The form buttons. - * - * @var array - */ - protected $buttons = [ - 'cancel' => [ - 'href' => '{url.previous}' - ] - ]; - - /** - * The form options. - * - * @var array - */ - protected $options = [ - 'title' => 'anomaly.module.files::message.new_folder' - ]; - - /** - * Fired when the builder - * is ready to build. - * - * @throws \Exception - */ - public function onReady() - { - if (!$this->getDisk() && !$this->getEntry()) { - throw new \Exception('The $disk parameter is required when creating a folder.'); - } - } - - /** - * Fire just before saving the entry. - */ - public function onSaving() - { - $entry = $this->getFormEntry(); - $parent = $this->getParent(); - $disk = $this->getDisk(); - - if ($disk) { - $entry->disk = $disk->getId(); - } - - if ($parent) { - $entry->parent_id = $parent->getId(); - } - } - - /** - * Get the disk. - * - * @return DiskInterface|null - */ - public function getDisk() - { - return $this->disk; - } - - /** - * Set the disk. - * - * @param DiskInterface $disk - * @return $this - */ - public function setDisk(DiskInterface $disk) - { - $this->disk = $disk; - - return $this; - } - - /** - * Get the parent folder. - * - * @return FolderInterface|null - */ - public function getParent() - { - return $this->parent; - } - - /** - * Set the parent folder. - * - * @param FolderInterface $parent - * @return $this - */ - public function setParent(FolderInterface $parent) - { - $this->parent = $parent; - - return $this; - } } diff --git a/src/Folder/Table/FolderTableBuilder.php b/src/Folder/Table/FolderTableBuilder.php index 21aecce..564bdde 100644 --- a/src/Folder/Table/FolderTableBuilder.php +++ b/src/Folder/Table/FolderTableBuilder.php @@ -1,9 +1,6 @@ getDisk()) { - throw new \Exception('The $disk parameter is required.'); - } - } + protected $actions = [ + 'delete' + ]; - /** - * Fired just before querying. - * - * @param Builder $query - */ - public function onQuerying(Builder $query) - { - $disk = $this->getDisk(); - - // Limit results to the desired disk. - $query->where('disk_id', $disk->getId()); - - // Limit results to the desired parent folder if any. - if ($parent = $this->getParent()) { - $query->where('parent_id', $parent->getId()); - } else { - $query->where('parent_id', null); - } - } - - /** - * Get the disk. - * - * @return DiskInterface - */ - public function getDisk() - { - return $this->disk; - } - - /** - * Set the disk interface. - * - * @param DiskInterface $disk - * @return $this - */ - public function setDisk(DiskInterface $disk) - { - $this->disk = $disk; - - return $this; - } - - /** - * Get the parent folder. - * - * @return FolderInterface - */ - public function getParent() - { - return $this->parent; - } - - /** - * Set the parent folder. - * - * @param FolderInterface $parent - * @return $this - */ - public function setParent(FolderInterface $parent) - { - $this->parent = $parent; - - return $this; - } } diff --git a/src/Http/Controller/Admin/BrowserController.php b/src/Http/Controller/Admin/BrowserController.php deleted file mode 100644 index b6a9c3f..0000000 --- a/src/Http/Controller/Admin/BrowserController.php +++ /dev/null @@ -1,140 +0,0 @@ - - * @author Ryan Thompson - * @package Anomaly\FilesModule\Http\Controller\Admin - */ -class BrowserController extends AdminController -{ - - /** - * The disk repository. - * - * @var DiskRepositoryInterface - */ - protected $disks; - - /** - * The file repository. - * - * @var FileRepositoryInterface - */ - protected $files; - - /** - * The folder repository. - * - * @var FolderRepositoryInterface - */ - protected $folders; - - /** - * Create a new BrowserController instance. - * - * @param DiskRepositoryInterface $disks - * @param FileRepositoryInterface $files - * @param FolderRepositoryInterface $folders - */ - function __construct( - DiskRepositoryInterface $disks, - FileRepositoryInterface $files, - FolderRepositoryInterface $folders - ) { - parent::__construct(); - - $this->disks = $disks; - $this->files = $files; - $this->folders = $folders; - } - - /** - * Return the browser index. - * - * @param BrowserTableBuilder $browser - * @param DiskTableBuilder $disks - * @param FolderTableBuilder $folders - * @param FileTableBuilder $files - * @param null $disk - * @param null $path - * @return \Symfony\Component\HttpFoundation\Response - */ - public function index( - BrowserTableBuilder $browser, - DiskTableBuilder $disks, - FolderTableBuilder $folders, - FileTableBuilder $files, - $disk = null, - $path = null - ) { - - /** - * If a disk is selected then don't include them - * but add them to the file and folder tables. - */ - if ($disk && $disk = $this->disks->findBySlug($disk)) { - - $this->dispatch(new AddDiskBreadcrumb($disk)); - - $browser->addTable('folders', $folders->setDisk($disk)); - $browser->addTable('files', $files->setDisk($disk)); - } else { - $browser->addTable('disks', $disks); - } - - /** - * If we have a path available then find the folder - * and add it to the folder and file tables. - */ - if ($disk && $path && $folder = $this->folders->findByPath($path, $disk)) { - - $this->dispatch(new AddFolderBreadcrumbs($folder)); - - $files->setFolder($folder); - $folders->setParent($folder); - } - - return $browser->render(); - } - - /** - * Return the details of a file or folder. - * - * @param $disk - * @param $path - * @return string - */ - public function view($disk, $path) - { - $disk = $this->disks->findBySlug($disk); - - $folder = $this->folders->findByPath(dirname($path), $disk); - $file = $this->files->findByName(basename($path), $disk, $folder); - - if (!$disk || (!$folder && !$file)) { - abort(404); - } - - if ($file) { - return json_encode($file); - } - - if ($folder) { - return json_encode($folder); - } - } -} diff --git a/src/Http/Controller/Admin/DisksController.php b/src/Http/Controller/Admin/DisksController.php index 4468fa9..2e1e3a9 100644 --- a/src/Http/Controller/Admin/DisksController.php +++ b/src/Http/Controller/Admin/DisksController.php @@ -68,6 +68,18 @@ public function create( $form->addForm('disk', $disk->setAdapter($adapter)); $form->addForm('configuration', $configuration->setEntry($adapter->getNamespace())); + $form->on( + 'saving_configuration', + function () use ($form) { + + /* @var ConfigurationFormBuilder $configuration */ + $disk = $form->getChildFormEntry('disk'); + $configuration = $form->getChildForm('configuration'); + + $configuration->setScope($disk->getSlug()); + } + ); + return $form->render(); } diff --git a/src/Http/Controller/Admin/FilesController.php b/src/Http/Controller/Admin/FilesController.php index 9d3932b..1214012 100644 --- a/src/Http/Controller/Admin/FilesController.php +++ b/src/Http/Controller/Admin/FilesController.php @@ -5,10 +5,10 @@ use Anomaly\FilesModule\File\Contract\FileRepositoryInterface; use Anomaly\FilesModule\File\Form\FileEntryFormBuilder; use Anomaly\FilesModule\File\Form\FileFormBuilder; +use Anomaly\FilesModule\File\Table\FileTableBuilder; use Anomaly\FilesModule\File\Upload\UploadFormBuilder; use Anomaly\FilesModule\Folder\Contract\FolderRepositoryInterface; use Anomaly\Streams\Platform\Http\Controller\AdminController; -use Symfony\Component\HttpFoundation\Response; /** * Class FilesController @@ -22,31 +22,39 @@ class FilesController extends AdminController { /** - * Return the form to upload files. + * Display an index of existing entries. * - * @param FolderRepositoryInterface $folders - * @param DiskRepositoryInterface $disks - * @param UploadFormBuilder $form - * @param $disk - * @param null $path - * @return Response + * @param FileTableBuilder $table + * @return \Symfony\Component\HttpFoundation\Response */ - public function upload( - FolderRepositoryInterface $folders, - DiskRepositoryInterface $disks, - UploadFormBuilder $form, - $disk, - $path = null - ) { - $form->setDisk($disk = $disks->findBySlug($disk)); - - if ($path && $folder = $folders->findByPath($path, $disk)) { - $form->setFolder($folder); - } + public function index(FileTableBuilder $table) + { + return $table->render(); + } + /** + * Create a new entry. + * + * @param FileFormBuilder $form + * @return \Symfony\Component\HttpFoundation\Response + */ + public function create(FileFormBuilder $form) + { return $form->render(); } + /** + * Edit an existing entry. + * + * @param FileFormBuilder $form + * @param $id + * @return \Symfony\Component\HttpFoundation\Response + */ + /*public function edit(FileFormBuilder $form, $id) + { + return $form->render($id); + }*/ + public function edit( FileEntryFormBuilder $form, FileRepositoryInterface $files, @@ -57,19 +65,38 @@ public function edit( $file = $files->find($id); $disk = $file->getDisk(); $stream = $disk->getEntriesStream(); - $entryForm ->setModel($stream->getEntryModel()) ->setEntry($file->getEntryId()); - $fileForm->setEntry($id); - $form ->addForm('entry', $entryForm) ->addForm('file', $fileForm); - $form->setOption('redirect', dirname('admin/files/browser/' . $disk->browserPath($files->find($id)->path()))); - return $form->render($id); } + + /** + * Return the form to upload files. + * + * @param FolderRepositoryInterface $folders + * @param DiskRepositoryInterface $disks + * @param UploadFormBuilder $form + * @param $disk + * @param null $path + * @return \Symfony\Component\HttpFoundation\Response + */ + public function upload( + FolderRepositoryInterface $folders, + DiskRepositoryInterface $disks, + UploadFormBuilder $form, + $disk, + $path = null + ) { + $form->setDisk($disk = $disks->findBySlug($disk)); + if ($path && $folder = $folders->findBySlug($path, $disk)) { + $form->setFolder($folder); + } + return $form->render(); + } } diff --git a/src/Http/Controller/Admin/FoldersController.php b/src/Http/Controller/Admin/FoldersController.php index f9b6f6b..88e8a81 100644 --- a/src/Http/Controller/Admin/FoldersController.php +++ b/src/Http/Controller/Admin/FoldersController.php @@ -1,8 +1,7 @@ setDisk($disk = $disks->findBySlug($disk)); - - if ($path && $parent = $folders->findByPath($path, $disk)) { - $form->setParent($parent); - } + public function index(FolderTableBuilder $table) + { + return $table->render(); + } + /** + * Create a new entry. + * + * @param FolderFormBuilder $form + * @return \Symfony\Component\HttpFoundation\Response + */ + public function create(FolderFormBuilder $form) + { return $form->render(); } + + /** + * Edit an existing entry. + * + * @param FolderFormBuilder $form + * @param $id + * @return \Symfony\Component\HttpFoundation\Response + */ + public function edit(FolderFormBuilder $form, $id) + { + return $form->render($id); + } }