Skip to content

Commit

Permalink
Merge branch 'galleries-module'
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebacker committed May 9, 2014
2 parents 474eda6 + b34507d commit 85fbeb1
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 74 deletions.
11 changes: 6 additions & 5 deletions app/TypiCMS/Modules/Files/Controllers/Admin/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ public function index()
{
$allowedViews = ['index', 'filepicker', 'thumbnails', 'gallery'];

$page = Input::get('page');
$type = Input::get('type');
$view = Input::get('view', 'thumbnails');
$view = ! in_array($view, $allowedViews) ? 'thumbnails' : $view ;
$page = Input::get('page');
$type = Input::get('type');
$gallery_id = Input::get('gallery_id');
$view = Input::get('view', 'thumbnails');
$view = ! in_array($view, $allowedViews) ? 'thumbnails' : $view ;

$itemsPerPage = Config::get('files::admin.itemsPerPage');

$data = $this->repository->byPageFrom($page, $itemsPerPage, null, array('translations'), true, $type);
$data = $this->repository->byPageFrom($page, $itemsPerPage, $gallery_id, array('translations'), true, $type);

$models = Paginator::make($data->items, $data->totalItems, $itemsPerPage);

Expand Down
9 changes: 4 additions & 5 deletions app/TypiCMS/Modules/Files/Repositories/CacheDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,23 @@ public function __construct(FileInterface $repo, CacheInterface $cache)
*
* @param int $page Number of models per page
* @param int $limit Results per page
* @param model $from related model
* @param model $gallery_id related model
* @param boolean $all get published models or all
* @param array $with Eager load related models
* @param string $type file type : a,v,d,i,o
* @return StdClass Object with $items and $totalItems for pagination
*/
public function byPageFrom($page = 1, $limit = 10, $from = null, array $with = array(), $all = false, $type = null)
public function byPageFrom($page = 1, $limit = 10, $gallery_id = null, array $with = array(), $all = false, $type = null)
{
$fromKey = ($from) ? $from->id . get_class($from) : '' ;
$cacheKey = md5(
App::getLocale() . 'byPageFrom' . $page . $limit . $fromKey . $all . implode(Input::except('page')) . $type
App::getLocale() . 'byPageFrom' . $page . $limit . $gallery_id . $all . implode(Input::except('page')) . $type
);

if ($this->cache->has($cacheKey)) {
return $this->cache->get($cacheKey);
}

$models = $this->repo->byPageFrom($page, $limit, $from, $with, $all, $type);
$models = $this->repo->byPageFrom($page, $limit, $gallery_id, $with, $all, $type);

// Store in cache for next request
$this->cache->put($cacheKey, $models);
Expand Down
10 changes: 7 additions & 3 deletions app/TypiCMS/Modules/Files/Repositories/EloquentFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public function __construct(Model $model)
*
* @param int $page Number of models per page
* @param int $limit Results per page
* @param model $from related model
* @param model $gallery_id from witch gallery ?
* @param boolean $all get published models or all
* @param array $with Eager load related models
* @param string $type file type : a,v,d,i,o
* @return StdClass Object with $items and $totalItems for pagination
*/
public function byPageFrom($page = 1, $limit = 10, $from = null, array $with = array(), $all = false, $type = null)
public function byPageFrom($page = 1, $limit = 10, $gallery_id = null, array $with = array(), $all = false, $type = null)
{
$result = new StdClass;
$result->page = $page;
Expand All @@ -42,10 +42,14 @@ public function byPageFrom($page = 1, $limit = 10, $from = null, array $with = a

$query = $this->make($with);

if ($type) {
if ($type) { // witch type of files to get (a,v,d,i,o) ?
$query->where('type', $type);
}

if ($gallery_id) {
$query->where('gallery_id', $gallery_id);
}

$totalItems = $query->count();

$query->order()
Expand Down
4 changes: 2 additions & 2 deletions app/TypiCMS/Modules/Files/Repositories/FileInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ interface FileInterface
*
* @param int $page Number of models per page
* @param int $limit Results per page
* @param model $from related model
* @param model $gallery_id related model
* @param array $with Eager load related models
* @param boolean $all get published models or all
* @param string $type file type : a,v,d,i,o
* @return StdClass Object with $items and $totalItems for pagination
*/
public function byPageFrom($page = 1, $limit = 10, $from = null, array $with = array(), $all = false, $type = null);
public function byPageFrom($page = 1, $limit = 10, $gallery_id = null, array $with = array(), $all = false, $type = null);

/**
* Delete model
Expand Down
10 changes: 5 additions & 5 deletions app/TypiCMS/Modules/Files/Views/files/admin/_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@

<div class="col-sm-6">

{{ Form::hidden('folder_id', 0) }}
{{ Form::hidden('gallery_id', Input::get('gallery_id', 0)) }}
{{ Form::hidden('user_id', 0) }}
{{ Form::hidden('folder_id', $model->folder_id ?: 0) }}
{{ Form::hidden('gallery_id', $model->gallery_id ?: 0) }}
{{ Form::hidden('user_id', $model->user_id ?: 0) }}
{{ Form::hidden('type') }}
{{ Form::hidden('position', 0) }}
{{ Form::hidden('position', $model->position ?: 0) }}
{{ Form::hidden('path') }}
{{ Form::hidden('filename') }}
{{ Form::hidden('extension') }}
{{ Form::hidden('mimetype') }}
{{ Form::hidden('width') }}
{{ Form::hidden('height') }}
{{ Form::hidden('download_count', 0) }}
{{ Form::hidden('download_count', $model->download_count ?: 0) }}

<div class="clearfix well media @if($errors->has('file'))has-error@endif">
@if(isset($model->filename) and $model->filename)
Expand Down
22 changes: 9 additions & 13 deletions app/TypiCMS/Modules/Files/Views/files/admin/filepicker.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,16 @@ function selectAndClose(image) {
@endforeach

<div class="dropzone-previews clearfix sortable sortable-thumbnails">
@if (count($models))
@foreach ($models as $key => $model)
<div class="thumbnail" id="item_{{ $model->id }}">
{{ $model->present()->checkbox }}
{{ $model->present()->thumb }}
<div class="caption">
<a href="#" class="btn btn-default btn-xs btn-block btn-insert" onclick="selectAndClose('/{{ $model->path }}{{ $model->filename }}')">@lang('files::global.Insert')</a>
<small>{{ $model->filename }}</small>
</div>
@foreach ($models as $key => $model)
<div class="thumbnail" id="item_{{ $model->id }}">
{{ $model->present()->checkbox }}
{{ $model->present()->thumb }}
<div class="caption">
<a href="#" class="btn btn-default btn-xs btn-block btn-insert" onclick="selectAndClose('/{{ $model->path }}{{ $model->filename }}')">@lang('files::global.Insert')</a>
<small>{{ $model->filename }}</small>
</div>
@endforeach
@else
<p class="text-muted">@lang('global.No file')</p>
@endif
</div>
@endforeach
</div>
<div class="dz-message">@lang('files::global.Drop files to upload')</div>

Expand Down
22 changes: 9 additions & 13 deletions app/TypiCMS/Modules/Files/Views/files/admin/gallery.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,16 @@
@endforeach

<div class="dropzone-previews clearfix sortable sortable-thumbnails">
@if (count($models))
@foreach ($models as $key => $model)
<div class="thumbnail" id="item_{{ $model->id }}" href="{{ route('admin.files.edit', $model->id) }}">
{{ $model->present()->checkbox }}
{{ $model->present()->thumb }}
<div class="caption">
<small>{{ $model->present()->status }} {{ $model->filename }}</small>
<div>{{ $model->alt_attribute }}</div>
</div>
@foreach ($models as $key => $model)
<div class="thumbnail" id="item_{{ $model->id }}" href="{{ route('admin.files.edit', $model->id) }}">
{{ $model->present()->checkbox }}
{{ $model->present()->thumb }}
<div class="caption">
<small>{{ $model->present()->status }} {{ $model->filename }}</small>
<div>{{ $model->alt_attribute }}</div>
</div>
@endforeach
@else
<p class="text-muted">@lang('global.No file')</p>
@endif
</div>
@endforeach
</div>
<div class="dz-message">@lang('files::global.Drop files to upload')</div>

Expand Down
15 changes: 15 additions & 0 deletions app/TypiCMS/Modules/Galleries/Presenters/GalleryPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,19 @@
class GalleryPresenter extends Presenter
{

/**
* Files in list
*
* @return string
*/
public function countFiles()
{
$nbFiles = count($this->entity->files);
$label = $nbFiles ? 'label-success' : 'label-default' ;
$html[] = '<span class="label ' . $label . '">';
$html[] = $nbFiles;
$html[] = '</span>';

return implode("\r\n", $html);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@

</div>


<iframe class="col-sm-6" height="1000" src="/admin/files?view=gallery&amp;gallery_id={{ $model->id }}" frameborder="0"></iframe>
@if ($model->id)
<iframe class="col-sm-6" height="1000" src="/admin/files?view=gallery&amp;gallery_id={{ $model->id }}" frameborder="0"></iframe>
@else
<div class="col-sm-6">
<p class="alert alert-info">Create the gallery, then add files</p>
</div>
@endif

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@
</div>

{{ Form::hidden('menu_id', $menu->id); }}
{{ Form::hidden('position'); }}
{{ Form::hidden('parent'); }}
{{ Form::hidden('position', $model->position ?: 0); }}
{{ Form::hidden('parent', $model->parent ?: 0); }}
{{ Form::hidden('id'); }}
30 changes: 9 additions & 21 deletions app/TypiCMS/Presenters/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,6 @@ public function titleAnchor()
return '<a href="' . $url . '">' . $this->entity->title . '</a>';
}

/**
* Files in list
*
* @return string
*/
public function countFiles()
{
$nbFiles = count($this->entity->files);
$label = $nbFiles ? 'label-success' : 'label-default' ;
$url = route('admin.files.index', array('module' => $this->entity->getTable(), 'id' => $this->entity->id));
$html[] = '<a class="label ' . $label . '" href="' . $url . '">';
$html[] = $nbFiles;
$html[] = '</a>';

return implode("\r\n", $html);
}

/**
* Get the front end url from the current back end url
*
Expand All @@ -109,16 +92,21 @@ public function publicUri($lang)
{
$routeName = $lang . strstr(Route::current()->getName(), '.');
$routeName = preg_replace('/\.edit$/', '.slug', $routeName);
// if model is translated and is online
// If model is translated and is online
if (isset($this->entity->$lang->slug) and $this->entity->$lang->status) {
try {
try { // Does this public route exists ?
return route($routeName, $this->entity->$lang->slug);
} catch (Exception $e) {
return $returnRoute = route('root');
return $lang;
}
}
// If model is offline or there is no translation
$routeName = substr($routeName, 0, strrpos($routeName, '.'));
return route($routeName);
try { // Does this public route exists ?
return route($routeName);
} catch (Exception $e) {
return $lang;
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function run()
$this->call('EventSeeder');
$this->call('PlaceSeeder');
$this->call('TranslationSeeder');
$this->call('GallerySeeder');
}

}
Loading

0 comments on commit 85fbeb1

Please sign in to comment.