diff --git a/build-test-project.sh b/build-test-project.sh index cc35ead..9081770 100644 --- a/build-test-project.sh +++ b/build-test-project.sh @@ -1,18 +1,17 @@ # Change these to the values for your test MySQL DB -db_host=192.168.10.10 +db_host="192.168.10.10" db_port=3306 -db_database=homestead +db_database=showcase_test_db db_username=homestead db_password=secret if [ -d "./test-project" ]; then - cd test-project - php artisan migrate:reset - cd .. + php ./reset-db.php $db_host $db_database $db_username $db_password rm -rf test-project echo "Removed old test project." fi +php ./create-db.php $db_host $db_database $db_username $db_password composer create-project laravel/laravel test-project 5.4.* php ./edit-composer.php cd test-project @@ -28,7 +27,7 @@ sed -i '' 's/Laravel\\Tinker\\TinkerServiceProvider::class,/Laravel\\Tinker\\Tin Laracasts\\Flash\\FlashServiceProvider::class,/' ./config/app.php cp ../UsersTableSeeder.php ./database/seeds/ -composer require brokerexchange/showcase=dev-feature/1.0 +composer require brokerexchange/showcase=dev-feature/namespace-showcase-routes composer dump-autoload echo "Pre auth" php artisan make:auth diff --git a/create-db.php b/create-db.php new file mode 100644 index 0000000..f00ce39 --- /dev/null +++ b/create-db.php @@ -0,0 +1,9 @@ + PDO::ERRMODE_EXCEPTION] +); +$stmt = $pdo->exec("CREATE DATABASE IF NOT EXISTS $db"); \ No newline at end of file diff --git a/readme.md b/readme.md index accf176..28f3626 100644 --- a/readme.md +++ b/readme.md @@ -28,6 +28,13 @@ If you want to publish all the assets: php artisan vendor:publish --tag=showcase ``` +If you only want to publish specific pieces: +``` +php artisan vendor:publish --tag=showcase-assets +php artisan vendor:publish --tag=showcase-config +php artisan vendor:publish --tag=showcase-views +``` + > TODO: Finish this section and fix things so you don't have to use public/vendor ### Install the package development environment @@ -111,13 +118,17 @@ After you've installed the package, you can use `php artisan vendor:publish --ta Once the resources are published, you can find them in the `resources/views/vendor/showcase` directory. You can modify any of the package views, including the admin panels. #### Add Custom Display Component -If you want to add a custom component, just create a new file in `resources/views/vendor/showcase/public/components`. Then, when creating or editing a display, type in the name of your custom component (sans the blade extension) and your display will use it! +If you want to add a custom component, just create a new file in `resources/views/vendor/showcase/public/components`. Then, when creating or editing a display, your custom component will show up in the dropdown selection! #### Custom CSS Just target the Showcase selectors with your CSS to customize the styling. To make the custom styling show up on the admin panels, make sure you add a link tag for your CSS to the `_stylesheets` include in `resources/views/vendor/showcase/app/includes`. ### Configuration There are some configuration options exposed for you in the config file `showcase.php`. +- `table_prefix` sets the prefix used by Showcase tables +- `middleware` sets what middleware Showcase routes go through (comma delimited) +- `description_length` sets a character limit on the description field +- `route_prefix` sets the prefix used for Showcase routes and named routes #### Table Prefix By default, all showcase tables are prefixed with `showcase_`. You may change this to whatever you desire. diff --git a/reset-db.php b/reset-db.php new file mode 100644 index 0000000..fff942c --- /dev/null +++ b/reset-db.php @@ -0,0 +1,10 @@ + PDO::ERRMODE_EXCEPTION] +); +$stmt = $pdo->exec("DROP DATABASE IF EXISTS $db"); \ No newline at end of file diff --git a/src/Showcase.php b/src/Showcase.php index ac61113..3b92791 100644 --- a/src/Showcase.php +++ b/src/Showcase.php @@ -2,6 +2,8 @@ namespace Showcase; +use Illuminate\Support\Facades\Storage; + class Showcase { /** @@ -43,4 +45,85 @@ public static function templateFileExists($file, $type) return file_exists(base_path() . "/resources/views/vendor/showcase/public/components/$type/$file.blade.php") ?: file_exists(__DIR__."/resources/views/public/components/$type/$file.blade.php"); } + + /** + * Get all view filenames. + * + * @param string $type The type of view file being requested. + * + * @return array + */ + protected static function getViewFilenames($type) + { + $sources = [ + base_path() . "/resources/views/vendor/showcase/public/components/$type/", + __DIR__ . "/resources/views/public/components/$type/" + ]; + + $filenames = []; + + foreach ($sources as $source) { + $rawFilenames = self::_files($source); + + $refinedFilenames = array_map( + function ($filename) { + $filenameArray = explode(DIRECTORY_SEPARATOR, $filename); + return $filenameArray[count($filenameArray) - 1]; + }, + $rawFilenames + ); + + $filenames = array_merge($filenames, $refinedFilenames); + } + + return array_reduce( + $filenames, + function ($carry, $filename) use ($filenames) { + if (array_search($filename, $carry) === false) { + $carry[] = $filename; + } + + return $carry; + }, + [] + ); + } + + /** + * Get all view filenames sans extension. + * + * @param string $type The type of view file being requested. + * + * @return array + */ + public static function getViewFilenamesBasic($type) + { + return array_map( + function ($filename) { + return str_replace('.blade.php', '', $filename); + }, + self::getViewFilenames($type) + ); + } + + /** + * Get all files in a directory. + * + * @param string $directory The path to the directory. + * + * @return array + */ + private static function _files($directory) + { + $glob = glob($directory.DIRECTORY_SEPARATOR.'*'); + if ($glob === false) { + return []; + } + // To get the appropriate files, we'll simply glob the directory and filter + // out any "files" that are not truly files so we do not end up with any + // directories in our list, but only true files within the directory. + return array_filter($glob, function ($file) { + return filetype($file) == 'file'; + }); + } } \ No newline at end of file diff --git a/src/app/Http/Controllers/DisplayController.php b/src/app/Http/Controllers/DisplayController.php index 774388f..8975f6e 100644 --- a/src/app/Http/Controllers/DisplayController.php +++ b/src/app/Http/Controllers/DisplayController.php @@ -3,9 +3,10 @@ namespace Showcase\App\Http\Controllers; use Showcase\App\Display; +use Showcase\App\Http\Requests\DisplayRequest; use Showcase\App\Trophy; use Illuminate\Http\Request; -use Showcase\App\Http\Requests\DisplayRequest; +use Showcase\Showcase; class DisplayController extends Controller { @@ -26,7 +27,13 @@ public function index() */ public function create() { - return view('showcase::app.display.create', compact('trophies')); + $displayViews = Showcase::getViewFilenamesBasic('display'); + $trophyViews = Showcase::getViewFilenamesBasic('trophy'); + + return view( + 'showcase::app.display.create', + compact('trophies', 'displayViews', 'trophyViews') + ); } /** @@ -44,7 +51,7 @@ public function store(DisplayRequest $request) $display->trophies()->detach(); $display->trophies()->attach($request->trophies); - return redirect()->route('displays.show', compact('display')); + return redirect()->route(config('showcase.route_prefix', 'showcase') . '.displays.show', compact('display')); } /** @@ -66,7 +73,13 @@ public function show(Display $display) */ public function edit(Display $display) { - return view('showcase::app.display.edit', compact('display', 'trophies')); + $displayViews = Showcase::getViewFilenamesBasic('display'); + $trophyViews = Showcase::getViewFilenamesBasic('trophy'); + + return view( + 'showcase::app.display.edit', + compact('display', 'trophies', 'displayViews', 'trophyViews') + ); } /** @@ -85,7 +98,7 @@ public function update(DisplayRequest $request, Display $display) $display->trophies()->detach(); $display->trophies()->attach($request->trophies); - return redirect()->route('displays.show', compact('display')); + return redirect()->route(config('showcase.route_prefix', 'showcase') . '.displays.show', compact('display')); } /** @@ -100,6 +113,6 @@ public function destroy(Display $display) $display->delete(); - return redirect()->route('displays.index'); + return redirect()->route(config('showcase.route_prefix', 'showcase') . '.displays.index'); } } diff --git a/src/app/Http/Controllers/ShowcaseController.php b/src/app/Http/Controllers/ShowcaseController.php deleted file mode 100644 index 9ce24df..0000000 --- a/src/app/Http/Controllers/ShowcaseController.php +++ /dev/null @@ -1,10 +0,0 @@ -display !== null ? Display::find($display)->default_trophy_component_view : null; + + $trophyViews = Showcase::getViewFilenamesBasic('trophy'); - // $component_views = Storage::files(base_dir('resources/views/public/components/trophies')); - - return view('showcase::app.trophy.create', compact('default_view', 'displays', 'component_views')); + return view( + 'showcase::app.trophy.create', + compact('default_view', 'displays', 'trophyViews') + ); } /** @@ -48,7 +52,7 @@ public function store(TrophyRequest $request) $trophy->displays()->detach(); $trophy->displays()->attach($request->displays); - return redirect()->route('trophies.show', compact('trophy')); + return redirect()->route(config('showcase.route_prefix', 'showcase') . '.trophies.show', compact('trophy')); } /** @@ -70,7 +74,12 @@ public function show(Trophy $trophy) */ public function edit(Trophy $trophy) { - return view('showcase::app.trophy.edit', compact('trophy', 'displays')); + $trophyViews = Showcase::getViewFilenamesBasic('trophy'); + + return view( + 'showcase::app.trophy.edit', + compact('trophy', 'displays', 'trophyViews') + ); } /** @@ -89,7 +98,7 @@ public function update(TrophyRequest $request, Trophy $trophy) flash()->success('Trophy updated!'); - return redirect()->route('trophies.show', compact('trophy')); + return redirect()->route(config('showcase.route_prefix', 'showcase') . '.trophies.show', compact('trophy')); } /** @@ -104,6 +113,6 @@ public function destroy(Trophy $trophy) $trophy->delete(); - return redirect()->route('trophies.index'); + return redirect()->route(config('showcase.route_prefix', 'showcase') . '.trophies.index'); } } diff --git a/src/app/Providers/ShowcaseProvider.php b/src/app/Providers/ShowcaseProvider.php index 738cd46..9f0c528 100644 --- a/src/app/Providers/ShowcaseProvider.php +++ b/src/app/Providers/ShowcaseProvider.php @@ -26,11 +26,19 @@ public function boot() __DIR__.'/../../resources/assets/build' => public_path('vendor/showcase'), __DIR__.'/../../resources/views' => resource_path('/views/vendor/showcase'), ], 'showcase'); + + $this->publishes([ + __DIR__.'/../../config.php' => config_path('showcase.php') + ], 'showcase-config'); $this->publishes([ __DIR__.'/../../resources/assets/build' => public_path('vendor/showcase'), ], 'showcase-assets'); + $this->publishes([ + __DIR__.'/../../resources/views' => resource_path('/views/vendor/showcase') + ], 'showcase-views'); + Blade::directive('showcaseDisplay', function ($display) { return " 'showcase_', + 'table_prefix' => env('SHOWCASE_TABLE_PREFIX', 'showcase_'), /* |-------------------------------------------------------------------------- @@ -20,7 +20,7 @@ | An array of existing application middleware you'd like Showcase routes to | pass through. This is required to use Showcase behind authentication. */ - 'middleware' => ['web', 'auth'], + 'middleware' => explode(',', env('SHOWCASE_MIDDLEWARE', 'web,auth')), /* |-------------------------------------------------------------------------- @@ -29,5 +29,14 @@ | | Change the trophy description length maximum. */ - 'description_length' => 55, + 'description_length' => env('SHOWCASE_DESCRIPTION_LENGTH', 55), + + /* + |-------------------------------------------------------------------------- + | Route Prefix + |-------------------------------------------------------------------------- + | + | Sets the prefix for Showcase routes. + */ + 'route_prefix' => env('SHOWCASE_ROUTE_PREFIX', 'showcase'), ]; diff --git a/src/resources/views/app/display/create.blade.php b/src/resources/views/app/display/create.blade.php index 42484a4..105fb66 100644 --- a/src/resources/views/app/display/create.blade.php +++ b/src/resources/views/app/display/create.blade.php @@ -1,21 +1,31 @@ -@extends('showcase::app.layouts.app') -@section('title', 'Create Display') +@extends('showcase::app.layouts.app') + +@section('title', 'Create Display') + @section('content')

Create New Display

-
+ {{csrf_field()}}
- +
- +
- +
diff --git a/src/resources/views/app/display/edit.blade.php b/src/resources/views/app/display/edit.blade.php index 1569fc1..f3078a7 100644 --- a/src/resources/views/app/display/edit.blade.php +++ b/src/resources/views/app/display/edit.blade.php @@ -1,9 +1,11 @@ -@extends('showcase::app.layouts.app') -@section('title', 'Edit Display') +@extends('showcase::app.layouts.app') + +@section('title', 'Edit Display') + @section('content')

Edit Display

- + {{method_field('PUT')}} {{csrf_field()}}
@@ -11,11 +13,38 @@
- +
- +
force_trophy_default ? 'checked' : ''}}> @@ -32,7 +61,4 @@
- - - @stop \ No newline at end of file diff --git a/src/resources/views/app/includes/_header.blade.php b/src/resources/views/app/includes/_header.blade.php index 3f7c0f0..4011d22 100644 --- a/src/resources/views/app/includes/_header.blade.php +++ b/src/resources/views/app/includes/_header.blade.php @@ -3,22 +3,22 @@