From 8784af77f5a400f8a4dedbcf62fa865f2fe5ad00 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Mon, 21 Oct 2019 13:58:12 -0300 Subject: [PATCH 01/16] add missgin getter in Log entity --- src/classes/entities/class-tainacan-log.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/classes/entities/class-tainacan-log.php b/src/classes/entities/class-tainacan-log.php index 9a04b546c..ca62a7986 100644 --- a/src/classes/entities/class-tainacan-log.php +++ b/src/classes/entities/class-tainacan-log.php @@ -94,6 +94,15 @@ class Log extends Entity { function get_date() { return $this->get_mapped_property( 'date' ); } + + /** + * Return the log slug + * + * @return mixed|null + */ + function get_slug() { + return $this->get_mapped_property( 'slug' ); + } /** From 0b407e03991b31902ead4fc1a5503c24ecdaddfd Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Wed, 23 Oct 2019 16:48:51 -0300 Subject: [PATCH 02/16] add test for object post type of the taxonomies --- tests/test-taxonomies.php | 167 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) diff --git a/tests/test-taxonomies.php b/tests/test-taxonomies.php index 6d13b6070..164e6b186 100644 --- a/tests/test-taxonomies.php +++ b/tests/test-taxonomies.php @@ -416,4 +416,171 @@ class Taxonomies extends TAINACAN_UnitTestCase { } + function test_metadata_taxonomy_term_count() { + $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); + $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); + + $collection_1 = $this->tainacan_entity_factory->create_entity( + 'collection', + array( 'name' => 'test-1' ), + true + ); + + $collection_2 = $this->tainacan_entity_factory->create_entity( + 'collection', + array( 'name' => 'test-2' ), + true + ); + + $tax = $this->tainacan_entity_factory->create_entity( + 'taxonomy', + array( + 'name' => 'tax_test', + 'status' => 'publish', + 'enabled_post_types' => [$collection_1->get_db_identifier(), $collection_2->get_db_identifier()] + ), + true + ); + + $tax_repository = $this->tainacan_entity_factory->create_entity( + 'taxonomy', + array( + 'name' => 'tax_test_repository', + 'status' => 'publish' + ), + true + ); + + $t1 = $this->tainacan_entity_factory->create_entity( + 'term', + array( + 'taxonomy' => $tax->get_db_identifier(), + 'name' => 'term', + 'user' => get_current_user_id(), + ), + true + ); + + $t2 = $this->tainacan_entity_factory->create_entity( + 'term', + array( + 'taxonomy' => $tax_repository->get_db_identifier(), + 'name' => 'term_repository' + ), + true + ); + + $metadatum_1 = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'meta-1', + 'description' => 'description-1', + 'collection' => $collection_1, + 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', + 'status' => 'publish', + 'metadata_type_options' => [ + 'taxonomy_id' => $tax->get_id(), + 'allow_new_terms' => 'no' + ] + ), + true + ); + + $metadatum_2 = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'meta-2', + 'description' => 'description-2', + 'collection' => $collection_2, + 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', + 'status' => 'publish', + 'metadata_type_options' => [ + 'taxonomy_id' => $tax->get_id(), + 'allow_new_terms' => 'no' + ] + ), + true + ); + + $metadatum_repository = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'meta-1', + 'description' => 'description-1', + 'collection_id' => $Tainacan_Metadata->get_default_metadata_attribute(), + 'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy', + 'status' => 'publish', + 'metadata_type_options' => [ + 'taxonomy_id' => $tax_repository->get_id(), + 'allow_new_terms' => 'no' + ] + ), + true + ); + + $i1 = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'item teste', + 'description' => 'adasdasdsa', + 'collection' => $collection_1 + ), + true + ); + $itemMeta1 = new \Tainacan\Entities\Item_Metadata_Entity($i1, $metadatum_1); + $itemMeta1->set_value('term'); + $itemMeta1->validate(); + $Tainacan_Item_Metadata->insert($itemMeta1); + + $itemMeta1_repo = new \Tainacan\Entities\Item_Metadata_Entity($i1, $metadatum_repository); + $itemMeta1_repo->set_value('term_repository'); + $itemMeta1_repo->validate(); + $Tainacan_Item_Metadata->insert($itemMeta1_repo); + + + $i2 = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'item teste', + 'description' => 'adasdasdsa', + 'collection' => $collection_2 + ), + true + ); + $itemMeta2 = new \Tainacan\Entities\Item_Metadata_Entity($i2, $metadatum_2); + $itemMeta2->set_value('term'); + $itemMeta2->validate(); + $Tainacan_Item_Metadata->insert($itemMeta2); + + $itemMeta2_repo = new \Tainacan\Entities\Item_Metadata_Entity($i2, $metadatum_repository); + $itemMeta2_repo->set_value('term_repository'); + $itemMeta2_repo->validate(); + $Tainacan_Item_Metadata->insert($itemMeta2_repo); + + $terms = get_terms([ + 'taxonomy' => $tax->get_db_identifier(), + //'hide_empty' => false, + ]); + $this->assertEquals(1, count($terms)); + + wp_update_term_count($t1->get_term_id(), $tax->get_db_identifier()); + wp_update_term_count($t2->get_term_id(), $tax_repository->get_db_identifier()); + + $term = get_term($t1->get_term_id()); + $term_repo = get_term($t2->get_term_id()); + $tax_used = get_object_taxonomies( [$collection_1->get_db_identifier(), $collection_2->get_db_identifier()]); + + $tax = get_taxonomy($tax->get_db_identifier()); + $tax_repository = get_taxonomy($tax_repository->get_db_identifier()); + + $this->assertContains($collection_1->get_db_identifier(), $tax->object_type); + $this->assertContains($collection_2->get_db_identifier(), $tax->object_type); + + $this->assertContains($collection_1->get_db_identifier(), $tax_repository->object_type); + $this->assertContains($collection_2->get_db_identifier(), $tax_repository->object_type); + + $this->assertEquals(2, $term->count); + $this->assertEquals(2, $term_repo->count); + } + } \ No newline at end of file From 0dca242530bfb19209b09aef2b38058a8a10855e Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Wed, 23 Oct 2019 16:55:27 -0300 Subject: [PATCH 03/16] remove `enabled_post_types` on declared taxonomy. --- tests/test-taxonomies.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-taxonomies.php b/tests/test-taxonomies.php index 164e6b186..8c2db54d2 100644 --- a/tests/test-taxonomies.php +++ b/tests/test-taxonomies.php @@ -437,7 +437,7 @@ class Taxonomies extends TAINACAN_UnitTestCase { array( 'name' => 'tax_test', 'status' => 'publish', - 'enabled_post_types' => [$collection_1->get_db_identifier(), $collection_2->get_db_identifier()] + //'enabled_post_types' => [$collection_1->get_db_identifier(), $collection_2->get_db_identifier()] ), true ); From cd81023420a9cfad29d6ccb9c5d5e1d135349da5 Mon Sep 17 00:00:00 2001 From: leogermani Date: Wed, 23 Oct 2019 20:08:00 -0300 Subject: [PATCH 04/16] Make WP update terms count for all items #318 --- .../entities/class-tainacan-taxonomy.php | 53 +++--- tests/test-taxonomies.php | 176 +++++++++--------- 2 files changed, 116 insertions(+), 113 deletions(-) diff --git a/src/classes/entities/class-tainacan-taxonomy.php b/src/classes/entities/class-tainacan-taxonomy.php index af5c94265..dd11af5d2 100644 --- a/src/classes/entities/class-tainacan-taxonomy.php +++ b/src/classes/entities/class-tainacan-taxonomy.php @@ -22,28 +22,28 @@ class Taxonomy extends Entity { * @var string */ static $post_type = 'tainacan-taxonomy'; - + /** * {@inheritDoc} * @see \Tainacan\Entities\Entity::capability_type * @var string */ protected static $capability_type = ['tainacan-taxonomy', 'tainacan-taxonomies']; - + /** * {@inheritDoc} * @see \Tainacan\Entities\Entity::repository * @var string */ protected $repository = 'Taxonomies'; - + /** * Prefix used to create the db_identifier * * @var string */ static $db_identifier_prefix = 'tnc_tax_'; - + public function __toString(){ return apply_filters("tainacan-taxonomy-to-string", $this->get_name(), $this); } @@ -67,7 +67,7 @@ class Taxonomy extends Entity { 'new_item_name' => __( 'New Genre term', 'tainacan' ), 'menu_name' => $this->get_name(), ); - + $enabled_post_types = $this->get_enabled_post_types(); $enabled_post_types = sizeof($enabled_post_types) ? $enabled_post_types : null; $show_ui = is_array($enabled_post_types) ? true : false; @@ -80,21 +80,22 @@ class Taxonomy extends Entity { 'show_admin_column' => false, 'rewrite' => [ 'slug' => $this->get_slug() - ], + ], + 'update_count_callback' => '_update_generic_term_count' ); - + if (taxonomy_exists($this->get_db_identifier())){ unregister_taxonomy($this->get_db_identifier()); } - - - - register_taxonomy( - $this->get_db_identifier(), - $enabled_post_types, - $args + + + + register_taxonomy( + $this->get_db_identifier(), + $enabled_post_types, + $args ); - + return true; } @@ -135,7 +136,7 @@ class Taxonomy extends Entity { function get_slug() { return $this->get_mapped_property('slug'); } - + /** * Return the enabled post types * @@ -144,7 +145,7 @@ class Taxonomy extends Entity { function get_enabled_post_types() { return $this->get_mapped_property('enabled_post_types'); } - + // special Getters /** @@ -194,7 +195,7 @@ class Taxonomy extends Entity { function set_allow_insert($value) { $this->set_mapped_property('allow_insert', $value); } - + /** * Sets enabled post types * @@ -221,19 +222,19 @@ class Taxonomy extends Entity { return parent::validate(); } - + /** - * Check if a term already exists + * Check if a term already exists * - * @param string $term_name The term name - * @param int|null $parent The ID of the parent term to look for children or null to look for terms in any hierarchical position. Default is null - * @param bool $return_term wether to return the term object if it exists. default is to false - * - * @return bool|WP_Term return boolean indicating if term exists. If $return_term is true and term exists, return WP_Term object + * @param string $term_name The term name + * @param int|null $parent The ID of the parent term to look for children or null to look for terms in any hierarchical position. Default is null + * @param bool $return_term wether to return the term object if it exists. default is to false + * + * @return bool|WP_Term return boolean indicating if term exists. If $return_term is true and term exists, return WP_Term object */ function term_exists($term_name, $parent = null, $return_term = false) { $repo = $this->get_repository(); return $repo->term_exists($this, $term_name, $parent, $return_term); } -} \ No newline at end of file +} diff --git a/tests/test-taxonomies.php b/tests/test-taxonomies.php index 8c2db54d2..e30d6a5d7 100644 --- a/tests/test-taxonomies.php +++ b/tests/test-taxonomies.php @@ -69,9 +69,9 @@ class Taxonomies extends TAINACAN_UnitTestCase { $this->assertEquals( $test->get_name(), 'Rock' ); $this->assertEquals( $test->get_user(), 56 ); } - + function test_terms_of_draft_taxonomy() { - + $taxonomy = $this->tainacan_entity_factory->create_entity( 'taxonomy', array( @@ -82,14 +82,14 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance(); $terms = $Tainacan_Terms->fetch(['hide_empty' => false], $taxonomy->get_id()); - + $this->assertEquals(0, sizeof($terms), 'new auto draft taxonomy should return 0 terms'); - + $term = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -98,17 +98,17 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - - - + + + $terms = $Tainacan_Terms->fetch(['hide_empty' => false], $taxonomy->get_id()); - + $this->assertEquals(1, sizeof($terms), 'you should be able to create a term even if the taxonomy is still auto-draft'); - + } - + function test_term_exists() { - + $taxonomy = $this->tainacan_entity_factory->create_entity( 'taxonomy', array( @@ -119,10 +119,10 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance(); - + $term = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -131,7 +131,7 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $parent = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -140,7 +140,7 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $child = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -150,14 +150,14 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $this->assertFalse( $Tainacan_Terms->term_exists('Reggae', $taxonomy->get_db_identifier()) ); $this->assertTrue( $Tainacan_Terms->term_exists('Rock', $taxonomy->get_db_identifier()) ); - + //var_dump( $Tainacan_Terms->term_exists('Rock', $taxonomy->get_db_identifier(), 0, true) ); - - // test extreme case - + + // test extreme case + $term_2 = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -167,49 +167,49 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $this->assertFalse( $Tainacan_Terms->term_exists('test 123', $taxonomy->get_db_identifier(), 0) ); // parent 0 $this->assertTrue( $Tainacan_Terms->term_exists('test 123', $taxonomy->get_db_identifier(), $term->get_id()) ); // spaces in between - - // testing passing taxonomy object + + // testing passing taxonomy object $this->assertTrue( $Tainacan_Terms->term_exists('Rock', $taxonomy) ); - + // testing passing taxonomy ID $this->assertTrue( $Tainacan_Terms->term_exists('Rock', $taxonomy->get_id()) ); - + // testing via Taxonomy object $this->assertTrue( $taxonomy->term_exists('Rock') ); - - // testing retrieving the term + + // testing retrieving the term $this->assertTrue( $taxonomy->term_exists('Rock', 0, true) instanceof \WP_Term ); $this->assertEquals( $term->get_id(), $taxonomy->term_exists('Rock', 0, true)->term_taxonomy_id ); - - // test parent + + // test parent $this->assertTrue( $Tainacan_Terms->term_exists('Child', $taxonomy->get_db_identifier()) ); // parent null $this->assertFalse( $Tainacan_Terms->term_exists('Child', $taxonomy->get_db_identifier(), 0) ); // parent 0 - $this->assertTrue( $Tainacan_Terms->term_exists('Child', $taxonomy->get_db_identifier(), $parent->get_id()) ); // parent - - // test with ID + $this->assertTrue( $Tainacan_Terms->term_exists('Child', $taxonomy->get_db_identifier(), $parent->get_id()) ); // parent + + // test with ID $this->assertTrue( $Tainacan_Terms->term_exists($term->get_id(), $taxonomy->get_id()) ); - - // test get term + + // test get term $test_term = $Tainacan_Terms->term_exists($term->get_id(), $taxonomy->get_id(), null, true); $this->assertEquals($term->get_id(), $test_term->term_id); - + $test_term = $Tainacan_Terms->term_exists('Rock', $taxonomy->get_id(), null, true); $this->assertEquals($term->get_id(), $test_term->term_id); - + $test_term = $Tainacan_Terms->term_exists('Parent', $taxonomy->get_id(), null, true); $this->assertEquals($parent->get_id(), $test_term->term_id); - + // test brackets $test_term = $Tainacan_Terms->term_exists('[Rock]', $taxonomy->get_id(), null, true); $this->assertFalse($test_term); - + } - + function test_term_validation() { - + $taxonomy = $this->tainacan_entity_factory->create_entity( 'taxonomy', array( @@ -220,10 +220,10 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance(); - + $term = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -232,7 +232,7 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $parent = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -241,7 +241,7 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $child = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -251,27 +251,27 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $newTerm = new \Tainacan\Entities\Term(); $newTerm->set_name('Child'); $newTerm->set_taxonomy($taxonomy->get_db_identifier()); - + $this->assertTrue( $newTerm->validate() ); - + $newTerm->set_parent($parent->get_id()); - + $this->assertFalse( $newTerm->validate(), 'term should not validate because it has a duplicate in the same level' ); - + $child->set_description('changed'); - + $this->assertTrue( $child->validate(), 'child should validate'); - - - + + + } - + /** - * @group enabled + * @group enabled */ function test_enabled_post_types(){ $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); @@ -287,15 +287,15 @@ class Taxonomies extends TAINACAN_UnitTestCase { ); $taxonomy = $Tainacan_Taxonomies->insert($taxonomy); - + $pto = get_object_taxonomies('post'); $pages = get_object_taxonomies('page'); $this->assertContains($taxonomy->get_db_identifier(), $pto); $this->assertNotContains($taxonomy->get_db_identifier(), $pages); } - + function test_brackets() { - + $taxonomy = $this->tainacan_entity_factory->create_entity( 'taxonomy', array( @@ -306,10 +306,10 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance(); - + $term = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -318,7 +318,7 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $term2 = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -327,16 +327,16 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $terms = $Tainacan_Terms->fetch(['hide_empty' => false], $taxonomy); $this->assertEquals(2, sizeof($terms)); - + } - + function test_brackets_2() { - + $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); - + $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( @@ -345,7 +345,7 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $taxonomy = $this->tainacan_entity_factory->create_entity( 'taxonomy', array( @@ -381,7 +381,7 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $i2 = $this->tainacan_entity_factory->create_entity( 'item', array( @@ -391,44 +391,44 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $itemMeta1 = new \Tainacan\Entities\Item_Metadata_Entity($i1, $metadatum); $itemMeta1->set_value('Rock'); $itemMeta1->validate(); $Tainacan_Item_Metadata->insert($itemMeta1); - + //$this->assertNotFalse(term_exists( 'Rock', $taxonomy->get_db_identifier() )); // term_exists() is not to be trusted //$this->assertFalse(term_exists( '[Rock]', $taxonomy->get_db_identifier() )); - + $itemMeta2 = new \Tainacan\Entities\Item_Metadata_Entity($i2, $metadatum); $itemMeta2->set_value('[Rock]'); $itemMeta2->validate(); $Tainacan_Item_Metadata->insert($itemMeta2); - + $itemMeta1_check = new \Tainacan\Entities\Item_Metadata_Entity($i1, $metadatum); $this->assertEquals('Rock', $itemMeta1_check->get_value()->get_name()); - + $itemMeta2_check = new \Tainacan\Entities\Item_Metadata_Entity($i2, $metadatum); $this->assertEquals('[Rock]', $itemMeta2_check->get_value()->get_name()); - - - + + + } - + function test_metadata_taxonomy_term_count() { $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $collection_1 = $this->tainacan_entity_factory->create_entity( 'collection', - array( 'name' => 'test-1' ), + array( 'name' => 'test-1', 'status' => 'publish', ), true ); $collection_2 = $this->tainacan_entity_factory->create_entity( 'collection', - array( 'name' => 'test-2' ), + array( 'name' => 'test-2', 'status' => 'publish', ), true ); @@ -469,7 +469,7 @@ class Taxonomies extends TAINACAN_UnitTestCase { ), true ); - + $metadatum_1 = $this->tainacan_entity_factory->create_entity( 'metadatum', array( @@ -523,7 +523,8 @@ class Taxonomies extends TAINACAN_UnitTestCase { array( 'title' => 'item teste', 'description' => 'adasdasdsa', - 'collection' => $collection_1 + 'collection' => $collection_1, + 'status' => 'publish' ), true ); @@ -531,7 +532,7 @@ class Taxonomies extends TAINACAN_UnitTestCase { $itemMeta1->set_value('term'); $itemMeta1->validate(); $Tainacan_Item_Metadata->insert($itemMeta1); - + $itemMeta1_repo = new \Tainacan\Entities\Item_Metadata_Entity($i1, $metadatum_repository); $itemMeta1_repo->set_value('term_repository'); $itemMeta1_repo->validate(); @@ -543,7 +544,8 @@ class Taxonomies extends TAINACAN_UnitTestCase { array( 'title' => 'item teste', 'description' => 'adasdasdsa', - 'collection' => $collection_2 + 'collection' => $collection_2, + 'status' => 'private' ), true ); @@ -564,12 +566,12 @@ class Taxonomies extends TAINACAN_UnitTestCase { $this->assertEquals(1, count($terms)); wp_update_term_count($t1->get_term_id(), $tax->get_db_identifier()); - wp_update_term_count($t2->get_term_id(), $tax_repository->get_db_identifier()); + wp_update_term_count($t2->get_term_id(), $tax_repository->get_db_identifier()); $term = get_term($t1->get_term_id()); $term_repo = get_term($t2->get_term_id()); $tax_used = get_object_taxonomies( [$collection_1->get_db_identifier(), $collection_2->get_db_identifier()]); - + $tax = get_taxonomy($tax->get_db_identifier()); $tax_repository = get_taxonomy($tax_repository->get_db_identifier()); @@ -583,4 +585,4 @@ class Taxonomies extends TAINACAN_UnitTestCase { $this->assertEquals(2, $term_repo->count); } -} \ No newline at end of file +} From 333aa976fd3bdeaa4ab6a04725fcf9a1d820e6d6 Mon Sep 17 00:00:00 2001 From: leogermani Date: Tue, 29 Oct 2019 15:01:38 -0300 Subject: [PATCH 05/16] fix after merge 0.13 --- src/classes/entities/class-tainacan-log.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/classes/entities/class-tainacan-log.php b/src/classes/entities/class-tainacan-log.php index 02ed6ba83..583c717b7 100644 --- a/src/classes/entities/class-tainacan-log.php +++ b/src/classes/entities/class-tainacan-log.php @@ -94,15 +94,6 @@ class Log extends Entity { function get_date() { return $this->get_mapped_property( 'date' ); } - - /** - * Return the log slug - * - * @return mixed|null - */ - function get_slug() { - return $this->get_mapped_property( 'slug' ); - } /** * Return the log slug @@ -113,7 +104,6 @@ class Log extends Entity { return $this->get_mapped_property( 'slug' ); } - /** * Return the Log description * From e894a2f7ca593b2bba651ab633f2cf75cebae42f Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Tue, 29 Oct 2019 16:50:16 -0300 Subject: [PATCH 06/16] Adds open source highlight to plugin description and website and wiki links to plugins readme. --- src/readme.txt | 9 +++++++-- src/tainacan.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/readme.txt b/src/readme.txt index 626660e34..317dd3764 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -8,11 +8,11 @@ Stable tag: 0.13 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html -Tainacan is a powerful and flexible repository platform for WordPress. Manage and publish your digital collections just as easily as you post to your blog, having all the tools of a professional repository platform. +Tainacan is an open source, powerful and flexible repository platform for WordPress. Manage and publish your digital collections just as easily as you post to your blog, having all the tools of a professional repository platform. == Description == -Tainacan is a powerful and flexible repository platform for WordPress. Manage and publish your digital collections just as easily as you post to your blog, having all the tools of a professional repository platform. +[Tainacan](https://tainacan.org/) is an open source, powerful and flexible repository platform for WordPress. Manage and publish your digital collections just as easily as you post to your blog, having all the tools of a professional repository platform. = Features = @@ -76,6 +76,11 @@ Upload the files to the plugins directory and activate it. You can also install If you have Imagick installed in your server, Tainacan will be able to automatically generate a thumbnail from your PDF files. This is desired but not required. +== Find out more == + +* Visit our oficial website: [https://tainacan.org/](https://tainacan.org/) +* Check our documentation Wiki: [https://wiki.tainacan.org/](https://wiki.tainacan.org/) + == Screenshots == 1. Manage your repository diff --git a/src/tainacan.php b/src/tainacan.php index 361e6bbf2..dbbae9846 100644 --- a/src/tainacan.php +++ b/src/tainacan.php @@ -2,7 +2,7 @@ /* Plugin Name: Tainacan Plugin URI: https://tainacan.org/ -Description: powerfull and flexible repository platform for WordPress. Manage and publish you digital collections as easily as publishing a post to your blog, while having all the tools of a professional respository platform. +Description: Open source, powerfull and flexible repository platform for WordPress. Manage and publish you digital collections as easily as publishing a post to your blog, while having all the tools of a professional respository platform. Author: Tainacan.org Version: 0.13 Text Domain: tainacan From c6591008e2f8a66da30a0eec27e4946e0535a238 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Wed, 30 Oct 2019 12:59:46 -0300 Subject: [PATCH 07/16] Removes blur events as they are no more used #320. --- .../components/edition/item-metadata-bulk-edition-form.vue | 2 -- src/classes/metadata-types/date/Date.vue | 6 ------ src/classes/metadata-types/numeric/Numeric.vue | 5 ----- src/classes/metadata-types/relationship/Relationship.vue | 1 - src/classes/metadata-types/selectbox/Selectbox.vue | 1 - src/classes/metadata-types/taxonomy/Taxonomy.vue | 2 -- src/classes/metadata-types/taxonomy/TaxonomyCheckbox.vue | 1 - src/classes/metadata-types/taxonomy/TaxonomyRadio.vue | 1 - src/classes/metadata-types/taxonomy/TaxonomyTaginput.vue | 2 -- src/classes/metadata-types/text/Text.vue | 5 +---- src/classes/metadata-types/textarea/Textarea.vue | 4 ---- 11 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/admin/components/edition/item-metadata-bulk-edition-form.vue b/src/admin/components/edition/item-metadata-bulk-edition-form.vue index 5779108b6..c3742fd6c 100644 --- a/src/admin/components/edition/item-metadata-bulk-edition-form.vue +++ b/src/admin/components/edition/item-metadata-bulk-edition-form.vue @@ -132,8 +132,6 @@ :metadatum="{ metadatum: metadatum }" :value="itemMetadata[index].value" @input="clearErrorMessage(metadatum.id); bulkEdit($event, metadatum)"/> - diff --git a/src/classes/metadata-types/date/Date.vue b/src/classes/metadata-types/date/Date.vue index 36e24646c..b68f2997c 100644 --- a/src/classes/metadata-types/date/Date.vue +++ b/src/classes/metadata-types/date/Date.vue @@ -10,7 +10,6 @@ type="text" v-mask="dateMask" v-model="dateValue" - @blur="onBlur" @input="onInput" :placeholder="dateFormat.toLowerCase()">

- @@ -64,9 +62,6 @@ disabled: false, }, methods: { - onBlur() { - this.$emit('blur'); - }, onInput: _.debounce(function ($event) { // Emty dates don't need to be validated, they remove the metadata if ($event.target.value != '') { @@ -89,7 +84,6 @@ } else { this.$emit('input', [null]); } - this.$emit('blur'); }, 300) } } diff --git a/src/classes/metadata-types/numeric/Numeric.vue b/src/classes/metadata-types/numeric/Numeric.vue index 4c0377e60..a71eea76f 100644 --- a/src/classes/metadata-types/numeric/Numeric.vue +++ b/src/classes/metadata-types/numeric/Numeric.vue @@ -7,8 +7,6 @@ type="number" :value="inputValue" step="0.01" - @blur="onBlur" - @change="onBlur" @input="onInput($event)"/> @@ -33,9 +31,6 @@ disabled: false, }, methods: { - onBlur() { - this.$emit('blur'); - }, onInput($event) { this.inputValue = $event; this.$emit('input', this.inputValue); diff --git a/src/classes/metadata-types/relationship/Relationship.vue b/src/classes/metadata-types/relationship/Relationship.vue index b36e5262d..b98d819a7 100644 --- a/src/classes/metadata-types/relationship/Relationship.vue +++ b/src/classes/metadata-types/relationship/Relationship.vue @@ -84,7 +84,6 @@ }, onInput( $event ) { this.$emit('input', $event); - this.$emit('blur'); }, search: _.debounce(function(query) { if ( this.selected.length > 0 && this.metadatum.metadatum.multiple === 'no') diff --git a/src/classes/metadata-types/selectbox/Selectbox.vue b/src/classes/metadata-types/selectbox/Selectbox.vue index 532a63b64..3965d9172 100644 --- a/src/classes/metadata-types/selectbox/Selectbox.vue +++ b/src/classes/metadata-types/selectbox/Selectbox.vue @@ -7,7 +7,6 @@ :placeholder="$i18n.get('label_selectbox_init')" :value="value" :class="{'is-empty': value == undefined || value == ''}" - @blur="$emit('blur')" @input="onChecked($event)">

+ @input="changeValue()"/> + @input="changeValue()"/>
@@ -103,8 +107,7 @@ }, data(){ return { - inputs: [], - metadatumTypeMessage: '' + inputs: [] } }, computed: { @@ -113,27 +116,22 @@ let errors = eventBus.getErrors(this.metadatum.metadatum.id); if (errors) { - this.setMetadatumTypeMessage('is-danger'); for (let error of errors) { - for (let index of Object.keys(error)) { - // this.$console.log(index); + for (let index of Object.keys(error)) errorMessage += error[index] + '\n'; - } } - } else { - this.setMetadatumTypeMessage(''); } return errorMessage; + }, + metadatumTypeMessage() { + return this.getErrorMessage ? 'is-danger' : '' } }, created(){ - this.getValue(); + this.createInputs(); }, methods: { - emitIsChangingValue() { - this.changeValue(); - }, changeValue: _.debounce(function() { if (this.metadatum.value != this.inputs) { @@ -159,7 +157,8 @@ if (this.metadatum.value.id == this.inputs) return; - } else if (this.metadatum.value instanceof Array) { + } else if (this.metadatum.value instanceof Array) { + let equal = []; for (let meta of this.inputs) { @@ -173,16 +172,20 @@ return; } - eventBus.$emit('input', { item_id: this.metadatum.item.id, metadatum_id: this.metadatum.metadatum.id, values: this.inputs } ); + eventBus.$emit('input', { + item_id: this.metadatum.item.id, + metadatum_id: this.metadatum.metadatum.id, + values: this.inputs + } ); } }, 1000), - getValue(){ + createInputs(){ if (this.metadatum.value instanceof Array) { this.inputs = this.metadatum.value.slice(0); if (this.inputs.length === 0) this.inputs.push(''); - + } else { this.metadatum.value == null || this.metadatum.value == undefined ? this.inputs.push('') : this.inputs.push(this.metadatum.value); } @@ -195,12 +198,9 @@ this.inputs.splice(index, 1); this.changeValue(); }, - isTextInputComponent(component){ - let array = ['tainacan-relationship','tainacan-taxonomy']; - return !( array.indexOf( component ) >= 0 ); - }, - setMetadatumTypeMessage(message){ - this.metadatumTypeMessage = message; + isTextInputComponent(component) { + const array = ['tainacan-relationship','tainacan-taxonomy']; + return !(array.indexOf(component) >= 0 ); } } } From 811a86f065a3913eedc1ac86ec3a7768930a28bf Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Thu, 31 Oct 2019 15:24:42 -0300 Subject: [PATCH 10/16] Avoids unecessary patch when loading relationship metadata. Other adjustments to relationship item metatada #320. --- .../scss/_dropdown-and-autocomplete.scss | 1 + .../relationship/Relationship.vue | 120 +++++++++--------- .../metadata-types/tainacan-form-item.vue | 68 +++++----- src/js/event-bus-web-components.js | 37 +++--- 4 files changed, 112 insertions(+), 114 deletions(-) diff --git a/src/admin/scss/_dropdown-and-autocomplete.scss b/src/admin/scss/_dropdown-and-autocomplete.scss index 6e31ab2ac..1d7dbf541 100644 --- a/src/admin/scss/_dropdown-and-autocomplete.scss +++ b/src/admin/scss/_dropdown-and-autocomplete.scss @@ -55,6 +55,7 @@ } .media-content { display: flex; + align-items: center; width: 80%; .ellipsed-text { diff --git a/src/classes/metadata-types/relationship/Relationship.vue b/src/classes/metadata-types/relationship/Relationship.vue index b98d819a7..cdded1bad 100644 --- a/src/classes/metadata-types/relationship/Relationship.vue +++ b/src/classes/metadata-types/relationship/Relationship.vue @@ -4,16 +4,37 @@ expanded :disabled="disabled" :id="id" - v-model="selected" + :value="selected" + @input="onInput" :data="options" :maxtags="maxtags != undefined ? maxtags : (metadatum.metadatum.multiple == 'yes' || allowNew === true ? 100 : 1)" autocomplete attached - :loading="loading" + :loading="isLoading" :aria-close-label="$i18n.get('remove_value')" :class="{'has-selected': selected != undefined && selected != []}" field="label" - @typing="search"/> + @typing="(query) => { options = []; search(query); }"> + + +
@@ -22,17 +43,20 @@ import qs from 'qs'; export default { - created(){ - let collectionId = ( this.metadatum && this.metadatum.metadatum.metadata_type_options.collection_id ) ? this.metadatum.metadatum.metadata_type_options.collection_id : this.collection_id; - if ( this.metadatum.value && (Array.isArray( this.metadatum.value ) ? this.metadatum.value.length > 0 : true )){ + created() { + this.collectionId = ( this.metadatum && this.metadatum.metadatum.metadata_type_options && this.metadatum.metadatum.metadata_type_options.collection_id ) ? this.metadatum.metadatum.metadata_type_options.collection_id : ''; + if (this.metadatum.value && (Array.isArray( this.metadatum.value ) ? this.metadatum.value.length > 0 : true )) { let query = qs.stringify({ postin: ( Array.isArray( this.metadatum.value ) ) ? this.metadatum.value : [ this.metadatum.value ] }); query += this.metadatum.metadatum.metadata_type_options.search ? '&fetch_only_meta=' + this.metadatum.metadatum.metadata_type_options.search : ''; - axios.get('/collection/'+collectionId+'/items?' + query + '&nopaging=1&fetch_only=title,thumbnail') + axios.get('/collection/' + this.collectionId + '/items?' + query + '&nopaging=1&fetch_only=title,thumbnail') .then( res => { if (res.data.items) { - for (let item of res.data.items) { - this.selected.push({ label: this.getItemLabel(item), value: item.id, img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : '' }); - } + for (let item of res.data.items) + this.selected.push({ + label: this.getItemLabel(item), + value: item.id, + img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : '' + }); } }) .catch(error => { @@ -40,99 +64,79 @@ }); } }, - data(){ + data() { return { results:'', selected:[], options: [], - loading: false, - collectionId: 0, + isLoading: false, + collectionId: '', inputValue: null, queryObject: {}, itemsFound: [] } }, props: { - metadatum: { - type: Object - }, - collection_id: { - type: Number - }, + metadatum: Object, id: '', maxtags: undefined, disabled: false, allowNew: true, }, - watch: { - selected( value ){ - this.selected = value; - let values = []; - if( this.selected.length > 0 ){ - for(let val of this.selected){ - values.push( val.value ); - } - } - this.onInput( values ); - } - }, methods: { setResults(option){ if(!option) return; this.results = option.value; }, - onInput( $event ) { - this.$emit('input', $event); + onInput(newSelected) { + this.selected = newSelected; + this.$emit('input', newSelected.map((item) => item.value)); }, search: _.debounce(function(query) { if ( this.selected.length > 0 && this.metadatum.metadatum.multiple === 'no') return ''; if (query !== '') { - this.loading = true; - this.options = []; - - let metaquery = this.mountQuery( query ); - let collectionId = ( this.metadatum && this.metadatum.metadatum.metadata_type_options.collection_id ) ? this.metadatum.metadatum.metadata_type_options.collection_id : this.collection_id; - - axios.get('/collection/'+collectionId+'/items?' + qs.stringify( metaquery )) - .then( res => { - this.loading = false; - this.options = []; - let result = res.data; + this.isLoading = true; - if (result.items) { - for (let item of result.items) { - this.options.push({ label: this.getItemLabel(item), value: item.id }) - } + axios.get('/collection/' + this.collectionId + '/items?' + this.getQueryString(query)) + .then( res => { + this.isLoading = false; + this.options = []; + + if (res.data.items) { + for (let item of res.data.items) + this.options.push({ + label: this.getItemLabel(item), + value: item.id, + img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : '' + }) } }) .catch(error => { this.$console.log(error); }); - } else { - this.options = []; } + }, 500), getItemLabel(item) { let label = ''; for (let m in item.metadata) { - if (item.metadata[m].id == this.metadatum.metadatum.metadata_type_options.search) { + if (item.metadata[m].id == this.metadatum.metadatum.metadata_type_options.search) label = item.metadata[m].value_as_string; - } } - if (label != '' && label != item.title && item.title != '') { + if (label != '' && label != item.title && item.title != '') label += ' (' + item.title + ')'; - } else if (label == '') { + else if (label == '') label = item.title; - } + return label; }, - mountQuery( search ) { + getQueryString( search ) { let query = []; - if ( this.metadatum.metadatum.metadata_type_options && + if (this.metadatum.metadatum.metadata_type_options && this.metadatum.metadatum.metadata_type_options.search) { query['metaquery'] = []; @@ -149,7 +153,7 @@ query['fetch_only'] = 'title,thumbnail'; query['fetch_only_meta'] = this.metadatum.metadatum.metadata_type_options.search; - return query; + return qs.stringify(query); } } } diff --git a/src/classes/metadata-types/tainacan-form-item.vue b/src/classes/metadata-types/tainacan-form-item.vue index ae67629bf..94a4bcb30 100644 --- a/src/classes/metadata-types/tainacan-form-item.vue +++ b/src/classes/metadata-types/tainacan-form-item.vue @@ -133,51 +133,49 @@ }, methods: { changeValue: _.debounce(function() { - - if (this.metadatum.value != this.inputs) { - if (this.inputs.length > 0 && this.inputs[0].value) { - let terms = this.inputs.map(term => term.value) - - if (this.metadatum.value instanceof Array){ - let equal = []; - - for (let meta of terms) { - let foundIndex = this.metadatum.value.findIndex(element => meta == element.id); - if (foundIndex >= 0) - equal.push(this.metadatum.value[foundIndex]); - } - - if (equal.length == terms.length && this.metadatum.value.length <= equal.length) - return; - - } - } else if (this.metadatum.value.constructor.name == 'Object') { - - if (this.metadatum.value.id == this.inputs) - return; - - } else if (this.metadatum.value instanceof Array) { - + if (this.inputs.length > 0 && this.inputs[0].value) { + let terms = this.inputs.map(term => term.value) + + if (this.metadatum.value instanceof Array){ let equal = []; - for (let meta of this.inputs) { + for (let meta of terms) { let foundIndex = this.metadatum.value.findIndex(element => meta == element.id); - if (foundIndex >= 0) equal.push(this.metadatum.value[foundIndex]); } - if (equal.length == this.inputs.length && this.metadatum.value.length <= equal.length) + if (equal.length == terms.length && this.metadatum.value.length <= equal.length) return; - } - eventBus.$emit('input', { - item_id: this.metadatum.item.id, - metadatum_id: this.metadatum.metadatum.id, - values: this.inputs - } ); - } + } + } else if (this.metadatum.value.constructor.name == 'Object') { + + if (this.metadatum.value.id == this.inputs) + return; + + } else if (this.metadatum.value instanceof Array) { + + let equal = []; + + for (let meta of this.inputs) { + let foundIndex = this.metadatum.value.findIndex(element => meta == element.id); + + if (foundIndex >= 0) + equal.push(this.metadatum.value[foundIndex]); + } + + if (equal.length == this.inputs.length && this.metadatum.value.length <= equal.length) + return; + } + + eventBus.$emit('input', { + itemId: this.metadatum.item.id, + metadatumId: this.metadatum.metadatum.id, + values: this.inputs + } ); + }, 1000), createInputs(){ if (this.metadatum.value instanceof Array) { diff --git a/src/js/event-bus-web-components.js b/src/js/event-bus-web-components.js index 995e0d85f..c96a85589 100644 --- a/src/js/event-bus-web-components.js +++ b/src/js/event-bus-web-components.js @@ -15,51 +15,46 @@ export const eventBus = new Vue({ } }, methods : { - updateValue(data){ + updateValue({ itemId, metadatumId, values}){ this.$emit('isUpdatingValue', true); - if (data.item_id) { + if (itemId) { - if (data.values.length > 0 && data.values[0].value) { - let val = []; - for (let i of data.values) - val.push(i.value); - - data.values = val; - } - - let values = ( Array.isArray( data.values[0] ) ) ? data.values[0] : data.values ; + if (values.length > 0 && values[0].value) { + let onlyValues = values.map((aValueObject) => aValueObject.value); + values = onlyValues; + } this.$store.dispatch('item/updateMetadata', { - item_id: data.item_id, - metadatum_id: data.metadatum_id, - values: values + item_id: itemId, + metadatum_id: metadatumId, + values: Array.isArray(values[0]) ? values[0] : values }) .then(() => { this.$emit('isUpdatingValue', false); - let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == data.metadatum_id ); - if ( index >= 0) + let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == metadatumId ); + if (index >= 0) this.errors.splice( index, 1); }) .catch((error) => { this.$emit('isUpdatingValue', false); - let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == data.metadatum_id ); + let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == metadatumId ); let messages = []; for (let index in error) messages.push(error[index]); if ( index >= 0) - Vue.set( this.errors, index, { metadatum_id: data.metadatum_id, errors: messages }); + Vue.set( this.errors, index, { metadatum_id: metadatumId, errors: messages }); else - this.errors.push( { metadatum_id: data.metadatum_id, errors: messages } ); + this.errors.push( { metadatum_id: metadatumId, errors: messages } ); }); } }, getErrors(metadatum_id) { - let error = this.errors.find( errorItem => errorItem.metadatum_id == metadatum_id ); - return ( error ) ? error.errors : false + let error = this.errors.find(errorItem => errorItem.metadatum_id == metadatum_id); + return error ? error.errors : false }, clearAllErrors() { this.errors = []; From 4f814b12d3894e91c52ee8c8e11cc2ad60a9619f Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Thu, 31 Oct 2019 15:56:42 -0300 Subject: [PATCH 11/16] Changes sorting direction on term edition form parent request. Solves overlapping css issue of autocomplete. --- src/admin/components/edition/term-edition-form.vue | 2 +- src/admin/scss/_dropdown-and-autocomplete.scss | 1 + src/classes/metadata-types/tainacan-form-item.vue | 2 +- src/classes/metadata-types/taxonomy/AddNewTerm.vue | 2 +- src/js/store/modules/taxonomy/actions.js | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/admin/components/edition/term-edition-form.vue b/src/admin/components/edition/term-edition-form.vue index 7c1c21dd6..76cd5d2bb 100644 --- a/src/admin/components/edition/term-edition-form.vue +++ b/src/admin/components/edition/term-edition-form.vue @@ -144,7 +144,7 @@ :message="$i18n.get('info_help_parent_term')"/> { // 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") + axios.tainacan.get('/taxonomy/' + taxonomyId + '/terms?searchterm=' + search + '&hierarchical=1&exclude_tree=' + termId + "&hideempty=0&offset=0&number=20&order=asc") .then(res => { let parentTerms = res.data; resolve( parentTerms ); From 52c0f37152cf2f7982009aca9cebc6aa56ce1510 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Thu, 31 Oct 2019 16:21:18 -0300 Subject: [PATCH 12/16] Fixes thumbnail on autocomplete for terms and relationship filter. --- .../components/edition/term-edition-form.vue | 13 +++++++++- .../scss/_dropdown-and-autocomplete.scss | 25 +++++++++++-------- src/admin/scss/_variables.scss | 2 +- .../autocomplete/Autocomplete.vue | 15 ++--------- .../filter-types/filter-types-mixin.js | 7 +++--- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/admin/components/edition/term-edition-form.vue b/src/admin/components/edition/term-edition-form.vue index 76cd5d2bb..4ecf148a2 100644 --- a/src/admin/components/edition/term-edition-form.vue +++ b/src/admin/components/edition/term-edition-form.vue @@ -155,7 +155,18 @@ @focus="clearErrors('parent');" :disabled="!hasParent"> diff --git a/src/admin/scss/_dropdown-and-autocomplete.scss b/src/admin/scss/_dropdown-and-autocomplete.scss index 6ab98fb20..1c3270cbc 100644 --- a/src/admin/scss/_dropdown-and-autocomplete.scss +++ b/src/admin/scss/_dropdown-and-autocomplete.scss @@ -51,19 +51,22 @@ .is-small { color: $gray4; } &.is-active { background-color: $turquoise2; } - .media-left { - margin-right: 0.5rem; - } - .media-content { - display: flex; + .media { align-items: center; - width: 80%; + + .media-left { + margin-right: 0.5rem; + } + .media-content { + display: flex; + width: 80%; - .ellipsed-text { - overflow-x: hidden; - text-overflow: ellipsis; - white-space: nowrap; - margin-right: 3px; + .ellipsed-text { + overflow-x: hidden; + text-overflow: ellipsis; + white-space: nowrap; + margin-right: 3px; + } } } } diff --git a/src/admin/scss/_variables.scss b/src/admin/scss/_variables.scss index dcce3f443..142e9739a 100644 --- a/src/admin/scss/_variables.scss +++ b/src/admin/scss/_variables.scss @@ -121,7 +121,7 @@ $subheader-height: 42px; $side-menu-width: 160px; $filter-menu-width: 16.666666667%; $filter-menu-width-theme: 20.833333333%; -$page-height: calc(100% - 94px); +$page-height: calc(100vh - 94px); // Overall Pages padding: $page-side-padding: 4.166666667%;//82px; diff --git a/src/classes/filter-types/autocomplete/Autocomplete.vue b/src/classes/filter-types/autocomplete/Autocomplete.vue index 11d99df6f..a780b119d 100644 --- a/src/classes/filter-types/autocomplete/Autocomplete.vue +++ b/src/classes/filter-types/autocomplete/Autocomplete.vue @@ -20,7 +20,7 @@ + :src="props.option.img">
{{ props.option.label }} @@ -148,15 +148,4 @@ } } } - - \ No newline at end of file + \ No newline at end of file diff --git a/src/classes/filter-types/filter-types-mixin.js b/src/classes/filter-types/filter-types-mixin.js index a452caf21..d3adc7190 100644 --- a/src/classes/filter-types/filter-types-mixin.js +++ b/src/classes/filter-types/filter-types-mixin.js @@ -276,13 +276,14 @@ export const dynamicFilterTypeMixin = { sResults.push({ label: item.label, value: item.value, + img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : (item.img ? item.img : ''), total_items: item.total_items }); } else if (indexToIgnore < 0) { opts.push({ label: item.label, value: item.value, - img: (item.img ? item.img : this.thumbPlaceholderPath), + img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : (item.img ? item.img : ''), total_items: item.total_items }); } @@ -291,14 +292,14 @@ export const dynamicFilterTypeMixin = { sResults.push({ label: item.label, value: item.value, - img: (item.img ? item.img : this.thumbPlaceholderPath), + img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : (item.img ? item.img : ''), total_items: item.total_items }); } else { opts.push({ label: item.label, value: item.value, - img: (item.img ? item.img : this.thumbPlaceholderPath), + img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : (item.img ? item.img : ''), total_items: item.total_items }); } From 9f4eaa4a7dc5e03785aa338f99a56b92d17f4196 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Thu, 31 Oct 2019 18:29:40 -0300 Subject: [PATCH 13/16] Removes unecessary id prop from metadata components. #320. --- .../bulk-edition/bulk-edition-modal.vue | 4 -- src/classes/metadata-types/date/Date.vue | 7 +--- .../metadata-types/numeric/Numeric.vue | 7 +--- .../relationship/Relationship.vue | 3 +- .../metadata-types/selectbox/Selectbox.vue | 41 ++++++++----------- .../metadata-types/tainacan-form-item.vue | 3 -- .../metadata-types/taxonomy/AddNewTerm.vue | 5 +-- .../metadata-types/taxonomy/Taxonomy.vue | 10 ++--- .../taxonomy/TaxonomyCheckbox.vue | 34 ++++++++------- .../metadata-types/taxonomy/TaxonomyRadio.vue | 9 ++-- .../taxonomy/TaxonomyTaginput.vue | 6 +-- src/classes/metadata-types/text/Text.vue | 3 +- .../metadata-types/textarea/Textarea.vue | 7 +--- 13 files changed, 52 insertions(+), 87 deletions(-) diff --git a/src/admin/components/bulk-edition/bulk-edition-modal.vue b/src/admin/components/bulk-edition/bulk-edition-modal.vue index f12fb76f8..98536d722 100644 --- a/src/admin/components/bulk-edition/bulk-edition-modal.vue +++ b/src/admin/components/bulk-edition/bulk-edition-modal.vue @@ -97,8 +97,6 @@ :maxtags="1" :class="{'is-field-history': bulkEditionProcedures[criterion].isDone}" :disabled="bulkEditionProcedures[criterion].isDone" - :id="getMetadataByID(bulkEditionProcedures[criterion].metadatumID).metadata_type_object.component + - '-' + getMetadataByID(bulkEditionProcedures[criterion].metadatumID).slug" :is="getMetadataByID(bulkEditionProcedures[criterion].metadatumID).metadata_type_object.component" :metadatum="{metadatum: getMetadataByID(bulkEditionProcedures[criterion].metadatumID)}" class="tainacan-bulk-edition-field" @@ -152,8 +150,6 @@ :maxtags="1" :class="{'is-field-history': bulkEditionProcedures[criterion].isDone}" :disabled="bulkEditionProcedures[criterion].isDone || bulkEditionProcedures[criterion].isExecuting" - :id="getMetadataByID(bulkEditionProcedures[criterion].metadatumID).metadata_type_object.component + - '-' + getMetadataByID(bulkEditionProcedures[criterion].metadatumID).slug" :is="getMetadataByID(bulkEditionProcedures[criterion].metadatumID).metadata_type_object.component" :metadatum="{metadatum: getMetadataByID(bulkEditionProcedures[criterion].metadatumID)}" class="tainacan-bulk-edition-field tainacan-bulk-edition-field-last" diff --git a/src/classes/metadata-types/date/Date.vue b/src/classes/metadata-types/date/Date.vue index 242975850..0629f349d 100644 --- a/src/classes/metadata-types/date/Date.vue +++ b/src/classes/metadata-types/date/Date.vue @@ -1,6 +1,7 @@ + \ No newline at end of file diff --git a/src/classes/metadata-types/taxonomy/Taxonomy.vue b/src/classes/metadata-types/taxonomy/Taxonomy.vue index 4514b78c7..0fbc9e661 100644 --- a/src/classes/metadata-types/taxonomy/Taxonomy.vue +++ b/src/classes/metadata-types/taxonomy/Taxonomy.vue @@ -1,60 +1,39 @@ - - \ No newline at end of file diff --git a/src/classes/metadata-types/taxonomy/TaxonomyCheckbox.vue b/src/classes/metadata-types/taxonomy/TaxonomyCheckbox.vue index 346b797f9..ed203f42c 100644 --- a/src/classes/metadata-types/taxonomy/TaxonomyCheckbox.vue +++ b/src/classes/metadata-types/taxonomy/TaxonomyCheckbox.vue @@ -25,7 +25,7 @@ class="control has-icons-right is-loading is-clearfix" /> - \ No newline at end of file + + + \ No newline at end of file diff --git a/src/classes/metadata-types/taxonomy/TaxonomyTaginput.vue b/src/classes/metadata-types/taxonomy/TaxonomyTaginput.vue index 19906744c..b3cc69d70 100644 --- a/src/classes/metadata-types/taxonomy/TaxonomyTaginput.vue +++ b/src/classes/metadata-types/taxonomy/TaxonomyTaginput.vue @@ -37,7 +37,7 @@ }, watch: { selected(){ - if(this.allowSelectToCreate && this.selected[0]){ + if (this.allowSelectToCreate && this.selected[0]) { this.selected[0].label.includes(`(${this.$i18n.get('select_to_create')})`); this.selected[0].label = this.selected[0].label.split('(')[0]; } @@ -45,7 +45,6 @@ }, props: { metadatumComponentId: '', - options: Array, value: [ Number, String, Array ], allowNew: true, taxonomyId: Number, @@ -54,7 +53,7 @@ maxtags: '', }, created(){ - if(this.value && this.value.length > 0){ + if (this.value && this.value.length > 0){ this.selected = this.value; } }, @@ -85,13 +84,11 @@ }).then((res) => { this.termList = res.terms; - for(let term of this.termList){ + for (let term of this.termList) this.labels.push({label: term.name, value: term.id}); - } - if(this.termList.length <= 0 && this.allowSelectToCreate){ + if (this.termList.length <= 0 && this.allowSelectToCreate) this.labels.push({label: `${value} (${this.$i18n.get('select_to_create')})`, value: value}) - } this.isFetching = false; }).catch((error) => { @@ -102,9 +99,8 @@ updateSelectedValues(){ let selected = []; - for( let term of this.value){ + for( let term of this.value) selected.push({label: term.label, value: term.value}) - } this.selected = selected; }, From 6f5c586b16543589c464ffb07362e8d836bc8575 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Mon, 4 Nov 2019 12:11:04 -0300 Subject: [PATCH 16/16] Several updates to terms queries with hideempty and continues the work of #320. --- .../edition/metadatum-edition-form.vue | 2 +- .../components/other/checkbox-radio-modal.vue | 2 +- src/admin/scss/tainacan-admin.scss | 1 + src/admin/tainacan-admin-i18n.php | 9 +- .../filter-types/taxonomy/Taginput.vue | 3 +- .../relationship/Relationship.vue | 3 + .../metadata-types/tainacan-form-item.vue | 66 ++++---- .../metadata-types/taxonomy/AddNewTerm.vue | 47 +++--- .../taxonomy/TaxonomyCheckbox.vue | 59 +++++-- .../metadata-types/taxonomy/TaxonomyRadio.vue | 155 +++++++++++------- .../carousel-terms-list-theme.vue | 2 +- .../carousel-terms-list/index.js | 2 +- 12 files changed, 218 insertions(+), 133 deletions(-) diff --git a/src/admin/components/edition/metadatum-edition-form.vue b/src/admin/components/edition/metadatum-edition-form.vue index 217194366..2c7eeb39e 100644 --- a/src/admin/components/edition/metadatum-edition-form.vue +++ b/src/admin/components/edition/metadatum-edition-form.vue @@ -150,7 +150,7 @@ - + diff --git a/src/admin/components/other/checkbox-radio-modal.vue b/src/admin/components/other/checkbox-radio-modal.vue index dc5f4491b..2ed103415 100644 --- a/src/admin/components/other/checkbox-radio-modal.vue +++ b/src/admin/components/other/checkbox-radio-modal.vue @@ -366,7 +366,7 @@ this.isSelectedTermsLoading = true; - axios.get(`/taxonomy/${this.taxonomy_id}/terms/?${qs.stringify({ include: selected})}`) + axios.get(`/taxonomy/${this.taxonomy_id}/terms/?${qs.stringify({ hideempty: 0, include: selected})}`) .then((res) => { for (const term of res.data) this.saveSelectedTagName(term.id, term.name); diff --git a/src/admin/scss/tainacan-admin.scss b/src/admin/scss/tainacan-admin.scss index a904f487a..f8429551b 100644 --- a/src/admin/scss/tainacan-admin.scss +++ b/src/admin/scss/tainacan-admin.scss @@ -98,6 +98,7 @@ a:hover { .add-link { display: inline; font-size: 0.75rem; + margin: 3px 0 6px 0; &.disabled { pointer-events: none; cursor: default; diff --git a/src/admin/tainacan-admin-i18n.php b/src/admin/tainacan-admin-i18n.php index a63454c57..90c85f187 100644 --- a/src/admin/tainacan-admin-i18n.php +++ b/src/admin/tainacan-admin-i18n.php @@ -199,7 +199,9 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_select_taxonomy_input_type' => __( 'Input type', 'tainacan' ), 'label_taxonomy_allow_new_terms' => __( 'Allow new terms', 'tainacan' ), 'label_selectbox_init' => __( 'Select', 'tainacan' ), - 'label_options' => __( 'Insert options', 'tainacan' ), + 'label_insert_options' => __( 'Insert options', 'tainacan'), + 'label_available_terms' => __( 'Available terms', 'tainacan' ), + 'label_some_available_terms' => __( 'Some available terms', 'tainacan' ), 'label_attachments' => __( 'Attachments', 'tainacan' ), 'label_attachment' => __( 'Attachment', 'tainacan' ), 'label_enabled' => __( 'Enabled', 'tainacan' ), @@ -212,6 +214,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_parent_term' => __( 'Parent Term', 'tainacan' ), 'label_children_terms' => __( 'children terms', 'tainacan' ), 'label_new_term' => __( 'Create New Term', 'tainacan' ), + 'label_create_and_select' => __( 'Create and Select', 'tainacan' ), 'label_new_child' => __( 'New Child', 'tainacan' ), 'label_taxonomy_terms' => __( 'Taxonomy Terms', 'tainacan' ), 'label_no_parent_term' => __( 'No parent term', 'tainacan' ), @@ -347,6 +350,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_show_metadata' => __( 'Show metadata', 'tainacan' ), 'label_all_terms' => __( 'All terms', 'tainacan' ), 'label_selected_terms' => __( 'Selected terms', 'tainacan' ), + 'label_selected_term' => __( 'Selected term', 'tainacan' ), 'label_all_metadatum_values' => __( 'All metadatum values', 'tainacan' ), 'label_selected_metadatum_values' => __( 'Selected metadatum values', 'tainacan' ), 'label_editing_item_number' => __( 'Editing item n.', 'tainacan' ), @@ -445,7 +449,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'instruction_image_upload_box' => __( 'Drop an image here or click to upload.', 'tainacan' ), 'instruction_select_a_status' => __( 'Select a status:', 'tainacan' ), 'instruction_select_a_status2' => __( 'Select a status', 'tainacan' ), - 'instruction_click_to_select_a_filter_type' => __( 'Click to select a filter type:', 'tainacan' ), + 'instruction_click_to_select_a_filter_type' => __( 'Click to select a filter type:', 'tainacan' ), 'instruction_select_a_parent_term' => __( 'Select a parent term:', 'tainacan' ), 'instruction_select_a_metadatum' => __( 'Select a metadatum', 'tainacan' ), 'instruction_cover_page' => __( 'Type to search a Page to choose.', 'tainacan' ), @@ -569,6 +573,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'info_showing_taxonomies' => __( 'Showing taxonomies ', 'tainacan' ), 'info_showing_activities' => __( 'Showing activities ', 'tainacan' ), 'info_showing_processes' => __( 'Showing processes ', 'tainacan' ), + 'info_showing_terms' => __( 'Showing terms ', 'tainacan' ), 'info_warning_remove_from_trash_first' => __( 'Remove this item from trash first' ), 'info_to' => __( ' to ', 'tainacan' ), 'info_of' => __( ' of ', 'tainacan' ), diff --git a/src/classes/filter-types/taxonomy/Taginput.vue b/src/classes/filter-types/taxonomy/Taginput.vue index 848f28021..24946f87b 100644 --- a/src/classes/filter-types/taxonomy/Taginput.vue +++ b/src/classes/filter-types/taxonomy/Taginput.vue @@ -157,7 +157,8 @@ let params = { 'include': metadata.terms, - 'order': 'asc' + 'order': 'asc', + 'fetchonly': 0 }; return axios.get('/taxonomy/' + this.taxonomyId + '/terms/?' + qs.stringify(params) ) diff --git a/src/classes/metadata-types/relationship/Relationship.vue b/src/classes/metadata-types/relationship/Relationship.vue index 899638356..5520ffad6 100644 --- a/src/classes/metadata-types/relationship/Relationship.vue +++ b/src/classes/metadata-types/relationship/Relationship.vue @@ -5,11 +5,14 @@ :disabled="disabled" :id="metadatum.metadatum.metadata_type_object.component + '-' + metadatum.metadatum.slug" :value="selected" + size="is-small" + icon="magnify" @input="onInput" :data="options" :maxtags="maxtags != undefined ? maxtags : (metadatum.metadatum.multiple == 'yes' || allowNew === true ? 100 : 1)" autocomplete attached + :placeholder="$i18n.get('instruction_type_existing_term')" :loading="isLoading" :aria-close-label="$i18n.get('remove_value')" :class="{'has-selected': selected != undefined && selected != []}" diff --git a/src/classes/metadata-types/tainacan-form-item.vue b/src/classes/metadata-types/tainacan-form-item.vue index bafb3bf98..6b24c6c53 100644 --- a/src/classes/metadata-types/tainacan-form-item.vue +++ b/src/classes/metadata-types/tainacan-form-item.vue @@ -46,37 +46,41 @@ v-model="inputs[0]" :metadatum="metadatum" @input="changeValue()"/> - +
@@ -170,19 +174,13 @@ metadatumId: this.metadatum.metadatum.id, values: this.inputs } ); - + }, 900), - createInputs(){ - if (this.metadatum.value instanceof Array) { - + createInputs(){ + if (this.metadatum.value instanceof Array) this.inputs = this.metadatum.value.slice(0); - - if (this.inputs.length === 0) - this.inputs.push(''); - - } else { - this.metadatum.value == null || this.metadatum.value == undefined ? this.inputs.push('') : this.inputs.push(this.metadatum.value); - } + else + this.metadatum.value == null || this.metadatum.value == undefined ? this.inputs = [] : this.inputs.push(this.metadatum.value); }, addInput(){ this.inputs.push(''); diff --git a/src/classes/metadata-types/taxonomy/AddNewTerm.vue b/src/classes/metadata-types/taxonomy/AddNewTerm.vue index de4467123..80b56967e 100644 --- a/src/classes/metadata-types/taxonomy/AddNewTerm.vue +++ b/src/classes/metadata-types/taxonomy/AddNewTerm.vue @@ -10,10 +10,10 @@  {{ $i18n.get('label_new_term') }} - +
+ class="add-new-term-form"> @@ -70,22 +71,22 @@

- - - - +
+ + +
@@ -229,9 +230,15 @@ \ No newline at end of file diff --git a/src/classes/metadata-types/taxonomy/TaxonomyCheckbox.vue b/src/classes/metadata-types/taxonomy/TaxonomyCheckbox.vue index ed203f42c..d33f1a1ac 100644 --- a/src/classes/metadata-types/taxonomy/TaxonomyCheckbox.vue +++ b/src/classes/metadata-types/taxonomy/TaxonomyCheckbox.vue @@ -3,7 +3,7 @@

- {{ $i18n.get('label_selected_terms') + ' :' }} + {{ $i18n.get('label_selected_terms') + ':' }}

- -
+

+ {{ (isShowingAllTerms ? $i18n.get('label_available_terms') : $i18n.get('label_some_available_terms')) + ':' }} +

+ - - {{ $i18n.get('label_view_all') }} - +
+ + {{ + $i18n.get('info_showing_terms') + 1 + + $i18n.get('info_to') + options.length + + $i18n.get('info_of') + totalTerms + '. ' + }} + + + {{ $i18n.get('label_view_all') + ' ' + totalTerms + '.' }} + +
@@ -62,7 +76,6 @@ this.getTermsFromTaxonomy(); this.$parent.$on('update-taxonomy-inputs', ($event) => { if ($event.taxonomyId == this.taxonomyId && $event.metadatumId == this.metadatum.metadatum.id) { - this.terms = []; this.offset = 0; this.getTermsFromTaxonomy(); } @@ -86,6 +99,11 @@ this.fetchSelectedLabels(); } }, + computed: { + isShowingAllTerms() { + return this.terms.length >= this.totalTerms; + } + }, props: { value: [ Number, String, Array ], disabled: false, @@ -109,7 +127,7 @@ if (this.taxonomyId) { this.isSelectedTermsLoading = true; - axios.get(`/taxonomy/${this.taxonomyId}/terms/?${qs.stringify({ include: selected })}`) + axios.get(`/taxonomy/${this.taxonomyId}/terms/?${qs.stringify({ hideempty: 0, include: selected })}`) .then((res) => { let terms = res.data; @@ -128,7 +146,9 @@ } }, getTermsFromTaxonomy() { - let endpoint = '/taxonomy/' + this.taxonomyId + '/terms?hideempty=0&order=asc&number=' + this.termsNumber + '&offset=' + this.offset; + this.terms = []; + + const endpoint = '/taxonomy/' + this.taxonomyId + '/terms?hideempty=0&order=asc&number=' + this.termsNumber + '&offset=' + this.offset; axios.get(endpoint) .then( res => { @@ -193,7 +213,7 @@ } - diff --git a/src/classes/metadata-types/taxonomy/TaxonomyRadio.vue b/src/classes/metadata-types/taxonomy/TaxonomyRadio.vue index 4f847f2b3..56e48355f 100644 --- a/src/classes/metadata-types/taxonomy/TaxonomyRadio.vue +++ b/src/classes/metadata-types/taxonomy/TaxonomyRadio.vue @@ -3,7 +3,7 @@

- {{ $i18n.get('label_selected_terms') + ' :' }} + {{ $i18n.get('label_selected_term') + ':' }}

- - {{ $i18n.get('clear_radio') }} - -
+

+ {{ (isShowingAllTerms ? $i18n.get('label_available_terms') : $i18n.get('label_some_available_terms')) + ':' }} +

+ +
+ + {{ + $i18n.get('info_showing_terms') + 1 + + $i18n.get('info_to') + options.length + + $i18n.get('info_of') + totalTerms + '. ' + }} + + + {{ $i18n.get('label_view_all') + ' ' + totalTerms + '.' }} +
- - {{ $i18n.get('label_view_all') }} -
- \ No newline at end of file diff --git a/src/gutenberg-blocks/tainacan-terms/carousel-terms-list/carousel-terms-list-theme.vue b/src/gutenberg-blocks/tainacan-terms/carousel-terms-list/carousel-terms-list-theme.vue index bd00f838a..eb000cbc3 100644 --- a/src/gutenberg-blocks/tainacan-terms/carousel-terms-list/carousel-terms-list-theme.vue +++ b/src/gutenberg-blocks/tainacan-terms/carousel-terms-list/carousel-terms-list-theme.vue @@ -240,7 +240,7 @@ export default { this.termsRequestSource = axios.CancelToken.source(); - let endpoint = '/taxonomy/' + this.taxonomyId + '/terms/?'+ qs.stringify({ include: this.selectedTerms }) + '&fetch_only=id,name,url,header_image'; + let endpoint = '/taxonomy/' + this.taxonomyId + '/terms/?'+ qs.stringify({ hideempty: 0, include: this.selectedTerms }) + '&fetch_only=id,name,url,header_image'; this.tainacanAxios.get(endpoint, { cancelToken: this.termsRequestSource.token }) .then(response => { diff --git a/src/gutenberg-blocks/tainacan-terms/carousel-terms-list/index.js b/src/gutenberg-blocks/tainacan-terms/carousel-terms-list/index.js index 5652dcc43..8e739259f 100644 --- a/src/gutenberg-blocks/tainacan-terms/carousel-terms-list/index.js +++ b/src/gutenberg-blocks/tainacan-terms/carousel-terms-list/index.js @@ -210,7 +210,7 @@ registerBlockType('tainacan/carousel-terms-list', { terms = []; - let endpoint = '/taxonomy/' + taxonomyId + '/terms/?'+ qs.stringify({ include: selectedTerms }) + '&fetch_only=id,name,url,header_image'; + let endpoint = '/taxonomy/' + taxonomyId + '/terms/?'+ qs.stringify({ hideempty: 0, include: selectedTerms }) + '&fetch_only=id,name,url,header_image'; tainacan.get(endpoint, { cancelToken: itemsRequestSource.token }) .then(response => {