Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
v0.0.8 (#23)
Browse files Browse the repository at this point in the history
* Feature/1.0 (#17)

* Update readme.md (#10)

* Update readme.md

* Remove ToDo

* build script now builds own separate db for testing

* added functionality to get names of view files; create display should now use dropdown for component view

* fixed bug in getViewFilenames so it actually returns filenames

* refined the results of getViewFilenames

* fixed a dumb typo

* form styling

* getViewFilenames now filters out duplicate values

* fixed getViewFilenames to use filter instead of reduce

* i'm stupid

* fixed comparison in getViewFilenames reduction to check explicitly for false

* using select for create display trophy views

* forgot to change to getViewFilenames :oops:

* added getViewFilenamesBasic to get view filenames sans extensions

* fixed a dumb typo

* added dropdowns for display edit; refactored display create dropdowns to show old values

* fixed bug with display edit form

* dropdowns added to trophy create/edit forms

* fixed old value inputs for display and trophy edit forms

* fixed code spacing

* Views Dropdown (#18)

* added functionality to get names of view files; create display should now use dropdown for component view

* fixed bug in getViewFilenames so it actually returns filenames

* refined the results of getViewFilenames

* fixed a dumb typo

* form styling

* getViewFilenames now filters out duplicate values

* fixed getViewFilenames to use filter instead of reduce

* i'm stupid

* fixed comparison in getViewFilenames reduction to check explicitly for false

* using select for create display trophy views

* forgot to change to getViewFilenames :oops:

* added getViewFilenamesBasic to get view filenames sans extensions

* fixed a dumb typo

* added dropdowns for display edit; refactored display create dropdowns to show old values

* fixed bug with display edit form

* dropdowns added to trophy create/edit forms

* fixed old value inputs for display and trophy edit forms

* fixed code spacing

* added showcase route which redirects to display.index

* updated readme

* fixed typo in showcase route listing

* updated build script

* added a namespace to showcase routes

* removed ShowcaseController because it isn't being used; fixed namespace issue with showcase routes

* should be prefix not namespace

* fixed typo in showcase redirect route

* fixed previous typo fix

* refactored chained calls to group options for showcase routes

* converted prefix to use config; changed route_namespace to route_prefix

* added route as

* changed showcase route's name to home instead of showcase

* changed postfix for as from _ to .; fixed bug in showcase_home redirect

* updated all places where the old route names were called

* missed a few spots in the last update

* config file now checks for envvars before setting its defaults

* added tagged publishing for config and views

* updated readme
  • Loading branch information
Jantho1990 authored Oct 16, 2018
1 parent 682c026 commit c49272c
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 66 deletions.
11 changes: 5 additions & 6 deletions build-test-project.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions create-db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
[$script, $host, $db, $user, $pass] = $argv;
$pdo = new PDO(
"mysql:host=$host",
$user,
$pass,
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
$stmt = $pdo->exec("CREATE DATABASE IF NOT EXISTS $db");
13 changes: 12 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions reset-db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

[$script, $host, $db, $user, $pass] = $argv;
$pdo = new PDO(
"mysql:host=$host",
$user,
$pass,
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
$stmt = $pdo->exec("DROP DATABASE IF EXISTS $db");
83 changes: 83 additions & 0 deletions src/Showcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Showcase;

use Illuminate\Support\Facades\Storage;

class Showcase
{
/**
Expand Down Expand Up @@ -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';
});
}
}
25 changes: 19 additions & 6 deletions src/app/Http/Controllers/DisplayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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')
);
}

/**
Expand All @@ -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'));
}

/**
Expand All @@ -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')
);
}

/**
Expand All @@ -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'));
}

/**
Expand All @@ -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');
}
}
10 changes: 0 additions & 10 deletions src/app/Http/Controllers/ShowcaseController.php

This file was deleted.

23 changes: 16 additions & 7 deletions src/app/Http/Controllers/TrophyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Showcase\App\Display;
use Showcase\App\Trophy;
use Showcase\App\Http\Requests\TrophyRequest;
use Showcase\Showcase;

class TrophyController extends Controller
{
Expand All @@ -29,10 +30,13 @@ public function create()
$default_view = request()->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')
);
}

/**
Expand All @@ -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'));
}

/**
Expand All @@ -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')
);
}

/**
Expand All @@ -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'));
}

/**
Expand All @@ -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');
}
}
8 changes: 8 additions & 0 deletions src/app/Providers/ShowcaseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<?php
if ({$display} !== '') {
Expand Down
15 changes: 12 additions & 3 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| This will add a prefix to all Showcase-related tables. This is useful if
| you have existing, conflicting table names.
*/
'table_prefix' => 'showcase_',
'table_prefix' => env('SHOWCASE_TABLE_PREFIX', 'showcase_'),

/*
|--------------------------------------------------------------------------
Expand All @@ -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')),

/*
|--------------------------------------------------------------------------
Expand All @@ -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'),
];
Loading

0 comments on commit c49272c

Please sign in to comment.