Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
#	src/Models/Place.php
#	src/Models/PlaceTranslation.php
  • Loading branch information
sdebacker committed Aug 31, 2017
2 parents 665c11b + b5773c5 commit 9cfe3a3
Show file tree
Hide file tree
Showing 31 changed files with 327 additions and 581 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
],
"require": {
"typicms/core": "~2.9.0"
"laravel/framework": "~5.5.0"
},
"autoload": {
"psr-4": {
Expand Down
Empty file removed public/.gitkeep
Empty file.
12 changes: 7 additions & 5 deletions src/Composers/SidebarViewComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ class SidebarViewComposer
{
public function compose(View $view)
{
$view->sidebar->group(trans('global.menus.content'), function (SidebarGroup $group) {
$group->addItem(trans('places::global.name'), function (SidebarItem $item) {
if (Gate::denies('see-all-places')) {
return;
}
$view->sidebar->group(__('Content'), function (SidebarGroup $group) {
$group->id = 'content';
$group->weight = 30;
$group->addItem(__('Places'), function (SidebarItem $item) {
$item->id = 'places';
$item->icon = config('typicms.places.sidebar.icon', 'icon fa fa-fw fa-map-marker');
$item->weight = config('typicms.places.sidebar.weight');
$item->route('admin::index-places');
$item->append('admin::create-place');
$item->authorize(
Gate::allows('index-places')
);
});
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/Facades/Facade.php → src/Facades/Places.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace TypiCMS\Modules\Places\Facades;

use Illuminate\Support\Facades\Facade as MainFacade;
use Illuminate\Support\Facades\Facade;

class Facade extends MainFacade
class Places extends Facade
{
/**
* Get the registered name of the component.
Expand All @@ -13,6 +13,6 @@ class Facade extends MainFacade
*/
protected static function getFacadeAccessor()
{
return 'TypiCMS\Modules\Places\Repositories\PlaceInterface';
return 'Places';
}
}
43 changes: 38 additions & 5 deletions src/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use TypiCMS\Modules\Core\Http\Controllers\BaseAdminController;
use TypiCMS\Modules\Places\Http\Requests\FormRequest;
use TypiCMS\Modules\Places\Models\Place;
use TypiCMS\Modules\Places\Repositories\PlaceInterface;
use TypiCMS\Modules\Places\Repositories\EloquentPlace;

class AdminController extends BaseAdminController
{
public function __construct(PlaceInterface $place)
public function __construct(EloquentPlace $place)
{
parent::__construct($place);
}
Expand All @@ -21,7 +21,7 @@ public function __construct(PlaceInterface $place)
*/
public function index()
{
$models = $this->repository->all([], true);
$models = $this->repository->with('files')->findAll();
app('JavaScript')->put('models', $models);

return view('places::admin.index');
Expand All @@ -34,7 +34,8 @@ public function index()
*/
public function create()
{
$model = $this->repository->getModel();
$model = $this->repository->createModel();
app('JavaScript')->put('model', $model);

return view('places::admin.create')
->with(compact('model'));
Expand All @@ -49,6 +50,8 @@ public function create()
*/
public function edit(Place $place)
{
app('JavaScript')->put('model', $place);

return view('places::admin.edit')
->with(['model' => $place]);
}
Expand Down Expand Up @@ -77,8 +80,38 @@ public function store(FormRequest $request)
*/
public function update(Place $place, FormRequest $request)
{
$this->repository->update($request->all());
$this->repository->update($request->id, $request->all());

return $this->redirect($request, $place);
}

/**
* Remove the specified resource from storage.
*
* @param \TypiCMS\Modules\Places\Models\Place $place
*
* @return \Illuminate\Http\JsonResponse
*/
public function destroy(Place $place)
{
$deleted = $this->repository->delete($place);

return response()->json([
'error' => !$deleted,
]);
}

/**
* List models.
*
* @return \Illuminate\View\View
*/
public function files(Place $place)
{
$data = [
'models' => $place->files,
];

return response()->json($data, 200);
}
}
64 changes: 0 additions & 64 deletions src/Http/Controllers/ApiController.php

This file was deleted.

17 changes: 8 additions & 9 deletions src/Http/Controllers/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace TypiCMS\Modules\Places\Http\Controllers;

use Illuminate\Support\Facades\Request;
use TypiCMS\Modules\Core\Http\Controllers\BasePublicController;
use TypiCMS\Modules\Places\Repositories\PlaceInterface;
use TypiCMS\Modules\Places\Repositories\EloquentPlace;

class PublicController extends BasePublicController
{
public function __construct(PlaceInterface $place)
public function __construct(EloquentPlace $place)
{
parent::__construct($place);
}
Expand All @@ -20,8 +19,8 @@ public function __construct(PlaceInterface $place)
*/
public function index()
{
$models = $this->repository->all();
if (Request::ajax()) {
$models = $this->repository->published()->findAll();
if (request()->wantsJson()) {
return $models;
}

Expand All @@ -36,8 +35,8 @@ public function index()
*/
public function search()
{
$models = $this->repository->all();
if (Request::ajax()) {
$models = $this->repository->published()->findAll();
if (request()->wantsJson()) {
return $models;
}

Expand All @@ -52,8 +51,8 @@ public function search()
*/
public function show($slug)
{
$model = $this->repository->bySlug($slug);
if (Request::ajax()) {
$model = $this->repository->published()->bySlug($slug);
if (request()->wantsJson()) {
return $model;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Http/Requests/FormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class FormRequest extends AbstractFormRequest
public function rules()
{
return [
'email' => 'email|max:255',
'website' => 'url|max:255',
'image' => 'image|max:2000',
'*.title' => 'max:255',
'*.slug' => 'alpha_dash|max:255',
'email' => 'nullable|email|max:255',
'website' => 'nullable|url|max:255',
'image_id' => 'nullable|integer',
'title.*' => 'nullable|max:255',
'slug.*' => 'nullable|alpha_dash|max:255',
];
}
}
68 changes: 36 additions & 32 deletions src/Models/Place.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,65 @@

namespace TypiCMS\Modules\Places\Models;

use Dimsav\Translatable\Translatable;
use Laracasts\Presenter\PresentableTrait;
use Spatie\Translatable\HasTranslations;
use TypiCMS\Modules\Core\Models\Base;
use TypiCMS\Modules\Files\Models\File;
use TypiCMS\Modules\History\Traits\Historable;
use TypiCMS\Modules\Places\Presenters\ModulePresenter;

class Place extends Base
{
use HasTranslations;
use Historable;
use Translatable;
use PresentableTrait;

protected $presenter = 'TypiCMS\Modules\Places\Presenters\ModulePresenter';
protected $presenter = ModulePresenter::class;

protected $fillable = [
'address',
'email',
'phone',
'fax',
'website',
'image',
'latitude',
'longitude',
];
protected $guarded = ['id', 'exit'];

/**
* Translatable model configs.
*
* @var array
*/
public $translatedAttributes = [
public $translatable = [
'title',
'slug',
'summary',
'body',
'status',
];

protected $appends = ['status', 'title', 'thumb'];
protected $appends = ['image', 'thumb', 'title_translated', 'status_translated'];

/**
* Append status attribute from translation table.
* Append title_translated attribute.
*
* @return string
*/
public function getStatusAttribute($value)
public function getTitleTranslatedAttribute()
{
return $value;
$locale = config('app.locale');

return $this->translate('title', config('typicms.content_locale', $locale));
}

/**
* Append title attribute from translation table.
* Append status_translated attribute.
*
* @return string title
* @return string
*/
public function getTitleAttribute($value)
public function getStatusTranslatedAttribute()
{
return $value;
$locale = config('app.locale');

return $this->translate('status', config('typicms.content_locale', $locale));
}

/**
* Append image attribute.
*
* @return string
*/
public function getImageAttribute()
{
return $this->files->first();
}

/**
Expand All @@ -72,11 +74,13 @@ public function getThumbAttribute()
}

/**
* Columns that are file.
* A news can have many files.
*
* @var array
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public $attachments = [
'image',
];
public function files()
{
return $this->morphToMany(File::class, 'model', 'model_has_files', 'model_id', 'file_id')
->orderBy('model_has_files.position');
}
}
Loading

0 comments on commit 9cfe3a3

Please sign in to comment.