Skip to content

Commit c93a3d2

Browse files
authored
Merge pull request #3411 from codeeu/dev
nova updates
2 parents fe5df0e + 4268d41 commit c93a3d2

19 files changed

Lines changed: 1439 additions & 33 deletions

app/DreamJobRoleModel.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class DreamJobRoleModel extends Model
8+
{
9+
protected $fillable = [
10+
'first_name',
11+
'last_name',
12+
'slug',
13+
'role',
14+
'image',
15+
'country',
16+
'description1',
17+
'description2',
18+
'link',
19+
'video',
20+
'pathway_map_link',
21+
'position',
22+
'active',
23+
];
24+
25+
protected $casts = [
26+
'position' => 'integer',
27+
'active' => 'boolean',
28+
];
29+
}

app/DreamJobsPage.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class DreamJobsPage extends Model
8+
{
9+
protected $table = 'dream_jobs_page';
10+
11+
protected $fillable = [
12+
'hero_dynamic',
13+
'about_dynamic',
14+
'role_models_dynamic',
15+
'resources_dynamic',
16+
'hero_intro',
17+
'hero_cta_text',
18+
'hero_cta_link',
19+
'about_title',
20+
'about_description',
21+
'about_video_url',
22+
'role_models_title',
23+
'resources_title',
24+
'locale_overrides',
25+
];
26+
27+
protected $casts = [
28+
'hero_dynamic' => 'boolean',
29+
'about_dynamic' => 'boolean',
30+
'role_models_dynamic' => 'boolean',
31+
'resources_dynamic' => 'boolean',
32+
'locale_overrides' => 'array',
33+
];
34+
35+
public function resources()
36+
{
37+
return $this->hasMany(DreamJobsResource::class, 'page_id')->orderBy('position');
38+
}
39+
40+
public static function config(): self
41+
{
42+
$page = self::first();
43+
if ($page) {
44+
return $page;
45+
}
46+
47+
return self::create([
48+
'hero_dynamic' => false,
49+
'about_dynamic' => false,
50+
'role_models_dynamic' => false,
51+
'resources_dynamic' => false,
52+
'hero_cta_link' => '#dream-job-resources',
53+
'about_video_url' => 'https://www.youtube.com/embed/pzP-kToeym4?si=FzutCQGW4rO5M_5A',
54+
'locale_overrides' => null,
55+
]);
56+
}
57+
58+
public function contentForLocale(string $key, ?string $locale = null): string
59+
{
60+
$locale = $locale ?? app()->getLocale();
61+
$overrides = $this->locale_overrides ?? [];
62+
if (!empty($overrides[$locale][$key])) {
63+
return (string) $overrides[$locale][$key];
64+
}
65+
66+
$value = $this->getAttribute($key);
67+
return $value !== null ? (string) $value : '';
68+
}
69+
70+
public function resourcesForLocale(?string $locale = null): array
71+
{
72+
return $this->resources()
73+
->where('active', true)
74+
->orderBy('position')
75+
->get()
76+
->map(fn (DreamJobsResource $item) => [
77+
'title' => $item->titleForLocale($locale),
78+
'description' => $item->descriptionForLocale($locale),
79+
'button_text' => $item->buttonTextForLocale($locale),
80+
'button_link' => $item->button_link,
81+
'image' => $item->image,
82+
])
83+
->all();
84+
}
85+
}

app/DreamJobsResource.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class DreamJobsResource extends Model
8+
{
9+
protected $table = 'dream_jobs_resources';
10+
11+
protected $fillable = [
12+
'page_id',
13+
'title',
14+
'description',
15+
'button_text',
16+
'button_link',
17+
'image',
18+
'position',
19+
'active',
20+
'locale_overrides',
21+
];
22+
23+
protected $casts = [
24+
'position' => 'integer',
25+
'active' => 'boolean',
26+
'locale_overrides' => 'array',
27+
];
28+
29+
public function page()
30+
{
31+
return $this->belongsTo(DreamJobsPage::class, 'page_id');
32+
}
33+
34+
public function titleForLocale(?string $locale = null): string
35+
{
36+
$locale = $locale ?? app()->getLocale();
37+
$overrides = $this->locale_overrides ?? [];
38+
if (!empty($overrides[$locale]['title'])) {
39+
return (string) $overrides[$locale]['title'];
40+
}
41+
42+
return (string) ($this->title ?? '');
43+
}
44+
45+
public function descriptionForLocale(?string $locale = null): string
46+
{
47+
$locale = $locale ?? app()->getLocale();
48+
$overrides = $this->locale_overrides ?? [];
49+
if (!empty($overrides[$locale]['description'])) {
50+
return (string) $overrides[$locale]['description'];
51+
}
52+
53+
return (string) ($this->description ?? '');
54+
}
55+
56+
public function buttonTextForLocale(?string $locale = null): string
57+
{
58+
$locale = $locale ?? app()->getLocale();
59+
$overrides = $this->locale_overrides ?? [];
60+
if (!empty($overrides[$locale]['button_text'])) {
61+
return (string) $overrides[$locale]['button_text'];
62+
}
63+
64+
return (string) ($this->button_text ?? '');
65+
}
66+
}

