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

This commit is contained in:
Jacson Passold 2018-04-18 14:13:23 -03:00
commit 4a8b8a51f6
43 changed files with 11337 additions and 418 deletions

3
.gitignore vendored
View File

@ -21,4 +21,5 @@ src/assets/css/tainacan-admin.css
src/assets/css/tainacan-admin.css.map src/assets/css/tainacan-admin.css.map
cypress/videos cypress/videos
cypress/screenshots cypress/screenshots
.vscode .vscode
src/pdf-viewer/pdfjs-dist

View File

@ -51,6 +51,15 @@ then
fi fi
### END npm build ### ### END npm build ###
## Fetch PDF.js
if [ ! -d "src/pdf-viewer/pdfjs-dist" ]; then
echo "Fething PDF.js"
mkdir -p src/pdf-viewer/pdfjs-dist
wget https://github.com/mozilla/pdf.js/releases/download/v1.9.426/pdfjs-1.9.426-dist.zip
unzip pdfjs-1.9.426-dist.zip -d src/pdf-viewer/pdfjs-dist/
rm pdfjs-1.9.426-dist.zip
fi
echo "Updating files in $wp_plugin_dir" echo "Updating files in $wp_plugin_dir"
rm -rf $wp_plugin_dir rm -rf $wp_plugin_dir

View File

@ -27,7 +27,7 @@ Logs are stored as posts. Check WP_Query docs to learn all args accepted in the
**Returns:** `\WP_Query|Array` — an instance of wp query OR array of entities; **Returns:** `\WP_Query|Array` — an instance of wp query OR array of entities;
### `public function log_inserts($new_value, $value = null)` ### `public function insert_log($new_value, $value = null)`
Insert a log when a new entity is inserted Insert a log when a new entity is inserted
**Parameters:** **Parameters:**

View File

