refactor helpers

This commit is contained in:
radhika587
2022-02-23 17:58:07 +05:30
parent 439fc4e002
commit b819307612
5 changed files with 81 additions and 117 deletions

View File

@ -44,8 +44,8 @@ class InvoicePdfController extends Controller
} }
return view('app')->with([ return view('app')->with([
'customer_logo' => get_customer_logo($invoice->company_id), 'customer_logo' => get_company_setting('customer_portal_logo', $invoice->company_id),
'current_theme' => get_customer_portal_theme($invoice->company_id) 'current_theme' => get_company_setting('customer_portal_theme', $invoice->company_id)
]); ]);
} }

View File

@ -26,11 +26,11 @@ class ViewServiceProvider extends ServiceProvider
public function boot() public function boot()
{ {
if (\Storage::disk('local')->has('database_created') && Schema::hasTable('settings')) { if (\Storage::disk('local')->has('database_created') && Schema::hasTable('settings')) {
View::share('login_page_logo', get_login_page_logo()); View::share('login_page_logo', get_app_setting('login_page_logo'));
View::share('login_page_heading', get_login_page_heading()); View::share('login_page_heading', get_app_setting('login_page_heading'));
View::share('login_page_description', get_login_page_description()); View::share('login_page_description', get_app_setting('login_page_description'));
View::share('admin_page_title', get_admin_page_title()); View::share('admin_page_title', get_app_setting('admin_page_title'));
View::share('copyright_text', get_copyright_text()); View::share('copyright_text', get_app_setting('copyright_text'));
} }
} }
} }

View File

@ -7,127 +7,53 @@ use Crater\Models\Setting;
use Illuminate\Support\Str; use Illuminate\Support\Str;
/** /**
* Get current customer theme * Get company setting
* *
* @param $company_id * @param $company_id
* @return string * @return string
*/ */
function get_customer_portal_theme($company_id) function get_company_setting($key, $company_id)
{ {
if (\Storage::disk('local')->has('database_created')) { if (\Storage::disk('local')->has('database_created')) {
return CompanySetting::getSetting('customer_portal_theme', $company_id); return CompanySetting::getSetting($key, $company_id);
} }
} }
/** /**
* Get current customer logo * Get app setting
* *
* @param $company_id * @param $company_id
* @return string * @return string
*/ */
function get_customer_logo($company_id) function get_app_setting($key)
{ {
if (\Storage::disk('local')->has('database_created')) { if (\Storage::disk('local')->has('database_created')) {
return CompanySetting::getSetting('customer_portal_logo', $company_id); return Setting::getSetting($key);
} }
} }
/** /**
* Get current customer page title * Get page title
* *
* @param $company_id * @param $company_id
* @return string * @return string
*/ */
function get_customer_page_title($company_id) function get_page_title($company_id)
{ {
$routeName = Route::currentRouteName();
$pageTitle = null;
$defaultPageTitle = 'Crater - Self Hosted Invoicing Platform';
if (\Storage::disk('local')->has('database_created')) { if (\Storage::disk('local')->has('database_created')) {
return CompanySetting::getSetting('customer_portal_page_title', $company_id); if ($routeName === 'customer.dashboard') {
} $pageTitle = CompanySetting::getSetting('customer_portal_page_title', $company_id);
return $pageTitle ? $pageTitle : $defaultPageTitle;
} }
/** $pageTitle = Setting::getSetting('admin_page_title');
* Get current admin portal logo return $pageTitle ? $pageTitle : $defaultPageTitle;
*
* @param $company_id
* @return string
*/
function get_login_page_logo()
{
if (\Storage::disk('local')->has('database_created')) {
return Setting::getSetting('login_page_logo');
}
}
/**
* Get current admin theme
*
* @return string
*/
function get_admin_portal_theme()
{
if (\Storage::disk('local')->has('database_created')) {
$setting = Setting::getSetting('admin_portal_theme');
if ($setting) {
return $setting;
}
return 'crater';
}
return 'crater';
}
/**
* Get current login page heading
*
* @param $company_id
* @return string
*/
function get_login_page_heading()
{
if (\Storage::disk('local')->has('database_created')) {
return Setting::getSetting('login_page_heading');
}
}
/**
* Get current login page description
*
* @param $company_id
* @return string
*/
function get_login_page_description()
{
if (\Storage::disk('local')->has('database_created')) {
return Setting::getSetting('login_page_description');
}
}
/**
* Get admin page title
*
* @param $company_id
* @return string
*/
function get_admin_page_title()
{
if (\Storage::disk('local')->has('database_created')) {
return Setting::getSetting('admin_page_title');
}
}
/**
* Get admin page title
*
* @param $company_id
* @return string
*/
function get_copyright_text()
{
if (\Storage::disk('local')->has('database_created')) {
return Setting::getSetting('copyright_text');
} }
} }

