Update exhibition of attachment log (#147)

This commit is contained in:
weryques 2018-12-06 14:32:11 -02:00
parent a26fed0273
commit 47172fe2a2
2 changed files with 93 additions and 10 deletions

View File

@ -34,6 +34,48 @@
</picture> </picture>
</div> </div>
</div> </div>
<div
v-if="attributeName == 'attachments'"
class="content">
<p class="is-capitalized has-text-blue5">
{{ attributeName }}
<small class="has-text-gray4"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<div
class="tainacan-attachments-in-modal"
v-if="diff.old.length">
<template v-for="attachment in diff.old">
<div
class="box"
v-if="attachment.mime_type.includes('image')">
<p>{{ `${$i18n.get('label_title')}: ${attachment.title}` }}</p>
<figure
style="height: 150px; width: 150px;"
class="image">
<img
width="100%"
style="height: 100% !important;"
:src="attachment.url"
:alt="attributeName">
</figure>
</div>
<div
class="box"
v-else-if="['pdf', 'audio', 'video'].includes(attachment.mime_type.split('/')[1])">
<p>{{ `${$i18n.get('label_title')}: ${attachment.title}` }}</p>
<object
width="100%"
:data="attachment.url"
:type="attachment.mime_type"/>
</div>
</template>
</div>
<div v-else>
<p>{{ infoEmpty }}</p>
</div>
</div>
<div <div
class="content" class="content"
v-else> v-else>
@ -108,6 +150,48 @@
</picture> </picture>
</div> </div>
</div> </div>
<div
v-if="attributeName == 'attachments'"
class="content">
<p class="is-capitalized has-text-blue5">
{{ attributeName }}
<small class="has-text-gray4"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<div
class="tainacan-attachments-in-modal"
v-if="diff.new.length">
<template v-for="attachment in diff.new">
<div
class="box"
v-if="attachment.mime_type.includes('image')">
<p>{{ `${$i18n.get('label_title')}: ${attachment.title}` }}</p>
<figure
style="height: 150px; width: 150px;"
class="image">
<img
width="100%"
style="height: 100% !important;"
:src="attachment.url"
:alt="attributeName">
</figure>
</div>
<div
class="box"
v-else-if="['pdf', 'audio', 'video'].includes(attachment.mime_type.split('/')[1])">
<p>{{ `${$i18n.get('label_title')}: ${attachment.title}` }}</p>
<object
width="100%"
:data="attachment.url"
:type="attachment.mime_type"/>
</div>
</template>
</div>
<div v-else>
<p>{{ infoEmpty }}</p>
</div>
</div>
<div <div
class="content" class="content"
v-else> v-else>
@ -288,4 +372,11 @@
.modal-card-body { .modal-card-body {
min-height: 400px; min-height: 400px;
} }
.tainacan-attachments-in-modal {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-between;
}
</style> </style>

View File

@ -246,16 +246,8 @@ class Logs extends Repository {
// get all attachments except the new // get all attachments except the new
$old_attachments = $tainacan_post->get_attachments( $post_ID ); $old_attachments = $tainacan_post->get_attachments( $post_ID );
foreach ( $old_attachments as $index => $a ) { // get all attachments
unset( $old_attachments[ $index ]['id'] ); $new_attachments = $tainacan_post->get_attachments();
}
$new_attachments[] = [
'title' => $attachment->post_title,
'description' => $attachment->post_content,
'mime_type' => $attachment->post_mime_type,
'url' => $attachment->guid,
];
$array_diff_with_index = array_map( 'unserialize', $array_diff_with_index = array_map( 'unserialize',
array_diff_assoc( array_map( 'serialize', $new_attachments ), array_map( 'serialize', $old_attachments ) ) ); array_diff_assoc( array_map( 'serialize', $new_attachments ), array_map( 'serialize', $old_attachments ) ) );