Browse Source

Add agency logo upload

Add appLogoImageHelper
Add new validation rule file_extension:ext1,ext2,...
Add default logo image
Restructure agency edit and detail page
pull/1/head
Nafies Luthfi 8 years ago
parent
commit
0edff8d5a3
  1. 18
      app/Http/Controllers/Users/AgencyController.php
  2. 2
      app/Http/Controllers/Users/ProfileController.php
  3. 3
      app/Providers/AppServiceProvider.php
  4. 31
      app/helpers.php
  5. BIN
      public/assets/imgs/default-logo.png
  6. 21
      resources/lang/id/agency.php
  7. 1
      resources/lang/id/contact.php
  8. 2
      resources/views/layouts/partials/sidebar.blade.php
  9. 28
      resources/views/users/agency/edit.blade.php
  10. 27
      resources/views/users/agency/show.blade.php
  11. 6
      routes/web/account.php
  12. 2
      tests/Feature/Auth/ChangePasswordTest.php
  13. 2
      tests/Feature/Auth/LoginTest.php
  14. 2
      tests/Feature/Auth/RegistrationTest.php
  15. 20
      tests/Feature/Users/UserProfileTest.php

18
app/Http/Controllers/Users/AgencyController.php

@ -33,4 +33,22 @@ class AgencyController extends Controller
return redirect()->route('users.agency.show');
}
public function logoUpload()
{
$file = request()->validate([
'logo' => 'required|max:100|file_extension:png,jpg',
]);
\File::delete(public_path('assets/imgs/'.Option::get('agency_logo_path')));
$filename = $file['logo']->getClientOriginalName();
$file['logo']->move(public_path('assets/imgs'), $filename);
Option::set('agency_logo_path', $filename);
flash(trans('agency.updated'), 'success');
return redirect()->route('users.agency.show');
}
}

2
app/Http/Controllers/Users/ProfileController.php

