From ba16e2ced0f425bda1e254e117c27bbf8fa9d747 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 25 May 2020 16:54:23 -0300 Subject: [PATCH 01/71] Basic folder and bundle structure for item submission shortcode. #388 --- .../class-tainacan-theme-helper.php | 23 +++- src/views/item-submission/item-submission.vue | 48 +++++++ .../js/item-submission-main.js | 123 ++++++++++++++++++ .../pages/item-submission-form.vue | 11 ++ .../scss/item-submission-basics.sass | 11 ++ webpack.config.js | 1 + 6 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 src/views/item-submission/item-submission.vue create mode 100644 src/views/item-submission/js/item-submission-main.js create mode 100644 src/views/item-submission/pages/item-submission-form.vue create mode 100644 src/views/item-submission/scss/item-submission-basics.sass diff --git a/src/classes/theme-helper/class-tainacan-theme-helper.php b/src/classes/theme-helper/class-tainacan-theme-helper.php index 2be0c2688..e5fac1159 100644 --- a/src/classes/theme-helper/class-tainacan-theme-helper.php +++ b/src/classes/theme-helper/class-tainacan-theme-helper.php @@ -49,7 +49,8 @@ class Theme_Helper { add_filter('get_the_archive_title', array($this, 'filter_archive_title')); add_shortcode( 'tainacan-search', array($this, 'search_shortcode')); - + add_shortcode( 'tainacan-item-submission', array($this, 'item_submission_shortcode')); + add_action( 'generate_rewrite_rules', array( &$this, 'rewrite_rules' ), 10, 1 ); add_filter( 'query_vars', array( &$this, 'rewrite_rules_query_vars' ) ); add_filter( 'template_include', array( &$this, 'rewrite_rule_template_include' ) ); @@ -354,6 +355,26 @@ class Theme_Helper { return $image; } + public function item_submission_shortcode($args) { + global $TAINACAN_BASE_URL; + + $props = ' '; + + // Passes arguments to custom props + if ($args) { + foreach ($args as $key => $value) { + if ($value == true || $value == 'true') { + $props .= str_replace('_', '-', $key) . '="' . $value . '" '; + } + } + } + + wp_enqueue_script('tainacan-item-submission', $TAINACAN_BASE_URL . '/assets/js/item_submission.js' , ['underscore', 'media-editor', 'media-views', 'customize-controls'] , TAINACAN_VERSION); + wp_localize_script('tainacan-item-submission', 'tainacan_plugin', \Tainacan\Admin::get_instance()->get_admin_js_localization_params()); + + return "
"; + } + public function search_shortcode($args) { $props = ' '; diff --git a/src/views/item-submission/item-submission.vue b/src/views/item-submission/item-submission.vue new file mode 100644 index 000000000..c4fbb5b3b --- /dev/null +++ b/src/views/item-submission/item-submission.vue @@ -0,0 +1,48 @@ + + + + + \ No newline at end of file diff --git a/src/views/item-submission/js/item-submission-main.js b/src/views/item-submission/js/item-submission-main.js new file mode 100644 index 000000000..39de9d3a1 --- /dev/null +++ b/src/views/item-submission/js/item-submission-main.js @@ -0,0 +1,123 @@ +// Main imports +import Vue from 'vue'; +import Buefy from 'buefy'; +import VTooltip from 'v-tooltip'; +import cssVars from 'css-vars-ponyfill'; +import VueTheMask from 'vue-the-mask'; +import qs from 'qs'; + +// Metadata Types +import Text from '../../admin/components/metadata-types/text/Text.vue'; +import Textarea from '../../admin/components/metadata-types/textarea/Textarea.vue'; +import Selectbox from '../../admin/components/metadata-types/selectbox/Selectbox.vue'; +import Numeric from '../../admin/components/metadata-types/numeric/Numeric.vue'; +import Date from '../../admin/components/metadata-types/date/Date.vue'; +import Relationship from '../../admin/components/metadata-types/relationship/Relationship.vue'; +import Taxonomy from '../../admin/components/metadata-types/taxonomy/Taxonomy.vue'; +import Compound from '../../admin/components/metadata-types/compound/Compound.vue'; +import User from '../../admin/components/metadata-types/user/User.vue'; + +// Main components +import ItemSubmissionForm from '../pages/item-submission-form.vue'; +import ItemSubmission from '../item-submission.vue'; + +// Remaining imports +import HelpButton from '../../admin/components/other/help-button.vue'; +import store from '../../admin/js/store/store'; +import { I18NPlugin, UserPrefsPlugin, ConsolePlugin, StatusHelperPlugin, CommentsStatusHelperPlugin } from '../../admin/js/utilities'; + +document.addEventListener("DOMContentLoaded", () => { + + // Mount only if the div exists + if (document.getElementById('tainacan-item-submission-form')) { + + + // Display Icons only once everything is loaded + function listen(evnt, elem, func) { + if (elem.addEventListener) // W3C DOM + elem.addEventListener(evnt,func,false); + else if (elem.attachEvent) { // IE DOM + var r = elem.attachEvent("on"+evnt, func); + return r; + } else if (document.head) { + var iconHideStyle = document.createElement("style"); + iconHideStyle.innerText = '.tainacan-icon{ opacity: 1 !important; }'; + document.head.appendChild(iconHideStyle); + } else { + var iconHideStyle = document.createElement("style"); + iconHideStyle.innerText = '.tainacan-icon{ opacity: 1 !important; }'; + document.getElementsByTagName("head")[0].appendChild(iconHideStyle); + } + } + + /* Registers Extra Vue Plugins passed to the window.tainacan_extra_plugins */ + if (typeof window.tainacan_extra_plugins != "undefined") { + for (let [extraVuePluginName, extraVuePluginObject] of Object.entries(window.tainacan_extra_plugins)) + Vue.use(extraVuePluginObject); + } + + // Configure and Register Plugins + Vue.use(Buefy, { + defaultTooltipAnimated: true + }); + Vue.use(VTooltip); + Vue.use(I18NPlugin); + Vue.use(UserPrefsPlugin); + Vue.use(StatusHelperPlugin); + Vue.use(ConsolePlugin, {visual: false}); + Vue.use(VueTheMask); + Vue.use(CommentsStatusHelperPlugin); + + /* Registers Extra Vue Components passed to the window.tainacan_extra_components */ + if (typeof window.tainacan_extra_components != "undefined") { + for (let [extraVueComponentName, extraVueComponentObject] of Object.entries(window.tainacan_extra_components)) { + Vue.component(extraVueComponentName, extraVueComponentObject); + } + } + + /* Metadata */ + Vue.component('tainacan-text', Text); + Vue.component('tainacan-textarea', Textarea); + Vue.component('tainacan-selectbox', Selectbox); + Vue.component('tainacan-numeric', Numeric); + Vue.component('tainacan-date', Date); + Vue.component('tainacan-relationship', Relationship); + Vue.component('tainacan-taxonomy', Taxonomy); + Vue.component('tainacan-compound', Compound); + Vue.component('tainacan-user', User); + + /* Main page component */ + Vue.component('item-submission-form', ItemSubmissionForm); + Vue.component('item-submission', ItemSubmission); + + /* Others */ + Vue.component('help-button', HelpButton); + + const VueItemSubmission = new Vue({ + store, + data: {}, + beforeMount () {}, + methods: { + isParameterTrue(parameter) { + const value = this.$el.attributes[parameter].value; + return (value == true || value == 'true' || value == '1' || value == 1) ? true : false; + } + }, + render: h => h(ItemSubmission) + }); + + VueItemSubmission.$mount('#tainacan-item-submission-form'); + + listen("load", window, function() { + var iconsStyle = document.createElement("style"); + iconsStyle.setAttribute('type', 'text/css'); + iconsStyle.innerText = '.tainacan-icon{ opacity: 1 !important; }'; + document.head.appendChild(iconsStyle); + }); + + // Initialize Ponyfill for Custom CSS properties + cssVars({ + // Options... + }); + } +}); \ No newline at end of file diff --git a/src/views/item-submission/pages/item-submission-form.vue b/src/views/item-submission/pages/item-submission-form.vue new file mode 100644 index 000000000..aeb7bdc7d --- /dev/null +++ b/src/views/item-submission/pages/item-submission-form.vue @@ -0,0 +1,11 @@ + + + \ No newline at end of file diff --git a/src/views/item-submission/scss/item-submission-basics.sass b/src/views/item-submission/scss/item-submission-basics.sass new file mode 100644 index 000000000..aa303e24f --- /dev/null +++ b/src/views/item-submission/scss/item-submission-basics.sass @@ -0,0 +1,11 @@ +@import "../../../../node_modules/bulma/sass/utilities/_all.sass" +@import "../../../../node_modules/bulma/sass/base/helpers.sass" +@import "../../../../node_modules/bulma/sass/form/_all.sass" +@import "../../../../node_modules/bulma/sass/components/pagination.sass" +@import "../../../../node_modules/bulma/sass/elements/icon.sass" +@import "../../../../node_modules/bulma/sass/elements/tag.sass" +@import "../../../../node_modules/bulma/sass/components/tabs.sass" +@import "../../../../node_modules/bulma/sass/elements/button.sass" +@import "../../../../node_modules/bulma/sass/grid/columns.sass" +@import "../../../../node_modules/bulma/sass/components/dropdown.sass" +@import "../../../../node_modules/bulma/sass/components/modal.sass" \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index aae27a997..6cd281ee7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,6 +7,7 @@ module.exports = { entry: { admin: './src/views/admin/js/main.js', theme_search: './src/views/theme-search/js/theme-main.js', + item_submission: './src/views/item-submission/js/item-submission-main.js', roles: './src/views/roles/js/roles-main.js', block_terms_list: './src/views/gutenberg-blocks/tainacan-terms/terms-list/index.js', From 33d6eda1d7a4c41a5926eae35dcfaffab1cf937e Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 25 May 2020 17:09:37 -0300 Subject: [PATCH 02/71] Begins implementing theme side of item submission #388 --- src/views/item-submission/item-submission.vue | 4 +- .../js/item-submission-main.js | 10 +- .../pages/item-submission-form.vue | 703 +++++++++++++++++- 3 files changed, 711 insertions(+), 6 deletions(-) diff --git a/src/views/item-submission/item-submission.vue b/src/views/item-submission/item-submission.vue index c4fbb5b3b..807ec7543 100644 --- a/src/views/item-submission/item-submission.vue +++ b/src/views/item-submission/item-submission.vue @@ -1,5 +1,7 @@ \ No newline at end of file From e7c519f51b2f6f29913b128fa31815ac3653edcb Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 26 May 2020 17:47:00 -0300 Subject: [PATCH 03/71] Item edition form content on the item submission bundle. #388. --- .../components/edition/term-edition-form.vue | 1 + .../relationship/Relationship.vue | 6 +- src/views/admin/js/wp-media-frames.js | 4 +- src/views/item-submission/item-submission.vue | 116 +- .../js/item-submission-main.js | 5 +- .../pages/item-submission-form.vue | 1762 +++++++++++------ .../scss/item-submission-basics.sass | 1 + src/views/tainacan-admin-i18n.php | 1 + 8 files changed, 1237 insertions(+), 659 deletions(-) diff --git a/src/views/admin/components/edition/term-edition-form.vue b/src/views/admin/components/edition/term-edition-form.vue index c8d71233d..5c53f36e5 100644 --- a/src/views/admin/components/edition/term-edition-form.vue +++ b/src/views/admin/components/edition/term-edition-form.vue @@ -575,6 +575,7 @@ z-index: 99; text-align: center; color: var(--tainacan-info-color); + background-color: transparent; } #button-delete-header, #button-edit-header { diff --git a/src/views/admin/components/metadata-types/relationship/Relationship.vue b/src/views/admin/components/metadata-types/relationship/Relationship.vue index 89d543f04..89b3a3337 100644 --- a/src/views/admin/components/metadata-types/relationship/Relationship.vue +++ b/src/views/admin/components/metadata-types/relationship/Relationship.vue @@ -42,7 +42,7 @@ {{ $i18n.get('info_no_item_found') }} \ No newline at end of file + + + diff --git a/src/views/item-submission/scss/item-submission-basics.sass b/src/views/item-submission/scss/item-submission-basics.sass index aa303e24f..1323d6d72 100644 --- a/src/views/item-submission/scss/item-submission-basics.sass +++ b/src/views/item-submission/scss/item-submission-basics.sass @@ -4,6 +4,7 @@ @import "../../../../node_modules/bulma/sass/components/pagination.sass" @import "../../../../node_modules/bulma/sass/elements/icon.sass" @import "../../../../node_modules/bulma/sass/elements/tag.sass" +@import "../../../../node_modules/bulma/sass/elements/image.sass" @import "../../../../node_modules/bulma/sass/components/tabs.sass" @import "../../../../node_modules/bulma/sass/elements/button.sass" @import "../../../../node_modules/bulma/sass/grid/columns.sass" diff --git a/src/views/tainacan-admin-i18n.php b/src/views/tainacan-admin-i18n.php index ba988bcec..32d5deca6 100644 --- a/src/views/tainacan-admin-i18n.php +++ b/src/views/tainacan-admin-i18n.php @@ -465,6 +465,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_editing_capabilitiy' => __( 'Editing capabilitiy', 'tainacan' ), 'label_default_author_user' => __( 'Set the item author as default value', 'tainacan' ), 'label_crate_new_item' => __( 'Create new item', 'tainacan' ), + 'label_submit' => __( 'Submit', 'tainacan' ), // Instructions. More complex sentences to guide user and placeholders 'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ), From 30c78695caef6c179ebc4c72b0d922312fe27baa Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 27 May 2020 11:50:39 -0300 Subject: [PATCH 04/71] Enqueues necessary js for using wordpress media manager modals. --- src/classes/theme-helper/class-tainacan-theme-helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/classes/theme-helper/class-tainacan-theme-helper.php b/src/classes/theme-helper/class-tainacan-theme-helper.php index e5fac1159..323deb790 100644 --- a/src/classes/theme-helper/class-tainacan-theme-helper.php +++ b/src/classes/theme-helper/class-tainacan-theme-helper.php @@ -369,7 +369,9 @@ class Theme_Helper { } } - wp_enqueue_script('tainacan-item-submission', $TAINACAN_BASE_URL . '/assets/js/item_submission.js' , ['underscore', 'media-editor', 'media-views', 'customize-controls'] , TAINACAN_VERSION); + wp_enqueue_media(); + wp_enqueue_script('jcrop'); + wp_enqueue_script('tainacan-item-submission', $TAINACAN_BASE_URL . '/assets/js/item_submission.js' , ['underscore', 'jcrop', 'media-editor', 'media-views', 'customize-controls'] , TAINACAN_VERSION); wp_localize_script('tainacan-item-submission', 'tainacan_plugin', \Tainacan\Admin::get_instance()->get_admin_js_localization_params()); return "
"; From 82790948b95f5678661d581339afe9eba97fd7ff Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 27 May 2020 12:17:50 -0300 Subject: [PATCH 05/71] Updates form colors from css variables. --- .../admin/components/edition/item-edition-form.vue | 10 +++++----- src/views/admin/components/other/help-button.vue | 7 ++++--- src/views/admin/scss/_custom_variables.scss | 1 + .../item-submission/pages/item-submission-form.vue | 3 ++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/views/admin/components/edition/item-edition-form.vue b/src/views/admin/components/edition/item-edition-form.vue index 32fe074d0..70034cdbd 100644 --- a/src/views/admin/components/edition/item-edition-form.vue +++ b/src/views/admin/components/edition/item-edition-form.vue @@ -1517,7 +1517,7 @@ export default { } .status-tag { color: var(--tainacan-white); - background: var(--tainacan-turquoise5); + background: var(--tainacan-secondary); padding: 0.15em 0.5em; font-size: 0.75em; margin: 0 1em 0 0; @@ -1615,7 +1615,7 @@ export default { color: var(--tainacan-secondary); margin-bottom: 6px; &:hover { - background-color: var(--tainacan-turquoise2); + background-color: var(--tainacan-primary); cursor: pointer; } } @@ -1754,7 +1754,7 @@ export default { .sequence-progress { height: 5px; - background: var(--tainacan-turquoise5); + background: var(--tainacan-secondary); width: 0%; position: absolute; top: 0; @@ -1772,7 +1772,7 @@ export default { .sequence-button { background-color: transparent; - color: var(--tainacan-turquoise5); + color: var(--tainacan-secondary); border: none; .icon { @@ -1783,7 +1783,7 @@ export default { &:focus, &:active { background-color: transparent !important; - color: var(--tainacan-turquoise5) !important; + color: var(--tainacan-secondary) !important; } } } diff --git a/src/views/admin/components/other/help-button.vue b/src/views/admin/components/other/help-button.vue index 8abe2a0f9..65de698ef 100644 --- a/src/views/admin/components/other/help-button.vue +++ b/src/views/admin/components/other/help-button.vue @@ -49,8 +49,7 @@ export default { } .help-tooltip { z-index: 99999999999999999999; - color: var(--tainacan-turquoise5); - background-color: var(--tainacan-turquoise2); + background-color: var(--tainacan-primary); border: none; display: block; border-radius: 5px; @@ -70,6 +69,7 @@ export default { h5 { font-size: 0.875em; font-weight: bold; + color: var(--tainacan-secondary); } } @@ -82,6 +82,7 @@ export default { white-space: normal !important; overflow: visible !important; max-height: 100% !important; + color: var(--tainacan-secondary); } } @@ -95,7 +96,7 @@ export default { border-style: solid; } &:before { - border-color: var(--tainacan-turquoise2) transparent transparent transparent; + border-color: var(--tainacan-primary) transparent transparent transparent; border-right-width: 15px; border-top-width: 12px; border-left-width: 15px; diff --git a/src/views/admin/scss/_custom_variables.scss b/src/views/admin/scss/_custom_variables.scss index d8647ab5a..3637dbe49 100644 --- a/src/views/admin/scss/_custom_variables.scss +++ b/src/views/admin/scss/_custom_variables.scss @@ -80,6 +80,7 @@ #tainacan-admin-app, .theme-items-list, +.tainacan-item-submission-form, .tainacan-modal-content { // Some Bulma classes will work with SASS but not with CSS variables diff --git a/src/views/item-submission/pages/item-submission-form.vue b/src/views/item-submission/pages/item-submission-form.vue index d19caa70c..25a558b3f 100644 --- a/src/views/item-submission/pages/item-submission-form.vue +++ b/src/views/item-submission/pages/item-submission-form.vue @@ -1023,7 +1023,7 @@ export default { color: var(--tainacan-secondary); margin-bottom: 6px; &:hover { - background-color: var(--tainacan-turquoise2); + background-color: var(--tainacan-primary); cursor: pointer; } } @@ -1110,6 +1110,7 @@ export default { color: var(--tainacan-info-color); top: 70px; max-width: 90px; + background: transparent; } .thumbnail-buttons-row { From 6347a5e6acae9bd9dd15ec7a946d2e8cdf8fe6e0 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 27 May 2020 14:38:14 -0300 Subject: [PATCH 06/71] Creates Gutenberg block for item submission form. #388. --- .../class-tainacan-gutenberg-block.php | 38 +- .../tainacan-facets/faceted-search/index.js | 1 - .../item-submission-form/index.js | 397 ++++++++++++++++++ .../item-submission-form.scss | 315 ++++++++++++++ .../pages/item-submission-form.vue | 10 +- webpack.config.js | 4 +- 6 files changed, 756 insertions(+), 9 deletions(-) create mode 100644 src/views/gutenberg-blocks/tainacan-items/item-submission-form/index.js create mode 100644 src/views/gutenberg-blocks/tainacan-items/item-submission-form/item-submission-form.scss diff --git a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php index 8908bb5c3..4c6ae4442 100644 --- a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php +++ b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php @@ -26,6 +26,7 @@ function tainacan_blocks_add_gutenberg_blocks_actions() { add_action('init', 'tainacan_blocks_register_tainacan_collections_list'); add_action('init', 'tainacan_blocks_register_tainacan_carousel_collections_list'); add_action('init', 'tainacan_blocks_register_tainacan_facets_list'); + add_action('init', 'tainacan_blocks_register_tainacan_item_submission_form'); add_action('init', 'tainacan_blocks_add_plugin_settings'); @@ -152,6 +153,38 @@ function tainacan_blocks_register_tainacan_dynamic_items_list(){ } } +function tainacan_blocks_register_tainacan_item_submission_form(){ + global $TAINACAN_BASE_URL; + global $TAINACAN_VERSION; + + wp_register_script( + 'tainacan-item-submission', + $TAINACAN_BASE_URL . '/assets/js/item_submission.js', + ['underscore', 'jcrop', 'media-editor', 'media-views', 'customize-controls'], + TAINACAN_VERSION + ); + + wp_register_script( + 'item-submission-form', + $TAINACAN_BASE_URL . '/assets/js/block_item_submission_form.js', + array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor') + ); + + wp_register_style( + 'item-submission-form', + $TAINACAN_BASE_URL . '/assets/css/tainacan-gutenberg-block-item-submission-form.css', + array('wp-edit-blocks', 'tainacan-blocks-common-styles') + ); + + if (function_exists('register_block_type')) { + register_block_type( 'tainacan/item-submission-form', array( + 'editor_script' => 'item-submission-form', + 'style' => 'item-submission-form', + 'script' => 'tainacan-item-submission' + ) ); + } +} + function tainacan_blocks_register_tainacan_faceted_search(){ global $TAINACAN_BASE_URL; global $TAINACAN_VERSION; @@ -356,8 +389,11 @@ function tainacan_blocks_add_plugin_settings() { wp_localize_script( 'carousel-collections-list', 'tainacan_blocks', $settings ); wp_localize_script( 'facets-list', 'tainacan_blocks', $settings ); - // The facet facteded search block uses a different settings object, the same used on the theme items list + // The faceded search block uses a different settings object, the same used on the theme items list wp_localize_script( 'tainacan-search', 'tainacan_plugin', \Tainacan\Admin::get_instance()->get_admin_js_localization_params() ); + + // The item submission search block uses a different settings object, the same used on the item submission component + wp_localize_script( 'tainacan-item-submission', 'tainacan_plugin', \Tainacan\Admin::get_instance()->get_admin_js_localization_params() ); } function tainacan_blocks_get_common_styles() { diff --git a/src/views/gutenberg-blocks/tainacan-facets/faceted-search/index.js b/src/views/gutenberg-blocks/tainacan-facets/faceted-search/index.js index dd41a058d..a2e842ed5 100644 --- a/src/views/gutenberg-blocks/tainacan-facets/faceted-search/index.js +++ b/src/views/gutenberg-blocks/tainacan-facets/faceted-search/index.js @@ -229,7 +229,6 @@ registerBlockType('tainacan/faceted-search', { showInlineViewModeOptions, showFullscreenWithViewModes, listType, - isCollectionModalOpen, isTermModalOpen, backgroundColor, baseFontSize, diff --git a/src/views/gutenberg-blocks/tainacan-items/item-submission-form/index.js b/src/views/gutenberg-blocks/tainacan-items/item-submission-form/index.js new file mode 100644 index 000000000..d785cddf8 --- /dev/null +++ b/src/views/gutenberg-blocks/tainacan-items/item-submission-form/index.js @@ -0,0 +1,397 @@ +const { registerBlockType } = wp.blocks; + +const { __ } = wp.i18n; + +const { Button, ColorPicker, BaseControl, CheckboxControl, RangeControl, FontSizePicker, HorizontalRule, SelectControl, ToggleControl, Placeholder, PanelBody } = wp.components; + +const { InspectorControls } = wp.editor; + +import CollectionModal from '../../tainacan-facets/faceted-search/collection-modal.js'; + +registerBlockType('tainacan/item-submission-form', { + title: __('Tainacan Item Submission Form', 'tainacan'), + icon: + + + + + , + category: 'tainacan-blocks', + keywords: [ __( 'item', 'tainacan' ), __( 'submission', 'tainacan' ), __( 'form', 'tainacan' ) ], + description: __('A public item submission form, to allow visitors to create items drafts.', 'tainacan'), + attributes: { + collectionId: { + type: String, + default: undefined + }, + isCollectionModalOpen: { + type: Boolean, + default: false + }, + backgroundColor: { + type: String, + default: '#ffffff' + }, + baseFontSize: { + type: Number, + default: 16 + }, + inputColor: { + type: String, + default: '#1d1d1d' + }, + inputBackgroundColor: { + type: String, + default: '#ffffff' + }, + inputBorderColor: { + type: String, + default: '#dbdbdb' + }, + labelColor: { + type: String, + default: '#454647' + }, + infoColor: { + type: String, + default: '#555758' + }, + primaryColor: { + type: String, + default: '#d9eced' + }, + secondaryColor: { + type: String, + default: '#298596' + } + }, + supports: { + align: ['full', 'wide'], + html: true, + multiple: false + }, + edit({ attributes, setAttributes, className, isSelected, clientId }){ + let { + collectionId, + isCollectionModalOpen, + baseFontSize, + backgroundColor, + inputColor, + inputBackgroundColor, + inputBorderColor, + labelColor, + infoColor, + primaryColor, + secondaryColor + } = attributes; + + const fontSizes = [ + { + name: __( 'Tiny', 'tainacan' ), + slug: 'tiny', + size: 12, + }, + { + name: __( 'Small', 'tainacan' ), + slug: 'small', + size: 14, + }, + { + name: __( 'Normal', 'tainacan' ), + slug: 'normal', + size: 16, + }, + { + name: __( 'Big', 'tainacan' ), + slug: 'big', + size: 18, + }, + { + name: __( 'Huge', 'tainacan' ), + slug: 'huge', + size: 20, + }, + ]; + + function openCollectionModal() { + isCollectionModalOpen = true; + setAttributes( { + isCollectionModalOpen: isCollectionModalOpen + } ); + } + + return ( +
+ +
+ + + { + setAttributes( { baseFontSize: newFontSize } ); + } } + /> + + + { + backgroundColor = colorValue.hex; + setAttributes({ backgroundColor: backgroundColor }); + }} + disableAlpha + /> + + + + { + secondaryColor = colorValue.hex; + setAttributes({ secondaryColor: secondaryColor }); + }} + disableAlpha + /> + + + + { + primaryColor = colorValue.hex; + setAttributes({ primaryColor: primaryColor }); + }} + disableAlpha + /> + + + + { + inputBackgroundColor = colorValue.hex; + setAttributes({ inputBackgroundColor: inputBackgroundColor }); + }} + disableAlpha + /> + + + + { + inputColor = colorValue.hex; + setAttributes({ inputColor: inputColor }); + }} + disableAlpha + /> + + + + { + inputBorderColor = colorValue.hex; + setAttributes({ inputBorderColor: inputBorderColor }); + }} + disableAlpha + /> + + + + { + labelColor = colorValue.hex; + setAttributes({ labelColor: labelColor }); + }} + disableAlpha + /> + + + { + infoColor = colorValue.hex; + setAttributes({ infoColor: infoColor }); + }} + disableAlpha + /> + + + +
+ + { (isSelected && collectionId != undefined ) ? + ( +
+
+

+ + + + + + {__('Submit items to colection.', 'tainacan') } +   + +

+
+
+ ) : null + } + + { ( collectionId == undefined ) ? ( + + )}> +

