From ba273ffbcf61b43e4fec447c083ea5b08bad7f2e Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 5 Feb 2018 14:21:54 +0000 Subject: [PATCH] search functionality and settings fixes --- app/Http/Controllers/SettingsController.php | 19 +++ app/Providers/AppServiceProvider.php | 11 +- app/Setting.php | 112 ++++++++++++++++++ ...018_02_04_185524_create_settings_table.php | 1 + database/seeds/SettingsSeeder.php | 19 ++- public/css/app.css | 83 ++++++++++++- public/mix-manifest.json | 4 +- resources/assets/sass/_app.scss | 67 ++++++++++- resources/views/partials/search.blade.php | 1 + resources/views/settings/form.blade.php | 15 +-- resources/views/settings/list.blade.php | 17 +-- resources/views/welcome.blade.php | 2 + routes/web.php | 2 + 13 files changed, 314 insertions(+), 39 deletions(-) create mode 100644 resources/views/partials/search.blade.php diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index ea280e9c..7fa0e21b 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -32,6 +32,8 @@ class SettingsController extends Controller { $setting = Setting::find($id); + if((bool)$setting->system === true) return abort(404); + if (!is_null($setting)) { return view('settings.edit')->with([ 'setting' => $setting, @@ -80,4 +82,21 @@ class SettingsController extends Controller ]); } } + /** + * @param int $id + * + * @return \Illuminate\Http\RedirectResponse + */ + public function clear($id) + { + $setting = Setting::find($id); + if((bool)$setting->system !== true) { + $setting->value = ''; + $setting->save(); + } + return redirect()->route('settings.index')->with([ + 'success' => 'You have successfully edited this Setting!', + ]); + + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 17864c94..1061a061 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -15,7 +15,9 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { - if(!file_exists(database_path(env('DB_DATABASE')))) { + $alt_bg = ''; + + if(!is_file(database_path(env('DB_DATABASE')))) { // first time setup touch(database_path(env('DB_DATABASE'))); Artisan::call('migrate', array('--path' => 'database/migrations', '--force' => true, '--seed' => true)); @@ -24,9 +26,10 @@ class AppServiceProvider extends ServiceProvider //Artisan::call('config:cache'); //Artisan::call('route:cache'); } - $alt_bg = ''; - if($bg_image = Setting::fetch('background_image')) { - $alt_bg = ' style="background-image: url('.asset('storage/'.$bg_image).')"'; + if(is_file(database_path(env('DB_DATABASE')))) { + if($bg_image = Setting::fetch('background_image')) { + $alt_bg = ' style="background-image: url('.asset('storage/'.$bg_image).')"'; + } } view()->share('alt_bg', $alt_bg); diff --git a/app/Setting.php b/app/Setting.php index 64a73094..1b277925 100644 --- a/app/Setting.php +++ b/app/Setting.php @@ -4,6 +4,7 @@ namespace App; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Input; +use Form; class Setting extends Model { @@ -39,6 +40,79 @@ class Setting extends Model ]; } + public function getListValueAttribute() + { + switch($this->type) { + case 'image': + if(!empty($this->value)) { + $value = 'View'; + } else { + $value = '- not set -'; + } + break; + case 'boolean': + if((bool)$this->value === true) { + $value = 'Yes'; + } else { + $value = 'No'; + } + break; + case 'select': + if(!empty($this->value) || $this->value !== 'none') { + $options = (array)json_decode($this->options); + $value = $options[$this->value]; + } else { + $value = '- not set -'; + } + break; + default: + $value = $this->value; + break; + } + + return $value; + + } + + public function getEditValueAttribute() + { + switch($this->type) { + case 'image': + $value = ''; + if(isset($this->value) && !empty($this->value)) { + $value .= ''; + } + $value .= Form::file('value', ['class' => 'form-control']); + if(isset($this->value) && !empty($this->value)) { + $value .= 'Reset back to default'; + } + + break; + case 'boolean': + $checked = false; + if(isset($this->value) && (bool)$this->value === true) $checked = true; + $set_checked = ($checked) ? ' checked="checked"' : ''; + $value = ' + '; + + break; + case 'select': + $options = json_decode($this->options); + $value = Form::select('value', $options, null, ['class' => 'form-control']); + break; + default: + $value = Form::text('value', null, ['class' => 'form-control']); + break; + } + + return $value; + + } + public function group() { return $this->belongsTo('App\SettingGroup', 'group_id'); @@ -85,4 +159,42 @@ class Setting extends Model { return array_key_exists($key, Setting::$cache); } + + /** + * @return html + */ + public static function search() + { + $output = ''; + $homepage_search = self::fetch('homepage_search'); + $search_provider = self::where('key', '=', 'search_provider')->first(); + + $options = (array)json_decode($search_provider->options); + $name = $options[$search_provider->value]; + if((bool)$homepage_search && (bool)$search_provider->value) { + switch($search_provider->value) { + case 'google': + $url = 'https://www.google.com/search'; + $var = 'q'; + break; + case 'ddg': + $url = 'https://duckduckgo.com/'; + $var = 'q'; + break; + case 'bing': + $url = 'https://www.bing.com/search'; + $var = 'q'; + break; + } + $output .= '
'; + $output .= Form::open(['url' => $url, 'method' => 'get']); + $output .= '
'; + $output .= Form::text($var, null, ['class' => 'homesearch', 'placeholder' => $name.' search...']); + $output .= ''; + $output .= '
'; + $output .= Form::close(); + $output .= '
'; + } + return $output; + } } diff --git a/database/migrations/2018_02_04_185524_create_settings_table.php b/database/migrations/2018_02_04_185524_create_settings_table.php index 9313ab2f..dec2f147 100644 --- a/database/migrations/2018_02_04_185524_create_settings_table.php +++ b/database/migrations/2018_02_04_185524_create_settings_table.php @@ -18,6 +18,7 @@ class CreateSettingsTable extends Migration $table->integer('group_id')->default(0); $table->string('key'); $table->string('type')->default('text'); + $table->text('options')->nullable(); $table->string('label'); $table->string('value')->nullable(); $table->string('order')->default(0); diff --git a/database/seeds/SettingsSeeder.php b/database/seeds/SettingsSeeder.php index ed82ff00..cc4280ae 100644 --- a/database/seeds/SettingsSeeder.php +++ b/database/seeds/SettingsSeeder.php @@ -61,10 +61,27 @@ class SettingsSeeder extends Seeder $setting->id = 3; $setting->group_id = 3; $setting->key = 'homepage_search'; - $setting->type = 'text'; + $setting->type = 'boolean'; $setting->label = 'Homepage Search'; $setting->save(); } + if(!Setting::find(4)) { + $options = json_encode([ + 'none' => '- not set -', + 'google' => 'Google', + 'ddg' => 'DuckDuckGo', + 'bing' => 'Bing' + ]); + + $setting = new Setting; + $setting->id = 4; + $setting->group_id = 3; + $setting->key = 'search_provider'; + $setting->type = 'select'; + $setting->options = $options; + $setting->label = 'Search Provider'; + $setting->save(); + } } } diff --git a/public/css/app.css b/public/css/app.css index ecbc0a24..ea8febe0 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -318,6 +318,13 @@ body { padding: 20px; } +#app main { + -webkit-box-orient: vertical; + -webkit-box-direction: normal; + -ms-flex-direction: column; + flex-direction: column; +} + #app main, #app #sortable { padding: 10px; @@ -721,7 +728,8 @@ div.create .input label:not(.switch) { font-weight: 300; } -div.create .input input { +div.create .input input, +div.create .input select { width: 100%; border: 1px solid #dedfe2; padding: 10px; @@ -864,6 +872,79 @@ button.link { background: transparent; } +a.settinglink { + color: #2f313a; + font-size: 13px; + margin: 15px 5px; + display: inline-block; + font-weight: 700; +} + +.setting-view-image { + margin-bottom: 20px; + display: inline-block; +} + +.setting-view-image img { + max-width: 330px; +} + +.searchform { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -ms-flex-item-align: start; + align-self: flex-start; + text-align: center; + margin: 50px auto; + padding: 14px; + background: rgba(0, 0, 0, 0.2); + border-radius: 14px; + -webkit-box-shadow: inset 0px 1px 6px 0 rgba(0, 0, 0, 0.3); + box-shadow: inset 0px 1px 6px 0 rgba(0, 0, 0, 0.3); + border-top: 1px solid rgba(0, 0, 0, 0.5); + border-bottom: 1px solid rgba(255, 255, 255, 0.35); + position: relative; + width: 100%; + max-width: 500px; +} + +.searchform form { + width: 100%; +} + +.searchform .input-container { + background: white; + border-radius: 5px; + -webkit-box-shadow: 0px 0px 5px 0 rgba(0, 0, 0, 0.4); + box-shadow: 0px 0px 5px 0 rgba(0, 0, 0, 0.4); + overflow: hidden; +} + +.searchform input { + padding: 17px 15px; + font-size: 15px; + border: 0 none; + width: 100%; + background: transparent; +} + +.searchform button { + position: absolute; + right: 14px; + top: 14px; + border: none; + font-size: 16px; + padding: 7px 15px; + line-height: 37px; + font-weight: 500; + border-top-right-radius: 5px; + border-bottom-right-radius: 5px; + color: white; + text-transform: uppercase; + background: #d64d55; +} + /*! Huebee v2.0.0 http://huebee.buzz ---------------------------------------------- */ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index afa46bbf..adcf0e3f 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,4 +1,4 @@ { - "/css/app.css": "/css/app.css?id=fff34714aa687ec711d3", - "/js/app.js": "/js/app.js?id=aa9e426dc7b92d42d3b2" + "/css/app.css": "/css/app.css?id=d47acbf87c5ae533ddf5", + "/js/app.js": "/js/app.js?id=a809f8ee6ee8636e0f2b" } \ No newline at end of file diff --git a/resources/assets/sass/_app.scss b/resources/assets/sass/_app.scss index f4dffa47..04775e28 100644 --- a/resources/assets/sass/_app.scss +++ b/resources/assets/sass/_app.scss @@ -66,6 +66,9 @@ body { } } + main { + flex-direction: column; + } main, #sortable { padding: 10px; display: flex; @@ -387,7 +390,7 @@ div.create { display: block; font-weight: 300; } - input { + input, select { width: 100%; border: 1px solid #dedfe2; padding: 10px; @@ -512,4 +515,66 @@ div.create { border: none; appearance: none; background: transparent; + } + + a.settinglink { + color: $app-text; + font-size: 13px; + margin: 15px 5px; + display: inline-block; + font-weight: 700; + } + .setting-view-image { + margin-bottom: 20px; + display: inline-block; + img { + max-width: 330px; + } + } + + .searchform { + display: flex; + align-self: flex-start; + text-align: center; + margin: 50px auto; + padding: 14px; + background: rgba(0,0,0,0.2); + border-radius: 14px; + box-shadow: inset 0px 1px 6px 0 rgba(0,0,0,0.3); + border-top: 1px solid rgba(0,0,0,0.5); + border-bottom: 1px solid rgba(255,255,255,0.35); + position: relative; + width: 100%; + max-width: 500px; + form { + width: 100%; + } + .input-container { + background: white; + border-radius: 5px; + box-shadow: 0px 0px 5px 0 rgba(0,0,0,0.4); + overflow: hidden; + } + input { + padding: 17px 15px; + font-size: 15px; + border: 0 none; + width: 100%; + background: transparent; + } + button { + position: absolute; + right: 14px; + top: 14px; + border: none; + font-size: 16px; + padding: 7px 15px; + line-height: 37px; + font-weight: 500; + border-top-right-radius: 5px; + border-bottom-right-radius: 5px; + color: white; + text-transform: uppercase; + background: $app-red; + } } \ No newline at end of file diff --git a/resources/views/partials/search.blade.php b/resources/views/partials/search.blade.php new file mode 100644 index 00000000..3df5d38f --- /dev/null +++ b/resources/views/partials/search.blade.php @@ -0,0 +1 @@ +{!! App\Setting::search() !!} diff --git a/resources/views/settings/form.blade.php b/resources/views/settings/form.blade.php index 7f6986f7..bb8f76e7 100644 --- a/resources/views/settings/form.blade.php +++ b/resources/views/settings/form.blade.php @@ -14,20 +14,7 @@ -->
- @php($type = explode('|', $setting->type)[0]) - {!! Form::label('value', 'Value') !!} - @if ($type == 'image') - {!! Form::file('value', ['class' => 'form-control']) !!} - @elseif ($type == 'select') - @php($options = explode('|', $setting->type)[1]) - @php($options = explode(',', $options)) - {!! Form::select('value', $options, null, ['class' => 'form-control']) !!} - @elseif ($type == 'textarea') - {!! Form::textarea('value', Request::get('value'), ['class' => 'form-control trumbowyg', 'placeholder' => 'FAQ contents']) !!} - @else - {!! Form::text('value', null, ['class' => 'form-control']) !!} - @endif - + {!! $setting->edit_value !!}
diff --git a/resources/views/settings/list.blade.php b/resources/views/settings/list.blade.php index 15702232..811f9d04 100644 --- a/resources/views/settings/list.blade.php +++ b/resources/views/settings/list.blade.php @@ -25,22 +25,7 @@ {{ $setting->label }} - @php($type = explode('|', $setting->type)[0]) - @if ($type == 'image') - @if(!empty($setting->value)) - View - @else - - not set - - @endif - @elseif ($type == 'select') - @if ($setting->value == 1) - YES - @else - NO - @endif - @else - {!! $setting->value !!} - @endif + {!! $setting->list_value !!} @if((bool)$setting->system !== true) diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index c5fdaca8..5bf84b7d 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -1,6 +1,8 @@ @extends('app') @section('content') + @include('partials.search') + @if($apps->first()) @include('sortable') @else diff --git a/routes/web.php b/routes/web.php index ae7591de..d1fc1bb4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -34,6 +34,8 @@ Route::group([ ->name('index'); Route::get('edit/{id}', 'SettingsController@edit') ->name('edit'); + Route::get('clear/{id}', 'SettingsController@clear') + ->name('clear'); Route::patch('edit/{id}', 'SettingsController@update');