Prefer dynamic virtual profile icons.

This commit is contained in:
FelisCatus 2014-10-27 22:42:23 +08:00
parent 054be60531
commit 79eb0b53fe
21 changed files with 88 additions and 94 deletions

View File

@ -299,11 +299,6 @@ module.exports = exports =
create: (profile) ->
profile.defaultProfileName ?= 'direct'
profile.rules ?= []
if profile.profileType == 'VirtualProfile' and not profile.virtualType?
target = exports.byName(profile.defaultProfileName, {})
if target
profile.virtualType = target.profileType
profile.color = target.color
directReferenceSet: (profile) ->
refs = {}
refs[exports.nameAsKey(profile.defaultProfileName)] =

View File

@ -289,8 +289,7 @@ class Options
profileType: p.profileType
color: p.color
builtin: if p.builtin then true
if p.virtualType
profiles[key].virtualType = p.virtualType
if p.profileType == 'VirtualProfile'
profiles[key].defaultProfileName = p.defaultProfileName
if not allReferenceSet?
allReferenceSet = OmegaPac.Profiles.allReferenceSet profile, @_options
@ -330,7 +329,8 @@ class Options
@_state.set({
'currentProfileName': @_currentProfileName
'isSystemProfile': @_isSystem
'currentProfileCanAddRule': profile.rules? and not profile.virtualType
'currentProfileCanAddRule':
profile.rules? and profile.profileType != 'VirtualProfile'
})
@_setAvailableProfiles()
@ -656,9 +656,6 @@ class Options
return Promise.reject new ProfileNotExistError(defaultProfileName)
profile.defaultProfileName = defaultProfileName
if profile.virtualType
profile.color = target.color
profile.virtualType = target.profileType
OmegaPac.Profiles.updateRevision(profile)
changes = {}
changes[OmegaPac.Profiles.nameAsKey(profile)] = profile

View File