View File

@ -3,20 +3,58 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
@if (Route::currentRouteName() === 'admin') <!-- @php
@if(isset($admin_page_title) && $admin_page_title != null) $routeName = Route::currentRouteName();
<title>{{$admin_page_title}}</title>
$isAdminPage = false;
$isCustomerPage = false;
$hasAdminPageTitle = false;
$hasCustomerPageTitle = false;
switch ($routeName) {
case 'admin.dashboard':
$isAdminPage = true;
break;
case 'home':
$isAdminPage = true;
break;
case 'login':
$isAdminPage = true;
break;
case 'reset-password':
$isAdminPage = true;
break;
case 'forgot-password':
$isAdminPage = true;
break;
case 'customer.dashboard':
$isCustomerPage = true;
break;
}
if(isset($admin_page_title) && $admin_page_title != null) {
$hasAdminPageTitle = true;
}
if(isset($customer_page_title) && $customer_page_title != null) {
$hasCustomerPageTitle = true;
}
@endphp -->
<!-- @if ($isAdminPage && $hasAdminPageTitle)
<title>Admin Page</title>
@elseif ($isCustomerPage && $hasCustomerPageTitle)
<title>Customer Page</title>
@else @else
<title>Crater - Self Hosted Invoicing Platform</title> <title>Crater - Self Hosted Invoicing Platform</title>
@endif @endif -->
@endif
@if (Route::currentRouteName() === 'customer.login') <title>{{ get_page_title(!Request::header('company')) }}</title>
@if(isset($customer_page_title) && $customer_page_title != null)
<title>{{$customer_page_title}}</title>
@else
<title>Crater - Self Hosted Invoicing Platform</title>
@endif
@endif
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicons/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="32x32" href="/favicons/favicon-32x32.png">
@ -39,7 +77,7 @@
<body <body
class="h-full overflow-hidden bg-gray-100 font-base class="h-full overflow-hidden bg-gray-100 font-base
@if(isset($current_theme)) theme-{{ $current_theme }} @else theme-{{get_admin_portal_theme()}} @endif "> @if(isset($current_theme)) theme-{{ $current_theme }} @else theme-{{get_app_setting('admin_portal_theme') ?? 'crater'}} @endif ">
<!-- Module Scripts --> <!-- Module Scripts -->
@foreach (\Crater\Services\Module\ModuleFacade::allScripts() as $name => $path) @foreach (\Crater\Services\Module\ModuleFacade::allScripts() as $name => $path)

View File

@ -131,15 +131,15 @@ Route::get('/installation', function () {
Route::get('/admin/{vue?}', function () { Route::get('/admin/{vue?}', function () {
return view('app'); return view('app');
})->where('vue', '[\/\w\.-]*')->name('admin')->middleware(['install', 'redirect-if-unauthenticated']); })->where('vue', '[\/\w\.-]*')->name('admin.dashboard')->middleware(['install', 'redirect-if-unauthenticated']);
Route::get('{company:slug}/customer/{vue?}', function (Company $company) { Route::get('{company:slug}/customer/{vue?}', function (Company $company) {
return view('app')->with([ return view('app')->with([
'customer_logo' => get_customer_logo($company->id), 'customer_logo' => get_company_setting('customer_portal_logo', $company->id),
'current_theme' => get_customer_portal_theme($company->id), 'current_theme' => get_company_setting('customer_portal_theme', $company->id),
'customer_page_title' => get_customer_page_title($company->id) 'customer_page_title' => get_company_setting('customer_portal_page_title', $company->id)
]); ]);
})->where('vue', '[\/\w\.-]*')->name('customer.login')->middleware(['install']); })->where('vue', '[\/\w\.-]*')->name('customer.dashboard')->middleware(['install']);
Route::get('/', function () { Route::get('/', function () {
return view('app'); return view('app');