app/HackathonsPage.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class HackathonsPage extends Model
8+
{
9+
protected $table = 'hackathons_page';
10+
11+
protected $fillable = [
12+
'dynamic_content',
13+
'hero_title',
14+
'hero_subtitle',
15+
'intro_title',
16+
'intro_paragraph_1',
17+
'intro_paragraph_2',
18+
'details_title',
19+
'details_paragraph_1',
20+
'details_paragraph_2',
21+
'details_paragraph_3',
22+
'details_paragraph_4',
23+
'video_url',
24+
'recap_button_text',
25+
'recap_button_link',
26+
'toolkit_button_text',
27+
'toolkit_button_link',
28+
'locale_overrides',
29+
];
30+
31+
protected $casts = [
32+
'dynamic_content' => 'boolean',
33+
'locale_overrides' => 'array',
34+
];
35+
36+
public static function config(): self
37+
{
38+
$page = self::first();
39+
if ($page) {
40+
return $page;
41+
}
42+
43+
return self::create([
44+
'dynamic_content' => false,
45+
'locale_overrides' => null,
46+
]);
47+
}
48+
49+
public function contentForLocale(string $key, ?string $locale = null): string
50+
{
51+
$locale = $locale ?? app()->getLocale();
52+
$overrides = $this->locale_overrides ?? [];
53+
if (!empty($overrides[$locale][$key])) {
54+
return (string) $overrides[$locale][$key];
55+
}
56+
57+
$value = $this->getAttribute($key);
58+
return $value !== null ? (string) $value : '';
59+
}
60+
}

app/Nova/DreamJobRoleModel.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace App\Nova;
4+
5+
use Illuminate\Http\Request;
6+
use Laravel\Nova\Fields\Boolean;
7+
use Laravel\Nova\Fields\ID;
8+
use Laravel\Nova\Fields\Number;
9+
use Laravel\Nova\Fields\Text;
10+
use Laravel\Nova\Fields\Textarea;
11+
use Laravel\Nova\Http\Requests\NovaRequest;
12+
13+
class DreamJobRoleModel extends Resource
14+
{
15+
public static $group = 'Content';
16+
17+
public static $model = \App\DreamJobRoleModel::class;
18+
19+
public static $title = 'slug';
20+
21+
public static $search = [
22+
'first_name',
23+
'last_name',
24+
'slug',
25+
'role',
26+
];
27+
28+
public static function label()
29+
{
30+
return 'Dream Jobs Role Models';
31+
}
32+
33+
public static function singularLabel()
34+
{
35+
return 'Dream Jobs Role Model';
36+
}
37+
38+
public function fields(Request $request): array
39+
{
40+
return [
41+
ID::make()->sortable(),
42+
43+
Text::make('First Name', 'first_name')->rules('required', 'max:255'),
44+
Text::make('Last Name', 'last_name')->rules('required', 'max:255'),
45+
Text::make('Slug', 'slug')
46+
->rules('required', 'max:255', 'unique:dream_job_role_models,slug,{{resourceId}}')
47+
->help('Used in URL, e.g. anny-tubbs'),
48+
Textarea::make('Role', 'role')->rules('required'),
49+
50+
Text::make('Image URL', 'image')
51+
->rules('required', 'max:2048')
52+
->help('Path from site root, e.g. /images/dream-jobs/anny-tubbs.png'),
53+
Text::make('Country Code', 'country')
54+
->rules('required', 'max:8')
55+
->help('Flag code used by existing assets, e.g. be, fr, gr'),
56+
57+
Textarea::make('Description 1', 'description1')->nullable(),
58+
Textarea::make('Description 2', 'description2')->nullable(),
59+
60+
Text::make('Profile Link', 'link')->nullable()->rules('nullable', 'max:2048'),
61+
Text::make('Video Embed URL', 'video')->nullable()->rules('nullable', 'max:2048'),
62+
Text::make('Pathway Map Filename', 'pathway_map_link')
63+
->nullable()
64+
->rules('nullable', 'max:255')
65+
->help('Filename in /public/docs/dream-jobs/, e.g. Career Pathway Map Anny Tubbs.pdf'),
66+
67+
Number::make('Position', 'position')
68+
->min(0)
69+
->default(0)
70+
->help('Lower numbers appear first.'),
71+
72+
Boolean::make('Active', 'active')->default(true),
73+
];
74+
}
75+
76+
public static function indexQuery(NovaRequest $request, $query)
77+
{
78+
return $query->orderBy('position')->orderBy('first_name');
79+
}
80+
}

0 commit comments

Comments
 (0)