Skip to content

Commit

Permalink
Update dataService documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tothandras committed Aug 22, 2015
1 parent 9bea1c3 commit dbc185e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
46 changes: 26 additions & 20 deletions master/docs/developer/www.rst
Expand Up @@ -634,7 +634,7 @@ It uses the following libraries:
The DataService is available as a standalone AngularJS module.
Installation via bower:
.. code-block:: none
.. code-block:: shell
bower install buildbot-data --save
Expand All @@ -646,39 +646,43 @@ Inject the ``bbData`` module to your application:
Methods:
* ``.get(endpoint, [id], [query])``: returns a promise<Collection>, when the promise is resolved, the Collection contains all the requested data
``.getXs([id], [query])``: returns a promise<Collection>, when the promise is resolved, the Collection contains all the requested data
* call .getArray() on the returned promise to get the updating Collection before it's filled with the initial data
* it's highly advised to use these instead of the lower level ``.get('string')`` function
* ``Xs`` can be the following: ``Builds``, ``Builders``, ``Buildrequests``, ``Buildsets``, ``Buildslaves``, ``Changes``, ``Changesources``, ``Forceschedulers``, ``Masters``, ``Schedulers``, ``Sourcestamps``
* call ``.getArray()`` on the returned promise to get the Collection before it's filled with the initial data
.. code-block:: coffeescript
# assign builds to $scope.builds once the Collection is filled
dataService.get('builds', builderid: 1).then (builds) ->
dataService.getBuilds(builderid: 1).then (builds) ->
$scope.builds = builds
# load steps for every build
builds.forEach (b) -> b.loadSteps()
# assign builds to $scope.builds before the Collection is filled using the .getArray() function
$scope.builds = dataService.get('builds', builderid: 1).getArray()
$scope.builds = dataService.getBuilds(builderid: 1).getArray()
* ``.getXXX([id], [query])``: returns a promise<Collection>, when the promise is resolved, the Collection contains all the requested data
``.get(endpoint, [id], [query])``: returns a promise<Collection>, when the promise is resolved, the Collection contains all the requested data
* it's higly advised to use these instead of the ``.get('string')`` function
* XXX can be the following: Builds, Builders, Buildrequests, Buildsets, Buildslaves, Changes, Changesources, Forceschedulers, Masters, Schedulers, Sourcestamps
* call .getArray() on the returned promise to get the updating Collection before it's filled with the initial data
* call ``.getArray()`` on the returned promise to get the Collection before it's filled with the initial data
.. code-block:: coffeescript
# assign builds to $scope.builds once the Collection is filled
dataService.getBuilds(builderid: 1).then (builds) ->
builderid = 1
dataService.get("builders/#{builderid}/builds", limit: 1).then (builds) ->
$scope.builds = builds
# load steps for every build
builds.forEach (b) -> b.loadSteps()
# assign builds to $scope.builds before the Collection is filled using the .getArray() function
$scope.builds = dataService.getBuilds(builderid: 1).getArray()
$scope.builds = dataService.get('builds', builderid: 1).getArray()
* ``.open(scope)``: returns a DataAccessor, handles bindings, open a new accessor every time you need updating data in a controller
``.open(scope)``: returns a DataAccessor, handles bindings
* open a new accessor every time you need updating data in a controller
* it registers a $destroy event handling function on the scope, it automatically unsubscribes from updates that has been requested by the DataAccessor
.. code-block:: coffeescript
Expand All @@ -696,29 +700,29 @@ Methods:
# request new data, it updates automatically
@builders = opened.getBuilders(limit: 10, order: '-started_at').getArray()
* ``.control(url, method, [params])``: returns a promise, sends a JSON RPC2 POST request to the server
``.control(url, method, [params])``: returns a promise, sends a JSON RPC2 POST request to the server
.. code-block:: coffeescript
# open a new accessor every time you need updating data in a controller
dataService.control('Forceschedulers/force', 'force').then (response) ->
dataService.control('forceschedulers/force', 'force').then (response) ->
$log.debug(response)
, (reason) ->
$log.error(reason)
* ``.clearCache()``: clears the IndexedDB tables and reloads the current page
``.clearCache()``: clears the IndexedDB tables and reloads the current page
.. code-block:: coffeescript
class DemoController extends Controller
constructor: (@dataService) ->
onClick: -> @dataService.clearCache()
Methods on the Wrapper classes:
Methods on the object returned by the ``.getXs()`` methods:
* ``.getXXX([id], [query])``: returns a promise<Collection>, when the promise is resolved, the Collection contains all the requested data
``.getXs([id], [query])``: returns a promise<Collection>, when the promise is resolved, the Collection contains all the requested data
* same as dataService.getXXX, but with relative endpoint
* same as ``dataService.getXs``, but with relative endpoint
.. code-block:: coffeescript
Expand All @@ -731,7 +735,9 @@ Methods on the Wrapper classes:
# assign completed test to every build
b.complete_steps = steps.map (s) -> s.complete
* ``.loadXXX([id], [query])``: returns a promise<Collection>, the Collection contains all the requested data, it is also assigned to wrapperInstance.xxx
``.loadXs([id], [query])``: returns a promise<Collection>, the Collection contains all the requested data, which is also assigned to ``o.Xs``
* ``o.loadXs()`` is equivalent to ``o.getXs().then (xs) -> o.xs = xs``
.. code-block:: coffeescript
Expand All @@ -748,7 +754,7 @@ Methods on the Wrapper classes:
# builder has a builds field, and the builds have a steps field containing the corresponding data
$log.debug(builder)
* ``.control(method, params)``: returns a promise, sends a JSON RPC2 POST request to the server
``.control(method, params)``: returns a promise, sends a JSON RPC2 POST request to the server
RecentStorage
.............
Expand Down
Expand Up @@ -194,7 +194,7 @@ class IndexedDB extends Service
stores = {}
for name, s of specification
if angular.isArray(s.fields)
a = s.fields.map (e) -> e.split(':')[0]
a = s.fields[..]
i = a.indexOf(s.id)
if i > -1 then a[i] = "&#{a[i]}"
else a.unshift('++id')
Expand Down
Expand Up @@ -295,15 +295,15 @@ describe 'IndexedDB service', ->
test1:
id: 'id1'
fields: [
'id1:number'
'field1:string'
'field2:timestamp'
'id1'
'field1'
'field2'
]
test2:
id: null
fields: [
'fieldA:number'
'fieldB:string'
'fieldA'
'fieldB'
]

result = indexedDBService.processSpecification(specification)
Expand Down

0 comments on commit dbc185e

Please sign in to comment.