From ecb2afe5682e365dc0bfb2addafe505b4250b1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimund=20Schl=C3=BC=C3=9Fler?= Date: Thu, 1 Feb 2024 18:59:30 +0100 Subject: [PATCH] feat: use web history mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Raimund Schlüßler --- appinfo/routes.php | 29 ++++++++++++++++++++++++----- src/router.js | 12 ++++++++++-- src/store/collections.js | 4 ++-- src/store/settings.js | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 9bdbf8fd9..91e10703e 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -21,10 +21,29 @@ */ return [ 'routes' => [ - ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], - ['name' => 'collections#getCollections','url' => '/collections', 'verb' => 'GET'], - ['name' => 'collections#setVisibility', 'url' => '/collection/{collectionID}/visibility/{visibility}', 'verb' => 'POST'], - ['name' => 'settings#get', 'url' => '/settings', 'verb' => 'GET'], - ['name' => 'settings#set', 'url' => '/settings/{setting}', 'verb' => 'POST'], + ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], + ['name' => 'page#index', 'url' => '/calendars', 'verb' => 'GET', 'postfix' => 'view.calendars'], + ['name' => 'page#index', 'url' => '/calendars/', 'verb' => 'GET', 'postfix' => 'view.calendars./'], + [ + 'name' => 'page#index', + 'url' => '/calendars/{calendar}', + 'verb' => 'GET', + 'postfix' => 'view.calendars.calendar', + 'requirements' => array('calendar' => '.+') + ], + ['name' => 'page#index', 'url' => '/collections', 'verb' => 'GET', 'postfix' => 'view.collections'], + ['name' => 'page#index', 'url' => '/collections/', 'verb' => 'GET', 'postfix' => 'view.collections./'], + [ + 'name' => 'page#index', + 'url' => '/collections/{collection}', + 'verb' => 'GET', + 'postfix' => 'view.collections.collection', + 'requirements' => array('collection' => '.+') + ], + + ['name' => 'collections#getCollections','url' => '/api/v1/collections', 'verb' => 'GET'], + ['name' => 'collections#setVisibility', 'url' => '/api/v1/collection/{collectionID}/visibility/{visibility}', 'verb' => 'POST'], + ['name' => 'settings#get', 'url' => '/api/v1/settings', 'verb' => 'GET'], + ['name' => 'settings#set', 'url' => '/api/v1/settings/{setting}', 'verb' => 'POST'], ] ]; diff --git a/src/router.js b/src/router.js index 332d256c3..09788541e 100644 --- a/src/router.js +++ b/src/router.js @@ -25,8 +25,16 @@ import AppSidebar from './views/AppSidebar.vue' import Calendar from './views/AppContent/Calendar.vue' import Collections from './views/AppContent/Collections.vue' +import { getRootUrl, generateUrl } from '@nextcloud/router' + import { h } from 'vue' -import { createWebHashHistory, createRouter, RouterView } from 'vue-router' +import { createWebHistory, createRouter, RouterView } from 'vue-router' + +const webRootWithIndexPHP = getRootUrl() + '/index.php' +const doesURLContainIndexPHP = window.location.pathname.startsWith(webRootWithIndexPHP) +const base = generateUrl('apps/tasks', {}, { + noRewrite: doesURLContainIndexPHP, +}) const routes = [ { path: '/', redirect: getInitialRoute() }, @@ -81,7 +89,7 @@ const routes = [ ] const router = createRouter({ - history: createWebHashHistory(), + history: createWebHistory(base), routes, }) diff --git a/src/store/collections.js b/src/store/collections.js index 7230aab9e..c3c7f5f77 100644 --- a/src/store/collections.js +++ b/src/store/collections.js @@ -103,7 +103,7 @@ const actions = { */ loadCollections({ commit }) { return new Promise(function(resolve) { - Requests.get(generateUrl('apps/tasks/collections')) + Requests.get(generateUrl('apps/tasks/api/v1/collections')) .then(response => { commit('setCollections', { collections: response.data.data.collections, @@ -123,7 +123,7 @@ const actions = { setVisibility(context, collection) { context.commit('setVisibility', collection) return new Promise(function() { - Requests.post(generateUrl('apps/tasks/collection/{id}/visibility/{show}', collection), {}) + Requests.post(generateUrl('apps/tasks/api/v1/collection/{id}/visibility/{show}', collection), {}) }) }, } diff --git a/src/store/settings.js b/src/store/settings.js index c87f03d1d..d0698d9b2 100644 --- a/src/store/settings.js +++ b/src/store/settings.js @@ -118,7 +118,7 @@ const actions = { setSetting(context, payload) { context.commit('setSetting', payload) return new Promise(function() { - Requests.post(generateUrl('apps/tasks/settings/{type}', payload), { value: payload.value }) + Requests.post(generateUrl('apps/tasks/api/v1/settings/{type}', payload), { value: payload.value }) }) },