News: Add is_pinned

This commit is contained in:
Igor Scheller 2020-12-27 02:51:05 +01:00 committed by msquare
parent 28e357acd3
commit 85044bc833
11 changed files with 69 additions and 6 deletions

View File

@ -0,0 +1,37 @@
<?php
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class NewsAddIsPinned extends Migration
{
use Reference;
/**
* Run the migration
*/
public function up()
{
$this->schema->table(
'news',
function (Blueprint $table) {
$table->boolean('is_pinned')->default(false)->after('is_meeting');
}
);
}
/**
* Reverse the migration
*/
public function down()
{
$this->schema->table(
'news',
function (Blueprint $table) {
$table->dropColumn('is_pinned');
}
);
}
}

View File

@ -2885,6 +2885,9 @@ msgstr "Betreff"
msgid "news.edit.is_meeting" msgid "news.edit.is_meeting"
msgstr "Treffen" msgstr "Treffen"
msgid "news.edit.is_pinned"
msgstr "Oben anpinnen"
msgid "news.edit.message" msgid "news.edit.message"
msgstr "Nachricht" msgstr "Nachricht"

View File

@ -171,6 +171,9 @@ msgstr "Subject"
msgid "news.edit.is_meeting" msgid "news.edit.is_meeting"
msgstr "Meeting" msgstr "Meeting"
msgid "news.edit.is_pinned"
msgstr "Pin to top"
msgid "news.edit.message" msgid "news.edit.message"
msgstr "Message" msgstr "Message"

View File

@ -42,6 +42,7 @@
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
{{ f.checkbox('is_meeting', __('news.edit.is_meeting'), is_meeting) }} {{ f.checkbox('is_meeting', __('news.edit.is_meeting'), is_meeting) }}
{{ f.checkbox('is_pinned', __('news.edit.is_pinned'), is_pinned) }}
</div> </div>
</div> </div>

View File

@ -53,6 +53,7 @@
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title"> <h3 class="panel-title">
<a href="{{ url('news/' ~ news.id) }}"> <a href="{{ url('news/' ~ news.id) }}">
{% if news.is_pinned %}{{ m.glyphicon('pushpin') }}{% endif %}
{% if news.is_meeting %}{{ __('news.is_meeting') }}{% endif %} {% if news.is_meeting %}{{ __('news.is_meeting') }}{% endif %}
{{ news.title }} {{ news.title }}
</a> </a>

View File

@ -96,7 +96,8 @@ class NewsController extends BaseController
'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,
] + $this->getNotifications(), ] + $this->getNotifications(),
); );
} }
@ -116,6 +117,7 @@ class NewsController extends BaseController
'title' => 'required', 'title' => 'required',
'text' => 'required', 'text' => 'required',
'is_meeting' => 'optional|checked', 'is_meeting' => 'optional|checked',
'is_pinned' => 'optional|checked',
'delete' => 'optional|checked', 'delete' => 'optional|checked',
'preview' => 'optional|checked', 'preview' => 'optional|checked',
]); ]);
@ -146,6 +148,7 @@ class NewsController extends BaseController
$news->title = $data['title']; $news->title = $data['title'];
$news->text = $data['text']; $news->text = $data['text'];
$news->is_meeting = !is_null($data['is_meeting']); $news->is_meeting = !is_null($data['is_meeting']);
$news->is_pinned = !is_null($data['is_pinned']);
if (!is_null($data['preview'])) { if (!is_null($data['preview'])) {
return $this->showEdit($news); return $this->showEdit($news);
@ -154,11 +157,12 @@ class NewsController extends BaseController
$news->save(); $news->save();
$this->log->info( $this->log->info(
'Updated {type} "{news}": {text}', 'Updated {pinned}{type} "{news}": {text}',
[ [
'type' => $news->is_meeting ? 'meeting' : 'news', 'pinned' => $news->is_pinned ? 'pinned ' : '',
'news' => $news->title, 'type' => $news->is_meeting ? 'meeting' : 'news',
'text' => $news->text, 'news' => $news->title,
'text' => $news->text,
] ]
); );

View File

@ -149,6 +149,7 @@ class NewsController extends BaseController
$news = $query $news = $query
->with('user') ->with('user')
->withCount('comments') ->withCount('comments')
->orderByDesc('is_pinned')
->orderByDesc('updated_at') ->orderByDesc('updated_at')
->limit($perPage) ->limit($perPage)
->offset(($page - 1) * $perPage) ->offset(($page - 1) * $perPage)

View File

@ -15,6 +15,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
* @property string $title * @property string $title
* @property string $text * @property string $text
* @property bool $is_meeting * @property bool $is_meeting
* @property bool $is_pinned
* @property Carbon|null $created_at * @property Carbon|null $created_at
* @property Carbon|null $updated_at * @property Carbon|null $updated_at
* *
@ -25,6 +26,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
* @method static QueryBuilder|LogEntry[] whereTitle($value) * @method static QueryBuilder|LogEntry[] whereTitle($value)
* @method static QueryBuilder|LogEntry[] whereText($value) * @method static QueryBuilder|LogEntry[] whereText($value)
* @method static QueryBuilder|LogEntry[] whereIsMeeting($value) * @method static QueryBuilder|LogEntry[] whereIsMeeting($value)
* @method static QueryBuilder|LogEntry[] whereIsPinned($value)
* @method static QueryBuilder|LogEntry[] whereCreatedAt($value) * @method static QueryBuilder|LogEntry[] whereCreatedAt($value)
* @method static QueryBuilder|LogEntry[] whereUpdatedAt($value) * @method static QueryBuilder|LogEntry[] whereUpdatedAt($value)
*/ */
@ -38,6 +40,7 @@ class News extends BaseModel
/** @var array */ /** @var array */
protected $casts = [ protected $casts = [
'is_meeting' => 'boolean', 'is_meeting' => 'boolean',
'is_pinned' => 'boolean',
]; ];
/** @var array */ /** @var array */
@ -45,6 +48,7 @@ class News extends BaseModel
'title', 'title',
'text', 'text',
'is_meeting', 'is_meeting',
'is_pinned',
'user_id', 'user_id',
]; ];

