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
{
return [
'title' => $this->faker->text(50),
'text' => $this->faker->realText(),
'is_meeting' => $this->faker->boolean(),
'is_pinned' => $this->faker->boolean(.1),
'is_important' => $this->faker->boolean(.1),
'user_id' => User::factory(),
'title' => $this->faker->text(50),
'text' => $this->faker->realText(),
'is_meeting' => $this->faker->boolean(),
'is_pinned' => $this->faker->boolean(.1),
'is_highlighted' => $this->faker->boolean(.1),
'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')
->limit(1)
->get();
return [
__('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[] $free_shifts
* @param News[]|Collection $important_news
* @param News[]|Collection $highlighted_news
* @return string
*/
function public_dashboard_view($stats, $free_shifts, $important_news)
function public_dashboard_view($stats, $free_shifts, $highlighted_news)
{
$needed_angels = '';
$news = '';
if ($important_news->isNotEmpty()) {
$first_news = $important_news->first();
if ($highlighted_news->isNotEmpty()) {
$first_news = $highlighted_news->first();
$news = div('alert alert-warning text-center', [
'<a href="' . url('/news/' . $first_news->id) . '"><strong>' . $first_news->title . '</strong></a>',
]);

View File

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

View File

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

View File

@ -49,9 +49,9 @@
{{ f.checkbox('is_pinned', __('news.edit.is_pinned'), {
'checked': is_pinned,
}) }}
{% if has_permission_to('news.important') %}
{{ f.checkbox('is_important', __('news.edit.is_important'), {
'checked': is_important,
{% if has_permission_to('news.highlight') %}
{{ f.checkbox('is_highlighted', __('news.edit.is_highlighted'), {
'checked': is_highlighted,
}) }}
{% endif %}
</div>
@ -82,7 +82,7 @@
<div class="col-md-12">
<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 %}">
{% if news.is_meeting %}{{ __('news.is_meeting') }}{% endif %}
{{ news.title }}

View File

@ -48,7 +48,7 @@
{% endblock %}
{% 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) %}
<div class="card-header {% if news.is_meeting and theme.type == 'dark' %}text-white{% endif %}">
<a href="{{ url('news/' ~ news.id) }}" class="text-inherit">

View File

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

View File

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

View File

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

View File

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