1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-23 10:52:31 +01:00
This commit is contained in:
FreeScout 2018-09-22 22:02:02 -07:00
parent 597416b4bc
commit a679d1915d
14 changed files with 279 additions and 17 deletions

3
.gitignore vendored
View File

@ -24,3 +24,6 @@ Thumbs.db
public/css/builds/
public/js/builds/
public/.well-known
/Modules
/Modules/**/.git
public/modules

26
Modules/.gitkeep Normal file
View File

@ -0,0 +1,26 @@
/node_modules
/public/hot
/public/storage
/storage/*.key
# We are committing /vendor directory to make installation process super easy, even on a shared hosting:
# - https://www.codeenigma.com/build/blog/do-you-really-need-composer-production
# - https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md
/vendor/**/.git
#/vendor
/.idea
/.vagrant
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.env
/bootstrap/compiled.php
composer.phar
composer.lock
.DS_Store
Thumbs.db
/.htaccess
public/css/builds/
public/js/builds/
public/.well-known

View File

@ -18,7 +18,7 @@ class Build extends Command
*
* @var string
*/
protected $description = 'Run commands building app assets';
protected $description = 'Run commands building application assets';
/**
* Create a new command instance.

View File

@ -0,0 +1,113 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
class ModuleBuild extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'freescout:module-build {module_alias?}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Build module or all modules (if module_alias is empty)';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$all = false;
$modules = [];
// Create a symlink for the module (or all modules)
$module_alias = $this->argument('module_alias');
if (!$module_alias) {
$modules = \Module::all();
$modules_aliases = [];
foreach ($modules as $module) {
$modules_aliases[] = $module->name;
}
if (!$modules_aliases) {
$this->error('No modules found');
return;
}
$all = $this->confirm('You have not specified a module alias, would you like to build all available modules ('.implode(', ', $modules_aliases).')?');
if (!$all) {
return;
}
}
if ($all) {
foreach ($modules as $module) {
$this->buildModule($module);
}
} else {
$module = \Module::findByAlias($module_alias);
if (!$module) {
$this->error('Module with the specified alias not found: '.$module_alias);
return;
}
$this->buildModule($module);
}
}
public function buildModule($module)
{
$this->line('Module: '.$module->getName());
$public_symlink = public_path('modules').DIRECTORY_SEPARATOR.$module->alias;
if (!file_exists($public_symlink)) {
$this->error('Public symlink ['.$public_symlink.'] not found. Run module installation command first: php artisan freescout:module-install');
return;
}
$this->buildVars($module);
}
public function buildVars($module)
{
try {
$params = [
'locales' => config('app.locales'),
];
$filesystem = new Filesystem();
$file_path = public_path('modules/'.$module->alias.'/js/vars.js');
$compiled = view($module->alias.'::js/vars', $params)->render();
if ($compiled) {
$filesystem->put($file_path, $compiled);
}
$this->info("Created: {$file_path}");
} catch (\Exception $e) {
$this->error($e->getMessage());
}
}
}

View File

@ -0,0 +1,97 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class ModuleInstall extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'freescout:module-install {module_alias?}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Install module or all modules (if module_alias is empty)';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$install_all = false;
$modules = [];
// Create a symlink for the module (or all modules)
$module_alias = $this->argument('module_alias');
if (!$module_alias) {
$modules = \Module::all();
$modules_aliases = [];
foreach ($modules as $module) {
$modules_aliases[] = $module->name;
}
if (!$modules_aliases) {
$this->error('No modules found');
return;
}
$install_all = $this->confirm('You have not specified a module alias, would you like to install all available modules ('.implode(', ', $modules_aliases).')?');
if (!$install_all) {
return;
}
}
if ($install_all) {
$this->call('module:migrate');
foreach ($modules as $module) {
$this->createModulePublicSymlink($module);
}
} else {
$module = \Module::findByAlias($module_alias);
if (!$module) {
$this->error('Module with the specified alias not found: '.$module_alias);
return;
}
$this->call('module:migrate "'.$module->getName().'"');
$this->createModulePublicSymlink($module);
}
$this->call('cache:clear');
$this->call('queue:restart');
}
public function createModulePublicSymlink($module)
{
$from = public_path('modules').DIRECTORY_SEPARATOR.$module->alias;
$to = $module->getExtraPath('Public');
if (file_exists($from)) {
return $this->info('Public symlink already exists');
}
try {
symlink($to, $from);
} catch (\Exception $e) {
$this->error('Error occured creating ['.$from.'] symlink: '.$e->getMessage());
}
$this->info('The ['.$from.'] symlink has been created');
}
}

View File

@ -65,11 +65,11 @@ class Option extends Model
* @param string $name
* @return string
*/
public static function get($name, $default = false, $decode = true, $cache = false)
public static function get($name, $default = false, $decode = true)
{
if ($cache && isset(self::$cache[$name])) {
return self::$cache[$name];
}
// if ($cache && isset(self::$cache[$name])) {
// return self::$cache[$name];
// }
$option = Option::where('name', (string)$name)->first();
if ($option) {
@ -82,9 +82,9 @@ class Option extends Model
$value = $default;
}
if ($cache) {
self::$cache[$name] = $value;
}
// if ($cache) {
// self::$cache[$name] = $value;
// }
return $value;
}

View File