@ -23,40 +23,55 @@ angular.module('omegaDecoration', []).value('profileIcons', {
-1
else
1
).directive('omegaProfileIcon', (profileIcons) ->
).constant('getVirtualTarget', (profile, options) ->
if profile?.profileType == 'VirtualProfile'
options?['+' + profile.defaultProfileName]
).directive('omegaProfileIcon', (profileIcons, getVirtualTarget) ->
restrict: 'A'
template: '''
<span ng-style="{color: color || profile.color}"
ng-class="{'virtual-profile-icon': profile.virtualType}"
class="glyphicon {{getIcon(profile)}}">
<span ng-style="{color: color || getColor(profile)}"
ng-class="{'virtual-profile-icon': isVirtual(profile)}"
class="glyphicon {{icon || getIcon(profile)}}">
</span>
'''
scope:
'profile': '=?omegaProfileIcon'
'icon': '=?icon'
'color': '=?color'
'options': '=options'
link: (scope, element, attrs, ngModel) ->
scope.profileIcons = profileIcons
scope.isVirtual = (profile) ->
profile?.profileType == 'VirtualProfile'
scope.getIcon = (profile) ->
(scope.icon || scope.profileIcons[profile.virtualType] ||
profileIcons[profile.profileType])
type = profile?.profileType
type = getVirtualTarget(profile, scope.options)?.profileType ? type
profileIcons[type]
scope.getColor = (profile) ->
color = undefined
while profile
color = profile.color
profile = getVirtualTarget(profile, scope.options)
color
).directive('omegaProfileInline', ->
restrict: 'A'
template: '''
<span omega-profile-icon="profile"></span>
<span omega-profile-icon="profile" options="options"></span>
{{dispName ? dispName(profile) : profile.name}}
'''
scope:
'profile': '=omegaProfileInline'
'dispName': '=?dispName'
'options': '=options'
).directive('omegaHtml', ($compile) ->
restrict: 'A'
link: (scope, element, attrs, ngModel) ->
locals =
$profile: (profile = 'profile', dispName = 'dispNameFilter') ->
$profile: (profile = 'profile', dispName = 'dispNameFilter',
options = 'options') ->
"""
<span class="profile-inline" omega-profile-inline="#{profile}"
disp-name="#{dispName}"></span>
disp-name="#{dispName}" options="#{options}"></span>
"""
getHtml = -> scope.$eval(attrs.omegaHtml, locals)
scope.$watch getHtml, (html) ->
@ -70,6 +85,7 @@ angular.module('omegaDecoration', []).value('profileIcons', {
'profiles': '&omegaProfileSelect'
'defaultText': '@?defaultText'
'dispName': '=?dispName'
'options': '=options'
link: (scope, element, attrs, ngModel) ->
scope.profileIcons = profileIcons
scope.currentProfiles = []

View File

@ -222,10 +222,11 @@ main {
border: none;
}
.sp-preview {
.sp-preview, .profile-color-editor-fake {
margin-right: 0;
height: 30px;
width: 30px;
border: solid 1px #222;
}
.sp-dd {

View File

@ -103,6 +103,8 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,
conflict: '!$value || !profileByName($value)'
reserved: '!$value || !isProfileNameReserved($value)'
scope.profileIcons = profileIcons
scope.dispNameFilter = dispNameFilter
scope.options = $scope.options
$modal.open(
templateUrl: 'partials/new_profile.html'
scope: scope
@ -122,10 +124,11 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,
scope.toName = toName
scope.profileByName = $rootScope.profileByName
scope.dispNameFilter = dispNameFilter
scope.options = $scope.options
scope.profileSelect = (model) ->
"""
<div omega-profile-select="options | profiles:profile"
ng-model="#{model}"
ng-model="#{model}" options="options"
disp-name="dispNameFilter" style="display: inline-block;">
</div>
"""
@ -157,7 +160,8 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,
scope.validateProfileName =
conflict: '!$value || $value == fromName || !profileByName($value)'
reserved: '!$value || !isProfileNameReserved($value)'
scope.profileIcons = profileIcons
scope.dispNameFilter = $scope.dispNameFilter
scope.options = $scope.options
$modal.open(
templateUrl: 'partials/rename_profile.html'
scope: scope

View File

@ -1,6 +1,6 @@
angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams,
$location, $rootScope, $timeout, $state, $modal, profileColorPalette,
getAttachedName, getParentName) ->
getAttachedName, getParentName, getVirtualTarget) ->
name = $stateParams.name
profileTemplates =
'FixedProfile': 'profile_fixed.html'
@ -18,13 +18,22 @@ angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams,
showPalette: true
showSelectionPalette: true
$scope.getProfileColor = ->
color = undefined
profile = $scope.profile
while profile
color = profile.color
profile = getVirtualTarget(profile, $scope.options)
color
$scope.deleteProfile = ->
profileName = $scope.profile.name
refs = OmegaPac.Profiles.referencedBySet(profileName, $rootScope.options)
scope = $rootScope.$new('isolate')
scope.profile = $scope.profile
scope.profileIcons = $scope.profileIcons
scope.dispNameFilter = $scope.dispNameFilter
scope.options = $scope.options
if Object.keys(refs).length > 0
refSet = {}
@ -94,15 +103,4 @@ angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams,
revisionChanged = true
$scope.$watch expression, onChange, true
onProfileChange = (profile, oldProfile) ->
return if profile == oldProfile
if profile.virtualType
target = $scope.profileByName(profile.defaultProfileName)
profile.color = target.color
profile.virtualType = target.profileType
OmegaPac.Profiles.each $scope.options, (key, p) ->
if p.virtualType and p.defaultProfileName == profile.name
onProfileChange(p, null)
$scope.watchAndUpdateRevision 'profile'
$scope.$watch 'profile', onProfileChange, true

View File

@ -118,7 +118,8 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $location,
scope = $scope.$new('isolate')
scope.rule = $scope.profile.rules[index]
scope.ruleProfile = $scope.profileByName(scope.rule.profileName)
scope.profileIcons = $scope.profileIcons
scope.dispNameFilter = $scope.dispNameFilter
scope.options = $scope.options
$modal.open(
templateUrl: 'partials/rule_remove_confirm.html'
scope: scope
@ -128,14 +129,15 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $location,
$scope.resetRules = ->
scope = $scope.$new('isolate')
scope.ruleProfile = $scope.profileByName($scope.profile.defaultProfileName)
scope.profileIcons = $scope.profileIcons
scope.ruleProfile = $scope.profileByName($scope.defaultProfileName)
scope.dispNameFilter = $scope.dispNameFilter
scope.options = $scope.options
$modal.open(
templateUrl: 'partials/rule_reset_confirm.html'
scope: scope
).result.then ->
for rule in $scope.profile.rules
rule.profileName = $scope.profile.defaultProfileName
rule.profileName = $scope.defaultProfileName
$scope.sortableOptions =
handle: '.sort-bar'
@ -202,7 +204,8 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $location,
return unless $scope.attached
scope = $scope.$new('isolate')
scope.attached = $scope.attached
scope.profileIcons = profileIcons
scope.dispNameFilter = $scope.dispNameFilter
scope.options = $scope.options
$modal.open(
templateUrl: 'partials/delete_attached.html'
scope: scope

View File

@ -30,9 +30,7 @@ html(lang='en' ng-controller='MasterCtrl' ng-csp)
li.nav-header {{'options_navHeader_profiles' | tr}}
li(ng-repeat='profile in options | profiles:"sorted"' ui-sref-active='active')
a(ui-sref='profile({name: profile.name})')
span(omega-profile-icon='profile')
= ' '
| {{profile.name}}
span(omega-profile-inline='profile' options='options')
li
a(role='button' ng-click='newProfile()')
span.glyphicon.glyphicon-plus

View File

@ -8,9 +8,7 @@
.well
ul.list-style-none
li(ng-repeat='p in refs')
span(omega-profile-icon='p')
= ' '
| {{p.name | dispName}}
span(omega-profile-inline='p' options='options' disp-name='dispNameFilter')
p {{'options_modifyReferringProfiles' | tr}}
.modal-footer
button.btn.btn-default(ng-click='$dismiss()') {{'dialog_cancel' | tr}}

View File

@ -6,7 +6,7 @@
.modal-body
p {{'options_deleteAttachedConfirm' | tr}}
.well
span(omega-profile-icon='attached')
span(omega-profile-icon='attached' options='options')
= ' '
| {{attached.sourceUrl || ('options_ruleListLineCount' | tr:[attached.ruleList.split('\n').length])}}
.modal-footer

View File

@ -6,9 +6,7 @@
.modal-body
p {{'options_deleteProfileConfirm' | tr}}
.well
span(omega-profile-icon='profile')
= ' '
| {{profile.name}}
span(omega-profile-inline='profile' options='options' disp-name='dispNameFilter')
.modal-footer
button.btn.btn-default(ng-click='$dismiss()') {{'dialog_cancel' | tr}}
button.btn.btn-danger(type='button' ng-click='$close("ok")') {{'options_deleteProfile' | tr}}

View File

@ -1,7 +1,7 @@
.btn-group.omega-profile-select(dropdown on-toggle="toggled(open)")
button.btn.btn-default.dropdown-toggle(type='button' aria-expanded='false'
role='listbox' aria-haspopup='true')
span(omega-profile-icon='selectedProfile' icon='selectedProfile ? undefined : "glyphicon-time"')
span(omega-profile-icon='selectedProfile' options='options' icon='selectedProfile ? undefined : "glyphicon-time"')
= ' '
span(ng-show='!!profileName') {{getName(selectedProfile)}}
span(ng-show='!profileName') {{defaultText}}
@ -14,5 +14,5 @@
= ' {{defaultText}}'
li(role='option' ng-repeat='profile in dispProfiles' ng-class='{active: profileName == profile.name}')
a(ng-click='setProfileName(profile.name)')
span(omega-profile-icon='profile')
span(omega-profile-icon='profile' options='options')
= ' {{getName(profile)}}'

View File

@ -15,6 +15,9 @@
= ' '
| {{'options_deleteProfile' | tr}}
span.profile-color-editor
x-spectrum-colorpicker(ng-model='profile.color' options='spectrumOptions')
.profile-color-editor-fake(ng-if='profile.profileType == "VirtualProfile"'
ng-style="{'background-color': getProfileColor()}")
x-spectrum-colorpicker(ng-model='profile.color' options='spectrumOptions'
ng-if='profile.profileType != "VirtualProfile"')
h2.profile-name {{'options_profileTabPrefix' | tr}}{{profile.name}}
div(ng-include='profileTemplate')

View File

@ -5,12 +5,12 @@ div(ng-controller='RuleListProfileCtrl')
label {{'options_ruleListMatchProfile' | tr}}
= ' '
div(omega-profile-select='options | profiles:profile' ng-model='profile.matchProfileName'
disp-name='dispNameFilter' style='display: inline-block;')
disp-name='dispNameFilter' options='options' style='display: inline-block;')
.form-group
label {{'options_ruleListDefaultProfile' | tr}}
= ' '
div(omega-profile-select='options | profiles:profile' ng-model='profile.defaultProfileName'
disp-name='dispNameFilter' style='display: inline-block;')
disp-name='dispNameFilter' options='options' style='display: inline-block;')
form.form-group
label {{'options_ruleListFormat' | tr}}
.radio.inline-form-control.no-min-width(ng-repeat='format in ruleListFormats')

View File

@ -52,7 +52,8 @@ div(ng-controller='SwitchProfileCtrl')
ui-validate='{pattern: "validateCondition(rule.condition, $value)"}')
td
div(omega-profile-select='options | profiles:profile' ng-model='rule.profileName'
disp-name='dispNameFilter' ng-class='{disabled: rule.condition.conditionType == "NeverCondition"}')
disp-name='dispNameFilter' options='options'
ng-class='{disabled: rule.condition.conditionType == "NeverCondition"}')
td
button.btn.btn-danger.btn-sm(title="{{'options_deleteRule' | tr}}" ng-click='removeRule($index)')
span.glyphicon.glyphicon-trash
@ -80,7 +81,7 @@ div(ng-controller='SwitchProfileCtrl')
| {{'options_switchAttachedProfileInConditionDisabled' | tr}}
td
div(omega-profile-select='options | profiles:profile' ng-model='attached.matchProfileName'
disp-name='dispNameFilter' ng-class='{disabled: !attachedOptions.enabled}')
disp-name='dispNameFilter' options='options' ng-class='{disabled: !attachedOptions.enabled}')
td
button.btn.btn-danger.btn-sm(title="{{'options_deleteAttached' | tr}}" ng-click='removeAttached()')
span.glyphicon.glyphicon-trash
@ -90,7 +91,7 @@ div(ng-controller='SwitchProfileCtrl')
td(colspan='2') {{'options_switchDefaultProfile' | tr}}
td
div(omega-profile-select='options | profiles:profile' ng-model='defaultProfileName'
disp-name='dispNameFilter')
disp-name='dispNameFilter' options='options')
td
button.btn.btn-info.btn-sm(title="{{'options_resetRules_help' | tr}}" ng-click='resetRules()')
span.glyphicon.glyphicon-chevron-up

View File

@ -7,7 +7,7 @@ div
label {{'options_virtualProfileTarget' | tr}}
= ' '
div(omega-profile-select='options | profiles:profile' ng-model='profile.defaultProfileName'
disp-name='dispNameFilter' style='display: inline-block;')
disp-name='dispNameFilter' style='display: inline-block;' options='options')
section.settings-group
h3 {{'options_group_virtualProfileReplace' | tr}}
p.help-block(omega-html='"options_virtualProfileReplaceHelp" | tr:[$profile("profileByName(profile.defaultProfileName)")]')

View File

@ -6,11 +6,11 @@
.modal-body
p(omega-html='"options_replaceProfileConfirm" | tr:[profileSelect("fromName"), profileSelect("toName")]')
.well
span(omega-profile-inline='profileByName(fromName)')
span(omega-profile-inline='profileByName(fromName)' options='options' disp-name='dispNameFilter')
= ' '
span.glyphicon.glyphicon-chevron-right
= ' '
span(omega-profile-inline='profileByName(toName)')
span(omega-profile-inline='profileByName(toName)' options='options' disp-name='dispNameFilter')
.help-block(omega-html="'options_replaceProfileHelp' | tr:[$profile('profileByName(fromName)'), $profile('profileByName(toName)')]")
.modal-footer
button.btn.btn-default(ng-click='$dismiss()') {{'dialog_cancel' | tr}}

View File

@ -10,9 +10,7 @@
= ' '
| {{rule.condition.pattern}}
span.pull-right
span(omega-profile-icon='ruleProfile')
= ' '
| {{ruleProfile.name | dispName}}
span(omega-profile-inline='ruleProfile' disp-name='dispNameFilter' options='options')
.modal-footer
button.btn.btn-default(ng-click='$dismiss()') {{'dialog_cancel' | tr}}
button.btn.btn-danger(type='button' ng-click='$close("ok")') {{'options_deleteRule' | tr}}

View File

@ -6,9 +6,7 @@
.modal-body
p {{'options_resetRulesConfirm' | tr}}
.well
span(omega-profile-icon='ruleProfile')
= ' '
| {{ruleProfile.name | dispName}}
span(omega-profile-inline='ruleProfile' disp-name='dispNameFilter' options='options')
.modal-footer
button.btn.btn-default(ng-click='$dismiss()') {{'dialog_cancel' | tr}}
button.btn.btn-warning(type='button' ng-click='$close("ok")') {{'options_resetRules' | tr}}

View File

@ -17,7 +17,7 @@ section.settings-group
= ' '
div(omega-profile-select='options | profiles:"all"' ng-model='options["-startupProfileName"]'
default-text="{{'options_startupProfile_none' | tr}}" disp-name='dispNameFilter'
style='display: inline-block;')
style='display: inline-block;' options='options')
div.checkbox
label
input(type='checkbox' ng-model='options["-showConditionTypes"]' ng-true-value='1' ng-false-value='0' omega-int2str)
@ -36,12 +36,8 @@ section.settings-group
ul.cycle-profile-container.cycle-enabled(ui-sortable="sortableOptions"
ng-model='options["-quickSwitchProfiles"]')
li(ng-repeat='name in options["-quickSwitchProfiles"]')
span(omega-profile-icon='profileByName(name)')
= ' '
| {{name | dispName}}
span(omega-profile-inline='profileByName(name)' options='options' disp-name='dispNameFilter')
h4 {{'options_notCycledProfiles' | tr}}
ul.cycle-profile-container(ui-sortable="sortableOptions" ng-model='notCycledProfiles')
li.bg-success(ng-repeat='name in notCycledProfiles')
span(omega-profile-icon='profileByName(name)')
= ' '
| {{name | dispName}}
span(omega-profile-inline='profileByName(name)' options='options' disp-name='dispNameFilter')

