diff --git a/src/admin/components/edition/term-edition-form.vue b/src/admin/components/edition/term-edition-form.vue index 0911e97c2..8e696d658 100644 --- a/src/admin/components/edition/term-edition-form.vue +++ b/src/admin/components/edition/term-edition-form.vue @@ -45,7 +45,7 @@ - + + + + + + + + + + +

+ {{ $i18n.get('info_warning_changing_parent_term') }} +

+
+
+
@@ -19,8 +18,7 @@ v-if="!openAdvancedSearch" class="is-hidden-tablet" id="filter-menu-compress-button" - :class="{'filter-menu-compress-button-top-repo': isRepositoryLevel}" - :style="{ top: !isOnTheme ? (searchControlHeight + 70) + 'px' : (searchControlHeight - 25) + 'px' }" + :style="{ top: !isOnTheme ? (isRepositoryLevel ? (searchControlHeight + 100) : (searchControlHeight + 70) + 'px') : (searchControlHeight - 25) + 'px' }" @click="isFilterModalActive = !isFilterModalActive"> {{ $i18n.get('filters') }} @@ -770,7 +768,7 @@ 'getAdminViewMode' ]), onSwipeFiltersMenu($event) { - let screenWidth = window.screen.width; + let screenWidth = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth); if ($event.offsetDirection == 4 && screenWidth <= 768) { if (!this.isFilterModalActive) @@ -1274,9 +1272,6 @@ } } - .filter-menu-compress-button-top-repo { - top: 123px !important; - } #filter-menu-compress-button { position: absolute; z-index: 99; @@ -1287,7 +1282,7 @@ width: 23px; border: none; background-color: $turquoise1; - color: $blue5; + color: $turquoise5; padding: 0; border-top-right-radius: 2px; border-bottom-right-radius: 2px; diff --git a/src/admin/pages/lists/taxonomies-page.vue b/src/admin/pages/lists/taxonomies-page.vue index 897cd79d7..31573b784 100644 --- a/src/admin/pages/lists/taxonomies-page.vue +++ b/src/admin/pages/lists/taxonomies-page.vue @@ -141,14 +141,17 @@ this.load(); }, onChangePerPage(value) { - this.taxonomiesPerPage = value; - this.$userPrefs.set('taxonomies_per_page', value) - .then((newValue) => { - this.taxonomiesPerPage = newValue; - }) - .catch(() => { - this.$console.log("Error settings user prefs for taxonomies per page") - }); + if (value != this.taxonomiesPerPage) { + this.$userPrefs.set('taxonomies_per_page', value) + .then((newValue) => { + this.taxonomiesPerPage = newValue; + }) + .catch(() => { + this.$console.log("Error settings user prefs for taxonomies per page") + }); + + } + this.taxonomiesPerPage = value; this.load(); }, onPageChange(page) { diff --git a/src/admin/pages/lists/term-items-page.vue b/src/admin/pages/lists/term-items-page.vue index 96894baca..b5b092271 100644 --- a/src/admin/pages/lists/term-items-page.vue +++ b/src/admin/pages/lists/term-items-page.vue @@ -771,7 +771,7 @@ 'getAdminViewMode' ]), onSwipeFiltersMenu($event) { - let screenWidth = window.screen.width; + let screenWidth = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth); if ($event.offsetDirection == 4 && screenWidth <= 768) { if (!this.isFilterModalActive) @@ -1289,7 +1289,7 @@ width: 23px; border: none; background-color: $turquoise1; - color: $blue5; + color: $turquoise5; padding: 0; border-top-right-radius: 2px; border-bottom-right-radius: 2px; diff --git a/src/admin/scss/_repository-level-overrides.scss b/src/admin/scss/_repository-level-overrides.scss new file mode 100644 index 000000000..3c77ef84d --- /dev/null +++ b/src/admin/scss/_repository-level-overrides.scss @@ -0,0 +1,91 @@ +// Repository-level pages +// This garantees that any component inside a .repository-level-page +// will have a blue color instead of a turquoise. +.repository-level-page { + + margin-top: 94px; + height: $page-height !important; + + @media screen and (max-width: 769px) { + margin-top: 42px; + } + + .is-primary:not(.upload-draggable), .is-primary:hover, .is-primary:focus { + background-color: $blue4 !important; + color: white !important; + } + .is-secondary, .is-secondary:hover, .is-secondary:focus { + background-color: $blue5 !important; + color: white !important; + } + .has-text-primary, .has-text-primary:hover, .is-has-text-primary:focus { + color: $blue4 !important; + } + a, a:hover, + .has-text-secondary, .has-text-secondary:hover, .is-has-text-secondary:focus { + color: $blue3 !important; + } + .tainacan-page-title hr{ + background-color: $blue3; + } + .button[disabled]:not(.is-white), .button:hover[disabled]:not(.is-white) { + border: none !important; + cursor: not-allowed !important; + color: $gray4 !important; + background-color: $gray2 !important; + } + .button.is-outlined { + color: $blue5 !important; + } + .tabs { + li.is-active a { + border-bottom: 5px solid $blue5; + color: $blue5; + } + } + .select:not(.is-multiple)::after { + color: $blue5; + + option:checked, option:hover { + background-color: $gray2 !important; + } + } + .tainacan-table { + tr.selected-row { + background-color: $blue1 !important; + .checkbox-cell .checkbox, .actions-cell .actions-container { + background-color: $blue2 !important; + } + } + } + .dropdown-trigger { + .button .icon { + color: $blue5; + } + } + .dropdown-menu .dropdown-content { + .dropdown-item.is-active { background-color: $blue2; } + } + + .switch { + &:hover input[type="checkbox"]:checked + .check { + background-color: $blue2; + } + input[type="checkbox"]:checked + .check { + border: 2px solid $blue5; + + &::before { + background-color: $blue5; + } + } + &.is-small { + input[type="checkbox"]:checked + .check { + border: 1.5px solid $blue5; + } + } + } + #filter-menu-compress-button { + background-color: $blue1 !important; + color: $blue5 !important; + } +} \ No newline at end of file diff --git a/src/admin/scss/_tainacan-form.scss b/src/admin/scss/_tainacan-form.scss index 5052f6232..f8d32d13c 100644 --- a/src/admin/scss/_tainacan-form.scss +++ b/src/admin/scss/_tainacan-form.scss @@ -30,6 +30,7 @@ white-space: nowrap; text-overflow: ellipsis; overflow: hidden; + vertical-align: top; } .required-metadatum-asterisk { color: $gray3; @@ -74,7 +75,7 @@ padding-left: 0.8em; font-size: 12px; text-overflow: ellipsis; - overflow-x: hidden; + overflow: hidden; white-space: nowrap; } .select { diff --git a/src/admin/scss/_view-mode-cards.scss b/src/admin/scss/_view-mode-cards.scss index 0b9454ceb..721523e0a 100644 --- a/src/admin/scss/_view-mode-cards.scss +++ b/src/admin/scss/_view-mode-cards.scss @@ -20,24 +20,26 @@ padding: 0px; flex-basis: 0; margin: 0.75rem; - max-width: 410px; - min-width: 410px; + max-width: 425px; + min-width: 425px; min-height: 218px; max-height: 218px; cursor: pointer; - @media screen and (max-width: 450px) { + @media screen and (max-width: 480px) { max-width: 100%; min-width: 100%; + min-height: 176px; + max-height: 176px; img { - width: 33.333333% !important; - height: 33.333333% !important; + width: 130px !important; + height: 130px !important; } } &:hover { - background-color: #f2f2f2 !important; + background-color: $gray1 !important; } .card-checkbox { @@ -109,7 +111,7 @@ p.metadata-description { font-size: 0.6875rem !important; overflow: hidden; - margin-bottom: 1.5rem; + margin-bottom: 1rem; max-height: 152px; } diff --git a/src/admin/scss/_view-mode-records.scss b/src/admin/scss/_view-mode-records.scss index ef731a4e3..d58eee301 100644 --- a/src/admin/scss/_view-mode-records.scss +++ b/src/admin/scss/_view-mode-records.scss @@ -17,6 +17,7 @@ } .tainacan-record { + background-color: #f6f6f6; padding: 0px; flex-basis: 0; margin: 0 auto 42px auto; @@ -28,7 +29,7 @@ display: block; &:hover { - background-color: #f2f2f2 !important; + background-color: $gray1 !important; } .record-checkbox { @@ -86,6 +87,7 @@ text-overflow: ellipsis; white-space: nowrap; overflow: hidden; + transition: background-color 0.3s; } } &:hover .metadata-title { diff --git a/src/admin/scss/tainacan-admin.scss b/src/admin/scss/tainacan-admin.scss index ba212f4c1..2a5033c8c 100644 --- a/src/admin/scss/tainacan-admin.scss +++ b/src/admin/scss/tainacan-admin.scss @@ -23,6 +23,7 @@ @import "../scss/_tags.scss"; @import "../scss/_notices.scss"; @import "../scss/_filters-menu-modal.scss"; +@import "../scss/_repository-level-overrides.scss"; // Clears wordpress content body.tainacan-admin-page #adminmenumain, body.tainacan-admin-page #wpfooter, body.tainacan-admin-page #wp-auth-check-wrap { @@ -65,92 +66,6 @@ a:hover { } } -// Repository-level pages -.repository-level-page { - margin-top: 94px; - height: $page-height !important; - - @media screen and (max-width: 769px) { - margin-top: 42px; - } - - .is-primary:not(.upload-draggable), .is-primary:hover, .is-primary:focus { - background-color: $blue4 !important; - color: white !important; - } - .is-secondary, .is-secondary:hover, .is-secondary:focus { - background-color: $blue5 !important; - color: white !important; - } - .has-text-primary, .has-text-primary:hover, .is-has-text-primary:focus { - color: $blue4 !important; - } - a, a:hover, - .has-text-secondary, .has-text-secondary:hover, .is-has-text-secondary:focus { - color: $blue5 !important; - } - .tainacan-page-title { - h1 { - color: $blue5 !important; - } - } - .button[disabled]:not(.is-white), .button:hover[disabled]:not(.is-white) { - border: none !important; - cursor: not-allowed !important; - color: $gray4 !important; - background-color: $gray2 !important; - } - .button.is-outlined { - color: $blue5 !important; - } - .tabs { - li.is-active a { - border-bottom: 5px solid $blue5; - color: $blue5; - } - } - .select:not(.is-multiple)::after { - color: $blue5; - - option:checked, option:hover { - background-color: $gray2 !important; - } - } - .tainacan-table { - tr.selected-row { - background-color: $blue1 !important; - .checkbox-cell .checkbox, .actions-cell .actions-container { - background-color: $blue2 !important; - } - } - } - .dropdown-trigger { - .button .icon { - color: $blue5; - } - } - .dropdown-menu .dropdown-content { - .dropdown-item.is-active { background-color: $blue2; } - } - - .switch { - &:hover input[type="checkbox"]:checked + .check { - background-color: $blue2; - } - input[type="checkbox"]:checked + .check { - border: 2px solid $blue5; - - &::before { - background-color: $blue5; - } - } - &.is-small { - input[type="checkbox"]:checked + .check { - border: 1.5px solid $blue5; - } - } - } -} // Generic page container .page-container { padding: $page-top-padding $page-side-padding; diff --git a/src/admin/tainacan-admin-i18n.php b/src/admin/tainacan-admin-i18n.php index bf2d16c11..3c6b0850f 100644 --- a/src/admin/tainacan-admin-i18n.php +++ b/src/admin/tainacan-admin-i18n.php @@ -317,6 +317,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'instruction_insert_mapper_metadatum_info' => __( 'Insert the new mapper\'s metadatum info', 'tainacan' ), 'instruction_select_max_options_to_show' => __( 'Select max options to show', 'tainacan' ), 'instruction_select_collection_fetch_items' => __( 'Select a collection to fecth items', 'tainacan' ), + 'instruction_parent_term' => __( 'Type to search a Parent Term to choose.', 'tainacan' ), // Info. Other feedback to user. 'info_search_results' => __( 'Search Results', 'tainacan' ), @@ -384,6 +385,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'info_possible_external_sources' => __( 'Possible external sources: CSV, Instagram, Youtube, etc.', 'tainacan' ), 'info_help_term_name' => __( 'The term name', 'tainacan' ), 'info_help_term_description' => __( 'The description of the Term.', 'tainacan' ), + 'info_help_parent_term' => __( 'The parent term', 'tainacan' ), 'info_no_attachments_on_item_yet' => __( 'The are no attachments on this item so far.', 'tainacan' ), 'info_repository_metadata_inheritance' => __( 'Repository Metadata will be inherited by all collections.', 'tainacan' ), 'info_repository_filters_inheritance' => __( 'Repository Filters will be inherited by all collections.', 'tainacan' ), @@ -415,6 +417,8 @@ return apply_filters( 'tainacan-admin-i18n', [ 'info_there_are_no_metadata_in_repository_level' => __( 'There are no metadata in repository level', 'tainacan' ), 'info_import_collection' => __( 'Import from external sources.', 'tainacan' ), 'info_import_items' => __( 'Import items from external sources.', 'tainacan' ), + 'info_no_parent_term_found' => __( 'No valid parent term was found with this name.', 'tainacan' ), + 'info_warning_changing_parent_term' => __( 'Warning! Changing parent term will reload the terms list, thus uncheking any selection.', 'tainacan' ), // Tainacan Metadatum Types 'tainacan-text' => __( 'Text', 'tainacan' ), diff --git a/src/admin/theme-items-list.vue b/src/admin/theme-items-list.vue index 233172b5d..51e6b98fc 100644 --- a/src/admin/theme-items-list.vue +++ b/src/admin/theme-items-list.vue @@ -20,7 +20,7 @@ export default { name: "ThemeItemsList", created() { - this.$userPrefs.init(); + this.$userPrefs.init(); } } diff --git a/src/api/class-tainacan-rest-controller.php b/src/api/class-tainacan-rest-controller.php index d9224d3bc..7f5bad846 100644 --- a/src/api/class-tainacan-rest-controller.php +++ b/src/api/class-tainacan-rest-controller.php @@ -42,11 +42,9 @@ class REST_Controller extends \WP_REST_Controller { * @return \Tainacan\Entities\Entity */ protected function prepare_item_for_updating($object, $new_values){ - foreach ($new_values as $key => $value) { $object->set($key, $value); } - return $object; } @@ -84,8 +82,10 @@ class REST_Controller extends \WP_REST_Controller { 'postin' => 'post__in', 'relation' => 'relation', 'nopaging' => 'nopaging', - 'meta_key' => 'meta_key', - 'meta_type' => 'meta_type' + 'metatype' => 'meta_type', + 'hierarchical' => 'hierarchical', + 'exclude' => 'exclude', + 'excludetree' => 'exclude_tree' ]; $meta_query = [ diff --git a/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php b/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php index 9d9724649..9fd782a2c 100644 --- a/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php +++ b/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php @@ -82,6 +82,21 @@ class REST_Bulkedit_Controller extends REST_Controller { 'permission_callback' => array($this, 'bulk_edit_permissions_check'), ), ) + ); + register_rest_route($this->namespace, '/collection/(?P[\d]+)/' . $this->rest_base . '/(?P[0-9a-f]+)/set_status', + array( + array( + 'methods' => \WP_REST_Server::CREATABLE, + 'callback' => array($this, 'set_status'), + 'permission_callback' => array($this, 'bulk_edit_permissions_check'), + 'args' => [ + 'value' => [ + 'type' => 'string', + 'description' => __( 'The new status value', 'tainacan' ), + ], + ], + ), + ) ); register_rest_route($this->namespace, '/collection/(?P[\d]+)/' . $this->rest_base . '/(?P[0-9a-f]+)/set', array( @@ -221,6 +236,33 @@ class REST_Bulkedit_Controller extends REST_Controller { return $this->generic_action('replace_value', $request, ['old_value', 'new_value']); + } + + public function set_status($request) { + $body = json_decode($request->get_body(), true); + + if( !isset($body['value']) ){ + return new \WP_REST_Response([ + 'error_message' => __('Value must be provided', 'tainacan'), + ], 400); + } + + $group_id = $request['group_id']; + + $args = ['id' => $group_id]; + + $bulk = new \Tainacan\Bulk_Edit($args); + + $action = $bulk->set_status($body['value']); + + if ( is_wp_error($action) ) { + return new \WP_REST_Response([ + 'error_message' => $action->get_error_message(), + ], 400); + } else { + return new \WP_REST_Response($action, 200); + } + } public function trash_items($request) { diff --git a/src/classes/class-tainacan-bulk-edit.php b/src/classes/class-tainacan-bulk-edit.php index 4cf646312..4a7fa8f1a 100644 --- a/src/classes/class-tainacan-bulk-edit.php +++ b/src/classes/class-tainacan-bulk-edit.php @@ -141,6 +141,33 @@ class Bulk_Edit { return $wpdb->prepare( "SELECT $fields FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $this->meta_key, $this->get_id() ); } + + /** + * Sets the status to all items in the current group + * + */ + public function set_status($value) { + + if (!$this->get_id()) { + return new \WP_Error( 'no_id', __( 'Bulk Edit group not initialized', 'tainacan' ) ); + } + + $possible_values = ['draft', 'publish', 'private']; + + // Specific validation + if (!in_array($value, $possible_values)) { + return new \WP_Error( 'invalid_action', __( 'Invalid status', 'tainacan' ) ); + } + + global $wpdb; + + $select_q = $this->_build_select( 'post_id' ); + + $query = $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s WHERE ID IN ($select_q)", $value); + + return $wpdb->query($query); + + } /** * Adds a value to a metadatum to all items in the current group diff --git a/src/classes/libs/wp-background-process.php b/src/classes/libs/wp-background-process.php index 942d4ca5b..d234d7f42 100644 --- a/src/classes/libs/wp-background-process.php +++ b/src/classes/libs/wp-background-process.php @@ -452,7 +452,7 @@ if ( ! class_exists( 'WP_Background_Process' ) ) { exit; } - $this->handle(); + $this->dispatch(); exit; } diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index 4f9e0d9bb..73c2bf9db 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -245,13 +245,9 @@ class Collections extends Repository { $args = array( 'labels' => $labels, 'hierarchical' => true, - //'supports' => array('title'), - //'taxonomies' => array(self::TAXONOMY), 'public' => true, 'show_ui' => tnc_enable_dev_wp_interface(), 'show_in_menu' => tnc_enable_dev_wp_interface(), - //'menu_position' => 5, - //'show_in_nav_menus' => false, 'publicly_queryable' => true, 'exclude_from_search' => true, 'has_archive' => true, diff --git a/src/classes/repositories/class-tainacan-filters.php b/src/classes/repositories/class-tainacan-filters.php index 0d3581bfa..0c4251551 100644 --- a/src/classes/repositories/class-tainacan-filters.php +++ b/src/classes/repositories/class-tainacan-filters.php @@ -125,13 +125,9 @@ class Filters extends Repository { $args = array( 'labels' => $labels, 'hierarchical' => true, - //'supports' => array('title'), - //'taxonomies' => array(self::TAXONOMY), 'public' => true, 'show_ui' => tnc_enable_dev_wp_interface(), 'show_in_menu' => tnc_enable_dev_wp_interface(), - //'menu_position' => 5, - //'show_in_nav_menus' => false, 'publicly_queryable' => true, 'exclude_from_search' => true, 'has_archive' => true, diff --git a/src/classes/repositories/class-tainacan-items.php b/src/classes/repositories/class-tainacan-items.php index 6c8e1c71f..26e0726be 100644 --- a/src/classes/repositories/class-tainacan-items.php +++ b/src/classes/repositories/class-tainacan-items.php @@ -425,7 +425,7 @@ class Items extends Repository { $TainacanMedia = \Tainacan\Media::get_instance(); $thumb_blob = $TainacanMedia->get_pdf_cover( $filepath ); if ( $thumb_blob ) { - $thumb_id = $TainacanMedia->insert_attachment_from_blob( $thumb_blob, basename( $filepath ) . '-cover.jpg', $item->get_id() ); + $thumb_id = $TainacanMedia->insert_attachment_from_blob( $thumb_blob, basename( $filepath ) . '-cover.jpg' ); return $thumb_id; } @@ -443,7 +443,7 @@ class Items extends Repository { return $existing_thumb; } else { $TainacanMedia = \Tainacan\Media::get_instance(); - $thumb_id = $TainacanMedia->insert_attachment_from_url( $thumb_url, $item->get_id() ); + $thumb_id = $TainacanMedia->insert_attachment_from_url( $thumb_url ); update_post_meta( $item->get_id(), $meta_key, $thumb_id ); return $thumb_id; diff --git a/src/classes/repositories/class-tainacan-logs.php b/src/classes/repositories/class-tainacan-logs.php index 1a30503b7..95b03661a 100644 --- a/src/classes/repositories/class-tainacan-logs.php +++ b/src/classes/repositories/class-tainacan-logs.php @@ -141,13 +141,10 @@ class Logs extends Repository { $args = array( 'labels' => $labels, 'hierarchical' => true, - //'supports' => array('title'), - //'taxonomies' => array(self::TAXONOMY), 'public' => false, 'show_ui' => tnc_enable_dev_wp_interface(), 'show_in_menu' => tnc_enable_dev_wp_interface(), - //'menu_position' => 5, - //'show_in_nav_menus' => false, + 'show_in_nav_menus' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, diff --git a/src/classes/repositories/class-tainacan-metadata.php b/src/classes/repositories/class-tainacan-metadata.php index acb9a6547..a3c7da332 100644 --- a/src/classes/repositories/class-tainacan-metadata.php +++ b/src/classes/repositories/class-tainacan-metadata.php @@ -227,13 +227,9 @@ class Metadata extends Repository { $args = array( 'labels' => $labels, 'hierarchical' => true, - //'supports' => array('title'), - //'taxonomies' => array(self::TAXONOMY), 'public' => true, 'show_ui' => tnc_enable_dev_wp_interface(), 'show_in_menu' => tnc_enable_dev_wp_interface(), - //'menu_position' => 5, - //'show_in_nav_menus' => false, 'publicly_queryable' => true, 'exclude_from_search' => true, 'has_archive' => true, diff --git a/src/classes/repositories/class-tainacan-taxonomies.php b/src/classes/repositories/class-tainacan-taxonomies.php index 3b2d89c76..96acb22e2 100644 --- a/src/classes/repositories/class-tainacan-taxonomies.php +++ b/src/classes/repositories/class-tainacan-taxonomies.php @@ -105,13 +105,9 @@ class Taxonomies extends Repository { $args = array( 'labels' => $labels, 'hierarchical' => true, - //'supports' => array('title'), - //'taxonomies' => array(self::TAXONOMY), 'public' => true, 'show_ui' => tnc_enable_dev_wp_interface(), 'show_in_menu' => tnc_enable_dev_wp_interface(), - //'menu_position' => 5, - //'show_in_nav_menus' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'has_archive' => false, @@ -119,6 +115,7 @@ class Taxonomies extends Repository { 'can_export' => true, 'rewrite' => true, 'map_meta_cap' => true, + 'show_in_nav_menus' => false, 'capability_type' => Entities\Taxonomy::get_capability_type(), 'supports' => [ 'title', diff --git a/src/classes/repositories/class-tainacan-terms.php b/src/classes/repositories/class-tainacan-terms.php index b774498c2..c32f8137c 100644 --- a/src/classes/repositories/class-tainacan-terms.php +++ b/src/classes/repositories/class-tainacan-terms.php @@ -52,7 +52,7 @@ class Terms extends Repository { 'type' => 'integer', 'description' => __( 'The parent of the term', 'tainacan' ), 'default' => 0, - 'validation' => '' + //'validation' => '' ], 'description' => [ 'map' => 'description', @@ -60,7 +60,7 @@ class Terms extends Repository { 'type' => 'string', 'description' => __( 'The term description', 'tainacan' ), 'default' => '', - 'validation' => '' + //'validation' => '' ], 'taxonomy' => [ 'map' => 'taxonomy', @@ -139,10 +139,11 @@ class Terms extends Repository { if ( $mapped['map'] != 'termmeta' ) { $get_ = 'get_' . $prop; - if ( ! empty( $term->WP_Term->{$mapped['map']} ) ) { + if ( $term->WP_Term->{$mapped['map']} || + ($mapped['map'] == 'parent' && $term->WP_Term->{$mapped['map']} >= 0) ) { + $args[ $mapped['map'] ] = $term->$get_(); } - } } diff --git a/src/importer/class-tainacan-csv.php b/src/importer/class-tainacan-csv.php index 6087c9cc0..d77fd2a5d 100644 --- a/src/importer/class-tainacan-csv.php +++ b/src/importer/class-tainacan-csv.php @@ -29,29 +29,29 @@ class CSV extends Importer { * @inheritdoc */ public function get_source_metadata(){ - $file = new \SplFileObject( $this->tmp_file, 'r' ); - $file->seek(0); + if (($handle = fopen($this->tmp_file, "r")) !== false) { - $columns = []; - $rawColumns = str_getcsv( $file->fgets(), $this->get_option('delimiter'), $this->get_option('enclosure') ); + $rawColumns = fgetcsv($handle, 0, $this->get_option('delimiter')); + $columns = []; - if( $rawColumns ){ - foreach( $rawColumns as $index => $rawColumn ){ - - if( strpos($rawColumn,'special_') === 0 ){ - - if( $rawColumn === 'special_document' ){ - $this->set_option('document_index', $index); - } else if( $rawColumn === 'special_attachments' ){ - $this->set_option('attachment_index', $index); + if( $rawColumns ){ + foreach( $rawColumns as $index => $rawColumn ){ + + if( strpos($rawColumn,'special_') === 0 ){ + + if( $rawColumn === 'special_document' ){ + $this->set_option('document_index', $index); + } else if( $rawColumn === 'special_attachments' ){ + $this->set_option('attachment_index', $index); + } + + } else { + $columns[] = $rawColumn; } - - } else { - $columns[] = $rawColumn; } + + return $columns; } - - return $columns; } return []; @@ -62,9 +62,12 @@ class CSV extends Importer { * returns all header including special */ public function raw_source_metadata(){ - $file = new \SplFileObject( $this->tmp_file, 'r' ); - $file->seek(0); - return $file->fgetcsv( $this->get_option('delimiter') ); + + if (($handle = fopen($this->tmp_file, "r")) !== false) { + return fgetcsv($handle, 0, $this->get_option('delimiter')); + } + + return false; } /** @@ -75,29 +78,42 @@ class CSV extends Importer { $headers = $this->raw_source_metadata(); $this->add_log('Proccessing item index ' . $index . ' in collection ' . $collection_definition['id'] ); - // search the index in the file and get values - $file = new \SplFileObject( $this->tmp_file, 'r' ); - $file->setFlags(\SplFileObject::SKIP_EMPTY); - $file->seek( $index ); + + if (($handle = fopen($this->tmp_file, "r")) !== false) { + $file = $handle; + + } else { + $this->add_error_log(' Error reading the file '); + return false; + + } if( $index === 0 ){ - $file->current(); - $file->next(); - $this->add_log(' Delimiter to parse' . $this->get_option('delimiter') ); - $values = str_getcsv( $file->fgets(), $this->get_option('delimiter'), $this->get_option('enclosure') ); - }else{ - $this->add_log(' Delimiter to parse' . $this->get_option('delimiter') ); - $values = str_getcsv( rtrim($file->fgets()), $this->get_option('delimiter'), $this->get_option('enclosure') ); + // moves the pointer forward + fgetcsv($file, 0, $this->get_option('delimiter')); + + } else { + //get the pointer + $csv_pointer= $this->get_transient('csv_pointer'); + + if( $csv_pointer ){ + fseek($file, $csv_pointer); + } } + $this->add_transient('csv_last_pointer', ftell($file)); // add reference to post_process item in after_inserted_item() + $values = fgetcsv($file, 0, $this->get_option('delimiter'), $this->get_option('enclosure')); + $this->add_transient('csv_pointer', ftell($file)); // add reference for insert + if( count( $headers ) !== count( $values ) ){ $string = (is_array($values)) ? implode('::', $values ) : $values; - $this->add_log(' Mismatch count headers and row columns '); - $this->add_log(' Headers count: ' . count( $headers ) ); - $this->add_log(' Values count: ' . count( $values ) ); - $this->add_log(' Values string: ' . $string ); + $this->add_error_log(' Mismatch count headers and row columns '); + $this->add_error_log(' Headers count: ' . count( $headers ) ); + $this->add_error_log(' Values count: ' . count( $values ) ); + $this->add_error_log(' enclosure : ' . $enclosure ); + $this->add_error_log(' Values string: ' . $string ); return false; } @@ -120,7 +136,6 @@ class CSV extends Importer { } $this->add_log('Success to proccess index: ' . $index ); - $this->add_transient('actual_index', $index); // add reference for insert return $processedItem; } @@ -133,17 +148,17 @@ class CSV extends Importer { if( !empty($column_document) || !empty( $column_attachment ) ){ - $index = $this->get_transient('actual_index'); - $file = new \SplFileObject( $this->tmp_file, 'r' ); - $file->setFlags(\SplFileObject::SKIP_EMPTY); - $file->seek( $index ); - - if( $index === 0 ){ - $file->current(); - $file->next(); - } - - $values = str_getcsv( rtrim($file->fgets()), $this->get_option('delimiter'), $this->get_option('enclosure') ); + if (($handle = fopen($this->tmp_file, "r")) !== false) { + $file = $handle; + } else { + $this->add_error_log(' Error reading the file '); + return false; + } + + $csv_pointer= $this->get_transient('csv_last_pointer'); + fseek($file, $csv_pointer); + + $values = fgetcsv($file, 0, $this->get_option('delimiter'), $this->get_option('enclosure')); if( is_array($values) && !empty($column_document) ){ $this->handle_document( $values[$column_document], $inserted_item); @@ -159,14 +174,17 @@ class CSV extends Importer { * @inheritdoc */ public function get_source_number_of_items(){ - if (isset($this->tmp_file) && file_exists($this->tmp_file)) { - $file = new \SplFileObject( $this->tmp_file, 'r' ); - $file->seek(PHP_INT_MAX); - // -1 removing header - return $this->total_items = $file->key() - 1; + if ( isset($this->tmp_file) && file_exists($this->tmp_file) && ($handle = fopen($this->tmp_file, "r")) !== false) { + $cont = 0; + + while ( ($data = fgetcsv($handle, 0, $this->get_option('delimiter')) ) !== false ) { + $cont++; + } + + // does not count the header + return $cont - 1; } return false; - } @@ -329,6 +347,7 @@ class CSV extends Importer { */ private function handle_document($column_value, $item_inserted){ $TainacanMedia = \Tainacan\Media::get_instance(); + $this->items_repo->disable_logs(); if( strpos($column_value,'url:') === 0 ){ $correct_value = trim(substr($column_value, 4)); @@ -393,6 +412,8 @@ class CSV extends Importer { $this->add_log('Setting item thumbnail: ' . $thumb_id); set_post_thumbnail( $item_inserted->get_id(), (int) $thumb_id ); } + + $this->items_repo->enable_logs(); return true; @@ -403,6 +424,8 @@ class CSV extends Importer { */ private function handle_attachment( $column_value, $item_inserted){ $TainacanMedia = \Tainacan\Media::get_instance(); + + $this->items_repo->disable_logs(); $attachments = explode( $this->get_option('multivalued_delimiter'), $column_value); @@ -433,5 +456,8 @@ class CSV extends Importer { $this->add_log('Attachment file in Server imported from ' . $attachment); } } + + $this->items_repo->enable_logs(); + } } \ No newline at end of file diff --git a/src/importer/class-tainacan-importer.php b/src/importer/class-tainacan-importer.php index 815717ca6..1667a1725 100644 --- a/src/importer/class-tainacan-importer.php +++ b/src/importer/class-tainacan-importer.php @@ -763,6 +763,7 @@ abstract class Importer { */ public function insert( $processed_item, $collection_index ) { + remove_action( 'post_updated', 'wp_save_post_revision' ); $collections = $this->get_collections(); $collection_definition = isset($collections[$collection_index]) ? $collections[$collection_index] : false; if ( !$collection_definition || !is_array($collection_definition) || !isset($collection_definition['id']) || !isset($collection_definition['mapping']) ) { @@ -778,6 +779,7 @@ abstract class Importer { $Tainacan_Items->disable_logs(); $Tainacan_Metadata->disable_logs(); + $Tainacan_Item_Metadata->disable_logs(); $item = new Entities\Item(); $itemMetadataArray = []; diff --git a/src/importer/class-tainacan-old-tainacan.php b/src/importer/class-tainacan-old-tainacan.php index 40252ff01..34f482a79 100644 --- a/src/importer/class-tainacan-old-tainacan.php +++ b/src/importer/class-tainacan-old-tainacan.php @@ -272,7 +272,8 @@ class Old_Tainacan extends Importer{ * @return Tainacan\Entities\Item Item inserted */ public function insert( $processed_item, $collection_index ) { - $collection_id = $processed_item['collection_definition']; + $this->items_repo->disable_logs(); + $collection_id = $processed_item['collection_definition']; $item_Old = $processed_item['item']->item; $collection = new Entities\Collection($collection_id['id']); @@ -321,6 +322,7 @@ class Old_Tainacan extends Importer{ */ public function add_item_metadata( $item, $metadata_old, $collection_id ){ $relationships = []; + $this->item_metadata_repo->disable_logs(); foreach( $metadata_old as $metadatum ){ diff --git a/src/importer/class-tainacan-test-importer.php b/src/importer/class-tainacan-test-importer.php index c9f1bb34b..87939c297 100644 --- a/src/importer/class-tainacan-test-importer.php +++ b/src/importer/class-tainacan-test-importer.php @@ -287,7 +287,7 @@ class Test_Importer extends Importer {
-

