Adds check for permalinks structure before loading the Tainacan Admin.

This commit is contained in:
mateuswetah 2024-06-26 15:57:56 -03:00
parent 5a79068796
commit 3b91a5159a
4 changed files with 89 additions and 52 deletions

View File

@ -5,46 +5,48 @@
:class="{
'tainacan-admin-mobile-app-mode': $adminOptions.mobileAppMode
}">
<template v-if="activeRoute == 'HomePage'">
<tainacan-header v-if="!$adminOptions.hideTainacanHeader" />
<router-view />
</template>
<template v-else>
<primary-menu
v-if="!$adminOptions.hidePrimaryMenu"
:active-route="activeRoute"
:is-menu-compressed="isMenuCompressed" />
<button
v-if="!$adminOptions.hidePrimaryMenu && !$adminOptions.hidePrimaryMenuCompressButton"
id="menu-compress-button"
class="is-hidden-mobile"
:style="{ top: menuCompressButtonTop }"
:aria-label="$i18n.get('label_shrink_menu')"
@click="isMenuCompressed = !isMenuCompressed">
<span
v-tooltip="{
content: $i18n.get('label_shrink_menu'),
autoHide: true,
placement: 'auto-end',
popperClass: ['tainacan-tooltip', 'tooltip', 'tainacan-repository-tooltip']
}"
class="icon">
<i
:class="{ 'tainacan-icon-arrowleft' : !isMenuCompressed, 'tainacan-icon-arrowright' : isMenuCompressed }"
class="tainacan-icon tainacan-icon-1-25em" />
</span>
</button>
<tainacan-header v-if="!$adminOptions.hideTainacanHeader" />
<tainacan-repository-subheader
v-if="!$adminOptions.hideRepositorySubheader"
:is-repository-level="isRepositoryLevel"
:is-menu-compressed="isMenuCompressed" />
<div
id="repository-container"
class="column is-main-content"
:style="$adminOptions.hidePrimaryMenu ? '--tainacan-sidebar-width: 0px' : ''">
<router-view />
</div>
<template v-if="hasPermalinksStructure">
<template v-if="activeRoute == 'HomePage'">
<tainacan-header v-if="!$adminOptions.hideTainacanHeader" />
<router-view />
</template>
<template v-else>
<primary-menu
v-if="!$adminOptions.hidePrimaryMenu"
:active-route="activeRoute"
:is-menu-compressed="isMenuCompressed" />
<button
v-if="!$adminOptions.hidePrimaryMenu && !$adminOptions.hidePrimaryMenuCompressButton"
id="menu-compress-button"
class="is-hidden-mobile"
:style="{ top: menuCompressButtonTop }"
:aria-label="$i18n.get('label_shrink_menu')"
@click="isMenuCompressed = !isMenuCompressed">
<span
v-tooltip="{
content: $i18n.get('label_shrink_menu'),
autoHide: true,
placement: 'auto-end',
popperClass: ['tainacan-tooltip', 'tooltip', 'tainacan-repository-tooltip']
}"
class="icon">
<i
:class="{ 'tainacan-icon-arrowleft' : !isMenuCompressed, 'tainacan-icon-arrowright' : isMenuCompressed }"
class="tainacan-icon tainacan-icon-1-25em" />
</span>
</button>
<tainacan-header v-if="!$adminOptions.hideTainacanHeader" />
<tainacan-repository-subheader
v-if="!$adminOptions.hideRepositorySubheader"
:is-repository-level="isRepositoryLevel"
:is-menu-compressed="isMenuCompressed" />
<div
id="repository-container"
class="column is-main-content"
:style="$adminOptions.hidePrimaryMenu ? '--tainacan-sidebar-width: 0px' : ''">
<router-view />
</div>
</template>
</template>
</div>
</template>
@ -70,7 +72,8 @@
return {
isMenuCompressed: false,
isRepositoryLevel : true,
activeRoute: '/collections'
activeRoute: '/collections',
hasPermalinksStructure: false
}
},
computed: {
@ -109,20 +112,46 @@
}
},
created() {
this.$statusHelper.loadStatuses();
this.$userPrefs.init();
this.isMenuCompressed = (this.$route.params.collectionId != undefined);
this.activeRoute = this.$route.name;
this.isRepositoryLevel = this.$route.params.collectionId == undefined;
wp.hooks.doAction('tainacan_navigation_path_updated', this.$route);
if (jQuery && jQuery( document ))
jQuery( document ).ajaxError(this.onHeartBitError);
this.hasPermalinksStructure = tainacan_plugin.has_permalinks_structure;
if ( this.hasPermalinksStructure ) {
this.$statusHelper.loadStatuses();
this.$userPrefs.init();
this.isMenuCompressed = (this.$route.params.collectionId != undefined);
this.activeRoute = this.$route.name;
this.isRepositoryLevel = this.$route.params.collectionId == undefined;
if (jQuery && jQuery( document )) {
jQuery( document ).ajaxError(this.onHeartBitError);
}
} else {
this.onPermalinksError();
}
},
methods: {
onPermalinksError() {
this.$buefy.modal.open({
component: CustomDialog,
props: {
title: this.$i18n.get('error_permalinks_label'),
message: this.$i18n.getWithVariables('error_permalinks_detail', [ '<a href="' + tainacan_plugin.admin_url + 'options-permalink.php">', '</a>' ]),
hideCancel: true,
confirmText: this.$i18n.get('label_go_to_permalinks'),
onConfirm: () => {
window.location.href = tainacan_plugin.admin_url + 'options-permalink.php';
}
},
ariaRole: 'alertdialog',
ariaModal: true,
customClass: 'tainacan-modal',
canCancel: false,
});
},
onHeartBitError(event, jqxhr, settings) {
if (settings && settings.url == '/wp-admin/admin-ajax.php') {
if (settings && settings.url == tainacan_plugin.admin_url + 'admin-ajax.php') {
this.$buefy.snackbar.open({
message: this.$i18n.get('error_connectivity'),
type: 'is-danger',

View File

@ -51,7 +51,7 @@
type="submit"
class="button is-success"
@click="onConfirm(); $emit('close');">
{{ $i18n.get('continue') }}
{{ confirmText ? confirmText : $i18n.get('continue') }}
</button>
</footer>
</div>
@ -66,6 +66,10 @@
title: String,
message: String,
icon: String,
confirmText: {
type: String,
default: ''
},
onConfirm: {
type: Function,
default: () => {}

View File

@ -179,7 +179,8 @@ abstract class Pages {
'tainacan_enable_relationship_metaquery' => (
defined('TAINACAN_ENABLE_RELATIONSHIP_METAQUERY') &&
true === TAINACAN_ENABLE_RELATIONSHIP_METAQUERY
)
),
'has_permalinks_structure' => get_option('permalink_structure') !== ''
];
$maps = [

View File

@ -709,7 +709,8 @@ return apply_filters( 'tainacan-i18n', [
'label_item_submission_options' => __( 'Item submission options', 'tainacan' ),
'label_metadata_related_features' => __( 'Metadata related features', 'tainacan' ),
'label_preview' => __( 'Preview', 'tainacan' ),
'label_go_to_permalinks' => __( 'Go to permalinks', 'tainacan' ),
// Instructions. More complex sentences to guide user and placeholders
'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ),
'instruction_delete_selected_items' => __( 'Delete selected items', 'tainacan' ),
@ -1118,6 +1119,7 @@ return apply_filters( 'tainacan-i18n', [
/* Errors displayed on the interface bottom notifications */
'error_connectivity_label' => __('Connectivity issue', 'tainacan'),
'error_connectivity' => __('It is possible that you are disconnected or the server is not working properly.', 'tainacan'),
'error_permalinks_label' => __('Permalinks issue', 'tainacan'),
'error_400' => __('Some request went wrong due to invalid syntax.', 'tainacan'),
'error_401' => __('You must authenticate to access this information. Try logging in again on the WordPress Admin panel.', 'tainacan'),
'error_403' => __('It seems that you are not allowed to access this content.', 'tainacan'),
@ -1130,6 +1132,7 @@ return apply_filters( 'tainacan-i18n', [
'error_511' => __('You must authenticate to get access this information. Try logging in again on the WordPress Admin panel.', 'tainacan'),
'error_other' => __('Something went wrong here. You may want to try again or contact the Administrator.', 'tainacan'),
'error_connectivity_detail' => __('The WordPress Heartbit API sends requests periodically to the server to update some information. The latest request failed for some reason. It can be the case of a lost connection or bad communication between the browser and the server.', 'tainacan'),
'error_permalinks_detail' => __( 'Tainacan requires your Permalink settings to be configured. Please visit %sPermalink settings%s and define it to an option such as "postname".', 'tainacan' ),
'error_400_detail' => __('The server could not understand the request due to invalid syntax. This is possibly an issue with Tainacan and should be reported to its developers.', 'tainacan'),
'error_401_detail' => __('You must authenticate to get access this information. Even if you have access to the Tainacan admin panel, it may be the case that your session cookies were lost. Try reloading the page or logging again on the WordPress Admin panel.', 'tainacan'),
'error_403_detail' => __('It seems that you are not allowed to access this content. Your user might have a role with insufficient capabilities. If that is not the case, check if you are correctly logged in on the WordPress Admin panel.', 'tainacan'),