From 0c56b19b6af455e5f865dbb57f081f6f3b860ca8 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Thu, 30 Jun 2022 12:18:12 -0300 Subject: [PATCH] Creates tainacan_mobile_app page and emits events to mobile app. (https://github.com/tainacan/tainacan-mobile/issues/17) --- .eslintrc.js | 3 ++- .../components/edition/item-edition-form.vue | 15 ++++++++++++--- src/views/class-tainacan-admin.php | 15 +++++++++++++++ src/views/mobile-app/admin-page.php | 5 +++++ .../mobile-app/class-tainacan-mobile-app.php | 13 +++++++++++++ 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/views/mobile-app/admin-page.php create mode 100644 src/views/mobile-app/class-tainacan-mobile-app.php diff --git a/.eslintrc.js b/.eslintrc.js index 7c719f95e..202a3f642 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -36,6 +36,7 @@ module.exports = { 'jQuery': true, 'tainacan_extra_components': true, 'tainacan_extra_plugins': true, - 'grecaptcha': true + 'grecaptcha': true, + 'webkit': true } } \ No newline at end of file diff --git a/src/views/admin/components/edition/item-edition-form.vue b/src/views/admin/components/edition/item-edition-form.vue index b028fa340..1f82e7559 100644 --- a/src/views/admin/components/edition/item-edition-form.vue +++ b/src/views/admin/components/edition/item-edition-form.vue @@ -1320,7 +1320,7 @@ export default { this.isLoading = false; - if (!this.$adminOptions.itemEditionMode) { + if (!this.$adminOptions.itemEditionMode && !this.$adminOptions.mobileAppMode) { if (!this.isOnSequenceEdit) { if (this.form.status != 'trash') { @@ -1345,6 +1345,15 @@ export default { item: this.$adminOptions.itemEditionMode ? this.item : null }, tainacan_plugin.admin_url); + + // In Mobile app, we send a message to inform updates + if ( + this.$adminOptions.mobileAppMode && + webkit && + webkit.messageHandlers && + webkit.messageHandlers.cordova_iab + ) + webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify({ 'type': 'item_updated', 'item': this.item })); }) .catch((errors) => { @@ -1366,14 +1375,14 @@ export default { }); }, onDiscard() { - if (!this.$adminOptions.itemEditionMode) + if (!this.$adminOptions.itemEditionMode && !this.$adminOptions.mobileAppMode) this.$router.go(-1); parent.postMessage({ type: 'itemEditionMessage', item: this.$adminOptions.itemEditionMode ? false : null }, - tainacan_plugin.admin_url); + tainacan_plugin.admin_url); }, createNewItem() { diff --git a/src/views/class-tainacan-admin.php b/src/views/class-tainacan-admin.php index 15d20d42d..3b269696c 100644 --- a/src/views/class-tainacan-admin.php +++ b/src/views/class-tainacan-admin.php @@ -76,6 +76,15 @@ class Admin { array( &$this, 'item_submission' ) ); + add_submenu_page( + null, // Mobile app page is not listed in the menu + __('Mobile App', 'tainacan'), + __('Mobile App', 'tainacan'), + 'manage_tainacan', + 'tainacan_mobile_app', + array( &$this, 'mobile_app' ) + ); + add_action( 'load-' . $page_suffix, array( &$this, 'load_admin_page' ) ); add_action( 'load-' . $roles_page_suffix, array( &$this, 'load_roles_page' ) ); add_action( 'load-' . $reports_page_suffix, array( &$this, 'load_reports_page' ) ); @@ -480,5 +489,11 @@ class Admin { $submission->admin_page(); } + public function mobile_app() { + require_once('mobile-app/class-tainacan-mobile-app.php'); + $Mobile_app = new Mobile_App(); + $Mobile_app->admin_page(); + } + } diff --git a/src/views/mobile-app/admin-page.php b/src/views/mobile-app/admin-page.php new file mode 100644 index 000000000..143032c09 --- /dev/null +++ b/src/views/mobile-app/admin-page.php @@ -0,0 +1,5 @@ +
+

+ +

+
\ No newline at end of file diff --git a/src/views/mobile-app/class-tainacan-mobile-app.php b/src/views/mobile-app/class-tainacan-mobile-app.php new file mode 100644 index 000000000..8e971fc55 --- /dev/null +++ b/src/views/mobile-app/class-tainacan-mobile-app.php @@ -0,0 +1,13 @@ +