Merge branch 'develop' of https://github.com/tainacan/tainacan into develop
This commit is contained in:
commit
f8c8497922
|
@ -843,7 +843,7 @@ export default {
|
|||
height: 30px !important;
|
||||
width: 30px !important;
|
||||
z-index: 99;
|
||||
margin-left: 10px !important;
|
||||
margin-left: 12px !important;
|
||||
|
||||
.icon {
|
||||
display: inherit;
|
||||
|
@ -876,7 +876,7 @@ export default {
|
|||
.header-buttons-row {
|
||||
text-align: right;
|
||||
top: -35px;
|
||||
right: 5px;
|
||||
right: 20px;
|
||||
position: relative;
|
||||
}
|
||||
}
|
||||
|
@ -908,8 +908,8 @@ export default {
|
|||
}
|
||||
.thumbnail-buttons-row {
|
||||
position: relative;
|
||||
left: 100px;
|
||||
bottom: -136px;
|
||||
left: 60px;
|
||||
bottom: -142px;
|
||||
}
|
||||
}
|
||||
.selected-cover-page {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<template>
|
||||
<div>
|
||||
<b-loading
|
||||
:active.sync="isLoading"
|
||||
:can-cancel="false"/>
|
||||
<button
|
||||
id="metadata-column-compress-button"
|
||||
@click="isMetadataColumnCompressed = !isMetadataColumnCompressed">
|
||||
|
@ -291,35 +294,32 @@
|
|||
v-model="visibility"
|
||||
value="publish"
|
||||
native-value="publish">
|
||||
{{ $i18n.get('publish_visibility') }}
|
||||
<span class="icon">
|
||||
<i class="mdi mdi-earth"/>
|
||||
</span> {{ $i18n.get('publish_visibility') }}
|
||||
</b-radio>
|
||||
<b-radio
|
||||
v-model="visibility"
|
||||
value="private"
|
||||
native-value="private">
|
||||
{{ $i18n.get('private_visibility') }}
|
||||
<span class="icon">
|
||||
<i class="mdi mdi-lock"/>
|
||||
</span> {{ $i18n.get('private_visibility') }}
|
||||
</b-radio>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Status -------------------------------- -->
|
||||
<div class="section-label">
|
||||
<!--<div class="section-label">
|
||||
<label>{{ $i18n.get('label_status') }}</label>
|
||||
<span class="required-metadatum-asterisk">*</span>
|
||||
<help-button
|
||||
:title="$i18n.getHelperTitle('items', 'status')"
|
||||
:message="$i18n.getHelperMessage('items', 'status')"/>
|
||||
</div>
|
||||
<!-- Last Updated Info -->
|
||||
<p>{{ ($i18n.get('info_updated_at') + ' ' + lastUpdated) }}
|
||||
<em>
|
||||
<span v-if="isUpdatingValues && !isEditingValues"> {{ $i18n.get('info_updating_metadata_values') }}</span>
|
||||
<span v-if="isEditingValues"> {{ $i18n.get('info_editing_metadata_values') }}</span>
|
||||
</em>
|
||||
</p>
|
||||
<div class="section-status">
|
||||
|
||||
<!--<div class="field has-addons">
|
||||
<div class="field has-addons">
|
||||
<b-select
|
||||
v-model="form.status"
|
||||
:placeholder="$i18n.get('instruction_select_a_status')">
|
||||
|
@ -340,14 +340,8 @@
|
|||
{{ $i18n.get('save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div> -->
|
||||
<p
|
||||
v-if="item.status == 'auto-draft'"
|
||||
class="help is-danger">
|
||||
{{ $i18n.get('info_item_not_saved') }}
|
||||
</p>
|
||||
<p class="help is-danger">{{ formErrorMessage }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>-->
|
||||
|
||||
<label class="section-label">{{ $i18n.get('metadata') }}</label>
|
||||
<br>
|
||||
|
@ -370,18 +364,37 @@
|
|||
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer form-submission-footer">
|
||||
<div v-if="form.status == 'trash'">
|
||||
<div class="footer">
|
||||
<!-- Last Updated Info -->
|
||||
<div class="update-info-section">
|
||||
<p>{{ ($i18n.get('info_updated_at') + ' ' + lastUpdated) }}
|
||||
<em>
|
||||
<span v-if="isUpdatingValues && !isEditingValues"> {{ $i18n.get('info_updating_metadata_values') }}</span>
|
||||
<span v-if="isEditingValues"> {{ $i18n.get('info_editing_metadata_values') }}</span>
|
||||
</em>
|
||||
</p>
|
||||
<p class="help is-danger">{{ errorList }}</p>
|
||||
<p class="help is-danger">{{ formErrorMessage }}</p>
|
||||
</div>
|
||||
<div
|
||||
class="form-submission-footer"
|
||||
v-if="form.status == 'trash'">
|
||||
<button
|
||||
@click="onDeletePermanently()"
|
||||
type="button"
|
||||
class="button is-outlined">{{ $i18n.get('label_delete_permanently') }}</button>
|
||||
<button
|
||||
@click="onSubmit('draft')"
|
||||
type="button"
|
||||
class="button is-secondary">{{ $i18n.get('label_save_as_draft') }}</button>
|
||||
<button
|
||||
@click="onSubmit(visibility)"
|
||||
type="button"
|
||||
class="button is-success">{{ $i18n.get('label_publish') }}</button>
|
||||
</div>
|
||||
<div v-if="form.status == 'auto-draft' || form.status == 'draft' || form.status == undefined">
|
||||
<div
|
||||
class="form-submission-footer"
|
||||
v-if="form.status == 'auto-draft' || form.status == 'draft' || form.status == undefined">
|
||||
<button
|
||||
v-if="form.status == 'draft'"
|
||||
@click="onSubmit('trash')"
|
||||
|
@ -401,7 +414,9 @@
|
|||
type="button"
|
||||
class="button is-success">{{ $i18n.get('label_publish') }}</button>
|
||||
</div>
|
||||
<div v-if="form.status == 'publish' || form.status == 'private'">
|
||||
<div
|
||||
class="form-submission-footer"
|
||||
v-if="form.status == 'publish' || form.status == 'private'">
|
||||
<button
|
||||
@click="onSubmit('trash')"
|
||||
type="button"
|
||||
|
@ -417,10 +432,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<b-loading
|
||||
:active.sync="isLoading"
|
||||
:can-cancel="false"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -487,6 +498,9 @@ export default {
|
|||
},
|
||||
lastUpdated() {
|
||||
return this.getLastUpdated();
|
||||
},
|
||||
errrorList() {
|
||||
return eventBus.errors;
|
||||
}
|
||||
},
|
||||
components: {
|
||||
|
@ -504,7 +518,8 @@ export default {
|
|||
'sendAttachments',
|
||||
'updateThumbnail',
|
||||
'fetchAttachments',
|
||||
'cleanLastUpdated'
|
||||
'cleanLastUpdated',
|
||||
'setLastUpdated'
|
||||
]),
|
||||
...mapGetters('item',[
|
||||
'getMetadata',
|
||||
|
@ -544,6 +559,7 @@ export default {
|
|||
for (let metadatum of Object.keys(error)){
|
||||
eventBus.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
|
||||
}
|
||||
|
||||
}
|
||||
this.formErrorMessage = errors.error_message;
|
||||
this.form.status = previousStatus;
|
||||
|
@ -797,6 +813,7 @@ export default {
|
|||
this.visibility = this.item.status;
|
||||
|
||||
this.loadMetadata();
|
||||
this.setLastUpdated(this.item.modification_date);
|
||||
});
|
||||
|
||||
// Fetch current existing attachments
|
||||
|
@ -804,32 +821,15 @@ export default {
|
|||
}
|
||||
|
||||
// Sets feedback variables
|
||||
eventBus.$on('isChangingValue', () => {
|
||||
if (!this.isEditingValues) {
|
||||
this.isEditingValues = true;
|
||||
setTimeout(()=> {
|
||||
this.isEditingValues = false;
|
||||
}, 2000);
|
||||
this.$toast.open({
|
||||
duration: 2000,
|
||||
message: this.$i18n.get('info_editing_metadata_values'),
|
||||
position: 'is-bottom',
|
||||
})
|
||||
}
|
||||
});
|
||||
eventBus.$on('isUpdatingValue', (status) => {
|
||||
if (!this.isUpdatingValues) {
|
||||
this.isUpdatingValues = status;
|
||||
if (this.isUpdatingValues) {
|
||||
this.$toast.open({
|
||||
duration: 2000,
|
||||
message: this.$i18n.get('info_updating_metadata_values'),
|
||||
position: 'is-bottom',
|
||||
})
|
||||
}
|
||||
} else {
|
||||
this.isUpdatingValues = false;
|
||||
}
|
||||
this.isUpdatingValues = status;
|
||||
// if (this.isUpdatingValues) {
|
||||
// this.$toast.open({
|
||||
// duration: 2000,
|
||||
// message: this.$i18n.get('info_updating_metadata_values'),
|
||||
// position: 'is-bottom',
|
||||
// })
|
||||
// }
|
||||
});
|
||||
this.cleanLastUpdated();
|
||||
},
|
||||
|
@ -886,7 +886,7 @@ export default {
|
|||
}
|
||||
|
||||
.page-container-shrinked {
|
||||
height: calc(100% - 136px) !important; // Bigger than the others due footer's height
|
||||
height: calc(100% - 132px) !important; // Bigger than the others due footer's height
|
||||
}
|
||||
|
||||
.page-container {
|
||||
|
@ -917,6 +917,10 @@ export default {
|
|||
padding: 10px 0px 10px 60px;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 769px) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -933,7 +937,9 @@ export default {
|
|||
|
||||
.collapse-all {
|
||||
font-size: 12px;
|
||||
.icon { vertical-align: bottom; }
|
||||
.icon {
|
||||
vertical-align: bottom;
|
||||
}
|
||||
}
|
||||
|
||||
.section-box {
|
||||
|
@ -967,6 +973,13 @@ export default {
|
|||
}
|
||||
.section-status{
|
||||
padding: 16px 0;
|
||||
.field .b-radio {
|
||||
margin-right: 24px;
|
||||
.icon {
|
||||
font-size: 18px !important;
|
||||
color: $gray;
|
||||
}
|
||||
}
|
||||
}
|
||||
.section-attachments {
|
||||
border: 1px solid $draggable-border-color;
|
||||
|
@ -1044,15 +1057,38 @@ export default {
|
|||
}
|
||||
}
|
||||
|
||||
.form-submission-footer {
|
||||
.footer {
|
||||
|
||||
padding: 24px $page-side-padding;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
z-index: 999999;
|
||||
background-color: white;
|
||||
border-top: 2px solid $secondary;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: end;
|
||||
|
||||
.form-submission-footer {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: end;
|
||||
|
||||
.button {
|
||||
margin-left: 6px;
|
||||
margin-right: 6px;
|
||||
}
|
||||
.button.is-outlined {
|
||||
margin-left: 0px;
|
||||
margin-right: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.update-info-section {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
margin-top: -20px;
|
||||
top: 28px;
|
||||
color: $gray-light;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<template>
|
||||
<div>
|
||||
<b-loading :active.sync="isLoadingMetadatumTypes"/>
|
||||
<b-loading :active.sync="isLoadingMetadatumMappers"/>
|
||||
<tainacan-title v-if="!isRepositoryLevel"/>
|
||||
<p v-if="isRepositoryLevel">{{ $i18n.get('info_repository_metadata_inheritance') }}</p>
|
||||
<br>
|
||||
|
@ -138,8 +139,185 @@
|
|||
</div>
|
||||
</b-tab-item>
|
||||
<!-- Exposer -->
|
||||
<b-tab-item :label="$i18n.get('mapping')">
|
||||
<p>Under construction. You will be able to map your metadata to other metadata standards in this page.</p>
|
||||
<b-tab-item
|
||||
:label="$i18n.get('mapping')"
|
||||
v-model="activeMetadatumList">
|
||||
<div class="active-metadata-area">
|
||||
<section
|
||||
v-if="activeMetadatumList.length <= 0 && !isLoadingMetadata"
|
||||
class="field is-grouped-centered section">
|
||||
<div class="content has-text-gray has-text-centered">
|
||||
<p>
|
||||
<b-icon
|
||||
icon="format-list-bulleted-type"
|
||||
size="is-large"/>
|
||||
</p>
|
||||
<p>{{ $i18n.get('info_there_is_no_metadatum' ) }}</p>
|
||||
<p>{{ $i18n.get('info_create_metadata' ) }}</p>
|
||||
</div>
|
||||
</section>
|
||||
<section >
|
||||
<div class="field is-grouped form-submit">
|
||||
<b-select
|
||||
id="mappers-options-dropdown"
|
||||
class="button is-secondary"
|
||||
:placeholder="$i18n.get('instruction_select_a_mapper')">
|
||||
<option
|
||||
v-for="metadatum_mapper in metadatum_mappers"
|
||||
:key="metadatum_mapper.slug"
|
||||
@click="onSelectMetadataMapper(metadatum_mapper)">
|
||||
{{ $i18n.get(metadatum_mapper.name) }}
|
||||
</option>
|
||||
</b-select>
|
||||
<div
|
||||
class="control"
|
||||
v-if="mapper != '' && !isLoadingMetadatumMappers">
|
||||
<button
|
||||
class="button is-outlined"
|
||||
type="button"
|
||||
@click="onCancelUpdateMetadataMapperMetadata">{{ $i18n.get('cancel') }}</button>
|
||||
</div>
|
||||
<div
|
||||
class="control"
|
||||
v-if="mapper != '' && !isLoadingMetadatumMappers">
|
||||
<button
|
||||
@click.prevent="onUpdateMetadataMapperMetadataClick"
|
||||
class="button is-success">{{ $i18n.get('save') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<template>
|
||||
<section>
|
||||
<b-table
|
||||
:data="mapperMetadata"
|
||||
:loading="isMapperMetadataLoading">
|
||||
|
||||
<template slot-scope="props">
|
||||
<b-table-column
|
||||
field="label"
|
||||
:label="$i18n.get('label_mapper_metadata')">
|
||||
{{ props.row.label }}
|
||||
</b-table-column>
|
||||
|
||||
<b-table-column
|
||||
field="slug"
|
||||
:label="$i18n.get('metadatum')">
|
||||
<b-select
|
||||
:name="'mappers-metadatum-select-' + props.row.slug"
|
||||
v-model="props.row.selected"
|
||||
@input="onSelectMetadatumForMapperMetadata">
|
||||
<option
|
||||
value="">
|
||||
{{ $i18n.get('instruction_select_a_metadatum') }}
|
||||
</option>
|
||||
<option
|
||||
v-for="(metadatum, index) in activeMetadatumList"
|
||||
:key="index"
|
||||
:value="metadatum.id"
|
||||
:disabled="isMetadatumSelected(metadatum.id)">
|
||||
{{ metadatum.name }}
|
||||
</option>
|
||||
</b-select>
|
||||
</b-table-column>
|
||||
<b-table-column
|
||||
field="isCustom"
|
||||
label="">
|
||||
<a
|
||||
:style="{ visibility:
|
||||
props.row.isCustom
|
||||
? 'visible' : 'hidden'
|
||||
}"
|
||||
@click.prevent="editMetadatumCustomMapper(props.row)">
|
||||
<b-icon
|
||||
type="is-gray"
|
||||
icon="pencil"/>
|
||||
</a>
|
||||
<a
|
||||
:style="{ visibility:
|
||||
props.row.isCustom
|
||||
? 'visible' : 'hidden'
|
||||
}"
|
||||
@click.prevent="removeMetadatumCustomMapper(props.row)">
|
||||
<b-icon
|
||||
type="is-gray"
|
||||
icon="delete"/>
|
||||
</a>
|
||||
</b-table-column>
|
||||
</template>
|
||||
</b-table>
|
||||
</section>
|
||||
<section
|
||||
v-if="mapper != '' && mapper.allow_extra_metadata">
|
||||
<div
|
||||
class="modal-new-link">
|
||||
<a
|
||||
v-if="collectionId != null && collectionId != undefined"
|
||||
class="is-inline is-pulled-left add-link"
|
||||
@click="onNewMetadataMapperMetadata()">
|
||||
<b-icon
|
||||
icon="plus-circle"
|
||||
size="is-small"
|
||||
type="is-secondary"/>
|
||||
{{ $i18n.get('label_add_more_mapper_metadata') }}
|
||||
</a>
|
||||
</div>
|
||||
</section>
|
||||
<b-modal
|
||||
@close="onCancelNewMetadataMapperMetadata"
|
||||
:active.sync="isMapperMetadataCreating">
|
||||
<div
|
||||
class="tainacan-modal-content">
|
||||
<div class="tainacan-modal-title">
|
||||
<h2>{{ $i18n.get('instruction_insert_mapper_metadatum_info') }}</h2>
|
||||
<hr>
|
||||
</div>
|
||||
<b-field>
|
||||
<b-input
|
||||
v-model="new_metadata_label"
|
||||
required
|
||||
:placeholder="$i18n.get('label_name')"/>
|
||||
</b-field>
|
||||
<b-field>
|
||||
<b-input
|
||||
placeholder="URI"
|
||||
type="url"
|
||||
required
|
||||
v-model="new_metadata_uri"/>
|
||||
</b-field>
|
||||
<div class="field is-grouped form-submit">
|
||||
<div class="control">
|
||||
<button
|
||||
class="button is-outlined"
|
||||
type="button"
|
||||
@click="onCancelNewMetadataMapperMetadata">{{ $i18n.get('cancel') }}</button>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button
|
||||
@click.prevent="onSaveNewMetadataMapperMetadata"
|
||||
:disabled="isNewMetadataMapperMetadataDisabled"
|
||||
class="button is-success">{{ $i18n.get('save') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</b-modal>
|
||||
</template>
|
||||
<section
|
||||
v-if="mapper != '' && !isLoadingMetadatumMappers">
|
||||
<div class="field is-grouped form-submit w-100">
|
||||
<div class="control">
|
||||
<button
|
||||
class="button is-outlined"
|
||||
type="button"
|
||||
@click="onCancelUpdateMetadataMapperMetadata">{{ $i18n.get('cancel') }}</button>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button
|
||||
@click.prevent="onUpdateMetadataMapperMetadataClick"
|
||||
class="button is-success">{{ $i18n.get('save') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</b-tab-item>
|
||||
</b-tabs>
|
||||
</div>
|
||||
|
@ -158,13 +336,23 @@ export default {
|
|||
collectionId: '',
|
||||
isRepositoryLevel: false,
|
||||
isDraggingFromAvailable: false,
|
||||
isLoadingMetadatumMappers: true,
|
||||
mapper: '',
|
||||
mapperMetadata: [],
|
||||
isMapperMetadataLoading: false,
|
||||
isMapperMetadataCreating: false,
|
||||
mappedMetadata: [],
|
||||
isLoadingMetadatumTypes: true,
|
||||
isLoadingMetadata: false,
|
||||
isLoadingMetadatum: false,
|
||||
openedMetadatumId: '',
|
||||
formWithErrors: '',
|
||||
hightlightedMetadatum: '',
|
||||
editForms: {}
|
||||
editForms: {},
|
||||
newMapperMetadataList: [],
|
||||
new_metadata_label: '',
|
||||
new_metadata_uri: '',
|
||||
new_metadata_slug: ''
|
||||
}
|
||||
},
|
||||
components: {
|
||||
|
@ -187,6 +375,16 @@ export default {
|
|||
set(value) {
|
||||
this.updateMetadata(value);
|
||||
}
|
||||
},
|
||||
metadatum_mappers: {
|
||||
get() {
|
||||
return this.getMetadatumMappers();
|
||||
}
|
||||
},
|
||||
isNewMetadataMapperMetadataDisabled: {
|
||||
get() {
|
||||
return !this.new_metadata_label || !this.new_metadata_uri;
|
||||
}
|
||||
}
|
||||
},
|
||||
beforeRouteLeave ( to, from, next ) {
|
||||
|
@ -221,11 +419,14 @@ export default {
|
|||
'sendMetadatum',
|
||||
'deleteMetadatum',
|
||||
'updateMetadata',
|
||||
'updateCollectionMetadataOrder'
|
||||
'updateCollectionMetadataOrder',
|
||||
'fetchMetadatumMappers',
|
||||
'updateMetadataMapperMetadata'
|
||||
]),
|
||||
...mapGetters('metadata',[
|
||||
'getMetadatumTypes',
|
||||
'getMetadata'
|
||||
'getMetadata',
|
||||
'getMetadatumMappers'
|
||||
]),
|
||||
handleChange(event) {
|
||||
if (event.added) {
|
||||
|
@ -315,6 +516,203 @@ export default {
|
|||
this.formWithErrors = '';
|
||||
delete this.editForms[this.openedMetadatumId];
|
||||
this.openedMetadatumId = '';
|
||||
},
|
||||
onSelectMetadataMapper(metadatum_mapper) {
|
||||
this.isMapperMetadataLoading = true;
|
||||
this.mapper = metadatum_mapper; //TODO try to use v-model again
|
||||
this.mapperMetadata = [];
|
||||
this.mappedMetadata = [];
|
||||
|
||||
if(metadatum_mapper != '') {
|
||||
for (var k in metadatum_mapper.metadata) {
|
||||
var item = metadatum_mapper.metadata[k];
|
||||
item.slug = k;
|
||||
item.selected = '';
|
||||
item.isCustom = false;
|
||||
this.activeMetadatumList.forEach((metadatum) => {
|
||||
if(
|
||||
metadatum.exposer_mapping.hasOwnProperty(metadatum_mapper.slug) &&
|
||||
metadatum.exposer_mapping[metadatum_mapper.slug] == item.slug
|
||||
) {
|
||||
item.selected = metadatum.id;
|
||||
this.mappedMetadata.push(metadatum.id);
|
||||
}
|
||||
});
|
||||
this.mapperMetadata.push(item);
|
||||
}
|
||||
this.activeMetadatumList.forEach((metadatum) => {
|
||||
if(
|
||||
metadatum.exposer_mapping.hasOwnProperty(metadatum_mapper.slug) &&
|
||||
typeof metadatum.exposer_mapping[metadatum_mapper.slug] == 'object'
|
||||
) {
|
||||
this.newMapperMetadataList.push(Object.assign({},metadatum.exposer_mapping[metadatum_mapper.slug]));
|
||||
this.mappedMetadata.push(metadatum.id);
|
||||
var item = Object.assign({},metadatum.exposer_mapping[metadatum_mapper.slug]);
|
||||
item.selected = metadatum.id;
|
||||
item.isCustom = true;
|
||||
this.mapperMetadata.push(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.isMapperMetadataLoading = false;
|
||||
},
|
||||
isMetadatumSelected(id) {
|
||||
return this.mappedMetadata.indexOf(id) > -1;
|
||||
},
|
||||
onSelectMetadatumForMapperMetadata() {
|
||||
this.mappedMetadata = [];
|
||||
this.mapperMetadata.forEach((item) => {
|
||||
if(item.selected.length != 0) {
|
||||
this.mappedMetadata.push(item.selected);
|
||||
}
|
||||
});
|
||||
},
|
||||
onUpdateMetadataMapperMetadataClick() {
|
||||
this.isMapperMetadataLoading = true;
|
||||
var metadataMapperMetadata = [];
|
||||
this.mapperMetadata.forEach((item) => {
|
||||
if (item.selected.length != 0) {
|
||||
var map = {
|
||||
metadatum_id: item.selected,
|
||||
mapper_metadata: item.slug
|
||||
};
|
||||
metadataMapperMetadata.push(map);
|
||||
}
|
||||
});
|
||||
this.activeMetadatumList.forEach((item) => {
|
||||
if(this.mappedMetadata.indexOf(item.id) == -1) {
|
||||
var map = {
|
||||
metadatum_id: item.id,
|
||||
mapper_metadata: ''
|
||||
};
|
||||
metadataMapperMetadata.push(map);
|
||||
}
|
||||
});
|
||||
this.newMapperMetadataList.forEach((item) => {
|
||||
var slug = item.slug;
|
||||
metadataMapperMetadata.forEach( (meta, index) => {
|
||||
if(meta.mapper_metadata == slug) {
|
||||
var item_clone = Object.assign({}, item); // TODO check if still need to clone
|
||||
delete item_clone.selected;
|
||||
delete item_clone.isCustom;
|
||||
meta.mapper_metadata = item_clone;
|
||||
metadataMapperMetadata[index] = meta;
|
||||
}
|
||||
});
|
||||
});
|
||||
this.updateMetadataMapperMetadata({metadataMapperMetadata: metadataMapperMetadata, mapper: this.mapper.slug}).then(() => {
|
||||
this.isLoadingMetadata = true;
|
||||
this.refreshMetadata();
|
||||
this.isMapperMetadataLoading = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.isMapperMetadataLoading = false;
|
||||
});
|
||||
},
|
||||
onCancelUpdateMetadataMapperMetadata() {
|
||||
this.isMapperMetadataLoading = true;
|
||||
this.onSelectMetadataMapper(this.mapper);
|
||||
this.isMapperMetadataLoading = false;
|
||||
},
|
||||
onNewMetadataMapperMetadata() {
|
||||
this.isMapperMetadataCreating = true;
|
||||
},
|
||||
onCancelNewMetadataMapperMetadata() {
|
||||
this.isMapperMetadataCreating = false;
|
||||
this.new_metadata_label = '';
|
||||
this.new_metadata_uri = '';
|
||||
this.new_metadata_slug = '';
|
||||
},
|
||||
onSaveNewMetadataMapperMetadata() {
|
||||
this.isMapperMetadataLoading = true;
|
||||
var newMapperMetadata = {
|
||||
label: this.new_metadata_label,
|
||||
uri: this.new_metadata_uri,
|
||||
slug: this.stringToSlug(this.new_metadata_label),
|
||||
isCustom: true
|
||||
};
|
||||
var selected = '';
|
||||
if(this.new_metadata_slug != '') { // Editing
|
||||
this.newMapperMetadataList.forEach((meta, index) => {
|
||||
if(meta.slug == this.new_metadata_slug) {
|
||||
this.newMapperMetadataList.splice(index);
|
||||
this.mapperMetadata.forEach((item, index2) => {
|
||||
if (item.slug == this.new_metadata_slug) {
|
||||
selected = item.selected;
|
||||
this.mapperMetadata.splice(index2);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
this.newMapperMetadataList.push(newMapperMetadata);
|
||||
newMapperMetadata.selected = selected;
|
||||
this.mapperMetadata.push(newMapperMetadata);
|
||||
this.new_metadata_label = '';
|
||||
this.new_metadata_uri = '';
|
||||
this.new_metadata_slug = '';
|
||||
this.isMapperMetadataCreating = false;
|
||||
this.isMapperMetadataLoading = false;
|
||||
},
|
||||
stringToSlug(str) { // adapted from https://gist.github.com/spyesx/561b1d65d4afb595f295
|
||||
str = str.replace(/^\s+|\s+$/g, ''); // trim
|
||||
str = str.toLowerCase();
|
||||
|
||||
// remove accents, swap ñ for n, etc
|
||||
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
|
||||
var to = "aaaaeeeeiiiioooouuuunc------";
|
||||
|
||||
for (var i=0, l=from.length ; i<l ; i++) {
|
||||
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
|
||||
}
|
||||
|
||||
str = str.replace('.', '-') // replace a dot by a dash
|
||||
.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
|
||||
.replace(/\s+/g, '-') // collapse whitespace and replace by a dash
|
||||
.replace(/-+/g, '-'); // collapse dashes
|
||||
|
||||
return str;
|
||||
},
|
||||
editMetadatumCustomMapper(customMapperMeta) {
|
||||
this.new_metadata_label = customMapperMeta.label;
|
||||
this.new_metadata_uri = customMapperMeta.uri;
|
||||
this.new_metadata_slug = customMapperMeta.slug;
|
||||
this.isMapperMetadataCreating = true;
|
||||
},
|
||||
removeMetadatumCustomMapper(customMapperMeta) {
|
||||
var itemid = 0;
|
||||
this.newMapperMetadataList.forEach((meta, index) => {
|
||||
if(meta.slug == customMapperMeta.slug) {
|
||||
this.newMapperMetadataList.splice(index);
|
||||
var rem = this.mappedMetadata.indexOf(meta.selected);
|
||||
this.mappedMetadata.splice(rem);
|
||||
itemid = customMapperMeta.selected;
|
||||
}
|
||||
});
|
||||
if(itemid != '' && itemid > 0) {
|
||||
this.mapperMetadata.forEach((item, index) => {
|
||||
if (item.selected == itemid) {
|
||||
this.mapperMetadata.splice(index);
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
},
|
||||
refreshMetadata() {
|
||||
this.isRepositoryLevel = this.$route.name == 'MetadataPage' ? true : false;
|
||||
if (this.isRepositoryLevel)
|
||||
this.collectionId = 'default';
|
||||
else
|
||||
this.collectionId = this.$route.params.collectionId;
|
||||
|
||||
|
||||
this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: true})
|
||||
.then(() => {
|
||||
this.isLoadingMetadata = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.isLoadingMetadata = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
created() {
|
||||
|
@ -328,20 +726,13 @@ export default {
|
|||
.catch(() => {
|
||||
this.isLoadingMetadatumTypes = false;
|
||||
});
|
||||
|
||||
this.isRepositoryLevel = this.$route.name == 'MetadataPage' ? true : false;
|
||||
if (this.isRepositoryLevel)
|
||||
this.collectionId = 'default';
|
||||
else
|
||||
this.collectionId = this.$route.params.collectionId;
|
||||
|
||||
|
||||
this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: true})
|
||||
this.refreshMetadata();
|
||||
this.fetchMetadatumMappers()
|
||||
.then(() => {
|
||||
this.isLoadingMetadata = false;
|
||||
this.isLoadingMetadatumMappers = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.isLoadingMetadata = false;
|
||||
this.isLoadingMetadatumMappers = false;
|
||||
});
|
||||
},
|
||||
mounted() {
|
||||
|
@ -367,6 +758,16 @@ export default {
|
|||
margin: 1em 0em 2.0em 0em;
|
||||
}
|
||||
|
||||
.w-100 {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.modal-new-link {
|
||||
padding: 0.5em 1em 3em 1em;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
animation: spinAround 500ms infinite linear;
|
||||
border: 2px solid #dbdbdb;
|
||||
|
@ -700,5 +1101,9 @@ export default {
|
|||
|
||||
}
|
||||
}
|
||||
#mappers-options-dropdown {
|
||||
background-color: transparent;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
</style>
|
||||
</style>
|
||||
|
|
|
@ -13,6 +13,7 @@ import Page from '../pages/lists/taxonomies-page.vue'
|
|||
import TaxonomyPage from '../pages/singles/taxonomy-page.vue'
|
||||
import EventsPage from '../pages/lists/events-page.vue'
|
||||
import EventPage from '../pages/singles/event-page.vue'
|
||||
import ExportPage from '../pages/singles/export-page.vue'
|
||||
|
||||
// Edition Form Components
|
||||
import CollectionEditionForm from '../components/edition/collection-edition-form.vue'
|
||||
|
@ -71,6 +72,10 @@ const routes = [
|
|||
{ path: '/importers/', name: 'AvailableImportersPage', component: AvailableImportersPage, meta: {title: i18nGet('title_importers_page'), icon: 'file-multiple'} },
|
||||
{ path: '/importers/:importerSlug', name: 'ImporterEditionForm', component: ImporterEditionForm, meta: {title: i18nGet('title_importer_page'), icon: 'file-multiple'} },
|
||||
|
||||
{ path: '/export/collection/:collectionId', name: 'ExportCollection', component: ExportPage, meta: {title: i18nGet('title_export_collection_page'), icon: 'export'} },
|
||||
{ path: '/export/item/:itemId', name: 'ExportItem', component: ExportPage, meta: {title: i18nGet('title_export_item_page'), icon: 'export'} },
|
||||
{ path: '/export', name: 'Export', component: ExportPage, meta: {title: i18nGet('title_export_page'), icon: 'export'} },
|
||||
|
||||
{ path: '*', redirect: '/'}
|
||||
];
|
||||
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<template>
|
||||
<div class="columns is-fullheight">
|
||||
<section class="column is-secondary-content">
|
||||
<tainacan-subheader
|
||||
:class="{ 'is-shrink': shouldShrinkHeader }"
|
||||
:id="collectionId"/>
|
||||
<router-view
|
||||
@onShrinkHeader="onUpdateShrinkHeader($event)"
|
||||
id="export-page-container"
|
||||
:collection-id="collectionId"
|
||||
class="page-container page-container-small"
|
||||
:class="{'page-container-shrinked': shouldShrinkHeader }"/>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import TainacanSubheader from '../../components/navigation/tainacan-subheader.vue';
|
||||
|
||||
export default {
|
||||
name: 'ExportPage',
|
||||
data(){
|
||||
return {
|
||||
collectionId: Number,
|
||||
itemId: Number,
|
||||
selectedList: [],
|
||||
shouldShrinkHeader: false
|
||||
}
|
||||
},
|
||||
components: {
|
||||
TainacanSubheader
|
||||
},
|
||||
created(){
|
||||
this.collectionId = parseInt(this.$route.params.collectionId);
|
||||
this.itemId = parseInt(this.$route.params.itemId);
|
||||
this.selectedList = [],
|
||||
this.$eventBusSearch.setCollectionId(this.collectionId);
|
||||
},
|
||||
methods: {
|
||||
onUpdateShrinkHeader(event) {
|
||||
if (this.shouldShrinkHeader != event)
|
||||
this.shouldShrinkHeader = event;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
|
||||
|
|
@ -9,86 +9,103 @@
|
|||
<b-icon :icon="isMetadataColumnCompressed ? 'menu-left' : 'menu-right'" />
|
||||
</button>
|
||||
<tainacan-title/>
|
||||
<div class="columns">
|
||||
<div class="tainacan-form columns">
|
||||
<div class="column is-5-5">
|
||||
<div class="column is-12">
|
||||
<router-link
|
||||
class="button is-secondary"
|
||||
:to="{ path: $routerHelper.getItemEditPath(collectionId, itemId)}">
|
||||
{{ $i18n.getFrom('items','edit_item') }}
|
||||
</router-link>
|
||||
<a
|
||||
class="button is-success is-pulled-right"
|
||||
:href="item.url">
|
||||
{{ $i18n.getFrom('items', 'view_item') }}
|
||||
</a>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<!-- Status -------------------------------- -->
|
||||
<div class="section-label">
|
||||
<label>{{ $i18n.get('label_status') }}</label>
|
||||
</div>
|
||||
<div>
|
||||
<p>{{ item.status }}</p>
|
||||
</div>
|
||||
<br>
|
||||
<!-- Document -------------------------------- -->
|
||||
<div class="section-label">
|
||||
<label>{{ item.document !== undefined && item.document !== null && item.document !== '' ?
|
||||
$i18n.get('label_document') : $i18n.get('label_document_empty') }}</label>
|
||||
</div>
|
||||
<div class="section-box">
|
||||
<div
|
||||
v-if="item.document !== undefined && item.document !== null &&
|
||||
item.document_type !== undefined && item.document_type !== null &&
|
||||
item.document !== '' && item.document_type !== 'empty'">
|
||||
|
||||
<div class="column is-12">
|
||||
<div v-if="item.document_type === 'attachment'">
|
||||
<div v-html="item.document_as_html"/>
|
||||
</div>
|
||||
|
||||
<!-- Document -------------------------------- -->
|
||||
<div class="section-label">
|
||||
<label>{{ item.document !== undefined && item.document !== null && item.document !== '' ?
|
||||
$i18n.get('label_document') : $i18n.get('label_document_empty') }}</label>
|
||||
</div>
|
||||
<div class="section-box">
|
||||
<div
|
||||
v-if="item.document !== undefined && item.document !== null &&
|
||||
item.document_type !== undefined && item.document_type !== null &&
|
||||
item.document !== '' && item.document_type !== 'empty'">
|
||||
<div v-else-if="item.document_type === 'text'">
|
||||
<div v-html="item.document_as_html"/>
|
||||
</div>
|
||||
|
||||
<div v-if="item.document_type === 'attachment'">
|
||||
<div v-html="item.document_as_html"/>
|
||||
</div>
|
||||
|
||||
<div v-else-if="item.document_type === 'text'">
|
||||
<div v-html="item.document_as_html"/>
|
||||
</div>
|
||||
|
||||
<div v-else-if="item.document_type === 'url'">
|
||||
<div v-html="item.document_as_html"/>
|
||||
</div>
|
||||
<div v-else-if="item.document_type === 'url'">
|
||||
<div v-html="item.document_as_html"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column is-12">
|
||||
|
||||
<!-- Attachments ------------------------------------------ -->
|
||||
<div class="section-label">
|
||||
<label>{{ $i18n.get('label_attachments') }}</label>
|
||||
</div>
|
||||
<div class="section-box section-attachments">
|
||||
<div class="uploaded-files">
|
||||
<file-item
|
||||
:style="{ margin: 15 + 'px'}"
|
||||
v-if="attachmentsList.length > 0"
|
||||
v-for="(attachment, index) in attachmentsList"
|
||||
:key="index"
|
||||
:show-name="true"
|
||||
:file="attachment"/>
|
||||
<p v-if="attachmentsList.length <= 0"><br>{{ $i18n.get('info_no_attachments_on_item_yet') }}</p>
|
||||
</div>
|
||||
<!-- Thumbnail -------------------------------- -->
|
||||
<div class="section-label">
|
||||
<label>{{ $i18n.get('label_thumbnail') }}</label>
|
||||
</div>
|
||||
<div class="section-box section-thumbnail">
|
||||
<div class="thumbnail-field">
|
||||
<file-item
|
||||
v-if="item.thumbnail != undefined && item.thumbnail.thumb != undefined && item.thumbnail.thumb != false"
|
||||
:show-name="false"
|
||||
:size="178"
|
||||
:file="{
|
||||
media_type: 'image',
|
||||
guid: { rendered: item.thumbnail.thumb },
|
||||
title: { rendered: $i18n.get('label_thumbnail')},
|
||||
description: { rendered: `<img alt='Thumbnail' src='` + item.thumbnail.full + `'/>` }}"/>
|
||||
<figure
|
||||
v-if="item.thumbnail == undefined || item.thumbnail.thumb == undefined || item.thumbnail.thumb == false"
|
||||
class="image">
|
||||
<span class="image-placeholder">{{ $i18n.get('label_empty_thumbnail') }}</span>
|
||||
<img
|
||||
:alt="$i18n.get('label_thumbnail')"
|
||||
:src="thumbPlaceholderPath">
|
||||
</figure>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Attachments ------------------------------------------ -->
|
||||
<div class="section-label">
|
||||
<label>{{ $i18n.get('label_attachments') }}</label>
|
||||
</div>
|
||||
<div class="section-box section-attachments">
|
||||
<div class="uploaded-files">
|
||||
<file-item
|
||||
:style="{ margin: 15 + 'px'}"
|
||||
v-if="attachmentsList.length > 0"
|
||||
v-for="(attachment, index) in attachmentsList"
|
||||
:key="index"
|
||||
:show-name="true"
|
||||
:file="attachment"/>
|
||||
<p v-if="attachmentsList.length <= 0"><br>{{ $i18n.get('info_no_attachments_on_item_yet') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div
|
||||
v-show="!isMetadataColumnCompressed"
|
||||
class="column is-4-5">
|
||||
|
||||
<!-- Visibility (status public or private) -------------------------------- -->
|
||||
<div class="section-label">
|
||||
<label>{{ $i18n.get('label_visibility') }}</label>
|
||||
<span class="required-metadatum-asterisk">*</span>
|
||||
</div>
|
||||
<div class="section-status">
|
||||
<div class="field has-addons">
|
||||
<span v-if="item.status != 'private'">
|
||||
<span class="icon">
|
||||
<i class="mdi mdi-earth"/>
|
||||
</span> {{ $i18n.get('publish_visibility') }}
|
||||
</span>
|
||||
<span v-if="item.status == 'private'">
|
||||
<span class="icon">
|
||||
<i class="mdi mdi-lock"/>
|
||||
</span> {{ $i18n.get('private_visibility') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Metadata -------------------------------- -->
|
||||
<label class="section-label">{{ $i18n.get('metadata') }}</label>
|
||||
<br>
|
||||
<a
|
||||
|
@ -99,8 +116,6 @@
|
|||
type="is-secondary"
|
||||
:icon=" open ? 'menu-down' : 'menu-right'"/>
|
||||
</a>
|
||||
|
||||
<!-- Metadata -------------------------------- -->
|
||||
<div>
|
||||
<div
|
||||
v-for="(metadatum, index) of metadatumList"
|
||||
|
@ -132,6 +147,20 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<div class="form-submission-footer">
|
||||
<router-link
|
||||
class="button is-secondary"
|
||||
:to="{ path: $routerHelper.getItemEditPath(collectionId, itemId)}">
|
||||
{{ $i18n.getFrom('items','edit_item') }}
|
||||
</router-link>
|
||||
<a
|
||||
class="button is-success is-pulled-right"
|
||||
:href="item.url">
|
||||
{{ $i18n.getFrom('items', 'view_item') }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -228,6 +257,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
.page-container-shrinked {
|
||||
height: calc(100% - 132px) !important; // Bigger than the others due footer's height
|
||||
}
|
||||
|
||||
.page-container {
|
||||
padding: 25px 0px;
|
||||
|
||||
|
@ -236,21 +269,33 @@
|
|||
padding-right: $page-side-padding;
|
||||
}
|
||||
|
||||
.column {
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
.column.is-5-5 {
|
||||
width: 45.833333333%;
|
||||
padding-left: $page-side-padding;
|
||||
padding-right: $page-side-padding;
|
||||
transition: width 0.6s;
|
||||
|
||||
@media screen and (max-width: 769px) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
.column.is-4-5 {
|
||||
width: 37.5%;
|
||||
padding-left: $page-side-padding;
|
||||
padding-right: $page-side-padding;
|
||||
transition: all 0.6s;
|
||||
|
||||
.field {
|
||||
padding: 10px 0px 10px 30px;
|
||||
|
||||
.collapse .collapse-content {
|
||||
margin-left: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 769px) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -288,8 +333,9 @@
|
|||
}
|
||||
|
||||
.section-box {
|
||||
border: 1px solid $draggable-border-color;
|
||||
padding: 30px;
|
||||
|
||||
background-color: white;
|
||||
padding: 26px;
|
||||
margin-top: 16px;
|
||||
margin-bottom: 38px;
|
||||
|
||||
|
@ -318,19 +364,24 @@
|
|||
}
|
||||
}
|
||||
.section-status{
|
||||
width: 174px;
|
||||
}
|
||||
.section-thumbnail {
|
||||
width: 174px;
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
padding-bottom: 16px;
|
||||
font-size: 0.75rem;
|
||||
|
||||
.field {
|
||||
border-bottom: none;
|
||||
|
||||
.icon {
|
||||
font-size: 18px !important;
|
||||
color: $gray;
|
||||
}
|
||||
}
|
||||
}
|
||||
.section-attachments {
|
||||
border: 1px solid $draggable-border-color;
|
||||
height: 250px;
|
||||
max-width: 100%;
|
||||
resize: vertical;
|
||||
overflow: auto;
|
||||
padding: 15px;
|
||||
|
||||
p { margin: 4px 15px }
|
||||
}
|
||||
|
@ -341,5 +392,55 @@
|
|||
margin-left: -15px;
|
||||
margin-right: -15px;
|
||||
}
|
||||
|
||||
.thumbnail-field {
|
||||
|
||||
.content {
|
||||
padding: 10px;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
img {
|
||||
height: 178px;
|
||||
width: 178px;
|
||||
}
|
||||
.image-placeholder {
|
||||
position: absolute;
|
||||
margin-left: 45px;
|
||||
margin-right: 45px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: bold;
|
||||
z-index: 99;
|
||||
text-align: center;
|
||||
color: gray;
|
||||
top: 70px;
|
||||
max-width: 90px;
|
||||
}
|
||||
}
|
||||
|
||||
.footer {
|
||||
|
||||
padding: 24px $page-side-padding;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
z-index: 999999;
|
||||
background-color: white;
|
||||
border-top: 2px solid $secondary;
|
||||
width: 100%;
|
||||
|
||||
.form-submission-footer {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: end;
|
||||
|
||||
.button {
|
||||
margin-left: 6px;
|
||||
margin-right: 6px;
|
||||
}
|
||||
.button.is-outlined {
|
||||
margin-left: 0px;
|
||||
margin-right: auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ return apply_filters( 'tainacan-admin-i18n', [
|
|||
'terms' => __( 'Terms', 'tainacan' ),
|
||||
'mapping' => __( 'Mapping', 'tainacan' ),
|
||||
'importers' => __( 'Importers', 'tainacan' ),
|
||||
'metadata' => __( 'metadata', 'tainacan' ),
|
||||
|
||||
// Actions
|
||||
'edit' => __( 'Edit', 'tainacan' ),
|
||||
|
@ -100,6 +101,9 @@ return apply_filters( 'tainacan-admin-i18n', [
|
|||
'title_collection_filters_edition' => __( 'Edit Filters of', 'tainacan' ),
|
||||
'title_importer_page' => __( 'Importer', 'tainacan' ),
|
||||
'title_importers_page' => __( 'Importers', 'tainacan' ),
|
||||
'title_export_collection_page' => __( 'Export Collection Page', 'tainacan' ),
|
||||
'title_export_item_page' => __( 'Export Item Page', 'tainacan' ),
|
||||
'title_export_page' => __( 'Export Page', 'tainacan' ),
|
||||
|
||||
// Labels (used mainly on Aria Labels and Inputs)
|
||||
'label_clean' => __( 'Clear', 'tainacan' ),
|
||||
|
@ -253,6 +257,8 @@ return apply_filters( 'tainacan-admin-i18n', [
|
|||
'label_publish' => __( 'Publish', 'tainacan' ),
|
||||
'label_send_to_trash' => __( 'Send to trash', 'tainacan' ),
|
||||
'label_update' => __( 'Update', 'tainacan' ),
|
||||
'label_mapper_metadata' => __( 'Mapper Metadata', 'tainacan' ),
|
||||
'label_add_more_mapper_metadata' => __( 'Add more mapper\'s metadata', 'tainacan' ),
|
||||
|
||||
// Instructions. More complex sentences to guide user and placeholders
|
||||
'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ),
|
||||
|
@ -277,10 +283,13 @@ return apply_filters( 'tainacan-admin-i18n', [
|
|||
'instruction_search' => __( 'Search', 'tainacan' ),
|
||||
'instruction_search_in_repository' => __( 'Search in repository', 'tainacan' ),
|
||||
'instruction_select_a_target_collection' => __( 'Select a target collection', 'tainacan' ),
|
||||
'instruction_select_a_metadatum' => __( 'Select a metadatum', 'tainacan' ),
|
||||
'instruction_select_a_mapper' => __( 'Select a mapper', 'tainacan' ),
|
||||
'instruction_select_an_importer_type' => __( 'Select an importer type from the options above:', 'tainacan' ),
|
||||
'instruction_drop_file_or_click_to_upload' => __( 'Drop your source file or click here to upload.', 'tainacan' ),
|
||||
'instruction_select_metadatum_type' => __( 'Select a metadatum type.', 'tainacan' ),
|
||||
'instruction_configure_new_metadatum' => __( 'Configure new metadatum.', 'tainacan' ),
|
||||
'instruction_insert_mapper_metadatum_info' => __( 'Insert the new mapper\'s metadatum info', 'tainacan' ),
|
||||
|
||||
// Info. Other feedback to user.
|
||||
'info_search_results' => __( 'Search Results', 'tainacan' ),
|
||||
|
|
|
@ -6,6 +6,7 @@ use \Tainacan\API\REST_Controller;
|
|||
use Tainacan\Entities;
|
||||
use Tainacan\Repositories;
|
||||
use Tainacan\Entities\Entity;
|
||||
use Tainacan\Tests\TAINACAN_REST_Collections_Controller;
|
||||
|
||||
class REST_Export_Controller extends REST_Controller {
|
||||
private $item_metadata_repository;
|
||||
|
@ -80,21 +81,7 @@ class REST_Export_Controller extends REST_Controller {
|
|||
*
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
/*$collection_id = $request['collection_id'];
|
||||
$metadatum_id = $request['metadatum_id'];
|
||||
|
||||
if($request['fetch'] === 'all_metadatum_values'){
|
||||
$results = $this->metadatum_repository->fetch_all_metadatum_values($collection_id, $metadatum_id);
|
||||
|
||||
return new \WP_REST_Response($results, 200);
|
||||
}
|
||||
|
||||
$result = $this->metadatum_repository->fetch($metadatum_id, 'OBJECT');
|
||||
|
||||
$prepared_item = $this->prepare_item_for_response($result, $request);
|
||||
return new \WP_REST_Response(apply_filters('tainacan-rest-response', $prepared_item, $request), 200);*/
|
||||
}
|
||||
public function get_item( $request ) { }
|
||||
|
||||
/**
|
||||
* @param \WP_REST_Request $request
|
||||
|
@ -212,7 +199,6 @@ class REST_Export_Controller extends REST_Controller {
|
|||
$prepared_item = $this->prepare_item_for_response($item, $request);
|
||||
|
||||
array_push($response, $prepared_item);
|
||||
file_put_contents('/tmp/2', print_r($prepared_item, true), FILE_APPEND);
|
||||
}
|
||||
wp_reset_postdata();
|
||||
}
|
||||
|
@ -225,12 +211,42 @@ class REST_Export_Controller extends REST_Controller {
|
|||
$response = [$prepared_item];
|
||||
}
|
||||
} else { // Export All
|
||||
|
||||
$collections = $query;
|
||||
$collection_controller = new REST_Collections_Controller();
|
||||
if ($collections->have_posts()) {
|
||||
while ($collections->have_posts()) {
|
||||
$collections->the_post();
|
||||
$collection_id = $collections->post->ID;
|
||||
$collection = \Tainacan\Repositories\Repository::get_entity_by_post($collections->post);
|
||||
|
||||
$prepared_collection = $collection_controller->prepare_item_for_response($collection, $request);
|
||||
|
||||
$prepared_items = [];
|
||||
|
||||
$items = $this->items_repository->fetch($args, $collection_id, 'WP_Query');
|
||||
if ($items->have_posts()) {
|
||||
while ( $items->have_posts() ) { //TODO write line by line
|
||||
$items->the_post();
|
||||
|
||||
$item = new Entities\Item($items->post);
|
||||
|
||||
$prepared_item = $this->prepare_item_for_response($item, $request);
|
||||
|
||||
array_push($prepared_items, $prepared_item);
|
||||
}
|
||||
wp_reset_postdata();
|
||||
}
|
||||
|
||||
$prepared_collection['items'] = $prepared_items;
|
||||
array_push($prepared_collection, $response);
|
||||
}
|
||||
wp_reset_postdata();
|
||||
}
|
||||
}
|
||||
|
||||
$rest_response = new \WP_REST_Response(apply_filters('tainacan-rest-response', $response, $request));
|
||||
//file_put_contents($filename, $rest_response->get_data());
|
||||
file_put_contents('/tmp/1', print_r($rest_response->get_data(), true));
|
||||
$data = $rest_response->get_data();
|
||||
file_put_contents($filename, is_string($data) ? $data : print_r($data, true));
|
||||
|
||||
if($background) {
|
||||
$log->set_status('publish');
|
||||
|
@ -291,7 +307,15 @@ class REST_Export_Controller extends REST_Controller {
|
|||
$rest_response->header('X-WP-TotalPages', 1);
|
||||
}
|
||||
} else { // Export All
|
||||
|
||||
$Tainacan_Collection = \Tainacan\Repositories\Collections::get_instance();
|
||||
$collections = $Tainacan_Collection->fetch(['post_status' => 'publish'], 'WP_Query');
|
||||
|
||||
$response = $this->export($request, $collections, $args);
|
||||
$total_items = $collections->found_posts;
|
||||
$ret = $response instanceof Entity ? $response->__toArray() : $response;
|
||||
$rest_response = new \WP_REST_Response($ret, 200);
|
||||
|
||||
$rest_response->header('X-WP-Total', (int) $total_items);
|
||||
}
|
||||
|
||||
return $rest_response;
|
||||
|
@ -309,4 +333,4 @@ class REST_Export_Controller extends REST_Controller {
|
|||
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
use Tainacan\Entities\Metadatum;
|
||||
|
||||
class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
||||
|
||||
|
@ -21,7 +22,12 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
|||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
)
|
||||
),
|
||||
array(
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -38,6 +44,20 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
|||
|
||||
return $metadatum_arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Metadatum $item
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return array|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function prepare_metadatum_for_response( $item, $request ) {
|
||||
if(!empty($item)){
|
||||
$item_arr = ['field_id' => $item->get_id(), 'exposer_mapping' => $item->get('exposer_mapping')];
|
||||
return $item_arr;
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_REST_Request $request
|
||||
|
@ -51,7 +71,7 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
|||
|
||||
$prepared = [];
|
||||
foreach ($metadatum_mappers as $metadatum_mapper){
|
||||
array_push($prepared, $this->prepare_item_for_response($metadatum_mapper, $request));
|
||||
if($metadatum_mapper->show_ui) array_push($prepared, $this->prepare_item_for_response($metadatum_mapper, $request));
|
||||
}
|
||||
|
||||
return new \WP_REST_Response($prepared, 200);
|
||||
|
@ -65,6 +85,93 @@ class REST_Metadatum_Mappers_Controller extends REST_Controller {
|
|||
public function get_items_permissions_check( $request ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if current user has permission to update a metadata mappers
|
||||
*
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return bool|\WP_Error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function update_item_permissions_check( $request ) {
|
||||
$body = json_decode( $request->get_body(), true );
|
||||
if(
|
||||
is_array($body) &&
|
||||
array_key_exists('metadata_mappers', $body) &&
|
||||
is_array($body['metadata_mappers']) &&
|
||||
count($body['metadata_mappers']) > 0 &&
|
||||
array_key_exists('exposer_map', $body)
|
||||
) {
|
||||
$metadatum_mapper = $body['metadata_mappers'][0];
|
||||
$metadatum = \Tainacan\Repositories\Repository::get_entity_by_post($metadatum_mapper['metadatum_id']);
|
||||
if($metadatum instanceof \Tainacan\Entities\Metadatum && $metadatum->can_edit()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_REST_Request $request
|
||||
*
|
||||
* @return \WP_Error|\WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
$Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance();
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
$body = json_decode( $request->get_body(), true );
|
||||
if($mapper = $Tainacan_Exposers::request_has_mapper($request)) {
|
||||
if(count($body['metadata_mappers']) > 0) {
|
||||
$response = [];
|
||||
$saved = [];
|
||||
foreach ($body['metadata_mappers'] as $metadatum_mapper) {
|
||||
$metadatum_mapper['metadatum_id'] = intval($metadatum_mapper['metadatum_id']);
|
||||
if(is_array($metadatum_mapper['mapper_metadata'])) {
|
||||
foreach ($metadatum_mapper['mapper_metadata'] as $k => $tag) {
|
||||
$metadatum_mapper['mapper_metadata'][$k] = esc_attr($tag);
|
||||
}
|
||||
} else {
|
||||
$metadatum_mapper['mapper_metadata'] = sanitize_text_field($metadatum_mapper['mapper_metadata']);
|
||||
}
|
||||
$isSaved = false;
|
||||
$metadatum = $Tainacan_Metadata->fetch($metadatum_mapper['metadatum_id']);
|
||||
$exposer_mapping = $metadatum->get('exposer_mapping');
|
||||
if($metadatum_mapper['mapper_metadata'] == '') {
|
||||
if(array_key_exists($mapper->slug, $exposer_mapping) ) {
|
||||
unset($exposer_mapping[$mapper->slug]);
|
||||
$isSaved = true;
|
||||
}
|
||||
} else {
|
||||
if( !array_key_exists($mapper->slug, $exposer_mapping) || $exposer_mapping[$mapper->slug] != $metadatum_mapper['mapper_metadata']) {
|
||||
$exposer_mapping[$mapper->slug] = $metadatum_mapper['mapper_metadata'];
|
||||
$isSaved = true;
|
||||
}
|
||||
}
|
||||
if($isSaved) {
|
||||
$metadatum->set('exposer_mapping', $exposer_mapping);
|
||||
if($metadatum->validate()) {
|
||||
$Tainacan_Metadata->update($metadatum);
|
||||
$response[] = $this->prepare_metadatum_for_response($metadatum, $request);
|
||||
} else {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('One or more values are invalid.', 'tainacan'),
|
||||
'errors' => $prepared->get_errors(),
|
||||
'metadatum' => $this->prepare_item_for_response($prepared, $request),
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new \WP_REST_Response($response, 200);
|
||||
}
|
||||
}
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Body can not be empty.', 'tainacan'),
|
||||
'item' => $request->get_body()
|
||||
], 400);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -121,11 +121,9 @@
|
|||
},
|
||||
methods: {
|
||||
emitIsChangingValue() {
|
||||
eventBus.isChangingValue(true);
|
||||
|
||||
this.changeValue();
|
||||
},
|
||||
changeValue: _.debounce(function(){
|
||||
changeValue: _.debounce(function() {
|
||||
|
||||
if(this.metadatum.value != this.inputs){
|
||||
|
||||
|
@ -178,7 +176,7 @@
|
|||
|
||||
eventBus.$emit('input', { item_id: this.metadatum.item.id, metadatum_id: this.metadatum.metadatum.id, values: this.inputs } );
|
||||
}
|
||||
}, 4000),
|
||||
}, 1000),
|
||||
getValue(){
|
||||
if (this.metadatum.value instanceof Array) {
|
||||
this.inputs = this.metadatum.value.slice(0);
|
||||
|
|
|
@ -367,7 +367,7 @@ class Metadata extends Repository {
|
|||
* metadata not ordinated appear on the end of the list
|
||||
*
|
||||
*
|
||||
* @param $result Response from method fetch
|
||||
* @param \WP_Query|array $result Response from method fetch
|
||||
* @param Entities\Collection $collection
|
||||
* @param bool $include_disabled Wether to include disabled metadata in the results or not
|
||||
* @return array or WP_Query ordinate
|
||||
|
|
|
@ -25,11 +25,13 @@ class Exposers {
|
|||
}
|
||||
|
||||
public function __construct() {
|
||||
self::$instance = $this;
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\Xml');
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\Txt');
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\Html');
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\Csv');
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\OAI_PMH');
|
||||
$this->register_exposer_type('Tainacan\Exposers\Types\JSON_LD');
|
||||
do_action('tainacan-register-exposer-types');
|
||||
$this->register_exposer_mapper('Tainacan\Exposers\Mappers\Dublin_Core');
|
||||
$this->register_exposer_mapper('Tainacan\Exposers\Mappers\Value');
|
||||
|
@ -135,12 +137,23 @@ class Exposers {
|
|||
$ret = $item_arr;
|
||||
$metadatum_mapping = $item_arr['metadatum']['exposer_mapping'];
|
||||
if(array_key_exists($mapper->slug, $metadatum_mapping)) {
|
||||
if(is_array($mapper->metadata) && !array_key_exists( $metadatum_mapping[$mapper->slug], $mapper->metadata) ) {
|
||||
if(
|
||||
is_string($metadatum_mapping[$mapper->slug]) && is_array($mapper->metadata) && !array_key_exists( $metadatum_mapping[$mapper->slug], $mapper->metadata) ||
|
||||
is_array($metadatum_mapping[$mapper->slug]) && $mapper->allow_extra_metadata != true
|
||||
) {
|
||||
throw new \Exception('Invalid Mapper Option');
|
||||
}
|
||||
$ret = [$mapper->prefix.$metadatum_mapping[$mapper->slug].$mapper->sufix => $item_arr['value']]; //TODO Validate option
|
||||
} else if($mapper->slug == 'value') {
|
||||
$slug = '';
|
||||
if(is_string($metadatum_mapping[$mapper->slug])) {
|
||||
$slug = $metadatum_mapping[$mapper->slug];
|
||||
} else {
|
||||
$slug = $metadatum_mapping[$mapper->slug]['slug'];
|
||||
}
|
||||
$ret = [$mapper->prefix.$slug.$mapper->sufix => $item_arr['value']]; //TODO Validate option
|
||||
} elseif($mapper->slug == 'value') {
|
||||
$ret = [$item_arr['metadatum']['name'] => $item_arr['value']];
|
||||
} else {
|
||||
$ret = [];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
@ -178,6 +191,22 @@ class Exposers {
|
|||
return substr($request->get_route(), 0, strlen('/tainacan/v2')) == '/tainacan/v2';
|
||||
}
|
||||
|
||||
/**
|
||||
* check if query came from url
|
||||
* @param \WP_REST_Request $request
|
||||
*/
|
||||
public static function request_has_url_param($request) {
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
$query_url_params = $request->get_query_params();
|
||||
if (
|
||||
is_array($query_url_params) && array_key_exists('exposer_type', $query_url_params) &&
|
||||
$Tainacan_Exposers->has_type($query_url_params['exposer_type'])
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* adapt request response to exposer type
|
||||
* @param \WP_REST_Response $response
|
||||
|
@ -189,7 +218,13 @@ class Exposers {
|
|||
if($this->is_tainacan_request($request) && $response instanceof \WP_REST_Response ) {
|
||||
if($request->get_method() == 'GET') {
|
||||
if($exposer = $this->request_has_type($request)) {
|
||||
return $exposer->rest_request_after_callbacks($response, $handler, $request);
|
||||
$type_responde = $exposer->rest_request_after_callbacks($response, $handler, $request);
|
||||
if(self::request_has_url_param($request)) {
|
||||
header(implode('', $response->get_headers()));
|
||||
echo $response->get_data();
|
||||
exit();
|
||||
}
|
||||
return $type_responde;
|
||||
}
|
||||
} elseif($request->get_method() == 'POST') {
|
||||
if($mapper = $this->request_has_mapper($request)) {
|
||||
|
@ -216,13 +251,20 @@ class Exposers {
|
|||
*/
|
||||
public static function request_has_type($request) {
|
||||
$body = json_decode( $request->get_body(), true );
|
||||
$query_url_params = $request->get_query_params();
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
if(
|
||||
is_array($body) && array_key_exists('exposer-type', $body) &&
|
||||
$Tainacan_Exposers->has_type($body['exposer-type'])
|
||||
is_array($body) && array_key_exists('exposer_type', $body) &&
|
||||
$Tainacan_Exposers->has_type($body['exposer_type'])
|
||||
) {
|
||||
$type = $Tainacan_Exposers->check_class_name($body['exposer-type'], true);
|
||||
$type = $Tainacan_Exposers->check_class_name($body['exposer_type'], true);
|
||||
return new $type;
|
||||
} elseif (
|
||||
is_array($query_url_params) && array_key_exists('exposer_type', $query_url_params) &&
|
||||
$Tainacan_Exposers->has_type($query_url_params['exposer_type'])
|
||||
){
|
||||
$type = $Tainacan_Exposers->check_class_name($query_url_params['exposer_type'], true);
|
||||
return new $type;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -244,19 +286,33 @@ class Exposers {
|
|||
public static function request_has_mapper($request) {
|
||||
$body = json_decode( $request->get_body(), true );
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
$query_url_params = $request->get_query_params();
|
||||
|
||||
$type = self::request_has_type($request);
|
||||
if( // There are a defined mapper
|
||||
is_array($body) && array_key_exists('exposer-map', $body) &&
|
||||
$Tainacan_Exposers->has_mapper($body['exposer-map'])
|
||||
is_array($body) && array_key_exists('exposer_map', $body) &&
|
||||
$Tainacan_Exposers->has_mapper($body['exposer_map'])
|
||||
) {
|
||||
if(
|
||||
$type === false || // do not have a exposer type
|
||||
$type->get_mappers() === true || // the type accept all mappers
|
||||
( is_array($type->get_mappers()) && in_array($body['exposer-map'], $type->get_mappers()) ) ) { // the current mapper is accepted by type
|
||||
$mapper = $Tainacan_Exposers->check_class_name($body['exposer-map'], true, self::MAPPER_CLASS_PREFIX);
|
||||
( is_array($type->get_mappers()) && in_array($body['exposer_map'], $type->get_mappers()) )
|
||||
) { // the current mapper is accepted by type
|
||||
$mapper = $Tainacan_Exposers->check_class_name($body['exposer_map'], true, self::MAPPER_CLASS_PREFIX);
|
||||
return new $mapper;
|
||||
}
|
||||
}
|
||||
} elseif(
|
||||
is_array($query_url_params) && array_key_exists('exposer_map', $query_url_params) &&
|
||||
$Tainacan_Exposers->has_mapper($query_url_params['exposer_map'])
|
||||
) {
|
||||
if(
|
||||
$type === false || // do not have a exposer type
|
||||
$type->get_mappers() === true || // the type accept all mappers
|
||||
( is_array($type->get_mappers()) && in_array($query_url_params['exposer_map'], $type->get_mappers()) )
|
||||
) { // the current mapper is accepted by type
|
||||
$mapper = $Tainacan_Exposers->check_class_name($query_url_params['exposer_map'], true, self::MAPPER_CLASS_PREFIX);
|
||||
return new $mapper;
|
||||
}
|
||||
} elseif( is_object($type) && is_array($type->get_mappers()) && count($type->get_mappers()) > 0 ) { //there are no defined mapper, let use the first one o list if has a list
|
||||
$mapper = $Tainacan_Exposers->check_class_name($type->get_mappers()[0], true, self::MAPPER_CLASS_PREFIX);
|
||||
return new $mapper;
|
||||
|
@ -298,6 +354,27 @@ class Exposers {
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of registered types
|
||||
* @param string $output output format, ARRAY_N or OBJECT
|
||||
* @return array of slug or array of \Tainacan\Exposers\Types\Type
|
||||
*/
|
||||
public function get_types($output = \ARRAY_N) {
|
||||
$ret = [];
|
||||
switch ($output) {
|
||||
case \OBJECT:
|
||||
foreach ($this->types as $type) {
|
||||
$ret[] = new $type;
|
||||
}
|
||||
break;
|
||||
case \ARRAY_N:
|
||||
default:
|
||||
return $this->types;
|
||||
break;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \WP_REST_Response $response
|
||||
|
@ -339,4 +416,35 @@ class Exposers {
|
|||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $base_url url base for exposer parameters append
|
||||
* @return string|string[][]
|
||||
*/
|
||||
public static function get_exposer_urls($base_url = '') {
|
||||
$Tainacan_Exposers = self::get_instance();
|
||||
$mappers = $Tainacan_Exposers->get_mappers();
|
||||
$types = $Tainacan_Exposers->get_types(\OBJECT);
|
||||
$urls = [];
|
||||
foreach ($types as $type) {
|
||||
$url = $base_url.(strpos($base_url, '?') === false ? '?' : '&').'exposer_type='.$type->slug;
|
||||
$urls[$type->slug] = [$url];
|
||||
if(is_array($type->get_mappers())) {
|
||||
$first = true; // first is default, jump
|
||||
foreach ($type->get_mappers() as $type_mapper) {
|
||||
if($first) {
|
||||
$first = false;
|
||||
continue;
|
||||
}
|
||||
$urls[$type->slug][] = $url.'&exposer_map='.$type_mapper;
|
||||
}
|
||||
} else {
|
||||
foreach ($mappers as $type_mapper) {
|
||||
$urls[$type->slug][] = $url.'&exposer_map='.$type_mapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $urls;
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ abstract class Mapper {
|
|||
* 'URI' => 'http://...', // URI of the metadatum description
|
||||
* 'label' => 'Label', // Label to show on UI
|
||||
* 'metadata_type' => 'date', // Tainacan recomended metadatum type, default text
|
||||
* 'core_metadatum' => 'description' // if have a core tainacan metadatum, what?
|
||||
* 'core_metadatum' => false // if have a core tainacan metadatum, what?
|
||||
* ['date' => [
|
||||
* 'URI' => 'http://purl.org/dc/elements/1.1/date',
|
||||
* 'label' => 'Date',
|
||||
|
@ -23,7 +23,7 @@ abstract class Mapper {
|
|||
* 'description' => [
|
||||
* 'URI' => 'http://purl.org/dc/elements/1.1/description',
|
||||
* 'label' => 'Description',
|
||||
* 'core_metadatum' => 'description'
|
||||
* 'core_metadatum' => true
|
||||
* ]]
|
||||
* @var array
|
||||
*/
|
||||
|
@ -32,6 +32,7 @@ abstract class Mapper {
|
|||
public $prefix = ''; // Tag prefix like "dc:"
|
||||
public $sufix = ''; // Tag sufix
|
||||
public $header = false; // API response header or file header to be used with
|
||||
public $show_ui = true; // Show mapper in ui and api calls
|
||||
|
||||
public function _toArray() {
|
||||
return [
|
||||
|
|
|
@ -13,5 +13,6 @@ class Value extends Mapper {
|
|||
public $context_url = '';
|
||||
public $header = '';
|
||||
public $metadata = false;
|
||||
public $show_ui = false;
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Exposers\Types;
|
||||
|
||||
/**
|
||||
* Generate a text formated response
|
||||
*
|
||||
*/
|
||||
class JSON_LD extends Type {
|
||||
|
||||
public $mappers = ['value', 'dublin-core'];
|
||||
public $slug = 'json-ld'; // type slug for url safe
|
||||
|
||||
protected $contexts = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
* @see \Tainacan\Exposers\Types\Type::rest_request_after_callbacks()
|
||||
*/
|
||||
public function rest_request_after_callbacks( $response, $handler, $request ) {
|
||||
$response->set_headers( [
|
||||
'Content-Type: application/json; charset=' . get_option( 'blog_charset' ),
|
||||
'Link: <'.get_bloginfo('url').'/item.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"'
|
||||
]);
|
||||
$mapper = \Tainacan\Exposers\Exposers::request_has_mapper($request);
|
||||
if(property_exists($mapper, 'XML_namespace') && !empty($mapper->XML_namespace)) {
|
||||
$namespace = $mapper->XML_namespace;
|
||||
$context_slug = str_replace(':', '', $mapper->prefix);
|
||||
$this->contexts[$context_slug] = $namespace;
|
||||
}
|
||||
$this->contexts['@language'] = $this->get_locale($response->get_data());
|
||||
$contexts = '';
|
||||
foreach ($this->contexts as $slug => $url) {
|
||||
if(strlen($contexts) > 0) $contexts .= ',';
|
||||
$contexts .= '"'.$slug.'": "'.$url.'"';
|
||||
}
|
||||
$jsonld ='';
|
||||
$jsonld =
|
||||
'{
|
||||
"@context":{
|
||||
'.$contexts.'
|
||||
},
|
||||
'.$this->array_to_jsonld($response->get_data(), apply_filters('tainacan-exposer-jsonld', $jsonld)).'
|
||||
}
|
||||
' ;
|
||||
$response->set_data($jsonld);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Array to Txt
|
||||
* @param array $data
|
||||
* @param string $jsonld
|
||||
* @return string
|
||||
*/
|
||||
protected function array_to_jsonld( $data, $jsonld ) {
|
||||
foreach( $data as $key => $value ) {
|
||||
if( is_array($value) ) {
|
||||
$jsonld .= (strlen($jsonld) > 0 ? ',' : '').'"'.$key.'": '.$this->array_to_jsonld($value, '['.$jsonld.']');
|
||||
} else {
|
||||
$jsonld .= (strlen($jsonld) > 0 ? ',' : '').'"'.$key.'": {"@value": "'.$value .'"}';
|
||||
}
|
||||
}
|
||||
return $jsonld;
|
||||
}
|
||||
|
||||
public function get_locale($obj) {
|
||||
if(array_key_exists('ID', $obj) && function_exists('wpml_get_language_information')) {
|
||||
$lang_envs = wpml_get_language_information($obj['ID']);
|
||||
return $lang_envs['locale'];
|
||||
}
|
||||
return get_locale();
|
||||
}
|
||||
}
|
|
@ -33,10 +33,7 @@ export const eventBus = new Vue({
|
|||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
isChangingValue() {
|
||||
this.$emit('isChangingValue', true);
|
||||
},
|
||||
},
|
||||
updateValue(data){
|
||||
|
||||
this.$emit('isUpdatingValue', true);
|
||||
|
|
|
@ -221,7 +221,7 @@ export const sendCollection = ( { commit }, { name, description, status, mapper
|
|||
name: name,
|
||||
description: description,
|
||||
status: status,
|
||||
'exposer-map': mapper
|
||||
exposer_map: mapper
|
||||
})
|
||||
.then( res => {
|
||||
commit('setCollection', { name: name, description: description, status: status, mapper: mapper });
|
||||
|
|
|
@ -53,10 +53,14 @@ export const cleanMetadata = ({ commit }) => {
|
|||
commit('cleanMetadata');
|
||||
};
|
||||
|
||||
export const cleanLastUpdated = ({commit}) => {
|
||||
export const cleanLastUpdated = ({ commit }) => {
|
||||
commit('cleanLastUpdated');
|
||||
};
|
||||
|
||||
export const setLastUpdated = ({ commit}, value) => {
|
||||
commit('setLastUpdated', value);
|
||||
};
|
||||
|
||||
// Actions directly related to Item
|
||||
export const fetchItem = ({ commit }, item_id) => {
|
||||
commit('cleanItem')
|
||||
|
@ -172,7 +176,6 @@ export const fetchAttachments = ({ commit }, item_id) => {
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
export const updateThumbnail = ({ commit }, { itemId, thumbnailId }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.tainacan.patch('/items/' + itemId, {
|
||||
|
|
|
@ -9,7 +9,7 @@ export const cleanItem = ( state ) => {
|
|||
}
|
||||
|
||||
export const cleanLastUpdated = ( state ) => {
|
||||
state.cleanLastUpdated = '';
|
||||
state.lastUpdated = '';
|
||||
}
|
||||
|
||||
export const setSingleAttachment = ( state, attachment ) => {
|
||||
|
@ -60,8 +60,12 @@ export const setSingleMetadatum = ( state, metadatum) => {
|
|||
}
|
||||
}
|
||||
|
||||
export const setLastUpdated = (state) => {
|
||||
let now = new Date();
|
||||
state.lastUpdated = now.toLocaleString();
|
||||
export const setLastUpdated = (state, value) => {
|
||||
if (value != undefined)
|
||||
state.lastUpdated = value;
|
||||
else {
|
||||
let now = new Date();
|
||||
state.lastUpdated = now.toLocaleString();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -168,6 +168,23 @@ export const fetchMetadatumMappers = ({commit}) => {
|
|||
});
|
||||
}
|
||||
|
||||
export const updatemetadatumMappers = ({commit}, metadatumMappers) => {
|
||||
commit('setmetadatumMappers', metadatumMappers);
|
||||
export const updateMetadataMapperMetadata = ({ dispatch }, {metadataMapperMetadata, mapper}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.tainacan.post('/metadatum-mappers', {
|
||||
metadata_mappers: metadataMapperMetadata,
|
||||
exposer_map: mapper
|
||||
}).then((res) => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const updateMetadatumMappers = ({commit}, metadatumMappers) => {
|
||||
commit('setMetadatumMappers', metadatumMappers);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -94,15 +94,107 @@ class TAINACAN_REST_Export_Controller extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
$item_metadata3 = $Tainacan_Item_Metadata->insert($item_metadata3);
|
||||
|
||||
return ['collection' => $collection, 'items' => [$item, $item2, $item3], 'metadatum' => $metadatum, 'items_metadatas' => [$item_metadata, $item_metadata2, $item_metadata3]];
|
||||
$collection2 = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
'name' => 'testeItemExport2',
|
||||
'description' => 'No description',
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$type2 = $this->tainacan_metadatum_factory->create_metadatum('text');
|
||||
|
||||
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
||||
'metadatum',
|
||||
array(
|
||||
'name' => 'teste_Export2',
|
||||
'description' => 'descricao2',
|
||||
'collection' => $collection2,
|
||||
'metadata_type' => $type2,
|
||||
'exposer_mapping' => [
|
||||
'dublin-core' => 'contributor'
|
||||
]
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$item_c2 = $this->tainacan_entity_factory->create_entity(
|
||||
'item',
|
||||
array(
|
||||
'title' => 'item_c2_teste_Export',
|
||||
'description' => 'adasdasdsa_c2',
|
||||
'collection' => $collection2
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$item_c2_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item_c2, $metadatum2);
|
||||
|
||||
$item_c2_metadata->set_value('teste_export_metadatum_value');
|
||||
|
||||
$item_c2_metadata->validate();
|
||||
|
||||
$item_c2_metadata = $Tainacan_Item_Metadata->insert($item_c2_metadata);
|
||||
|
||||
$item_c2_2 = $this->tainacan_entity_factory->create_entity(
|
||||
'item',
|
||||
array(
|
||||
'title' => 'item_c2_teste_Export2',
|
||||
'description' => 'adasdasdsa2_c2',
|
||||
'collection' => $collection2
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$item_c2_metadata2 = new \Tainacan\Entities\Item_Metadata_Entity($item_c2_2, $metadatum2);
|
||||
|
||||
$item_c2_metadata2->set_value('teste_export_metadatum_value2');
|
||||
|
||||
$item_c2_metadata2->validate();
|
||||
|
||||
$item_c2_metadata2 = $Tainacan_Item_Metadata->insert($item_c2_metadata2);
|
||||
|
||||
$item_c2_3 = $this->tainacan_entity_factory->create_entity(
|
||||
'item',
|
||||
array(
|
||||
'title' => 'item_c2_teste_Export3',
|
||||
'description' => 'adasdasdsa3_c2',
|
||||
'collection' => $collection2
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$item_c2_metadata3 = new \Tainacan\Entities\Item_Metadata_Entity($item_c2_3, $metadatum2);
|
||||
|
||||
$item_c2_metadata3->set_value('teste_export_metadatum_value3');
|
||||
|
||||
$item_c2_metadata3->validate();
|
||||
|
||||
$item_c2_metadata3 = $Tainacan_Item_Metadata->insert($item_c2_metadata3);
|
||||
|
||||
return [
|
||||
'collection' => $collection,
|
||||
'items' => [$item, $item2, $item3],
|
||||
'metadatum' => $metadatum,
|
||||
'items_metadatas' => [$item_metadata, $item_metadata2, $item_metadata3],
|
||||
'collections' => [$collection, $collection2],
|
||||
'items2' => [$item_c2, $item_c2_2, $item_c2_3],
|
||||
'items_metadatas2' => [$item_c2_metadata, $item_c2_metadata2, $item_c2_metadata3],
|
||||
];
|
||||
}
|
||||
|
||||
public function test_export_a_collection() {
|
||||
extract($this->create_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Xml',
|
||||
'exposer-map' => 'Value',
|
||||
'exposer_type' => 'Xml',
|
||||
'exposer_map' => 'Value',
|
||||
'export-background' => false
|
||||
]);
|
||||
|
||||
|
@ -132,6 +224,47 @@ class TAINACAN_REST_Export_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group export_all
|
||||
*/
|
||||
public function test_export_all() {
|
||||
extract($this->create_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer_type' => 'Xml',
|
||||
'exposer-map' => 'Value',
|
||||
'export-background' => false
|
||||
]);
|
||||
|
||||
$query = [
|
||||
'orderby' => 'id',
|
||||
'order' => 'asc',
|
||||
];
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/export' );
|
||||
$request->set_query_params($query);
|
||||
$request->set_body($item_exposer_json);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertInstanceOf('SimpleXMLElement', $xml = @simplexml_load_string($data));
|
||||
|
||||
//var_dump($data);
|
||||
/*
|
||||
$this->assertEquals(3, $xml->count());
|
||||
$i = 0;
|
||||
foreach ($xml->children() as $xml_item ) {
|
||||
$metadata = $items[$i]->get_metadata();
|
||||
foreach ($metadata as $metadatum_meta) {
|
||||
$metadatum = $metadatum_meta->get_metadatum();
|
||||
$this->assertEquals($metadatum_meta->get_value(), $xml_item->{$metadatum->get_name()});
|
||||
//echo "{$metadatum->get_name()}:{$metadatum_meta->get_value()}"; // uncomment if need debug
|
||||
}
|
||||
$i++;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -8,6 +8,10 @@ namespace Tainacan\Tests;
|
|||
class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
||||
protected $item;
|
||||
protected $collection;
|
||||
/**
|
||||
*
|
||||
* @var \Tainacan\Entities\Metadatum
|
||||
*/
|
||||
protected $metadatum;
|
||||
|
||||
protected function create_meta_requirements() {
|
||||
|
@ -79,7 +83,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-map' => 'Value',
|
||||
'exposer_map' => 'Value',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->metadatum->get_id() );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -125,7 +129,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Xml',
|
||||
'exposer_type' => 'Xml',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->metadatum->get_id() );
|
||||
|
@ -137,7 +141,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertInstanceOf('SimpleXMLElement', @simplexml_load_string($data));
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-map' => 'Dublin Core',
|
||||
'exposer_map' => 'Dublin Core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->metadatum->get_id() );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -147,8 +151,8 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers', $data['dc:language']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Xml',
|
||||
'exposer-map' => 'Dublin Core',
|
||||
'exposer_type' => 'Xml',
|
||||
'exposer_map' => 'Dublin Core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -190,7 +194,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers_slug', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-map' => 'dublin-core',
|
||||
'exposer_map' => 'dublin-core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/'. $this->metadatum->get_id() );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -200,8 +204,8 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('TestValues_exposers_slug', $data['dc:language']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'xml',
|
||||
'exposer-map' => 'dublin-core',
|
||||
'exposer_type' => 'xml',
|
||||
'exposer_map' => 'dublin-core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -227,7 +231,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
extract($this->create_meta_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'OAI-PMH',
|
||||
'exposer_type' => 'OAI-PMH',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -250,8 +254,8 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
extract($this->create_meta_requirements());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Html',
|
||||
'exposer-map' => 'Value'
|
||||
'exposer_type' => 'Html',
|
||||
'exposer_map' => 'Value'
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -310,7 +314,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-type' => 'Csv',
|
||||
'exposer_type' => 'Csv',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
|
@ -383,7 +387,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer-map' => 'Value',
|
||||
'exposer_map' => 'Value',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/items/' . $this->item->get_id() );
|
||||
|
@ -402,7 +406,7 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
*/
|
||||
public function test_mapped_new_collection() {
|
||||
$collection_JSON = json_encode([
|
||||
'exposer-map' => 'Dublin Core',
|
||||
'exposer_map' => 'Dublin Core',
|
||||
'name' => 'TesteJsonAddDublin_Core',
|
||||
'description' => 'Teste JSON Dublin Core mapped',
|
||||
'status' => 'publish'
|
||||
|
@ -433,6 +437,68 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group json_dl_exposer
|
||||
*/
|
||||
public function test_jsondl_exposer() {
|
||||
global $Tainacan_Metadata, $Tainacan_Item_Metadata;
|
||||
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$item__metadata_json = json_encode([
|
||||
'values' => 'TestValues_exposers',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $this->item->get_id() . '/metadata/' . $this->metadatum->get_id() );
|
||||
$request->set_body($item__metadata_json);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals($this->item->get_id(), $data['item']['id']);
|
||||
$this->assertEquals('TestValues_exposers', $data['value']);
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer_type' => 'json-ld',
|
||||
'exposer_map' => 'dublin-core',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $this->item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = json_decode($response->get_data());
|
||||
|
||||
$this->assertEquals('http://purl.org/dc/elements/1.1/', $data->{'@context'}->dc);
|
||||
$this->assertEquals(get_locale(), $data->{'@context'}->{'@language'});
|
||||
$this->assertEquals($this->item->get('description'), $data->{'dc:description'}->{'@value'});
|
||||
$this->assertEquals($this->item->get('title'), $data->{'dc:title'}->{'@value'});
|
||||
$this->assertEquals('TestValues_exposers', $data->{'dc:language'}->{'@value'});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group exposer_urls
|
||||
*/
|
||||
/*public function test_exposer_urls() {
|
||||
global $Tainacan_Metadata, $Tainacan_Item_Metadata;
|
||||
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$id = $item->get_id();
|
||||
$base_url = "{$this->namespace}/items/{$id}/";
|
||||
$urls = \Tainacan\Exposers\Exposers::get_exposer_urls($base_url);
|
||||
foreach ($urls as $type => $type_urls) {
|
||||
foreach ($type_urls as $url) {
|
||||
$request = new \WP_REST_Request('GET', $url);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status(), $url);
|
||||
}
|
||||
}
|
||||
}*/ // TODO automate test this
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -7,6 +7,62 @@ namespace Tainacan\Tests;
|
|||
*/
|
||||
class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCase {
|
||||
|
||||
protected function create_meta_requirements() {
|
||||
$collection = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
'name' => 'testItemMetadatumMappers',
|
||||
'description' => 'No description',
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$type = $this->tainacan_metadatum_factory->create_metadatum('text');
|
||||
|
||||
$metadatum = $this->tainacan_entity_factory->create_entity(
|
||||
'metadatum',
|
||||
array(
|
||||
'name' => 'test_MetadatumMappers',
|
||||
'description' => 'descricao',
|
||||
'collection' => $collection,
|
||||
'metadata_type' => $type,
|
||||
'exposer_mapping' => [
|
||||
'dublin-core' => 'language'
|
||||
]
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$metadatum2 = $this->tainacan_entity_factory->create_entity(
|
||||
'metadatum',
|
||||
array(
|
||||
'name' => 'test_MetadatumMappers2',
|
||||
'description' => 'descricao2',
|
||||
'collection' => $collection,
|
||||
'metadata_type' => $type
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
$item = $this->tainacan_entity_factory->create_entity(
|
||||
'item',
|
||||
array(
|
||||
'title' => 'item_teste_MetadatumMappers',
|
||||
'description' => 'adasdasdsaadsf',
|
||||
'collection' => $collection
|
||||
),
|
||||
true,
|
||||
true
|
||||
);
|
||||
$this->collection = $collection;
|
||||
$this->item = $item;
|
||||
$this->metadatum = $metadatum;
|
||||
return ['collection' => $collection, 'item' => $item, 'metadatum' => $metadatum, 'metadatum2' => $metadatum2];
|
||||
}
|
||||
|
||||
public function test_get_metadatum_mappers(){
|
||||
|
||||
$metadatum_mapper_request = new \WP_REST_Request('GET', $this->namespace . '/metadatum-mappers');
|
||||
|
@ -18,6 +74,10 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
$Tainacan_Metadata = \Tainacan\Exposers\Exposers::get_instance();
|
||||
|
||||
$metadatum_mappers = $Tainacan_Metadata->get_mappers("OBJECT");
|
||||
/** @var \Tainacan\Exposers\Mappers\Mapper $metadatum_mapper **/
|
||||
foreach ($metadatum_mappers as $k => $metadatum_mapper) {
|
||||
if(!$metadatum_mapper->show_ui) unset($metadatum_mappers[$k]);
|
||||
}
|
||||
|
||||
$this->assertEquals(count($metadatum_mappers), count($data));
|
||||
|
||||
|
@ -32,6 +92,99 @@ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCas
|
|||
$this->assertEquals($metadatum_mappers[$i]->header, $data[$i]['header']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_update_metadatum_mappers(){
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$dc = new \Tainacan\Exposers\Mappers\Dublin_Core();
|
||||
|
||||
$metadatum_mapper_request = new \WP_REST_Request('POST', $this->namespace . '/metadatum-mappers');
|
||||
$metadatum_mapper_json = json_encode([
|
||||
'metadata_mappers' => [
|
||||
['metadatum_id' => $metadatum->get_id(), 'mapper_metadata' => 'contributor'],
|
||||
['metadatum_id' => $metadatum2->get_id(), 'mapper_metadata' => 'coverage']
|
||||
],
|
||||
'exposer_map' => $dc->slug
|
||||
]);
|
||||
$metadatum_mapper_request->set_body($metadatum_mapper_json);
|
||||
$metadatum_mapper_response = $this->server->dispatch($metadatum_mapper_request);
|
||||
$this->assertEquals(200, $metadatum_mapper_response->get_status());
|
||||
$data = $metadatum_mapper_response->get_data();
|
||||
|
||||
$this->assertEquals('contributor', $data[0]['exposer_mapping']['dublin-core']);
|
||||
$this->assertEquals('coverage', $data[1]['exposer_mapping']['dublin-core']);
|
||||
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
|
||||
$db_metadatum = $Tainacan_Metadata->fetch($metadatum->get_id());
|
||||
$exposer_mapping = $db_metadatum->get('exposer_mapping');
|
||||
$this->assertEquals('contributor', $exposer_mapping['dublin-core']);
|
||||
|
||||
$db_metadatum = $Tainacan_Metadata->fetch($metadatum2->get_id());
|
||||
$exposer_mapping = $db_metadatum->get('exposer_mapping');
|
||||
$this->assertEquals('coverage', $exposer_mapping['dublin-core']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group new_mapper_metadatum
|
||||
*/
|
||||
public function test_update_metadatum_mappers_new_meta(){
|
||||
extract($this->create_meta_requirements());
|
||||
|
||||
$dc = new \Tainacan\Exposers\Mappers\Dublin_Core();
|
||||
|
||||
$metadatum_mapper_request = new \WP_REST_Request('POST', $this->namespace . '/metadatum-mappers');
|
||||
$new_metadatum_mapper = new \stdClass();
|
||||
$new_metadatum_mapper->slug = 'TesteNewMeta';
|
||||
$new_metadatum_mapper->uri = 'TesteNewMetaUri.com';
|
||||
$new_metadatum_mapper->type = 'text';
|
||||
$metadatum_mapper_json = json_encode([
|
||||
'metadata_mappers' => [
|
||||
['metadatum_id' => $metadatum->get_id(), 'mapper_metadata' => 'contributor'],
|
||||
['metadatum_id' => $metadatum2->get_id(), 'mapper_metadata' => $new_metadatum_mapper ]
|
||||
],
|
||||
'exposer_map' => $dc->slug
|
||||
]);
|
||||
$metadatum_mapper_request->set_body($metadatum_mapper_json);
|
||||
$metadatum_mapper_response = $this->server->dispatch($metadatum_mapper_request);
|
||||
$this->assertEquals(200, $metadatum_mapper_response->get_status());
|
||||
$data = $metadatum_mapper_response->get_data();
|
||||
|
||||
$this->assertEquals('contributor', $data[0]['exposer_mapping']['dublin-core']);
|
||||
$this->assertEquals('TesteNewMeta', $data[1]['exposer_mapping']['dublin-core']['slug']);
|
||||
$this->assertEquals('TesteNewMetaUri.com', $data[1]['exposer_mapping']['dublin-core']['uri']);
|
||||
$this->assertEquals('text', $data[1]['exposer_mapping']['dublin-core']['type']);
|
||||
|
||||
$item__metadata_json = json_encode([
|
||||
'values' => 'TestValues_exposersCustomMeta',
|
||||
]);
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/item/' . $item->get_id() . '/metadata/' . $metadatum2->get_id() );
|
||||
$request->set_body($item__metadata_json);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$item_exposer_json = json_encode([
|
||||
'exposer_type' => 'OAI-PMH',
|
||||
]);
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/item/' . $item->get_id() . '/metadata' );
|
||||
$request->set_body($item_exposer_json);
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$data = $response->get_data();
|
||||
|
||||
$xml = new \SimpleXMLElement($data);
|
||||
$dc = $xml->children(\Tainacan\Exposers\Mappers\Dublin_Core::XML_DC_NAMESPACE);
|
||||
$this->assertEquals('adasdasdsaadsf', $dc->description);
|
||||
$this->assertEquals('item_teste_MetadatumMappers', $dc->title);
|
||||
$this->assertEquals('', $dc->contributor);
|
||||
$this->assertEquals('TestValues_exposersCustomMeta', $dc->TesteNewMeta);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -60,7 +60,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
$this->assertTrue($old_tainacan instanceof \Tainacan\Importer\Old_Tainacan);
|
||||
}
|
||||
|
||||
/*public function test_file_old_tainacan () {
|
||||
|
|
Loading…
Reference in New Issue