Skip to content

Commit

Permalink
Merge branch 'master' into events
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Apr 3, 2024
2 parents 3d2e661 + 456385c commit 69a685d
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 17 deletions.
4 changes: 2 additions & 2 deletions resources/views/fields/input.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</label>
<div class="form-group--stacked">
@if($prefix)
<div class="form-group-label">{!! $prefix !!}</div>
<div class="form-group-label" style="white-space: nowrap;">{!! $prefix !!}</div>
@endif
<input {{ $attrs }} value="{{ $value }}">
@if($suffix)
<div class="form-group-label">{!! $suffix !!}</div>
<div class="form-group-label" style="white-space: nowrap;">{!! $suffix !!}</div>
@endif
</div>
@if($invalid)
Expand Down
4 changes: 2 additions & 2 deletions resources/views/fields/morph-to.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class="form-control"
<div>
<div class="form-group--stacked">
@if($prefix)
<div class="form-group-label">{!! $prefix !!}</div>
<div class="form-group-label" style="white-space: nowrap;">{!! $prefix !!}</div>
@endif
<select {{ $attrs }}>
@if($nullable)
Expand All @@ -40,7 +40,7 @@ class="form-control"
@endforeach
</select>
@if($suffix)
<div class="form-group-label">{!! $suffix !!}</div>
<div class="form-group-label" style="white-space: nowrap;">{!! $suffix !!}</div>
@endif
</div>
@if($invalid)
Expand Down
4 changes: 2 additions & 2 deletions resources/views/fields/select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@if(! empty($options))
<div class="form-group--stacked">
@if($prefix)
<div class="form-group-label">{!! $prefix !!}</div>
<div class="form-group-label" style="white-space: nowrap;">{!! $prefix !!}</div>
@endif
<select {{ $attrs }}>
@if($nullable)
Expand All @@ -27,7 +27,7 @@
@endforeach
</select>
@if($suffix)
<div class="form-group-label">{!! $suffix !!}</div>
<div class="form-group-label" style="white-space: nowrap;">{!! $suffix !!}</div>
@endif
</div>
@if($invalid)
Expand Down
4 changes: 2 additions & 2 deletions resources/views/fields/slug.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</label>
<div class="form-group--stacked">
@if($prefix)
<div class="form-group-label">{!! $prefix !!}</div>
<div class="form-group-label" style="white-space: nowrap;">{!! $prefix !!}</div>
@endif
<input {{ $attrs }} value="{{ $value }}" x-bind:readonly="readonly">
@if($suffix)
<div class="form-group-label">{!! $suffix !!}</div>
<div class="form-group-label" style="white-space: nowrap;">{!! $suffix !!}</div>
@endif
<button type="button" class="btn btn--outline-primary" x-on:click="readonly = false">
{{ __('Edit') }}
Expand Down
45 changes: 41 additions & 4 deletions src/Fields/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace Cone\Root\Fields;

use Closure;
use Cone\Root\Root;
use DateTimeInterface;
use DateTimeZone;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Date as DateFactory;

class Date extends Field
Expand All @@ -18,7 +21,7 @@ class Date extends Field
/**
* The timezone.
*/
protected string $timezone = 'UTC';
protected string $timezone;

/**
* Indicates if the field should include time.
Expand All @@ -34,6 +37,7 @@ public function __construct(string $label, Closure|string|null $modelAttribute =

$this->type('date');
$this->step(1);
$this->timezone(Root::instance()->getTimezone());
}

/**
Expand Down Expand Up @@ -77,21 +81,54 @@ public function withTime(bool $value = true): static
/**
* Set the timezone.
*/
public function timezone(string $value): static
public function timezone(string|DateTimeZone $value): static
{
$this->timezone = $value;
$this->timezone = $value instanceof DateTimeZone ? $value->getName() : $value;

$this->suffix($this->timezone);

return $this;
}

/**
* {@inheritdoc}
*/
public function getValueForHydrate(Request $request): ?string
{
$value = parent::getValueForHydrate($request);

if (! is_null($value)) {
$value = DateFactory::parse($value, $this->timezone)
->setTimezone(Config::get('app.timezone'))
->toISOString();
}

return $value;
}

/**
* {@inheritdoc}
*/
public function getValue(Model $model): mixed
{
$value = parent::getValue($model);

if (! is_null($value)) {
$value = DateFactory::parse($value, Config::get('app.timezone'))
->setTimezone($this->timezone);
}

return $value;
}

/**
* {@inheritdoc}
*/
public function resolveFormat(Request $request, Model $model): ?string
{
if (is_null($this->formatResolver)) {
$this->formatResolver = function (Request $request, Model $model, mixed $value): ?string {
return is_null($value) ? $value : DateFactory::parse($value)->setTimezone($this->timezone)->format($this->format);
return is_null($value) ? $value : $value->format($this->format);
};
}

Expand Down
4 changes: 1 addition & 3 deletions src/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public function login(Request $request): RedirectResponse
}

if (! Auth::guard()->user()->hasVerifiedEmail()) {
$this->logout($request);

throw ValidationException::withMessages([
return $this->logout($request)->withErrors([
'email' => [__('auth.unverified')],
]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Cone\Root\Database\Factories\NotificationFactory;
use Cone\Root\Interfaces\Models\Notification as Contract;
use Cone\Root\Root;
use Cone\Root\Traits\InteractsWithProxy;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
Expand Down Expand Up @@ -68,7 +69,7 @@ protected function formattedCreatedAt(): Attribute
{
return new Attribute(
get: function (): ?string {
return $this->created_at?->isoFormat('YYYY. MMMM DD. HH:mm');
return $this->created_at?->setTimezone(Root::instance()->getTimezone())?->isoFormat('YYYY. MMMM DD. HH:mm');
}
);
}
Expand Down
25 changes: 24 additions & 1 deletion src/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Cone\Root\Navigation\Registry as Navigation;
use Cone\Root\Resources\Resources;
use Cone\Root\Widgets\Widgets;
use DateTimeZone;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
Expand All @@ -22,7 +23,7 @@ class Root
*
* @var string
*/
public const VERSION = '2.2.8';
public const VERSION = '2.2.11';

/**
* The registered booting callbacks.
Expand Down Expand Up @@ -59,6 +60,11 @@ class Root
*/
protected ?Closure $authResolver = null;

/**
* The Root timezone.
*/
protected string $timezone;

/**
* Create a new Root instance.
*/
Expand All @@ -69,6 +75,7 @@ public function __construct(Application $app)
$this->widgets = new Widgets();
$this->navigation = new Navigation();
$this->breadcrumbs = new Breadcrumbs();
$this->timezone = $app['config']->get('app.timezone');
}

/**
Expand Down Expand Up @@ -171,4 +178,20 @@ public function authorize(Closure $callback): void
{
$this->authResolver = $callback;
}

/**
* Set the Root timezone.
*/
public function setTimezone(string|DateTimeZone $value): void
{
$this->timezone = $value instanceof DateTimeZone ? $value->getName() : $value;
}

/**
* Get the Root timezone.
*/
public function getTimezone(): string
{
return $this->timezone;
}
}

0 comments on commit 69a685d

Please sign in to comment.