Skip to content

Commit

Permalink
Merge branch 'jqhph:2.0' into inspire
Browse files Browse the repository at this point in the history
  • Loading branch information
jorry2008 authored Apr 20, 2022
2 parents 0743e60 + c7a9073 commit 414c14e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 22 deletions.
3 changes: 0 additions & 3 deletions config/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,6 @@
'file' => 'files',
],

// Overwriting an existing file.
'override' => env('ADMIN_UPLOAD_OVERRIDE', false),

],

/*
Expand Down
40 changes: 24 additions & 16 deletions resources/assets/dcat/js/extensions/DarkMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,48 @@ export default class DarkMode {
var storage = localStorage || {setItem:function () {}, getItem: function () {}},
darkMode = this,
key = 'dcat-admin-theme-mode',
mode = storage.getItem(key),
icon = '.dark-mode-switcher i';

function switchMode(dark) {
if (dark) {
$(icon).addClass('icon-sun').removeClass('icon-moon');
darkMode.display(true);
return;
function switchMode(theme) {
switch (theme) {
case 'dark': {
$(icon).addClass('icon-sun').removeClass('icon-moon');
darkMode.display(true);
break;
}
case 'def': {
darkMode.display(false);
$(icon).removeClass('icon-sun').addClass('icon-moon');
break;
}
default: {
break;
}
}

darkMode.display(false);
$(icon).removeClass('icon-sun').addClass('icon-moon');
}

if (mode === 'dark') {
switchMode(true);
} else if (mode === 'def') {
switchMode(false)
}
switchMode(storage.getItem(key));

$(document).off('click', selector).on('click', selector, function () {
$(icon).toggleClass('icon-sun icon-moon');

if ($(icon).hasClass('icon-moon')) {
switchMode(false);
switchMode('def');

storage.setItem(key, 'def');

} else {
storage.setItem(key, 'dark');

switchMode(true)
switchMode('dark')
}
})

window.addEventListener('storage', function (event) {
if (event.key === key) {
switchMode(event.newValue);
}
});
}

toggle() {
Expand Down
12 changes: 11 additions & 1 deletion src/Form/Field/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class File extends Field implements UploadFieldInterface
/**
* @var array
*/
protected $options = ['events' => []];
protected $options = [
'events' => [],
'override' => false,
];

public function __construct($column, $arguments = [])
{
Expand Down Expand Up @@ -227,4 +230,11 @@ public static function deleteRules(Field $field, &$fieldRules)
Helper::deleteContains($fieldRules, ['image', 'file', 'dimensions', 'size', 'max', 'min']);
}
}

public function override(bool $override = true)
{
$this->options['override'] = $override;

return $this;
}
}
13 changes: 12 additions & 1 deletion src/Form/Field/UploadField.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function initStorage()
*/
public function renameIfExists(UploadedFile $file)
{
if ($this->getStorage()->exists("{$this->getDirectory()}/$this->name") && ! config('admin.upload.override')) {
if ($this->getStorage()->exists("{$this->getDirectory()}/$this->name")) {
$this->name = $this->generateUniqueName($file);
}
}
Expand Down Expand Up @@ -194,6 +194,10 @@ public function upload(UploadedFile $file)

$this->name = $this->getStoreName($file);

if ($this->options['override']) {
$this->remove();
}

$this->renameIfExists($file);

$this->prepareFile($file);
Expand All @@ -216,6 +220,13 @@ public function upload(UploadedFile $file)
throw new UploadException(trans('admin.uploader.upload_failed'));
}

public function remove()
{
if ($this->getStorage()->exists("{$this->getDirectory()}/$this->name")) {
$this->getStorage()->delete("{$this->getDirectory()}/$this->name");
}
}

/**
* @param UploadedFile $file
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Scaffold/LangCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function create(string $controller, ?string $title)
*/
protected function getLangPath(string $controller)
{
$path = resource_path('lang/'.App::getLocale());
$path = rtrim(app()->langPath(), '/').'/'.App::getLocale();

return $path.'/'.Helper::slug($controller).'.php';
}
Expand Down

0 comments on commit 414c14e

Please sign in to comment.