diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php new file mode 100644 index 000000000..e0695f22d --- /dev/null +++ b/app/Http/Controllers/SettingController.php @@ -0,0 +1,44 @@ +checkPermission('settings-update'); + return view('settings/index'); + } + + + + /** + * Update the specified settings in storage. + * + * @param Request $request + * @return Response + */ + public function update(Request $request) + { + $this->checkPermission('settings-update'); + // Cycles through posted settings and update them + foreach($request->all() as $name => $value) { + if(strpos($name, 'setting-') !== 0) continue; + $key = str_replace('setting-', '', trim($name)); + Setting::put($key, $value); + } + return redirect('/settings'); + } + +} diff --git a/app/Http/routes.php b/app/Http/routes.php index eb945c72f..2dfd35abd 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -71,6 +71,10 @@ Route::group(['middleware' => 'auth'], function () { Route::get('/', 'HomeController@index'); Route::get('/home', 'HomeController@index'); + // Settings + Route::get('/settings', 'SettingController@index'); + Route::post('/settings', 'SettingController@update'); + }); diff --git a/app/Providers/CustomFacadeProvider.php b/app/Providers/CustomFacadeProvider.php index bb4520c18..6e6318824 100644 --- a/app/Providers/CustomFacadeProvider.php +++ b/app/Providers/CustomFacadeProvider.php @@ -4,6 +4,7 @@ namespace Oxbow\Providers; use Illuminate\Support\ServiceProvider; use Oxbow\Services\ActivityService; +use Oxbow\Services\SettingService; class CustomFacadeProvider extends ServiceProvider { @@ -27,5 +28,9 @@ class CustomFacadeProvider extends ServiceProvider $this->app->bind('activity', function() { return new ActivityService($this->app->make('Oxbow\Activity')); }); + + $this->app->bind('setting', function() { + return new SettingService($this->app->make('Oxbow\Setting')); + }); } } diff --git a/app/Services/ActivityService.php b/app/Services/ActivityService.php index a4259bf12..a515eea1c 100644 --- a/app/Services/ActivityService.php +++ b/app/Services/ActivityService.php @@ -81,11 +81,13 @@ class ActivityService * Gets the latest activity. * @param int $count * @param int $page + * @return array */ public function latest($count = 20, $page = 0) { - return $this->activity->orderBy('created_at', 'desc') + $activityList = $this->activity->orderBy('created_at', 'desc') ->skip($count * $page)->take($count)->get(); + return $this->filterSimilar($activityList); } /** @@ -99,7 +101,7 @@ class ActivityService function entityActivity($entity, $count = 20, $page = 0) { $activity = $entity->hasMany('Oxbow\Activity')->orderBy('created_at', 'desc') - ->skip($count*$page)->take($count)->get(); + ->skip($count * $page)->take($count)->get(); return $this->filterSimilar($activity); } @@ -109,16 +111,17 @@ class ActivityService * @param Activity[] $activity * @return array */ - protected function filterSimilar($activity) { + protected function filterSimilar($activity) + { $newActivity = []; $previousItem = false; - foreach($activity as $activityItem) { - if($previousItem === false) { + foreach ($activity as $activityItem) { + if ($previousItem === false) { $previousItem = $activityItem; $newActivity[] = $activityItem; continue; } - if(!$activityItem->isSimilarTo($previousItem)) { + if (!$activityItem->isSimilarTo($previousItem)) { $newActivity[] = $activityItem; } $previousItem = $activityItem; diff --git a/app/Services/Facades/Setting.php b/app/Services/Facades/Setting.php new file mode 100644 index 000000000..eb584416b --- /dev/null +++ b/app/Services/Facades/Setting.php @@ -0,0 +1,14 @@ +setting = $setting; + } + + /** + * Gets a setting from the database, + * If not found, Returns default, Which is false by default. + * @param $key + * @param string|bool $default + * @return bool|string + */ + public function get($key, $default = false) + { + $setting = $this->getSettingObjectByKey($key); + return $setting === null ? $default : $setting->value; + } + + /** + * Checks if a setting exists. + * @param $key + * @return bool + */ + public function has($key) + { + $setting = $this->getSettingObjectByKey($key); + return $setting !== null; + } + + /** + * Add a setting to the database. + * @param $key + * @param $value + * @return bool + */ + public function put($key, $value) + { + $setting = $this->setting->firstOrNew([ + 'setting_key' => $key + ]); + $setting->value = $value; + $setting->save(); + return true; + } + + /** + * Removes a setting from the database. + * @param $key + * @return bool + */ + public function remove($key) + { + $setting = $this->getSettingObjectByKey($key); + if($setting) { + $setting->delete(); + } + return true; + } + + /** + * Gets a setting model from the database for the given key. + * @param $key + * @return mixed + */ + private function getSettingObjectByKey($key) { + return $this->setting->where('setting_key', '=', $key)->first(); + } + +} \ No newline at end of file diff --git a/app/Setting.php b/app/Setting.php new file mode 100644 index 000000000..af36a1a7e --- /dev/null +++ b/app/Setting.php @@ -0,0 +1,12 @@ + env('APP_DEBUG', false), + 'debug' => env('APP_DEBUG', false), /* |-------------------------------------------------------------------------- @@ -26,7 +26,7 @@ return [ | */ - 'url' => 'http://localhost', + 'url' => 'http://localhost', /* |-------------------------------------------------------------------------- @@ -39,7 +39,7 @@ return [ | */ - 'timezone' => 'UTC', + 'timezone' => 'UTC', /* |-------------------------------------------------------------------------- @@ -52,7 +52,7 @@ return [ | */ - 'locale' => 'en', + 'locale' => 'en', /* |-------------------------------------------------------------------------- @@ -78,9 +78,9 @@ return [ | */ - 'key' => env('APP_KEY', 'AbAZchsay4uBTU33RubBzLKw203yqSqr'), + 'key' => env('APP_KEY', 'AbAZchsay4uBTU33RubBzLKw203yqSqr'), - 'cipher' => 'AES-256-CBC', + 'cipher' => 'AES-256-CBC', /* |-------------------------------------------------------------------------- @@ -95,7 +95,7 @@ return [ | */ - 'log' => 'single', + 'log' => 'single', /* |-------------------------------------------------------------------------- @@ -108,7 +108,7 @@ return [ | */ - 'providers' => [ + 'providers' => [ /* * Laravel Framework Service Providers... @@ -165,7 +165,7 @@ return [ | */ - 'aliases' => [ + 'aliases' => [ 'App' => Illuminate\Support\Facades\App::class, 'Artisan' => Illuminate\Support\Facades\Artisan::class, @@ -210,7 +210,8 @@ return [ * Custom */ - 'Activity' => Oxbow\Services\Facades\Activity::class, + 'Activity' => Oxbow\Services\Facades\Activity::class, + 'Setting' => Oxbow\Services\Facades\Setting::class, ], diff --git a/database/migrations/2015_08_30_125859_create_settings_table.php b/database/migrations/2015_08_30_125859_create_settings_table.php new file mode 100644 index 000000000..8437668f7 --- /dev/null +++ b/database/migrations/2015_08_30_125859_create_settings_table.php @@ -0,0 +1,31 @@ +string('setting_key')->primary()->indexed(); + $table->text('value'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('settings'); + } +} diff --git a/resources/assets/sass/_forms.scss b/resources/assets/sass/_forms.scss index 2e0c5cf0e..1fb24cb4a 100644 --- a/resources/assets/sass/_forms.scss +++ b/resources/assets/sass/_forms.scss @@ -10,7 +10,7 @@ color: #222; width: 250px; max-width: 100%; - -webkit-appearance:none; + //-webkit-appearance:none; &.neg, &.invalid { border: 1px solid $negative; } @@ -25,9 +25,10 @@ label { display: block; line-height: 1.4em; - font-size: 0.9em; + font-size: 0.94em; font-weight: 500; - color: #333; + color: #666; + padding-bottom: 2px; } label.radio, label.checkbox { diff --git a/resources/assets/sass/styles.scss b/resources/assets/sass/styles.scss index 7be43ab6b..d6534789a 100644 --- a/resources/assets/sass/styles.scss +++ b/resources/assets/sass/styles.scss @@ -485,4 +485,19 @@ body.dragging, body.dragging * { background-color: $negative; color: #EEE; } +} + +.setting-nav { + margin-top: $-l; + border-top: 1px solid #DDD; + border-bottom: 1px solid #DDD; + a { + padding: $-m; + display: inline-block; + //color: #666; + &.selected { + //color: $primary; + background-color: #f8f8f8; + } + } } \ No newline at end of file diff --git a/resources/views/base.blade.php b/resources/views/base.blade.php index 06f217848..4e1e74398 100644 --- a/resources/views/base.blade.php +++ b/resources/views/base.blade.php @@ -54,7 +54,7 @@
- +
{{ Auth::user()->name }} diff --git a/resources/views/books/show.blade.php b/resources/views/books/show.blade.php index 4f007e243..d80cc09e1 100644 --- a/resources/views/books/show.blade.php +++ b/resources/views/books/show.blade.php @@ -78,8 +78,6 @@
- -