From eacd65d68d96fc6cb5fa0aec90c137165238ee93 Mon Sep 17 00:00:00 2001 From: Jacson Passold Date: Tue, 28 Aug 2018 00:19:39 -0300 Subject: [PATCH 01/31] add allow comments meta prop to collection --- .../entities/class-tainacan-collection.php | 20 ++++++++++++++++++- .../entities/class-tainacan-entity.php | 2 +- .../class-tainacan-collections.php | 10 +++++++++- .../repositories/class-tainacan-items.php | 4 ++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index 47aa9bbec..c38eba22b 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -34,7 +34,8 @@ class Collection extends Entity { $header_image_id, $header_image, $moderators_ids, - $comment_status; + $comment_status, + $allow_comments; /** * {@inheritDoc} @@ -501,6 +502,14 @@ class Collection extends Entity { public function get_comment_status() { return $this->get_mapped_property('comment_status'); } + + /** + * Checks if comments are allowed for the current Collection Items. + * @return bool + */ + public function get_allow_comments() { + return $this->get_mapped_property('allow_comments'); + } /** * Set the collection name @@ -702,6 +711,15 @@ class Collection extends Entity { public function set_comment_status( $value ) { $this->set_mapped_property('comment_status', $value); } + + /** + * Sets if comments are allowed for the current Collection Items. + * + * @param $value bool + */ + public function set_allow_comments( $value ) { + $this->set_mapped_property('allow_comments', $value ); + } // Moderators methods diff --git a/src/classes/entities/class-tainacan-entity.php b/src/classes/entities/class-tainacan-entity.php index baac8f5d3..a9503a4f9 100644 --- a/src/classes/entities/class-tainacan-entity.php +++ b/src/classes/entities/class-tainacan-entity.php @@ -154,7 +154,7 @@ class Entity { * @return mixed property value */ public function get_mapped_property($prop) { - if (isset($this->$prop) ){ + if ( isset($this->$prop) ){ return $this->$prop; } diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index 6ac854542..4f9e0d9bb 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -199,9 +199,17 @@ class Collections extends Repository { 'map' => 'comment_status', 'title' => __( 'Comment Status', 'tainacan' ), 'type' => 'string', - 'description' => __( 'The status of collection comment, if is "open" the comments are allowed for collection items, or is "closed" for deny comments to items.', 'tainacan' ), + 'description' => __( 'The status of collection comment, if is "open" the comments are allowed, or is "closed" for deny comments.', 'tainacan' ), 'default' => get_default_comment_status(Entities\Collection::get_post_type()), 'validation' => v::optional(v::stringType()->in( [ 'open', 'closed' ] )), + ], + 'allow_comments' => [ + 'map' => 'meta', + 'title' => __( 'Allow Items Comments', 'tainacan' ), + 'type' => 'string', + 'description' => __( 'Collection items comment is allowed, if is "open" the comments are allowed for collection items, or is "closed" for deny comments to items.', 'tainacan' ), + 'default' => 'open', + 'validation' => v::optional(v::stringType()->in( [ 'open', 'closed' ] )), ] ] ); diff --git a/src/classes/repositories/class-tainacan-items.php b/src/classes/repositories/class-tainacan-items.php index 5b1b9268c..6c8e1c71f 100644 --- a/src/classes/repositories/class-tainacan-items.php +++ b/src/classes/repositories/class-tainacan-items.php @@ -398,7 +398,7 @@ class Items extends Repository { /** * Get a default thumbnail ID from the item document. * - * @param EntitiesItem $item The item + * @param Entities\Item $item The item * * @return int|null The thumbnail ID or null if it was not possible to find a thumbnail */ @@ -491,7 +491,7 @@ class Items extends Repository { if($item != false && $item instanceof Entities\Item) { $collection = $item->get_collection(); - if($collection->get_comment_status() !== 'open' ) return false; + if( $collection->get_allow_comments() !== 'open' ) return false; } return $open_comment; From add549b8818247ede6e2daae76bc819e98ae0ce1 Mon Sep 17 00:00:00 2001 From: Jacson Passold Date: Tue, 28 Aug 2018 00:19:55 -0300 Subject: [PATCH 02/31] fix item comment open test --- tests/test-items.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test-items.php b/tests/test-items.php index 818365dff..2c4ffeb8b 100644 --- a/tests/test-items.php +++ b/tests/test-items.php @@ -279,7 +279,7 @@ class Items extends TAINACAN_UnitTestCase { 'collection', array( 'name' => 'collectionComments', - 'comment_status' => 'closed' + 'allow_comments' => 'closed' ), true, true @@ -303,8 +303,8 @@ class Items extends TAINACAN_UnitTestCase { $this->assertFalse(comments_open($item->get_id())); $collections = \Tainacan\Repositories\Collections::get_instance(); - $collection->set('comment_status', 'open'); - $collection->validate(); + $collection->set('allow_comments', 'open'); + $this->assertTrue($collection->validate()); $collections->update($collection); $this->assertTrue(comments_open($item->get_id())); @@ -312,7 +312,7 @@ class Items extends TAINACAN_UnitTestCase { $items = \Tainacan\Repositories\Items::get_instance(); $item->set('comment_status', 'closed'); - $item->validate(); + $this->assertTrue($item->validate()); $items->update($item); $this->assertFalse(comments_open($item->get_id())); From 8910ad2ab85e96902866163de752e045b92778a1 Mon Sep 17 00:00:00 2001 From: Jacson Passold Date: Tue, 28 Aug 2018 00:20:52 -0300 Subject: [PATCH 03/31] add allow_commets prop to collection module --- src/js/store/modules/collection/actions.js | 23 +++++++++++++++++--- src/js/store/modules/collection/getters.js | 4 ++++ src/js/store/modules/collection/index.js | 3 ++- src/js/store/modules/collection/mutations.js | 8 +++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/js/store/modules/collection/actions.js b/src/js/store/modules/collection/actions.js index adc8918e0..04bb6575d 100644 --- a/src/js/store/modules/collection/actions.js +++ b/src/js/store/modules/collection/actions.js @@ -174,6 +174,20 @@ export const fetchCollectionCommentStatus = ({ commit }, id) => { }); }; +export const fetchCollectionAllowComments = ({ commit }, id) => { + return new Promise((resolve, reject) =>{ + axios.tainacan.get('/collections/' + id + '?fetch_only=allow_comments') + .then(res => { + let collectionAllowComments = res.data; + commit('setCollectionAllowComments', collectionAllowComments.allow_comments); + resolve( collectionAllowComments.allow_comments ); + }) + .catch(error => { + reject(error); + }) + }); +}; + export const fetchCollectionNameAndURL = ({ commit }, id) => { //commit('cleanCollectionName'); return new Promise((resolve, reject) =>{ @@ -223,7 +237,8 @@ export const updateCollection = ({ commit }, { parent, enabled_view_modes, default_view_mode, - comment_status + comment_status, + allow_comments }) => { return new Promise((resolve, reject) => { axios.tainacan.patch('/collections/' + collection_id, { @@ -237,7 +252,8 @@ export const updateCollection = ({ commit }, { parent: parent, enabled_view_modes: enabled_view_modes, default_view_mode: default_view_mode, - comment_status: comment_status + comment_status: comment_status, + allow_comments: allow_comments }).then( res => { commit('setCollection', { id: collection_id, @@ -251,7 +267,8 @@ export const updateCollection = ({ commit }, { parent: parent, enabled_view_modes: enabled_view_modes, default_view_mode: default_view_mode, - comment_status: comment_status + comment_status: comment_status, + allow_comments: allow_comments }); commit('setCollectionName', res.data.name); commit('setCollectionURL', res.data.url); diff --git a/src/js/store/modules/collection/getters.js b/src/js/store/modules/collection/getters.js index bb72d0a10..3abd562ae 100644 --- a/src/js/store/modules/collection/getters.js +++ b/src/js/store/modules/collection/getters.js @@ -28,4 +28,8 @@ export const getAttachments = state => { export const getCollectionCommentStatus = state => { return state.collectionCommentStatus; +} + +export const getCollectionAllowComments = state => { + return state.collectionAllowComments; } \ No newline at end of file diff --git a/src/js/store/modules/collection/index.js b/src/js/store/modules/collection/index.js index 7692ce1bb..6f67b9c12 100644 --- a/src/js/store/modules/collection/index.js +++ b/src/js/store/modules/collection/index.js @@ -11,7 +11,8 @@ const state = { collectionName: '', collectionURL: '', attachments: [], - collectionCommentStatus: '' + collectionCommentStatus: '', + collectionAllowComments: '' }; export default { diff --git a/src/js/store/modules/collection/mutations.js b/src/js/store/modules/collection/mutations.js index 535b9f2dc..4ac1e814c 100644 --- a/src/js/store/modules/collection/mutations.js +++ b/src/js/store/modules/collection/mutations.js @@ -77,4 +77,12 @@ export const setCollectionCommentStatus = (state, collectionCommentStatus) => { export const cleanCollectionCommentStatus = (state) => { state.collectionCommentStatus = ''; +} + +export const setCollectionAllowComments = (state, collectionAllowComments) => { + state.collectionAllowComments = collectionAllowComments; +} + +export const cleanCollectionAllowComments = (state) => { + state.collectionAllowComments = ''; } \ No newline at end of file From a8cbdd304a5699be864cc94492a415ee5366e1bc Mon Sep 17 00:00:00 2001 From: Jacson Passold Date: Tue, 28 Aug 2018 00:22:15 -0300 Subject: [PATCH 04/31] use allow comments instead of comment status in collection --- .../edition/collection-edition-form.vue | 16 ++++++++-------- .../components/edition/item-edition-form.vue | 12 ++++++------ src/admin/pages/singles/item-page.vue | 10 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/admin/components/edition/collection-edition-form.vue b/src/admin/components/edition/collection-edition-form.vue index 70ad0bdf2..9c0a1a58b 100644 --- a/src/admin/components/edition/collection-edition-form.vue +++ b/src/admin/components/edition/collection-edition-form.vue @@ -236,10 +236,10 @@ size="is-small" true-value="open" false-value="closed" - v-model="form.comment_status" /> + v-model="form.allow_comments" /> + :title="$i18n.getHelperTitle('collections', 'allow_comments')" + :message="$i18n.getHelperMessage('collections', 'allow_comments')"/>
@@ -440,7 +440,7 @@ export default { moderators_ids: [], enabled_view_modes: [], default_view_mode: [], - comment_status: '' + allow_comments: '' }, thumbnail: {}, cover: {}, @@ -543,7 +543,7 @@ export default { parent: this.form.parent, enabled_view_modes: this.form.enabled_view_modes, default_view_mode: this.form.default_view_mode, - comment_status: this.form.comment_status + allow_comments: this.form.allow_comments }; this.updateCollection(data).then(updatedCollection => { @@ -558,7 +558,7 @@ export default { this.form.enable_cover_page = this.collection.enable_cover_page; this.form.enabled_view_modes = this.collection.enabled_view_modes; this.form.default_view_mode = this.collection.default_view_mode; - this.form.comment_status = this.collection.comment_status; + this.form.allow_comments = this.collection.allow_comments; this.isLoading = false; this.formErrorMessage = ''; @@ -603,7 +603,7 @@ export default { this.form.default_view_mode = this.collection.default_view_mode; this.form.enabled_view_modes = []; this.moderators = []; - this.form.comment_status = this.collection.comment_status; + this.form.allow_comments = this.collection.allow_comments; // Pre-fill status with publish to incentivate it this.form.status = 'publish'; @@ -790,7 +790,7 @@ export default { this.form.default_view_mode = this.collection.default_view_mode; this.form.enabled_view_modes = JSON.parse(JSON.stringify(this.collection.enabled_view_modes)); this.moderators = JSON.parse(JSON.stringify(this.collection.moderators)); - this.form.comment_status = this.collection.comment_status; + this.form.allow_comments = this.collection.allow_comments; // Generates CoverPage from current cover_page_id info if (this.form.cover_page_id != undefined && this.form.cover_page_id != '') { diff --git a/src/admin/components/edition/item-edition-form.vue b/src/admin/components/edition/item-edition-form.vue index 7d198aa83..036f3b027 100644 --- a/src/admin/components/edition/item-edition-form.vue +++ b/src/admin/components/edition/item-edition-form.vue @@ -254,7 +254,7 @@ + v-if="collectionAllowComments == 'open'"> { - this.collectionCommentStatus = collectionCommentStatus; + // Obtains if collection allow items comments + this.fetchCollectionAllowComments(this.collectionId).then((collectionAllowComments) => { + this.collectionAllowComments = collectionAllowComments; }); // Sets feedback variables diff --git a/src/admin/pages/singles/item-page.vue b/src/admin/pages/singles/item-page.vue index 2aaddeaa0..0cc3bc7d6 100644 --- a/src/admin/pages/singles/item-page.vue +++ b/src/admin/pages/singles/item-page.vue @@ -87,7 +87,7 @@ + v-if="collectionAllowComments == 'open'"> { - this.collectionCommentStatus = collectionCommentStatus; + this.fetchCollectionAllowComments(this.collectionId).then((collectionAllowComments) => { + this.collectionAllowComments = collectionAllowComments; }); } From 98538468c3a52b7d9511c15427e0d8f113d99c0c Mon Sep 17 00:00:00 2001 From: weryques Date: Fri, 31 Aug 2018 17:32:52 -0300 Subject: [PATCH 05/31] Fixes overflow in checkbox modal --- src/admin/components/bulk-edition/bulk-edition-modal.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/admin/components/bulk-edition/bulk-edition-modal.vue b/src/admin/components/bulk-edition/bulk-edition-modal.vue index ec072277b..0cbdba644 100644 --- a/src/admin/components/bulk-edition/bulk-edition-modal.vue +++ b/src/admin/components/bulk-edition/bulk-edition-modal.vue @@ -9,7 +9,7 @@
-