batch replace/rename initialComment by pinnedComment

This commit is contained in:
Mathieu Jaumotte 2021-12-13 16:31:16 +01:00
parent 52a137ee77
commit f8071d32c0
7 changed files with 72 additions and 34 deletions

View File

@ -186,7 +186,7 @@ class AccompanyingPeriod implements
* ) * )
* @Groups({"read"}) * @Groups({"read"})
*/ */
private ?Comment $initialComment = null; private ?Comment $pinnedComment = null;
/** /**
* @var string * @var string
@ -563,7 +563,7 @@ class AccompanyingPeriod implements
public function getComments(): Collection public function getComments(): Collection
{ {
return $this->comments->filter(function (Comment $c) { return $this->comments->filter(function (Comment $c) {
return $c !== $this->initialComment; return $c !== $this->pinnedComment;
}); });
} }
@ -606,9 +606,9 @@ class AccompanyingPeriod implements
/** /**
* @Groups({"read"}) * @Groups({"read"})
*/ */
public function getInitialComment(): ?Comment public function getPinnedComment(): ?Comment
{ {
return $this->initialComment; return $this->pinnedComment;
} }
public function getIntensity(): ?string public function getIntensity(): ?string
@ -1030,17 +1030,17 @@ class AccompanyingPeriod implements
/** /**
* @Groups({"write"}) * @Groups({"write"})
*/ */
public function setInitialComment(?Comment $comment = null): self public function setPinnedComment(?Comment $comment = null): self
{ {
if (null !== $this->initialComment) { if (null !== $this->pinnedComment) {
$this->removeComment($this->initialComment); $this->removeComment($this->pinnedComment);
} }
if ($comment instanceof Comment) { if ($comment instanceof Comment) {
$this->addComment($comment); $this->addComment($comment);
} }
$this->initialComment = $comment; $this->pinnedComment = $comment;
return $this; return $this;
} }

View File

