Merge branch 'develop' of https://github.com/tainacan/tainacan into develop

This commit is contained in:
weryques 2018-05-04 09:26:34 -03:00
commit 2857159cf4
8 changed files with 175 additions and 130 deletions

View File

@ -102,7 +102,7 @@
height: 21px;
width: 23px;
border: none;
background-color: $primary-light;
background-color: #c1dae0;
color: $secondary;
padding: 0px;
border-top-right-radius: 2px;

View File

@ -27,7 +27,7 @@
<div class="header-item">
<b-dropdown>
<button
class="button"
class="button is-white"
slot="trigger">
<span>{{ $i18n.get('label_table_fields') }}</span>
<b-icon icon="menu-down"/>
@ -66,7 +66,7 @@
</option>
</b-select>
<button
class="button is-small"
class="button is-white is-small"
@click="onChangeOrder()">
<b-icon :icon="order == 'ASC' ? 'sort-ascending' : 'sort-descending'"/>
</button>

View File

@ -65,7 +65,7 @@ $page-height: calc(100% - 53px);
$page-side-padding: 82px;
$page-top-padding: 27px;
$page-small-side-padding: 22px;
$page-small-top-padding: 22px;
$page-small-top-padding: 25px;
$page-mobile-side-padding: 1em;
$page-mobile-top-padding: 0.5em;

View File

