Skip to content

Commit

Permalink
Add watcher on the calling scope in watchAndUpdateRevision. Fix #79.
Browse files Browse the repository at this point in the history
  • Loading branch information
FelisCatus committed Dec 20, 2014
1 parent a3df567 commit 1a68f4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 0 additions & 1 deletion omega-web/src/omega/controllers/master.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,

onOptionChange = (options, oldOptions) ->
return if options == oldOptions or not oldOptions?
plainOptions = angular.fromJson(angular.toJson(options))
$rootScope.optionsDirty = true
$rootScope.$watch 'options', onOptionChange, true

Expand Down
24 changes: 13 additions & 11 deletions omega-web/src/omega/controllers/profile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams,
break
$state.go('ui')

# The watcher should be applied on the calling scope.
# coffeelint: disable=missing_fat_arrows
$scope.watchAndUpdateRevision = (expression) ->
revisionChanged = false
onChange = (profile, oldProfile) ->
return profile if profile == oldProfile or not profile or not oldProfile
if revisionChanged and profile.revision != oldProfile.revision
revisionChanged = false
else
OmegaPac.Profiles.updateRevision(profile)
revisionChanged = true
this.$watch expression, onChange, true

unwatch = $scope.$watch (-> $scope.options?['+' + name]), (profile) ->
if not profile
if $scope.options
Expand All @@ -92,15 +105,4 @@ angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams,
$scope.profileTemplate = 'partials/' + templ
$scope.scriptable = true

$scope.watchAndUpdateRevision = (expression) ->
revisionChanged = false
onChange = (profile, oldProfile) ->
return profile if profile == oldProfile or not profile or not oldProfile
if revisionChanged and profile.revision != oldProfile.revision
revisionChanged = false
else
OmegaPac.Profiles.updateRevision(profile)
revisionChanged = true
$scope.$watch expression, onChange, true

$scope.watchAndUpdateRevision 'profile'

0 comments on commit 1a68f4c

Please sign in to comment.