App folder structure under src
:
assets
- images and icons storagecommon
- available mixins, http client, main menu, Vue with Vuetify and themedirectives
- custom directivesfilters
- custom filtersfragments
- all app fragments used by pagesi18n
- internationalization resourcesmodels
- models used to deal transport ors response data and deals with app state and transitionspages
- app pages (currently only themaps
page is available)resources
- support files like the loader lib, definitions and options used to process requests and responsesrouter
- router component based on vue-router componentsstore
- app store definitionssupport
- support utilities, like geo-utils, ors-api-runner, routes-resolver and app modes
This is a Single Page Application (SPA). This means that the client app is loaded in the browser and defines which components and pages are processed based on the browser URL. The app watches every change in the browser URL and updates its state based on that. These URL changes don't trigger a request to the back-end directly, but the components loaded/updated will decide which requests must be run to load the required data. Meaning, that the front-end (this app) is decoupled from the back-ends (ORS API and ORS website)
The app load cycle follows these steps:
- Execute the
main.js
file and add global extensions, mixins components and external libs. The filemain.js
also includes the main files of the router, vuex-store and i18n-translations, which will internally load all.router.js
,.store.js
and.i18n.js
files from sub-folders. main.js
will run a request to get necessary data from a service and then create a Vue.js app instance and load theApp.vue
. At this pointAppHooks
is set up and attached to the main Vue.js instance and then theappLoaded
hook is called.App.vue
includes all basic navigation components, like menu, sidebar, footer etc.- After loading all routes (including the ones in the
pages
sub folder) the page with the/
route (Maps.vue
) will also be rendered in the<router-view></router-view>
slot inApp.vue
component.
Data flow, state and requests to services, in a simplified view, happens as follows:
- The app is loaded
- the API data are fetched from ORS website service and if
appConfig.appMenu.useORSMenu
is true, the menu items are loaded insrc/main.js
usingsrc/app-loader.js
. - the app
mode
is defined based on the matching URL in themaps.route.js
- the
maps
page, uses the app mode utility to define the app state using the currentmode
. This utility will also populate the values of theors-map-filters
based on the URL and build theAppRouteData
(in src/models/app-route-data.js). - based on the app mode/state certain components are activated/displayed
- Every component, once activated, may use the data in
src/config/ors-map-filters
to render its elements and may run requests to the ORS api using thesrc/support/ors-api-runner
. Once the request succeed, the response data will be used to fill theMapViewData
object. - Once an input is changed the app goes to a new URL and this makes the flow restart at the step 2.
- If a component changes the
MapViewData
model, it emits an event to themaps
page, that passes the currentMapViewData
object to theMapView
component. - Interactions via
MapView
may result in events sent back tomaps
page, that may notify other child components, that in their turn may change the URL and trigger the step 2 again. - Several app hooks are called during the app flow, and it is possible to listen to these hooks and run custom code
to modify some app behavior.
The available hooks are listed in
src/config-examples/hooks-example.js
and must be coded insrc/config/hooks.js
.
- the API data are fetched from ORS website service and if
This app uses feature by folder components and predefined folders where the business code should be placed in. Example of this design usage:
Page:
- my-page-name (folder)
- MyPageName.vue (main VueJS component file)
- my-page-name.css (styles for the page, included by the MyPageName.vue component)
- my-page-name
.store.js
(Vuex store module for the page, included by the store/store.js loader) - my-page-name
.route.js
(route to reach this page, included by the router/index loader) - i18n (folder)
- my-page-name
.i18n.en.js
(in this example containing the EN resources for the page)
- my-page-name
Component:
-
my-fragment-name (folder under
src/fragments/
)- MyFragmentName.vue (main VueJS component file)
- my-fragment-name.css (styles for the page, included by the MyFragmentName.vue component)
- my-fragment-name
.store.js
(Vuex store module for the fragment, included by the store/store.js loader) - i18n (folder)
- my-fragment-name
.i18n.en.js
(in this example containing the EN resources for the component)
- my-fragment-name
The app will automatically load:
- all the locale resources in i18n folder ending with
.i18n.*.js
where*
is the locale - the defined routes in files ending with
.routes.js
- the store definitions in files ending with
.store.js
All the Vue.js components created (including the fragments) will have, by default, the following methods/accessors defined in the main vue instance app:
-
showMessage (msg, theme, options)
- shows a message using the toaster with specified theme and options -
showError (msg, options)
- shows an error message using the toaster with the specified options -
showWarning (msg, options)
- shows a warning message using the toaster with the specified options -
showInfo (msg, options)
- shows an info message using the toaster with the specified options -
showSuccess (msg, options)
- shows a success message using the toaster with the specified options -
confirmDialog (title, text, options)
- shows a confirm-dialog with the specified title, text and options and returns a promise. If the user clicksyes
, the promise will be resolved, if s/he clicks onno
, the promise will be rejected. -
$store
- accessor to app vuex-store
maps
- the page where the user can search places, routes and create isochrones.
The menu displayed in the header and in the sidebar (low resolution and mobile devices) is loaded from the ORS website back-end and adjusted to be shown according the resolution.
The menu items are fetched on the app load (src/app-loader.js
).
It dispatches the store fetchMainMenu
and @/common/main-menu.js
retrieves the menu that uses
@/support/menu-manager.js
and @/support/model-service.js
.
Once the items from the back-end are loaded, MenuManager
adds or removes custom items and defines icons for sidebar
items.
The items displayed on the menu can be changed by running custom code on the loadMenuItems
and/or the
modifyMenu
hooks. Check the /src/config-example/hooks-example.js
to see more details.