Skip to content

Commit

Permalink
Another attempt to fix the element does not exist (yet) problem.
Browse files Browse the repository at this point in the history
Upon 404, we still define the object, with everything undefined, and register to events

Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
  • Loading branch information
Pierre Tardy committed Oct 30, 2014
1 parent cfff761 commit 11ef301
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 10 additions & 7 deletions www/base/src/app/builders/build/build.controller.coffee
Expand Up @@ -5,6 +5,8 @@ class Build extends Controller

buildbotService.bindHierarchy($scope, $stateParams, ['builders', 'builds'])
.then ([builder, build]) ->
if not build.number? and buildnumber > 1
$state.go('build', builder:builderid, build:buildnumber - 1)
breadcrumb = [
caption: "Builders"
sref: "builders"
Expand All @@ -21,10 +23,14 @@ class Build extends Controller
sref: "build({build:#{buildnumber - 1}})"

glBreadcrumbService.setBreadcrumb(breadcrumb)
buildbotService.one('builders', builderid).one('builds', buildnumber + 1).bind($scope, dest_key:"nextbuild").then ->
breadcrumb.push
caption: ''
sref: "build({build:#{buildnumber + 1}})"
buildbotService.one('builders', builderid).one('builds', buildnumber + 1).bind($scope, dest_key:"nextbuild")

$scope.$watch 'nextbuild.number', (n, o) ->
if not o? and n?
breadcrumb.push
caption: ''
sref: "build({build:#{buildnumber + 1}})"
glBreadcrumbService.setBreadcrumb(breadcrumb)

buildbotService.one("buildslaves", build.buildslaveid).bind($scope)
buildbotService.one("buildrequests", build.buildrequestid)
Expand All @@ -35,6 +41,3 @@ class Build extends Controller
recentStorage.addBuild
link: "#/builders/#{$scope.builder.builderid}/build/#{$scope.build.number}"
caption: "#{$scope.builder.name} / #{$scope.build.number}"
, ->
if buildnumber > 1
$state.go('build', builder:builderid, build:buildnumber - 1)
17 changes: 14 additions & 3 deletions www/base/src/app/common/services/buildbot/buildbot.service.coffee
Expand Up @@ -79,7 +79,7 @@ class BuildbotService extends Factory
e[k] = v
return
if not _.isArray(l)
debugger
throw Error("Collection value is not an array!")
value["id"] = value[idkey]
value["_raw_data"] = angular.copy(value)
# restangularize the object before putting it in
Expand All @@ -106,9 +106,20 @@ class BuildbotService extends Factory
elem.on("*", onUpdate).then (unsub) ->
events.push(unsub)
return res
, (res) ->
, (res) -> # got error
elem.value = null
bound = false
if res.status == 404
# It does not exist yet. That might be the case later
# we still 'define' it will all attributes 'undefined'
# and register to update events
# this allows controllers to watch until the value is defined
elem.value = {}
elem.on("*", onUpdate).then (unsub) ->
events.push(unsub)
return elem.value
# if not 404, we say it is unbound, to maybe retry later, and reject the promise
else
bound = false
return $q.reject(res)
elem.value = p
return p
Expand Down

0 comments on commit 11ef301

Please sign in to comment.