View File

@ -27,13 +27,11 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
ul.nav.nav-pills.nav-stacked(ng-hide='showConditionForm || proxyNotControllable')
li.profile(ng-repeat='profile in builtinProfiles' ng-class='{active: isActive(profile.name), "bg-info": isEffective(profile.name)}')
a(ng-click='applyProfile(profile)')
span(omega-profile-icon='profile' icon='getIcon(profile)')
= ' '
| {{profile.name | dispName}}
span(omega-profile-inline='profile' icon='getIcon(profile)' options='availableProfiles' disp-name='dispNameFilter')
li.profile.external-profile(ng-show='!!externalProfile' ng-class='{active: isActive(""), "bg-info": isEffective("")}')
a(ng-click='nameExternal.open = true')
form(name='nameExternalForm' ng-submit='nameExternalForm.$valid && saveExternal()')
span(omega-profile-icon='externalProfile' icon='getIcon(externalProfile, "normal")')
span(omega-profile-icon='externalProfile' icon='getIcon(externalProfile, "normal")' options='availableProfiles' disp-name='dispNameFilter')
= ' '
span(ng-show='!nameExternal.open') {{'popup_externalProfile' | tr}}
input.form-control(ng-show='!!nameExternal.open' ng-model='externalProfile.name' ng-blur='nameExternalForm.submit()'
@ -42,21 +40,17 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
li.profile(ng-repeat='profile in customProfiles' ng-class='{active: isActive(profile.name), "bg-info": isEffective(profile.name)}'
dropdown)
a(ng-click='applyProfile(profile)' ng-if='!profile.validResultProfiles')
span(omega-profile-icon='profile' icon='getIcon(profile)')
= ' '
| {{profile.name | dispName}}
span(omega-profile-inline='profile' icon='getIcon(profile)' options='availableProfiles' disp-name='dispNameFilter')
a.profile-with-default-edit(ng-click='applyProfile(profile)' ng-if='!!profile.validResultProfiles')
span(omega-profile-icon='profile' icon='getIcon(profile)')
= ' {{profile.name | dispName}} '
span(omega-profile-inline='profile' icon='getIcon(profile)' options='availableProfiles' disp-name='dispNameFilter')
= ' '
| [{{profile.defaultProfileName}}]
button.dropdown-toggle.btn.btn-default(ng-click='$event.stopPropagation()')
span.glyphicon.glyphicon-chevron-down
ul.dropdown-menu(ng-if='!!profile.validResultProfiles')
li(ng-repeat='p in profile.validResultProfiles' ng-class='{active: p.name == profile.defaultProfileName}')
a(ng-click='setDefaultProfile(profile.name, p.name)')
span(omega-profile-icon='p')
= ' '
| {{p.name | dispName}}
span(omega-profile-inline='p' options='availableProfiles' disp-name='dispNameFilter')
li.divider(ng-show='!!currentDomain && validResultProfiles.length')
li(ng-show='!!currentProfileCanAddRule')
a(ng-click='showConditionForm = true')
@ -73,9 +67,7 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
li(ng-repeat='profile in validResultProfiles' ng-class='{active: profile.name == currentTempRuleProfile}'
ng-show='!!currentTempRuleProfile || validResultProfiles.length == 1 || profile.name != currentProfileName')
a(ng-click='addTempRule(currentDomain, profile.name)')
span(omega-profile-icon='profile')
= ' '
| {{profile.name | dispName}}
span(omega-profile-inline='profile' options='availableProfiles' disp-name='dispNameFilter')
li.divider
li
a(ng-click='openOptions()')
@ -100,9 +92,7 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
| {{'popup_addConditionTo' | tr}}
= ' '
span.profile-inline
span(omega-profile-icon='currentProfile')
= ' '
| {{currentProfileName | dispName}}
span(omega-profile-inline='currentProfile' options='availableProfiles' disp-name='dispNameFilter')
div.form-group
label
| {{'options_conditionType' | tr}}
@ -123,7 +113,7 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
div.form-group
label {{'options_resultProfile' | tr}}
div(omega-profile-select='validResultProfiles' ng-model='rule.profileName'
disp-name='dispNameFilter')
disp-name='dispNameFilter' options='availableProfiles')
div.condition-controls
button.btn.btn-default(type='button' ng-click='showConditionForm = false')
| {{'dialog_cancel' | tr}}