@ -24,7 +24,7 @@ class ProfileController extends Controller
{
$user = auth()->user();
$user->name = request('name');
$user->name = request('name');
$user->email = request('email');
$user->save();

3
app/Providers/AppServiceProvider.php

@ -14,6 +14,9 @@ class AppServiceProvider extends ServiceProvider
public function boot()
{
require_once app_path().'/helpers.php';
\Validator::extend('file_extension', function ($attribute, $value, $parameters, $validator) {
return in_array($value->getClientOriginalExtension(), $parameters);
});
}
/**

31
app/helpers.php

@ -14,10 +14,10 @@ function formatRp($number)
{
if ($number == 0) {return 'Rp. 0';}
if ($number < 0) {
return '- Rp. ' . formatNo(abs($number));
return '- Rp. '.formatNo(abs($number));
}
return 'Rp. ' . formatNo($number);
return 'Rp. '.formatNo($number);
}
function formatDecimal($number)
@ -67,9 +67,9 @@ function formatDate($date)
$explodedDate = explode('-', $date);
if (count($explodedDate) == 3 && checkdate($explodedDate[1], $explodedDate[0], $explodedDate[2])) {
return $explodedDate[2] . '-' . $explodedDate[1] . '-' . $explodedDate[0];
return $explodedDate[2].'-'.$explodedDate[1].'-'.$explodedDate[0];
} else if (count($explodedDate) == 3 && checkdate($explodedDate[1], $explodedDate[2], $explodedDate[0])) {
return $explodedDate[2] . '-' . $explodedDate[1] . '-' . $explodedDate[0];
return $explodedDate[2].'-'.$explodedDate[1].'-'.$explodedDate[0];
}
throw new App\Exceptions\InvalidDateException('Kesalahan format tanggal');
@ -85,7 +85,7 @@ function dateId($date)
if (count($explodedDate) == 3 && checkdate($explodedDate[1], $explodedDate[2], $explodedDate[0])) {
$months = getMonths();
return $explodedDate[2] . ' ' . $months[$explodedDate[1]] . ' ' . $explodedDate[0];
return $explodedDate[2].' '.$months[$explodedDate[1]].' '.$explodedDate[0];
}
throw new App\Exceptions\InvalidDateException('Kesalahan format tanggal');
@ -110,7 +110,7 @@ function monthId($monthNumber)
function getMonths()
{
return [
'' => 'Pilih Bulan',
'' => 'Pilih Bulan',
'01' => 'Januari',
'02' => 'Pebruari',
'03' => 'Maret',
@ -163,15 +163,15 @@ function sanitizeNumber($number)
function formatSizeUnits($bytes)
{
if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
$bytes = number_format($bytes / 1073741824, 2).' GB';
} elseif ($bytes >= 1048576) {
$bytes = number_format($bytes / 1048576, 2) . ' MB';
$bytes = number_format($bytes / 1048576, 2).' MB';
} elseif ($bytes >= 1024) {
$bytes = number_format($bytes / 1024, 2) . ' KB';
$bytes = number_format($bytes / 1024, 2).' KB';
} elseif ($bytes > 1) {
$bytes = $bytes . ' bytes';
$bytes = $bytes.' bytes';
} elseif ($bytes == 1) {
$bytes = $bytes . ' byte';
$bytes = $bytes.' byte';
} else {
$bytes = '0 bytes';
}
@ -189,7 +189,7 @@ function formatSizeUnits($bytes)
function html_link_to_route($name, $title = null, $parameters = [], $attributes = [])
{
if (array_key_exists('icon', $attributes)) {
$title = '<i class="fa fa-' . $attributes['icon'] . '"></i> ' . $title;
$title = '<i class="fa fa-'.$attributes['icon'].'"></i> '.$title;
}
return app('html')->decode(link_to_route($name, $title, $parameters, $attributes));
@ -234,3 +234,10 @@ function paymentTypes($paymentTypeId = null)
return null;
}
function appLogoImage()
{
$logoString = '<img style="display: block;text-align: center;margin: 0 auto;width: 100%;max-width: 200px"';
$logoString .= 'src="'.asset('assets/imgs/'.Option::get('agency_logo_path', 'default-logo.png')).'">';
return $logoString;
}

BIN
public/assets/imgs/default-logo.png

After

Width: 400  |  Height: 400  |  Size: 58 KiB

21
resources/lang/id/agency.php

@ -7,15 +7,18 @@ return [
'detail' => 'Detail Agensi',
// Actions
'edit' => 'Edit Agensi',
'update' => 'Update Agensi',
'updated' => 'Update data Agensi telah berhasil.',
'edit' => 'Edit Agensi',
'update' => 'Update Agensi',
'updated' => 'Update data Agensi telah berhasil.',
'logo_change' => 'Ganti Logo Agensi',
'logo_upload' => 'Upload Logo Agensi',
// Attributes
'name' => 'Nama Agensi',
'tagline' => 'Tagline Agensi',
'email' => 'Email Agensi',
'website' => 'Website Agensi',
'address' => 'Alamat Agensi',
'phone' => 'Telp. Agensi',
'name' => 'Nama Agensi',
'tagline' => 'Tagline Agensi',
'email' => 'Email Agensi',
'website' => 'Website Agensi',
'address' => 'Alamat Agensi',
'phone' => 'Telp. Agensi',
'logo' => 'Logo Agensi',
];

1
resources/lang/id/contact.php

@ -6,4 +6,5 @@ return [
'phone_abb' => 'Telp.',
'cellphone' => 'Telepon Selular',
'email' => 'Email',
'website' => 'Website',
];

2
resources/views/layouts/partials/sidebar.blade.php

@ -10,7 +10,7 @@
<div class="navbar-default sidebar hidden-print" role="navigation">
<div class="sidebar-nav navbar-collapse">
<a class="navbar-brand text-center" title="Home | {{ Option::get('agency_tagline', 'Laravel app description') }}" href="{{ route('home') }}">
{!! Html::image(url('assets/imgs/logo.png'), 'Logo '.Option::get('agency_name','Laravel'), ['class' => 'sidebar-logo']) !!}
{!! Html::image(asset('assets/imgs/'.Option::get('agency_logo_path', 'default-logo.png')), 'Logo '.Option::get('agency_name','Laravel'), ['class' => 'sidebar-logo']) !!}
<div class="small" style="margin-top:10px">{{ Option::get('app_name','Laravel') }}</div>
</a>
<ul class="nav" id="side-menu">

28
resources/views/users/agency/edit.blade.php

@ -4,16 +4,32 @@
@section('content-dashboard')
<div class="row">
<div class="col-md-6 col-lg-offset-2">
{{ Form::open(['route' => 'users.agency.update', 'method' => 'patch']) }}
{{ Form::open(['route' => 'users.agency.update', 'method' => 'patch']) }}
<div class="col-md-4">
<legend>{{ trans('agency.detail') }}</legend>
{!! FormField::text('name', ['value' => Option::get('agency_name')]) !!}
{!! FormField::text('tagline', ['value' => Option::get('agency_tagline')]) !!}
{!! FormField::email('email', ['value' => Option::get('agency_email')]) !!}
{!! FormField::text('website', ['value' => Option::get('agency_phone')]) !!}
{!! FormField::textarea('address', ['value' => Option::get('agency_address')]) !!}
{!! FormField::text('phone', ['value' => Option::get('agency_website')]) !!}
{{ Form::submit(trans('agency.update'), ['class' => 'btn btn-info']) }}
{{ link_to_route('users.agency.show', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
<br>
<br>
</div>
<div class="col-md-5">
<legend>{{ trans('contact.contact') }}</legend>
<div class="row">
<div class="col-md-6">{!! FormField::email('email', ['value' => Option::get('agency_email')]) !!}</div>
<div class="col-md-6">{!! FormField::text('phone', ['value' => Option::get('agency_phone')]) !!}</div>
</div>
{!! FormField::textarea('address', ['value' => Option::get('agency_address')]) !!}
{!! FormField::text('website', ['value' => Option::get('agency_website')]) !!}
</div>
{{ Form::close() }}
<div class="col-md-3">
{{ Form::open(['route' => 'users.agency.logo-upload', 'method' => 'patch', 'files' => true]) }}
<legend>{{ trans('agency.logo') }}</legend>
<p>{!! appLogoImage() !!}</p>
{!! FormField::file('logo', ['label' => trans('agency.logo_change')]) !!}
{{ Form::submit(trans('agency.logo_upload'), ['class' => 'btn btn-default']) }}
{{ Form::close() }}
</div>
</div>

27
resources/views/users/agency/show.blade.php

@ -4,19 +4,28 @@
@section('content-dashboard')
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="col-md-4 text-center">
<p>{!! appLogoImage() !!}</p>
<h3 class="text-primary">{{ Option::get('agency_name') }}</h3>
<p>{{ Option::get('agency_tagline') }}</p>
<br>
{{ link_to_route('users.agency.edit', trans('agency.edit'), [], ['class' => 'btn btn-info']) }}
</div>
<div class="col-md-8">
<legend style="border-bottom: none;margin-bottom: 10px; margin-left: 6px;">
{{ trans('agency.detail') }}
</legend>
<div class="panel panel-default">
<table class="table">
<tr><th class="col-xs-4">{{ trans('agency.name') }}</th><td>{{ Option::get('agency_name') }}</td></tr>
<tr><th>{{ trans('agency.name') }}</th><td>{{ Option::get('agency_name') }}</td></tr>
<tr><th>{{ trans('agency.tagline') }}</th><td>{{ Option::get('agency_tagline') }}</td></tr>
<tr><th>{{ trans('agency.email') }}</th><td>{{ Option::get('agency_email') }}</td></tr>
<tr><th>{{ trans('agency.phone') }}</th><td>{{ Option::get('agency_phone') }}</td></tr>
<tr><th>{{ trans('agency.address') }}</th><td>{!! nl2br(Option::get('agency_address')) !!}</td></tr>
<tr><th>{{ trans('agency.website') }}</th><td>{{ Option::get('agency_website') }}</td></tr>
<tr><th>{{ trans('contact.email') }}</th><td>{{ Option::get('agency_email') }}</td></tr>
<tr><th>{{ trans('contact.phone') }}</th><td>{{ Option::get('agency_phone') }}</td></tr>
<tr><th>{{ trans('address.address') }}</th><td>{!! nl2br(Option::get('agency_address')) !!}</td></tr>
<tr><th>{{ trans('contact.website') }}</th><td>{{ Option::get('agency_website') }}</td></tr>
</table>
<div class="panel-footer">
{{ link_to_route('users.agency.edit', trans('agency.edit'), [], ['class' => 'btn btn-info']) }}
</div>
</div>
</div>
</div>

6
routes/web/account.php

@ -59,3 +59,9 @@ Route::patch('agency/update', [
'uses' => 'Users\AgencyController@update',
'middleware' => ['web', 'auth'],
]);
Route::patch('agency/logo-upload', [
'as' => 'users.agency.logo-upload',
'uses' => 'Users\AgencyController@logoUpload',
'middleware' => ['web', 'auth'],
]);

2
tests/Feature/Auth/MemberChangePasswordTest.php → tests/Feature/Auth/ChangePasswordTest.php

@ -4,7 +4,7 @@ namespace Tests\Feature\Auth;
use Tests\TestCase;
class MemberChangePasswordTest extends TestCase
class ChangePasswordTest extends TestCase
{
/** @test */
public function member_can_change_password()

2
tests/Feature/Auth/MemberLoginTest.php → tests/Feature/Auth/LoginTest.php

@ -5,7 +5,7 @@ namespace Tests\Feature\Auth;
use App\Entities\Users\User;
use Tests\TestCase;
class MemberLoginTest extends TestCase
class LoginTest extends TestCase
{
/** @test */
public function user_can_login_and_logout()

2
tests/Feature/Auth/MemberRegistrationTest.php → tests/Feature/Auth/RegistrationTest.php

@ -5,7 +5,7 @@ namespace Tests\Feature\Auth;
use App\Entities\Users\User;
use Tests\TestCase;
class MemberRegistrationTest extends TestCase
class RegistrationTest extends TestCase
{
/** @test */
public function registration_validation()

20
tests/Feature/Users/UserProfileTest.php

@ -93,4 +93,24 @@ class UserProfileTest extends TestCase
'value' => 'Tagline agensi saya',
]);
}
/** @test */
public function admin_user_can_update_agency_logo_image()
{
$user = $this->adminUserSigningIn();
$this->visit(route('users.agency.edit'));
$this->attach(storage_path('app/guitar-640.jpg'), 'logo');
$this->press(trans('agency.logo_upload'));
$this->see(trans('agency.updated'));
$this->seePageIs(route('users.agency.show'));
$this->seeInDatabase('site_options', [
'key' => 'agency_logo_path',
'value' => 'guitar-640.jpg',
]);
$this->assertFileExistsThenDelete(public_path('assets/imgs/guitar-640.jpg'));
}
}
Loading…
Cancel
Save