Skip to content

Commit

Permalink
Merge branch 'develop' into wip/support-uploading-packages
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeTowers committed Nov 27, 2024
2 parents 29195d2 + ad02e34 commit a88d645
Show file tree
Hide file tree
Showing 36 changed files with 262 additions and 177 deletions.
39 changes: 34 additions & 5 deletions modules/backend/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<?php namespace Backend;

use Backend;
use BackendMenu;
use BackendAuth;
use Backend\Models\UserRole;
use Backend\Classes\WidgetManager;
use System\Classes\MailManager;
use Backend\Facades\Backend;
use Backend\Facades\BackendAuth;
use Backend\Facades\BackendMenu;
use Backend\Models\AccessLog;
use Backend\Models\UserRole;
use Exception;
use Illuminate\Support\Facades\Event;
use System\Classes\CombineAssets;
use System\Classes\MailManager;
use System\Classes\SettingsManager;
use System\Classes\UpdateManager;
use Winter\Storm\Support\Facades\Config;
use Winter\Storm\Support\Facades\Flash;
use Winter\Storm\Support\ModuleServiceProvider;

class ServiceProvider extends ModuleServiceProvider
Expand All @@ -25,6 +31,7 @@ public function register()
$this->registerMailer();
$this->registerAssetBundles();
$this->registerBackendPermissions();
$this->registerBackendUserEvents();

/*
* Backend specific
Expand Down Expand Up @@ -207,6 +214,28 @@ protected function registerBackendPermissions()
});
}

/**
* Register the backend user events
*/
protected function registerBackendUserEvents()
{
Event::listen('backend.user.login', function (\Backend\Models\User $user) {
// @TODO: Deprecate this, and only run migrations when it makes sense
$runMigrationsOnLogin = (bool) Config::get('cms.runMigrationsOnLogin', Config::get('app.debug', false));
if ($runMigrationsOnLogin) {
try {
// Load version updates
UpdateManager::instance()->update();
} catch (Exception $e) {
Flash::error($e->getMessage());
}
}

// Log the sign in event
AccessLog::add($user);
});
}

/*
* Register widgets
*/
Expand Down
16 changes: 0 additions & 16 deletions modules/backend/controllers/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
use Backend;
use BackendAuth;
use Backend\Classes\Controller;
use Backend\Models\AccessLog;
use Config;
use Exception;
use Flash;
use Mail;
use Request;
use System\Classes\UpdateManager;
use ValidationException;
use Validator;
use Winter\Storm\Foundation\Http\Middleware\CheckForTrustedHost;
Expand Down Expand Up @@ -94,20 +92,6 @@ public function signin_onSubmit()
'password' => post('password')
], $remember);

$runMigrationsOnLogin = (bool) Config::get('cms.runMigrationsOnLogin', Config::get('app.debug', false));

if ($runMigrationsOnLogin) {
try {
// Load version updates
UpdateManager::instance()->update();
} catch (Exception $ex) {
Flash::error($ex->getMessage());
}
}

// Log the sign in event
AccessLog::add($user);

// Redirect to the intended page after successful sign in
return Backend::redirectIntended('backend');
}
Expand Down
6 changes: 5 additions & 1 deletion modules/backend/formwidgets/RecordFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class RecordFinder extends FormWidgetBase
/**
* @var string Prompt to display if no record is selected.
*/
public $prompt = 'Click the %s button to find a record';
public $prompt = null;

