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

This commit is contained in:
mateuswetah 2020-12-07 15:33:57 -03:00
commit cd640d4ac3
8 changed files with 63 additions and 36 deletions

View File

@ -183,11 +183,10 @@ class REST_Importers_Controller extends REST_Controller {
* @return string|\WP_Error|\WP_REST_Response
*/
public function update_item( $request ) {
$session_id = $request['session_id'];
$session_id = $request['session_id'];
$body = json_decode($request->get_body(), true);
$body = json_decode($request->get_body(), true);
if(!empty($body)){
if (!empty($body)) {
$attributes = [];
foreach ($body as $att => $value){
@ -197,10 +196,8 @@ class REST_Importers_Controller extends REST_Controller {
global $Tainacan_Importer_Handler;
$importer = $Tainacan_Importer_Handler->get_importer_instance_by_session_id($session_id);
if($importer) {
foreach ($body as $att => $value){
if ($importer) {
foreach ($body as $att => $value) {
if ($att == 'collection') {
if (is_array($value) && isset($value['id'])) {
if ($importer->add_collection($value) === false ) {
@ -383,8 +380,5 @@ class REST_Importers_Controller extends REST_Controller {
return new \WP_REST_Response( $importers, 200 );
}
}
?>

View File

@ -482,8 +482,12 @@ class REST_Metadata_Controller extends REST_Controller {
$attributes = [];
$metadatum_id = $request['metadatum_id'];
$confirm_repository = false;
foreach ($body as $att => $value){
if ($att === "repository_level" && $value === "yes") {
$confirm_repository = true;
continue;
}
$attributes[$att] = $value;
}
@ -491,25 +495,28 @@ class REST_Metadata_Controller extends REST_Controller {
$error_message = __('Metadata with this ID was not found', 'tainacan');
if($metadatum){
if ($metadatum) {
// These conditions are for verify if endpoints are used correctly
if(!$collection_id && $metadatum->get_collection_id() !== 'default') {
$error_message = __('This metadata is not a default metadata', 'tainacan');
return new \WP_REST_Response( [
'error_message' => $error_message,
'metadatum_id' => $metadatum_id
'metadatum_id' => $metadatum_id
] );
} elseif ($collection_id && $metadatum->get_collection_id() === 'default'){
$error_message = __('This metadata is not a collection metadata', 'tainacan');
return new \WP_REST_Response( [
'error_message' => $error_message,
'metadatum_id' => $metadatum_id
'metadatum_id' => $metadatum_id
] );
}
if (isset($request['repository_level']) && $confirm_repository) {
$attributes['collection_id'] = "default";
}
$prepared_metadata = $this->prepare_item_for_updating($metadatum, $attributes);
if($prepared_metadata->validate()){
@ -523,7 +530,7 @@ class REST_Metadata_Controller extends REST_Controller {
return new \WP_REST_Response([
'error_message' => __('One or more values are invalid.', 'tainacan'),
'errors' => $prepared_metadata->get_errors(),
'metadatum' => $this->prepare_item_for_response($prepared_metadata, $request)
'metadatum' => $this->prepare_item_for_response($prepared_metadata, $request)
], 400);
}

View File

@ -653,7 +653,7 @@ class CSV extends Importer {
*
* @param array $processed_item Associative array with metadatum source's as index with
* its value or values
* @param integet $collection_index The index in the $this->collections array of the collection the item is beeing inserted into
* @param integer $collection_index The index in the $this->collections array of the collection the item is being inserted into
*
* @return Tainacan\Entities\Item Item inserted
*/
@ -721,7 +721,7 @@ class CSV extends Importer {
if( is_array( $processed_item ) ) {
foreach ( $processed_item as $metadatum_source => $values ) {
if ( $metadatum_source == 'special_document' ||
if ($metadatum_source == 'special_document' ||
$metadatum_source == 'special_attachments' ||
$metadatum_source == 'special_item_status' ||
$metadatum_source == 'special_comment_status') {
@ -735,9 +735,9 @@ class CSV extends Importer {
}
$metadatum = $Tainacan_Metadata->fetch( $tainacan_metadatum_id );
if( $this->is_empty_value( $values ) ) continue;
if ($this->is_empty_value($values)) continue;
if( $metadatum instanceof Entities\Metadatum ) {
if ($metadatum instanceof Entities\Metadatum) {
$singleItemMetadata = new Entities\Item_Metadata_Entity( $item, $metadatum); // *empty item will be replaced by inserted in the next foreach
if( $metadatum->get_metadata_type() == 'Tainacan\Metadata_Types\Taxonomy' ) {
if( !is_array( $values ) ) {
@ -958,18 +958,25 @@ class CSV extends Importer {
public function add_collection(array $collection) {
if (isset($collection['id'])) {
if( isset($collection['mapping']) && is_array($collection['mapping']) ){
if (isset($collection['mapping']) && is_array($collection['mapping'])) {
foreach( $collection['mapping'] as $metadatum_id => $header ){
if( !is_numeric($metadatum_id) ) {
$metadatum = $this->create_new_metadata( $header, $collection['id']);
if ( $metadatum == false ) {
if (!is_numeric($metadatum_id)) {
$repo_key = "create_repository_metadata";
$collection_id = $collection['id'];
if (strpos($metadatum_id, $repo_key) !== false) {
$collection_id = "default";
}
$metadatum = $this->create_new_metadata($header, $collection_id);
if ($metadatum == false) {
$this->add_error_log( __("Error while creating metadatum, please review the metadatum description.", 'tainacan') );
$this->abort();
return false;
}
if( is_object($metadatum) && $metadatum instanceof \Tainacan\Entities\Metadatum ){
if (is_object($metadatum) && $metadatum instanceof \Tainacan\Entities\Metadatum) {
$collection['mapping'][$metadatum->get_id()] = $header;
} elseif ( is_array($metadatum) && sizeof($metadatum) == 2) {
$parent_header = key($header);

View File

@ -11,7 +11,6 @@ class Importer_Handler {
$this->bg_importer = new Background_Importer();
add_action('init', array(&$this, 'init'));
}
public function init() {
@ -220,5 +219,3 @@ class Importer_Handler {
global $Tainacan_Importer_Handler;
$Tainacan_Importer_Handler = new Importer_Handler();
?>

View File

@ -80,6 +80,11 @@
:value="'create_metadata' + index">
{{ $i18n.get('label_create_metadatum') }}
</option>
<option
v-if="collection && collection.current_user_can_edit_metadata"
:value="'create_repository_metadata' + index">
{{ $i18n.get('label_create_repository_metadata') }}
</option>
<option
v-for="(collectionMetadatum, metadatumIndex) of collectionMetadata"
:key="metadatumIndex"

View File

@ -209,6 +209,21 @@
:message="$i18n.getHelperMessage('metadata', 'collection_key')"/>
</b-checkbox>
</b-field>
<b-field
v-if="!isRepositoryLevel && isOnModal"
>
<b-checkbox
class="is-inline-block"
v-model="editForm.repository_level"
@input="clearErrors('repository_level')"
name="repository_level"
true-value="yes"
false-value="no"
>
{{ $i18n.get('label_repository_metadata') }}
</b-checkbox>
</b-field>
</b-field>
<component
@ -282,13 +297,10 @@
}
},
created() {
this.editForm = this.editedMetadatum;
this.formErrors = this.editForm.formErrors != undefined ? this.editForm.formErrors : {};
this.formErrorMessage = this.editForm.formErrors != undefined ? this.editForm.formErrorMessage : '';
this.oldForm = JSON.parse(JSON.stringify(this.originalMetadatum));
},
mounted() {
// Fills hook forms with it's real values
@ -312,10 +324,13 @@
...mapActions('metadata', [
'updateMetadatum'
]),
saveEdition(metadatum) {
saveEdition(metadatum) {
if ((metadatum.metadata_type_object && metadatum.metadata_type_object.form_component) || metadatum.edit_form == '') {
let repository = this.editForm.repository_level;
if (repository && repository === 'yes') {
this.isRepositoryLevel = true;
}
if ((metadatum.metadata_type_object && metadatum.metadata_type_object.form_component) || metadatum.edit_form == '') {
this.fillExtraFormData(this.editForm);
this.isUpdating = true;
this.updateMetadatum({

View File

@ -3,7 +3,7 @@ import { SnackbarProgrammatic as Snackbar } from 'buefy';
import { ModalProgrammatic as Modal } from 'buefy';
import CustomDialog from '../components/other/custom-dialog.vue'
// Simpler version of the i18n plugin to translate error feedbac messages
// Simpler version of the i18n plugin to translate error feedback messages
const i18nGet = function (key) {
let string = tainacan_plugin.i18n[key];
return (string !== undefined && string !== null && string !== '' ) ? string : "ERROR: Invalid i18n key!";

View File

@ -311,6 +311,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_metadata_mapping' => __( 'Metadata mapping', 'tainacan' ),
'label_select_metadatum' => __( 'Select metadatum', 'tainacan' ),
'label_create_metadatum' => __( 'Create metadatum', 'tainacan' ),
'label_create_repository_metadata' => __( 'Create repository metadata', 'tainacan' ),
'label_select_metadatum_type' => __( 'Select a metadatum type', 'tainacan' ),
'label_add_more_metadata' => __( 'Add more metadata', 'tainacan' ),
'label_from_source_collection' => __( 'From source file', 'tainacan' ),
@ -434,6 +435,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_document_uploaded' => __( 'Document uploaded', 'tainacan' ),
'label_repository_filter' => __( 'Repository filter', 'tainacan' ),
'label_repository_metadatum' => __( 'Repository metadatum', 'tainacan' ),
'label_repository_metadata' => __( 'Repository metadata', 'tainacan' ),
'label_collection_filter' => __( 'Collection filter', 'tainacan' ),
'label_collection_metadatum' => __( 'Collection metadatum', 'tainacan' ),
'label_collection_capabilities' => __( 'Collection capabilities', 'tainacan' ),