+ + + + + + {__('Show an item submission form.', 'tainacan')} +

+ + +
+ ) : ( + +
+
+ { __('Warning: this is just a demonstration. To see the submission form, either preview or publish your post.', 'tainacan') } +
+
+
+
+ + ) + } + + { isCollectionModalOpen ? + { + collectionId = collectionId; + setAttributes({ + collectionId: collectionId, + isCollectionModalOpen: false + }); + }} + onCancelSelection={ () => setAttributes({ isCollectionModalOpen: false }) }/> + : null + } + +
+ ); + }, + save({ attributes, className }){ + const { + collectionId, + backgroundColor, + baseFontSize, + inputColor, + inputBackgroundColor, + inputBorderColor, + labelColor, + infoColor, + primaryColor, + secondaryColor + } = attributes; + + return
+
+
+
+ } +}); \ No newline at end of file diff --git a/src/views/gutenberg-blocks/tainacan-items/item-submission-form/item-submission-form.scss b/src/views/gutenberg-blocks/tainacan-items/item-submission-form/item-submission-form.scss new file mode 100644 index 000000000..5730cee37 --- /dev/null +++ b/src/views/gutenberg-blocks/tainacan-items/item-submission-form/item-submission-form.scss @@ -0,0 +1,315 @@ +@import '../../gutenberg-blocks-variables.scss'; + +.wp-block-tainacan-faceted-search { + margin: 2em auto; + + // Spinner + .spinner-container { + min-height: 56px; + padding: 1em; + display: flex; + justify-content: center; + align-items: center; + color: var(--tainacan-block-gray4, $gray4); + } + + .preview-warning { + width: 100%; + font-size: 0.875em; + font-style: italic; + color: var(--tainacan-block-gray4, $gray4); + text-align: center; + margin: 4px auto; + } + .items-list-placeholder { + font-size: 1.125em; + min-height: 500px; + width: 100%; + display: flex; + flex-wrap: nowrap; + flex-direction: column; + border-radius: 4px; + border: 1px solid rgba(200,200,200, 0.3); + overflow: hidden; + + .search-control, + .filters, + .items, + .pagination { + background-color: var(--tainacan-background-color, white); + border: 1px solid rgba(200,200,200, 0.3); + padding: 12px; + margin: 0px; + border-radius: 1px; + } + .search-control { + flex: 0 0 15%; + display: flex; + justify-content: space-between; + align-items: center; + } + .below-search-control { + position: relative; + display: flex; + flex-wrap: nowrap; + flex-direction: row; + flex: 1 0 auto; + + .filters { + flex: 0 1 var(--tainacan-filter-menu-width-theme, 20%); + display: flex; + flex-direction: column; + padding: 40px 20px 60px 15px; + + .fake-filter { + display: flex; + flex-direction: column; + width: 80%; + margin: 5% 12%; + .fake-text { + margin: 4px 0; + width: 35%; + background-color: var(--tainacan-label-color, rgba(200,200,200, 0.2)); + } + .fake-searchbar { + width: 100%; + } + .fake-checkbox-list { + &>div { + width: 100%; + display: flex; + align-items: center; + + &:nth-child(odd) .fake-text { + width: 60%; + } + } + .fake-checkbox { + display: block; + width: 0.4em; + height: 0.4em; + min-width: 0.4em; + min-height: 0.4em; + max-width: 0.4em; + max-height: 0.4em; + border: 2px solid var(--tainacan-input-border-color, rgba(200,200,200, 0.3)); + border-radius: 2px; + margin-right: 4px; + } + .fake-text { + background-color: var(--tainacan-input-color, rgba(200,200,200, 0.3)); + width: 54%; + } + .fake-link { + width: 25%; + margin: 3px; + } + } + } + .fake-filters-heading { + position: relative; + top: -1.3em; + left: -0.3em; + background-color: var(--tainacan-heading-color, rgba(200,200,200, 0.3)); + height: 0.2em; + width: 28%; + border-radius: 2px; + } + } + .aside-filters { + display: flex; + flex-wrap: nowrap; + flex-direction: column; + flex: 1 1 auto; + + .items { + flex: 1 0 auto; + display: flex; + flex-wrap: wrap; + justify-content: space-evenly; + align-content: flex-start; + } + + .pagination { + flex: 0 1 5%; + display: flex; + justify-content: space-between; + align-items: center; + + &>.fake-text { + background-color: var(--tainacan-info-color, rgba(200,200,200, 0.2)); + } + } + } + } + .fake-text { + background-color: var(--tainacan-input-color, rgba(200,200,200, 0.3)); + height: 0.2em; + width: 24%; + min-width: 1.25em; + border-radius: 2px; + } + .fake-link { + background-color: var(--tainacan-secondary, rgba(200,200,200, 0.3)); + height: 0.2em; + width: 10%; + border-radius: 2px; + } + .fake-icon { + background-color: var(--tainacan-info-color, rgba(200,200,200, 0.3)); + height: 0.3em; + width: 0.3em; + min-height: 0.3em; + min-width: 0.3em; + max-height: 0.3em; + max-width: 0.3em; + border-radius: 5px; + } + .fake-tooltip { + background-color: var(--tainacan-primary, rgba(200,200,200, 0.1)); + position: absolute; + height: 0.75em; + width: 4em; + border-radius: 2px; + display: flex; + justify-content: center; + align-items: center; + top: -0.75em; + left: 1em; + + .fake-link { + width: 100%; + margin: 0 4px 0 8px; + } + + &:before { + content: ""; + display: block; + position: absolute; + left: 12px; + width: 0; + height: 0; + border-style: solid; + } + &:before { + border-color: var(--tainacan-primary) transparent transparent transparent; + border-right-width: 7px; + border-top-width: 6px; + border-left-width: 7px; + bottom: -8px; + } + } + .fake-searchbar { + background-color: var(--tainacan-input-background-color, rgba(200,200,200, 0.3)); + height: 0.8em; + width: 18%; + border: 2px solid var(--tainacan-input-border-color, rgba(200,200,200, 0.3)); + border-radius: 3px; + + .fake-advanced-searchbar { + display: block; + background-color: var(--tainacan-secondary, rgba(200,200,200, 0.3)); + height: 0.2em; + border-radius: 3px; + width: 70%; + position: relative; + bottom: -0.85em; + } + } + .fake-hide-button { + display: flex; + justify-content: center; + align-items: center; + background-color: var(--tainacan-primary, rgba(200,200,200, 0.1)); + height: 0.9em; + width: 0.9em; + font-size: 0.75em; + border-radius: 3px; + position: absolute; + left: 0px; + top: 42px; + + .fake-icon { + background-color: var(--tainacan-secondary, rgba(200,200,200, 0.3)); + } + } + .fake-button { + background-color: var(--tainacan-background-color, white); + height: 0.8em; + width: 10%; + max-width: 3.25em; + min-width: 1em; + margin-left: 6px; + border-radius: 3px; + display: flex; + align-items: center; + margin-right: auto; + + .fake-text { + background-color: var(--tainacan-input-color, rgba(200,200,200, 0.3)); + width: 95%; + margin: 0 2px; + } + .fake-icon { + flex: 1 0 auto; + margin: 0 2px; + } + } + .fake-buttons-group { + flex: 0 0 15%; + display: flex; + justify-content: space-evenly; + } + .fake-item { + background-color: var(--tainacan-item-background-color, white); + flex: 1 0 180px; + margin: 12px; + height: 78px; + + &.fake-item-hovered, + &:hover { + background-color: var(--tainacan-item-hover-background-color, rgba(200,200,200, 0.2)); + .fake-item-header { + background-color: var(--tainacan-item-heading-hover-background-color, rgba(200,200,200, 0.3)); + } + } + .fake-item-header { + height: 20px; + width: 100%; + position: relative; + top: 0; + display: flex; + align-items: center; + padding: 6px; + + .fake-text { + background-color: var(--tainacan-heading-color, rgba(200,200,200, 0.35)); + } + } + .fake-item-thumb { + background-size: cover; + background-color: var(--tainacan-input-border-color, rgba(200,200,200, 0.1)); + height: 58px; + width: 58px; + float: left; + } + .fake-item-description { + background-color: var(--tainacan-info-color, rgba(200,200,200, 0.15)); + height: 0.18em; + width: 60%; + border-radius: 2px; + margin: 8px 6px 2px 6px; + position: relative; + left: 62px; + + &:nth-child(odd) { + width: 50%; + } + } + } + } + + .theme-items-list { + max-width: 100% !important; + } +} diff --git a/src/views/item-submission/pages/item-submission-form.vue b/src/views/item-submission/pages/item-submission-form.vue index 25a558b3f..c564b66eb 100644 --- a/src/views/item-submission/pages/item-submission-form.vue +++ b/src/views/item-submission/pages/item-submission-form.vue @@ -946,13 +946,12 @@ export default { diff --git a/src/views/admin/js/store/modules/item/actions.js b/src/views/admin/js/store/modules/item/actions.js index c3e827449..e12d31a72 100644 --- a/src/views/admin/js/store/modules/item/actions.js +++ b/src/views/admin/js/store/modules/item/actions.js @@ -323,12 +323,14 @@ export const deleteGroupFromItemSubmissionMetadatum = ({ commit }, { metadatum_i export const submitItemSubmission = ({ commit }, { itemSubmission, itemSubmissionMetadata }) => { return new Promise((resolve, reject) => { - for (let key of Object.keys(itemSubmission)) { + let item = JSON.parse(JSON.stringify(itemSubmission)); // Use a copy as the next request will need document, attchment and thumbnail + + for (let key of Object.keys(item)) { if (['document', 'attachments', 'thumbnail'].includes(key) ) - delete itemSubmission[key]; + delete item[key]; } - axios.tainacan.post('/collection/' + itemSubmission.collection_id + '/items/submission', {...itemSubmission, metadata: itemSubmissionMetadata } ) + axios.tainacan.post('/collection/' + itemSubmission.collection_id + '/items/submission', {...item, metadata: itemSubmissionMetadata } ) .then( res => { resolve( res.data.id ); }).catch( error => { @@ -345,14 +347,14 @@ export const finishItemSubmission = ({ commit }, { itemSubmission, fakeItemId }) let config = { headers: { 'content-type': 'multipart/form-data' } } - + console.log(itemSubmission) const formData = new FormData(); for (let key of Object.keys(itemSubmission)) { if (['document', 'attachments', 'thumbnail'].includes(key) ) formData.append(key, itemSubmission[key]); } - + console.log(formData) axios.tainacan.post('/collection/' + itemSubmission.collection_id + '/items/submission/' + fakeItemId + '/finish', formData, config ) .then( res => { resolve( res.data ); From d3e7f788d6e32dfae22f42c49fa5ca29fdc25e67 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 25 Sep 2020 11:54:47 -0300 Subject: [PATCH 43/71] Fixes attachment array submission --- src/views/admin/js/store/modules/item/actions.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/views/admin/js/store/modules/item/actions.js b/src/views/admin/js/store/modules/item/actions.js index e12d31a72..128e8d876 100644 --- a/src/views/admin/js/store/modules/item/actions.js +++ b/src/views/admin/js/store/modules/item/actions.js @@ -351,8 +351,12 @@ export const finishItemSubmission = ({ commit }, { itemSubmission, fakeItemId }) const formData = new FormData(); for (let key of Object.keys(itemSubmission)) { - if (['document', 'attachments', 'thumbnail'].includes(key) ) + if (['document','thumbnail'].includes(key) ) formData.append(key, itemSubmission[key]); + else if (key === 'attachments') { + for (let i = 0; i < itemSubmission[key].length; i++) + formData.append(key + '[' + i + ']', itemSubmission[key][i]); + } } console.log(formData) axios.tainacan.post('/collection/' + itemSubmission.collection_id + '/items/submission/' + fakeItemId + '/finish', formData, config ) From eb125b1c534c6c86725cd932493616bbb9862f00 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 25 Sep 2020 12:02:29 -0300 Subject: [PATCH 44/71] hack on get_submission_anonymous_user #388 --- src/classes/entities/class-tainacan-collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index 63098306f..4c28bd6b7 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -552,7 +552,7 @@ class Collection extends Entity { * @return bool */ function get_submission_anonymous_user() { - return $this->get_mapped_property( 'submission_anonymous_user' ) != 'false'; + return true || $this->get_mapped_property( 'submission_anonymous_user' ) != 'false'; } /** From 67ddf74ffe140de321cb6268294c8ab03c0db03d Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 25 Sep 2020 14:12:54 -0300 Subject: [PATCH 45/71] New fields on collection edition form and removes hack on collection validation. #388 --- src/classes/entities/class-tainacan-collection.php | 2 +- src/views/admin/components/edition/collection-edition-form.vue | 3 +++ src/views/admin/js/store/modules/item/actions.js | 2 -- src/views/admin/js/store/modules/item/mutations.js | 1 - 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index 4c28bd6b7..63098306f 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -552,7 +552,7 @@ class Collection extends Entity { * @return bool */ function get_submission_anonymous_user() { - return true || $this->get_mapped_property( 'submission_anonymous_user' ) != 'false'; + return $this->get_mapped_property( 'submission_anonymous_user' ) != 'false'; } /** diff --git a/src/views/admin/components/edition/collection-edition-form.vue b/src/views/admin/components/edition/collection-edition-form.vue index 4145eeb71..b6ef977ca 100644 --- a/src/views/admin/components/edition/collection-edition-form.vue +++ b/src/views/admin/components/edition/collection-edition-form.vue @@ -816,6 +816,9 @@ export default { parent: this.form.parent, enabled_view_modes: this.form.enabled_view_modes, default_view_mode: this.form.default_view_mode, + allows_submission: this.form.allows_submission, + submission_anonymous_user: this.form.submission_anonymous_user, + submission_default_status: this.form.submission_default_status, allow_comments: this.form.allow_comments, hide_items_thumbnail_on_lists: this.form.hide_items_thumbnail_on_lists }; diff --git a/src/views/admin/js/store/modules/item/actions.js b/src/views/admin/js/store/modules/item/actions.js index 128e8d876..1401f76c3 100644 --- a/src/views/admin/js/store/modules/item/actions.js +++ b/src/views/admin/js/store/modules/item/actions.js @@ -347,7 +347,6 @@ export const finishItemSubmission = ({ commit }, { itemSubmission, fakeItemId }) let config = { headers: { 'content-type': 'multipart/form-data' } } - console.log(itemSubmission) const formData = new FormData(); for (let key of Object.keys(itemSubmission)) { @@ -358,7 +357,6 @@ export const finishItemSubmission = ({ commit }, { itemSubmission, fakeItemId }) formData.append(key + '[' + i + ']', itemSubmission[key][i]); } } - console.log(formData) axios.tainacan.post('/collection/' + itemSubmission.collection_id + '/items/submission/' + fakeItemId + '/finish', formData, config ) .then( res => { resolve( res.data ); diff --git a/src/views/admin/js/store/modules/item/mutations.js b/src/views/admin/js/store/modules/item/mutations.js index c7653cf1c..80a292aee 100644 --- a/src/views/admin/js/store/modules/item/mutations.js +++ b/src/views/admin/js/store/modules/item/mutations.js @@ -208,6 +208,5 @@ export const deleteGroupFromItemSubmissionMetadatum = (state, { metadatum_id, ch existingMetadatum.value = existingMetadatumValue; Vue.set(state.itemSubmissionMetadata, existingMetadatumIndex, existingMetadatum); } - console.log('store', JSON.parse(JSON.stringify(state.itemSubmissionMetadata[existingMetadatumIndex].value))) } } From 024cda5236abc85b02ed41c49113a8c81e9d9f10 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 25 Sep 2020 14:30:20 -0300 Subject: [PATCH 46/71] Fixes reactivity of toggle allows_submission in collection edition form. #388 --- .../admin/components/edition/collection-edition-form.vue | 4 +++- .../tainacan-items/item-submission-form/index.js | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/views/admin/components/edition/collection-edition-form.vue b/src/views/admin/components/edition/collection-edition-form.vue index b6ef977ca..ae8044131 100644 --- a/src/views/admin/components/edition/collection-edition-form.vue +++ b/src/views/admin/components/edition/collection-edition-form.vue @@ -473,7 +473,6 @@ :title="$i18n.getHelperTitle('collections', 'allows_submission')" :message="$i18n.getHelperMessage('collections', 'allows_submission')"/> -
{ collectionId = collectionId; From e7006be920ddff886b31a0578eb319709a332d78 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 25 Sep 2020 15:30:10 -0300 Subject: [PATCH 47/71] submission create thumbnail and remove attachments on erro #388 --- .../class-tainacan-rest-items-controller.php | 43 +++++++++++++++---- .../entities/class-tainacan-collection.php | 2 +- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php index 174cd664e..578f2a6ff 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php @@ -987,14 +987,8 @@ class REST_Items_Controller extends REST_Controller { $TainacanMedia = \Tainacan\Media::get_instance(); $files = $request->get_file_params(); - if( isset($files['thumbnail']) && !is_array($files['thumbnail']['tmp_name']) == 1 && $files['thumbnail']['size'] > 0 ) { - $tmp_file_name = sys_get_temp_dir() . DIRECTORY_SEPARATOR . \hexdec(\uniqid()) . '_' . $files['thumbnail']['name']; - move_uploaded_file($files['thumbnail']['tmp_name'], $tmp_file_name); - $thumbnail_id = $TainacanMedia->insert_attachment_from_file($tmp_file_name); - $item->set__thumbnail_id($thumbnail_id); - unlink($tmp_file_name); - } + $insert_attachments = []; if( isset($files['document']) && !is_array($files['document']['tmp_name']) == 1 && $files['document']['size'] > 0 ) { $tmp_file_name = sys_get_temp_dir() . DIRECTORY_SEPARATOR . \hexdec(\uniqid()) . '_' . $files['document']['name']; move_uploaded_file($files['document']['tmp_name'], $tmp_file_name); @@ -1002,6 +996,30 @@ class REST_Items_Controller extends REST_Controller { $item->set_document_type('attachment'); $item->set_document($document_id); unlink($tmp_file_name); + $insert_attachments[] = $document_id; + } + + if( isset($files['thumbnail']) && !is_array($files['thumbnail']['tmp_name']) == 1 && $files['thumbnail']['size'] > 0 ) { + $tmp_file_name = sys_get_temp_dir() . DIRECTORY_SEPARATOR . \hexdec(\uniqid()) . '_' . $files['thumbnail']['name']; + move_uploaded_file($files['thumbnail']['tmp_name'], $tmp_file_name); + $thumbnail_id = $TainacanMedia->insert_attachment_from_file($tmp_file_name); + unlink($tmp_file_name); + $item->set__thumbnail_id($thumbnail_id); + $insert_attachments[] = $thumbnail_id; + } else { + $thumbnail_id = $this->items_repository->get_thumbnail_id_from_document($item); + if (!is_null($thumbnail_id)) { + set_post_thumbnail( $item_id, (int) $thumbnail_id ); + $insert_attachments[] = $thumbnail_id; + } + } + + if ($document_id === false || $thumbnail_id === false) { + if($document_id !== false) wp_delete_attachment($document_id, true); + if($thumbnail_id !== false) wp_delete_attachment($thumbnail_id, true); + return new \WP_REST_Response([ + 'error_message' => __('error on create document or thumbnail.', 'tainacan'), + ], 400); } if( isset($files['attachments']) ) { @@ -1010,8 +1028,17 @@ class REST_Items_Controller extends REST_Controller { for ($i = 0; $i < count($attachments); $i++) { $tmp_file_name = sys_get_temp_dir() . DIRECTORY_SEPARATOR . \hexdec(\uniqid()) . '_' . $attachments_name[$i]; move_uploaded_file($attachments[$i], $tmp_file_name); - $TainacanMedia->insert_attachment_from_file($tmp_file_name, $item_id); + $attachment_id = $TainacanMedia->insert_attachment_from_file($tmp_file_name, $item_id); unlink($tmp_file_name); + if($attachment_id === false) { + foreach($insert_attachments as $remove_id) { + wp_delete_attachment($remove_id, true); + } + return new \WP_REST_Response([ + 'error_message' => __('error on create attachments.', 'tainacan'), + ], 400); + } + $insert_attachments[] = $attachment_id; } } diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index 63098306f..bc53ba9f0 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -570,7 +570,7 @@ class Collection extends Entity { * @return bool */ function get_allows_submission() { - return true || $this->get_mapped_property( 'allows_submission' ) != 'false'; + return $this->get_mapped_property( 'allows_submission' ) != 'false'; } /** From a33e5ba44ed47cfa817aa01cc0e0fc1cc2c8e116 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 25 Sep 2020 16:06:54 -0300 Subject: [PATCH 48/71] Several style adjustments to the form. #388 --- .../metadata-types/compound/Compound.vue | 3 +- .../relationship/Relationship.vue | 2 +- .../metadata-types/taxonomy/Taxonomy.vue | 2 +- .../other/checkbox-radio-filter-input.vue | 4 + .../components/other/checkbox-radio-input.vue | 4 + .../other/checkbox-radio-metadata-input.vue | 6 +- .../admin/components/other/help-button.vue | 1 + .../faceted-search/collection-modal.js | 24 +++- .../pages/item-submission-form.vue | 113 +++++++----------- src/views/tainacan-admin-i18n.php | 2 +- 10 files changed, 86 insertions(+), 75 deletions(-) diff --git a/src/views/admin/components/metadata-types/compound/Compound.vue b/src/views/admin/components/metadata-types/compound/Compound.vue index e683a2ed7..14ee31a78 100644 --- a/src/views/admin/components/metadata-types/compound/Compound.vue +++ b/src/views/admin/components/metadata-types/compound/Compound.vue @@ -347,7 +347,8 @@ height: 1px; } .empty-label { - color: var(--tainacan-gray3); + color: var(--tainacan-gray4); + font-size: 0.875em; font-style: italic; } } diff --git a/src/views/admin/components/metadata-types/relationship/Relationship.vue b/src/views/admin/components/metadata-types/relationship/Relationship.vue index dde9452f6..aefa7da23 100644 --- a/src/views/admin/components/metadata-types/relationship/Relationship.vue +++ b/src/views/admin/components/metadata-types/relationship/Relationship.vue @@ -50,7 +50,7 @@ diff --git a/src/views/admin/components/metadata-types/taxonomy/Taxonomy.vue b/src/views/admin/components/metadata-types/taxonomy/Taxonomy.vue index feb2d8017..a9272af77 100644 --- a/src/views/admin/components/metadata-types/taxonomy/Taxonomy.vue +++ b/src/views/admin/components/metadata-types/taxonomy/Taxonomy.vue @@ -95,7 +95,7 @@ this.taxonomyId = metadata_type_options.taxonomy_id; this.taxonomy = metadata_type_options.taxonomy; - if (metadata_type_options && metadata_type_options.allow_new_terms && this.itemMetadatum.item) + if (this.itemMetadatum.item && this.itemMetadatum.item.id && metadata_type_options && metadata_type_options.allow_new_terms && this.itemMetadatum.item) this.allowNew = metadata_type_options.allow_new_terms == 'yes'; this.getTermsId(); diff --git a/src/views/admin/components/other/checkbox-radio-filter-input.vue b/src/views/admin/components/other/checkbox-radio-filter-input.vue index e3ea543ef..737bcac7e 100644 --- a/src/views/admin/components/other/checkbox-radio-filter-input.vue +++ b/src/views/admin/components/other/checkbox-radio-filter-input.vue @@ -1096,6 +1096,10 @@ .tags.is-small { font-size: 0.875em; } + + section p { + font-size: 0.875em; + } } .tainacan-modal-checkbox-search-results-body { diff --git a/src/views/admin/components/other/checkbox-radio-input.vue b/src/views/admin/components/other/checkbox-radio-input.vue index 3a17bbed0..387f1eaca 100644 --- a/src/views/admin/components/other/checkbox-radio-input.vue +++ b/src/views/admin/components/other/checkbox-radio-input.vue @@ -1166,6 +1166,10 @@ .tags.is-small { font-size: 0.875em; } + + section p { + font-size: 0.875em; + } } .tainacan-modal-checkbox-search-results-body { diff --git a/src/views/admin/components/other/checkbox-radio-metadata-input.vue b/src/views/admin/components/other/checkbox-radio-metadata-input.vue index 057b995f0..e656a615f 100644 --- a/src/views/admin/components/other/checkbox-radio-metadata-input.vue +++ b/src/views/admin/components/other/checkbox-radio-metadata-input.vue @@ -733,7 +733,7 @@ margin-bottom: 0 !important; ul { - padding: none; + padding: 0; } } .hidden-tabs-section /deep/ .tabs { @@ -1017,6 +1017,10 @@ .tags.is-small { font-size: 0.875em; } + + section p { + font-size: 0.875em; + } } .tainacan-modal-checkbox-search-results-body { diff --git a/src/views/admin/components/other/help-button.vue b/src/views/admin/components/other/help-button.vue index 10d34948d..ae36f4a65 100644 --- a/src/views/admin/components/other/help-button.vue +++ b/src/views/admin/components/other/help-button.vue @@ -70,6 +70,7 @@ export default { font-size: 0.875em; font-weight: bold; color: var(--tainacan-secondary); + margin-bottom: 0; } } diff --git a/src/views/gutenberg-blocks/tainacan-facets/faceted-search/collection-modal.js b/src/views/gutenberg-blocks/tainacan-facets/faceted-search/collection-modal.js index de58d5834..5bc527d92 100644 --- a/src/views/gutenberg-blocks/tainacan-facets/faceted-search/collection-modal.js +++ b/src/views/gutenberg-blocks/tainacan-facets/faceted-search/collection-modal.js @@ -1,5 +1,6 @@ import tainacan from '../../js/axios.js'; import axios from 'axios'; +import qs from 'qs'; const { __ } = wp.i18n; @@ -63,7 +64,16 @@ export default class CollectionModal extends React.Component { if (this.state.collectionPage <= 1) someModalCollections = []; - let endpoint = '/collections/?perpage=' + this.state.collectionsPerPage + '&paged=' + this.state.collectionPage; + let query = { + perpage: this.state.collectionsPerPage, + paged: this.state.collectionPage + } + + if (this.props.filterOptionsBy && Object.keys(this.props.filterOptionsBy).length !== 0) + query = {...query, meta_query: this.props.filterOptionsBy} + + + let endpoint = '/collections/?' + qs.stringify(query); if (this.state.collectionOrderBy == 'date') endpoint += '&orderby=date&order=asc'; @@ -125,7 +135,17 @@ export default class CollectionModal extends React.Component { collections: [] }); - let endpoint = '/collections/?perpage=' + this.state.collectionsPerPage; + let query = { + perpage: this.state.collectionsPerPage, + paged: this.state.collectionPage + } + + if (this.props.filterOptionsBy && Object.keys(this.props.filterOptionsBy).length !== 0) + query = {...query, meta_query: this.props.filterOptionsBy} + + + let endpoint = '/collections/?' + qs.stringify(query); + if (name != undefined && name != '') endpoint += '&search=' + name; diff --git a/src/views/item-submission/pages/item-submission-form.vue b/src/views/item-submission/pages/item-submission-form.vue index be6a93d04..68fe702bd 100644 --- a/src/views/item-submission/pages/item-submission-form.vue +++ b/src/views/item-submission/pages/item-submission-form.vue @@ -31,11 +31,10 @@ :message="$i18n.getHelperMessage('items', 'document')"/>
-
-
- +
+ @@ -128,8 +127,8 @@ :message="$i18n.getHelperMessage('items', '_thumbnail_id')"/>
-

{{ showThumbnailInput ? $i18n.get('info_thumbnail_custom') : $i18n.get('info_thumbnail_default_from_document') }}

-
+
+

{{ showThumbnailInput ? $i18n.get('info_thumbnail_custom') : $i18n.get('info_thumbnail_default_from_document') }}

@@ -195,8 +195,11 @@
-
+
@@ -247,7 +250,7 @@ :title="$i18n.getHelperTitle('items', 'comment_status')" :message="$i18n.getHelperMessage('items', 'comment_status')"/>
-
+
-
+
+ +
@@ -317,16 +325,11 @@

- + +
@@ -554,6 +557,8 @@ export default { diff --git a/src/views/tainacan-admin-i18n.php b/src/views/tainacan-admin-i18n.php index 886f8769c..eeefae979 100644 --- a/src/views/tainacan-admin-i18n.php +++ b/src/views/tainacan-admin-i18n.php @@ -480,7 +480,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_esc_key' => __( 'ESC', 'tainacan' ), 'label_view_selected_items_as' => __( 'View selected items as...', 'tainacan' ), 'label_actions_for_the_selection' => __( 'Actions for the selection', 'tainacan' ), - 'label_upload_custom_thumbnail' => __( 'Upload custom thubmnail', 'tainacan' ), + 'label_upload_custom_thumbnail' => __( 'Upload custom thumbnail', 'tainacan' ), 'label_switch_document_type' => __( 'Switch document type', 'tainacan' ), // Instructions. More complex sentences to guide user and placeholders From 2f72f54a9666fd85e04d0c7e03e44454525c06d1 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 25 Sep 2020 16:19:51 -0300 Subject: [PATCH 49/71] remove `flush` to avoid modify header #388 --- src/classes/class-tainacan-media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/class-tainacan-media.php b/src/classes/class-tainacan-media.php index de7815a31..5758a1393 100644 --- a/src/classes/class-tainacan-media.php +++ b/src/classes/class-tainacan-media.php @@ -42,7 +42,7 @@ class Media { if( ob_get_level() > 0 ) { ob_flush(); } - flush(); + // flush(); } /** From 9bd7aa1c19c664030964b8ea42ab2e106009987a Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 25 Sep 2020 16:20:15 -0300 Subject: [PATCH 50/71] add test isset on variables #388 --- .../api/endpoints/class-tainacan-rest-items-controller.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php index 578f2a6ff..e3be774fb 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php @@ -1014,9 +1014,9 @@ class REST_Items_Controller extends REST_Controller { } } - if ($document_id === false || $thumbnail_id === false) { - if($document_id !== false) wp_delete_attachment($document_id, true); - if($thumbnail_id !== false) wp_delete_attachment($thumbnail_id, true); + if ((isset($document_id) && $document_id === false) || (isset($thumbnail_id) && $thumbnail_id === false)) { + if(isset($document_id) && $document_id !== false) wp_delete_attachment($document_id, true); + if(isset($thumbnail_id) && $thumbnail_id !== false) wp_delete_attachment($thumbnail_id, true); return new \WP_REST_Response([ 'error_message' => __('error on create document or thumbnail.', 'tainacan'), ], 400); From 7a0abfd1ba9882484335f3a236070b0f1da62ad4 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 25 Sep 2020 16:24:28 -0300 Subject: [PATCH 51/71] add mapped property `allows_submission` #388 --- src/classes/entities/class-tainacan-collection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index bc53ba9f0..c27c4cdb1 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -35,6 +35,7 @@ class Collection extends Entity { $header_image, $comment_status, $allow_comments, + $allows_submission, $hide_items_thumbnail_on_lists, $submission_anonymous_user, $submission_default_status; From 5a345e324e6a492b4a975c96843cbc04d264bd97 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 25 Sep 2020 16:24:39 -0300 Subject: [PATCH 52/71] fix tests #388 --- tests/test-api-items-submission.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test-api-items-submission.php b/tests/test-api-items-submission.php index 6e0753c44..f65c73998 100644 --- a/tests/test-api-items-submission.php +++ b/tests/test-api-items-submission.php @@ -17,7 +17,8 @@ class TAINACAN_REST_Items_Submission extends TAINACAN_UnitApiTestCase { 'name' => 'Col-1', 'description' => 'Col-1', 'status' => 'publish', - 'submission_anonymous_user' => true + 'submission_anonymous_user' => true, + 'allows_submission' => true ], true ); @@ -28,7 +29,8 @@ class TAINACAN_REST_Items_Submission extends TAINACAN_UnitApiTestCase { 'name' => 'Col-2', 'description' => 'Col-2', 'status' => 'publish', - 'submission_anonymous_user' => false + 'submission_anonymous_user' => false, + 'allows_submission' => true ], true ); From 375fb7d17f1c5ccb8d9019c5606dcd35e4a35b9f Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 25 Sep 2020 16:41:06 -0300 Subject: [PATCH 53/71] URL and Text documents passed in the first submission endpoint #388. --- ...n-gutenberg-block-item-submission-form.css | 15 +-- ...tenberg-block-item-submission-form.css.map | 2 +- .../admin/js/store/modules/item/actions.js | 6 +- .../item-submission-form/index.js | 121 +++++++++--------- .../item-submission-form.scss | 22 +--- 5 files changed, 64 insertions(+), 102 deletions(-) diff --git a/src/assets/css/tainacan-gutenberg-block-item-submission-form.css b/src/assets/css/tainacan-gutenberg-block-item-submission-form.css index 9415f8da4..88e7919b9 100644 --- a/src/assets/css/tainacan-gutenberg-block-item-submission-form.css +++ b/src/assets/css/tainacan-gutenberg-block-item-submission-form.css @@ -32,23 +32,10 @@ border-radius: 4px; border: 1px solid rgba(200, 200, 200, 0.3); overflow: hidden; } - .wp-block-tainacan-item-submission-form .item-submission-form-placeholder .form-columns { - display: flex; } - .wp-block-tainacan-item-submission-form .item-submission-form-placeholder .form-columns > div:first-child { - padding-right: 4.1666667%; } - .wp-block-tainacan-item-submission-form .item-submission-form-placeholder .form-columns > div { - flex-grow: 1; - flex-shrink: 0; - flex-basis: 50%; } - @media screen and (max-width: 768px) { - .wp-block-tainacan-item-submission-form .item-submission-form-placeholder .form-columns { - flex-wrap: wrap; } - .wp-block-tainacan-item-submission-form .item-submission-form-placeholder .form-columns > div { - flex-basis: 100%; } } .wp-block-tainacan-item-submission-form .item-submission-form-placeholder .fake-text { background-color: var(--tainacan-label-color, rgba(200, 200, 200, 0.3)); height: 0.2em; - width: 24%; + width: 15%; min-width: 1.25em; border-radius: 2px; display: inline-block; } diff --git a/src/assets/css/tainacan-gutenberg-block-item-submission-form.css.map b/src/assets/css/tainacan-gutenberg-block-item-submission-form.css.map index cc1542232..8207f62b1 100644 --- a/src/assets/css/tainacan-gutenberg-block-item-submission-form.css.map +++ b/src/assets/css/tainacan-gutenberg-block-item-submission-form.css.map @@ -1,6 +1,6 @@ { "version": 3, -"mappings": "AAEA,uBAAwB;EACpB,MAAM,EAAE,kBAAkB;EAE1B,sDAA+B;IAC3B,WAAW,EAAE,IAAI;IACjB,SAAS,EAAE,OAAO;IAClB,KAAK,EAAE,oCAAmC;;AAGlD,uCAAwC;EACpC,MAAM,EAAE,QAAQ;EAGhB,0DAAmB;IACf,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,MAAM;IACvB,WAAW,EAAE,MAAM;IACnB,KAAK,EAAE,oCAAmC;EAG9C,wDAAiB;IACb,KAAK,EAAE,IAAI;IACX,SAAS,EAAE,OAAO;IAClB,UAAU,EAAE,MAAM;I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QACb,cAAc,EAAE,MAAM;QACtB,SAAS,EAAE,MAAM;QAEjB,sHAAY;UACR,KAAK,EAAE,IAAI;UACX,SAAS,EAAE,IAAI;UACf,MAAM,EAAE,gBAAgB;QAE5B,uHAAe;UACX,aAAa,EAAE,sEAAoE;UACnF,aAAa,EAAE,KAAK;IAIhC,sFAAa;MACT,OAAO,EAAE,WAAW;MACpB,OAAO,EAAE,IAAI;MACb,WAAW,EAAE,MAAM;MACnB,eAAe,EAAE,aAAa;MAE9B,mGAAa;QACT,gBAAgB,EAAE,oDAAkD;MAExE,mGAAa;QACT,MAAM,EAAE,KAAK;MAEjB,2GAAqB;QACjB,WAAW,EAAE,IAAI", "sources": ["../../views/gutenberg-blocks/tainacan-items/item-submission-form/item-submission-form.scss"], "names": [], "file": "tainacan-gutenberg-block-item-submission-form.css" diff --git a/src/views/admin/js/store/modules/item/actions.js b/src/views/admin/js/store/modules/item/actions.js index 1401f76c3..3c4613c33 100644 --- a/src/views/admin/js/store/modules/item/actions.js +++ b/src/views/admin/js/store/modules/item/actions.js @@ -326,7 +326,9 @@ export const submitItemSubmission = ({ commit }, { itemSubmission, itemSubmissio let item = JSON.parse(JSON.stringify(itemSubmission)); // Use a copy as the next request will need document, attchment and thumbnail for (let key of Object.keys(item)) { - if (['document', 'attachments', 'thumbnail'].includes(key) ) + if (['attachments', 'thumbnail'].includes(key) ) + delete item[key]; + else if (key === 'document' && itemSubmission.document_type === 'attachment' ) delete item[key]; } @@ -350,7 +352,7 @@ export const finishItemSubmission = ({ commit }, { itemSubmission, fakeItemId }) const formData = new FormData(); for (let key of Object.keys(itemSubmission)) { - if (['document','thumbnail'].includes(key) ) + if (key === 'thumbnail' || (key === 'document' && itemSubmission.document_type === 'attachment') ) formData.append(key, itemSubmission[key]); else if (key === 'attachments') { for (let i = 0; i < itemSubmission[key].length; i++) diff --git a/src/views/gutenberg-blocks/tainacan-items/item-submission-form/index.js b/src/views/gutenberg-blocks/tainacan-items/item-submission-form/index.js index a574f461a..4855e6769 100644 --- a/src/views/gutenberg-blocks/tainacan-items/item-submission-form/index.js +++ b/src/views/gutenberg-blocks/tainacan-items/item-submission-form/index.js @@ -548,82 +548,75 @@ registerBlockType('tainacan/item-submission-form', { '--tainacan-secondary': secondaryColor }} class="item-submission-form-placeholder"> -
-
- { - (!hideFileModalButton || !hideTextModalButton || !hideLinkModalButton) ? - ( -
- -
- { hideFileModalButton ? null : } - { hideTextModalButton ? null : } - { hideLinkModalButton ? null : } -
-
- ) : null - } - { !hideThumbnailSection ? - ( -
- -
-
- -
-
- ) : null - } - { !hideAttachmentsSection ? + +
+ { + (!hideFileModalButton || !hideTextModalButton || !hideLinkModalButton) ? (
- -
-
-
-
-
+ +
+ { hideFileModalButton ? null : } + { hideTextModalButton ? null : } + { hideLinkModalButton ? null : }
) : null - } - -
- + } + { !hideThumbnailSection ? + ( +
+ +
+
+ ) : null + } + { !hideAttachmentsSection ? + ( +
+ +
+
+
+
+
+
-
- - - + @@ -333,9 +333,27 @@
+ +
+
+
+

+ + + +

+

{{ $i18n.get('label_sending_form') }}

+

{{ $i18n.get('info_submission_processing') }}

+

{{ $i18n.get('info_submission_uploading') }}

+
+
+
+

@@ -379,15 +397,17 @@ export default { data(){ return { isLoading: false, + isSubmitting: false, + isUploading: false, metadataCollapses: [], collapseAll: true, form: { collection_id: Number, - document: null, + document: '', document_type: '', comment_status: '', attachments: [], - thumbnail: null + thumbnail: '' }, formErrorMessage: '', hasSentForm: false, @@ -451,7 +471,7 @@ export default { onSubmit() { // Puts loading on Item edition - this.isLoading = true; + this.isSubmitting = true; let data = this.form; this.fillExtraFormData(data); @@ -463,11 +483,15 @@ export default { this.submitItemSubmission({ itemSubmission: this.itemSubmission, itemSubmissionMetadata: this.itemSubmissionMetadata }) .then((fakeItemId) => { + + this.isUploading = true; + this.isSubmitting = false; + if (fakeItemId) { this.finishItemSubmission({ itemSubmission: this.itemSubmission, fakeItemId: fakeItemId }) .then(() => { this.hasSentForm = true; - this.isLoading = false; + this.isUploading = false; }) .catch((errors) => { if (errors.errors) { @@ -656,6 +680,7 @@ export default { .files-list { display: flex; + flex-wrap: wrap; } .form-submission-footer { diff --git a/src/views/tainacan-admin-i18n.php b/src/views/tainacan-admin-i18n.php index eeefae979..956992965 100644 --- a/src/views/tainacan-admin-i18n.php +++ b/src/views/tainacan-admin-i18n.php @@ -482,6 +482,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_actions_for_the_selection' => __( 'Actions for the selection', 'tainacan' ), 'label_upload_custom_thumbnail' => __( 'Upload custom thumbnail', 'tainacan' ), 'label_switch_document_type' => __( 'Switch document type', 'tainacan' ), + 'label_sending_form' => __( 'Sending form...', 'tainacan' ), // Instructions. More complex sentences to guide user and placeholders 'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ), @@ -747,6 +748,8 @@ return apply_filters( 'tainacan-admin-i18n', [ 'info_gallery_help_end' => __( 'At any moment, you can also check the item metadata list by clicking on the metadata icon (%1$s) or go directly to the item page, where you will have all its details, by clicking on the eye icon (%2$s).', 'tainacan' ), 'info_thumbnail_custom' => __( 'Upload the desired image for the thumbnail', 'tainacan'), 'info_thumbnail_default_from_document' => __( 'A thumbnail will be automatically generated from the submitted document file', 'tainacan'), + 'info_submission_processing' => __( 'Please, wait while the submission is being processed', 'tainacan'), + 'info_submission_uploading' => __( 'Please, wait while files are uploaded', 'tainacan'), // Datepicker months 'datepicker_month_january' => __( 'January', 'tainacan' ), From 051d17a8e42d94e7814561be25ca186441c06a37 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 25 Sep 2020 17:20:09 -0300 Subject: [PATCH 56/71] change mapped property bool to string #388 --- .../class-tainacan-rest-items-controller.php | 6 ++---- .../entities/class-tainacan-collection.php | 12 ++++++------ tests/test-api-items-submission.php | 16 ++++++++-------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php index d972c5de9..2cd0f8e53 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php @@ -889,8 +889,6 @@ class REST_Items_Controller extends REST_Controller { } try { - $collection = $this->collections_repository->fetch($collection_id); - $item['status'] = 'auto-draft'; $item = $this->prepare_item_for_database( [ $item, $collection_id ] ); @@ -1059,8 +1057,8 @@ class REST_Items_Controller extends REST_Controller { public function submission_item_permissions_check ( $request ) { $collection = $this->collections_repository->fetch($request['collection_id']); - if ($collection instanceof Entities\Collection && $collection->get_allows_submission()) { - if ($collection->get_submission_anonymous_user()) { + if ($collection instanceof Entities\Collection && $collection->get_allows_submission() == 'yes') { + if ($collection->get_submission_anonymous_user() == 'yes') { return true; } return current_user_can($collection->get_items_capabilities()->edit_posts); diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index c27c4cdb1..11fd01f48 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -550,10 +550,10 @@ class Collection extends Entity { /** * Get enable submission with anonymous user * - * @return bool + * @return string "yes"|"no" */ function get_submission_anonymous_user() { - return $this->get_mapped_property( 'submission_anonymous_user' ) != 'false'; + return $this->get_mapped_property( 'submission_anonymous_user' ); } /** @@ -568,10 +568,10 @@ class Collection extends Entity { /** * Checks if submission items are allowed for the current collection. * - * @return bool + * @return string "yes"|"no" */ function get_allows_submission() { - return $this->get_mapped_property( 'allows_submission' ) != 'false'; + return $this->get_mapped_property( 'allows_submission' ); } /** @@ -775,7 +775,7 @@ class Collection extends Entity { /** * Set enable submission with anonymous user * - * @param [boolean] $value + * @param [string] $value * * @return void */ @@ -797,7 +797,7 @@ class Collection extends Entity { /** * Set if submission items are allowes for the current collection. * - * @param [boolean] $value + * @param [string] $value * * @return void */ diff --git a/tests/test-api-items-submission.php b/tests/test-api-items-submission.php index f65c73998..68ff40911 100644 --- a/tests/test-api-items-submission.php +++ b/tests/test-api-items-submission.php @@ -17,8 +17,8 @@ class TAINACAN_REST_Items_Submission extends TAINACAN_UnitApiTestCase { 'name' => 'Col-1', 'description' => 'Col-1', 'status' => 'publish', - 'submission_anonymous_user' => true, - 'allows_submission' => true + 'submission_anonymous_user' => 'yes', + 'allows_submission' => 'yes' ], true ); @@ -29,8 +29,8 @@ class TAINACAN_REST_Items_Submission extends TAINACAN_UnitApiTestCase { 'name' => 'Col-2', 'description' => 'Col-2', 'status' => 'publish', - 'submission_anonymous_user' => false, - 'allows_submission' => true + 'submission_anonymous_user' => 'no', + 'allows_submission' => 'yes' ], true ); @@ -238,8 +238,8 @@ class TAINACAN_REST_Items_Submission extends TAINACAN_UnitApiTestCase { public function test_submission_item_user_anonymous() { wp_logout(); - $this->assertEquals($this->col_user_anonymous->get_submission_anonymous_user(), true); - $this->assertEquals($this->col_user_logged->get_submission_anonymous_user(), false); + $this->assertEquals($this->col_user_anonymous->get_submission_anonymous_user(), 'yes'); + $this->assertEquals($this->col_user_logged->get_submission_anonymous_user(), 'no'); $metadatums = $this->collections_metadatum[$this->col_user_anonymous->get_id()]; @@ -309,8 +309,8 @@ class TAINACAN_REST_Items_Submission extends TAINACAN_UnitApiTestCase { public function test_submission_item_user_logged() { // echo "user_id" . $this->user_id; - $this->assertEquals($this->col_user_anonymous->get_submission_anonymous_user(), true); - $this->assertEquals($this->col_user_logged->get_submission_anonymous_user(), false); + $this->assertEquals($this->col_user_anonymous->get_submission_anonymous_user(), 'yes'); + $this->assertEquals($this->col_user_logged->get_submission_anonymous_user(), 'no'); $metadatums = $this->collections_metadatum[$this->col_user_anonymous->get_id()]; $item_json = json_encode([ From bf84c64c54e11236036bf82b8c1ffd7e6409462f Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 25 Sep 2020 17:24:06 -0300 Subject: [PATCH 57/71] Uses string instead of boolean to new collection properties --- .../components/edition/collection-edition-form.vue | 10 +++++++--- .../faceted-search/collection-modal.js | 14 ++++++++++++-- .../tainacan-items/item-submission-form/index.js | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/views/admin/components/edition/collection-edition-form.vue b/src/views/admin/components/edition/collection-edition-form.vue index ae8044131..6e9addd28 100644 --- a/src/views/admin/components/edition/collection-edition-form.vue +++ b/src/views/admin/components/edition/collection-edition-form.vue @@ -468,6 +468,8 @@
@@ -489,6 +491,8 @@ { collectionId = collectionId; From c210d2d20151bcda0d003f522f655af15660674c Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 25 Sep 2020 17:26:59 -0300 Subject: [PATCH 58/71] add validation for mapped property #388 --- .../repositories/class-tainacan-collections.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index 6f640ba6f..c5b8deccc 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -198,9 +198,11 @@ class Collections extends Repository { 'submission_anonymous_user' => [ 'map' => 'meta', 'title' => __( 'Allows submission by anonymous user', 'tainacan' ), - 'type' => 'boolean', + 'type' => 'string', 'description' => __( 'If enabled, allows submission by anonymous user.', 'tainacan' ), - 'default' => 'false' + 'default' => 'no', + 'on_error' => __( 'Value should be yes or no', 'tainacan' ), + 'validation' => v::stringType()->in( [ 'yes', 'no' ] ), // yes or no ], 'submission_default_status' => [ 'map' => 'meta', @@ -212,9 +214,11 @@ class Collections extends Repository { 'allows_submission' => [ 'map' => 'meta', 'title' => __( 'Allows item submission', 'tainacan' ), - 'type' => 'boolean', + 'type' => 'string', 'description' => __( 'If enabled, the collection allows item submission, for example via the Item Submission block.', 'tainacan' ), - 'default' => 'false' + 'default' => 'no', + 'on_error' => __( 'Value should be yes or no', 'tainacan' ), + 'validation' => v::stringType()->in( [ 'yes', 'no' ] ), // yes or no ], 'hide_items_thumbnail_on_lists' => [ 'map' => 'meta', From a8610d96c1ced74e2b760d1281145a3600c6170b Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 25 Sep 2020 17:48:40 -0300 Subject: [PATCH 59/71] Fixes search queries on collection modal. --- .../faceted-search/collection-modal.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/views/gutenberg-blocks/tainacan-facets/faceted-search/collection-modal.js b/src/views/gutenberg-blocks/tainacan-facets/faceted-search/collection-modal.js index 061d16b4b..a7f0cd1f8 100644 --- a/src/views/gutenberg-blocks/tainacan-facets/faceted-search/collection-modal.js +++ b/src/views/gutenberg-blocks/tainacan-facets/faceted-search/collection-modal.js @@ -69,10 +69,18 @@ export default class CollectionModal extends React.Component { paged: this.state.collectionPage } - if (this.props.filterOptionsBy && Object.keys(this.props.filterOptionsBy).length !== 0) - query = {...query, meta_query: this.props.filterOptionsBy} - + if (this.props.filterOptionsBy && Object.keys(this.props.filterOptionsBy).length !== 0) { + let metaqueries = []; + for (let metaquery of Object.keys(this.props.filterOptionsBy)) { + metaqueries.push({ + key: metaquery, + value: this.props.filterOptionsBy[metaquery] + }) + } + query = {...query, metaquery: metaqueries} + } + let endpoint = '/collections/?' + qs.stringify(query); if (this.state.collectionOrderBy == 'date') @@ -146,14 +154,12 @@ export default class CollectionModal extends React.Component { for (let metaquery of Object.keys(this.props.filterOptionsBy)) { metaqueries.push({ key: metaquery, - value: this.props.filterOptionsBy[key] + value: this.props.filterOptionsBy[metaquery] }) } - query = {...query, metaquery: metaqueries} } - let endpoint = '/collections/?' + qs.stringify(query); if (name != undefined && name != '') From d7cc44059d2cb91a362cb33c35e42c7454e0b1d0 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 28 Sep 2020 12:06:08 -0300 Subject: [PATCH 60/71] Fixes some error notification on the item submission form. #388 --- .../pages/item-submission-form.vue | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/views/item-submission/pages/item-submission-form.vue b/src/views/item-submission/pages/item-submission-form.vue index e41190387..3b8637de6 100644 --- a/src/views/item-submission/pages/item-submission-form.vue +++ b/src/views/item-submission/pages/item-submission-form.vue @@ -5,8 +5,8 @@ :active.sync="isLoading" :can-cancel="false"/>
@@ -505,7 +505,9 @@ export default { } this.formErrorMessage = errors.error_message; } - this.isLoading = false; + this.isSubmitting = false; + this.hasSentForm = false; + this.isUploading = false; }); } }) @@ -521,7 +523,9 @@ export default { } this.formErrorMessage = errors.error_message; } - this.isLoading = false; + this.isSubmitting = false; + this.hasSentForm = false; + this.isUploading = false; }); }, onDiscard() { @@ -689,7 +693,7 @@ export default { display: flex; justify-content: space-between; align-items: center; - font-size: 1em; + font-size: 0.875em; @keyframes blink { from { color: var(--tainacan-blue5); } @@ -699,6 +703,7 @@ export default { .footer-message { display: flex; align-items: center; + margin: 12px; } .update-info-section { color: var(--tainacan-info-color); From 0d0dd23bd7e8622fc12d8ab5982f579f478b3492 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Mon, 28 Sep 2020 15:38:07 -0300 Subject: [PATCH 61/71] add slug docment types on errors #388 --- .../class-tainacan-rest-items-controller.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php index 2cd0f8e53..0866e3f4b 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php @@ -1013,10 +1013,18 @@ class REST_Items_Controller extends REST_Controller { } if ((isset($document_id) && $document_id === false) || (isset($thumbnail_id) && $thumbnail_id === false)) { - if(isset($document_id) && $document_id !== false) wp_delete_attachment($document_id, true); - if(isset($thumbnail_id) && $thumbnail_id !== false) wp_delete_attachment($thumbnail_id, true); + $entities_erros = ["document", "thumbnail"]; + if(isset($document_id) && $document_id !== false) { + $entities_erros = ["thumbnail"]; + wp_delete_attachment($document_id, true); + } + if(isset($thumbnail_id) && $thumbnail_id !== false) { + $entities_erros = ["document"]; + wp_delete_attachment($thumbnail_id, true); + } return new \WP_REST_Response([ 'error_message' => __('error on create document or thumbnail.', 'tainacan'), + 'errors' => $entities_erros ], 400); } @@ -1034,6 +1042,7 @@ class REST_Items_Controller extends REST_Controller { } return new \WP_REST_Response([ 'error_message' => __('error on create attachment ', 'tainacan') . "($attachments_name[$i])", + 'errors' => ['attachment'] ], 400); } $insert_attachments[] = $attachment_id; From 6deb0d81c776179028e426e79c229e90548268eb Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 28 Sep 2020 15:44:45 -0300 Subject: [PATCH 62/71] Continues form error updates #388. --- src/views/admin/js/store/modules/item/actions.js | 2 +- src/views/item-submission/pages/item-submission-form.vue | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/views/admin/js/store/modules/item/actions.js b/src/views/admin/js/store/modules/item/actions.js index 3c4613c33..835b04a88 100644 --- a/src/views/admin/js/store/modules/item/actions.js +++ b/src/views/admin/js/store/modules/item/actions.js @@ -362,7 +362,7 @@ export const finishItemSubmission = ({ commit }, { itemSubmission, fakeItemId }) axios.tainacan.post('/collection/' + itemSubmission.collection_id + '/items/submission/' + fakeItemId + '/finish', formData, config ) .then( res => { resolve( res.data ); - }).catch( error => { + }).catch( error => { reject({ errors: error.response.data.errors, error_message: error.response.data.error_message diff --git a/src/views/item-submission/pages/item-submission-form.vue b/src/views/item-submission/pages/item-submission-form.vue index 3b8637de6..bbc401db5 100644 --- a/src/views/item-submission/pages/item-submission-form.vue +++ b/src/views/item-submission/pages/item-submission-form.vue @@ -503,8 +503,9 @@ export default { }); } } - this.formErrorMessage = errors.error_message; } + this.formErrorMessage = errors.error_message; + this.isSubmitting = false; this.hasSentForm = false; this.isUploading = false; @@ -521,8 +522,9 @@ export default { }); } } - this.formErrorMessage = errors.error_message; } + this.formErrorMessage = errors.error_message; + this.isSubmitting = false; this.hasSentForm = false; this.isUploading = false; From dddfae2513313d99d5e54ee07f8953286b90338d Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 28 Sep 2020 17:30:25 -0300 Subject: [PATCH 63/71] Integrates error popup component with file upload errors. #388 --- .../other/item-metadatum-errors-tooltip.vue | 19 +++++-- src/views/admin/scss/_tags.scss | 9 ++++ .../pages/item-submission-form.vue | 52 +++++++++++++------ 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/views/admin/components/other/item-metadatum-errors-tooltip.vue b/src/views/admin/components/other/item-metadatum-errors-tooltip.vue index 04622ac18..e3b16f78d 100644 --- a/src/views/admin/components/other/item-metadatum-errors-tooltip.vue +++ b/src/views/admin/components/other/item-metadatum-errors-tooltip.vue @@ -18,10 +18,15 @@ v-if="error.errors.length" :key="index"> + {{ $i18n.get('label_' + getErrorMessage(error.errors)) }} + + {{ getErrorMessage(error.errors) }} - +

{{ getErrorMessage(error.errors) }}

@@ -45,9 +50,13 @@ export default { methods: { getErrorMessage(errors) { let metadatumErrorMessage = ''; - for (let singleError of errors) { - for (let index of Object.keys(singleError)) - metadatumErrorMessage += singleError[index] + '\n'; + for (let singleError of errors) { + if (typeof singleError != 'string') { + for (let index of Object.keys(singleError)) + metadatumErrorMessage += singleError[index] + '\n'; + } else { + metadatumErrorMessage += singleError; + } } return metadatumErrorMessage; }, diff --git a/src/views/admin/scss/_tags.scss b/src/views/admin/scss/_tags.scss index aaeefc73d..f4485b5e1 100644 --- a/src/views/admin/scss/_tags.scss +++ b/src/views/admin/scss/_tags.scss @@ -54,5 +54,14 @@ } } } + + &.is-danger, + &.is-danger:hover, + &.is-danger:focus, + &.is-danger:active { + border-color: var(--tainacan-danger) !important; + background-color: var(--tainacan-red1) !important; + color: var(--tainacan-danger) !important; + } } } \ No newline at end of file diff --git a/src/views/item-submission/pages/item-submission-form.vue b/src/views/item-submission/pages/item-submission-form.vue index bbc401db5..3a549d959 100644 --- a/src/views/item-submission/pages/item-submission-form.vue +++ b/src/views/item-submission/pages/item-submission-form.vue @@ -9,7 +9,6 @@ v-show="!isLoading && !isSubmitting && !isUploading" class="tainacan-form" label-width="120px"> -