View File

@ -214,6 +214,7 @@ class NewsControllerTest extends ControllerTest
'title' => 'New title', 'title' => 'New title',
'text' => 'New text', 'text' => 'New text',
'is_meeting' => '1', 'is_meeting' => '1',
'is_pinned' => '1',
'preview' => '1', 'preview' => '1',
]); ]);
$this->response->expects($this->once()) $this->response->expects($this->once())
@ -225,6 +226,7 @@ class NewsControllerTest extends ControllerTest
$news = $data['news']; $news = $data['news'];
// Contains new text // Contains new text
$this->assertTrue($news->is_meeting); $this->assertTrue($news->is_meeting);
$this->assertTrue($news->is_pinned);
$this->assertEquals('New title', $news->title); $this->assertEquals('New title', $news->title);
$this->assertEquals('New text', $news->text); $this->assertEquals('New text', $news->text);
@ -242,6 +244,7 @@ class NewsControllerTest extends ControllerTest
$this->assertEquals('Foo', $news->title); $this->assertEquals('Foo', $news->title);
$this->assertEquals('<b>foo</b>', $news->text); $this->assertEquals('<b>foo</b>', $news->text);
$this->assertFalse($news->is_meeting); $this->assertFalse($news->is_meeting);
$this->assertFalse($news->is_pinned);
} }
/** /**

View File

@ -44,12 +44,14 @@ class NewsControllerTest extends TestCase
'title' => 'Bar', 'title' => 'Bar',
'text' => 'bar', 'text' => 'bar',
'is_meeting' => false, 'is_meeting' => false,
'is_pinned' => true,
'user_id' => 1, 'user_id' => 1,
], ],
[ [
'title' => 'baz', 'title' => 'baz',
'text' => 'baz', 'text' => 'baz',
'is_meeting' => true, 'is_meeting' => true,
'is_pinned' => true,
'user_id' => 1, 'user_id' => 1,
], ],
[ [
@ -62,6 +64,7 @@ class NewsControllerTest extends TestCase
'title' => 'Ipsum', 'title' => 'Ipsum',
'text' => 'ipsum', 'text' => 'ipsum',
'is_meeting' => true, 'is_meeting' => true,
'is_pinned' => true,
'user_id' => 1, 'user_id' => 1,
], ],
[ [
@ -111,6 +114,8 @@ class NewsControllerTest extends TestCase
$this->assertTrue($news->isNotEmpty()); $this->assertTrue($news->isNotEmpty());
$this->assertEquals(3, $data['pages']); $this->assertEquals(3, $data['pages']);
$this->assertEquals(2, $data['page']); $this->assertEquals(2, $data['page']);
$this->assertTrue($news[0]->is_pinned);
$this->assertEquals('Ipsum', $news[0]->title);
break; break;
case 2: case 2:
// Show meetings // Show meetings

View File

@ -78,7 +78,7 @@ class NewsTest extends ModelTest
public function testCreate(): void public function testCreate(): void
{ {
$news = (new News())->create( $news = (new News())->create(
$this->newsData + ['is_meeting' => true] $this->newsData + ['is_meeting' => true, 'is_pinned' => true]
); );
$news = $news->find($news->id); $news = $news->find($news->id);
@ -86,5 +86,6 @@ class NewsTest extends ModelTest
$this->assertSame($this->newsData['title'], $news->title); $this->assertSame($this->newsData['title'], $news->title);
$this->assertSame($this->newsData['text'], $news->text); $this->assertSame($this->newsData['text'], $news->text);
$this->assertTrue($news->is_meeting); $this->assertTrue($news->is_meeting);
$this->assertTrue($news->is_pinned);
} }
} }