Changes between Version 1 and Version 2 of DeveloperGuidelines/EdenMobile/Routing


Ignore:
Timestamp:
03/30/17 11:37:03 (8 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/EdenMobile/Routing

    v1 v2  
    11= EdenMobile UI Routing and Controllers =
    22
    3  - ''tbw''
     3EdenMobile is a single-page application (SPA), i.e. it only has a single page {{{www/index.html}}} which is loaded when the app starts, and has parts of its contents replaced as the user interacts with it.
     4
     5Instead of "pages" to display different application views, EdenMobile implements application '''states'''. Each state has its own "view template" that defines the inner HTML of the front-page, and a controller that supplies data and processing methods for the UI widgets.
     6
     7== Routing ==
     8
     9The routing of user actions to the different app states is provided by the [https://github.com/angular-ui/ui-router/wiki AngularJS UI Router].
     10
     11States have names to reference them, and state references can additionally contain parameters to pass to the state controller.
     12
     13States can be entered either by using {{{$state.go()}}} (=similar to Sahana Eden's {{{redirect()}}}, just without leaving the page):
     14{{{#!js
     15$state.go('data.update', {resourceName: resourceName, recordID: recordID}, {location: 'replace', reload: true});
     16}}}
     17
     18...or by HTML links using fragment identifiers to encode the state reference:
     19{{{#!xml
     20<a href="#/data/update/{{resourceName}}/{{recordID}}">Edit Record</a>
     21}}}
     22
     23Either variant would be resolved against this entry in {{{www/config/routing.py}}}:
     24{{{#!js
     25.state('data.update', {
     26    url: '/{resourceName}/{recordID:int}',
     27    views: {
     28        'data': {
     29            templateUrl: 'views/data/update.html',
     30            controller: "EMDataUpdate"
     31        }
     32    }
     33})
     34}}}
     35
     36...and let the UI router:
     37- replace the contents of the {{{<ion-nav-view>}}} directive on the {{{www/index.html}}} front-page with {{{www/views/data/update.html}}} (executing any directives)
     38- invoke the {{{EMDataUpdate}}} controller (defined in {{{wwww/controllers/update.js}}})
     39- pass the {{{resourceName}}} and {{{recordID}}} parameters to the {{{$stateParams}}}, from where the controller can access them
     40
     41== View and Controller ==
     42
     43The role of controllers and views is equivalent to controllers/views in the Sahana Eden web application.
     44
     45The view template is rendered once when the state is entered the first time (unless reloading is enforced in $state.go), and the state controller executed every time when the state is entered.
     46
     47State controllers live in the www/controllers folder, and view templates in www/views.