@ -20,10 +20,10 @@
tag-name="textarea"> tag-name="textarea">
</ckeditor> </ckeditor>
<div v-if="initialComment" class="metadata"> <div v-if="pinnedComment" class="metadata">
{{ $t('comment.created_by', [ {{ $t('comment.created_by', [
initialComment.creator.text, pinnedComment.creator.text,
$d(initialComment.createdAt.datetime, 'long') $d(pinnedComment.createdAt.datetime, 'long')
]) }} ]) }}
</div> </div>
@ -32,7 +32,7 @@
<li> <li>
<button type="submit" class="btn btn-save">{{ $t('action.save') }}</button> <button type="submit" class="btn btn-save">{{ $t('action.save') }}</button>
</li> </li>
<li v-if="initialComment !== null"> <li v-if="pinnedComment !== null">
<a class="btn btn-delete" <a class="btn btn-delete"
@click="removeComment"> @click="removeComment">
{{ $t('action.delete') }} {{ $t('action.delete') }}
@ -66,15 +66,15 @@ export default {
} }
}, },
computed: { computed: {
initialComment() { pinnedComment() {
return this.$store.state.accompanyingCourse.initialComment; return this.$store.state.accompanyingCourse.pinnedComment;
}, },
content: { content: {
set(value) { set(value) {
this.formdata.content = value; this.formdata.content = value;
}, },
get() { get() {
return (this.initialComment)? this.initialComment.content : {}; return (this.pinnedComment)? this.pinnedComment.content : {};
} }
}, },
errors() { errors() {
@ -107,7 +107,7 @@ export default {
/* /*
* TODO * TODO
* - [x] delete button in ul record_actions, but not in form * - [x] delete button in ul record_actions, but not in form
* - [ ] display updatedAt => initialComment fetch PATCH content changes MUST NOT change object id !! * - [ ] display updatedAt => pinnedComment fetch PATCH content changes MUST NOT change object id !!
*/ */
</script> </script>

View File

@ -163,7 +163,7 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
}, },
postFirstComment(state, comment) { postFirstComment(state, comment) {
//console.log('### mutation: postFirstComment', comment); //console.log('### mutation: postFirstComment', comment);
state.accompanyingCourse.initialComment = comment; state.accompanyingCourse.pinnedComment = comment;
}, },
updateSocialIssues(state, value) { updateSocialIssues(state, value) {
console.log('updateSocialIssues', value); console.log('updateSocialIssues', value);
@ -565,11 +565,11 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
}, },
postFirstComment({ commit }, payload) { postFirstComment({ commit }, payload) {
const url = `/api/1.0/person/accompanying-course/${id}.json` const url = `/api/1.0/person/accompanying-course/${id}.json`
const body = { type: "accompanying_period", initialComment: payload } const body = { type: "accompanying_period", pinnedComment: payload }
return makeFetch('PATCH', url, body) return makeFetch('PATCH', url, body)
.then((response) => { .then((response) => {
commit('postFirstComment', response.initialComment); commit('postFirstComment', response.pinnedComment);
}) })
.catch((error) => { .catch((error) => {
commit('catchError', error); commit('catchError', error);

View File

@ -78,19 +78,19 @@
</div> </div>
{% endif %} {% endif %}
{% if accompanyingCourse.initialComment is not empty %} {% if accompanyingCourse.pinnedComment is not empty %}
<div class="col col-sm-6 col-lg-4 comment mb-4"> <div class="col col-sm-6 col-lg-4 comment mb-4">
<h4 class="item-key">{{ 'Pinned comment'|trans }}</h4> <h4 class="item-key">{{ 'Pinned comment'|trans }}</h4>
<blockquote class="chill-user-quote"> <blockquote class="chill-user-quote">
{{ accompanyingCourse.initialComment.content }} {{ accompanyingCourse.pinnedComment.content }}
<div class="metadata"> <div class="metadata">
{{ 'Last updated by'| trans }} {{ 'Last updated by'| trans }}
<span class="user"> <span class="user">
{{ accompanyingCourse.initialComment.updatedBy|chill_entity_render_box }} {{ accompanyingCourse.pinnedComment.updatedBy|chill_entity_render_box }}
</span> </span>
{{ 'on'|trans ~ ' ' }} {{ 'on'|trans ~ ' ' }}
<span class="date"> <span class="date">
{{ accompanyingCourse.initialComment.updatedAt|format_datetime("medium", "short") }} {{ accompanyingCourse.pinnedComment.updatedAt|format_datetime("medium", "short") }}
</span> </span>
</div> </div>
</blockquote> </blockquote>

View File

@ -60,28 +60,28 @@ final class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
$this->assertFalse($period->isClosingAfterOpening()); $this->assertFalse($period->isClosingAfterOpening());
} }
public function testInitialComment() public function testPinnedComment()
{ {
$period = new AccompanyingPeriod(new DateTime()); $period = new AccompanyingPeriod(new DateTime());
$comment = new Comment(); $comment = new Comment();
$replacingComment = new Comment(); $replacingComment = new Comment();
$period->setInitialComment(null); $period->setPinnedComment(null);
$this->assertNull($period->getInitialComment()); $this->assertNull($period->getPinnedComment());
$period->setInitialComment($comment); $period->setPinnedComment($comment);
$this->assertSame($period->getInitialComment(), $comment); $this->assertSame($period->getPinnedComment(), $comment);
$this->assertSame($period, $comment->getAccompanyingPeriod()); $this->assertSame($period, $comment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments');
$period->setInitialComment($replacingComment); $period->setPinnedComment($replacingComment);
$this->assertSame($period->getInitialComment(), $replacingComment); $this->assertSame($period->getPinnedComment(), $replacingComment);
$this->assertSame($period, $replacingComment->getAccompanyingPeriod()); $this->assertSame($period, $replacingComment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments');
$this->assertNull($comment->getAccompanyingPeriod()); $this->assertNull($comment->getAccompanyingPeriod());
$period->setInitialComment(null); $period->setPinnedComment(null);
$this->assertNull($period->getInitialComment()); $this->assertNull($period->getPinnedComment());
$this->assertNull($replacingComment->getAccompanyingPeriod()); $this->assertNull($replacingComment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments');
} }

View File

@ -554,7 +554,7 @@ paths:
value: value:
type: accompanying_period type: accompanying_period
id: 2668, id: 2668,
initialComment: pinnedComment:
type: accompanying_period_comment type: accompanying_period_comment
content: > content: >
This is my an initial comment. This is my an initial comment.
@ -1139,7 +1139,7 @@ paths:
description: "OK" description: "OK"
400: 400:
description: "transition cannot be applyed" description: "transition cannot be applyed"
/1.0/person/accompanying-course/{id}/confidential.json: /1.0/person/accompanying-course/{id}/confidential.json:
post: post:
tags: tags:

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
* @author Mathieu Jaumotte mathieu.jaumotte@champs-libres.coop
*/
final class Version20211213150253 extends AbstractMigration
{
public function getDescription(): string
{
return 'rename initialComment attribute to pinnedComment';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_accompanying_period DROP CONSTRAINT fk_e260a8683111d50b');
$this->addSql('DROP INDEX idx_e260a8683111d50b');
$this->addSql('ALTER TABLE chill_person_accompanying_period RENAME COLUMN initialcomment_id TO pinnedcomment_id');
$this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A868B0804E90 FOREIGN KEY (pinnedcomment_id) REFERENCES chill_person_accompanying_period_comment (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_E260A868B0804E90 ON chill_person_accompanying_period (pinnedcomment_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_accompanying_period DROP CONSTRAINT FK_E260A868B0804E90');
$this->addSql('DROP INDEX IDX_E260A868B0804E90');
$this->addSql('ALTER TABLE chill_person_accompanying_period RENAME COLUMN pinnedcomment_id TO initialcomment_id');
$this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT fk_e260a8683111d50b FOREIGN KEY (initialcomment_id) REFERENCES chill_person_accompanying_period_comment (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX idx_e260a8683111d50b ON chill_person_accompanying_period (initialcomment_id)');
}
}