App banner can now be set. Closes #120

This commit is contained in:
James Brooks
2014-12-31 11:45:54 +00:00
parent 3132a65cc3
commit d60cd4db81
3 changed files with 59 additions and 5 deletions

View File

@@ -99,7 +99,7 @@ class DashSettingsController extends Controller
}
/**
* Updates the statsu page settings.
* Updates the status page settings.
*
* @return \Illuminate\View\View
*/
@@ -108,6 +108,37 @@ class DashSettingsController extends Controller
// Fetch all of the settings we've been POSTed.
$settings = Input::all();
if (Input::hasFile('app_banner')) {
$file = Input::file('app_banner');
// Image Validation.
// Image size in bytes.
$maxSize = $file->getMaxFilesize();
if ($file->getSize() > $maxSize) {
return Redirect::back()->withErrorMessage('You need to upload an image that is less than '.$maxSize.'.');
} elseif (!$file->isValid() || $file->getError()) {
return Redirect::back()->withErrorMessage($file->getErrorMessage());
} elseif (strpos($file->getMimeType(), 'image/') !== 0) {
return Redirect::back()->withErrorMessage('Only images may be uploaded.');
}
// Store the banner.
Setting::firstOrCreate([
'name' => 'app_banner'
])->update([
'value' => base64_encode(file_get_contents($file->getRealPath()))
]);
// Store the banner type
Setting::firstOrCreate([
'name' => 'app_banner_type'
])->update([
'value' => $file->getMimeType()
]);
}
unset($settings['app_banner']);
try {
foreach ($settings as $settingName => $settingValue) {
$setting = Setting::firstOrCreate([

View File

@@ -13,13 +13,13 @@
<div class="content-wrapper">
<div class="row">
<div class="col-sm-12">
<form name='SettingsForm' class='form-vertical' role='form' action='/dashboard/settings' method='POST'>
<form name='SettingsForm' class='form-vertical' role='form' action='/dashboard/settings' method='POST' enctype="multipart/form-data">
<h4 class="sub-header" id='application-setup'>Application Setup</h4>
@if($saved = Session::get('saved'))
@if(($saved = Session::get('saved')))
<div class='alert alert-success'><strong>{{ Lang::get('cachet.dashboard.settings_saved') }}</strong></div>
@elseif(Session::has('saved'))
<div class='alert alert-danger'><strong>{{ Lang::get('cachet.dashboard.settings_not_saved') }}</strong></div>
@elseif(Session::has('error_message'))
<div class='alert alert-danger'><strong>{{ Session::get('error_message') }}</strong></div>
@endif
<fieldset>
@@ -39,6 +39,20 @@
</div>
</div>
</div>
<div class='row'>
<div class='col-xs-12'>
<div class='form-group'>
<label>Banner Image</label>
@if($banner = Setting::get('app_banner'))
<div class='well'>
<img src='data:{{ Setting::get("app_banner_type") }};base64,{{ $banner }}' style='max-width: ' />
</div>
@endif
<input type='file' name='app_banner' class='form-control' />
<span class='help-block'>It's recommended that you upload files no bigger than 930px wide.</span>
</div>
</div>
</div>
</fieldset>
<div class='row'>

View File

@@ -1,6 +1,15 @@
@extends('layout.master')
@section('content')
@if($bannerImage = Setting::get('app_banner'))
<div class='row'>
<div class='col-md-12 text-center'>
<?php $bannerType = Setting::get('app_banner_type') ?>
<img src='data:{{ $bannerType }};base64, {{ $bannerImage}}' class='banner-image' />
</div>
</div>
@endif
<div class='alert alert-{{ $systemStatus }}'>{{ $systemMessage }}</div>
@include('partials.components')