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_action( 'admin_menu', array(&$this, 'add_admin_menu') );
add_filter( 'admin_body_class', array(&$this, 'admin_body_class') ); add_filter( 'admin_body_class', array(&$this, 'admin_body_class') );
add_action( 'init', array(&$this, 'register_user_meta') );
} }
function add_admin_menu() { function add_admin_menu() {
@ -76,12 +78,14 @@ class Admin {
$cur_user = wp_get_current_user(); $cur_user = wp_get_current_user();
$user_caps = array(); $user_caps = array();
$prefs = array();
if ($cur_user instanceof \WP_User) { if ($cur_user instanceof \WP_User) {
if (is_array($cur_user->allcaps)) { if (is_array($cur_user->allcaps)) {
foreach ($cur_user->allcaps as $cap => $bool) foreach ($cur_user->allcaps as $cap => $bool)
if ($bool === true) if ($bool === true)
$user_caps[] = $cap; $user_caps[] = $cap;
} }
$prefs = get_user_meta($cur_user->ID, 'tainacan_prefs', true);
} }
$settings = [ $settings = [
@ -91,6 +95,7 @@ class Admin {
'components' => $components, 'components' => $components,
'i18n' => $tainacan_admin_i18n, 'i18n' => $tainacan_admin_i18n,
'user_caps' => $user_caps, 'user_caps' => $user_caps,
'user_prefs' => $prefs,
'base_url' => $TAINACAN_BASE_URL '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. * TAINACAN_REST_Controller constructor.
*/ */
public function __construct() { public function __construct() {
add_action( 'rest_api_init', function () { //add_action( 'rest_api_init', function () {
register_rest_field( 'user', // register_rest_field( 'user',
'meta', // 'meta',
array( // array(
'update_callback' => array($this, 'up_user_meta'), // 'update_callback' => array($this, 'up_user_meta'),
'get_callback' => array($this, 'gt_user_meta'), // 'get_callback' => array($this, 'gt_user_meta'),
) // )
); // );
} ); //} );
} }
/** /**

View File

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