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

This commit is contained in:
weryques 2018-03-06 08:30:44 -03:00
commit b71ddd26de
14 changed files with 223 additions and 71 deletions

1
.gitignore vendored
View File

@ -19,4 +19,3 @@ last-package-build.md5
src/admin/scss/.sass-cache
src/assets/css/tainacan-admin.css
src/assets/css/tainacan-admin.css.map
cypress

View File

@ -1,4 +1,5 @@
# the destination folder, inside the plugins folder of some WordPress installation
destination=~/devel/wordpress/wp-content/plugins/tainacan
wp_base_dir=~/devel/wordpress
wp_url=http://localhost/wp
wp_url=http://localhost/wordpress
wp_plugin_dir=~/devel/wordpress/wp-content/plugins/tainacan

View File

@ -52,10 +52,10 @@ fi
### END npm build ###
echo "Updating files in $destination"
rm -rf $destination
mkdir $destination
cp -R src/* $destination/
rm -rf $destination/scss
echo "Updating files in $wp_plugin_dir"
rm -rf $wp_plugin_dir
mkdir $wp_plugin_dir
cp -R src/* $wp_plugin_dir/
rm -rf $wp_plugin_dir/scss
echo "Build complete!"

View File

@ -1 +1,3 @@
{}
{
"projectId": "tubzok"
}

View File

@ -0,0 +1,7 @@
describe('Tainacan Test', function () {
it('.should() - assert that <title> is correct', function () {
cy.visit('http://localhost/wordpress/wp-admin')
cy.get('log').type('admin').should('have.value', 'amdin')
cy.get('pwd').type('root').should('have.value', 'root')
})
})

17
cypress/plugins/index.js Normal file
View File

@ -0,0 +1,17 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}

17
cypress/support/index.js Normal file
View File

@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Alternatively you can use CommonJS syntax:
// require('./commands')

49
run-cypress.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
if [ $# - lt 2 ]; then
echo "usage: $0 [skip-head]"
exit 1
fi
SKIP_HEAD=${1-1}
source build-config.cfg
./build.sh
plugin_name=`basename $wp_plugin_dir`
test_db_prefix='wptests_'
################## set up cypress environment
# replace table prefix in wp_config
echo "Changing DB prefix in wp_config..."
sed -i s/"require_once(ABSPATH . 'wp-settings.php');"/"\$table_prefix = '$test_db_prefix';\nrequire_once(ABSPATH . 'wp-settings.php');"/ $wp_base_dir/wp-config.php
# install WordPress
cd $wp_base_dir
echo "Installing WordPress..."
wp core install --url=$wp_url --title=Test --admin_user=admin --admin_password=admin --admin_email=admin@admin.com
# Activate Tainacan
wp plugin activate $plugin_name
# back to tainacan dev directory
cd -
# cypress beginning
if [ ${SKIP_HEAD} = "0" ]
then
./node_modules/.bin/cypress run
else
./node_modules/.bin/cypress run --headed
fi
################## teardown cypress environment
# remove WordPress
echo "Removing WordPress..."
cd $wp_base_dir
wp db query "DROP TABLES $(wp db tables | paste -s -d, -);"
# recover table prefix in wp_config
echo "Restoring DB prefix in wp_config..."
sed -i s/"\$table_prefix = '$test_db_prefix';"/""/ $wp_base_dir/wp-config.php

View File

@ -1,41 +1,8 @@
#!/bin/bash
source build-config.cfg
#./build.sh
plugin_name=`basename $destination`
test_db_prefix='wp_tainacan_test_'
################## set up cypress environment
# replace table prefix in wp_config
echo "Changing DB prefix in wp_config..."
sed -i s/"require_once(ABSPATH . 'wp-settings.php');"/"\$table_prefix = '$test_db_prefix';\nrequire_once(ABSPATH . 'wp-settings.php');"/ $wp_base_dir/wp-config.php
# install WordPress
cd $wp_base_dir
echo "Installing WordPress..."
wp core install --url=$wp_url --title=Test --admin_user=admin --admin_password=admin --admin_email=admin@admin.com
# Activate Tainacan
wp plugin activate $plugin_name
# back to tainacan dev directory
cd -
#npx cypress run --env host=$wp_url,baseUrl=$wp_url
################## teardown cypress environment
# remove WordPress
echo "Removing WordPress..."
cd $wp_base_dir
wp db query "DROP TABLES $(wp db tables | paste -s -d, -);"
# recover table prefix in wp_config
echo "Restoring DB prefix in wp_config..."
sed -i s/"\$table_prefix = '$test_db_prefix';"/""/ $wp_base_dir/wp-config.php
echo "Running unit tests in PHPUnit..."
phpunit
echo "Running integration tests headless in Crypess..."
# the value 0 leaves the cypress headless
./run-cypress.sh 0

View File

@ -10,16 +10,47 @@
@change="handleChange"
:class="{'fields-area-receive': isDraggingFromAvailable}"
:list="activeFieldList"
:options="{group: { name:'fields', pull: false, put: true }, chosenClass: 'sortable-chosen', filter: '.not-sortable-item'}">
<div
:options="{group: { name:'fields', pull: false, put: true }, 'handle': '.handle', chosenClass: 'sortable-chosen', filter: '.not-sortable-item'}">
<div
class="active-field-item"
:class="{'not-sortable-item': field.id == undefined || isRepositoryLevel}"
:class="{'not-sortable-item': field.id == undefined || isRepositoryLevel }"
v-for="(field, index) in activeFieldList" :key="index">
{{ field.name }}
<span class="label-details"><span class="loading-spinner" v-if="field.id == undefined"></span> <b-tag v-if="field.status != undefined">{{field.status}}</b-tag></span>
<a @click.prevent="removeField(field)" v-if="field.id != undefined"><b-icon icon="delete"></b-icon></a>
<b-icon icon="pencil" v-if="field.id != undefined"></b-icon>
<div>
<div class="handle">
{{ field.name }}
<span class="label-details"><span class="loading-spinner" v-if="field.id == undefined"></span> <b-tag v-if="field.status != undefined">{{field.status}}</b-tag></span>
<b-icon type="is-gray" class="is-pulled-right" icon="drag"></b-icon>
<a @click.prevent="removeField(field)" v-if="field.id != undefined"><b-icon icon="delete"></b-icon></a>
<a @click.prevent="editField(field)" v-if="field.id != undefined"><b-icon icon="pencil" v-if="field.id != undefined"></b-icon></a>
</div>
<div v-if="openedFieldId == field.id">
<form v-on:submit.prevent="saveEdition($event, field)">
<b-field :label="$i18n.get('label_status')">
<b-select
id="tainacan-select-status"
name="status"
:value="editForm"
:placeholder="$i18n.get('instruction_select_a_status')">
<option value="private">{{ $i18n.get('publish')}}</option>
<option value="private">{{ $i18n.get('private')}}</option>
</b-select>
</b-field>
<div v-html="field.edit_form"></div>
<div class="field is-grouped">
<div class="control">
<button class="button is-link" type="submit">Submit</button>
</div>
<div class="control">
<button class="button is-text" @click.prevent="cancelEdition(field)" slot="trigger">Cancel</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- <div class="not-sortable-item" slot="footer">{{ $i18n.get('instruction_dragndrop_fields_collection') }}</div> -->
</draggable>
</b-field>
@ -55,7 +86,10 @@ export default {
isRepositoryLevel: false,
isDraggingFromAvailable: false,
isLoadingFieldTypes: true,
isLoadingFields: false
isLoadingFields: false,
isLoadingField: false,
editForm: {},
openedFieldId: ''
}
},
methods: {
@ -80,6 +114,21 @@ export default {
this.updateFieldsOrder();
}
},
saveEdition($event, field) {
this.openedFieldId = field.id;
let data = []
for (let i = 0; i < $event.target.length; i++) {
let input = {};
input[$event.target[i].name] = $event.target[i].value;
data.push(input);
}
console.log(data);
},
cancelEdition(field) {
this.editForm = {};
this.openedFieldId = '';
},
updateFieldsOrder() {
let fieldsOrder = [];
for (let field of this.activeFieldList) {
@ -117,6 +166,12 @@ export default {
})
.catch((error) => {
});
},
editField(field) {
if (this.openedFieldId == field.id)
this.openedFieldId = '';
else
this.openedFieldId = field.id;
}
},
computed: {
@ -129,8 +184,8 @@ export default {
},
created() {
this.isLoadingFieldTypes = true;
this.isLoadingFields = true;
this.isLoadingFields = true;
this.fetchFieldTypes()
.then((res) => {
this.isLoadingFieldTypes = false;
@ -166,6 +221,10 @@ export default {
border: 1px dashed gray;
}
.collapse {
display: initial;
}
.active-field-item {
background-color: white;
padding: 0.2em 0.5em;
@ -195,7 +254,7 @@ export default {
&.not-sortable-item {
color: gray;
cursor: wait;
cursor: default;
}
}
.active-field-item:hover {

View File

@ -197,8 +197,9 @@ export default {
handleSelectionChange() {
},
onChangeItemsPerPage(value) {
let prevValue = this.itemsPerPage;
this.itemsPerPage = value;
this.$userPrefs.set('items_per_page', value);
this.$userPrefs.set('num_items_per_page', value, prevValue);
this.loadItems();
},
goToItemPage(itemId) {
@ -229,12 +230,12 @@ export default {
}
},
created() {
this.$userPrefs.get('items_per_page')
this.$userPrefs.get('num_items_per_page')
.then((value) => {
this.itemsPerPage = value;
})
.catch((error) => {
this.$userPrefs.set('items_per_page', 12);
this.$userPrefs.set('num_items_per_page', 12, null);
});
},
mounted(){

View File

@ -29,22 +29,29 @@ UserPrefsPlugin.install = function (Vue, options = {}) {
return new Promise(( resolve, reject ) => {
wpApi.get('/wp/v2/users/me/')
.then( res => {
if (res.data.meta.hasOwnProperty(key))
resolve( res.data.key );
else
if (res.data.meta.hasOwnProperty(key)) {
if (res.data.key.length > 1)
resolve( res.data.key );
else
resolve( res.data.key[0] );
} else {
reject( { message: 'Key does not exists in user preference.', value: false} );
}
})
.catch(error => {
reject( { message: error, value: false});
});
});
},
set(metakey, value) {
let data = {
'meta': { metakey: value }
};
set(metakey, value, prevValue) {
let data = {}
if (prevValue != null)
data = {'meta': [{'metakey': metakey, 'metavalue': value, 'prevvalue': prevValue}]};
else
data = {'meta': [{'metakey': metakey, 'metavalue': value}]};
return new Promise(( resolve, reject ) => {
wpApi.post('/wp/v2/users/me/?context=edit&' + qs.stringify(data))
wpApi.post('/wp/v2/users/me/?' + qs.stringify(data))
.then( res => {
resolve( res.data );
})

View File

@ -8,7 +8,7 @@ export const fetchFields = ({ commit }, {collectionId, isRepositoryLevel}) => {
else
endpoint = '/fields/';
axios.get(endpoint)
axios.get(endpoint + '?context=edit')
.then((res) => {
let fields= res.data;
commit('setFields', fields);
@ -21,6 +21,30 @@ export const fetchFields = ({ commit }, {collectionId, isRepositoryLevel}) => {
});
}
export const fetchField = ({ commit }, {collectionId, fieldId, isRepositoryLevel}) => {
return new Promise((resolve, reject) => {
let endpoint = '';
if (!isRepositoryLevel)
endpoint = '/collection/' + collectionId + '/fields/' + fieldId;
else
endpoint = '/fields/' + fieldId;
axios.get(endpoint + '?context=edit')
.then((res) => {
let field = res.data;
commit('setSingleField', field);
resolve (field);
})
.catch((error) => {
console.log(error);
reject(error);
});
});
}
export const sendField = ( { commit }, { collectionId, name, fieldType, status, isRepositoryLevel }) => {
return new Promise(( resolve, reject ) => {
let endpoint = '';
@ -28,7 +52,7 @@ export const sendField = ( { commit }, { collectionId, name, fieldType, status,
endpoint = '/collection/' + collectionId + '/fields/';
else
endpoint = '/fields/';
axios.post(endpoint, {
axios.post(endpoint + '?context=edit', {
name: name,
field_type: fieldType,
status: status

View File

@ -1,3 +1,5 @@
import Vue from 'vue';
export const deleteField = ( state, field ) => {
let index = state.fields.findIndex(deletedField => deletedField.id === field.id);
if (index >= 0) {