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
This commit is contained in:
weryques 2018-05-07 13:57:02 -03:00
parent 87b85ec6ed
commit 6d06474a88
9 changed files with 36 additions and 43 deletions

View File

@ -6,7 +6,7 @@
v-for="(filter, index) in filters"
:key="index"
:filter="filter"
:opened="collapsed"/>
:open="collapsed"/>
</div>
</template>

View File

@ -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;
}
}

View File

@ -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
}

View File

@ -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;

View File

@ -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 );
}

View File

@ -25,7 +25,6 @@
</div>
</template>
</b-autocomplete>
<br>
<div class="field has-text-centered">
<b-tag
v-if="results !== ''"

View File

@ -35,13 +35,16 @@
class="column"
v-model="value_end"/>
</div>
<div class="field has-text-centered">
<div class="control has-text-centered">
<b-tag
v-if="isValid && !clear"
type="is-primary"
size="is-small"
closable
@close="clearSearch()">
type="is-white"
size="is-small"
class="is-size-7"
attached
rounded="false"
closable
@close="clearSearch()">
{{ showSearch() }}
</b-tag>
</div>

View File

@ -3,12 +3,12 @@
id="filter-item-forms"
:message="getErrorMessage"
:type="filterTypeMessage">
<b-collapse :open="opened">
<b-collapse :open="open">
<label
@click="opened = !opened"
slot="trigger">
slot="trigger"
slot-scope="props">
<b-icon
:icon="opened ? 'menu-down' : 'menu-right'"
:icon="props.open ? 'menu-down' : 'menu-right'"
size="is-small" />
{{ filter.name }}
</label>
@ -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;
}
}

View File

@ -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 = [];