From d3b8e4c4b8b155edd2234cb82a6c982091e608db Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Mon, 11 Jun 2018 16:04:44 -0300 Subject: [PATCH 1/7] Begins implamentation of new Collection Edition Form. --- .../edition/collection-edition-form.vue | 364 +++++++++--------- src/admin/scss/_tainacan-form.scss | 2 + src/admin/scss/_variables.scss | 2 +- src/admin/theme-items-list.vue | 6 +- .../filter-types/tainacan-filter-item.vue | 1 + 5 files changed, 196 insertions(+), 179 deletions(-) diff --git a/src/admin/components/edition/collection-edition-form.vue b/src/admin/components/edition/collection-edition-form.vue index 615cf338c..265247694 100644 --- a/src/admin/components/edition/collection-edition-form.vue +++ b/src/admin/components/edition/collection-edition-form.vue @@ -8,8 +8,39 @@ class="tainacan-form" label-width="120px"> -
-
+ + +
+ + + +
+ {{ $i18n.get('label_empty_header_image') }} + +
+
+ + + +
+
+
+ +
+
-
+
{{ $i18n.get('label_empty_thumbnail') }} @@ -42,94 +73,6 @@
- - - -
- - - -
- {{ $i18n.get('label_empty_header_image') }} - -
-
- - - -
-
-
-
-
- - - - - - - - - - - - - - - - - - -
@@ -192,6 +135,122 @@
+ +
+ + +
+ + + + + {{ registeredViewModes[viewMode].label }} + + + +
+
+ + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + - - -
- - -
- - - - - {{ registeredViewModes[viewMode].label }} - - - -
-
- - - - - - - - -
@@ -750,10 +750,30 @@ export default { .field { position: relative; } - + #button-edit-thumbnail, #button-edit-header-image { + + border-radius: 100px !important; + height: 40px !important; + width: 40px !important; + bottom: -20px; + left: -20px; + z-index: 99; + + .icon { + display: inherit; + padding: 0; + margin: 0; + margin-top: 1px; + } + } + .header-field { + img { + padding: 20px; + } + } .thumbnail-field { - max-height: 128px; - margin-bottom: 96px; + max-height: 208px; + margin-bottom: 180px; margin-top: -20px; .content { @@ -761,7 +781,11 @@ export default { font-size: 0.8em; } img { + border-radius: 100px; position: absolute; + height: 178px; + width: 178px; + padding: 20px; } .image-placeholder { position: absolute; @@ -774,34 +798,20 @@ export default { text-align: center; color: gray; } - #button-edit-thumbnail, #button-edit-header-image { - - border-radius: 100px !important; - height: 40px !important; - width: 40px !important; - bottom: -20px; - left: -20px; - z-index: 99; - - .icon { - display: inherit; - padding: 0; - margin: 0; - margin-top: 1px; - } - } + .thumbnail-buttons-row { - display: none; + visibility: hidden; + display: inline-block; + position: relative; + top: -20px; + background-color: rgba(255, 255, 255, 0.9); + padding: 2px 8px; + border-radius: 0px 0px 0px 4px; + left: 88px; } &:hover { .thumbnail-buttons-row { - display: inline-block; - position: relative; - top: -128px; - background-color: rgba(255, 255, 255, 0.9); - padding: 2px 8px; - border-radius: 0px 0px 0px 4px; - left: 88px; + visibility: visible; } } } diff --git a/src/admin/scss/_tainacan-form.scss b/src/admin/scss/_tainacan-form.scss index cf110e5e0..79421f6ff 100644 --- a/src/admin/scss/_tainacan-form.scss +++ b/src/admin/scss/_tainacan-form.scss @@ -19,6 +19,8 @@ font-size: 14px; display: inline-block; white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; } .required-metadatum-asterisk { color: $gray; diff --git a/src/admin/scss/_variables.scss b/src/admin/scss/_variables.scss index fc3efb7c0..df1e157b1 100644 --- a/src/admin/scss/_variables.scss +++ b/src/admin/scss/_variables.scss @@ -65,7 +65,7 @@ $header-height: 53px; $subheader-height: 82px; $side-menu-width: 180px; $filter-menu-width: 200px; -$filter-menu-width-theme: 270px; +$filter-menu-width-theme: 20.833333333%; $page-height: calc(100% - 53px); // Overall Pages padding: diff --git a/src/admin/theme-items-list.vue b/src/admin/theme-items-list.vue index cea0e167b..8b680a3c8 100644 --- a/src/admin/theme-items-list.vue +++ b/src/admin/theme-items-list.vue @@ -287,7 +287,11 @@ export default { min-width: $filter-menu-width-theme; background-color: unset; border-right: 0; - padding: 25px 25px 25px 4.1666667%; + padding: 25px 12px 25px 4.1666667%; + + .columns { + display: flex; + } } .search-control { diff --git a/src/classes/filter-types/tainacan-filter-item.vue b/src/classes/filter-types/tainacan-filter-item.vue index a4042a9d3..35c8181e1 100644 --- a/src/classes/filter-types/tainacan-filter-item.vue +++ b/src/classes/filter-types/tainacan-filter-item.vue @@ -201,6 +201,7 @@ font-weight: normal; font-size: 14px; display: inline-flex; + width: 100%; } .input, .textarea, .taginput-container { From 919c5e65e6c73eb8cd529a98955ecb10165eaadc Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Tue, 12 Jun 2018 10:06:06 -0300 Subject: [PATCH 2/7] More css adjustments. Limites shrinking header class changes to avoid DOM manipulations. --- .../edition/category-edition-form.vue | 3 --- .../edition/collection-edition-form.vue | 26 ++++++++++--------- .../edition/filter-edition-form.vue | 2 -- .../components/edition/item-edition-form.vue | 7 ++--- .../edition/metadatum-edition-form.vue | 2 -- .../components/edition/term-edition-form.vue | 2 -- src/admin/components/lists/metadata-list.vue | 2 +- src/admin/pages/lists/events-page.vue | 2 +- src/admin/pages/lists/items-page.vue | 9 ++----- src/admin/pages/singles/collection-page.vue | 8 ++++-- src/admin/scss/_tainacan-form.scss | 6 ----- 11 files changed, 26 insertions(+), 43 deletions(-) diff --git a/src/admin/components/edition/category-edition-form.vue b/src/admin/components/edition/category-edition-form.vue index a01ebcd6d..316496563 100644 --- a/src/admin/components/edition/category-edition-form.vue +++ b/src/admin/components/edition/category-edition-form.vue @@ -19,7 +19,6 @@ :title="$i18n.getHelperTitle('categories', 'name')" :message="$i18n.getHelperMessage('categories', 'name')"/> - + + - +
@@ -671,7 +668,7 @@ export default { }, mounted() { document.getElementById('collection-page-container').addEventListener('scroll', ($event) => { - this.$emit('onShrinkHeader', ($event.originalTarget.scrollTop > 53)); + this.$emit('onShrinkHeader', ($event.target.scrollTop > 53)); }); }, beforeRouteLeave ( to, from, next ) { diff --git a/src/admin/components/edition/metadatum-edition-form.vue b/src/admin/components/edition/metadatum-edition-form.vue index 588998805..e849912bd 100644 --- a/src/admin/components/edition/metadatum-edition-form.vue +++ b/src/admin/components/edition/metadatum-edition-form.vue @@ -18,7 +18,6 @@ :message="$i18n.getHelperMessage('metadata', 'name')"/> @@ -35,7 +34,6 @@ :message="$i18n.getHelperMessage('metadata', 'description')"/> @@ -78,7 +77,6 @@ :message="$i18n.get('info_help_term_description')"/> { - this.$emit('onShrinkHeader', ($event.originalTarget.scrollTop > 53)); + this.$emit('onShrinkHeader', ($event.target.scrollTop > 53)); }); } } diff --git a/src/admin/pages/lists/events-page.vue b/src/admin/pages/lists/events-page.vue index 2f16e9447..c77aa47c1 100644 --- a/src/admin/pages/lists/events-page.vue +++ b/src/admin/pages/lists/events-page.vue @@ -148,7 +148,7 @@ if (!this.isRepositoryLevel) { document.getElementById('collection-page-container').addEventListener('scroll', ($event) => { - this.$emit('onShrinkHeader', ($event.originalTarget.scrollTop > 53)); + this.$emit('onShrinkHeader', ($event.target.scrollTop > 53)); }); } } diff --git a/src/admin/pages/lists/items-page.vue b/src/admin/pages/lists/items-page.vue index 7148588ae..318097305 100644 --- a/src/admin/pages/lists/items-page.vue +++ b/src/admin/pages/lists/items-page.vue @@ -700,7 +700,7 @@ // Watch Scroll for shrinking header, only on Admin at collection level if (!this.isRepositoryLevel && !this.isOnTheme) { document.getElementById('items-list-area').addEventListener('scroll', ($event) => { - this.isHeaderShrinked = ($event.originalTarget.scrollTop > 53); + this.isHeaderShrinked = ($event.target.scrollTop > 53); this.$emit('onShrinkHeader', this.isHeaderShrinked); }); } @@ -771,18 +771,13 @@ .control { width: 100%; - - input { - height: 27px; - font-size: 11px; - color: $gray-light; - } .icon { pointer-events: all; cursor: pointer; color: $tertiary; height: 27px; font-size: 18px !important; + height: 2rem !important; } margin-bottom: 5px; } diff --git a/src/admin/pages/singles/collection-page.vue b/src/admin/pages/singles/collection-page.vue index 370f5aa7b..d0fcb9af7 100644 --- a/src/admin/pages/singles/collection-page.vue +++ b/src/admin/pages/singles/collection-page.vue @@ -5,7 +5,7 @@ :class="{ 'is-shrink': shouldShrinkHeader }" :id="collectionId"/> Date: Tue, 12 Jun 2018 11:06:42 -0300 Subject: [PATCH 3/7] Adds new metadatum primitive type long_text and attributes it to textarea metadatum_type. Removes access to ClassName in some frontend parts of admin in favor to primitive_type access (Closes #66). --- src/admin/components/lists/filters-list.vue | 4 +-- src/admin/components/lists/items-list.vue | 23 +++++++++++------ src/admin/components/lists/metadata-list.vue | 4 +-- .../class-tainacan-autocomplete.php | 2 +- .../checkbox/class-tainacan-checkbox.php | 2 +- .../selectbox/class-tainacan-selectbox.php | 2 +- .../taginput/class-tainacan-taginput.php | 2 +- .../textarea/class-tainacan-textarea.php | 2 +- src/theme-helper/table-view-mode.vue | 25 +++++++++++++------ 9 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/admin/components/lists/filters-list.vue b/src/admin/components/lists/filters-list.vue index 898b26680..0fbfdef3a 100644 --- a/src/admin/components/lists/filters-list.vue +++ b/src/admin/components/lists/filters-list.vue @@ -319,7 +319,7 @@ export default { for (let filter of this.filterTypes) { for (let supportedType of filter['supported_types']) { - if (choosenMetadatum.metadata_type_object.primitive_type == supportedType) + if (choosenMetadatum.metadatum_type_object.primitive_type == supportedType) this.allowedFilterTypes.push(filter); } } @@ -462,7 +462,7 @@ export default { mounted() { if (!this.isRepositoryLevel) { document.getElementById('collection-page-container').addEventListener('scroll', ($event) => { - this.$emit('onShrinkHeader', ($event.originalTarget.scrollTop > 53)); + this.$emit('onShrinkHeader', ($event.target.scrollTop > 53)); }); } } diff --git a/src/admin/components/lists/items-list.vue b/src/admin/components/lists/items-list.vue index 4d7450188..d9ffd6f7d 100644 --- a/src/admin/components/lists/items-list.vue +++ b/src/admin/components/lists/items-list.vue @@ -193,9 +193,13 @@ class="column-default-width" :class="{ 'thumbnail-cell': column.metadatum == 'row_thumbnail', - 'column-small-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Date' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Numeric') : false, - 'column-medium-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Selectbox' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Category' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Compound') : false, - 'column-large-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Textarea') : false, + 'column-small-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'date' || + column.metadata_type_object.primitive_type == 'float' || + column.metadata_type_object.primitive_type == 'int') : false, + 'column-medium-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'term' || + column.metadata_type_object.primitive_type == 'item' || + column.metadata_type_object.primitive_type == 'compound') : false, + 'column-large-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'long_string' || column.metadata_type_object.related_mapped_prop == 'description') : false, }" :custom-key="column.slug">
{{ column.name }}
@@ -230,10 +234,15 @@ :class="{ 'thumbnail-cell': column.metadatum == 'row_thumbnail', 'column-main-content' : column.metadata_type_object != undefined ? (column.metadata_type_object.related_mapped_prop == 'title') : false, - 'column-needed-width column-align-right' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Numeric') : false, - 'column-small-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Date' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Numeric') : false, - 'column-medium-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Selectbox' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Category' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Compound') : false, - 'column-large-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Textarea') : false, + 'column-needed-width column-align-right' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'float' || + column.metadata_type_object.primitive_type == 'int' ) : false, + 'column-small-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'date' || + column.metadata_type_object.primitive_type == 'int' || + column.metadata_type_object.primitive_type == 'float') : false, + 'column-medium-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'item' || + column.metadata_type_object.primitive_type == 'term' || + column.metadata_type_object.primitive_type == 'compound') : false, + 'column-large-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'long_string' || column.metadata_type_object.related_mapped_prop == 'description') : false, }" @click="goToItemPage(item)"> diff --git a/src/admin/components/lists/metadata-list.vue b/src/admin/components/lists/metadata-list.vue index a663349de..087a93960 100644 --- a/src/admin/components/lists/metadata-list.vue +++ b/src/admin/components/lists/metadata-list.vue @@ -84,8 +84,8 @@
diff --git a/src/classes/filter-types/autocomplete/class-tainacan-autocomplete.php b/src/classes/filter-types/autocomplete/class-tainacan-autocomplete.php index 60ced30b3..da183cb25 100644 --- a/src/classes/filter-types/autocomplete/class-tainacan-autocomplete.php +++ b/src/classes/filter-types/autocomplete/class-tainacan-autocomplete.php @@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); class Autocomplete extends Filter_Type { function __construct(){ - $this->set_supported_types(['string','item']); + $this->set_supported_types(['string','long_string','item']); $this->set_component('tainacan-filter-autocomplete'); } diff --git a/src/classes/filter-types/checkbox/class-tainacan-checkbox.php b/src/classes/filter-types/checkbox/class-tainacan-checkbox.php index 61c79bdf3..9057ad14b 100644 --- a/src/classes/filter-types/checkbox/class-tainacan-checkbox.php +++ b/src/classes/filter-types/checkbox/class-tainacan-checkbox.php @@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); class Checkbox extends Filter_Type { function __construct(){ - $this->set_supported_types(['string','item']); + $this->set_supported_types(['string','long_string','item']); $this->set_component('tainacan-filter-checkbox'); } diff --git a/src/classes/filter-types/selectbox/class-tainacan-selectbox.php b/src/classes/filter-types/selectbox/class-tainacan-selectbox.php index e9a24db88..26c1c17b3 100644 --- a/src/classes/filter-types/selectbox/class-tainacan-selectbox.php +++ b/src/classes/filter-types/selectbox/class-tainacan-selectbox.php @@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); class Selectbox extends Filter_Type { function __construct(){ - $this->set_supported_types(['string']); + $this->set_supported_types(['string', 'long_string']); $this->set_component('tainacan-filter-selectbox'); } diff --git a/src/classes/filter-types/taginput/class-tainacan-taginput.php b/src/classes/filter-types/taginput/class-tainacan-taginput.php index 2b13bdc73..f20c55b77 100644 --- a/src/classes/filter-types/taginput/class-tainacan-taginput.php +++ b/src/classes/filter-types/taginput/class-tainacan-taginput.php @@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); class Taginput extends Filter_Type { function __construct(){ - $this->set_supported_types(['string','item']); + $this->set_supported_types(['string','long_string','item']); $this->set_component('tainacan-filter-taginput'); } diff --git a/src/classes/metadata-types/textarea/class-tainacan-textarea.php b/src/classes/metadata-types/textarea/class-tainacan-textarea.php index 70ff0557a..18997da3c 100644 --- a/src/classes/metadata-types/textarea/class-tainacan-textarea.php +++ b/src/classes/metadata-types/textarea/class-tainacan-textarea.php @@ -12,7 +12,7 @@ class Textarea extends Metadata_Type { function __construct(){ // call metadatum type constructor parent::__construct(); - $this->set_primitive_type('string'); + $this->set_primitive_type('long_string'); $this->set_component('tainacan-textarea'); } diff --git a/src/theme-helper/table-view-mode.vue b/src/theme-helper/table-view-mode.vue index 695b12e99..0a95fe89e 100644 --- a/src/theme-helper/table-view-mode.vue +++ b/src/theme-helper/table-view-mode.vue @@ -11,10 +11,14 @@ v-if="column.display" class="column-default-width" :class="{ - 'thumbnail-cell': column.metadatum == 'row_thumbnail', - 'column-small-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Date' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Numeric') : false, - 'column-medium-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Selectbox' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Category' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Compound') : false, - 'column-large-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Textarea') : false, + 'thumbnail-cell': column.metadatum == 'row_thumbnail', + 'column-small-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'date' || + column.metadata_type_object.primitive_type == 'float' || + column.metadata_type_object.primitive_type == 'int') : false, + 'column-medium-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'term' || + column.metadata_type_object.primitive_type == 'item' || + column.metadata_type_object.primitive_type == 'compound') : false, + 'column-large-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'long_string' || column.metadata_type_object.related_mapped_prop == 'description') : false, }" :custom-key="column.slug">
{{ column.name }}
@@ -38,10 +42,15 @@ :class="{ 'thumbnail-cell': column.metadatum == 'row_thumbnail', 'column-main-content' : column.metadata_type_object != undefined ? (column.metadata_type_object.related_mapped_prop == 'title') : false, - 'column-needed-width column-align-right' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Numeric') : false, - 'column-small-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Date' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Numeric') : false, - 'column-medium-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Selectbox' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Category' || column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Compound') : false, - 'column-large-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.className == 'Tainacan\\Metadata_Types\\Textarea') : false, + 'column-needed-width column-align-right' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'float' || + column.metadata_type_object.primitive_type == 'int' ) : false, + 'column-small-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'date' || + column.metadata_type_object.primitive_type == 'int' || + column.metadata_type_object.primitive_type == 'float') : false, + 'column-medium-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'item' || + column.metadata_type_object.primitive_type == 'term' || + column.metadata_type_object.primitive_type == 'compound') : false, + 'column-large-width' : column.metadata_type_object != undefined ? (column.metadata_type_object.primitive_type == 'long_string' || column.metadata_type_object.related_mapped_prop == 'description') : false, }" @click="goToItemPage(item)"> From 7e78668225f33a3f2e0903fd80c341f811454cf2 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Tue, 12 Jun 2018 11:44:42 -0300 Subject: [PATCH 4/7] store core metadata values also in metadata table --- .../class-tainacan-item-metadata.php | 8 +++- tests/test-core-metadatum-types.php | 41 +++++++++---------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/classes/repositories/class-tainacan-item-metadata.php b/src/classes/repositories/class-tainacan-item-metadata.php index 8e5f28dce..b6630e924 100644 --- a/src/classes/repositories/class-tainacan-item-metadata.php +++ b/src/classes/repositories/class-tainacan-item-metadata.php @@ -48,9 +48,15 @@ class Item_Metadata extends Repository { $unique = !$item_metadata->is_multiple(); $metadata_type = $item_metadata->get_metadatum()->get_metadata_type_object(); + if ($metadata_type->get_core()) { $this->save_core_metadatum_value($item_metadata); - } elseif ($metadata_type->get_primitive_type() == 'term') { + // Core metadata are also stored as regular metadata (in the code following below) + // This is usefull to create queries via filters, advanced search or apis + // si you can search for title and content with meta_query as if they were regular metadata + } + + if ($metadata_type->get_primitive_type() == 'term') { $this->save_terms_metadatum_value($item_metadata); } elseif ($metadata_type->get_primitive_type() == 'compound') { // do nothing. Compound values are updated when its child metadata are updated diff --git a/tests/test-core-metadatum-types.php b/tests/test-core-metadatum-types.php index dfeb730bd..e5eac0888 100644 --- a/tests/test-core-metadatum-types.php +++ b/tests/test-core-metadatum-types.php @@ -24,32 +24,15 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase { $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( - 'name' => 'test', + 'name' => 'test', + 'status' => 'publish' ), true ); - $metadatum = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadado', - 'description' => 'title', - 'collection' => $collection, - 'metadata_type' => 'Tainacan\Metadata_Types\Core_Title' - ), - true - ); + $metadatum = $collection->get_core_title_metadatum(); - $metadatumDescription = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadado_desc', - 'description' => 'description', - 'collection' => $collection, - 'metadata_type' => 'Tainacan\Metadata_Types\Core_Description' - ), - true - ); + $metadatumDescription = $collection->get_core_description_metadatum(); $i = $this->tainacan_entity_factory->create_entity( @@ -57,7 +40,8 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase { array( 'title' => 'item test', 'description' => 'adasdasdsa', - 'collection' => $collection + 'collection' => $collection, + 'status' => 'publish' ), true ); @@ -90,6 +74,19 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase { $check_item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($checkItem, $metadatumDescription); $this->assertEquals('changed description', $check_item_metadata->get_value()); + + // check that the value was also stored in postmeta table + $checkMeta = $Tainacan_Items->fetch([ + 'meta_query' => [ + [ + 'key' => $metadatumDescription->get_id(), + 'value' => 'changed description' + ] + ] + ], [], 'OBJECT'); + + $this->assertEquals(1, sizeof($checkMeta)); + $this->assertEquals('changed description', $checkMeta[0]->get_description()); } From c56f8fd12dc011c5fc9db000ba36eb491cdf69e0 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Tue, 12 Jun 2018 12:59:31 -0300 Subject: [PATCH 5/7] Makes ViewModeCards a component instead of a template. --- .../components/navigation/tainacan-title.vue | 2 +- src/admin/js/theme-main.js | 7 +- src/admin/pages/lists/items-page.vue | 8 +- .../class-tainacan-theme-helper.php | 10 +- src/theme-helper/view-mode-cards.vue | 96 +++++++++++++++++++ ...able-view-mode.vue => view-mode-table.vue} | 8 +- 6 files changed, 117 insertions(+), 14 deletions(-) create mode 100644 src/theme-helper/view-mode-cards.vue rename src/theme-helper/{table-view-mode.vue => view-mode-table.vue} (97%) diff --git a/src/admin/components/navigation/tainacan-title.vue b/src/admin/components/navigation/tainacan-title.vue index 401a1e4df..fea7fd533 100644 --- a/src/admin/components/navigation/tainacan-title.vue +++ b/src/admin/components/navigation/tainacan-title.vue @@ -1,7 +1,7 @@ @@ -90,24 +110,38 @@ 'IN': this.$i18n.get('contains'), 'NOT IN': this.$i18n.get('not_contains') }, - totalSearchMetadata: 1, + searchCriterias: [1], advancedSearchQuery: { advancedSearch: true, - metaquery: { - relation: 'AND', - } }, } }, methods: { - addSearchMetadata(){ - this.totalSearchMetadata++; + removeThis(searchCriteria){ + let criteriaIndex = this.searchCriterias.findIndex((element) => { + return element == searchCriteria; + }); + + this.searchCriterias.splice(criteriaIndex, 1); + delete this.advancedSearchQuery[criteriaIndex]; + }, + addSearchCriteria(){ + let aleatoryKey = Math.floor(Math.random() * 1000) + 2; + + let found = this.searchCriterias.find((element) => { + return element == aleatoryKey; + }); + + if(found == undefined){ + this.searchCriterias.push(aleatoryKey); + } else { + this.addSearchCriteria(); + } }, clearSearch(){ - this.totalSearchMetadata = 1; + this.searchCriterias = [1]; this.advancedSearchQuery = { advancedSearch: true, - relation: 'AND', }; }, addValueToAdvancedSearchQuery: _.debounce(function(value, type, relation) { @@ -116,21 +150,40 @@ vm.addToAdvancedSearchQuery(value, type, relation); }, 900), searchAdvanced(){ + if(this.advancedSearchQuery.length > 2){ + this.advancedSearchQuery.relation = 'AND'; + } + this.$eventBusSearch.$emit('searchAdvanced', this.advancedSearchQuery); }, addToAdvancedSearchQuery(value, type, relation){ - if(this.advancedSearchQuery.metaquery.hasOwnProperty(relation)){ + if(this.advancedSearchQuery.hasOwnProperty(relation)){ //if(this.advancedSearchQuery[relation].compare === 'IN'){ //this.advancedSearchQuery[relation][type] = value.split(' '); //} else { - this.advancedSearchQuery.metaquery[relation][type] = value; + if(type == 'compare' && (this.advancedSearchQuery[relation]['compare'] == 'IN' || + this.advancedSearchQuery[relation]['compare'] == 'NOT IN')){ + + this.advancedSearchQuery[relation].value.push(value); + } else { + this.advancedSearchQuery[relation][type] = value; + } //} } else { - this.advancedSearchQuery.metaquery = Object.assign({}, this.advancedSearchQuery.metaquery, { - [`${relation}`]: { - [`${type}`]: value, - } - }); + if(type == 'compare' && (value == 'IN' || value == 'NOT IN')){ + + this.advancedSearchQuery = Object.assign({}, this.advancedSearchQuery, { + [`${relation}`]: { + [`${type}`]: [value], + } + }); + } else { + this.advancedSearchQuery = Object.assign({}, this.advancedSearchQuery, { + [`${relation}`]: { + [`${type}`]: value, + } + }); + } } console.log(this.advancedSearchQuery); diff --git a/src/admin/components/repository/collection-filter/collection-filter.vue b/src/admin/components/repository/collection-filter/collection-filter.vue index 1a93fedb4..b6e72f57c 100644 --- a/src/admin/components/repository/collection-filter/collection-filter.vue +++ b/src/admin/components/repository/collection-filter/collection-filter.vue @@ -78,7 +78,7 @@ apply_filter(){ this.$eventBusSearch.$emit( 'input', { filter: 'checkbox', - field_id: 'collection_id', + metadatum_id: 'collection_id', value: this.collectionsIdsToFilter, compare: 'IN', collection_id: this.collectionsIdsToFilter, diff --git a/src/admin/pages/lists/items-page.vue b/src/admin/pages/lists/items-page.vue index 1db8b3852..478aff81b 100644 --- a/src/admin/pages/lists/items-page.vue +++ b/src/admin/pages/lists/items-page.vue @@ -676,6 +676,10 @@ this.hasFiltered = hasFiltered; }); + this.$eventBusSearch.$on('advancedSearchResults', advancedSearchResults => { + this.advancedSearchResults = advancedSearchResults; + }); + this.$eventBusSearch.$on('hasToPrepareMetadataAndFilters', (to) => { /* This condition is to prevent a incorrect fetch by filter or metadata when we come from items * at collection level to items page at repository level diff --git a/src/admin/tainacan-admin-i18n.php b/src/admin/tainacan-admin-i18n.php index 079b22c9f..36b78f6e7 100644 --- a/src/admin/tainacan-admin-i18n.php +++ b/src/admin/tainacan-admin-i18n.php @@ -51,7 +51,7 @@ return apply_filters('tainacan-admin-i18n',[ 'new_blank_collection' => __( 'New Blank Collection', 'tainacan' ), 'split' => __( 'Split', 'tainacan' ), 'unified' => __( 'Unified', 'tainacan' ), - 'add_more_one_search_metadatum' => __( 'Add more one search metadatum', 'tainacan' ), + 'add_more_one_search_criteria' => __( 'Add more one search criteria', 'tainacan' ), 'clear_search' => __( 'Clear search', 'tainacan' ), // Wordpress Status diff --git a/src/classes/tainacan-creator.php b/src/classes/tainacan-creator.php index 1e0fe815a..58287751d 100644 --- a/src/classes/tainacan-creator.php +++ b/src/classes/tainacan-creator.php @@ -135,5 +135,4 @@ require_once(__DIR__ . '/../theme-helper/class-tainacan-theme-helper.php'); require_once(__DIR__ . '/../theme-helper/template-tags.php'); $Tainacan_Theme_Helper = \Tainacan\Theme_Helper::get_instance(); - ?> diff --git a/src/js/event-bus-search.js b/src/js/event-bus-search.js index 0a2138008..95099ba86 100644 --- a/src/js/event-bus-search.js +++ b/src/js/event-bus-search.js @@ -28,8 +28,6 @@ export default { this.$root.$on('searchAdvanced', advancedSearchQuery => { this.$store.dispatch('search/setPage', 1); - console.log('Emit caught', advancedSearchQuery); - this.searchAdvanced(advancedSearchQuery); this.updateURLQueries(); @@ -49,12 +47,9 @@ export default { this.$route.query.order = 'DESC'; if (this.$route.query.orderby == undefined) this.$route.query.orderby = 'date'; - - if(this.$route.query.advancedSearch){ - delete this.$route.query.advancedSearch; - - console.log('Route watch: '+ this.$route.query); - + + if(this.$route.query.metaquery && this.$route.query.metaquery.advancedSearch){ + console.log(this.$route); this.$store.dispatch('search/set_advanced_query', this.$route.query); } else { this.$store.dispatch('search/set_postquery', this.$route.query); @@ -134,15 +129,10 @@ export default { this.$store.dispatch('search/setViewMode', viewMode); this.updateURLQueries(); }, - updateURLQueries(isAdvancedSearch = false) { - this.$router.push({ query: {}}); - - if(isAdvancedSearch) { - this.$router.push({query: this.$store.getters['search/getAdvancedSearchQuery']}); - console.log(this.$route); - } else { - this.$router.push({query: this.$store.getters['search/getPostQuery']}); - } + updateURLQueries(isAdvancedSearch) { + this.$router.push({query: {}}); + this.$route.meta['advancedSearch'] = isAdvancedSearch; + this.$router.push({query: this.$store.getters['search/getPostQuery']}); }, updateStoreFromURL() { this.$store.dispatch('search/set_postquery', this.$route.query); @@ -162,6 +152,10 @@ export default { .then((res) => { this.$emit( 'isLoadingItems', false); this.$emit( 'hasFiltered', res.hasFiltered); + + if(res.advancedSearchResults){ + this.$emit('advancedSearchResults', res.advancedSearchResults); + } }) .catch(() => { this.$emit( 'isLoadingItems', false); diff --git a/src/js/store/modules/collection/actions.js b/src/js/store/modules/collection/actions.js index daa58f512..8055abe81 100644 --- a/src/js/store/modules/collection/actions.js +++ b/src/js/store/modules/collection/actions.js @@ -8,12 +8,28 @@ export const fetchItems = ({ rootGetters, dispatch, commit }, { collectionId, is // Adds queries for filtering let postQueries = rootGetters['search/getPostQuery']; - + let query = ''; // Sets a flag to inform components that an empty sate is or not due to filtering let hasFiltered = false; - if (postQueries.metaquery != undefined && postQueries.metaquery.length > 0) + let advancedSearchResults = false; + + if (postQueries.metaquery != undefined && postQueries.metaquery.metaquery){ hasFiltered = true; + if(postQueries.metaquery.metaquery.advancedSearch){ + + advancedSearchResults = postQueries.metaquery.metaquery.advancedSearch; + + delete postQueries.metaquery.metaquery.advancedSearch; + + query = qs.stringify({metaquery: postQueries.metaquery.metaquery}); + + console.log({q: query}); + } else { + query = postQueries; + } + } + // Garanttees at least empty fetch_only are passed in case none is found if (qs.stringify(postQueries.fetch_only) == '') dispatch('search/add_fetchonly', {} , { root: true }); @@ -24,24 +40,26 @@ export const fetchItems = ({ rootGetters, dispatch, commit }, { collectionId, is // Differentiates between repository level and collection level queries let endpoint = '/collection/'+collectionId+'/items?' - if (collectionId == undefined) + if (collectionId == undefined){ endpoint = '/items?' + } - if (!isOnTheme) + if (!isOnTheme){ endpoint = endpoint + 'context=edit&' - - axios.tainacan.get(endpoint + qs.stringify(postQueries)) + } + + axios.tainacan.get(endpoint+query) .then(res => { let items = res.data; let viewModeObject = tainacan_plugin.registered_view_modes[postQueries.view_mode]; if (isOnTheme && viewModeObject != undefined && viewModeObject.type == 'template') { - commit('setItemsListTemplate', items ); - resolve({'itemsListTemplate': items, 'total': res.headers['x-wp-total'], hasFiltered: hasFiltered}); + commit('setItemsListTemplate', items); + resolve({'itemsListTemplate': items, 'total': res.headers['x-wp-total'], hasFiltered: hasFiltered, advancedSearchResults: advancedSearchResults}); } else { - commit('setItems', items ); - resolve({'items': items, 'total': res.headers['x-wp-total'], hasFiltered: hasFiltered}); + commit('setItems', items); + resolve({'items': items, 'total': res.headers['x-wp-total'], hasFiltered: hasFiltered, advancedSearchResults: advancedSearchResults }); } dispatch('search/setTotalItems', res.headers['x-wp-total'], { root: true } ); }) diff --git a/src/js/store/modules/collection/index.js b/src/js/store/modules/collection/index.js index 55309be1c..f39d390e6 100644 --- a/src/js/store/modules/collection/index.js +++ b/src/js/store/modules/collection/index.js @@ -4,6 +4,7 @@ import * as mutations from './mutations'; const state = { items: [], + isFromAdvancedSearch: false, itemsListTemplate: '', collections: [], collection: null, diff --git a/src/js/store/modules/search/index.js b/src/js/store/modules/search/index.js index a10911b93..0b42bd391 100644 --- a/src/js/store/modules/search/index.js +++ b/src/js/store/modules/search/index.js @@ -21,7 +21,6 @@ const state = { }, view_mode: 'table' }, - advancedSearchQuery: {}, totalItems: 0 }; diff --git a/src/js/store/modules/search/mutations.js b/src/js/store/modules/search/mutations.js index 0bd1e8cef..956f2ef7b 100644 --- a/src/js/store/modules/search/mutations.js +++ b/src/js/store/modules/search/mutations.js @@ -9,7 +9,7 @@ export const setPostQuery = ( state, postquery ) => { }; export const setAdvancedSearchQuery = (state, advancedSearchQuery) => { - state.advancedSearchQuery = advancedSearchQuery; + state.postquery.metaquery = advancedSearchQuery; }; export const addMetaQuery = ( state, filter ) => { From 70a23b9c7de2541094421d1532812d6f475d9fa4 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Tue, 12 Jun 2018 14:06:15 -0300 Subject: [PATCH 7/7] register user meta tainacan_prefs as string --- src/admin/class-tainacan-admin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/admin/class-tainacan-admin.php b/src/admin/class-tainacan-admin.php index 720b9e719..4cfcd7a6e 100644 --- a/src/admin/class-tainacan-admin.php +++ b/src/admin/class-tainacan-admin.php @@ -223,9 +223,9 @@ class Admin { function register_user_meta() { $args = array( - //'sanitize_callback' => 'sanitize_my_meta_key', + //'sanitize_callback' => array(&$this, 'santize_user_tainacan_prefs'), //'auth_callback' => 'authorize_my_meta_key', - 'type' => 'array', + 'type' => 'string', 'description' => 'Tainacan admin user preferences', 'single' => true, 'show_in_rest' => true,