diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 5b4293226..9c13dcd2f 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -186,7 +186,7 @@ class AccompanyingPeriod implements * ) * @Groups({"read"}) */ - private ?Comment $initialComment = null; + private ?Comment $pinnedComment = null; /** * @var string @@ -563,7 +563,7 @@ class AccompanyingPeriod implements public function getComments(): Collection { return $this->comments->filter(function (Comment $c) { - return $c !== $this->initialComment; + return $c !== $this->pinnedComment; }); } @@ -606,9 +606,9 @@ class AccompanyingPeriod implements /** * @Groups({"read"}) */ - public function getInitialComment(): ?Comment + public function getPinnedComment(): ?Comment { - return $this->initialComment; + return $this->pinnedComment; } public function getIntensity(): ?string @@ -1030,17 +1030,17 @@ class AccompanyingPeriod implements /** * @Groups({"write"}) */ - public function setInitialComment(?Comment $comment = null): self + public function setPinnedComment(?Comment $comment = null): self { - if (null !== $this->initialComment) { - $this->removeComment($this->initialComment); + if (null !== $this->pinnedComment) { + $this->removeComment($this->pinnedComment); } if ($comment instanceof Comment) { $this->addComment($comment); } - $this->initialComment = $comment; + $this->pinnedComment = $comment; return $this; } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue index 7f5b04f99..5df43cdac 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue @@ -20,10 +20,10 @@ tag-name="textarea"> -
+
{{ $t('comment.created_by', [ - initialComment.creator.text, - $d(initialComment.createdAt.datetime, 'long') + pinnedComment.creator.text, + $d(pinnedComment.createdAt.datetime, 'long') ]) }}
@@ -32,7 +32,7 @@
  • -
  • +
  • {{ $t('action.delete') }} @@ -66,15 +66,15 @@ export default { } }, computed: { - initialComment() { - return this.$store.state.accompanyingCourse.initialComment; + pinnedComment() { + return this.$store.state.accompanyingCourse.pinnedComment; }, content: { set(value) { this.formdata.content = value; }, get() { - return (this.initialComment)? this.initialComment.content : {}; + return (this.pinnedComment)? this.pinnedComment.content : {}; } }, errors() { @@ -107,7 +107,7 @@ export default { /* * TODO * - [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 !! */ diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index a1858c6b3..d092adb0b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -163,7 +163,7 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise]) }, postFirstComment(state, comment) { //console.log('### mutation: postFirstComment', comment); - state.accompanyingCourse.initialComment = comment; + state.accompanyingCourse.pinnedComment = comment; }, updateSocialIssues(state, value) { console.log('updateSocialIssues', value); @@ -565,11 +565,11 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise]) }, postFirstComment({ commit }, payload) { 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) .then((response) => { - commit('postFirstComment', response.initialComment); + commit('postFirstComment', response.pinnedComment); }) .catch((error) => { commit('catchError', error); diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig index 215aa90c1..39e924d18 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/index.html.twig @@ -78,19 +78,19 @@
  • {% endif %} - {% if accompanyingCourse.initialComment is not empty %} + {% if accompanyingCourse.pinnedComment is not empty %}

    {{ 'Pinned comment'|trans }}

    - {{ accompanyingCourse.initialComment.content }} + {{ accompanyingCourse.pinnedComment.content }}
    diff --git a/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php index 9bbea0f1c..0ecc886f8 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Entity/AccompanyingPeriodTest.php @@ -60,28 +60,28 @@ final class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase $this->assertFalse($period->isClosingAfterOpening()); } - public function testInitialComment() + public function testPinnedComment() { $period = new AccompanyingPeriod(new DateTime()); $comment = new Comment(); $replacingComment = new Comment(); - $period->setInitialComment(null); - $this->assertNull($period->getInitialComment()); + $period->setPinnedComment(null); + $this->assertNull($period->getPinnedComment()); - $period->setInitialComment($comment); - $this->assertSame($period->getInitialComment(), $comment); + $period->setPinnedComment($comment); + $this->assertSame($period->getPinnedComment(), $comment); $this->assertSame($period, $comment->getAccompanyingPeriod()); $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); - $period->setInitialComment($replacingComment); - $this->assertSame($period->getInitialComment(), $replacingComment); + $period->setPinnedComment($replacingComment); + $this->assertSame($period->getPinnedComment(), $replacingComment); $this->assertSame($period, $replacingComment->getAccompanyingPeriod()); $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); $this->assertNull($comment->getAccompanyingPeriod()); - $period->setInitialComment(null); - $this->assertNull($period->getInitialComment()); + $period->setPinnedComment(null); + $this->assertNull($period->getPinnedComment()); $this->assertNull($replacingComment->getAccompanyingPeriod()); $this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments'); } diff --git a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml index 3c49cc264..218904e5e 100644 --- a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml @@ -554,7 +554,7 @@ paths: value: type: accompanying_period id: 2668, - initialComment: + pinnedComment: type: accompanying_period_comment content: > This is my an initial comment. @@ -1139,7 +1139,7 @@ paths: description: "OK" 400: description: "transition cannot be applyed" - + /1.0/person/accompanying-course/{id}/confidential.json: post: tags: diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20211213150253.php b/src/Bundle/ChillPersonBundle/migrations/Version20211213150253.php new file mode 100644 index 000000000..fc977165f --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20211213150253.php @@ -0,0 +1,38 @@ +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)'); + } +}