/**
* @var int Maximum rows to display for each page.
Expand Down Expand Up @@ -144,6 +144,10 @@ public function init()
'modelClass',
]);

if (!isset($this->prompt)) {
$this->prompt = Lang::get('backend::lang.recordfinder.default_prompt');
}

if (!$this->useRelation && !class_exists($this->modelClass)) {
throw new ApplicationException(Lang::get('backend::lang.recordfinder.invalid_model_class', ['modelClass' => $this->modelClass]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ class="field-recordfinder loading-indicator-container size-input-text"
data-control="recordfinder"
data-refresh-handler="<?= $this->getEventHandler('onRefresh') ?>"
data-data-locker="#<?= $field->getId() ?>">
<span class="form-control" <?= $previewMode ? 'disabled="disabled"' : '' ?>>
<span class="form-control" style="cursor:pointer"
<?= $previewMode ? 'disabled="disabled"' : '' ?>
data-control="popup"
data-size="huge"
data-handler="<?= $this->getEventHandler('onFindRecord') ?>"
data-request-data="recordfinder_flag: 1"
>
<?php if ($value): ?>
<span class="primary"><?= e($nameValue) ?: 'Undefined' ?></span>
<?php if ($descriptionValue): ?>
Expand Down
2 changes: 1 addition & 1 deletion modules/backend/formwidgets/repeater/assets/js/repeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
return $textInput.val()
}
} else {
var $disabledTextInput = $('.text-field:first > .form-control', $target)
var $disabledTextInput = $('.form-control:first', $target)
if ($disabledTextInput.length) {
return $disabledTextInput.text()
}
Expand Down
1 change: 1 addition & 0 deletions modules/backend/lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
],
'recordfinder' => [
'find_record' => 'Find Record',
'default_prompt' => 'Click the %s button to find a record',
'invalid_model_class' => 'The provided model class ":modelClass" for the recordfinder is invalid',
'cancel' => 'Cancel',
],
Expand Down
1 change: 1 addition & 0 deletions modules/backend/lang/fr/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
'return_to_list' => 'Retourner à la liste'
],
'recordfinder' => [
'default_prompt' => 'Cliquer sur %s pour chercher un enregistrement',
'find_record' => 'Trouver un enregistrement',
'invalid_model_class' => "La classe du modèle \":modelClass\" fournie pour le recordfinder n'est pas valide.",
'cancel' => 'Annuler',
Expand Down
2 changes: 1 addition & 1 deletion modules/backend/layouts/_head.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=0, minimal-ui">
<meta name="robots" content="noindex">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="app-timezone" content="<?= e(Config::get('app.timezone')) ?>">
<meta name="backend-base-path" content="<?= Backend::baseUrl() ?>">
<meta name="backend-timezone" content="<?= e(Backend\Models\Preference::get('timezone')) ?>">
Expand Down
2 changes: 1 addition & 1 deletion modules/backend/layouts/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=0">
<meta name="robots" content="noindex">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="backend-base-path" content="<?= Backend::baseUrl() ?>">
<meta name="csrf-token" content="<?= csrf_token() ?>">
<link rel="icon" type="image/png" href="<?= e(Backend\Models\BrandSetting::getFavicon()) ?>">
Expand Down
8 changes: 4 additions & 4 deletions modules/backend/models/User.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php namespace Backend\Models;

use Mail;
use Event;
use Backend;
use BackendAuth;
use Backend\Facades\Backend;
use Backend\Facades\BackendAuth;
use Illuminate\Support\Facades\Event;
use Winter\Storm\Auth\Models\User as UserBase;
use Winter\Storm\Support\Facades\Mail;

/**
* Administrator user model
Expand Down
7 changes: 3 additions & 4 deletions modules/backend/widgets/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function setFormValues($data = null)
public function onRefresh()
{
$result = [];
$saveData = $this->getSaveData(true);
$saveData = $this->getSaveData();

/**
* @event backend.form.beforeRefresh
Expand Down Expand Up @@ -1172,10 +1172,9 @@ protected function showFieldLabels($field)
/**
* Returns post data from a submitted form.
*/
public function getSaveData(bool $includeAllFields = false): array
public function getSaveData(): array
{
$this->defineFormFields();
$this->applyFiltersFromModel();

$result = [];

Expand All @@ -1194,7 +1193,7 @@ public function getSaveData(bool $includeAllFields = false): array
/*
* Disabled and hidden should be omitted from data set
*/
if (!$includeAllFields && ($field->disabled || $field->hidden)) {
if ($field->disabled || $field->hidden) {
continue;
}

Expand Down
90 changes: 79 additions & 11 deletions modules/cms/console/CreateTheme.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php namespace Cms\Console;

use InvalidArgumentException;
use System\Classes\Asset\PackageManager;
use Winter\Storm\Exception\SystemException;
use Winter\Storm\Scaffold\GeneratorCommand;

class CreateTheme extends GeneratorCommand
Expand Down Expand Up @@ -35,6 +37,11 @@ class CreateTheme extends GeneratorCommand
*/
protected $nameFrom = 'theme';

/**
* @var string The scaffold that we are building
*/
protected string $scaffold;

/**
* @var array Available theme scaffolds and their types
*/
Expand All @@ -54,10 +61,6 @@ class CreateTheme extends GeneratorCommand
'scaffold/theme/less/version.stub' => 'version.yaml',
],
'tailwind' => [
'scaffold/theme/tailwind/assets/src/css/base.stub' => 'assets/src/css/base.css',
'scaffold/theme/tailwind/assets/src/css/custom.stub' => 'assets/src/css/custom.css',
'scaffold/theme/tailwind/assets/src/css/theme.stub' => 'assets/src/css/theme.css',
'scaffold/theme/tailwind/assets/src/js/theme.stub' => 'assets/src/js/theme.js',
'scaffold/theme/tailwind/lang/en/lang.stub' => 'lang/en/lang.php',
'scaffold/theme/tailwind/layouts/default.stub' => 'layouts/default.htm',
'scaffold/theme/tailwind/pages/404.stub' => 'pages/404.htm',
Expand All @@ -68,12 +71,9 @@ class CreateTheme extends GeneratorCommand
'scaffold/theme/tailwind/partials/site/header.stub' => 'partials/site/header.htm',
'scaffold/theme/tailwind/partials/site/footer.stub' => 'partials/site/footer.htm',
'scaffold/theme/tailwind/.gitignore.stub' => '.gitignore',
'scaffold/theme/tailwind/package.stub' => 'package.json',
'scaffold/theme/tailwind/README.stub' => 'README.md',
'scaffold/theme/tailwind/tailwind.config.stub' => 'tailwind.config.js',
'scaffold/theme/tailwind/theme.stub' => 'theme.yaml',
'scaffold/theme/tailwind/version.stub' => 'version.yaml',
'scaffold/theme/tailwind/winter.mix.stub' => 'winter.mix.js',
],
];

