From 6d06474a8824c8f2df0272901e78c672befc7b2f Mon Sep 17 00:00:00 2001 From: weryques Date: Mon, 7 May 2018 13:57:02 -0300 Subject: [PATCH] Fixes and Fetch only of item Fixes error when collapse a filter with checkbox Update styles of checkbox filters Now is possible to limit the return of item metadata --- .../components/search/filters-items-list.vue | 2 +- src/admin/scss/tainacan-admin.scss | 3 +- src/api/class-tainacan-rest-controller.php | 6 ++-- .../class-tainacan-rest-items-controller.php | 14 ++++++-- src/classes/entities/class-tainacan-item.php | 4 +-- .../autocomplete/Autocomplete.vue | 1 - .../custom-interval/CustomInterval.vue | 13 +++++--- .../filter-types/tainacan-filter-item.vue | 32 ++++--------------- .../class-tainacan-item-metadata.php | 4 +-- 9 files changed, 36 insertions(+), 43 deletions(-) diff --git a/src/admin/components/search/filters-items-list.vue b/src/admin/components/search/filters-items-list.vue index 9498ead8a..430e07e5a 100644 --- a/src/admin/components/search/filters-items-list.vue +++ b/src/admin/components/search/filters-items-list.vue @@ -6,7 +6,7 @@ v-for="(filter, index) in filters" :key="index" :filter="filter" - :opened="collapsed"/> + :open="collapsed"/> diff --git a/src/admin/scss/tainacan-admin.scss b/src/admin/scss/tainacan-admin.scss index 1c2f301b4..409e80dc0 100644 --- a/src/admin/scss/tainacan-admin.scss +++ b/src/admin/scss/tainacan-admin.scss @@ -400,8 +400,7 @@ html { border-color: $gray-light !important; } input[type="checkbox"]:checked + .check { - background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1'%3E%3Cpath style='fill:%23000' d='M 0.04038059,0.6267767 0.14644661,0.52071068 0.42928932,0.80355339 0.3232233,0.90961941 z M 0.21715729,0.80355339 0.85355339,0.16715729 0.95961941,0.2732233 0.3232233,0.90961941 z'%3E%3C/path%3E%3C/svg%3E") no-repeat center center; - background-color: white; + background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1'%3E%3Cpath style='fill:%23000' d='M 0.04038059,0.6267767 0.14644661,0.52071068 0.42928932,0.80355339 0.3232233,0.90961941 z M 0.21715729,0.80355339 0.85355339,0.16715729 0.95961941,0.2732233 0.3232233,0.90961941 z'%3E%3C/path%3E%3C/svg%3E") no-repeat center center !important; border-color: $gray-light !important; } } diff --git a/src/api/class-tainacan-rest-controller.php b/src/api/class-tainacan-rest-controller.php index f37f22b4f..e72ba5dff 100644 --- a/src/api/class-tainacan-rest-controller.php +++ b/src/api/class-tainacan-rest-controller.php @@ -25,8 +25,10 @@ class REST_Controller extends \WP_REST_Controller { if (is_array($attributes)) { foreach ( $attributes as $attribute ) { try { - $get_ = 'get_' . $attribute; - $object_filtered[$attribute] = $object->$get_(); + if(!is_array($attribute)) { + $get_ = 'get_' . $attribute; + $object_filtered[ $attribute ] = $object->$get_(); + } } catch ( \Error $error ) { // Do nothing } diff --git a/src/api/endpoints/class-tainacan-rest-items-controller.php b/src/api/endpoints/class-tainacan-rest-items-controller.php index 70634eae9..42acd75f6 100644 --- a/src/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/api/endpoints/class-tainacan-rest-items-controller.php @@ -94,8 +94,8 @@ class REST_Items_Controller extends REST_Controller { * * @return mixed */ - private function add_metadata_to_item($item_object, $item_array){ - $item_metadata = $item_object->get_fields(); + private function add_metadata_to_item($item_object, $item_array, $args = []){ + $item_metadata = $item_object->get_fields($args); foreach($item_metadata as $index => $me){ $field = $me->get_field(); @@ -140,8 +140,16 @@ class REST_Items_Controller extends REST_Controller { } $attributes_to_filter = $request['fetch_only']; + $item_arr = $this->filter_object_by_attributes($item, $attributes_to_filter); - return $this->filter_object_by_attributes($item, $attributes_to_filter); + if(array_key_exists('metas', $attributes_to_filter)){ + + $args = array('post__in' => $attributes_to_filter['metas']); + + $item_arr = $this->add_metadata_to_item($item, $item_arr, $args); + } + + return $item_arr; } return $item; diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index cdfceccd5..d697fc627 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -333,10 +333,10 @@ class Item extends Entity { * * @return array Array of ItemMetadata objects */ - function get_fields() { + function get_fields($args = []) { $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); - return $Tainacan_Item_Metadata->fetch( $this, 'OBJECT' ); + return $Tainacan_Item_Metadata->fetch( $this, 'OBJECT', $args ); } diff --git a/src/classes/filter-types/autocomplete/Autocomplete.vue b/src/classes/filter-types/autocomplete/Autocomplete.vue index bddd18dfc..d8b68a8ab 100644 --- a/src/classes/filter-types/autocomplete/Autocomplete.vue +++ b/src/classes/filter-types/autocomplete/Autocomplete.vue @@ -25,7 +25,6 @@ -
-
+
+ type="is-white" + size="is-small" + class="is-size-7" + attached + rounded="false" + closable + @close="clearSearch()"> {{ showSearch() }}
diff --git a/src/classes/filter-types/tainacan-filter-item.vue b/src/classes/filter-types/tainacan-filter-item.vue index 83ba0267b..077023168 100644 --- a/src/classes/filter-types/tainacan-filter-item.vue +++ b/src/classes/filter-types/tainacan-filter-item.vue @@ -3,12 +3,12 @@ id="filter-item-forms" :message="getErrorMessage" :type="filterTypeMessage"> - + @@ -33,7 +33,7 @@ props: { filter: Object, query: Object, - opened: false, + open: false, }, data(){ return { @@ -135,27 +135,9 @@ } } - .radio { - margin-bottom: 0.2em; - } - - .checkbox { + .b-checkbox.checkbox { font-weight: normal; - font-size: 14px; - margin-bottom: 0.2em; - border: none !important; - - .check{ - width: 1rem !important; - height: 1rem !important; - - &:focus, &:active, &:checked { - box-shadow: none !important; - border: 1px gray !important; - border-radius: 2px !important; - } - } - + font-size: 12px; } } diff --git a/src/classes/repositories/class-tainacan-item-metadata.php b/src/classes/repositories/class-tainacan-item-metadata.php index e5916b219..01d54dbe3 100644 --- a/src/classes/repositories/class-tainacan-item-metadata.php +++ b/src/classes/repositories/class-tainacan-item-metadata.php @@ -185,7 +185,7 @@ class Item_Metadata extends Repository { * @return array * @throws \Exception */ - public function fetch($object, $output = null ){ + public function fetch($object, $output = null, $args = [] ){ if($object instanceof Entities\Item){ $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); @@ -195,7 +195,7 @@ class Item_Metadata extends Repository { return []; } - $meta_list = $Tainacan_Fields->fetch_by_collection($collection, [], 'OBJECT' ); + $meta_list = $Tainacan_Fields->fetch_by_collection($collection, $args, 'OBJECT' ); $return = [];