Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webumenia 1923 remove pagination on admin collection/articles #894

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ All notable changes to this project will be documented in this file[^1].
- RedirectLegacyCatalogRequest middleware for handling "legacy" catalog requests in new catalog
- 'hidden' catalog fields to V1 API filterables

### Changed
- add soft deletes to articles

## [2.79.0] - 2023-08-31
### Added
- images:generate-ratios command

### Changed
- behaviour for /api/v1/items/aggregations so that facet doesn't filter itself
- display published date on collection index
- add soft deletes to articles
- remove pagination from collections and articles in admin

## [2.78.0] - 2023-07-21
### Added
Expand Down
75 changes: 41 additions & 34 deletions app/Http/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@

class ArticleController extends Controller
{

/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$articles = Article::orderBy('created_at', 'desc')->paginate(20);
$articles = Article::orderBy('created_at', 'desc')->get();
return view('articles.index')->with('articles', $articles);
}

Expand All @@ -40,13 +39,15 @@ public function store(Request $request)
{
$request->validate(Article::getValidationRules());

$article = new Article;
$article = new Article();

// store translatable attributes
foreach (\Config::get('translatable.locales') as $i => $locale) {
if (hasTranslationValue($locale, $article->translatedAttributes)){
if (hasTranslationValue($locale, $article->translatedAttributes)) {
foreach ($article->translatedAttributes as $attribute) {
$article->translateOrNew($locale)->$attribute = $request->input($locale . '.' . $attribute);
$article->translateOrNew($locale)->$attribute = $request->input(
$locale . '.' . $attribute
);
}
}
}
Expand All @@ -69,7 +70,7 @@ public function store(Request $request)
if ($request->has('title_shadow')) {
$article->title_shadow = $request->input('title_shadow');
}

$article->save();

if ($request->hasFile('main_image')) {
Expand Down Expand Up @@ -105,10 +106,10 @@ public function edit($id)
return Redirect::route('article.index');
}

return view('articles.form', array_merge(
$this->buildSelectOptions(),
['article' => $article]
));
return view(
'articles.form',
array_merge($this->buildSelectOptions(), ['article' => $article])
);
}

/**
Expand All @@ -123,9 +124,11 @@ public function update(Article $article, Request $request)

// update translatable attributes
foreach (\Config::get('translatable.locales') as $i => $locale) {
if (hasTranslationValue($locale, $article->translatedAttributes)){
if (hasTranslationValue($locale, $article->translatedAttributes)) {
foreach ($article->translatedAttributes as $attribute) {
$article->translateOrNew($locale)->$attribute = $request->input($locale . '.' . $attribute);
$article->translateOrNew($locale)->$attribute = $request->input(
$locale . '.' . $attribute
);
}
}
}
Expand Down Expand Up @@ -166,10 +169,9 @@ public function update(Article $article, Request $request)
public function destroy($id)
{
Article::find($id)->delete();
return Redirect::route('article.index')->with('message', 'Článok bol zmazaný');;
return Redirect::route('article.index')->with('message', 'Článok bol zmazaný');
}


private function uploadMainImage($article, $request)
{
$main_image = $request->file('main_image');
Expand All @@ -180,26 +182,31 @@ private function uploadMainImage($article, $request)
private function buildSelectOptions()
{
return [
'eduMediaTypesOptions' => collect(Article::$eduMediaTypes)
->reduce(function ($options, $value) {
$options[$value] = trans("edu.media_type.$value");
return $options;
}),
'eduAgeGroupsOptions' => collect(Article::$eduAgeGroups)
->reduce(function ($options, $value) {
$options[$value] = trans("edu.age_group.$value");
return $options;
}),
'eduKeywordsOptions' => Article::all()
->pluck('edu_keywords')
->filter()
->flatten()
->unique()
->sort()
->reduce(function ($options, $value) {
$options[$value] = $value;
return $options;
}) ?? collect(),
'eduMediaTypesOptions' => collect(Article::$eduMediaTypes)->reduce(function (
$options,
$value
) {
$options[$value] = trans("edu.media_type.$value");
return $options;
}),
'eduAgeGroupsOptions' => collect(Article::$eduAgeGroups)->reduce(function (
$options,
$value
) {
$options[$value] = trans("edu.age_group.$value");
return $options;
}),
'eduKeywordsOptions' =>
Article::all()
->pluck('edu_keywords')
->filter()
->flatten()
->unique()
->sort()
->reduce(function ($options, $value) {
$options[$value] = $value;
return $options;
}) ?? collect(),
];
}
}
44 changes: 33 additions & 11 deletions app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ class CollectionController extends Controller
public function index()
{
if (Gate::allows('administer')) {
$collections = Collection::orderBy('created_at', 'desc')->with(['user'])->paginate(20);
$collections = Collection::orderBy('created_at', 'desc')
->with(['user'])
->get();
} else {
$collections = Collection::where('user_id', '=', Auth::user()->id)->orderBy('published_at', 'desc')->with(['user'])->paginate(20);
$collections = Collection::where('user_id', '=', Auth::user()->id)
->orderBy('published_at', 'desc')
->with(['user'])
->get();
}

return view('collections.index')->with('collections', $collections);
Expand Down Expand Up @@ -59,9 +64,11 @@ public function store()

// store translatable attributes
foreach (\Config::get('translatable.locales') as $i => $locale) {
if (hasTranslationValue($locale, $collection->translatedAttributes)){
if (hasTranslationValue($locale, $collection->translatedAttributes)) {
foreach ($collection->translatedAttributes as $attribute) {
$collection->translateOrNew($locale)->$attribute = Request::input($locale . '.' . $attribute);
$collection->translateOrNew($locale)->$attribute = Request::input(
$locale . '.' . $attribute
);
}
}
}
Expand Down Expand Up @@ -89,7 +96,9 @@ public function store()
return Redirect::route('collection.index');
}

return Redirect::back()->withInput()->withErrors($v);
return Redirect::back()
->withInput()
->withErrors($v);
}

/**
Expand Down Expand Up @@ -136,14 +145,16 @@ public function update($id)
$v = Validator::make(Request::all(), Collection::$rules);

if ($v->passes()) {
$input = Arr::except(Request::all(), array('_method'));
$input = Arr::except(Request::all(), ['_method']);

$collection = Collection::find($id);

foreach (\Config::get('translatable.locales') as $i => $locale) {
if (hasTranslationValue($locale, $collection->translatedAttributes)){
if (hasTranslationValue($locale, $collection->translatedAttributes)) {
foreach ($collection->translatedAttributes as $attribute) {
$collection->translateOrNew($locale)->$attribute = Request::input($locale . '.' . $attribute);
$collection->translateOrNew($locale)->$attribute = Request::input(
$locale . '.' . $attribute
);
}
}
}
Expand All @@ -166,7 +177,10 @@ public function update($id)
$this->uploadMainImage($collection);
}

Session::flash('message', 'Kolekcia <code>' . $collection->name . '</code> bola upravená');
Session::flash(
'message',
'Kolekcia <code>' . $collection->name . '</code> bola upravená'
);

return Redirect::route('collection.index');
}
Expand Down Expand Up @@ -208,7 +222,9 @@ public function fill()
}
}

return Redirect::back()->withMessage('Do kolekcie ' . $collection->name . ' bolo pridaných ' . count($items) . ' diel');
return Redirect::back()->withMessage(
'Do kolekcie ' . $collection->name . ' bolo pridaných ' . count($items) . ' diel'
);
} else {
return Redirect::back()->withMessage('Chyba: zvolená kolekcia nebola nájdená. ');
}
Expand All @@ -219,7 +235,13 @@ public function detach($collection_id, $item_id)
$collection = Collection::find($collection_id);
$collection->items()->detach($item_id);

return Redirect::back()->withMessage('Z kolekcie <strong>' . $collection->name . '</strong> bolo odstrádené dielo <code>' . $item_id . '</code>');
return Redirect::back()->withMessage(
'Z kolekcie <strong>' .
$collection->name .
'</strong> bolo odstrádené dielo <code>' .
$item_id .
'</code>'
);
}

private function uploadMainImage($collection)
Expand Down
4 changes: 0 additions & 4 deletions resources/views/articles/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ class="btn btn-success btn-xs btn-outline"
@endforeach
</tbody>
</table>

<div class="text-center"><?php echo $articles->render(); ?></div>


</div>
<!-- /.panel-body -->
</div>
Expand Down
Loading
Loading