@ -178,7 +178,7 @@ export default {
}, },
deleteSelectedCollections() { deleteSelectedCollections() {
this.$dialog.confirm({ this.$dialog.confirm({
message: this.$i18n.get('info_selected_collections_delete'), message: this.$i18n.get('info_warning_selected_collections_delete'),
onConfirm: () => { onConfirm: () => {
for (let collection of this.selectedCollections) { for (let collection of this.selectedCollections) {

View File

@ -29,7 +29,7 @@
class="clickable-row" class="clickable-row"
tag="span" tag="span"
router-link-active router-link-active
:active="props.row.log_diff.length > 0" :active="props.row.log_diffs.length > 0"
:to="{path: $routerHelper.getEventPath(props.row.id)}"> :to="{path: $routerHelper.getEventPath(props.row.id)}">
{{ props.row.title }} {{ props.row.title }}
</router-link> </router-link>
@ -47,7 +47,7 @@
class="clickable-row" class="clickable-row"
v-html="props.row.by" v-html="props.row.by"
tag="span" tag="span"
:active="props.row.log_diff.length > 0" :active="props.row.log_diffs.length > 0"
:to="{path: $routerHelper.getEventPath(props.row.id)}"/> :to="{path: $routerHelper.getEventPath(props.row.id)}"/>
</b-table-column> </b-table-column>
@ -58,18 +58,22 @@
:aria-label="$i18n.get('label_actions')"> :aria-label="$i18n.get('label_actions')">
<a <a
v-if="props.row.status === 'pending'"
id="button-approve" id="button-approve"
:aria-label="$i18n.get('approve_item')" :aria-label="$i18n.get('approve_item')"
@click.prevent.stop="approve(props.row.id)"> @click.prevent.stop="approveEvent(props.row.id)">
<b-icon <b-icon
icon="check" /> icon="check" />
</a> </a>
<a <a
v-if="props.row.status === 'pending'"
id="button-not-approve" id="button-not-approve"
class="delete" class="delete"
:aria-label="$i18n.get('not_approve_item')" :aria-label="$i18n.get('not_approve_item')"
@click.prevent.stop="notApprove(props.row.id)" /> @click.prevent.stop="notApproveEvent(props.row.id)" />
<small v-if="props.row.status !== 'pending'"> Approved </small>
</b-table-column> </b-table-column>
</template> </template>
@ -113,7 +117,13 @@
...mapActions('event', [ ...mapActions('event', [
'approve', 'approve',
'notApprove' 'notApprove'
]) ]),
approveEvent(eventId){
this.approve(eventId);
},
notApproveEvent(eventId){
this.notApprove(eventId);
}
} }
} }
</script> </script>

View File

@ -154,7 +154,6 @@ export default {
return this.getFieldTypes(); return this.getFieldTypes();
}, },
set(value) { set(value) {
console.log("OIEEE")
return this.updateFieldTypes(value); return this.updateFieldTypes(value);
} }
}, },

View File

@ -106,7 +106,6 @@ export default {
message: this.$i18n.get('info_warning_item_delete'), message: this.$i18n.get('info_warning_item_delete'),
onConfirm: () => { onConfirm: () => {
this.deleteItem(itemId).then(() => { this.deleteItem(itemId).then(() => {
this.loadItems();
this.$toast.open({ this.$toast.open({
duration: 3000, duration: 3000,
message: this.$i18n.get('info_item_deleted'), message: this.$i18n.get('info_item_deleted'),
@ -139,7 +138,6 @@ export default {
for (let item of this.selectedItems) { for (let item of this.selectedItems) {
this.deleteItem(item.id) this.deleteItem(item.id)
.then(() => { .then(() => {
this.loadItems();
this.$toast.open({ this.$toast.open({
duration: 3000, duration: 3000,
message: this.$i18n.get('info_item_deleted'), message: this.$i18n.get('info_item_deleted'),

View File

@ -7,7 +7,7 @@
<div class="content"> <div class="content">
<div class="title">{{ this.$i18n.get('info_logs_before') }}</div> <div class="title">{{ this.$i18n.get('info_logs_before') }}</div>
<div <div
v-for="(diff, key) in event.log_diff" v-for="(diff, key) in event.log_diffs"
v-if="diff.old" v-if="diff.old"
:key="key"> :key="key">
@ -39,7 +39,7 @@
<div class="content"> <div class="content">
<div class="title">{{ this.$i18n.get('info_logs_after') }}</div> <div class="title">{{ this.$i18n.get('info_logs_after') }}</div>
<div <div
v-for="(diff, key) in event.log_diff" v-for="(diff, key) in event.log_diffs"
:key="key"> :key="key">
<p/> <p/>
@ -55,7 +55,7 @@
class="content is-inline" > class="content is-inline" >
<div <div
class="is-inline has-text-success" class="is-inline"
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }" :class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }"
v-if="!Array.isArray(d) && d.constructor.name !== 'Object' ">{{ d }} v-if="!Array.isArray(d) && d.constructor.name !== 'Object' ">{{ d }}
</div> </div>
@ -67,7 +67,7 @@
class="is-inline"> class="is-inline">
<div <div
class="is-capitalized is-inline has-text-success" class="is-capitalized"
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }"> :class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
{{ `${i2.replace('_', ' ')}: ${e} ` }} {{ `${i2.replace('_', ' ')}: ${e} ` }}
</div> </div>

View File

@ -8,7 +8,7 @@
<div class="content"> <div class="content">
<div class="title">Changes</div> <div class="title">Changes</div>
<div <div
v-for="(diff, key) in event.log_diff" v-for="(diff, key) in event.log_diffs"
v-if="diff.old" v-if="diff.old"
:key="key"> :key="key">
@ -19,6 +19,7 @@
class="content is-inline"> class="content is-inline">
{{ diff.old }} {{ diff.old }}
</div> </div>
<div <div
v-else v-else
v-for="(o, ind) in diff.old" v-for="(o, ind) in diff.old"
@ -32,8 +33,10 @@
</div> </div>
</div> </div>
<hr class="divider">
<div <div
v-for="(diff, key) in event.log_diff" v-for="(diff, key) in event.log_diffs"
:key="key"> :key="key">
<p/> <p/>
@ -49,7 +52,7 @@
class="content is-inline" > class="content is-inline" >
<div <div
class="is-inline has-text-success" class="is-inline"
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }" :class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }"
v-if="!Array.isArray(d) && d.constructor.name !== 'Object' ">{{ d }} v-if="!Array.isArray(d) && d.constructor.name !== 'Object' ">{{ d }}
</div> </div>
@ -58,7 +61,7 @@
v-else v-else
v-for="(e, i2) in d" v-for="(e, i2) in d"
:key="i2" :key="i2"
class="is-capitalized has-text-success" class="is-capitalized"
:class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }"> :class="{ 'back-hlight': diff.diff_with_index.hasOwnProperty(i) }">
{{ `${i2.replace('_', ' ')}: ${e} ` }} {{ `${i2.replace('_', ' ')}: ${e} ` }}
</div> </div>

View File

@ -37,7 +37,6 @@
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { eventBusSearch } from '../../../js/event-bus-search';
export default { export default {
name: 'Pagination', name: 'Pagination',
@ -59,7 +58,7 @@ export default {
watch: { watch: {
page( value ){ page( value ){
if (value < 1) if (value < 1)
eventBusSearch.setPage(1); this.$eventBusSearch.setPage(1);
} }
}, },
methods: { methods: {
@ -75,13 +74,13 @@ export default {
} }
let prevValue = this.itemsPerPage; let prevValue = this.itemsPerPage;
eventBusSearch.setItemsPerPage(value); this.$eventBusSearch.setItemsPerPage(value);
this.$userPrefs.set('items_per_page', value, prevValue); this.$userPrefs.set('items_per_page', value, prevValue);
}, },
onPageChange(page) { onPageChange(page) {
if(page == 0) if(page == 0)
return; return;
eventBusSearch.setPage(page); this.$eventBusSearch.setPage(page);
}, },
getLastItemNumber() { getLastItemNumber() {
let last = (Number(this.itemsPerPage*(this.page - 1)) + Number(this.itemsPerPage)); let last = (Number(this.itemsPerPage*(this.page - 1)) + Number(this.itemsPerPage));

View File

@ -52,7 +52,6 @@
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { eventBusSearch } from '../../../js/event-bus-search';
export default { export default {
name: 'SearchControl', name: 'SearchControl',
@ -80,10 +79,10 @@ export default {
'getOrder' 'getOrder'
]), ]),
onChangeOrderBy(field) { onChangeOrderBy(field) {
eventBusSearch.setOrderBy(field); this.$eventBusSearch.setOrderBy(field);
}, },
onChangeOrder() { onChangeOrder() {
this.order == 'DESC' ? eventBusSearch.setOrder('ASC') : eventBusSearch.setOrder('DESC'); this.order == 'DESC' ? this.$eventBusSearch.setOrder('ASC') : this.$eventBusSearch.setOrder('DESC');
} }
} }
} }

View File

@ -27,14 +27,14 @@ import FilterCategorySelectbox from '../../classes/filter-types/category/Selectb
import TaincanFormItem from '../../classes/field-types/tainacan-form-item.vue'; import TaincanFormItem from '../../classes/field-types/tainacan-form-item.vue';
import TaincanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue'; import TaincanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue';
import ItemsPage from '../pages/lists/items-page.vue';
// Remaining imports // Remaining imports
import AdminPage from '../admin.vue' import AdminPage from '../admin.vue'
import HelpButton from '../components/other/help-button.vue'; import HelpButton from '../components/other/help-button.vue';
import draggable from 'vuedraggable' import draggable from 'vuedraggable'
import store from '../../js/store/store' import store from '../../js/store/store'
import router from './router' import { router} from './router'
import eventBusSearch from '../../js/event-bus-search';
import { I18NPlugin, UserPrefsPlugin, RouterHelperPlugin, ConsolePlugin } from './utilities'; import { I18NPlugin, UserPrefsPlugin, RouterHelperPlugin, ConsolePlugin } from './utilities';
// Changing title of pages // Changing title of pages
@ -50,8 +50,6 @@ Vue.use(UserPrefsPlugin);
Vue.use(RouterHelperPlugin); Vue.use(RouterHelperPlugin);
Vue.use(ConsolePlugin, {visual: false}); Vue.use(ConsolePlugin, {visual: false});
// Register Components
Vue.component('items-page',ItemsPage);
/* Fields */ /* Fields */
Vue.component('tainacan-text', Text); Vue.component('tainacan-text', Text);
Vue.component('tainacan-textarea', Textarea); Vue.component('tainacan-textarea', Textarea);
@ -81,9 +79,11 @@ Vue.component('tainacan-filter-category-selectbox', FilterCategorySelectbox);
Vue.component('help-button', HelpButton); Vue.component('help-button', HelpButton);
Vue.component('draggable', draggable); Vue.component('draggable', draggable);
Vue.use(eventBusSearch, { store: store, router: router});
new Vue({ new Vue({
el: '#tainacan-admin-app', el: '#tainacan-admin-app',
store, store,
router, router,
render: h => h(AdminPage) render: h => h(AdminPage)
}); });

View File

@ -67,7 +67,7 @@ const routes = [
{ path: '*', redirect: '/'} { path: '*', redirect: '/'}
]; ];
export default new VueRouter ({ export const router = new VueRouter ({
routes, routes,
// set custom query resolver // set custom query resolver
parseQuery(query) { parseQuery(query) {
@ -76,6 +76,21 @@ export default new VueRouter ({
stringifyQuery(query) { stringifyQuery(query) {
let result = qs.stringify(query); let result = qs.stringify(query);
return result ? ('?' + result) : '';
}
});
const themeRoutes = [];
export const routerTheme = new VueRouter ({
themeRoutes,
// set custom query resolver
parseQuery(query) {
return qs.parse(query);
},
stringifyQuery(query) {
let result = qs.stringify(query);
return result ? ('?' + result) : ''; return result ? ('?' + result) : '';
} }
}); });

View File

@ -0,0 +1,91 @@
// Main imports
import Vue from 'vue';
import Buefy from 'buefy';
// Custom elements
import Text from '../../classes/field-types/text/Text.vue';
import Textarea from '../../classes/field-types/textarea/Textarea.vue';
import Selectbox from '../../classes/field-types/selectbox/Selectbox.vue';
import Numeric from '../../classes/field-types/numeric/Numeric.vue';
import Date from '../../classes/field-types/date/Date.vue';
import Relationship from '../../classes/field-types/relationship/Relationship.vue';
import Category from '../../classes/field-types/category/Category.vue';
import FormRelationship from '../../classes/field-types/relationship/FormRelationship.vue';
import FormCategory from '../../classes/field-types/category/FormCategory.vue';
import FormSelectbox from '../../classes/field-types/selectbox/FormSelectbox.vue';
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue';
import FilterAutocomplete from '../../classes/filter-types/autocomplete/Autocomplete.vue';
import FilterCheckbox from '../../classes/filter-types/checkbox/Checkbox.vue';
import FilterTaginput from '../../classes/filter-types/taginput/Taginput.vue';
import FilterCategoryCheckbox from '../../classes/filter-types/category/Checkbox.vue';
import FilterCategoryTaginput from '../../classes/filter-types/category/Taginput.vue';
import FilterCategorySelectbox from '../../classes/filter-types/category/Selectbox.vue';
import TaincanFormItem from '../../classes/field-types/tainacan-form-item.vue';
import TaincanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue';
import ItemsPage from '../pages/lists/items-page.vue';
// Remaining imports
import HelpButton from '../components/other/help-button.vue';
import draggable from 'vuedraggable'
import store from '../../js/store/store'
import { routerTheme } from './router.js'
import eventBusSearch from '../../js/event-bus-search';
import { I18NPlugin, UserPrefsPlugin, RouterHelperPlugin, ConsolePlugin } from './utilities';
// Configure and Register Plugins
Vue.use(Buefy);
Vue.use(I18NPlugin);
Vue.use(UserPrefsPlugin);
Vue.use(RouterHelperPlugin);
Vue.use(ConsolePlugin, {visual: false});
/* Fields */
Vue.component('tainacan-text', Text);
Vue.component('tainacan-textarea', Textarea);
Vue.component('tainacan-selectbox', Selectbox);
Vue.component('tainacan-numeric', Numeric);
Vue.component('tainacan-date', Date);
Vue.component('tainacan-relationship', Relationship);
Vue.component('tainacan-category', Category);
Vue.component('tainacan-form-relationship', FormRelationship);
Vue.component('tainacan-form-category', FormCategory);
Vue.component('tainacan-form-selectbox', FormSelectbox);
Vue.component('tainacan-form-item', TaincanFormItem);
Vue.component('tainacan-filter-item', TaincanFiltersList);
/* Filters */
Vue.component('tainacan-filter-custom-interval', FilterCustomInterval);
Vue.component('tainacan-filter-selectbox', FilterSelectbox);
Vue.component('tainacan-filter-autocomplete', FilterAutocomplete);
Vue.component('tainacan-filter-checkbox', FilterCheckbox);
Vue.component('tainacan-filter-taginput', FilterTaginput);
Vue.component('tainacan-filter-category-checkbox', FilterCategoryCheckbox);
Vue.component('tainacan-filter-category-taginput', FilterCategoryTaginput);
Vue.component('tainacan-filter-category-selectbox', FilterCategorySelectbox);
/* Others */
Vue.component('help-button', HelpButton);
Vue.component('draggable', draggable);
Vue.component('items-page', ItemsPage);
Vue.use(eventBusSearch, { store: store, router: routerTheme});
new Vue({
el: '#tainacan-items-page',
store,
router: routerTheme,
data: {
collectionId: ''
},
template: '<items-page :collection-id="collectionId"></items-page>',
beforeMount () {
if (this.$el.attributes['collection-id'] != undefined)
this.collectionId = this.$el.attributes['collection-id'].value;
}
});

View File

@ -11,14 +11,14 @@
id="button-create-item" id="button-create-item"
tag="button" tag="button"
class="button is-secondary" class="button is-secondary"
:to="{ path: $routerHelper.getNewItemPath(finalCollectionId) }"> :to="{ path: $routerHelper.getNewItemPath(collectionId) }">
{{ $i18n.getFrom('items', 'new_item') }} {{ $i18n.getFrom('items', 'new_item') }}
</router-link> </router-link>
</div> </div>
<search-control <search-control
v-if="fields.length > 0 && (items.length != 0 || isLoadingItems)" v-if="fields.length > 0 && (items.length != 0 || isLoadingItems)"
:is-repository-level="isRepositoryLevel" :is-repository-level="isRepositoryLevel"
:collection-id="finalCollectionId" :collection-id="collectionId"
:table-fields="tableFields" :table-fields="tableFields"
:pref-table-fields="prefTableFields"/> :pref-table-fields="prefTableFields"/>
</div> </div>
@ -43,7 +43,7 @@
<p>{{ $i18n.get('info_there_is_no_filter' ) }}</p> <p>{{ $i18n.get('info_there_is_no_filter' ) }}</p>
<router-link <router-link
id="button-create-filter" id="button-create-filter"
:to="isRepositoryLevel ? $routerHelper.getNewFilterPath() : $routerHelper.getNewCollectionFilterPath(finalCollectionId)" :to="isRepositoryLevel ? $routerHelper.getNewFilterPath() : $routerHelper.getNewCollectionFilterPath(collectionId)"
tag="button" tag="button"
class="button is-secondary is-centered"> class="button is-secondary is-centered">
{{ $i18n.getFrom('filters', 'new_item') }}</router-link> {{ $i18n.getFrom('filters', 'new_item') }}</router-link>
@ -57,7 +57,7 @@
:active.sync="isLoadingItems"/> :active.sync="isLoadingItems"/>
<items-list <items-list
v-if="!isLoadingItems && items.length > 0" v-if="!isLoadingItems && items.length > 0"
:collection-id="finalCollectionId" :collection-id="collectionId"
:table-fields="tableFields" :table-fields="tableFields"
:items="items" :items="items"
:is-loading="isLoading"/> :is-loading="isLoading"/>
@ -76,7 +76,7 @@
id="button-create-item" id="button-create-item"
tag="button" tag="button"
class="button is-primary" class="button is-primary"
:to="{ path: $routerHelper.getNewItemPath(finalCollectionId) }"> :to="{ path: $routerHelper.getNewItemPath(collectionId) }">
{{ $i18n.getFrom('items', 'new_item') }} {{ $i18n.getFrom('items', 'new_item') }}
</router-link> </router-link>
</div> </div>
@ -94,14 +94,12 @@ import SearchControl from '../../components/search/search-control.vue'
import ItemsList from '../../components/lists/items-list.vue'; import ItemsList from '../../components/lists/items-list.vue';
import FiltersItemsList from '../../components/search/filters-items-list.vue'; import FiltersItemsList from '../../components/search/filters-items-list.vue';
import Pagination from '../../components/search/pagination.vue' import Pagination from '../../components/search/pagination.vue'
import { eventBusSearch } from '../../../js/event-bus-search'
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
export default { export default {
name: 'ItemsPage', name: 'ItemsPage',
data(){ data(){
return { return {
finalCollectionId: Number,
isRepositoryLevel: false, isRepositoryLevel: false,
tableFields: [], tableFields: [],
prefTableFields: [], prefTableFields: [],
@ -149,24 +147,24 @@ export default {
} }
}, },
created() { created() {
this.finalCollectionId = (this.collectionId != undefined && this.collectionId != null && this.collectionId != '' ) ? this.collectionId : this.$route.params.collectionId;
this.isRepositoryLevel = (this.finalCollectionId == undefined);
eventBusSearch.$on('isLoadingItems', isLoadingItems => { this.isRepositoryLevel = (this.collectionId == undefined);
this.$eventBusSearch.$on('isLoadingItems', isLoadingItems => {
this.isLoadingItems = isLoadingItems; this.isLoadingItems = isLoadingItems;
}); });
eventBusSearch.$on('hasFiltered', hasFiltered => { this.$eventBusSearch.$on('hasFiltered', hasFiltered => {
this.hasFiltered = hasFiltered; this.hasFiltered = hasFiltered;
}); });
this.isLoadingFilters = true; this.isLoadingFilters = true;
this.fetchFilters( { collectionId: this.finalCollectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true }) this.fetchFilters( { collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true })
.then(() => this.isLoadingFilters = false) .then(() => this.isLoadingFilters = false)
.catch(() => this.isLoadingFilters = false); .catch(() => this.isLoadingFilters = false);
this.isLoadingFields = true; this.isLoadingFields = true;
this.fetchFields({ collectionId: this.finalCollectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }).then(() => { this.fetchFields({ collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }).then(() => {
this.tableFields.push({ name: this.$i18n.get('label_thumbnail'), field: 'row_thumbnail', field_type: undefined, slug: 'featured_image', id: undefined, visible: true }); this.tableFields.push({ name: this.$i18n.get('label_thumbnail'), field: 'row_thumbnail', field_type: undefined, slug: 'featured_image', id: undefined, visible: true });
for (let field of this.fields) { for (let field of this.fields) {
@ -179,12 +177,12 @@ export default {
this.tableFields.push({ name: this.$i18n.get('label_actions'), field: 'row_actions', field_type: undefined, slug: 'actions', id: undefined, visible: true }); this.tableFields.push({ name: this.$i18n.get('label_actions'), field: 'row_actions', field_type: undefined, slug: 'actions', id: undefined, visible: true });
//this.prefTableFields = this.tableFields; //this.prefTableFields = this.tableFields;
// this.$userPrefs.get('table_columns_' + this.finalCollectionId) // this.$userPrefs.get('table_columns_' + this.collectionId)
// .then((value) => { // .then((value) => {
// this.prefTableFields = value; // this.prefTableFields = value;
// }) // })
// .catch((error) => { // .catch((error) => {
// this.$userPrefs.set('table_columns_' + this.finalCollectionId, this.prefTableFields, null); // this.$userPrefs.set('table_columns_' + this.collectionId, this.prefTableFields, null);
// }); // });
this.isLoadingFields = false; this.isLoadingFields = false;
@ -193,8 +191,9 @@ export default {
}); });
}, },
mounted(){ mounted(){
eventBusSearch.updateStoreFromURL(); this.$eventBusSearch.setCollectionId(this.collectionId);
eventBusSearch.loadItems(); this.$eventBusSearch.updateStoreFromURL();
this.$eventBusSearch.loadItems();
} }
} }

View File

@ -2,7 +2,9 @@
<div class="columns is-fullheight"> <div class="columns is-fullheight">
<section class="column is-secondary-content"> <section class="column is-secondary-content">
<tainacan-subheader :id="collectionId"/> <tainacan-subheader :id="collectionId"/>
<router-view class="page-container"/> <router-view
:collection-id="collectionId"
class="page-container"/>
</section> </section>
</div> </div>
</template> </template>

View File

@ -2,22 +2,27 @@
<div> <div>
<div class="is-fullheight"> <div class="is-fullheight">
<div class="page-container primary-page"> <div class="page-container primary-page">
<div class="title">{{ event.description }}</div>
<div class=""> <div class="level">
<div class="field"> <div class="level-left"/>
<b-switch <div class="level-right">
v-model="comp" <div class="level-item">
true-value="Unified" <b-switch
false-value="Split" v-model="comp"
class="is-pulled-right"> true-value="Unified"
{{ comp }} false-value="Split"
</b-switch> class="is-pulled-right">
{{ comp }}
</b-switch>
</div>
</div> </div>
</div> </div>
<hr class="divider">
<component <component
:is="comp" :is="comp"
:event="event" /> :event="event"/>
</div> </div>
</div> </div>
</div> </div>
@ -51,8 +56,8 @@
} }
}, },
components: { components: {
Split, Split,
Unified Unified
}, },
created() { created() {
this.eventId = parseInt(this.$route.params.eventId); this.eventId = parseInt(this.$route.params.eventId);
@ -65,6 +70,6 @@
<style> <style>
.back-hlight { .back-hlight {
background-color: rgb(231, 255, 237); background-color: rgb(186, 255, 220);
} }
</style> </style>

View File

@ -68,11 +68,11 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
if(!isset($request['fetch_only'])) { if(!isset($request['fetch_only'])) {
$item_array = $item->__toArray(); $item_array = $item->__toArray();
if ( $request['context'] === 'edit' ) { // if ( $request['context'] === 'edit' ) {
$log_diff = $item->diff(); // $log_diff = $item->diff();
//
$item_array['log_diff'] = $log_diff; // $item_array['log_diff'] = $log_diff;
} // }
unset($item_array['value']); unset($item_array['value']);
unset($item_array['old_value']); unset($item_array['old_value']);

View File

@ -0,0 +1,81 @@
<?php
namespace Tainacan;
class Embed {
private static $instance = null;
public static function get_instance() {
if(!isset(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
protected function __construct() {
/**
* Replace default WordPress embedders with HTML 5 tags instead of shortcodes
*/
add_filter('wp_embed_handler_video', [&$this, 'filter_video_embed'], 10, 4);
add_filter('wp_embed_handler_audio', [&$this, 'filter_audio_embed'], 10, 4);
/**
* ADD PDF Embed handler using PDF.js
* @var [type]
*/
wp_embed_register_handler( 'pdf', '#^https?://.+?\.(pdf)$#i', [&$this, 'pdf_embed_handler'] );
}
public function filter_video_embed($video, $attr, $url, $rawattr) {
$dimensions = '';
if ( ! empty( $attr['width'] ) && ! empty( $attr['height'] ) ) {
$dimensions .= sprintf( 'width="%d" ', (int) $attr['width'] );
//$dimensions .= sprintf( 'height="%d" ', (int) $attr['height'] );
}
$video = sprintf( '<video controls="" %s src="%s"></video>', $dimensions, esc_url( $url ) );
return $video;
}
public function filter_audio_embed($audio, $attr, $url, $rawattr) {
if ( ! empty( $attr['width'] ) ) {
$dimensions = sprintf( 'width="%d" ', (int) $attr['width'] );
}
$audio = sprintf('<audio controls="" src="%s" %s></audio>', $url, $dimensions);
return $audio;
}
public function pdf_embed_handler($matches, $attr, $url, $rawattr) {
global $TAINACAN_BASE_URL;
$viewer_url = $TAINACAN_BASE_URL . '/pdf-viewer/pdf-viewer.html?file=' . $url;
//$viewer_url = $TAINACAN_BASE_URL . '/assets/pdfjs-dist/web/viewer.html?file=' . $url;
$defaults = array(
'width' => 800,
'height' => 1000
);
$args = array_merge($defaults, $attr);
$dimensions = '';
if ( ! empty( $args['width'] ) && ! empty( $args['height'] ) ) {
$dimensions .= sprintf( "width='%d' ", (int) $args['width'] );
$dimensions .= sprintf( "height='%d' ", (int) $args['height'] );
}
$pdf = "<iframe id='iframePDF' name='iframePDF' src='$viewer_url' $dimensions allowfullscreen webkitallowfullscreen></iframe>";
return $pdf;
}
}

View File

@ -125,8 +125,7 @@ class Entity {
} }
} }
public function get_repository() public function get_repository() {
{
$namespace = '\Tainacan\Repositories\\'.$this->repository; $namespace = '\Tainacan\Repositories\\'.$this->repository;
$repository = $namespace::get_instance(); $repository = $namespace::get_instance();

View File

@ -494,4 +494,49 @@ class Item extends Entity {
} }
public function get_document_html($img_size = 'large') {
$type = $this->get_document_type();
$output = '';
if ( $type == 'url' ) {
$output .= apply_filters('the_content', $this->get_document());
} elseif ( $type == 'text' ) {
$output .= $this->get_document();
} elseif ( $type == 'attachment' ) {
if ( wp_attachment_is_image($this->get_document()) ) {
$img = wp_get_attachment_image($this->get_document(), $img_size);
$img_full = wp_get_attachment_url($this->get_document());
$output .= sprintf("<a href='%s' target='blank'>%s</a>", $img_full, $img);
} else {
global $wp_embed;
$url = wp_get_attachment_url($this->get_document());
$embed = $wp_embed->autoembed($url);
if ( $embed == $url ) {
// No embed handler found
// TODO: Add filter to allow customization
$output .= sprintf("<a href='%s' target='blank'>%s</a>", $url, $url);
} else {
$output .= $embed;
}
}
}
return $output;
}
} }

View File

@ -132,16 +132,16 @@ class Log extends Entity {
return maybe_unserialize( base64_decode( $this->get_mapped_property( 'value' ) ) ); return maybe_unserialize( base64_decode( $this->get_mapped_property( 'value' ) ) );
} }
/** // /**
* Get old value of log entry object // * Get old value of log entry object
* // *
* @param mixed $value // * @param mixed $value
* // *
* @return void // * @return void
*/ // */
public function get_old_value() { // public function get_old_value() {
return maybe_unserialize( base64_decode( $this->get_mapped_property( 'old_value' ) ) ); // return maybe_unserialize( base64_decode( $this->get_mapped_property( 'old_value' ) ) );
} // }
/** /**
* Set log tittle * Set log tittle
@ -226,15 +226,29 @@ class Log extends Entity {
$this->set_mapped_property( 'value', base64_encode( maybe_serialize( $value ) ) ); $this->set_mapped_property( 'value', base64_encode( maybe_serialize( $value ) ) );
} }
// /**
// * Set old value of log entry
// *
// * @param [mixed] $value
// *
// * @return void
// */
// protected function set_old_value( $value = null ) {
// $this->set_mapped_property( 'old_value', base64_encode( maybe_serialize( $value ) ) );
// }
/** /**
* Set old value of log entry * @param $diffs
*
* @param [mixed] $value
*
* @return void
*/ */
protected function set_old_value( $value = null ) { public function set_log_diffs($diffs){
$this->set_mapped_property( 'old_value', base64_encode( maybe_serialize( $value ) ) ); $this->set_mapped_property( 'log_diffs', $diffs );
}
/**
* @return mixed|null
*/
public function get_log_diffs(){
return $this->get_mapped_property('log_diffs');
} }
/** /**
@ -242,24 +256,22 @@ class Log extends Entity {
* @param boolean|string $msn * @param boolean|string $msn
* @param string $desc * @param string $desc
* @param mixed $new_value * @param mixed $new_value
* @param mixed $old_value * @param array $diffs
* @param string $status 'publish', 'private' or 'pending' * @param string $status 'publish', 'private' or 'pending'
* *
* @throws \Exception
* @return \Tainacan\Entities\Log * @return \Tainacan\Entities\Log
* @throws \Exception
*/ */
public static function create( $msn = false, $desc = '', $new_value = null, $old_value = null, $status = 'publish' ) { public static function create( $msn = false, $desc = '', $new_value = null, $diffs = [], $status = 'publish' ) {
$log = new Log(); $log = new Log();
$log->set_title( $msn ); $log->set_title( $msn );
$log->set_description( $desc ); $log->set_description( $desc );
$log->set_status( $status ); $log->set_status( $status );
$log->set_log_diffs( $diffs );
if ( ! is_null( $new_value ) ) { if ( ! is_null( $new_value ) ) {
$log->set_value( $new_value ); $log->set_value( $new_value );
if ( ! is_null( $old_value ) ) {
$log->set_old_value( $old_value );
}
} elseif ( $msn === false ) { } elseif ( $msn === false ) {
throw new \Exception( 'msn or new_value is need to log' ); throw new \Exception( 'msn or new_value is need to log' );
} }
@ -284,20 +296,20 @@ class Log extends Entity {
return $repository->approve( $this ); return $repository->approve( $this );
} }
/** // /**
* // *
* {@inheritDoc} // * {@inheritDoc}
* @see \Tainacan\Entities\Entity::diff() // * @see \Tainacan\Entities\Entity::diff()
*/ // */
public function diff($which = 0) { // public function diff($which = 0) {
$log = $this; // $log = $this;
//
if($which != 0) { // if($which != 0) {
$log = new self($which); // $log = new self($which);
} // }
//
$value = $log->get_value(); // $value = $log->get_value();
$old = $log->get_old_value(); // $old = $log->get_old_value();
return $value->diff($old); // return $value->diff($old);
} // }
} }

View File

@ -15,7 +15,6 @@
</template> </template>
<script> <script>
import { eventBusSearch } from '../../js/event-bus-search'
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
export default { export default {
@ -33,7 +32,7 @@
computed: { computed: {
getErrorMessage() { getErrorMessage() {
let msg = ''; let msg = '';
let errors = eventBusSearch.getErrors( this.filter.id ); let errors = this.$eventBusSearch.getErrors( this.filter.id );
if ( errors) { if ( errors) {
this.setFilterTypeMessage('is-danger'); this.setFilterTypeMessage('is-danger');
for (let index in errors) { for (let index in errors) {
@ -57,7 +56,7 @@
'getPostQuery' 'getPostQuery'
]), ]),
listen( event ){ listen( event ){
eventBusSearch.$emit( 'input', ( event.field_id ) ? event : event.detail[0] ); this.$eventBusSearch.$emit( 'input', ( event.field_id ) ? event : event.detail[0] );
}, },
setFilterTypeMessage( message ){ setFilterTypeMessage( message ){
this.filterTypeMessage = message; this.filterTypeMessage = message;

View File

@ -307,9 +307,21 @@ class Collections extends Repository {
} }
} }
// TODO: Implement this method
public function fetch_by_db_identifier( $db_identifier ) { public function fetch_by_db_identifier( $db_identifier ) {
if ( $id = $this->get_id_by_db_identifier($db_identifier) ) {
return $this->fetch($id);
}
}
public function get_id_by_db_identifier($db_identifier) {
$prefix = \Tainacan\Entities\Collection::$db_identifier_prefix;
$sufix = \Tainacan\Entities\Collection::$db_identifier_sufix;
$id = str_replace($prefix, '', $db_identifier);
$id = str_replace($sufix, '', $id);
if (is_numeric($id)) {
return (int) $id;
}
return false;
} }
function pre_update_moderators( $collection ) { function pre_update_moderators( $collection ) {

View File

@ -12,18 +12,15 @@ class Filters extends Repository {
private static $instance = null; private static $instance = null;
public static function get_instance() public static function get_instance() {
{ if(!isset(self::$instance)) {
if(!isset(self::$instance))
{
self::$instance = new self(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
} }
protected function __construct() protected function __construct() {
{
parent::__construct(); parent::__construct();
} }

View File

@ -7,8 +7,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Item_Metadata extends Repository { class Item_Metadata extends Repository {
protected function __construct() protected function __construct() {
{
parent::__construct(); parent::__construct();
} }
@ -16,10 +15,8 @@ class Item_Metadata extends Repository {
private static $instance = null; private static $instance = null;
public static function get_instance() public static function get_instance() {
{ if(!isset(self::$instance)) {
if(!isset(self::$instance))
{
self::$instance = new self(); self::$instance = new self();
} }
@ -33,12 +30,19 @@ class Item_Metadata extends Repository {
// TODO: Throw Warning saying you must validate object before insert() // TODO: Throw Warning saying you must validate object before insert()
} }
$old = $item_metadata;
$is_update = false; $is_update = false;
// TODO get props obj before update $diffs = [];
if( $item_metadata->get_id() ) { if ( $item_metadata->get_id() ) {
$is_update = true;
$old = $item_metadata->get_repository()->fetch( $item_metadata->get_id() ); if($item_metadata->get_status() === 'auto-draft') {
$is_update = false;
} else {
$is_update = true;
}
$old = $item_metadata->get_repository()->fetch( $item_metadata->get_id() );
$diffs = $this->diff($old, $item_metadata);
} }
$unique = !$item_metadata->is_multiple(); $unique = !$item_metadata->is_multiple();
@ -84,12 +88,10 @@ class Item_Metadata extends Repository {
} }
} }
} }
do_action('tainacan-insert', $item_metadata, $diffs, $is_update);
do_action('tainacan-insert-Item_Metadata_Entity', $item_metadata);
} }
do_action('tainacan-insert', $item_metadata, $old, $is_update);
do_action('tainacan-insert-Item_Metadata_Entity', $item_metadata);
$new_entity = new Entities\Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_field()); $new_entity = new Entities\Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_field());
@ -133,11 +135,18 @@ class Item_Metadata extends Repository {
if ($field_type->get_primitive_type() == 'term') { if ($field_type->get_primitive_type() == 'term') {
$new_terms = $item_metadata->get_value(); $new_terms = $item_metadata->get_value();
$taxonomy = new Entities\Taxonomy( $field_type->get_option('taxonomy_id') ); $taxonomy = new Entities\Taxonomy( $field_type->get_option('taxonomy_id') );
if( $taxonomy ){ if( $taxonomy ){
wp_set_object_terms($item_metadata->get_item()->get_id(), $new_terms, $taxonomy->get_db_identifier() ); $old = $item_metadata;
$success = wp_set_object_terms($item_metadata->get_item()->get_id(), $new_terms, $taxonomy->get_db_identifier() );
if(!$success instanceof \WP_Error) {
$diffs = $this->diff($old, $item_metadata);
do_action( 'tainacan-insert', $item_metadata, $diffs, true );
}
} }
} }
} }

View File

@ -168,12 +168,19 @@ class Items extends Repository {
public function insert( $item ) { public function insert( $item ) {
$old = $item;
$is_update = false; $is_update = false;
// TODO get props obj before update $diffs = [];
if( $item->get_id() ) { if ( $item->get_id() ) {
$is_update = true;
$old = $item->get_repository()->fetch( $item->get_id() ); $old = $item->get_repository()->fetch( $item->get_id() );
if($old->get_status() === 'auto-draft') {
$is_update = false;
} else {
$is_update = true;
}
$diffs = $this->diff($old, $item);
} }
$map = $this->get_map(); $map = $this->get_map();
@ -181,7 +188,7 @@ class Items extends Repository {
// get collection to determine post type // get collection to determine post type
$collection = $item->get_collection(); $collection = $item->get_collection();
if ( ! $collection ) { if ( !$collection ) {
return false; return false;
} }
@ -222,7 +229,7 @@ class Items extends Repository {
set_post_thumbnail( $item->WP_Post, $item->get_featured_img_id( $item->WP_Post->ID ) ); set_post_thumbnail( $item->WP_Post, $item->get_featured_img_id( $item->WP_Post->ID ) );
} }
do_action( 'tainacan-insert', $item, $old, $is_update ); do_action( 'tainacan-insert', $item, $diffs, $is_update );
do_action( 'tainacan-insert-Item', $item ); do_action( 'tainacan-insert-Item', $item );
// return a brand new object // return a brand new object

View File

@ -28,7 +28,7 @@ class Logs extends Repository {
protected function __construct() { protected function __construct() {
parent::__construct(); parent::__construct();
add_action( 'tainacan-insert', array( $this, 'log_inserts' ), 10, 3 ); add_action( 'tainacan-insert', array( $this, 'insert_log' ), 10, 3 );
} }
public function get_map() { public function get_map() {
@ -104,13 +104,16 @@ class Logs extends Repository {
'description' => __( 'The actual log value' ), 'description' => __( 'The actual log value' ),
'validation' => '' 'validation' => ''
], ],
'old_value' => [ // 'old_value' => [
// 'map' => 'meta',
// 'title' => __( 'Old value', 'tainacan' ),
// 'type' => 'string',
// 'description' => __( 'The old log value' ),
// 'validation' => ''
// ],
'log_diffs' => [
'map' => 'meta', 'map' => 'meta',
'title' => __( 'Old value', 'tainacan' ), ]
'type' => 'string',
'description' => __( 'The old log value' ),
'validation' => ''
],
] ); ] );
} }
@ -230,24 +233,22 @@ class Logs extends Repository {
* *
* @return Entities\Log new created log * @return Entities\Log new created log
*/ */
public function log_inserts( $new_value, $old_value = null, $is_update = null ) { public function insert_log( $new_value, $diffs, $is_update = null ) {
$msn = ""; $msn = "";
$description = ""; $description = "";
if ( is_object( $new_value ) ) { if ( is_object( $new_value ) ) {
// do not log a log // do not log a log
if ( method_exists( $new_value, 'get_post_type' ) && $new_value->get_post_type() == 'tainacan-log' || $new_value->get_status() === 'auto-draft' ) { if ( (method_exists( $new_value, 'get_post_type' ) && $new_value->get_post_type() === 'tainacan-log') || $new_value->get_status() === 'auto-draft' ) {
return; return false;
} }
if($new_value instanceof Entities\Field){ if($new_value instanceof Entities\Field){
$type = $new_value->get_field_type(); $type = $new_value->get_field_type();
if($type === 'Tainacan\Field_Types\Core_Title' || $type === 'Tainacan\Field_Types\Core_Description'){ if($type === 'Tainacan\Field_Types\Core_Title' || $type === 'Tainacan\Field_Types\Core_Description'){
return; return false;
} }
} elseif (!$is_update && $new_value instanceof Entities\Item || $new_value instanceof Entities\Collection) {
return;
} }
$type = get_class( $new_value ); $type = get_class( $new_value );
@ -300,7 +301,9 @@ class Logs extends Repository {
$msn = apply_filters( 'tainacan-insert-log-message-title', $msn, $type, $new_value ); $msn = apply_filters( 'tainacan-insert-log-message-title', $msn, $type, $new_value );
$description = apply_filters('tainacan-insert-log-description', $description, $type, $new_value); $description = apply_filters('tainacan-insert-log-description', $description, $type, $new_value);
return Entities\Log::create( $msn, $description, $new_value, $old_value ); if(!empty($diffs)) {
return Entities\Log::create( $msn, $description, $new_value, $diffs );
}
} }
/** /**

View File

@ -76,14 +76,21 @@ abstract class Repository {
// TODO: Throw Warning saying you must validate object before insert() // TODO: Throw Warning saying you must validate object before insert()
} }
$old = $obj;
$is_update = false; $is_update = false;
// TODO get props obj before update $diffs = [];
if( $obj->get_id() ) { if ( $obj->get_id() ) {
$is_update = true;
$old = $obj->get_repository()->fetch( $obj->get_id() ); $old = $obj->get_repository()->fetch( $obj->get_id() );
if(method_exists($old, 'get_status') && $old->get_status() === 'auto-draft') {
$is_update = false;
} else {
$is_update = true;
}
$diffs = $this->diff($old, $obj);
} }
$map = $this->get_map(); $map = $this->get_map();
// First iterate through the native post properties // First iterate through the native post properties
@ -118,7 +125,7 @@ abstract class Repository {
set_post_thumbnail( $obj->WP_Post, $obj->get_featured_img_id( $obj->WP_Post->ID ) ); set_post_thumbnail( $obj->WP_Post, $obj->get_featured_img_id( $obj->WP_Post->ID ) );
} }
do_action( 'tainacan-insert', $obj, $old, $is_update ); do_action( 'tainacan-insert', $obj, $diffs, $is_update );
do_action( 'tainacan-insert-' . $obj->get_post_type(), $obj ); do_action( 'tainacan-insert-' . $obj->get_post_type(), $obj );
// return a brand new object // return a brand new object
@ -343,8 +350,8 @@ abstract class Repository {
*/ */
public static function get_collections_db_identifiers() { public static function get_collections_db_identifiers() {
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$collections = $Tainacan_Collections->fetch( [], 'OBJECT' ); $collections = $Tainacan_Collections->fetch( [], 'OBJECT' );
$cpts = []; $cpts = [];
foreach ( $collections as $col ) { foreach ( $collections as $col ) {
$cpts[] = $col->get_db_identifier(); $cpts[] = $col->get_db_identifier();
} }
@ -366,9 +373,10 @@ abstract class Repository {
return $post; return $post;
} }
if (!$post instanceof \WP_Post) if ( ! $post instanceof \WP_Post ) {
return false; return false;
}
$post_type = $post->post_type; $post_type = $post->post_type;
return self::get_entity_by_post_type( $post_type, $post ); return self::get_entity_by_post_type( $post_type, $post );
@ -393,15 +401,15 @@ abstract class Repository {
} else { } else {
throw new \Exception( 'Collection object not found for this post' ); throw new \Exception( 'Collection object not found for this post' );
} }
} elseif ($post_type === \Tainacan\Repositories\Item_Metadata::get_instance()->entities_type::get_post_type()){ } elseif ( $post_type === \Tainacan\Repositories\Item_Metadata::get_instance()->entities_type::get_post_type() ) {
return new Entities\Item_Metadata_Entity(null, null); return new Entities\Item_Metadata_Entity( null, null );
} else { } else {
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance(); $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
$tnc_globals = [ $tnc_globals = [
$Tainacan_Collections, $Tainacan_Collections,
@ -439,13 +447,13 @@ abstract class Repository {
return $Tainacan_Items; return $Tainacan_Items;
} else { } else {
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance(); $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
$tnc_globals = [ $tnc_globals = [
$Tainacan_Collections, $Tainacan_Collections,
@ -615,7 +623,7 @@ abstract class Repository {
public function diff( $old = 0, $new ) { public function diff( $old = 0, $new ) {
$old_entity = null; $old_entity = null;
if ( $old === 0 ) { // self diff or other entity? if ( $old === 0) { // self diff or other entity?
$id = $new->get_id(); $id = $new->get_id();
if ( ! empty( $id ) ) { // there is a repository entity? if ( ! empty( $id ) ) { // there is a repository entity?
@ -624,42 +632,61 @@ abstract class Repository {
$entity_type = get_class( $new ); $entity_type = get_class( $new );
$old_entity = new $entity_type; // there is no saved entity, let compare with a new empty one $old_entity = new $entity_type; // there is no saved entity, let compare with a new empty one
} }
} else { // get entity from repository } else {
$old_entity = $this->get_entity_by_post( $old ); $old_entity = $old;
} }
$new_entity = $this->get_entity_by_post( $new ); $new_entity = $new;
$map = $this->get_map(); $map = $this->get_map();
$diff = []; $diff = [];
foreach ( $map as $prop => $mapped ) { foreach ( $map as $prop => $mapped ) {
if(method_exists($new_entity, 'get_featured_image')){
$old_image = $old_entity->get_featured_image();
$new_image = $new_entity->get_featured_image();
if($old_image != $new_image){
$diff['featured_image'] = [
'new' => $new_image,
'old' => $old_image,
'diff_with_index' => 0,
];
}
}
if ( $old_entity->get_mapped_property( $prop ) != $new_entity->get_mapped_property( $prop ) ) { if ( $old_entity->get_mapped_property( $prop ) != $new_entity->get_mapped_property( $prop ) ) {
if ( $mapped['map'] == 'meta_multi' || is_array($new_entity->get_mapped_property( $prop ))) { if ( $mapped['map'] === 'meta_multi' || ( $mapped['map'] === 'meta' && is_array( $new_entity->get_mapped_property( $prop ) ) ) ) {
// Array of diffs with index of diff in new array // Array of diffs with index of diff in new array
$array_diff_with_index = array_diff_assoc($new_entity->get_mapped_property( $prop ), $old_entity->get_mapped_property( $prop )); $new_v = $new_entity->get_mapped_property( $prop );
$old_v = $old_entity->get_mapped_property( $prop );
$old_v = !is_array($old_v) && empty($old_v) && !is_string($old_v) ? array() : ( !is_string($old_v) ? $old_v : [$old_v] );
$array_diff_with_index = array_map('unserialize',
array_diff_assoc(array_map('serialize', $new_v), array_map('serialize', $old_v)));
if ( ! empty( $array_diff_with_index ) ) { if ( ! empty( $array_diff_with_index ) ) {
$diff[ $prop ] = [ $diff[ $prop ] = [
'new' => $new_entity->get_mapped_property( $prop ), 'new' => $new_entity->get_mapped_property( $prop ),
'old' => $old_entity->get_mapped_property( $prop ), 'old' => $old_entity->get_mapped_property( $prop ),
'diff_with_index' => $array_diff_with_index, 'diff_with_index' => $array_diff_with_index,
]; ];
} }
} elseif($mapped['map'] !== 'post_modified') { } elseif ( $mapped['map'] !== 'post_modified' ) {
$new_as_array = explode(' ', $new_entity->get_mapped_property( $prop )); $new_as_array = explode( ' ', $new_entity->get_mapped_property( $prop ) );
$old_as_array = explode(' ', $old_entity->get_mapped_property( $prop )); $old_as_array = explode( ' ', $old_entity->get_mapped_property( $prop ) );
// Array of diffs with index of diff in new array // Array of diffs with index of diff in new array
$array_diff_with_index = array_diff_assoc($new_as_array, $old_as_array); $array_diff_with_index = array_diff_assoc( $new_as_array, $old_as_array );
$diff[ $prop ] = [ $diff[ $prop ] = [
'new' => $new_as_array, 'new' => $new_as_array,
'old' => $old_entity->get_mapped_property( $prop ), 'old' => $old_entity->get_mapped_property( $prop ),
'diff_with_index' => $array_diff_with_index, 'diff_with_index' => $array_diff_with_index,
]; ];
} }

View File

@ -98,15 +98,18 @@ class Terms extends Repository {
* @param Entities\Entity $term * @param Entities\Entity $term
* *
* @return Entities\Entity|Entities\Term * @return Entities\Entity|Entities\Term
* @throws \Exception
*/ */
public function insert($term){ public function insert($term){
$old = $term;
$is_update = false; $is_update = false;
// TODO get props obj before update $diffs = [];
if( $term->get_id() ) { if ( $term->get_id() ) {
$is_update = true; $is_update = true;
$old = $term->get_repository()->fetch( $term->get_id() );
$old = $this->fetch( $term->get_id(), $term->get_taxonomy() );
$diffs = $this->diff($old, $term);
} }
// First iterate through the native post properties // First iterate through the native post properties
@ -147,7 +150,7 @@ class Terms extends Repository {
} }
} }
do_action('tainacan-insert', $term, $old, $is_update); do_action('tainacan-insert', $term, $diffs, $is_update);
do_action('tainacan-insert-Term', $term); do_action('tainacan-insert-Term', $term);
return new Entities\Term($term_saved['term_id'], $term->get_taxonomy()); return new Entities\Term($term_saved['term_id'], $term->get_taxonomy());
@ -188,8 +191,12 @@ class Terms extends Repository {
} }
} }
} else { } elseif (is_string($taxonomies) && is_numeric($args)){ // if taxonomy is taxonomy_db_identifier
return []; $cpt = $taxonomies;
$term = get_term_by('id', $args, $cpt);
return new Entities\Term($term);
} }
if(is_array( $args ) && !empty( $cpt ) ){ // if an array of arguments is if(is_array( $args ) && !empty( $cpt ) ){ // if an array of arguments is

View File

@ -118,4 +118,6 @@ $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
$Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance(); $Tainacan_Exposers = \Tainacan\Exposers\Exposers::get_instance();
$Tainacan_Embed = \Tainacan\Embed::get_instance();
?> ?>

View File

@ -20,6 +20,58 @@ class Old_Tainacan extends Importer
$this->import_structure_and_mapping = $import_structure_and_mapping; $this->import_structure_and_mapping = $import_structure_and_mapping;
} }
public function fetch_from_remote( $url ){
$url_json = explode('/colecao/', $url)[0] . "/wp-json/tainacan/v1/collections";
$all_collections_info = wp_remote_get($url_json);
if(isset($all_collections_info['body']))
{
$all_collections_array = json_decode($all_collections_info['body']);
$collection_name = explode('/', $url);
$collection_name = array_filter($collection_name, function($item){
if(empty($item)) return false;
return true;
});
$collection_name = end($collection_name);
foreach($all_collections_array as $collection)
{
if(strcmp($collection->post_name, $collection_name) === 0)
{
$link = $collection->link[0]->href;
break;
}
}
if(!empty($link))
{
$items = wp_remote_get( $link."/items/?includeMetadata=1" );
if(isset($items['body']))
{
$items_array = json_decode($items['body']);
//Get Metatype
$meta_type = wp_remote_get($link."/metadata");
if(isset($meta_type['body']))
{
$meta_type_array = json_decode($meta_type['body']);
$file_info['items'] = $items_array;
$file_info['meta'] = $meta_type_array;
$file = fopen( $this->get_id().'.txt', 'w' );
fwrite( $file, serialize($file_info) );
fclose( $file );
return $this->set_file( $this->get_id().'.txt' );
}
}
}
}
}
/** /**
* get the fields of file/url to allow mapping * get the fields of file/url to allow mapping
* should return an array * should return an array
@ -29,10 +81,18 @@ class Old_Tainacan extends Importer
public function get_fields() public function get_fields()
{ {
$file = new \SplFileObject( $this->tmp_file, 'r' ); $file = new \SplFileObject( $this->tmp_file, 'r' );
$json = json_decode($file->fread($file->getSize()), true); $file_content = unserialize($file->fread($file->getSize()));
$item = $json['items'][0]['item'];
return array_keys($item); foreach($file_content['meta'] as $tab)
{
foreach($tab->{"tab-properties"} as $meta)
{
$fields[] = ['name' => $meta->name, 'type' => $meta->type];
}
}
return $fields;
} }
/** /**
@ -51,16 +111,17 @@ class Old_Tainacan extends Importer
// search the index in the file and get values // search the index in the file and get values
$file = new \SplFileObject( $this->tmp_file, 'r' ); $file = new \SplFileObject( $this->tmp_file, 'r' );
$json = json_decode($file->fread($file->getSize()), true); $file_content = unserialize($file->fread($file->getSize()));
$values = $json['items'][$index]['item']; /*to fix this*/
$values = $file_content['items']->items[$index]->item;
if( count( $headers ) !== count( $values ) ){ if( count( $headers ) !== count( $values ) ){
return false; return false;
} }
foreach ($headers as $header) { foreach ($headers as $header) {
$processedItem[ $header ] = $values[ $header ]; $processedItem[ $header['name'] ] = $values[ $header['name'] ];
} }
return $processedItem; return $processedItem;
@ -68,12 +129,10 @@ class Old_Tainacan extends Importer
function create_fields_and_mapping() { function create_fields_and_mapping() {
$file = new \SplFileObject( $this->tmp_file, 'r' );
$json = json_decode($file->fread($file->getSize()), true);
$item = $json['items'][0]['item'];
$fields_repository = \Tainacan\Repositories\Fields::get_instance(); $fields_repository = \Tainacan\Repositories\Fields::get_instance();
$avoid = [ $file_fields = $this->get_fields();
/*$avoid = [
'ID', 'ID',
'post_author', 'post_author',
'post_date', 'post_date',
@ -94,29 +153,27 @@ class Old_Tainacan extends Importer
'filter', 'filter',
'link', 'link',
'thumbnail' 'thumbnail'
]; ];*/
foreach($item as $field_name => $value) foreach($file_fields as $index => $meta_info)
{ {
if(!in_array($field_name, $avoid)) $newField = new \Tainacan\Entities\Field();
{
$newField = new \Tainacan\Entities\Field();
$newField->set_name($field_name); $newField->set_name($meta_info['name']);
$newField->set_field_type('Tainacan\Field_Types\Text');
$newField->set_collection($this->collection); $type = 'Text';
$newField->validate(); // there is no user input here, so we can be sure it will validate.
$newField = $fields_repository->insert($newField); $newField->set_field_type('Tainacan\Field_Types\\'.$type);
$source_fields = $this->get_fields(); $newField->set_collection($this->collection);
$newField->validate(); // there is no user input here, so we can be sure it will validate.
$source_id = array_search($field_name, $source_fields); $newField = $fields_repository->insert($newField);
$this->set_mapping([
$newField->get_id() => $source_fields[$source_id]
]); $this->set_mapping([
} $newField->get_id() => $file_fields[$index]
]);
} }
} }
@ -128,8 +185,8 @@ class Old_Tainacan extends Importer
public function get_total_items_from_source() public function get_total_items_from_source()
{ {
$file = new \SplFileObject( $this->tmp_file, 'r' ); $file = new \SplFileObject( $this->tmp_file, 'r' );
$json = json_decode($file->fread($file->getSize()), true); $file_content = unserialize($file->fread($file->getSize()));
return $this->total_items = $json['found_items']; return $this->total_items = $file_content['items']->found_items;
} }
} }

View File

@ -1,123 +1,127 @@
import Vue from 'vue'; export default {
import store from './store/store'
import router from './../admin/js/router.js';
export const eventBusSearch = new Vue({ install(Vue, options = {}) {
router,
store,
data: {
componentsTag: [],
errors : [],
query: {}
},
created(){
this.$on('input', data => {
store.dispatch('search/setPage', 1);
if( data.taxonomy ){ Vue.prototype.$eventBusSearch = new Vue({
this.add_taxquery(data); router: options.router,
} else { store: options.store,
this.add_metaquery(data); data: {
} componentsTag: [],
errors : [],
this.updateURLQueries(); query: {},
}); collectionId: undefined
}, },
watch: { created(){
'$route.query' () { this.$on('input', data => {
if (this.$route.name == 'CollectionItemsPage' || this.$route.name == 'ItemsPage') { this.$store.dispatch('search/setPage', 1);
if (this.$route.query.perpage == undefined)
this.$route.query.perpage = 12; if( data.taxonomy ){
if (this.$route.query.paged == undefined) this.add_taxquery(data);
this.$route.query.paged = 1; } else {
if (this.$route.query.order == undefined) this.add_metaquery(data);
this.$route.query.order = 'DESC';
if (this.$route.query.orderby == undefined)
this.$route.query.orderby = 'date';
store.dispatch('search/set_postquery', this.$route.query);
//console.log(this.$route.query);
this.loadItems();
}
}
},
methods: {
add_metaquery( data ){
if ( data && data.collection_id ){
store.dispatch('search/add_metaquery', data );
}
},
add_taxquery( data ){
if ( data && data.collection_id ){
store.dispatch('search/add_taxquery', data );
}
},
getErrors( filter_id ){
let error = this.errors.find( errorItem => errorItem.field_id === filter_id );
return ( error ) ? error.errors : false
},
listener(){
const components = this.getAllComponents();
for (let eventElement of components){
eventElement.addEventListener('input', (event) => {
if( event.detail ) {
this.add_metaquery( event.detail[0] );
} }
this.updateURLQueries();
}); });
} },
}, watch: {
setPage(page) { '$route.query' () {
store.dispatch('search/setPage', page); //if (this.$route.name == 'CollectionItemsPage' || this.$route.name == 'ItemsPage') {
this.updateURLQueries(); if (this.$route.query.perpage == undefined)
}, this.$route.query.perpage = 12;
setItemsPerPage(itemsPerPage) { if (this.$route.query.paged == undefined)
store.dispatch('search/setItemsPerPage', itemsPerPage); this.$route.query.paged = 1;
this.updateURLQueries(); if (this.$route.query.order == undefined)
}, this.$route.query.order = 'DESC';
setOrderBy(newOrderBy) { if (this.$route.query.orderby == undefined)
store.dispatch('search/setOrderBy', newOrderBy); this.$route.query.orderby = 'date';
this.updateURLQueries();
}, this.$store.dispatch('search/set_postquery', this.$route.query);
setOrder(newOrder) { this.loadItems();
store.dispatch('search/setOrder', newOrder); //}
this.updateURLQueries();
},
updateURLQueries() {
router.push({ query: {} });
router.push({ query: store.getters['search/getPostQuery'] });
},
updateStoreFromURL() {
store.dispatch('search/set_postquery', this.$route.query);
},
loadItems() {
this.$emit( 'isLoadingItems', true);
store.dispatch('collection/fetchItems', this.$route.params.collectionId).then((res) => {
this.$emit( 'isLoadingItems', false);
this.$emit( 'hasFiltered', res.hasFiltered);
})
.catch(() => {
this.$emit( 'isLoadingItems', false);
});
},
/* Dev interfaces methods */
registerComponent( name ){
if (this.componentsTag.indexOf(name) < 0) {
this.componentsTag.push( name );
}
},
getAllComponents(){
const components = [];
for( let component of this.componentsTag ){
const eventElements = document.getElementsByTagName( component );
if( eventElements ) {
for (let eventElement of eventElements){
components.push( eventElement );
}
} }
},
methods: {
add_metaquery( data ){
if ( data && data.collection_id ){
this.$store.dispatch('search/add_metaquery', data );
}
},
add_taxquery( data ){
if ( data && data.collection_id ){
this.$store.dispatch('search/add_taxquery', data );
}
},
getErrors( filter_id ){
let error = this.errors.find( errorItem => errorItem.field_id === filter_id );
return ( error ) ? error.errors : false
},
listener(){
const components = this.getAllComponents();
for (let eventElement of components){
eventElement.addEventListener('input', (event) => {
if( event.detail ) {
this.add_metaquery( event.detail[0] );
}
});
}
},
setPage(page) {
this.$store.dispatch('search/setPage', page);
this.updateURLQueries();
},
setItemsPerPage(itemsPerPage) {
this.$store.dispatch('search/setItemsPerPage', itemsPerPage);
this.updateURLQueries();
},
setOrderBy(newOrderBy) {
this.$store.dispatch('search/setOrderBy', newOrderBy);
this.updateURLQueries();
},
setOrder(newOrder) {
this.$store.dispatch('search/setOrder', newOrder);
this.updateURLQueries();
},
updateURLQueries() {
this.$router.push({ query: {} });
this.$router.push({ query: this.$store.getters['search/getPostQuery'] });
},
updateStoreFromURL() {
this.$store.dispatch('search/set_postquery', this.$route.query);
},
loadItems() {
this.$emit( 'isLoadingItems', true);
this.$store.dispatch('collection/fetchItems', this.collectionId).then((res) => {
this.$emit( 'isLoadingItems', false);
this.$emit( 'hasFiltered', res.hasFiltered);
})
.catch(() => {
this.$emit( 'isLoadingItems', false);
});
},
setCollectionId(collectionId) {
this.collectionId = collectionId;
},
/* Dev interfaces methods */
registerComponent( name ){
if (this.componentsTag.indexOf(name) < 0) {
this.componentsTag.push( name );
}
},
getAllComponents(){
const components = [];
for( let component of this.componentsTag ){
const eventElements = document.getElementsByTagName( component );
if( eventElements ) {
for (let eventElement of eventElements){
components.push( eventElement );
}
}
}
return components;
},
} }
return components; });
},
} }
}); }

View File

@ -4,7 +4,7 @@ import Buefy from 'buefy'
// include vue-custom-element plugin to Vue // include vue-custom-element plugin to Vue
import VueCustomElement from 'vue-custom-element'; import VueCustomElement from 'vue-custom-element';
import { eventBus } from './event-bus-web-components'; import { eventBus } from './event-bus-web-components';
import { eventBusSearch } from './event-bus-search'; import eventBusSearch from './event-bus-search';
Vue.use(Buefy); Vue.use(Buefy);
@ -25,47 +25,48 @@ import FilterAutocomplete from '../classes/filter-types/autocomplete/Autocomplet
import FilterCheckbox from '../classes/filter-types/checkbox/Checkbox.vue'; import FilterCheckbox from '../classes/filter-types/checkbox/Checkbox.vue';
import FilterTaginput from '../classes/filter-types/taginput/Taginput.vue'; import FilterTaginput from '../classes/filter-types/taginput/Taginput.vue';
Vue.use(eventBusSearch);
Vue.customElement('tainacan-text', Text); Vue.customElement('tainacan-text', Text);
eventBus.registerComponent( 'tainacan-text' ); //eventBus.registerComponent( 'tainacan-text' );
Vue.customElement('tainacan-textarea', Textarea); Vue.customElement('tainacan-textarea', Textarea);
eventBus.registerComponent( 'tainacan-textarea' ); //eventBus.registerComponent( 'tainacan-textarea' );
Vue.customElement('tainacan-selectbox', Selectbox); Vue.customElement('tainacan-selectbox', Selectbox);
eventBus.registerComponent( 'tainacan-selectbox' ); //eventBus.registerComponent( 'tainacan-selectbox' );
Vue.customElement('tainacan-numeric', Numeric); Vue.customElement('tainacan-numeric', Numeric);
eventBus.registerComponent( 'tainacan-numeric' ); //eventBus.registerComponent( 'tainacan-numeric' );
Vue.customElement('tainacan-date', Date); Vue.customElement('tainacan-date', Date);
eventBus.registerComponent( 'tainacan-date' ); //eventBus.registerComponent( 'tainacan-date' );
Vue.customElement('tainacan-relationship', Relationship); Vue.customElement('tainacan-relationship', Relationship);
eventBus.registerComponent( 'tainacan-relationship' ); //eventBus.registerComponent( 'tainacan-relationship' );
eventBus.listener(); //eventBus.listener();
/* Form */ /* Form */
Vue.customElement('tainacan-form-relationship', FormRelationship); Vue.customElement('tainacan-form-relationship', FormRelationship);
eventBus.registerComponent( 'tainacan-form-relationship' ); //eventBus.registerComponent( 'tainacan-form-relationship' );
/* Filters */ /* Filters */
Vue.customElement('tainacan-filter-custom-interval', FilterCustomInterval); Vue.customElement('tainacan-filter-custom-interval', FilterCustomInterval);
eventBusSearch.registerComponent( 'tainacan-filter-custom-interval' ); //eventBusSearch.registerComponent( 'tainacan-filter-custom-interval' );
Vue.customElement('tainacan-filter-selectbox', FilterSelectbox); Vue.customElement('tainacan-filter-selectbox', FilterSelectbox);
eventBusSearch.registerComponent( 'tainacan-filter-selectbox' ); //eventBusSearch.registerComponent( 'tainacan-filter-selectbox' );
Vue.customElement('tainacan-filter-autocomplete', FilterAutocomplete); Vue.customElement('tainacan-filter-autocomplete', FilterAutocomplete);
eventBusSearch.registerComponent( 'tainacan-filter-autocomplete' ); //eventBusSearch.registerComponent( 'tainacan-filter-autocomplete' );
Vue.customElement('tainacan-filter-checkbox', FilterCheckbox); Vue.customElement('tainacan-filter-checkbox', FilterCheckbox);
eventBusSearch.registerComponent( 'tainacan-filter-checkbox' ); //eventBusSearch.registerComponent( 'tainacan-filter-checkbox' );
Vue.customElement('tainacan-filter-taginput', FilterTaginput); Vue.customElement('tainacan-filter-taginput', FilterTaginput);
eventBusSearch.registerComponent( 'tainacan-filter-taginput' ); //eventBusSearch.registerComponent( 'tainacan-filter-taginput' );
eventBusSearch.listener(); //eventBusSearch.listener();

View File

@ -15,6 +15,7 @@ export const fetchItems = ({ rootGetters, dispatch, commit }, collectionId) => {
// Differentiates between repository level and collection level queries // Differentiates between repository level and collection level queries
let endpoint = '/collection/'+collectionId+'/items?' let endpoint = '/collection/'+collectionId+'/items?'
if (collectionId == undefined) if (collectionId == undefined)
endpoint = '/items?' endpoint = '/items?'

View File

@ -0,0 +1,359 @@
<!DOCTYPE html>
<!--
Copyright 2012 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Adobe CMap resources are covered by their own copyright but the same license:
Copyright 1990-2015 Adobe Systems Incorporated.
See https://github.com/adobe-type-tools/cmap-resources
-->
<html dir="ltr" mozdisallowselectionprint moznomarginboxes>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="google" content="notranslate">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>PDF.js viewer</title>
<link rel="stylesheet" href="pdfjs-dist/web/viewer.css">
<!-- This snippet is used in production (included from viewer.html) -->
<link rel="resource" type="application/l10n" href="pdfjs-dist/web/locale/locale.properties">
<script src="pdfjs-dist/build/pdf.js"></script>
<script src="pdf-viewer.js"></script>
</head>
<body tabindex="1" class="loadingInProgress">
<div id="outerContainer">
<div id="sidebarContainer">
<div id="toolbarSidebar">
<div class="splitToolbarButton toggled">
<button id="viewThumbnail" class="toolbarButton toggled" title="Show Thumbnails" tabindex="2" data-l10n-id="thumbs">
<span data-l10n-id="thumbs_label">Thumbnails</span>
</button>
<button id="viewOutline" class="toolbarButton" title="Show Document Outline (double-click to expand/collapse all items)" tabindex="3" data-l10n-id="document_outline">
<span data-l10n-id="document_outline_label">Document Outline</span>
</button>
<button id="viewAttachments" class="toolbarButton" title="Show Attachments" tabindex="4" data-l10n-id="attachments">
<span data-l10n-id="attachments_label">Attachments</span>
</button>
</div>
</div>
<div id="sidebarContent">
<div id="thumbnailView">
</div>
<div id="outlineView" class="hidden">
</div>
<div id="attachmentsView" class="hidden">
</div>
</div>
</div> <!-- sidebarContainer -->
<div id="mainContainer">
<div class="findbar hidden doorHanger" id="findbar">
<div id="findbarInputContainer">
<input id="findInput" class="toolbarField" title="Find" placeholder="Find in document…" tabindex="91" data-l10n-id="find_input">
<div class="splitToolbarButton">
<button id="findPrevious" class="toolbarButton findPrevious" title="Find the previous occurrence of the phrase" tabindex="92" data-l10n-id="find_previous">
<span data-l10n-id="find_previous_label">Previous</span>
</button>
<div class="splitToolbarButtonSeparator"></div>
<button id="findNext" class="toolbarButton findNext" title="Find the next occurrence of the phrase" tabindex="93" data-l10n-id="find_next">
<span data-l10n-id="find_next_label">Next</span>
</button>
</div>
</div>
<div id="findbarOptionsContainer">
<input type="checkbox" id="findHighlightAll" class="toolbarField" tabindex="94">
<label for="findHighlightAll" class="toolbarLabel" data-l10n-id="find_highlight">Highlight all</label>
<input type="checkbox" id="findMatchCase" class="toolbarField" tabindex="95">
<label for="findMatchCase" class="toolbarLabel" data-l10n-id="find_match_case_label">Match case</label>
<span id="findResultsCount" class="toolbarLabel hidden"></span>
</div>
<div id="findbarMessageContainer">
<span id="findMsg" class="toolbarLabel"></span>
</div>
</div> <!-- findbar -->
<div id="secondaryToolbar" class="secondaryToolbar hidden doorHangerRight">
<div id="secondaryToolbarButtonContainer">
<button id="secondaryPresentationMode" class="secondaryToolbarButton presentationMode visibleLargeView" title="Switch to Presentation Mode" tabindex="51" data-l10n-id="presentation_mode">
<span data-l10n-id="presentation_mode_label">Presentation Mode</span>
</button>
<button id="secondaryOpenFile" class="secondaryToolbarButton openFile visibleLargeView" title="Open File" tabindex="52" data-l10n-id="open_file">
<span data-l10n-id="open_file_label">Open</span>
</button>
<button id="secondaryPrint" class="secondaryToolbarButton print visibleMediumView" title="Print" tabindex="53" data-l10n-id="print">
<span data-l10n-id="print_label">Print</span>
</button>
<button id="secondaryDownload" class="secondaryToolbarButton download visibleMediumView" title="Download" tabindex="54" data-l10n-id="download">
<span data-l10n-id="download_label">Download</span>
</button>
<a href="#" id="secondaryViewBookmark" class="secondaryToolbarButton bookmark visibleSmallView" title="Current view (copy or open in new window)" tabindex="55" data-l10n-id="bookmark">
<span data-l10n-id="bookmark_label">Current View</span>
</a>
<div class="horizontalToolbarSeparator visibleLargeView"></div>
<button id="firstPage" class="secondaryToolbarButton firstPage" title="Go to First Page" tabindex="56" data-l10n-id="first_page">
<span data-l10n-id="first_page_label">Go to First Page</span>
</button>
<button id="lastPage" class="secondaryToolbarButton lastPage" title="Go to Last Page" tabindex="57" data-l10n-id="last_page">
<span data-l10n-id="last_page_label">Go to Last Page</span>
</button>
<div class="horizontalToolbarSeparator"></div>
<button id="pageRotateCw" class="secondaryToolbarButton rotateCw" title="Rotate Clockwise" tabindex="58" data-l10n-id="page_rotate_cw">
<span data-l10n-id="page_rotate_cw_label">Rotate Clockwise</span>
</button>
<button id="pageRotateCcw" class="secondaryToolbarButton rotateCcw" title="Rotate Counterclockwise" tabindex="59" data-l10n-id="page_rotate_ccw">
<span data-l10n-id="page_rotate_ccw_label">Rotate Counterclockwise</span>
</button>
<div class="horizontalToolbarSeparator"></div>
<button id="cursorSelectTool" class="secondaryToolbarButton selectTool toggled" title="Enable Text Selection Tool" tabindex="60" data-l10n-id="cursor_text_select_tool">
<span data-l10n-id="cursor_text_select_tool_label">Text Selection Tool</span>
</button>
<button id="cursorHandTool" class="secondaryToolbarButton handTool" title="Enable Hand Tool" tabindex="61" data-l10n-id="cursor_hand_tool">
<span data-l10n-id="cursor_hand_tool_label">Hand Tool</span>
</button>
<div class="horizontalToolbarSeparator"></div>
<button id="documentProperties" class="secondaryToolbarButton documentProperties" title="Document Properties…" tabindex="62" data-l10n-id="document_properties">
<span data-l10n-id="document_properties_label">Document Properties…</span>
</button>
</div>
</div> <!-- secondaryToolbar -->
<div class="toolbar">
<div id="toolbarContainer">
<div id="toolbarViewer">
<div id="toolbarViewerLeft">
<button id="sidebarToggle" class="toolbarButton" title="Toggle Sidebar" tabindex="11" data-l10n-id="toggle_sidebar">
<span data-l10n-id="toggle_sidebar_label">Toggle Sidebar</span>
</button>
<div class="toolbarButtonSpacer"></div>
<button id="viewFind" class="toolbarButton" title="Find in Document" tabindex="12" data-l10n-id="findbar">
<span data-l10n-id="findbar_label">Find</span>
</button>
<div class="splitToolbarButton hiddenSmallView">
<button class="toolbarButton pageUp" title="Previous Page" id="previous" tabindex="13" data-l10n-id="previous">
<span data-l10n-id="previous_label">Previous</span>
</button>
<div class="splitToolbarButtonSeparator"></div>
<button class="toolbarButton pageDown" title="Next Page" id="next" tabindex="14" data-l10n-id="next">
<span data-l10n-id="next_label">Next</span>
</button>
</div>
<input type="number" id="pageNumber" class="toolbarField pageNumber" title="Page" value="1" size="4" min="1" tabindex="15" data-l10n-id="page">
<span id="numPages" class="toolbarLabel"></span>
</div>
<div id="toolbarViewerRight">
<button id="presentationMode" class="toolbarButton presentationMode hiddenLargeView" title="Switch to Presentation Mode" tabindex="31" data-l10n-id="presentation_mode">
<span data-l10n-id="presentation_mode_label">Presentation Mode</span>
</button>
<button id="openFile" class="toolbarButton openFile hiddenLargeView" title="Open File" tabindex="32" data-l10n-id="open_file">
<span data-l10n-id="open_file_label">Open</span>
</button>
<button id="print" class="toolbarButton print hiddenMediumView" title="Print" tabindex="33" data-l10n-id="print">
<span data-l10n-id="print_label">Print</span>
</button>
<button id="download" class="toolbarButton download hiddenMediumView" title="Download" tabindex="34" data-l10n-id="download">
<span data-l10n-id="download_label">Download</span>
</button>
<a href="#" id="viewBookmark" class="toolbarButton bookmark hiddenSmallView" title="Current view (copy or open in new window)" tabindex="35" data-l10n-id="bookmark">
<span data-l10n-id="bookmark_label">Current View</span>
</a>
<div class="verticalToolbarSeparator hiddenSmallView"></div>
<button id="secondaryToolbarToggle" class="toolbarButton" title="Tools" tabindex="36" data-l10n-id="tools">
<span data-l10n-id="tools_label">Tools</span>
</button>
</div>
<div id="toolbarViewerMiddle">
<div class="splitToolbarButton">
<button id="zoomOut" class="toolbarButton zoomOut" title="Zoom Out" tabindex="21" data-l10n-id="zoom_out">
<span data-l10n-id="zoom_out_label">Zoom Out</span>
</button>
<div class="splitToolbarButtonSeparator"></div>
<button id="zoomIn" class="toolbarButton zoomIn" title="Zoom In" tabindex="22" data-l10n-id="zoom_in">
<span data-l10n-id="zoom_in_label">Zoom In</span>
</button>
</div>
<span id="scaleSelectContainer" class="dropdownToolbarButton">
<select id="scaleSelect" title="Zoom" tabindex="23" data-l10n-id="zoom">
<option id="pageAutoOption" title="" value="auto" selected="selected" data-l10n-id="page_scale_auto">Automatic Zoom</option>
<option id="pageActualOption" title="" value="page-actual" data-l10n-id="page_scale_actual">Actual Size</option>
<option id="pageFitOption" title="" value="page-fit" data-l10n-id="page_scale_fit">Page Fit</option>
<option id="pageWidthOption" title="" value="page-width" data-l10n-id="page_scale_width">Page Width</option>
<option id="customScaleOption" title="" value="custom" disabled="disabled" hidden="true"></option>
<option title="" value="0.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 50 }'>50%</option>
<option title="" value="0.75" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 75 }'>75%</option>
<option title="" value="1" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 100 }'>100%</option>
<option title="" value="1.25" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 125 }'>125%</option>
<option title="" value="1.5" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 150 }'>150%</option>
<option title="" value="2" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 200 }'>200%</option>
<option title="" value="3" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 300 }'>300%</option>
<option title="" value="4" data-l10n-id="page_scale_percent" data-l10n-args='{ "scale": 400 }'>400%</option>
</select>
</span>
</div>
</div>
<div id="loadingBar">
<div class="progress">
<div class="glimmer">
</div>
</div>
</div>
</div>
</div>
<menu type="context" id="viewerContextMenu">
<menuitem id="contextFirstPage" label="First Page"
data-l10n-id="first_page"></menuitem>
<menuitem id="contextLastPage" label="Last Page"
data-l10n-id="last_page"></menuitem>
<menuitem id="contextPageRotateCw" label="Rotate Clockwise"
data-l10n-id="page_rotate_cw"></menuitem>
<menuitem id="contextPageRotateCcw" label="Rotate Counter-Clockwise"
data-l10n-id="page_rotate_ccw"></menuitem>
</menu>
<div id="viewerContainer" tabindex="0">
<div id="viewer" class="pdfViewer"></div>
</div>
<div id="errorWrapper" hidden='true'>
<div id="errorMessageLeft">
<span id="errorMessage"></span>
<button id="errorShowMore" data-l10n-id="error_more_info">
More Information
</button>
<button id="errorShowLess" data-l10n-id="error_less_info" hidden='true'>
Less Information
</button>
</div>
<div id="errorMessageRight">
<button id="errorClose" data-l10n-id="error_close">
Close
</button>
</div>
<div class="clearBoth"></div>
<textarea id="errorMoreInfo" hidden='true' readonly="readonly"></textarea>
</div>
</div> <!-- mainContainer -->
<div id="overlayContainer" class="hidden">
<div id="passwordOverlay" class="container hidden">
<div class="dialog">
<div class="row">
<p id="passwordText" data-l10n-id="password_label">Enter the password to open this PDF file:</p>
</div>
<div class="row">
<input type="password" id="password" class="toolbarField">
</div>
<div class="buttonRow">
<button id="passwordCancel" class="overlayButton"><span data-l10n-id="password_cancel">Cancel</span></button>
<button id="passwordSubmit" class="overlayButton"><span data-l10n-id="password_ok">OK</span></button>
</div>
</div>
</div>
<div id="documentPropertiesOverlay" class="container hidden">
<div class="dialog">
<div class="row">
<span data-l10n-id="document_properties_file_name">File name:</span> <p id="fileNameField">-</p>
</div>
<div class="row">
<span data-l10n-id="document_properties_file_size">File size:</span> <p id="fileSizeField">-</p>
</div>
<div class="separator"></div>
<div class="row">
<span data-l10n-id="document_properties_title">Title:</span> <p id="titleField">-</p>
</div>
<div class="row">
<span data-l10n-id="document_properties_author">Author:</span> <p id="authorField">-</p>
</div>
<div class="row">
<span data-l10n-id="document_properties_subject">Subject:</span> <p id="subjectField">-</p>
</div>
<div class="row">
<span data-l10n-id="document_properties_keywords">Keywords:</span> <p id="keywordsField">-</p>
</div>
<div class="row">
<span data-l10n-id="document_properties_creation_date">Creation Date:</span> <p id="creationDateField">-</p>
</div>
<div class="row">
<span data-l10n-id="document_properties_modification_date">Modification Date:</span> <p id="modificationDateField">-</p>
</div>
<div class="row">
<span data-l10n-id="document_properties_creator">Creator:</span> <p id="creatorField">-</p>
</div>
<div class="separator"></div>
<div class="row">
<span data-l10n-id="document_properties_producer">PDF Producer:</span> <p id="producerField">-</p>
</div>
<div class="row">
<span data-l10n-id="document_properties_version">PDF Version:</span> <p id="versionField">-</p>
</div>
<div class="row">
<span data-l10n-id="document_properties_page_count">Page Count:</span> <p id="pageCountField">-</p>
</div>
<div class="buttonRow">
<button id="documentPropertiesClose" class="overlayButton"><span data-l10n-id="document_properties_close">Close</span></button>
</div>
</div>
</div>
<div id="printServiceOverlay" class="container hidden">
<div class="dialog">
<div class="row">
<span data-l10n-id="print_progress_message">Preparing document for printing…</span>
</div>
<div class="row">
<progress value="0" max="100"></progress>
<span data-l10n-id="print_progress_percent" data-l10n-args='{ "progress": 0 }' class="relative-progress">0%</span>
</div>
<div class="buttonRow">
<button id="printCancel" class="overlayButton"><span data-l10n-id="print_progress_close">Cancel</span></button>
</div>
</div>
</div>
</div> <!-- overlayContainer -->
</div> <!-- outerContainer -->
<div id="printContainer"></div>
</body>
</html>

10191
src/pdf-viewer/pdf-viewer.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -40,8 +40,11 @@ class Theme_Helper {
} }
public function print_scripts() { public function print_scripts() {
global $TAINACAN_BASE_URL;
if ( is_post_type_archive( \Tainacan\Repositories\Repository::get_collections_db_identifiers() ) ) { if ( is_post_type_archive( \Tainacan\Repositories\Repository::get_collections_db_identifiers() ) ) {
\Tainacan\Admin::get_instance()->add_admin_js(); //\Tainacan\Admin::get_instance()->add_admin_js();
wp_enqueue_script('tainacan-search', $TAINACAN_BASE_URL . '/assets/user_search-components.js' , [] , null, true);
wp_localize_script('tainacan-search', 'tainacan_plugin', \Tainacan\Admin::get_instance()->get_admin_js_localization_params());
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
namespace Tainacan; use \Tainacan\Entities;
use Tainacan\Entities; use \Tainacan\Repositories;
/** /**
* To be used inside The Loop * To be used inside The Loop
@ -17,7 +17,7 @@ use Tainacan\Entities;
* @param bool $hide_empty Wether to hide or not fields the item has no value to * @param bool $hide_empty Wether to hide or not fields the item has no value to
* @return string The HTML output * @return string The HTML output
*/ */
function get_tainacan_the_metadata($field = null, $hide_empty = true) { function tainacan_get_the_metadata($field = null, $hide_empty = true) {
$post = get_post(); $post = get_post();
$theme_helper = \Tainacan\Theme_Helper::get_instance(); $theme_helper = \Tainacan\Theme_Helper::get_instance();
@ -32,4 +32,13 @@ function get_tainacan_the_metadata($field = null, $hide_empty = true) {
function tainacan_the_metadata($field = null, $hide_empty = true) { function tainacan_the_metadata($field = null, $hide_empty = true) {
echo get_tainacan_the_metadata($field, $hide_empty); echo get_tainacan_the_metadata($field, $hide_empty);
}
/**
* When visiting a collection archive or single, returns the current collection id
*
* @uses get_post_type() WordPress function, which looks for the global $wp_query variable
*/
function tainacan_get_collection_id() {
return Repositories\Collections::get_instance()->get_id_by_db_identifier(get_post_type());
} }

View File

@ -29,7 +29,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
$this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() ); $this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() );
} }
public function test_automapping_old_tainacan() /*public function test_automapping_old_tainacan()
{ {
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
@ -47,7 +47,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' ); $_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' );
$_SESSION['tainacan_importer'][$id]->run(); $_SESSION['tainacan_importer'][$id]->run();
} }*/
public function test_file_old_tainacan () { public function test_file_old_tainacan () {
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
@ -63,14 +63,16 @@ class ImporterTests extends TAINACAN_UnitTestCase {
return false; return false;
} }
$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' ); //$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' );
//$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/wp-json/tainacan/v1/collections/970/items' ); //$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/wp-json/tainacan/v1/collections/970/items' );
$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/colecao/colecao-to-import/' );
// file isset on importer // file isset on importer
$this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) ); $this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) );
// count size of old tainacan file $_SESSION['tainacan_importer'][$id]->run();
/*// count size of old tainacan file
$this->assertEquals( 5, $_SESSION['tainacan_importer'][$id]->get_total_items() ); $this->assertEquals( 5, $_SESSION['tainacan_importer'][$id]->get_total_items() );
// get fields to mapping // get fields to mapping
@ -117,7 +119,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
$items = $Tainacan_Items->fetch( [], $collection, 'OBJECT' ); $items = $Tainacan_Items->fetch( [], $collection, 'OBJECT' );
$this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_total_items(), count( $items ) ); $this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_total_items(), count( $items ) );*/
} }
/** /**
* @group importer * @group importer

View File

@ -22,7 +22,6 @@ class Logs extends TAINACAN_UnitTestCase {
*/ */
function test_add() { function test_add() {
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$log = $this->tainacan_entity_factory->create_entity( $log = $this->tainacan_entity_factory->create_entity(
'log', 'log',
@ -43,44 +42,6 @@ class Logs extends TAINACAN_UnitTestCase {
$this->assertEquals( 'someone did that', $test->get_description() ); $this->assertEquals( 'someone did that', $test->get_description() );
$this->assertEquals( $user_id, $test->get_user_id() ); $this->assertEquals( $user_id, $test->get_user_id() );
$this->assertEquals( $blog_id, $test->get_blog_id() ); $this->assertEquals( $blog_id, $test->get_blog_id() );
$value = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'testeLogs',
'description' => 'adasdasdsa123',
'default_order' => 'DESC'
),
true
);
$old_value = $value;
$value->set_name( 'newtesteLogs' );
$new_value = $Tainacan_Collections->update( $value );
$create_log = Log::create( 'teste create', 'testing a log creation function', $new_value, $old_value );
$this->assertEquals( 'teste create', $create_log->get_title() );
$this->assertEquals( 'testing a log creation function', $create_log->get_description() );
$this->assertEquals( $new_value, $create_log->get_value() );
$this->assertEquals( $old_value, $create_log->get_old_value() );
$testDB = $Tainacan_Logs->fetch( $create_log->get_id() );
$this->assertEquals( 'teste create', $testDB->get_title() );
$this->assertEquals( 'testing a log creation function', $testDB->get_description() );
$this->assertEquals( $new_value, $testDB->get_value() );
$this->assertEquals( $old_value, $testDB->get_old_value() );
$last_log = $Tainacan_Logs->fetch_last();
$collection = $last_log->get_value();
$this->assertEquals( 'newtesteLogs', $collection->get_name() );
$this->assertEquals( 'adasdasdsa123', $collection->get_description() );
$this->assertEquals( 'DESC', $collection->get_default_order() );
} }
public function test_log_diff() { public function test_log_diff() {
@ -102,7 +63,7 @@ class Logs extends TAINACAN_UnitTestCase {
$log = $Tainacan_Logs->fetch_last(); $log = $Tainacan_Logs->fetch_last();
$diff = $log->diff(); $diff = $log->get_log_diffs();
$this->assertEquals( 'With name', "{$diff['name']['new'][0]} {$diff['name']['new'][1]}" ); $this->assertEquals( 'With name', "{$diff['name']['new'][0]} {$diff['name']['new'][1]}" );
$this->assertEquals( 'No name', $diff['name']['old'] ); $this->assertEquals( 'No name', $diff['name']['old'] );

View File

@ -4,6 +4,7 @@ let webpack = require('webpack');
module.exports = { module.exports = {
entry: { entry: {
dev_admin: './src/js/main.js', dev_admin: './src/js/main.js',
user_search: './src/admin/js/theme-main.js',
user_admin: './src/admin/js/main.js' user_admin: './src/admin/js/main.js'
}, },
output: { output: {