@ -75,7 +75,6 @@ html {
}
}
.tainacan-page-title, .tainacan-modal-title {
h1, h2 {
font-size: 20px;
@ -225,18 +224,39 @@ html {
// Some components have a different style in listing pages
.button {
border-width: 0;
border-radius: 6px !important;
font-weight: normal;
padding: 2px 15px !important;
margin-top: 0px !important;
margin-bottom: 0px !important;
height: inherit !important;
box-shadow: none !important;
display: inline-flex !important;
&.is-secondary:hover, &.is-secondary:focus {
background: $secondary !important;
}
&.is-primary:hover, &.is-primary:focus {
background: $primary !important;
}
&.is-success:hover, &.is-success:focus {
background: $success !important;
}
&.is-white:hover, &.is-white:focus {
background: $white !important;
}
&:active {
-webkit-transform: none !important;
transform: none !important;
}
}
.button.is-small {
height: 26px !important;
}
.button:not(.is-small):not(.is-medium):not(.is-large) {
height: 30px !important;
line-height: 20px !important;
font-size: 14px !important;
}
.select {
@ -245,35 +265,50 @@ html {
border: none;
border-radius: 6px !important;
font-weight: normal;
font-size: 14px !important;
height: 30px !important;
padding: 2px 25px 2px 15px!important;
margin-top: 0px !important;
margin-bottom: 0px !important;
&:focus>option:checked, &:focus>option:hover {
option:checked, option:hover {
background-color: $primary-lighter !important;
}
&:focus, &:active {
box-shadow: none !important;
text-decoration: none !important;
}
}
&:not(.is-multiple)::after {
content: "\F35D" !important;
font: normal normal normal 24px/1 "Material Design Icons" !important;
border: none !important;
transform: none;
margin-top: -0.6em;
right: 0.95em;
transform: none !important;
margin-top: -15px !important;
right: 10px !important;
color: $primary;
display: flex !important;
align-items: initial;
}
}
.dropdown {
.dropdown-trigger{
.button {
border: none;
}
.icon {
color: $primary;
align-items: start;
}
}
.button.is-primary, .button.is-secondary, .button.is-success {
.icon {
color: $white;
}
}
}
.dropdown-menu {
top: 26px;
.dropdown-content {
border-radius: 0px;
.dropdown-item {
.b-checkbox { width: 100% };
&:hover {
@ -284,6 +319,7 @@ html {
}
}
}
}
}
.switch {
input[type="checkbox"] + .check {
@ -389,6 +425,12 @@ html {
.pagination {
flex-grow: 1;
.pagination-link, .pagination-previous, .pagination-next {
background-color: transparent;
color: $secondary;
border: none;
}
}
}

View File

@ -475,7 +475,7 @@ abstract class Importer {
public function run(){
if($this->is_repository && $this->current_step < count($this->steps))
{
$process_name = key($this->steps);
//$process_name = key($this->steps);
$function_name = current($this->steps);
$continue = $this->{$function_name}();//If true still there is stuff to process

View File

@ -10,14 +10,22 @@ namespace Tainacan\Importer;
class Old_Tainacan extends Importer
{
public function __construct()
{
parent::__construct();
$this->set_repository();
$this->set_steps($this->steps);
$this->remove_import_method('file');
$this->add_import_method('url');
$this->tainacan_api_address = "/wp-json/tainacan/v1";
$this->wordpress_api_address = "/wp-json/wp/v2";
}
public $avoid = [
'ID',
'post_author',
'post_date',
'post_date_gmt',
/*'post_content',
'post_title',*/
'post_excerpt',
'post_status',
'comment_status',
@ -40,32 +48,7 @@ class Old_Tainacan extends Importer
'Create collections metadata' => 'create_collection_metas',
'Create collections items' => 'create_collection_items',
'Setting relationships' => 'set_relationships'
], $tainacan_api_address, $wordpress_api_address;
public function __construct()
{
parent::__construct();
$this->set_repository();
$this->set_steps($this->steps);
$this->remove_import_method('file');
$this->add_import_method('url');
$this->tainacan_api_address = "/wp-json/tainacan/v1";
$this->wordpress_api_address = "/wp-json/wp/v2";
}
public function verify_process_result($result)
{
if(is_wp_error($result))
{
$this->add_log('error', $result->get_error_message());
return false;
}else if(isset($result['body']))
{
return json_decode($result['body']);
}
return false;
}
], $tainacan_api_address, $wordpress_api_address, $created_categories;
public function create_categories()
@ -95,6 +78,7 @@ class Old_Tainacan extends Importer
/*Insert old tainacan id*/
add_post_meta($inserted_taxonomy->get_id(), 'old_tainacan_category_id', $category->term_id);
$this->created_categories[$category->term_id] = $inserted_taxonomy->get_id();
if(isset($category->children) && $inserted_taxonomy)
{
@ -106,56 +90,6 @@ class Old_Tainacan extends Importer
return false;
}
private function add_all_terms($taxonomy_father, $children, $term_father = null)
{
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
$children = $this->remove_same_name($children);
foreach ($children as $term)
{
$new_term = new \Tainacan\Entities\Term();
$new_term->set_taxonomy($taxonomy_father->get_db_identifier());
if($term_father)
{
$new_term->set_parent($term_father->get_id());
}
$new_term->set_name($term->name);
$new_term->set_description($term->description);
$inserted_term = $Tainacan_Terms->insert($new_term);
/*Insert old tainacan id*/
add_term_meta($inserted_term->get_id(), 'old_tainacan_category_id', $term->term_id );
if(isset($term->children))
{
$this->add_all_terms($taxonomy_father, $term->children, $inserted_term);
}
}
}
public function remove_same_name($terms)
{
$unique = [];
$unique_terms = [];
foreach($terms as $term)
{
$unique[$term->name] = $term->term_id;
}
foreach($terms as $index => $term)
{
if(in_array($term->term_id, $unique))
{
array_push($unique_terms, $term);
}
}
return $unique_terms;
}
public function create_collections()
{
$collections_link = $this->get_url() . $this->tainacan_api_address . "/collections";
@ -182,7 +116,7 @@ class Old_Tainacan extends Importer
public function create_repo_meta()
{
$repository_meta_link = $this->get_url() . $this->tainacan_api_address . "/repository/metadata";
$repository_meta_link = $this->get_url() . $this->tainacan_api_address . "/repository/metadata?includeMetadata=1";
$repo_meta = wp_remote_get($repository_meta_link);
$repo_meta_array = $this->verify_process_result($repo_meta);
@ -216,7 +150,9 @@ class Old_Tainacan extends Importer
$newField->set_field_type('Tainacan\Field_Types\\'.$type);
if(strcmp($type, "Category") == 0)
{
//$newField->set_field_type_options()
$taxonomy_id = $meta->metadata->taxonomy;
$new_category_id = $this->created_categories[$taxonomy_id];
$newField->set_field_type_options(['taxonomy_id' => $new_category_id]);
}
$newField->set_collection_id('default');
@ -245,6 +181,99 @@ class Old_Tainacan extends Importer
return false;
}
/*Aux functions*/
private function add_all_terms($taxonomy_father, $children, $term_father = null)
{
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
$children = $this->remove_same_name($children);
foreach ($children as $term)
{
$new_term = new \Tainacan\Entities\Term();
$new_term->set_taxonomy($taxonomy_father->get_db_identifier());
if($term_father)
{
$new_term->set_parent($term_father->get_id());
}
$new_term->set_name($term->name);
$new_term->set_description($term->description);
$inserted_term = $Tainacan_Terms->insert($new_term);
/*Insert old tainacan id*/
add_term_meta($inserted_term->get_id(), 'old_tainacan_category_id', $term->term_id );
if(isset($term->children))
{
$this->add_all_terms($taxonomy_father, $term->children, $inserted_term);
}
}
}
private function remove_same_name($terms)
{
$unique = [];
$unique_terms = [];
foreach($terms as $term)
{
$unique[$term->name] = $term->term_id;
}
foreach($terms as $index => $term)
{
if(in_array($term->term_id, $unique))
{
array_push($unique_terms, $term);
}
}
return $unique_terms;
}
private function verify_process_result($result)
{
if(is_wp_error($result))
{
$this->add_log('error', $result->get_error_message());
return false;
}else if(isset($result['body']))
{
return json_decode($result['body']);
}
return false;
}
public function define_type($type)
{
$type = strtolower($type);
$tainacan_types = ['text', 'textarea', 'numeric', 'date'];
if(in_array($type, $tainacan_types))
{
$type = ucfirst($type);
}else if(strcmp($type, 'autoincrement') === 0)
{
$type = "Numeric";
}else if(strcmp($type, 'item') === 0)
{
$type = "Relationship";
}else if(strcmp($type, 'tree') === 0)
{
$type = "Category";
}else if(strcmp($type, 'compound') === 0)
{
$type = "Compound";
}
else $type = 'Text';
return $type;
}
/*END aux functions*/
public function fetch_from_remote( $url ){
$url_json = explode('/colecao/', $url)[0] . "/wp-json/tainacan/v1/collections";
@ -442,32 +471,6 @@ class Old_Tainacan extends Importer
$this->set_mapping($mapping);
}
public function define_type($type)
{
$type = strtolower($type);
$tainacan_types = ['text', 'textarea', 'numeric', 'date'];
if(in_array($type, $tainacan_types))
{
$type = ucfirst($type);
}else if(strcmp($type, 'autoincrement') === 0)
{
$type = "Numeric";
}else if(strcmp($type, 'item') === 0)
{
$type = "Relationship";
}else if(strcmp($type, 'tree') === 0)
{
$type = "Category";
}else if(strcmp($type, 'compound') === 0)
{
$type = "Compound";
}
else $type = 'Text';
return $type;
}
/**
* Method implemented by the child importer class to return the number of items to be imported
* @return int

View File

@ -29,7 +29,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
$this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() );
}
/*public function test_automapping_old_tainacan()
public function test_automapping_old_tainacan()
{
//$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
//$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
@ -59,7 +59,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
$_SESSION['tainacan_importer'][$id]->run();
$this->assertTrue(true);
}*/
}
/*public function test_file_old_tainacan () {
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();