rename is_important to is_highlighted (#1215)

This commit is contained in:
xuwhite 2023-09-27 18:15:12 +02:00 committed by GitHub
parent 383f8ebde5
commit 8ebaffd71a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 102 additions and 61 deletions

View File

@ -16,12 +16,12 @@ class NewsFactory extends Factory
public function definition(): array public function definition(): array
{ {
return [ return [
'title' => $this->faker->text(50), 'title' => $this->faker->text(50),
'text' => $this->faker->realText(), 'text' => $this->faker->realText(),
'is_meeting' => $this->faker->boolean(), 'is_meeting' => $this->faker->boolean(),
'is_pinned' => $this->faker->boolean(.1), 'is_pinned' => $this->faker->boolean(.1),
'is_important' => $this->faker->boolean(.1), 'is_highlighted' => $this->faker->boolean(.1),
'user_id' => User::factory(), 'user_id' => User::factory(),
]; ];
} }
} }

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class NewsRenameImportantToHighlight extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$this->schema->table('news', function (Blueprint $table): void {
$table->renameColumn('is_important', 'is_highlighted');
});
$this->schema->getConnection()
->table('privileges')
->where('name', 'news.important')
->update(['name' => 'news.highlight', 'description' => 'Highlight News']);
}
/**
* Reverse the migration
*/
public function down(): void
{
$this->schema->table('news', function (Blueprint $table): void {
$table->renameColumn('is_highlighted', 'is_important');
});
$this->schema->getConnection()
->table('privileges')
->where('name', 'news.highlight')
->update(['name' => 'news.important', 'description' => 'Make News Important']);
}
}

View File

@ -57,14 +57,14 @@ function public_dashboard_controller()
} }
} }
$important_news = News::whereIsImportant(true) $highlighted_news = News::whereIsHighlighted(true)
->orderBy('updated_at') ->orderBy('updated_at')
->limit(1) ->limit(1)
->get(); ->get();
return [ return [
__('Public Dashboard'), __('Public Dashboard'),
public_dashboard_view($stats, $free_shifts, $important_news), public_dashboard_view($stats, $free_shifts, $highlighted_news),
]; ];
} }

View File

