Merge branch 'develop' of github.com:tainacan/tainacan into develop

This commit is contained in:
Jacson Passold 2018-03-07 10:48:15 -03:00
commit dbc138e1a8
3 changed files with 54 additions and 42 deletions

View File

@ -13,6 +13,8 @@ class Admin {
add_action( 'admin_menu', array(&$this, 'add_admin_menu') );
add_filter( 'admin_body_class', array(&$this, 'admin_body_class') );
add_action( 'init', array(&$this, 'register_user_meta') );
}
function add_admin_menu() {
@ -76,12 +78,14 @@ class Admin {
$cur_user = wp_get_current_user();
$user_caps = array();
$prefs = array();
if ($cur_user instanceof \WP_User) {
if (is_array($cur_user->allcaps)) {
foreach ($cur_user->allcaps as $cap => $bool)
if ($bool === true)
$user_caps[] = $cap;
}
$prefs = get_user_meta($cur_user->ID, 'tainacan_prefs', true);
}
$settings = [
@ -91,6 +95,7 @@ class Admin {
'components' => $components,
'i18n' => $tainacan_admin_i18n,
'user_caps' => $user_caps,
'user_prefs' => $prefs,
'base_url' => $TAINACAN_BASE_URL
];
@ -100,6 +105,17 @@ class Admin {
}
function register_user_meta() {
$args = array(
//'sanitize_callback' => 'sanitize_my_meta_key',
//'auth_callback' => 'authorize_my_meta_key',
'type' => 'array',
'description' => 'Tainacan admin user preferences',
'single' => true,
'show_in_rest' => true,
);
register_meta( 'user', 'tainacan_prefs', $args );
}
}

View File

@ -7,15 +7,15 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
* TAINACAN_REST_Controller constructor.
*/
public function __construct() {
add_action( 'rest_api_init', function () {
register_rest_field( 'user',
'meta',
array(
'update_callback' => array($this, 'up_user_meta'),
'get_callback' => array($this, 'gt_user_meta'),
)
);
} );
//add_action( 'rest_api_init', function () {
// register_rest_field( 'user',
// 'meta',
// array(
// 'update_callback' => array($this, 'up_user_meta'),
// 'get_callback' => array($this, 'gt_user_meta'),
// )
// );
//} );
}
/**

View File

@ -5,6 +5,7 @@
name="field_type_relationship[collection_id]"
placeholder="Select the collection to fetch items"
v-model="collection"
@change.native="emitValues()"
:loading="loading">
<option value="">Select...</option>
<option
@ -42,23 +43,14 @@
<b-field label="Allow repeated items">
<div class="block">
<div class="field">
<b-radio name="field_type_relationship[repeated]"
v-model="modelRepeated"
size="is-small"
native-value="yes">
Yes
</b-radio>
</div>
<div class="field">
<b-radio name="field_type_relationship[repeated]"
v-model="modelRepeated"
size="is-small"
native-value="no">
No
</b-radio>
</div>
</div>
<b-switch v-model="modelRepeated"
type="is-info"
@input="emitValues()"
true-value="yes"
false-value="no">
{{ labelRepeated() }}
</b-switch>
</div>
</b-field>
</section>
</template>
@ -93,12 +85,8 @@
} else {
this.fields = [];
this.hasFields = false;
this.modelSearch = []
}
this.emitValues();
},
modelRepeated( value ){
this.modelRepeated = value;
this.emitValues();
},
modelSearch( value ){
this.modelSearch = value;
@ -106,15 +94,18 @@
}
},
created(){
console.log( this.value);
this.fetchCollections().then( data => {
if( this.collection_id !== '' ){
if( this.collection_id && this.collection_id !== '' ){
this.collection = this.collection_id;
} else if ( this.value ) {
this.collection = this.value.collection_id;
}
})
});
if( this.repeated ){
this.modelRepeated = this.repeated;
} else if( this.value ) {
this.modelRepeated = this.value.repeated;
}
},
methods:{
@ -167,18 +158,23 @@
})
.catch((error) => {
this.hasFields = false;
console.log(error);
});
},
checkFields(){
try {
const json = JSON.parse( this.search );
this.modelSearch = json;
} catch(e){
this.modelSearch = [];
if( this.value && this.value.search.length > 0 ){
this.modelSearch = this.value.search;
} else {
try {
const json = JSON.parse( this.search );
this.modelSearch = json;
} catch(e){
this.modelSearch = [];
}
}
},
labelRepeated(){
return ( this.modelRepeated === 'yes' ) ? 'Yes' : 'No';
},
emitValues(){
this.$emit('input',{