Remove attached profile on profile removal. Fix #38.

This commit is contained in:
FelisCatus 2014-10-04 21:33:21 +08:00
parent 0a6a2d018b
commit 0ded79d403
3 changed files with 30 additions and 8 deletions

View File

@ -10,6 +10,15 @@ profileColorPalette = (colors.splice(0, 3) while colors.length)
angular.module('omega').constant('profileColors', profileColors) angular.module('omega').constant('profileColors', profileColors)
angular.module('omega').constant('profileColorPalette', profileColorPalette) angular.module('omega').constant('profileColorPalette', profileColorPalette)
attachedPrefix = '__ruleListOf_'
angular.module('omega').constant 'getAttachedName', (name) ->
attachedPrefix + name
angular.module('omega').constant 'getParentName', (name) ->
if name.indexOf(attachedPrefix) == 0
name.substr(attachedPrefix.length)
else
undefined
angular.module('omega').config ($stateProvider, $urlRouterProvider, angular.module('omega').config ($stateProvider, $urlRouterProvider,
$httpProvider) -> $httpProvider) ->
$urlRouterProvider.otherwise '/ui' $urlRouterProvider.otherwise '/ui'

View File

@ -1,5 +1,6 @@
angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams, angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams,
$location, $rootScope, $modal, $state, profileColorPalette) -> $location, $rootScope, $state, $modal, profileColorPalette, getAttachedName,
getParentName) ->
name = $stateParams.name name = $stateParams.name
profileTemplates = profileTemplates =
'FixedProfile': 'profile_fixed.html' 'FixedProfile': 'profile_fixed.html'
@ -19,24 +20,36 @@ angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams,
$scope.deleteProfile = -> $scope.deleteProfile = ->
profileName = $scope.profile.name profileName = $scope.profile.name
refs = OmegaPac.Profiles.referencedBySet(profileName, $rootScope.options) refs = OmegaPac.Profiles.referencedBySet(profileName, $rootScope.options)
refs = Object.keys(refs)
scope = $rootScope.$new('isolate') scope = $rootScope.$new('isolate')
scope.profile = $scope.profile scope.profile = $scope.profile
scope.profileIcons = $scope.profileIcons scope.profileIcons = $scope.profileIcons
if refs.length > 0 if Object.keys(refs).length > 0
scope.refs = refs.map (p) -> OmegaPac.Profiles.byKey(p, refSet = {}
$rootScope.options) for own key, pname of refs
parent = getParentName(pname)
if parent
key = OmegaPac.Profiles.nameAsKey(parent)
pname = parent
refSet[key] = pname
refProfiles = []
for own key of refSet
refProfiles.push(OmegaPac.Profiles.byKey(key, $rootScope.options))
scope.refs = refProfiles
$modal.open( $modal.open(
templateUrl: 'partials/cannot_delete_profile.html' templateUrl: 'partials/cannot_delete_profile.html'
scope: scope scope: scope
) )
return
else else
$modal.open( $modal.open(
templateUrl: 'partials/delete_profile.html' templateUrl: 'partials/delete_profile.html'
scope: scope scope: scope
).result.then -> ).result.then ->
attachedName = getAttachedName(profileName)
delete $rootScope.options[OmegaPac.Profiles.nameAsKey(attachedName)]
delete $rootScope.options[OmegaPac.Profiles.nameAsKey(profileName)] delete $rootScope.options[OmegaPac.Profiles.nameAsKey(profileName)]
if $rootScope.options['-startupProfileName'] == profileName if $rootScope.options['-startupProfileName'] == profileName
$rootScope.options['-startupProfileName'] = "" $rootScope.options['-startupProfileName'] = ""

View File

@ -1,5 +1,5 @@
angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $modal, angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $modal,
profileIcons) -> profileIcons, getAttachedName) ->
$scope.conditionI18n = $scope.conditionI18n =
'HostWildcardCondition': 'condition_hostWildcard' 'HostWildcardCondition': 'condition_hostWildcard'
@ -69,8 +69,8 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $modal,
$scope.ruleListFormats = OmegaPac.Profiles.ruleListFormats $scope.ruleListFormats = OmegaPac.Profiles.ruleListFormats
$scope.$watch 'profile.name', (name) -> $scope.$watch 'profile.name', (name) ->
$scope.attachedName = '__ruleListOf_' + name $scope.attachedName = getAttachedName(name)
$scope.attachedKey = OmegaPac.Profiles.nameAsKey('__ruleListOf_' + name) $scope.attachedKey = OmegaPac.Profiles.nameAsKey($scope.attachedName)
$scope.$watch 'options[attachedKey]', (attached) -> $scope.$watch 'options[attachedKey]', (attached) ->
$scope.attached = attached $scope.attached = attached