Skip to content

Commit

Permalink
Merge pull request rrze-mmz#84 from rrze-mmz/83-migrate-all-the-exist…
Browse files Browse the repository at this point in the history
…ing-settings

Migrate portal settings
  • Loading branch information
stefanosgeo authored Apr 23, 2024
2 parents 41147d7 + 854ca60 commit 4e33993
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 79 deletions.
8 changes: 0 additions & 8 deletions app/Http/Controllers/Backend/ClipsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ class ClipsController extends Controller
*/
public function index(): Application|Factory|\Illuminate\Contracts\View\View
{
// return view(
// 'backend.clips.index',
// [
// 'clips' => (auth()->user()->can('index-all-clips'))
// ? Clip::orderBy('title')->paginate(24)
// : auth()->user()->clips()->orderBy('updated_at')->paginate(12),
// ]
// );
return view('backend.clips.index');
}

Expand Down
20 changes: 6 additions & 14 deletions app/Http/Controllers/Backend/PortalSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Artisan;

class PortalSettingsController extends Controller
{
Expand All @@ -22,12 +21,7 @@ public function show(): Application|Factory|View
['name' => 'portal'],
[
'name' => 'portal',
'data' => [
'maintenance_mode' => config('tides.maintenance_mode'),
'allow_user_registration' => config('tides.allow_user_registration'),
'feeds_default_owner_name' => config('tides.feeds_default_owner_name'),
'feeds_default_owner_email' => config('tides.feeds_default_owner_email'),
],
'data' => [config('settings.portal')],
]
);

Expand All @@ -36,6 +30,11 @@ public function show(): Application|Factory|View
'allow_user_registration' => $setting->data['allow_user_registration'] ?? false,
'feeds_default_owner_name' => $setting->data['feeds_default_owner_name'] ?? 'Tides',
'feeds_default_owner_email' => $setting->data['feeds_default_owner_email'] ?? '[email protected]',
'player_show_article_link_in_player' => $setting->data['player_show_article_link_in_player'] ?? false,
'player_article_link_url' => $setting->data['player_article_link_url'] ?? 1,
'player_article_link_text' => $setting->data['player_article_link_text'] ?? '',
'clip_generic_poster_image_name' => $setting->data['clip_generic_poster_image_name'] ?? '',
'show_dropbox_files_in_dashboard' => $setting->data['show_dropbox_files_in_dashboard'] ?? true,
];

return view('backend.settings.portal', ['setting' => $setting->data]);
Expand All @@ -52,13 +51,6 @@ public function update(UpdatePortalSettings $request)
$setting = Setting::portal();
$validated = $request->validated();

//user updated setting
// if ($setting->data['maintenance_mode'] !== $validated['maintenance_mode']) {
// //temporary disabled because not working as expected
// $call = $validated['maintenance_mode'] ? 'down' : 'up';
// Artisan::call($call);
// }

$setting->data = $validated;
$setting->save();

Expand Down
20 changes: 9 additions & 11 deletions app/Http/Controllers/Frontend/ShowClipsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Enums\Content;
use App\Http\Controllers\Controller;
use App\Models\Clip;
use App\Models\Setting;
use App\Services\WowzaService;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\View\View;
Expand Down Expand Up @@ -50,17 +51,13 @@ public function show(Clip $clip, WowzaService $wowzaService): View
if ($wowzaStatus) {
$urls = $wowzaService->vodSecureUrls($clip);

if (empty($urls)) {
$defaultPlayerUrl = [];
} elseif ($urls->has('composite')) {
$defaultPlayerUrl = $urls['composite'];
} elseif ($urls->has('presenter')) {
$defaultPlayerUrl = $urls['presenter'];
} elseif ($urls->has('presentation')) {
$defaultPlayerUrl = $urls['presentation'];
} else {
$defaultPlayerUrl = [];
}
$defaultPlayerUrl = match (true) {
empty($urls) => [],
$urls->has('composite') => $urls['composite'],
$urls->has('presenter') => $urls['presenter'],
$urls->has('presentation') => $urls['presentation'],
default => []
};
}

return view('frontend.clips.show', [
Expand All @@ -70,6 +67,7 @@ public function show(Clip $clip, WowzaService $wowzaService): View
'alternativeVideoUrls' => $urls,
'previousNextClipCollection' => $clip->previousNextClipCollection(),
'assetsResolutions' => $assetsResolutions,
'playerSetting' => Setting::portal(),
]);
}
}
23 changes: 15 additions & 8 deletions app/Http/Requests/UpdatePortalSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@

