FlaresLinkBuilder service reference - alansfyeung/flares GitHub Wiki

FlaresLinkBuilder (FLB) will construct URLs that link to pages and/or resources, and provides a universal approach for getting to Laravel pages containing Angular ngRoute components.

Injecting

var flaresApp = angular.module('someModule', ['flaresBase']);
var flaresController = flaresApp.controller('someController', ['flaresLinkBuilder', ... , function(flaresLinkBuilder, ...){ ... }])

Note: no preceding $ sign when injecting flaresLinkBuilder into controller

Factorying

flaresLinkBuilder( defined-pagetype-name )

where defined-pagetype-name is [ 'member' | 'activity' | 'resource' ]

resource will set the FLB root to the Assets folder. It is useful for getting misc images, css and js.

member will help when retrieving pages for member operations

activity will help when retrieving pages for activity operations

Using FlaresLinkBuilder

Whilst factorying, FLB assigns both a singular and plural name to the object, as well as any "special" properties (for example, member operations contains a special "search" page). The singular and plural versions will be used internally by child methods that are fluently called later on.

FLB can be fluently chained to directly return a string (the URL), but for the purpose of demo we'll assign it to the flb variable.

var flb = flaresLinkBuilder('member');

By convention, pages to create new resources are pluralised. This is included in the FLB prototype:

flb.new().getLink();  // would return 'http://flares.206acu.org.au/members/new'

Pages to retrieve specifically ID'ed items are singularised. This is also included in the FLB prototype:

flb.retrieve().getLink();  // would return 'http://flares.206acu.org.au/member/'

To miscellaneously add URL path components, feed it an array of the path parts:

flb.addUrl(['path', 'to', 'something']).getLink();  // would return 'http://flares.206acu.org.au/path/to/something'

Generally getting just the page is useless, and we need to add some hash frags for AngularJS to parse as the ngRoute. Feed it an array of hash frag parts:

flb.retrieve().addFragment(['20611206', 'view', 'details']).getLink();  // would return 'http://flares.206acu.org.au/member#!20611206/view/details'

You can use any shortcut methods that were defined as part of the factory init. For example, member has a specially defined method for getting the search page:

flb.search().getLink();  // would return 'http://flares.206acu.org.au/members/search'