Skip to content

Commit 6e11101

Browse files
committed
Prepare for v3.0
2 parents 426a06d + 213a78b commit 6e11101

28 files changed

+210
-299
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
],
1111
"require": {
12-
"laravel/framework": "~5.2.0"
12+
"laravel/framework": "~5.5.0"
1313
},
1414
"minimum-stability": "dev",
1515
"prefer-stable": true

src/Composers/SidebarViewComposer.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ class SidebarViewComposer
1111
{
1212
public function compose(View $view)
1313
{
14-
$view->sidebar->group(trans('global.menus.content'), function (SidebarGroup $group) {
15-
$group->addItem(trans('objects::global.name'), function (SidebarItem $item) {
14+
if (Gate::denies('see-all-objects')) {
15+
return;
16+
}
17+
$view->sidebar->group(__('Content'), function (SidebarGroup $group) {
18+
$group->id = 'content';
19+
$group->weight = 30;
20+
$group->addItem(__('Objects'), function (SidebarItem $item) {
1621
$item->id = 'objects';
1722
$item->icon = config('typicms.objects.sidebar.icon');
1823
$item->weight = config('typicms.objects.sidebar.weight');
1924
$item->route('admin::index-objects');
2025
$item->append('admin::create-object');
21-
$item->authorize(
22-
Gate::allows('index-objects')
23-
);
2426
});
2527
});
2628
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace TypiCMS\Modules\Objects\Facades;
44

5-
use Illuminate\Support\Facades\Facade as MainFacade;
5+
use Illuminate\Support\Facades\Facade;
66

7-
class Facade extends MainFacade
7+
class Objects extends Facade
88
{
99
/**
1010
* Get the registered name of the component.
@@ -13,6 +13,6 @@ class Facade extends MainFacade
1313
*/
1414
protected static function getFacadeAccessor()
1515
{
16-
return 'TypiCMS\Modules\Objects\Repositories\ObjectInterface';
16+
return 'Objects';
1717
}
1818
}

src/Http/Controllers/AdminController.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
use TypiCMS\Modules\Core\Http\Controllers\BaseAdminController;
66
use TypiCMS\Modules\Objects\Http\Requests\FormRequest;
77
use TypiCMS\Modules\Objects\Models\Object;
8-
use TypiCMS\Modules\Objects\Repositories\ObjectInterface;
8+
use TypiCMS\Modules\Objects\Repositories\EloquentObject;
99

1010
class AdminController extends BaseAdminController
1111
{
12-
public function __construct(ObjectInterface $object)
12+
public function __construct(EloquentObject $object)
1313
{
1414
parent::__construct($object);
1515
}
@@ -21,7 +21,7 @@ public function __construct(ObjectInterface $object)
2121
*/
2222
public function index()
2323
{
24-
$models = $this->repository->all([], true);
24+
$models = $this->repository->with('files')->findAll();
2525
app('JavaScript')->put('models', $models);
2626

2727
return view('objects::admin.index');
@@ -34,7 +34,8 @@ public function index()
3434
*/
3535
public function create()
3636
{
37-
$model = $this->repository->getModel();
37+
$model = $this->repository->createModel();
38+
app('JavaScript')->put('model', $model);
3839

3940
return view('objects::admin.create')
4041
->with(compact('model'));
@@ -49,6 +50,8 @@ public function create()
4950
*/
5051
public function edit(Object $object)
5152
{
53+
app('JavaScript')->put('model', $object);
54+
5255
return view('objects::admin.edit')
5356
->with(['model' => $object]);
5457
}
@@ -77,8 +80,38 @@ public function store(FormRequest $request)
7780
*/
7881
public function update(Object $object, FormRequest $request)
7982
{
80-
$this->repository->update($request->all());
83+
$this->repository->update($request->id, $request->all());
8184

8285
return $this->redirect($request, $object);
8386
}
87+
88+
/**
89+
* Remove the specified resource from storage.
90+
*
91+
* @param \TypiCMS\Modules\Objects\Models\Object $object
92+
*
93+
* @return \Illuminate\Http\JsonResponse
94+
*/
95+
public function destroy(Object $object)
96+
{
97+
$deleted = $this->repository->delete($object);
98+
99+
return response()->json([
100+
'error' => !$deleted,
101+
]);
102+
}
103+
104+
/**
105+
* List models.
106+
*
107+
* @return \Illuminate\View\View
108+
*/
109+
public function files(Object $object)
110+
{
111+
$data = [
112+
'models' => $object->files,
113+
];
114+
115+
return response()->json($data, 200);
116+
}
84117
}

src/Http/Controllers/ApiController.php

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/Http/Controllers/PublicController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
namespace TypiCMS\Modules\Objects\Http\Controllers;
44

55
use TypiCMS\Modules\Core\Http\Controllers\BasePublicController;
6-
use TypiCMS\Modules\Objects\Repositories\ObjectInterface;
6+
use TypiCMS\Modules\Objects\Repositories\EloquentObject;
77

88
class PublicController extends BasePublicController
99
{
10-
public function __construct(ObjectInterface $object)
10+
public function __construct(EloquentObject $object)
1111
{
1212
parent::__construct($object);
1313
}
@@ -19,20 +19,20 @@ public function __construct(ObjectInterface $object)
1919
*/
2020
public function index()
2121
{
22-
$models = $this->repository->all();
22+
$models = $this->repository->published()->findAll();
2323

2424
return view('objects::public.index')
2525
->with(compact('models'));
2626
}
2727

2828
/**
29-
* Show news.
29+
* Show resource.
3030
*
3131
* @return \Illuminate\View\View
3232
*/
3333
public function show($slug)
3434
{
35-
$model = $this->repository->bySlug($slug);
35+
$model = $this->repository->published()->bySlug($slug);
3636

3737
return view('objects::public.show')
3838
->with(compact('model'));

src/Http/Requests/FormRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class FormRequest extends AbstractFormRequest
99
public function rules()
1010
{
1111
return [
12-
'image' => 'image|max:2000',
13-
'*.title' => 'max:255',
14-
'*.slug' => 'max:255',
12+
'image_id' => 'nullable|integer',
13+
'title.*' => 'nullable|max:255',
14+
'slug.*' => 'nullable|alpha_dash|max:255',
1515
];
1616
}
1717
}

src/Models/Object.php

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,65 @@
22

33
namespace TypiCMS\Modules\Objects\Models;
44

5-
use Dimsav\Translatable\Translatable;
65
use Laracasts\Presenter\PresentableTrait;
6+
use Spatie\Translatable\HasTranslations;
77
use TypiCMS\Modules\Core\Models\Base;
8+
use TypiCMS\Modules\Files\Models\File;
89
use TypiCMS\Modules\History\Traits\Historable;
10+
use TypiCMS\Modules\Objects\Presenters\ModulePresenter;
911

1012
class Object extends Base
1113
{
14+
use HasTranslations;
1215
use Historable;
1316
use PresentableTrait;
14-
use Translatable;
1517

16-
protected $presenter = 'TypiCMS\Modules\Objects\Presenters\ModulePresenter';
18+
protected $presenter = ModulePresenter::class;
1719

18-
/**
19-
* Declare any properties that should be hidden from JSON Serialization.
20-
*
21-
* @var array
22-
*/
23-
protected $hidden = [];
20+
protected $guarded = ['id', 'exit'];
2421

25-
protected $fillable = [
26-
'image',
27-
];
28-
29-
/**
30-
* Translatable model configs.
31-
*
32-
* @var array
33-
*/
34-
public $translatedAttributes = [
22+
public $translatable = [
3523
'title',
3624
'slug',
3725
'status',
3826
'summary',
3927
'body',
4028
];
4129

42-
protected $appends = ['status', 'title', 'thumb'];
30+
protected $appends = ['image', 'thumb', 'title_translated', 'status_translated'];
4331

4432
/**
45-
* Columns that are file.
33+
* Append title_translated attribute.
4634
*
47-
* @var array
35+
* @return string
4836
*/
49-
public $attachments = [
50-
'image',
51-
];
37+
public function getTitleTranslatedAttribute()
38+
{
39+
$locale = config('app.locale');
40+
41+
return $this->translate('title', config('typicms.content_locale', $locale));
42+
}
5243

5344
/**
54-
* Append status attribute from translation table.
45+
* Append status_translated attribute.
5546
*
5647
* @return string
5748
*/
58-
public function getStatusAttribute($value)
49+
public function getStatusTranslatedAttribute()
5950
{
60-
return $value;
51+
$locale = config('app.locale');
52+
53+
return $this->translate('status', config('typicms.content_locale', $locale));
6154
}
6255

6356
/**
64-
* Append title attribute from translation table.
57+
* Append image attribute.
6558
*
66-
* @return string title
59+
* @return string
6760
*/
68-
public function getTitleAttribute($value)
61+
public function getImageAttribute()
6962
{
70-
return $value;
63+
return $this->files->first();
7164
}
7265

7366
/**
@@ -79,4 +72,15 @@ public function getThumbAttribute()
7972
{
8073
return $this->present()->thumbSrc(null, 22);
8174
}
75+
76+
/**
77+
* Has many files.
78+
*
79+
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
80+
*/
81+
public function files()
82+
{
83+
return $this->morphToMany(File::class, 'model', 'model_has_files', 'model_id', 'file_id')
84+
->orderBy('model_has_files.position');
85+
}
8286
}

0 commit comments

Comments
 (0)