class UpdatePortalSettings extends FormRequest
{
protected function prepareForValidation()
{
$this->merge([
'maintenance_mode' => $this->maintenance_mode === 'on',
'allow_user_registration' => $this->allow_user_registration === 'on',
]);
}

/**
* Determine if the user is authorized to make this request.
*/
Expand All @@ -35,6 +27,21 @@ public function rules(): array
'allow_user_registration' => ['required', 'boolean'],
'feeds_default_owner_name' => ['required', 'string'],
'feeds_default_owner_email' => ['required', 'email'],
'show_dropbox_files_in_dashboard' => ['required', 'boolean'],
'player_show_article_link_in_player' => ['required', 'boolean'],
'player_article_link_url' => ['required', 'url'],
'player_article_link_text' => ['required', 'string'],
'clip_generic_poster_image_name' => ['required', 'string'],
];
}

protected function prepareForValidation(): void
{
$this->merge([
'maintenance_mode' => $this->maintenance_mode === 'on',
'allow_user_registration' => $this->allow_user_registration === 'on',
'show_dropbox_files_in_dashboard' => $this->show_dropbox_files_in_dashboard == 'on',
'player_show_article_link_in_player' => $this->player_show_article_link_in_player === 'on',
]);
}
}
2 changes: 2 additions & 0 deletions app/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use App\Enums\ApplicationStatus;
use App\Models\Traits\RecordsActivity;
use App\Observers\SettingObserver;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Casts\Attribute;
Expand All @@ -13,6 +14,7 @@
class Setting extends BaseModel
{
use HasFactory;
use RecordsActivity;

public function scopeOpenAdminPortalApplications(): \Illuminate\Support\Collection
{
Expand Down
12 changes: 3 additions & 9 deletions app/Observers/UserObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ public function __construct(private OpenSearchService $openSearchService)

/**
* Handle the User "created" event.
*
* @return void
*/
public function created(User $user)
public function created(User $user): void
{
$user->assignRole(Role::USER);
$user->settings()->create([
Expand All @@ -32,10 +30,8 @@ public function created(User $user)

/**
* Handle the User "updated" event.
*
* @return void
*/
public function updated(User $user)
public function updated(User $user): void
{
session()->flash('flashMessage', "{$user->getFullNameAttribute()} ".__FUNCTION__.' successfully');

Expand All @@ -44,10 +40,8 @@ public function updated(User $user)

/**
* Handle the User "deleted" event.
*
* @return void
*/
public function deleted(User $user)
public function deleted(User $user): void
{
Setting::where('name', $user->username)->delete();
session()->flash('flashMessage', "{$user->getFullNameAttribute()} ".__FUNCTION__.' successfully');
Expand Down
11 changes: 8 additions & 3 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use App\Enums\Acl;
use App\Models\Asset;
use App\Models\Clip;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
Expand All @@ -18,9 +19,13 @@
*/
function fetchClipPoster(?string $player_preview): string
{
return (is_null($player_preview))
? '/images/generic_clip_poster_image.png'
: "/thumbnails/previews-ng/{$player_preview}";
if (is_null($player_preview)) {
$portalSettings = Setting::portal();

return '/images/'.$portalSettings->data['clip_generic_poster_image_name'];
} else {
return "/thumbnails/previews-ng/{$player_preview}";
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions config/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'portal' => [
'maintenance_mode' => false,
'allow_user_registration' => false,
'show_dropbox_files_in_dashboard' => true,
'feeds_default_owner_name' => 'Tides',
'feeds_default_owner_email' => '[email protected]',
'default_image_id' => env('DEFAULT_IMAGE_ID', 1),
Expand All @@ -15,6 +16,10 @@
'admin_main_address' => env('ADMIN_MAIL_ADDRESS', '[email protected]'),
'cdn_server_url' => env('CDN_SERVER_URL', 'http://localhost/'),
'cdn_server_secret' => env('CDN_SERVER_SECRET', 'dsnJ23fjeq!'),
'player_show_article_link_in_player' => false,
'player_article_link_id' => 1,
'player_article_link_text' => '',
'clip_generic_poster_image_name' => 'generic_clip_poster_image.png',
],
'user' => [
'accept_use_terms' => false,
Expand Down
6 changes: 4 additions & 2 deletions resources/views/backend/dashboard/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@php use App\Models\Setting; @endphp
@extends('layouts.backend')

@section('content')
Expand Down Expand Up @@ -28,13 +29,14 @@
</div>
</div>
<div class="flex">
<div class="@if(count($files) > 0)) w-2/3 @else w-full @endif">
@php $dropBoxFilesCheck = count($files) > 0 && Setting::portal()->data['show_dropbox_files_in_dashboard']; @endphp
<div class="@if($dropBoxFilesCheck)) w-2/3 @else w-full @endif">
@if($opencastEvents->isNotEmpty())
@include('backend.dashboard._opencast-workflows',['opencastEvents' => $opencastEvents])
@endif
</div>
@can('administrate-portal-pages')
@if(count($files) > 0 )
@if($dropBoxFilesCheck)
<div class="w-1/3 pl-4">
@include('backend.dashboard._dropzone-files')
@include('backend.dashboard._trending-clips')
Expand Down
2 changes: 1 addition & 1 deletion resources/views/backend/settings/opencast.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class="w-4/5 space-y-4">
label="Theme ID top right"
:fullCol="false"
:required="true" />
<div class="mb-5 border-b-2 border-black py-4 pb-2 text-xl dark:text-white dark:border-white">
<div class="mb-5 border-b border-black py-4 pb-2 text-xl dark:text-white dark:border-white">
Archive Settings
</div>
<x-form.input field-name="archive_path"
Expand Down
98 changes: 78 additions & 20 deletions resources/views/backend/settings/portal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,84 @@
class="w-4/5 space-y-4">
@csrf
@method('PUT')
<x-form.toggle-button :value="$setting['maintenance_mode']"
label="Maintenance mode"
field-name="maintenance_mode"
/>
<x-form.toggle-button :value="$setting['allow_user_registration']"
label="Allow user registration"
field-name="allow_user_registration"
/>
<x-form.input field-name="feeds_default_owner_name"
input-type="text"
:value="$setting['feeds_default_owner_name']"
label="Default feeds owner name"
:fullCol="true"
:required="true" />
<x-form.input field-name="feeds_default_owner_email"
input-type="email"
:value="$setting['feeds_default_owner_email']"
label="Default feeds email"
:fullCol="true"
:required="true" />
<div class="bg-gray-200 border-2 rounded-2xl p-4 my-4 dark:bg-slate-800 dark:border-indigo-950">
<div
class="flex border-b border-black pb-1 text-xl font-semibold text-indigo-800
dark:text-indigo-400 dark:border-white mb-4 ">
General settings
</div>
<div class="space-y-2">
<x-form.toggle-button :value="$setting['maintenance_mode']"
label="Maintenance mode"
field-name="maintenance_mode"
/>
<x-form.toggle-button :value="$setting['allow_user_registration']"
label="Allow user registration"
field-name="allow_user_registration"
/>
<x-form.toggle-button :value="$setting['show_dropbox_files_in_dashboard']"
label="Show dropbox files in dashboard"
field-name="show_dropbox_files_in_dashboard"
/>
</div>

<div class="py-4">
<x-form.input field-name="feeds_default_owner_name"
input-type="text"
:value="$setting['feeds_default_owner_name']"
label="Default feeds owner name"
:fullCol="true"
:required="true" />
</div>

<x-form.input field-name="feeds_default_owner_email"
input-type="email"
:value="$setting['feeds_default_owner_email']"
label="Default feeds email"
:fullCol="true"
:required="true" />
</div>

<div class="bg-gray-200 border-2 rounded-2xl p-4 my-4 dark:bg-slate-800 dark:border-indigo-950">
<div
class="flex border-b border-black pb-1 text-xl font-semibold text-indigo-800
dark:text-indigo-400 dark:border-white mb-4 ">
Player settings
</div>
<x-form.toggle-button :value="$setting['player_show_article_link_in_player']"
label="Show article link and text in player"
field-name="player_show_article_link_in_player"
/>
<div class="py-4">
<x-form.input field-name="player_article_link_url"
input-type="url"
:value="$setting['player_article_link_url']"
label="Link article URL"
:fullCol="true"
:required="true" />
</div>

<x-form.input field-name="player_article_link_text"
input-type="text"
:value="$setting['player_article_link_text']"
label="Player Text for link"
:fullCol="true"
:required="true" />
</div>
<div class="bg-gray-200 border-2 rounded-2xl p-4 my-4 dark:bg-slate-800 dark:border-indigo-950">
<div
class="flex border-b border-black pb-1 text-xl font-semibold text-indigo-800
dark:text-indigo-400 dark:border-white mb-4 ">
Clip settings
</div>
<x-form.input field-name="clip_generic_poster_image_name"
input-type="text"
:value="$setting['clip_generic_poster_image_name']"
label="Poster image file name"
:fullCol="true"
:required="true" />
</div>

<div class="mt-10 space-x-4 pt-10">
<x-button class="bg-blue-600 hover:bg-blue-700">
Update
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/form/input.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
</div>
<div class="{{($fullCol)?'col-start-2 col-end-8':'w-full'}}">
<input class="py-2 px-4 w-full leading-tight text-gray-700 bg-white rounded border-2
<input class="py-2 px-4 w-full leading-tight bg-white rounded border-2
border-gray-200 appearance-none focus:outline-none focus:bg-white
focus:border-blue-500 "
type="{{ $inputType }}"
Expand Down
11 changes: 11 additions & 0 deletions resources/views/frontend/clips/_article_section.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="py-5 flex ">
<div class="w-full text-center px-4 py-2 border
border-transparent rounded-md font-medium text-xl tracking-wider
active:bg-white-900 focus:outline-none focus:border-white-900 bg-green-400 text-gray-800
focus:ring ring-gray-300 disabled:opacity-25
transition ease-in-out duration-150">
<a href="{{ $playerSetting->data['player_article_link_url'] }}">
{{ $playerSetting->data['player_article_link_text'] }}
</a>
</div>
</div>
Loading

0 comments on commit 4e33993

Please sign in to comment.