@ -26,6 +26,9 @@ class AppServiceProvider extends ServiceProvider
\App\Conversation::observe(\App\Observers\ConversationObserver::class);
\App\Thread::observe(\App\Observers\ThreadObserver::class);
\Illuminate\Notifications\DatabaseNotification::observe(\App\Observers\DatabaseNotificationObserver::class);
// Module functions
$this->registerModuleFunctions();
}
/**
@ -43,4 +46,18 @@ class AppServiceProvider extends ServiceProvider
$this->app['url']->forceScheme('https');
}
}
/**
* Register functions allowing modules to get/set their options.
*/
public function registerModuleFunctions()
{
\Module::macro('getOption', function($module_alias, $option_name) {
$default = \Config::get(strtolower($module_alias).'.'.$option_name);
return \Option::get($module_alias.'.'.$option_name, $default);
});
\Module::macro('setOption', function($module_alias, $option_name, $option_value) {
return \Option::set(strtolower($module_alias).'.'.$option_name, $option_value);
});
}
}

View File

@ -16,7 +16,9 @@
"axn/laravel-laroute": "1.3.0",
"html2text/html2text": "4.1.0",
"webklex/laravel-imap": "1.2.7",
"watson/rememberable": "2.0.4"
"watson/rememberable": "2.0.4",
"nwidart/laravel-modules": "2.7.0",
"tormjens/eventy": "0.5.4"
},
"require-dev": {
"barryvdh/laravel-debugbar": "v2.4.3",
@ -31,7 +33,8 @@
"database/factories"
],
"psr-4": {
"App\\": "app/"
"App\\": "app/",
"Modules\\": "Modules/"
}
},
"autoload-dev": {

View File

@ -285,6 +285,7 @@ return [
// Custom
'Helper' => App\Misc\Helper::class,
'Option' => App\Option::class,
],
];

4
public/js/vars.js vendored
View File

@ -8,7 +8,7 @@ var Vars = {
};
var lang_messages = {
var LangMessages = {
"en.messages": {
"ajax_error": "Error occured. Please check your internet connection and try again.",
@ -54,5 +54,5 @@ var lang_messages = {
(function () {
Lang = new Lang();
Lang.setMessages(lang_messages);
Lang.setMessages(LangMessages);
})();

0
public/modules/.gitkeep Normal file
View File

View File

@ -18,7 +18,7 @@ var Vars = {
Lang.get('messages.ajax_error');
Lang.get('messages.ajax_error', { name: 'Joe' });
--}}
var lang_messages = {
var LangMessages = {
@foreach ($locales as $locale)
"{{ $locale }}.messages": {
{{-- Add here strings which you need to be translated in JS--}}
@ -67,5 +67,5 @@ var lang_messages = {
(function () {
Lang = new Lang();
Lang.setMessages(lang_messages);
Lang.setMessages(LangMessages);
})();

View File

@ -21,7 +21,7 @@
{{-- Styles --}}
{{-- Conversation page must open immediately, so we are loading scripts present on conversation page --}}
{{-- style.css must be the last to able to redefine styles --}}
{!! Minify::stylesheet(array('/css/fonts.css', '/css/bootstrap.css', '/css/select2/select2.min.css', '/js/featherlight/featherlight.min.css', '/js/featherlight/featherlight.gallery.min.css', '/css/style.css')) !!}
{!! Minify::stylesheet(\Eventy::filter('stylesheets', array('/css/fonts.css', '/css/bootstrap.css', '/css/select2/select2.min.css', '/js/featherlight/featherlight.min.css', '/js/featherlight/featherlight.gallery.min.css', '/css/style.css'))) !!}
@yield('stylesheets')
</head>
<body class="@if (Auth::user() && Auth::user()->isAdmin()) user-is-admin @endif @yield('body_class')" @yield('body_attrs') @if (Auth::user()) data-auth_user_id="{{ Auth::user()->id }}" @endif>
@ -254,7 +254,7 @@
@yield('body_bottom')
{{-- Scripts --}}
{!! Minify::javascript(array('/js/jquery.js', '/js/bootstrap.js', '/js/laroute.js', '/js/lang.js', '/js/vars.js', '/js/parsley/parsley.min.js', '/js/parsley/i18n/'.Config::get('app.locale').'.js', '/js/select2/select2.full.min.js', '/js/polycast/polycast.js', '/js/push/push.min.js', '/js/featherlight/featherlight.min.js', '/js/featherlight/featherlight.gallery.min.js', '/js/main.js')) !!}
{!! Minify::javascript(\Eventy::filter('javascripts', array('/js/jquery.js', '/js/bootstrap.js', '/js/laroute.js', '/js/lang.js', '/js/vars.js', '/js/parsley/parsley.min.js', '/js/parsley/i18n/'.Config::get('app.locale').'.js', '/js/select2/select2.full.min.js', '/js/polycast/polycast.js', '/js/push/push.min.js', '/js/featherlight/featherlight.min.js', '/js/featherlight/featherlight.gallery.min.js', '/js/main.js'))) !!}
@yield('javascripts')
@if ($__env->yieldContent('javascript'))
<script type="text/javascript">

View File

@ -5,6 +5,7 @@
@section('content')
<div class="container">
<div class="heading">{{ App\Option::getCompanyName() }} {{ __('Dashboard') }}</div>
@filter('before_dashboard', '')
@if (count($mailboxes))
<div class="dash-cards margin-top">
@foreach ($mailboxes as $mailbox)
@ -53,5 +54,6 @@
@else
@include('partials/empty', ['icon' => 'home', 'empty_text' => __("Welcome home!")])
@endif
@filter('after_dashboard', '')
</div>
@endsection