@ -9,15 +9,15 @@ use Illuminate\Support\Collection;
* *
* @param array $stats * @param array $stats
* @param array[] $free_shifts * @param array[] $free_shifts
* @param News[]|Collection $important_news * @param News[]|Collection $highlighted_news
* @return string * @return string
*/ */
function public_dashboard_view($stats, $free_shifts, $important_news) function public_dashboard_view($stats, $free_shifts, $highlighted_news)
{ {
$needed_angels = ''; $needed_angels = '';
$news = ''; $news = '';
if ($important_news->isNotEmpty()) { if ($highlighted_news->isNotEmpty()) {
$first_news = $important_news->first(); $first_news = $highlighted_news->first();
$news = div('alert alert-warning text-center', [ $news = div('alert alert-warning text-center', [
'<a href="' . url('/news/' . $first_news->id) . '"><strong>' . $first_news->title . '</strong></a>', '<a href="' . url('/news/' . $first_news->id) . '"><strong>' . $first_news->title . '</strong></a>',
]); ]);

View File

@ -2050,8 +2050,8 @@ msgstr "+"
msgid "news.is_meeting" msgid "news.is_meeting"
msgstr "[Treffen]" msgstr "[Treffen]"
msgid "news.edit.is_important" msgid "news.edit.is_highlighted"
msgstr "Wichtig" msgstr "Hervorgehoben"
msgid "news.read_more" msgid "news.read_more"
msgstr "Weiterlesen" msgstr "Weiterlesen"

View File

@ -193,8 +193,8 @@ msgstr "Subject"
msgid "news.edit.is_meeting" msgid "news.edit.is_meeting"
msgstr "Meeting" msgstr "Meeting"
msgid "news.edit.is_important" msgid "news.edit.is_highlighted"
msgstr "Important" msgstr "Highlighted"
msgid "news.edit.is_pinned" msgid "news.edit.is_pinned"
msgstr "Pin to top" msgstr "Pin to top"

View File

@ -49,9 +49,9 @@
{{ f.checkbox('is_pinned', __('news.edit.is_pinned'), { {{ f.checkbox('is_pinned', __('news.edit.is_pinned'), {
'checked': is_pinned, 'checked': is_pinned,
}) }} }) }}
{% if has_permission_to('news.important') %} {% if has_permission_to('news.highlight') %}
{{ f.checkbox('is_important', __('news.edit.is_important'), { {{ f.checkbox('is_highlighted', __('news.edit.is_highlighted'), {
'checked': is_important, 'checked': is_highlighted,
}) }} }) }}
{% endif %} {% endif %}
</div> </div>
@ -82,7 +82,7 @@
<div class="col-md-12"> <div class="col-md-12">
<h2>{{ __('form.preview') }}</h2> <h2>{{ __('form.preview') }}</h2>
<div class="card {% if news.is_important %}bg-warning{% elseif news.is_meeting %}bg-info{% elseif theme.type =='light' %}bg-light{% else %}bg-secondary{% endif %} mb-4"> <div class="card {% if news.is_highlighted %}bg-warning{% elseif news.is_meeting %}bg-info{% elseif theme.type =='light' %}bg-light{% else %}bg-secondary{% endif %} mb-4">
<div class="card-header {% if news.is_meeting and theme.type == 'dark' %}text-white{% endif %}"> <div class="card-header {% if news.is_meeting and theme.type == 'dark' %}text-white{% endif %}">
{% if news.is_meeting %}{{ __('news.is_meeting') }}{% endif %} {% if news.is_meeting %}{{ __('news.is_meeting') }}{% endif %}
{{ news.title }} {{ news.title }}

View File

@ -48,7 +48,7 @@
{% endblock %} {% endblock %}
{% macro news(news, show_comments_link, is_overview) %} {% macro news(news, show_comments_link, is_overview) %}
<div class="card {% if news.is_important %}bg-warning{% elseif news.is_meeting %}bg-info{% elseif theme.type =='light' %}bg-light{% else %}bg-dark{% endif %} mb-4"> <div class="card {% if news.is_highlighted %}bg-warning{% elseif news.is_meeting %}bg-info{% elseif theme.type =='light' %}bg-light{% else %}bg-dark{% endif %} mb-4">
{% if is_overview|default(false) %} {% if is_overview|default(false) %}
<div class="card-header {% if news.is_meeting and theme.type == 'dark' %}text-white{% endif %}"> <div class="card-header {% if news.is_meeting and theme.type == 'dark' %}text-white{% endif %}">
<a href="{{ url('news/' ~ news.id) }}" class="text-inherit"> <a href="{{ url('news/' ~ news.id) }}" class="text-inherit">

View File

@ -47,10 +47,10 @@ class NewsController extends BaseController
return $this->response->withView( return $this->response->withView(
'pages/news/edit.twig', 'pages/news/edit.twig',
[ [
'news' => $news, 'news' => $news,
'is_meeting' => $news ? $news->is_meeting : $isMeetingDefault, 'is_meeting' => $news ? $news->is_meeting : $isMeetingDefault,
'is_pinned' => $news ? $news->is_pinned : false, 'is_pinned' => $news ? $news->is_pinned : false,
'is_important' => $news ? $news->is_important : false, 'is_highlighted' => $news ? $news->is_highlighted : false,
], ],
); );
} }
@ -63,13 +63,13 @@ class NewsController extends BaseController
$news = $this->news->findOrNew($newsId); $news = $this->news->findOrNew($newsId);
$data = $this->validate($request, [ $data = $this->validate($request, [
'title' => 'required', 'title' => 'required',
'text' => 'required', 'text' => 'required',
'is_meeting' => 'optional|checked', 'is_meeting' => 'optional|checked',
'is_pinned' => 'optional|checked', 'is_pinned' => 'optional|checked',
'is_important' => 'optional|checked', 'is_highlighted' => 'optional|checked',
'delete' => 'optional|checked', 'delete' => 'optional|checked',
'preview' => 'optional|checked', 'preview' => 'optional|checked',
]); ]);
if (!is_null($data['delete'])) { if (!is_null($data['delete'])) {
@ -96,8 +96,8 @@ class NewsController extends BaseController
$news->is_meeting = !is_null($data['is_meeting']); $news->is_meeting = !is_null($data['is_meeting']);
$news->is_pinned = !is_null($data['is_pinned']); $news->is_pinned = !is_null($data['is_pinned']);
if ($this->auth->can('news.important')) { if ($this->auth->can('news.highlight')) {
$news->is_important = !is_null($data['is_important']); $news->is_highlighted = !is_null($data['is_highlighted']);
} }
if (!is_null($data['preview'])) { if (!is_null($data['preview'])) {
@ -119,7 +119,7 @@ class NewsController extends BaseController
'Updated {pinned}{type} "{news}": {text}', 'Updated {pinned}{type} "{news}": {text}',
[ [
'pinned' => $news->is_pinned ? 'pinned ' : '', 'pinned' => $news->is_pinned ? 'pinned ' : '',
'important' => $news->is_important ? 'important ' : '', 'highlighted' => $news->is_highlighted ? 'highlighted ' : '',
'type' => $news->is_meeting ? 'meeting' : 'news', 'type' => $news->is_meeting ? 'meeting' : 'news',
'news' => $news->title, 'news' => $news->title,
'text' => $news->text, 'text' => $news->text,

View File

@ -138,7 +138,7 @@ class NewsController extends BaseController
->with('user') ->with('user')
->withCount('comments') ->withCount('comments')
->orderByDesc('is_pinned') ->orderByDesc('is_pinned')
->orderByDesc('is_important') ->orderByDesc('is_highlighted')
->orderByDesc('updated_at') ->orderByDesc('updated_at')
->orderByDesc('id') ->orderByDesc('id')
->limit($perPage) ->limit($perPage)

View File

@ -16,9 +16,9 @@ use Illuminate\Support\Str;
* @property int $id * @property int $id
* @property string $title * @property string $title
* @property string $text * @property string $text
* @property bool $is_highlighted
* @property bool $is_meeting * @property bool $is_meeting
* @property bool $is_pinned * @property bool $is_pinned
* @property bool $is_important
* @property Carbon|null $created_at * @property Carbon|null $created_at
* @property Carbon|null $updated_at * @property Carbon|null $updated_at
* *
@ -30,7 +30,7 @@ use Illuminate\Support\Str;
* @method static QueryBuilder|News[] whereText($value) * @method static QueryBuilder|News[] whereText($value)
* @method static QueryBuilder|News[] whereIsMeeting($value) * @method static QueryBuilder|News[] whereIsMeeting($value)
* @method static QueryBuilder|News[] whereIsPinned($value) * @method static QueryBuilder|News[] whereIsPinned($value)
* @method static QueryBuilder|News[] whereIsImportant($value) * @method static QueryBuilder|News[] whereIsHighlighted($value)
* @method static QueryBuilder|News[] whereCreatedAt($value) * @method static QueryBuilder|News[] whereCreatedAt($value)
* @method static QueryBuilder|News[] whereUpdatedAt($value) * @method static QueryBuilder|News[] whereUpdatedAt($value)
*/ */
@ -44,17 +44,17 @@ class News extends BaseModel
/** @var array<string, string> */ /** @var array<string, string> */
protected $casts = [ // phpcs:ignore protected $casts = [ // phpcs:ignore
'user_id' => 'integer', 'user_id' => 'integer',
'is_meeting' => 'boolean', 'is_meeting' => 'boolean',
'is_pinned' => 'boolean', 'is_pinned' => 'boolean',
'is_important' => 'boolean', 'is_highlighted' => 'boolean',
]; ];
/** @var array<string, bool> Default attributes */ /** @var array<string, bool> Default attributes */
protected $attributes = [ // phpcs:ignore protected $attributes = [ // phpcs:ignore
'is_meeting' => false, 'is_meeting' => false,
'is_pinned' => false, 'is_pinned' => false,
'is_important' => false, 'is_highlighted' => false,
]; ];
/** @var array<string> */ /** @var array<string> */
@ -63,7 +63,7 @@ class News extends BaseModel
'text', 'text',
'is_meeting', 'is_meeting',
'is_pinned', 'is_pinned',
'is_important', 'is_highlighted',
'user_id', 'user_id',
]; ];

View File

@ -158,12 +158,12 @@ class NewsControllerTest extends ControllerTest
{ {
$this->request->attributes->set('news_id', 1); $this->request->attributes->set('news_id', 1);
$this->request = $this->request->withParsedBody([ $this->request = $this->request->withParsedBody([
'title' => 'New title', 'title' => 'New title',
'text' => 'New text', 'text' => 'New text',
'is_meeting' => '1', 'is_meeting' => '1',
'is_pinned' => '1', 'is_pinned' => '1',
'is_important' => '1', 'is_highlighted' => '1',
'preview' => '1', 'preview' => '1',
]); ]);
$this->response->expects($this->once()) $this->response->expects($this->once())
->method('withView') ->method('withView')
@ -175,7 +175,7 @@ class NewsControllerTest extends ControllerTest
// Contains new text // Contains new text
$this->assertTrue($news->is_meeting); $this->assertTrue($news->is_meeting);
$this->assertTrue($news->is_pinned); $this->assertTrue($news->is_pinned);
$this->assertTrue($news->is_important); $this->assertTrue($news->is_highlighted);
$this->assertEquals('New title', $news->title); $this->assertEquals('New title', $news->title);
$this->assertEquals('New text', $news->text); $this->assertEquals('New text', $news->text);
@ -183,7 +183,7 @@ class NewsControllerTest extends ControllerTest
}); });
$this->auth->expects($this->atLeastOnce()) $this->auth->expects($this->atLeastOnce())
->method('can') ->method('can')
->with('news.important') ->with('news.highlight')
->willReturn(true); ->willReturn(true);
/** @var NewsController $controller */ /** @var NewsController $controller */
@ -198,7 +198,7 @@ class NewsControllerTest extends ControllerTest
$this->assertEquals('**foo**', $news->text); $this->assertEquals('**foo**', $news->text);
$this->assertFalse($news->is_meeting); $this->assertFalse($news->is_meeting);
$this->assertFalse($news->is_pinned); $this->assertFalse($news->is_pinned);
$this->assertFalse($news->is_important); $this->assertFalse($news->is_highlighted);
} }
/** /**

View File

@ -39,12 +39,12 @@ class NewsControllerTest extends ControllerTest
'user_id' => 1, 'user_id' => 1,
], ],
[ [
'title' => 'baz', 'title' => 'baz',
'text' => 'baz', 'text' => 'baz',
'is_meeting' => true, 'is_meeting' => true,
'is_pinned' => true, 'is_pinned' => true,
'is_important' => true, 'is_highlighted' => true,
'user_id' => 1, 'user_id' => 1,
], ],
[ [
'title' => 'Lorem', 'title' => 'Lorem',