ONOS-6726: UI-Lion: Quick Help.

Change-Id: I4725ae58c3c8fea6b8cb9c50593bd40b51d13e1b
This commit is contained in:
Simon Hunt 2017-07-11 11:45:50 -07:00
parent 6e920c89dd
commit a6ab9f0dd1
3 changed files with 49 additions and 19 deletions

View File

@ -23,7 +23,7 @@
'use strict'; 'use strict';
// injected references // injected references
var $log, fs, sus; var $log, fs, sus, ls;
// configuration // configuration
var defaultSettings = { var defaultSettings = {
@ -202,11 +202,13 @@
fmt.forEach(function (k) { fmt.forEach(function (k) {
var v = map.get(k), var v = map.get(k),
a = fs.isA(v), a = fs.isA(v),
d = (a && a[1]); d = (a && a[1]),
dfn = fs.isF(d),
dval = (dfn && dfn()) || d;
// '-' marks a separator; d is the description // '-' marks a separator; d is the description
if (k === '-' || d) { if (k === '-' || dval) {
b.push([mkKeyDisp(k), d]); b.push([mkKeyDisp(k), dval]);
} }
}); });
return b; return b;
@ -268,6 +270,10 @@
addRow(mkArrRow(vgest)); addRow(mkArrRow(vgest));
} }
function qhlion_title() {
var lion = ls.bundle('core.fw.QuickHelp');
return lion('qh_title');
}
function popBind(bindings) { function popBind(bindings) {
pane = svg.append('g') pane = svg.append('g')
@ -280,7 +286,7 @@
.attr('rx', 8); .attr('rx', 8);
pane.append('text') pane.append('text')
.text('Quick Help') .text(qhlion_title())
.attr({ .attr({
class: 'title', class: 'title',
dy: '1.2em', dy: '1.2em',
@ -342,12 +348,13 @@
angular.module('onosLayer') angular.module('onosLayer')
.factory('QuickHelpService', .factory('QuickHelpService',
['$log', 'FnService', 'SvgUtilService', ['$log', 'FnService', 'SvgUtilService', 'LionService',
function (_$log_, _fs_, _sus_) { function (_$log_, _fs_, _sus_, _ls_) {
$log = _$log_; $log = _$log_;
fs = _fs_; fs = _fs_;
sus = _sus_; sus = _sus_;
ls = _ls_;
function initQuickHelp(opts) { function initQuickHelp(opts) {
settings = angular.extend({}, defaultSettings, fs.isO(opts)); settings = angular.extend({}, defaultSettings, fs.isO(opts));

View File

@ -21,7 +21,7 @@
'use strict'; 'use strict';
// references to injected services // references to injected services
var $log, $timeout, fs, ts, ns, ee, qhs; var $log, $timeout, fs, ts, ns, ee, qhs, ls;
// internal state // internal state
var enabled = true, var enabled = true,
@ -162,13 +162,30 @@
} }
} }
// functions to obtain localized strings deferred from the setup of the
// global key data structures.
function qhlion() {
return ls.bundle('core.fw.QuickHelp');
}
function qhlion_show_hide() {
return qhlion()('qh_hint_show_hide_qh');
}
function qhlion_hint_esc() {
return qhlion()('qh_hint_esc');
}
function qhlion_hint_t() {
return qhlion()('qh_hint_t');
}
function setupGlobalKeys() { function setupGlobalKeys() {
angular.extend(keyHandler, { angular.extend(keyHandler, {
globalKeys: { globalKeys: {
backSlash: [quickHelp, 'Show / hide Quick Help'], backSlash: [quickHelp, qhlion_show_hide],
slash: [quickHelp, 'Show / hide Quick Help'], slash: [quickHelp, qhlion_show_hide],
esc: [escapeKey, 'Dismiss dialog or cancel selections'], esc: [escapeKey, qhlion_hint_esc],
T: [toggleTheme, "Toggle theme"] T: [toggleTheme, qhlion_hint_t]
}, },
globalFormat: ['backSlash', 'slash', 'esc', 'T'], globalFormat: ['backSlash', 'slash', 'esc', 'T'],
@ -302,15 +319,16 @@
angular.module('onosUtil') angular.module('onosUtil')
.factory('KeyService', .factory('KeyService',
['$log', '$timeout', 'FnService', 'ThemeService', 'NavService', ['$log', '$timeout', 'FnService', 'ThemeService', 'NavService',
'EeService', 'EeService', 'LionService',
function (_$log_, _$timeout_, _fs_, _ts_, _ns_, _ee_) { function (_$log_, _$timeout_, _fs_, _ts_, _ns_, _ee_, _ls_) {
$log = _$log_; $log = _$log_;
$timeout = _$timeout_; $timeout = _$timeout_;
fs = _fs_; fs = _fs_;
ts = _ts_; ts = _ts_;
ns = _ns_; ns = _ns_;
ee = _ee_; ee = _ee_;
ls = _ls_;
return { return {
bindQhs: function (_qhs_) { bindQhs: function (_qhs_) {

View File

@ -15,7 +15,7 @@
*/ */
/* /*
ONOS GUI -- Layer -- Flash Service - Unit Tests ONOS GUI -- Layer -- Quick Help Service - Unit Tests
*/ */
describe('factory: fw/layer/quickhelp.js', function () { describe('factory: fw/layer/quickhelp.js', function () {
var $log, fs, qhs, d3Elem, var $log, fs, qhs, d3Elem,
@ -39,7 +39,7 @@ describe('factory: fw/layer/quickhelp.js', function () {
'globalKeys', 'globalFormat', 'viewKeys', 'viewGestures' 'globalKeys', 'globalFormat', 'viewKeys', 'viewGestures'
]; ];
beforeEach(module('onosUtil', 'onosSvg', 'onosLayer')); beforeEach(module('onosUtil', 'onosSvg', 'onosLayer', 'onosRemote'));
beforeEach(inject(function (_$log_, FnService, QuickHelpService) { beforeEach(inject(function (_$log_, FnService, QuickHelpService) {
$log = _$log_; $log = _$log_;
@ -115,12 +115,16 @@ describe('factory: fw/layer/quickhelp.js', function () {
expect($log.warn).toHaveBeenCalledWith(warning, neededBindings); expect($log.warn).toHaveBeenCalledWith(warning, neededBindings);
}); });
it('should not warn if bindings are provided', function () { it('should not warn if bindings are provided (except lion)', function () {
spyOn($log, 'warn'); spyOn($log, 'warn');
expect(qhs.showQuickHelp(mockBindings)).toBe(undefined); expect(qhs.showQuickHelp(mockBindings)).toBe(undefined);
expect($log.warn).not.toHaveBeenCalled(); expect($log.warn).toHaveBeenCalledWith(
'No lion bundle registered:', 'core.fw.QuickHelp'
);
}); });
// TODO: consider testing localization of text
it('should append an svg', function () { it('should append an svg', function () {
var svg = d3Elem.select('svg'); var svg = d3Elem.select('svg');
expect(d3Elem.empty()).toBe(false); expect(d3Elem.empty()).toBe(false);
@ -149,7 +153,8 @@ describe('factory: fw/layer/quickhelp.js', function () {
expect(rect.attr('rx')).toBe('8'); expect(rect.attr('rx')).toBe('8');
text = g.select('text'); text = g.select('text');
expect(text.text()).toBe('Quick Help'); // NOTE: we aren't mocking localization, so should get %...% key tag
expect(text.text()).toBe('%qh_title%');
expect(text.classed('title')).toBe(true); expect(text.classed('title')).toBe(true);
expect(text.attr('dy')).toBe('1.2em'); expect(text.attr('dy')).toBe('1.2em');
expect(text.attr('transform')).toBeTruthy(); expect(text.attr('transform')).toBeTruthy();