+

@@ -595,6 +595,10 @@ class Test_Importer extends Importer { } + /** + * Example of a method that takes a long time to run + * and may run through multiple requests + */ public function finish_processing() { $this->add_log('finish_processing'); @@ -651,7 +655,7 @@ class Test_Importer extends Importer { $inserted_item->set_document( $id ); $inserted_item->set_document_type( 'attachment' ); - $this->add_log('Document URL imported from ' . $correct_value); + $this->add_log('Document URL imported from ' . $url); if( $inserted_item->validate() ) { $inserted_item = $this->items_repo->update($inserted_item); diff --git a/src/js/event-bus-search.js b/src/js/event-bus-search.js index 2416dfb33..b6083cf0c 100644 --- a/src/js/event-bus-search.js +++ b/src/js/event-bus-search.js @@ -159,8 +159,7 @@ export default { } this.loadItems(to); - } - + } } }, methods: { @@ -192,15 +191,14 @@ export default { this.updateURLQueries(); }, addFetchOnly( metadatum ){ - let prefsFetchOnly = this.collectionId != undefined ? 'fetch_only_' + this.collectionId : 'fetch_only'; - - if(this.$userPrefs.get(prefsFetchOnly) != metadatum) { - this.$userPrefs.set(prefsFetchOnly, metadatum) - .catch(() => {}); - } - this.$store.dispatch('search/add_fetchonly', metadatum ); - this.updateURLQueries(); + this.updateURLQueries(); + + let prefsFetchOnly = this.collectionId != undefined ? 'fetch_only_' + this.collectionId : 'fetch_only'; + if (JSON.stringify(this.$userPrefs.get(prefsFetchOnly)) != JSON.stringify(metadatum)) { + this.$userPrefs.set(prefsFetchOnly, metadatum) + .catch(() => { this.$console.log("Error setting user prefs for fetch_only"); }); + } }, cleanFetchOnly() { this.$store.dispatch('search/cleanFetchOnly'); @@ -228,14 +226,14 @@ export default { this.updateURLQueries(); }, setItemsPerPage(itemsPerPage) { + this.$store.dispatch('search/setItemsPerPage', itemsPerPage); + this.updateURLQueries(); + let prefsPerPage = this.collectionId != undefined ? 'items_per_page_' + this.collectionId : 'items_per_page'; if(this.$userPrefs.get(prefsPerPage) != itemsPerPage) { this.$userPrefs.set(prefsPerPage, itemsPerPage) .catch(() => {}); } - - this.$store.dispatch('search/setItemsPerPage', itemsPerPage); - this.updateURLQueries(); }, setOrderBy(orderBy) { let prefsOrderBy = this.collectionId != undefined ? 'order_by_' + this.collectionId : 'order_by'; @@ -265,24 +263,24 @@ export default { this.updateURLQueries(); }, setViewMode(viewMode) { + this.$store.dispatch('search/setViewMode', viewMode); + this.updateURLQueries(); + let prefsViewMode = this.collectionId != undefined ? 'view_mode_' + this.collectionId : 'view_mode'; if(this.$userPrefs.get(prefsViewMode) != viewMode) { this.$userPrefs.set(prefsViewMode, viewMode) .catch(() => {}); } - - this.$store.dispatch('search/setViewMode', viewMode); - this.updateURLQueries(); }, setAdminViewMode(adminViewMode) { + this.$store.dispatch('search/setAdminViewMode', adminViewMode); + this.updateURLQueries(); + let prefsAdminViewMode = this.collectionId != undefined ? 'admin_view_mode_' + this.collectionId : 'admin_view_mode'; if(this.$userPrefs.get(prefsAdminViewMode) != adminViewMode) { this.$userPrefs.set(prefsAdminViewMode, adminViewMode) - .catch(() => { }); + .catch(() => { }); } - - this.$store.dispatch('search/setAdminViewMode', adminViewMode); - this.updateURLQueries(); }, setInitialViewMode(viewMode) { this.$store.dispatch('search/setViewMode', viewMode); diff --git a/src/js/store/modules/search/actions.js b/src/js/store/modules/search/actions.js index 320c63673..1d87db5a7 100644 --- a/src/js/store/modules/search/actions.js +++ b/src/js/store/modules/search/actions.js @@ -79,16 +79,16 @@ export const setOrderBy = ({ state, commit }, orderBy ) => { } else if (orderBy.slug == 'author_name') { commit('setPostQueryAttribute', { attr: 'orderby', value: 'author_name' } ); } else if (orderBy.metadata_type_object.primitive_type == 'float' || orderBy.metadata_type_object.primitive_type == 'int') { - commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } ); + commit('setPostQueryAttribute', { attr: 'metakey', value: orderBy.id } ); commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value_num' } ); } else if (orderBy.metadata_type_object.primitive_type == 'date') { - commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } ); - commit('setPostQueryAttribute', { attr: 'meta_type', value: 'DATETIME' } ); + commit('setPostQueryAttribute', { attr: 'metakey', value: orderBy.id } ); + commit('setPostQueryAttribute', { attr: 'metatype', value: 'DATETIME' } ); commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value' } ); } else if (orderBy.metadata_type_object.core) { commit('setPostQueryAttribute', { attr: 'orderby', value: orderBy.metadata_type_object.related_mapped_prop } ); } else { - commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } ); + commit('setPostQueryAttribute', { attr: 'metakey', value: orderBy.id } ); commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value' } ); } diff --git a/src/js/store/modules/taxonomy/actions.js b/src/js/store/modules/taxonomy/actions.js index dfff48957..a5f8d1701 100644 --- a/src/js/store/modules/taxonomy/actions.js +++ b/src/js/store/modules/taxonomy/actions.js @@ -301,3 +301,28 @@ export const clearTerms = ({ commit }) => { commit('clearTerms'); }; +// Used only on Term Edition form, for autocomplete searhc for parents +export const fetchPossibleParentTerms = ({ commit }, { taxonomyId, termId, search } ) => { + return new Promise((resolve, reject) => { + axios.tainacan.get('/taxonomy/' + taxonomyId + '/terms?searchterm=' + search + '&hierarchical=1&exclude_tree=' + termId + "&hideempty=0&offset=0&number=20") + .then(res => { + let parentTerms = res.data; + resolve( parentTerms ); + }) + .catch(error => { + reject( error ); + }); + }); +}; +export const fetchParentName = ({ commit }, { taxonomyId, parentId } ) => { + return new Promise((resolve, reject) => { + axios.tainacan.get('/taxonomy/' + taxonomyId + '/terms/' + parentId + '?fetch_only=name') + .then(res => { + let parentName = res.data.name; + resolve( parentName ); + }) + .catch(error => { + reject( error ); + }); + }); +}; diff --git a/src/theme-helper/template-tags.php b/src/theme-helper/template-tags.php index c210a19ea..cd53d40c3 100644 --- a/src/theme-helper/template-tags.php +++ b/src/theme-helper/template-tags.php @@ -70,7 +70,7 @@ function tainacan_get_the_document() { if (!$item) return; - return $item->get_document_html(); + return apply_filters('tainacan-get-the-document', $item->get_document_html(), $item); } @@ -140,7 +140,7 @@ function tainacan_get_the_collection_name() { if ( $collection ) { $name = $collection->get_name(); } - return $name; + return apply_filters('tainacan-get-collection-name', $name, $collection); } /** @@ -163,7 +163,7 @@ function tainacan_get_the_collection_description() { if ( $collection ) { $description = $collection->get_description(); } - return $description; + return apply_filters('tainacan-get-collection-description', $description, $collection); } /** @@ -221,6 +221,52 @@ function tainacan_get_term() { return false; } +/** + * When visiting a taxonomy archive, returns the term name + * + * @return string + */ +function tainacan_get_the_term_name() { + $term = tainacan_get_term(); + $name = ''; + if ( $term ) { + $name = $term->name; + } + return apply_filters('tainacan-get-term-name', $name, $term); +} + +/** + * When visiting a taxonomy archive, prints the term name + * + * @return void + */ +function tainacan_the_term_name() { + echo tainacan_get_the_term_name(); +} + +/** + * When visiting a taxonomy archive, returns the term description + * + * @return string + */ +function tainacan_get_the_term_description() { + $term = tainacan_get_term(); + $description = ''; + if ( $term ) { + $description = $term->description; + } + return apply_filters('tainacan-get-term-description', $description, $term); +} + +/** + * When visiting a taxonomy archive, prints the term description + * + * @return void + */ +function tainacan_the_term_description() { + echo tainacan_get_the_term_description(); +} + /** * @see \Tainacan\Theme_Helper->register_view_mode() */ @@ -310,5 +356,6 @@ function tainacan_get_initials($string, $one = false) { $second = $words[ sizeof($words) - 1 ][0]; } - return strtoupper($first . $second); + $result = strtoupper($first . $second); + return apply_filters('tainacan-get-initials', $result, $string, $one); } \ No newline at end of file diff --git a/src/theme-helper/view-mode-cards.vue b/src/theme-helper/view-mode-cards.vue index c72767565..08886ae65 100644 --- a/src/theme-helper/view-mode-cards.vue +++ b/src/theme-helper/view-mode-cards.vue @@ -87,7 +87,8 @@ export default { collectionId: Number, displayedMetadata: Array, items: Array, - isLoading: false + isLoading: false, + shouldUseSmallCard: false }, data () { return { @@ -111,7 +112,8 @@ export default { } }, getLimitedDescription(description) { - return description.length > 300 ? description.substring(0, 297) + '...' : description; + let maxCharacter = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) <= 480 ? 155 : 330; + return description.length > maxCharacter ? description.substring(0, maxCharacter - 3) + '...' : description; } } } @@ -121,10 +123,11 @@ export default { $turquoise1: #e6f6f8; $turquoise2: #d1e6e6; $tainacan-input-color: #1d1d1d; + $gray1: #f2f2f2; $gray2: #e5e5e5; - $gray4: #898d8f; $gray3: #dcdcdc; - $gray4: #898d8f; + $gray4: #898d8f; + $gray5: #454647; @import "../../src/admin/scss/_view-mode-cards.scss"; diff --git a/src/theme-helper/view-mode-records.vue b/src/theme-helper/view-mode-records.vue index 068019c34..ff2bc5619 100644 --- a/src/theme-helper/view-mode-records.vue +++ b/src/theme-helper/view-mode-records.vue @@ -125,10 +125,11 @@ export default { $turquoise1: #e6f6f8; $turquoise2: #d1e6e6; $tainacan-input-color: #1d1d1d; + $gray1: #f2f2f2; $gray2: #e5e5e5; - $gray4: #898d8f; $gray3: #dcdcdc; - $gray4: #898d8f; + $gray4: #898d8f; + $gray5: #454647; @import "../../src/admin/scss/_view-mode-records.scss"; diff --git a/tests/test-bulkedit.php b/tests/test-bulkedit.php index 41b87ec72..d736cf1b5 100644 --- a/tests/test-bulkedit.php +++ b/tests/test-bulkedit.php @@ -605,6 +605,35 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { $this->assertEquals(20, $items->found_posts); } + + function test_set_status() { + $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); + + $ids = array_slice($this->items_ids, 4, 11); + + $bulk = new \Tainacan\Bulk_Edit([ + 'items_ids' => $ids, + ]); + + $id = $bulk->get_id(); + + $bulk->set_status('draft'); + + $items = $Tainacan_Items->fetch([ + 'status' => 'draft', + 'posts_per_page' => -1 + ]); + + $this->assertEquals(11, $items->found_posts); + + $items = $Tainacan_Items->fetch([ + 'publish' => 'draft', + 'posts_per_page' => -1 + ]); + + $this->assertEquals(29, $items->found_posts); + + } function test_set_regular_multi_meta() { @@ -840,6 +869,42 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { $this->assertEquals(14, $items->found_posts); + } + + /** + * @group api + */ + public function test_api_set_status() { + + $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); + + $ids = array_slice($this->items_ids, 2, 14); + + $bulk = new \Tainacan\Bulk_Edit([ + 'items_ids' => $ids, + ]); + + $body = json_encode([ + 'value' => 'private' + ]); + + + $request = new \WP_REST_Request( + 'POST', $this->api_baseroute . '/' . $bulk->get_id() . '/set_status' + ); + + $request->set_body( $body ); + + $response = $this->server->dispatch($request); + + $items = $Tainacan_Items->fetch([ + 'status' => 'private', + 'posts_per_page' => -1 + ]); + + $this->assertEquals(14, $items->found_posts); + + } /** diff --git a/tests/test-importer.php b/tests/test-importer.php index 7542cb7ca..1a9a59392 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -262,7 +262,11 @@ class ImporterTests extends TAINACAN_UnitTestCase { // Sample data $data = array( array('Data 11', 'Data 12', 'Data 13||TESTE', 'Data 14', 'Data 15'), - array('Data 21', 'Data 22', 'Data 23', 'Data 24', 'Data 25'), + array('Data 21', 'Data 22', 'this + is + having + multiple + lines', 'Data 24', 'Data 25'), array('Data 31', 'Data 32', utf8_decode( 'Data 33||Rééço' ), 'Data 34', 'Data 35'), array('Data 41', 'Data 42', 'Data 43||limbbo', 'Data 44', 'Data 45'), array('Data 51', 'Data 52', 'Data 53', 'Data 54', 'Data 55')