Expand All @@ -90,12 +90,13 @@ protected function getNameInput(): string
*/
protected function prepareVars(): array
{
$scaffold = $this->argument('scaffold') ?? 'tailwind';
$this->scaffold = $this->argument('scaffold') ?? 'tailwind';

$validOptions = $this->suggestScaffoldValues();
if (!in_array($scaffold, $validOptions)) {
throw new InvalidArgumentException("$scaffold is not an available theme scaffold type (Available types: " . implode(', ', $validOptions) . ')');
if (!in_array($this->scaffold, $validOptions)) {
throw new InvalidArgumentException("$this->scaffold is not an available theme scaffold type (Available types: " . implode(', ', $validOptions) . ')');
}
$this->stubs = $this->themeScaffolds[$scaffold];
$this->stubs = $this->themeScaffolds[$this->scaffold];

return [
'code' => $this->getNameInput(),
Expand Down Expand Up @@ -146,4 +147,71 @@ public function makeStub($stubName)

$this->files->put($destinationFile, $destinationContent);
}

public function makeStubs(): void
{
parent::makeStubs();

if ($this->scaffold === 'tailwind') {
// @TODO: allow support for mix here
$this->tailwindPostCreate('vite');
}
}

protected function tailwindPostCreate(string $processor): void
{
if ($this->call('npm:version', ['--silent' => true, '--compatible' => true]) !== 0) {
throw new SystemException(sprintf(
'NPM is not installed or is outdated, please ensure NPM >= v7.0 is available and then manually set up %s.',
$processor
));
}

$commands = [
// Set up the vite config files
$processor . ':create' => [
'message' => 'Generating ' . $processor . ' + tailwind config...',
'args' => [
'packageName' => 'theme-' . $this->getNameInput(),
'--no-interaction' => true,
'--force' => true,
'--silent' => true,
'--tailwind' => true
]
],
// Ensure all require packages are available for the new theme and add the new theme to our npm workspaces
$processor . ':install' => [
'message' => 'Installing NPM dependencies...',
'args' => [
'assetPackage' => ['theme-' . $this->getNameInput()],
'--no-interaction' => true,
'--silent' => false,
'--disable-tty' => true
]
],
// Run an initial compile to ensure styles are available for first load
$processor . ':compile' => [
'message' => 'Compiling your theme...',
'args' => [
'--package' => ['theme-' . $this->getNameInput()],
'--no-interaction' => true,
'--silent' => true,
]
]
];

foreach ($commands as $command => $data) {
$this->info($data['message']);

// Handle commands throwing errors
if ($this->call($command, $data['args']) !== 0) {
throw new SystemException(sprintf('Post create command `%s` failed, please review manually.', $command));
}

// Force PackageManger to reset available packages
if ($command === $processor . ':create') {
PackageManager::forgetInstance();
}
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit a88d645

Please sign in to comment.