Improves logs exhibition and pages when has no items
This commit is contained in:
parent
4352ac404c
commit
3b48e373b1
|
@ -9,6 +9,7 @@
|
|||
@click="deleteSelectedCollections()"><span>{{ $i18n.get('instruction_delete_selected_collections') }} </span><b-icon icon="delete"/></button>
|
||||
</b-field>
|
||||
<b-table
|
||||
v-if="totalCollections > 0"
|
||||
ref="collectionTable"
|
||||
:data="collections"
|
||||
:checked-rows.sync="selectedCollections"
|
||||
|
@ -100,27 +101,27 @@
|
|||
icon="delete"/></a>
|
||||
</b-table-column>
|
||||
</template>
|
||||
</b-table>
|
||||
|
||||
<!-- Empty state image -->
|
||||
<template slot="empty">
|
||||
<section class="section">
|
||||
<div class="content has-text-grey has-text-centered">
|
||||
<p>
|
||||
<b-icon
|
||||
<!-- Empty state image -->
|
||||
<div v-if="!totalCollections || totalCollections <= 0">
|
||||
<section class="section">
|
||||
<div class="content has-text-grey has-text-centered">
|
||||
<p>
|
||||
<b-icon
|
||||
icon="inbox"
|
||||
size="is-large"/>
|
||||
</p>
|
||||
<p>{{ $i18n.get('info_no_collection_created') }}</p>
|
||||
<router-link
|
||||
tag="button"
|
||||
class="button is-primary"
|
||||
:to="{ path: $routerHelper.getNewCollectionPath() }">
|
||||
{{ $i18n.getFrom('collections', 'new_item') }}
|
||||
</router-link>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
</b-table>
|
||||
</p>
|
||||
<p>{{ $i18n.get('info_no_collection_created') }}</p>
|
||||
<router-link
|
||||
tag="button"
|
||||
class="button is-primary"
|
||||
:to="{ path: $routerHelper.getNewCollectionPath() }">
|
||||
{{ $i18n.getFrom('collections', 'new_item') }}
|
||||
</router-link>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
@ -157,7 +158,7 @@ export default {
|
|||
position: 'is-bottom',
|
||||
type: 'is-secondary',
|
||||
queue: true
|
||||
})
|
||||
});
|
||||
for (let i = 0; i < this.selectedCollections.length; i++) {
|
||||
if (this.selectedCollections[i].id == this.collectionId)
|
||||
this.selectedCollections.splice(i, 1);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<template>
|
||||
<div class="primary-page page-container-small">
|
||||
<div class="sub-header">
|
||||
<div
|
||||
class="sub-header"
|
||||
v-if="totalCollections > 0">
|
||||
<div class="header-item">
|
||||
<router-link
|
||||
id="button-collection-creation"
|
||||
|
@ -12,7 +14,9 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="columns above-subheader">
|
||||
<aside class="column filters-menu">
|
||||
<aside
|
||||
class="column filters-menu"
|
||||
v-if="totalCollections > 0">
|
||||
<h3>{{ $i18n.getFrom('filters', 'name') }}</h3>
|
||||
</aside>
|
||||
<div class="column table-container">
|
||||
|
@ -23,7 +27,9 @@
|
|||
:collections-per-page="collectionsPerPage"
|
||||
:collections="collections"/>
|
||||
<!-- Footer -->
|
||||
<div class="pagination-area">
|
||||
<div
|
||||
class="pagination-area"
|
||||
v-if="totalCollections > 0">
|
||||
<div class="shown-items">
|
||||
{{
|
||||
$i18n.get('info_showing_collections') +
|
||||
|
@ -131,7 +137,7 @@ export default {
|
|||
})
|
||||
.catch(() => {
|
||||
this.$userPrefs.set('collections_per_page', 12, null);
|
||||
});
|
||||
});
|
||||
},
|
||||
mounted(){
|
||||
this.loadCollections();
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
<div
|
||||
class="page-container-small"
|
||||
:class="{'primary-page': isRepositoryLevel}">
|
||||
<div class="sub-header">
|
||||
<div
|
||||
class="sub-header"
|
||||
v-if="items.length > 0">
|
||||
<div class="header-item">
|
||||
<router-link
|
||||
tag="button"
|
||||
|
@ -19,7 +21,9 @@
|
|||
:pref-table-fields="prefTableFields"/>
|
||||
</div>
|
||||
<div class="columns above-subheader">
|
||||
<aside class="column filters-menu">
|
||||
<aside
|
||||
class="column filters-menu"
|
||||
v-if="items.length > 0">
|
||||
<h3>{{ $i18n.get('filters') }}</h3>
|
||||
<filters-items-list />
|
||||
</aside>
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
<div class="tile is-parent">
|
||||
<article class="tile notification is-child is-light">
|
||||
<div class="content">
|
||||
<p class="title">Before change</p>
|
||||
<div class="title">Before change</div>
|
||||
<div
|
||||
v-for="(diff, key) in event.log_diff"
|
||||
v-if="diff.old"
|
||||
:key="key">
|
||||
|
||||
<p/>
|
||||
<div class="has-text-weight-bold is-capitalized">{{ `${key.replace('_', ' ')}:` }}</div>
|
||||
<div class="content">{{ diff.old }}</div>
|
||||
</div>
|
||||
|
@ -22,13 +23,24 @@
|
|||
<div class="tile is-parent">
|
||||
<article class="tile notification is-child is-light">
|
||||
<div class="content">
|
||||
<p class="title">What was changed</p>
|
||||
<div class="title">What was changed</div>
|
||||
<div
|
||||
v-for="(diff, key) in event.log_diff"
|
||||
:key="key">
|
||||
|
||||
<div class="has-text-weight-bold is-capitalized">{{ `${key.replace('_', ' ')}:` }}</div>
|
||||
<div class="content has-text-primary">{{ diff.new }}</div>
|
||||
<p/>
|
||||
<div
|
||||
class="has-text-weight-bold is-capitalized"
|
||||
:class="{'has-text-primary': !diff.old }">
|
||||
{{ `${key.replace('_', ' ')}:` }}
|
||||
</div>
|
||||
<div
|
||||
v-for="(d, i) in diff.new"
|
||||
:key="i"
|
||||
:class="{'has-text-primary': diff.diff_with_index.hasOwnProperty(i) }"
|
||||
class="content is-inline" >
|
||||
{{ d }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
|
|
@ -212,6 +212,7 @@ class Logs extends Repository {
|
|||
'post_type' => Entities\Log::get_post_type(),
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC'
|
||||
];
|
||||
|
||||
$logs = $this->fetch( $args, 'OBJECT' );
|
||||
|
@ -265,8 +266,6 @@ class Logs extends Repository {
|
|||
$description = sprintf( __("The \"%s\" %s has been created.", 'tainacan' ), $name, strtolower($class_name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$msn = apply_filters( 'tainacan-insert-log-message-title', $msn, $type, $new_value );
|
||||
|
|
|
@ -617,6 +617,7 @@ abstract class Repository {
|
|||
|
||||
if ( $old === 0 ) { // self diff or other entity?
|
||||
$id = $new->get_id();
|
||||
|
||||
if ( ! empty( $id ) ) { // there is a repository entity?
|
||||
$old_entity = $this->get_entity_by_post( $new->WP_Post->ID );
|
||||
} else {
|
||||
|
@ -637,19 +638,29 @@ abstract class Repository {
|
|||
if ( $old_entity->get_mapped_property( $prop ) != $new_entity->get_mapped_property( $prop ) ) {
|
||||
|
||||
if ( $mapped['map'] == 'meta_multi' ) {
|
||||
$meta_diff = array_diff( $new_entity->get_mapped_property( $prop ), $old_entity->get_mapped_property( $prop ) );
|
||||
|
||||
if ( ! empty( $meta_diff ) ) {
|
||||
// Array of diffs with index of diff in new array
|
||||
$array_diff_with_index = array_diff_assoc($new_entity->get_mapped_property( $prop ), $old_entity->get_mapped_property( $prop ));
|
||||
|
||||
if ( ! empty( $array_diff_with_index ) ) {
|
||||
|
||||
$diff[ $prop ] = [
|
||||
'new' => $new_entity->get_mapped_property( $prop ),
|
||||
'old' => $old_entity->get_mapped_property( $prop ),
|
||||
'diff' => $meta_diff //TODO better expose difference
|
||||
'diff_with_index' => $array_diff_with_index,
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$new_as_array = explode(' ', $new_entity->get_mapped_property( $prop ));
|
||||
$old_as_array = explode(' ', $old_entity->get_mapped_property( $prop ));
|
||||
|
||||
// Array of diffs with index of diff in new array
|
||||
$array_diff_with_index = array_diff_assoc($new_as_array, $old_as_array);
|
||||
|
||||
$diff[ $prop ] = [
|
||||
'new' => $new_entity->get_mapped_property( $prop ),
|
||||
'old' => $old_entity->get_mapped_property( $prop )
|
||||
'new' => $new_as_array,
|
||||
'old' => $old_entity->get_mapped_property( $prop ),
|
||||
'diff_with_index' => $array_diff_with_index,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Tests;
|
||||
|
||||
use Tainacan\Entities\Log;
|
||||
|
||||
/**
|
||||
|
@ -15,93 +16,96 @@ use Tainacan\Entities\Log;
|
|||
class Logs extends TAINACAN_UnitTestCase {
|
||||
|
||||
|
||||
/**
|
||||
* Teste da insercao de um log simples apenas se criar o dado bruto
|
||||
*/
|
||||
function test_add() {
|
||||
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance();
|
||||
/**
|
||||
* Teste da insercao de um log simples apenas se criar o dado bruto
|
||||
*/
|
||||
function test_add() {
|
||||
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance();
|
||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance();
|
||||
|
||||
$log = $this->tainacan_entity_factory->create_entity(
|
||||
'log',
|
||||
array(
|
||||
'title' => 'blame someone',
|
||||
'description' => 'someone did that'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$blog_id = get_current_blog_id();
|
||||
$log = $this->tainacan_entity_factory->create_entity(
|
||||
'log',
|
||||
array(
|
||||
'title' => 'blame someone',
|
||||
'description' => 'someone did that'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
//retorna a taxonomia
|
||||
$test = $Tainacan_Logs->fetch($log->get_id());
|
||||
$user_id = get_current_user_id();
|
||||
$blog_id = get_current_blog_id();
|
||||
|
||||
$this->assertEquals( 'blame someone', $test->get_title() );
|
||||
$this->assertEquals( 'someone did that', $test->get_description() );
|
||||
$this->assertEquals( $user_id, $test->get_user_id() );
|
||||
$this->assertEquals( $blog_id, $test->get_blog_id() );
|
||||
|
||||
$value = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
'name' => 'testeLogs',
|
||||
'description' => 'adasdasdsa123',
|
||||
'default_order' => 'DESC'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance();
|
||||
|
||||
$value->set_name('new_testeLogs');
|
||||
$value->validate();
|
||||
$new_value = $Tainacan_Collections->insert($value);
|
||||
|
||||
$create_log = Log::create('teste create', 'testing a log creation function', $new_value, $value);
|
||||
|
||||
$this->assertEquals( 'teste create', $create_log->get_title() );
|
||||
$this->assertEquals( 'testing a log creation function', $create_log->get_description() );
|
||||
$this->assertEquals( $new_value, $create_log->get_value() );
|
||||
$this->assertEquals( $value, $create_log->get_old_value() );
|
||||
|
||||
$testDB = $Tainacan_Logs->fetch($create_log->get_id());
|
||||
|
||||
$this->assertEquals( 'teste create', $testDB->get_title() );
|
||||
$this->assertEquals( 'testing a log creation function', $testDB->get_description() );
|
||||
$this->assertEquals( $new_value, $testDB->get_value() );
|
||||
$this->assertEquals( $value, $testDB->get_old_value() );
|
||||
|
||||
$last_log = $Tainacan_Logs->fetch_last();
|
||||
$this->assertTrue(is_object($last_log));
|
||||
$collection = $last_log->get_value();
|
||||
|
||||
$this->assertEquals($collection->get_name(), 'new_testeLogs');
|
||||
$this->assertEquals($collection->get_description(), 'adasdasdsa123');
|
||||
$this->assertEquals($collection->get_default_order(), 'DESC');
|
||||
}
|
||||
//retorna a taxonomia
|
||||
$test = $Tainacan_Logs->fetch( $log->get_id() );
|
||||
|
||||
public function test_log_diff(){
|
||||
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance();
|
||||
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance();
|
||||
$this->assertEquals( 'blame someone', $test->get_title() );
|
||||
$this->assertEquals( 'someone did that', $test->get_description() );
|
||||
$this->assertEquals( $user_id, $test->get_user_id() );
|
||||
$this->assertEquals( $blog_id, $test->get_blog_id() );
|
||||
|
||||
$filter = $this->tainacan_entity_factory->create_entity(
|
||||
'filter',
|
||||
array(
|
||||
'name' => 'No name'
|
||||
),
|
||||
true
|
||||
);
|
||||
$value = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
'name' => 'testeLogs',
|
||||
'description' => 'adasdasdsa123',
|
||||
'default_order' => 'DESC'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
// Modify filter name
|
||||
$filter->set_name('With name');
|
||||
$old_value = $value;
|
||||
|
||||
$Tainacan_Filters->update($filter);
|
||||
$value->set_name( 'new_testeLogs' );
|
||||
$value->validate();
|
||||
|
||||
$log = $Tainacan_Logs->fetch_last();
|
||||
$new_value = $Tainacan_Collections->update( $value );
|
||||
|
||||
$diff = $log->diff();
|
||||
$create_log = Log::create( 'teste create', 'testing a log creation function', $new_value, $old_value );
|
||||
|
||||
$this->assertEquals('With name', $diff['name']['new']);
|
||||
$this->assertEquals('No name', $diff['name']['old']);
|
||||
}
|
||||
$this->assertEquals( 'teste create', $create_log->get_title() );
|
||||
$this->assertEquals( 'testing a log creation function', $create_log->get_description() );
|
||||
$this->assertEquals( $new_value, $create_log->get_value() );
|
||||
$this->assertEquals( $old_value, $create_log->get_old_value() );
|
||||
|
||||
$testDB = $Tainacan_Logs->fetch( $create_log->get_id() );
|
||||
|
||||
$this->assertEquals( 'teste create', $testDB->get_title() );
|
||||
$this->assertEquals( 'testing a log creation function', $testDB->get_description() );
|
||||
$this->assertEquals( $new_value, $testDB->get_value() );
|
||||
$this->assertEquals( $old_value, $testDB->get_old_value() );
|
||||
|
||||
$last_log = $Tainacan_Logs->fetch_last();
|
||||
|
||||
$collection = $last_log->get_value();
|
||||
|
||||
$this->assertEquals( 'new_testeLogs', $collection->get_name() );
|
||||
$this->assertEquals( 'adasdasdsa123', $collection->get_description() );
|
||||
$this->assertEquals( 'DESC', $collection->get_default_order() );
|
||||
}
|
||||
|
||||
public function test_log_diff() {
|
||||
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance();
|
||||
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance();
|
||||
|
||||
$filter = $this->tainacan_entity_factory->create_entity(
|
||||
'filter',
|
||||
array(
|
||||
'name' => 'No name',
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
// Modify filter name
|
||||
$filter->set_name( 'With name' );
|
||||
|
||||
$Tainacan_Filters->update( $filter );
|
||||
|
||||
$log = $Tainacan_Logs->fetch_last();
|
||||
|
||||
$diff = $log->diff();
|
||||
|
||||
$this->assertEquals( 'With name', $diff['name']['new'] );
|
||||
$this->assertEquals( 'No name', $diff['name']['old'] );
|
||||
$this->assertEquals( 'With', $diff['name']['diff_with_index'][0] );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue