From 780f5a998de5938011b311da0bf38739aecafb89 Mon Sep 17 00:00:00 2001 From: weryques Date: Thu, 22 Mar 2018 15:30:57 -0300 Subject: [PATCH] Category creation page, Category edition page and init of category page --- .../edition/category-edition-form.vue | 336 +++++++++++++++++- .../components/lists/categories-list.vue | 8 +- .../components/navigation/tainacan-header.vue | 17 +- src/admin/js/router.js | 2 + src/admin/js/utilities.js | 4 +- src/admin/pages/singles/category-page.vue | 59 +++ src/admin/tainacan-admin-i18n.php | 1 + .../entities/class-tainacan-taxonomy.php | 19 + .../class-tainacan-repository.php | 2 +- .../class-tainacan-taxonomies.php | 2 +- src/js/store/modules/category/actions.js | 91 ++++- src/js/store/modules/category/getters.js | 4 + src/js/store/modules/category/index.js | 3 +- src/js/store/modules/category/mutations.js | 4 + 14 files changed, 531 insertions(+), 21 deletions(-) create mode 100644 src/admin/pages/singles/category-page.vue diff --git a/src/admin/components/edition/category-edition-form.vue b/src/admin/components/edition/category-edition-form.vue index 960a5fc4d..dbafa31b9 100644 --- a/src/admin/components/edition/category-edition-form.vue +++ b/src/admin/components/edition/category-edition-form.vue @@ -1,22 +1,352 @@ - diff --git a/src/admin/components/lists/categories-list.vue b/src/admin/components/lists/categories-list.vue index f31d42f1a..aaa42edb1 100644 --- a/src/admin/components/lists/categories-list.vue +++ b/src/admin/components/lists/categories-list.vue @@ -94,7 +94,7 @@ + + \ No newline at end of file diff --git a/src/admin/tainacan-admin-i18n.php b/src/admin/tainacan-admin-i18n.php index 16cb0eb87..05dd1bc26 100644 --- a/src/admin/tainacan-admin-i18n.php +++ b/src/admin/tainacan-admin-i18n.php @@ -126,6 +126,7 @@ return [ 'instruction_dragndrop_filters_repository' => __( 'Drag and drop Fields to create Filters on Repository.', 'tainacan' ), 'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ), 'instruction_delete_selected_items' => __( 'Delete selected items', 'tainacan' ), + 'instruction_delete_selected_categories' => __( 'Delete selected categories', 'tainacan' ), 'instruction_image_upload_box' => __( 'Drop an image here or click to upload.', 'tainacan' ), 'instruction_select_a_status' => __( 'Select a status:', 'tainacan' ), 'instruction_select_a_filter_type' => __( 'Select a filter type:', 'tainacan' ), diff --git a/src/classes/entities/class-tainacan-taxonomy.php b/src/classes/entities/class-tainacan-taxonomy.php index 6f43ecdfc..58c1a3390 100644 --- a/src/classes/entities/class-tainacan-taxonomy.php +++ b/src/classes/entities/class-tainacan-taxonomy.php @@ -173,4 +173,23 @@ class Taxonomy extends Entity { function set_allow_insert($value) { $this->set_mapped_property('allow_insert', $value); } + + /** + * Validate Taxonomy + * + * @return bool + */ + function validate() { + if ( ! in_array( $this->get_status(), apply_filters( 'tainacan-status-require-validation', [ + 'publish', + 'future', + 'private' + ] ) ) ) { + return true; + } + + return parent::validate(); + + } + } \ No newline at end of file diff --git a/src/classes/repositories/class-tainacan-repository.php b/src/classes/repositories/class-tainacan-repository.php index d260991e6..cbeeb6210 100644 --- a/src/classes/repositories/class-tainacan-repository.php +++ b/src/classes/repositories/class-tainacan-repository.php @@ -80,7 +80,7 @@ abstract class Repository { // First iterate through the native post properties foreach ( $map as $prop => $mapped ) { - if ( $mapped['map'] != 'meta' && $mapped['map'] != 'meta_multi' && $mapped['map'] != 'thumbnail_id' ) { + if ( $mapped['map'] != 'meta' && $mapped['map'] != 'meta_multi' ) { $obj->WP_Post->{$mapped['map']} = $obj->get_mapped_property( $prop ); } } diff --git a/src/classes/repositories/class-tainacan-taxonomies.php b/src/classes/repositories/class-tainacan-taxonomies.php index 704aaa590..d0558c3a4 100644 --- a/src/classes/repositories/class-tainacan-taxonomies.php +++ b/src/classes/repositories/class-tainacan-taxonomies.php @@ -38,7 +38,7 @@ class Taxonomies extends Repository { 'title' => __('Name', 'tainacan'), 'type' => 'string', 'description' => __('Name of the taxonomy', 'tainacan'), - 'on_error' => __('The taxonomy should be a text value and not empty', 'tainacan'), + 'on_error' => __('The taxonomy name should be a text value and not empty', 'tainacan'), 'validation' => v::stringType()->notEmpty(), ], 'description' => [ diff --git a/src/js/store/modules/category/actions.js b/src/js/store/modules/category/actions.js index cbb6e143b..d8b4ff671 100644 --- a/src/js/store/modules/category/actions.js +++ b/src/js/store/modules/category/actions.js @@ -2,16 +2,57 @@ import axios from '../../../axios/axios' export const createCategory = ({commit}, category) => { return new Promise(( resolve, reject ) => { - axios.tainacan.post('/taxonomies/', { + axios.tainacan.post('/taxonomies', { name: category.name, description: category.description, status: category.status, slug: category.slug, - allow_insert: category.allow_insert + allow_insert: category.allowInsert }) .then( res => { + let category = res.data; + + console.log(category); commit('setCategory', category); - resolve( res.data ); + + resolve( category ); + }) + .catch(error => { + reject( error.response ); + }); + }); +}; + +export const deleteCategory = ({ commit }, categoryId) => { + return new Promise(( resolve, reject ) => { + axios.tainacan.delete(`/taxonomies/${categoryId}`, { + 'is_permanently': true + }) + .then(res => { + + resolve( res.data ); + }) + .catch(error => { + reject( error ) + }); + }); +}; + +export const updateCategory = ({ commit }, category) => { + return new Promise(( resolve, reject ) => { + axios.tainacan.patch(`/taxonomies/${category.categoryId}`, { + name: category.name, + description: category.description, + status: category.status, + slug: category.slug ? category.slug : '', + allow_insert: category.allowInsert + }) + .then( res => { + let category = res.data; + + commit('setCategory', category); + + resolve( category ); }) .catch(error => { reject( error.response ); @@ -21,15 +62,53 @@ export const createCategory = ({commit}, category) => { export const fetchCategories = ({ commit }, { page, categoriesPerPage } ) => { return new Promise((resolve, reject) => { - axios.tainacan.get('/taxonomies?paged='+ page +'&perpage='+ categoriesPerPage) + axios.tainacan.get(`/taxonomies?paged=${page}&perpage=${categoriesPerPage}`) .then(res => { let categories = res.data; + commit('setCategories', categories); - resolve({'categories': categories, 'total': res.headers['x-wp-total'] }); + + resolve({ + 'categories': categories, + 'total': res.headers['x-wp-total'] + }); }) .catch(error => { - console.log(error); reject(error); }); }); +}; + +export const fetchCategory = ({ commit }, categoryId) => { + return new Promise((resolve, reject) => { + axios.tainacan.get(`/taxonomies/${categoryId}`) + .then(res => { + let category = res.data; + + commit('setCategory', category); + + resolve({ + 'category': category + }) + }) + .catch(error => { + reject(error); + }) + }); +}; + +export const fetchCategoryName = ({ commit }, categoryId) => { + return new Promise((resolve, reject) => { + axios.tainacan.get(`/taxonomies/${categoryId}?fetch_only=name`) + .then(res => { + let name = res.data; + + commit('setCategoryName'); + + resolve(name.name) + }) + .catch(error => { + reject(error) + }) + }); }; \ No newline at end of file diff --git a/src/js/store/modules/category/getters.js b/src/js/store/modules/category/getters.js index 0d19ddd31..c4cbe39c1 100644 --- a/src/js/store/modules/category/getters.js +++ b/src/js/store/modules/category/getters.js @@ -4,4 +4,8 @@ export const getCategory = state => { export const getCategories = state => { return state.categories; +}; + +export const getCategoryName = state => { + return state.categoryName; }; \ No newline at end of file diff --git a/src/js/store/modules/category/index.js b/src/js/store/modules/category/index.js index 4c1a81d27..3863f310d 100644 --- a/src/js/store/modules/category/index.js +++ b/src/js/store/modules/category/index.js @@ -4,7 +4,8 @@ import * as mutations from './mutations'; const state = { categories: [], - category: null, + category: {}, + categoryName: String, }; export default { diff --git a/src/js/store/modules/category/mutations.js b/src/js/store/modules/category/mutations.js index 0e10c90da..d8bc5a110 100644 --- a/src/js/store/modules/category/mutations.js +++ b/src/js/store/modules/category/mutations.js @@ -4,4 +4,8 @@ export const setCategory = (state, category) => { export const setCategories = (state, categories) => { state.categories = categories; +}; + +export const setCategoryName = (state, name) => { + state.categoryName = name; }; \ No newline at end of file