diff --git a/src/views/class-tainacan-admin.php b/src/views/class-tainacan-admin.php index e8467eb7c..65afcc8ca 100644 --- a/src/views/class-tainacan-admin.php +++ b/src/views/class-tainacan-admin.php @@ -58,6 +58,15 @@ class Admin { array( &$this, 'roles_page' ) ); + $reports_page_suffix = add_submenu_page( + $this->menu_slug, + __('Reports', 'tainacan'), + __('Reports', 'tainacan'), + 'read', + 'tainacan_reports', + array( &$this, 'reports_page' ) + ); + add_submenu_page( $this->menu_slug, __('Item Submission', 'tainacan'), @@ -69,6 +78,7 @@ class Admin { 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' ) ); } function load_admin_page() { @@ -82,6 +92,11 @@ class Admin { add_action( 'admin_enqueue_scripts', array( &$this, 'add_roles_js' ), 90 ); } + function load_reports_page() { + add_action( 'admin_enqueue_scripts', array( &$this, 'add_reports_css' ), 90 ); + add_action( 'admin_enqueue_scripts', array( &$this, 'add_reports_js' ), 90 ); + } + function login_styles_reset( $style ) { if ( strpos( $style, 'wp-admin-css' ) !== false ) { $style = null; @@ -130,6 +145,33 @@ class Admin { echo "
"; } + function add_reports_css() { + global $TAINACAN_BASE_URL; + + wp_enqueue_style( 'tainacan-reports-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-reports.css', [], TAINACAN_VERSION ); + } + + function add_reports_js() { + + global $TAINACAN_BASE_URL; + + wp_enqueue_script( 'tainacan-reports', $TAINACAN_BASE_URL . '/assets/js/reports.js', ['underscore', 'wp-i18n'], TAINACAN_VERSION, true ); + wp_set_script_translations('tainacan-reports', 'tainacan'); + + $settings = $this->get_admin_js_localization_params(); + wp_localize_script( 'tainacan-reports', 'tainacan_plugin', $settings ); + wp_enqueue_script('underscore'); + wp_enqueue_script('wp-i18n'); + + do_action('tainacan-enqueue-reports-scripts'); + } + + function reports_page() { + global $TAINACAN_BASE_URL; + // TODO move it to a separate file and start the Vue project + echo "
"; + } + function add_admin_css() { global $TAINACAN_BASE_URL; diff --git a/src/views/reports/js/reports-main.js b/src/views/reports/js/reports-main.js new file mode 100644 index 000000000..bc6f626b9 --- /dev/null +++ b/src/views/reports/js/reports-main.js @@ -0,0 +1,31 @@ +import Vue from 'vue'; +import store from '../../admin/js/store/store'; +import router from './reports-router'; +import VTooltip from 'v-tooltip'; +import { Snackbar, Modal } from 'buefy'; + +// Vue Dev Tools! +Vue.config.devtools = process && process.env && process.env.NODE_ENV === 'development'; + +import { I18NPlugin } from './wp-i18n-plugin'; + +import ReportsPage from '../reports.vue'; + +Vue.use(I18NPlugin); +Vue.use(VTooltip); +Vue.use(Snackbar); +Vue.use(Modal); + +// Changing title of pages +router.beforeEach((to, from, next) => { + document.title = to.meta.title; + if (next() != undefined) + next(); +}); + +new Vue({ + el: '#tainacan-reports-app', + store, + router, + render: h => h(ReportsPage) +}); \ No newline at end of file diff --git a/src/views/reports/js/reports-router.js b/src/views/reports/js/reports-router.js new file mode 100644 index 000000000..5de88c64d --- /dev/null +++ b/src/views/reports/js/reports-router.js @@ -0,0 +1,29 @@ +import Vue from 'vue'; +import VueRouter from 'vue-router' +import qs from 'qs'; + +import ReportsList from '../pages/reports-list.vue'; + +const { __ } = wp.i18n; + +Vue.use(VueRouter); + +const routes = [ + { path: '/', redirect:'/reports' }, + { path: '/reports', name: 'ReportsList', component: ReportsList, meta: { title: __('Tainacan Reports') } }, + + { path: '*', redirect: '/'} +]; + +export default new VueRouter ({ + routes, + // set custom query resolver + parseQuery(query) { + return qs.parse(query); + }, + stringifyQuery(query) { + let result = qs.stringify(query); + + return result ? ('?' + result) : ''; + } +}); \ No newline at end of file diff --git a/src/views/reports/js/wp-i18n-plugin.js b/src/views/reports/js/wp-i18n-plugin.js new file mode 100644 index 000000000..e6e6c79cc --- /dev/null +++ b/src/views/reports/js/wp-i18n-plugin.js @@ -0,0 +1,29 @@ + +const { __, _x, _n, _nx } = wp.i18n; + +/** + I18N PLUGIN - Allows access to Wordpress translation functions. + __( '__', 'my-domain' ); + _x( '_x', '_x_context', 'my-domain' ); + _n( '_n_single', '_n_plural', number, 'my-domain' ); + _nx( '_nx_single', '_nx_plural', number, '_nx_context', 'my-domain' ); +**/ +export const I18NPlugin = {}; +I18NPlugin.install = function (Vue, options = {}) { + + Vue.prototype.$i18n = { + get(key) { + return __(key, 'tainacan'); + }, + getWithContext(key, keyContext) { + return _x(key, keyContext, 'tainacan'); + }, + getWithNumber(keySingle, keyPlural, number) { + return _n(keySingle, keyPlural, number, 'tainacan'); + }, + getWithNumberAndContext(keySingle, keyPlural, number, keyContext) { + return _nx(keySingle, keyPlural, number, keyContext, 'tainacan'); + }, + } + +}; \ No newline at end of file diff --git a/src/views/reports/pages/reports-list.vue b/src/views/reports/pages/reports-list.vue new file mode 100644 index 000000000..9e6518bce --- /dev/null +++ b/src/views/reports/pages/reports-list.vue @@ -0,0 +1,20 @@ + + + + + diff --git a/src/views/reports/reports.vue b/src/views/reports/reports.vue new file mode 100644 index 000000000..3ea847b47 --- /dev/null +++ b/src/views/reports/reports.vue @@ -0,0 +1,118 @@ + + + + + \ No newline at end of file diff --git a/src/views/reports/tainacan-reports.scss b/src/views/reports/tainacan-reports.scss new file mode 100644 index 000000000..b1d22df4b --- /dev/null +++ b/src/views/reports/tainacan-reports.scss @@ -0,0 +1,3 @@ +#tainacan-reports-app { + +} \ No newline at end of file diff --git a/webpack.common.js b/webpack.common.js index d9f4c3091..cb9b14217 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -6,6 +6,7 @@ module.exports = { theme_search: './src/views/theme-search/js/theme-main.js', item_submission: './src/views/item-submission/js/item-submission-main.js', roles: './src/views/roles/js/roles-main.js', + reports: './src/views/reports/js/reports-main.js', block_terms_list: './src/views/gutenberg-blocks/tainacan-terms/terms-list/index.js',