2 * App to drive the base page.
7 angular.module('egWorkstationAdmin',
8 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod'])
10 .config(['$routeProvider','$locationProvider','$compileProvider',
11 function($routeProvider , $locationProvider , $compileProvider) {
13 $locationProvider.html5Mode(true);
14 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/);
15 var resolver = {delay : function(egStartup) {return egStartup.go()}};
17 $routeProvider.when('/admin/workstation/workstations', {
18 templateUrl: './admin/workstation/t_workstations',
19 controller: 'WSRegCtrl',
23 $routeProvider.when('/admin/workstation/print/config', {
24 templateUrl: './admin/workstation/t_print_config',
25 controller: 'PrintConfigCtrl',
29 $routeProvider.when('/admin/workstation/print/templates', {
30 templateUrl: './admin/workstation/t_print_templates',
31 controller: 'PrintTemplatesCtrl',
35 $routeProvider.when('/admin/workstation/stored_prefs', {
36 templateUrl: './admin/workstation/t_stored_prefs',
37 controller: 'StoredPrefsCtrl',
41 $routeProvider.when('/admin/workstation/hatch', {
42 templateUrl: './admin/workstation/t_hatch',
43 controller: 'HatchCtrl',
47 $routeProvider.when('/admin/workstation/tests', {
48 templateUrl: './admin/workstation/t_tests',
49 controller: 'testsCtrl',
54 $routeProvider.otherwise({
55 templateUrl : './admin/workstation/t_splash',
56 controller : 'SplashCtrl',
61 .config(['ngToastProvider', function(ngToastProvider) {
62 ngToastProvider.configure({
63 verticalPosition: 'bottom',
68 .factory('workstationSvc',
69 ['$q','$timeout','$location','egCore','egConfirmDialog',
70 function($q , $timeout , $location , egCore , egConfirmDialog) {
74 service.get_all = function() {
75 return egCore.hatch.getItem('eg.workstation.all')
76 .then(function(all) { return all || [] });
79 service.get_default = function() {
80 return egCore.hatch.getItem('eg.workstation.default');
83 service.set_default = function(name) {
84 return egCore.hatch.setItem('eg.workstation.default', name);
87 service.register_workstation = function(base_name, name, org_id) {
88 return service.register_ws_api(base_name, name, org_id)
89 .then(function(ws_id) {
90 return service.track_new_ws(ws_id, name, org_id);
94 service.register_ws_api =
95 function(base_name, name, org_id, override, deferred) {
96 if (!deferred) deferred = $q.defer();
98 var method = 'open-ils.actor.workstation.register';
99 if (override) method += '.override';
102 'open-ils.actor', method, egCore.auth.token(), name, org_id)
104 .then(function(resp) {
106 if (evt = egCore.evt.parse(resp)) {
107 console.log('register returned ' + evt.toString());
109 if (evt.textcode == 'WORKSTATION_NAME_EXISTS' && !override) {
111 egConfirmDialog.open(
112 egCore.strings.WS_EXISTS, base_name, {
114 service.register_ws_api(
115 base_name, name, org_id, true, deferred)
117 cancel : function() {
124 alert(evt.toString());
128 console.log('Resolving register promise with: ' + resp);
129 deferred.resolve(resp);
133 return deferred.promise;
136 service.track_new_ws = function(ws_id, ws_name, owning_lib) {
137 console.log('Tracking newly created WS with ID ' + ws_id);
138 var new_ws = {id : ws_id, name : ws_name, owning_lib : owning_lib};
140 return service.get_all()
141 .then(function(all) {
143 return egCore.hatch.setItem('eg.workstation.all', all)
144 .then(function() { return new_ws });
148 // Remove all traces of the workstation locally.
149 // This does not remove the WS from the server.
150 service.remove_workstation = function(name) {
151 console.debug('Removing workstation: ' + name);
153 return egCore.hatch.getItem('eg.workstation.all')
155 // remove from list of all workstations
156 .then(function(all) {
158 var keep = all.filter(function(ws) {return ws.name != name});
159 return egCore.hatch.setItem('eg.workstation.all', keep)
163 return service.get_default()
165 }).then(function(def) {
167 console.debug('Removing default workstation: ' + name);
168 return egCore.hatch.removeItem('eg.workstation.default');
177 .controller('SplashCtrl',
178 ['$scope','$window','$location','egCore','egConfirmDialog',
179 function($scope , $window , $location , egCore , egConfirmDialog) {
181 egCore.hatch.getItem('eg.audio.disable').then(function(val) {
182 $scope.disable_sound = val;
185 egCore.hatch.getItem('eg.search.search_lib').then(function(val) {
186 $scope.search_lib = egCore.org.get(val);
188 $scope.handle_search_lib_changed = function(org) {
189 egCore.hatch.setItem('eg.search.search_lib', org.id());
192 egCore.hatch.getItem('eg.search.pref_lib').then(function(val) {
193 $scope.pref_lib = egCore.org.get(val);
195 $scope.handle_pref_lib_changed = function(org) {
196 egCore.hatch.setItem('eg.search.pref_lib', org.id());
199 $scope.adv_pane = 'advanced'; // default value if not explicitly set
200 egCore.hatch.getItem('eg.search.adv_pane').then(function(val) {
201 $scope.adv_pane = val;
203 $scope.$watch('adv_pane', function(newVal, oldVal) {
204 if (typeof newVal != 'undefined' && newVal != oldVal) {
205 egCore.hatch.setItem('eg.search.adv_pane', newVal);
209 $scope.apply_sound = function() {
210 if ($scope.disable_sound) {
211 egCore.hatch.setItem('eg.audio.disable', true);
213 egCore.hatch.removeItem('eg.audio.disable');
217 $scope.test_audio = function(sound) {
218 egCore.audio.play(sound);
223 .controller('PrintConfigCtrl',
225 function($scope , egCore) {
227 $scope.printConfig = {};
228 $scope.setContext = function(ctx) {
229 $scope.context = ctx;
230 $scope.isTestView = false;
232 $scope.setContext('default');
234 $scope.setContentType = function(type) { $scope.contentType = type }
235 $scope.setContentType('text/plain');
237 $scope.useHatchPrinting = function() {
238 return egCore.hatch.usePrinting();
241 $scope.hatchIsOpen = function() {
242 return egCore.hatch.hatchAvailable;
245 $scope.getPrinterByAttr = function(attr, value) {
247 angular.forEach($scope.printers, function(p) {
248 if (p[attr] == value) printer = p;
253 $scope.resetPrinterSettings = function(context) {
254 $scope.printConfig[context] = {
256 printer : $scope.defaultPrinter ? $scope.defaultPrinter.name : null,
263 $scope.savePrinterSettings = function(context) {
264 return egCore.hatch.setPrintConfig(
265 context, $scope.printConfig[context]);
268 $scope.printerConfString = function() {
269 if ($scope.printConfigError) return $scope.printConfigError;
270 if (!$scope.printConfig) return;
271 if (!$scope.printConfig[$scope.context]) return;
272 return JSON.stringify(
273 $scope.printConfig[$scope.context], undefined, 2);
276 function loadPrinterOptions(name) {
277 egCore.hatch.getPrinterOptions(name).then(
278 function(options) {$scope.printerOptions = options});
281 $scope.setPrinter = function(name) {
282 $scope.printConfig[$scope.context].printer = name;
283 loadPrinterOptions(name);
286 $scope.testPrint = function(withDialog) {
287 if ($scope.contentType == 'text/plain') {
289 context : $scope.context,
290 content_type : $scope.contentType,
291 content : $scope.textPrintContent,
292 show_dialog : withDialog
296 context : $scope.context,
297 content_type : $scope.contentType,
298 content : $scope.htmlPrintContent,
300 value1 : 'Value One',
301 value2 : 'Value Two',
302 date_value : '2015-02-04T14:04:34-0400'
304 show_dialog : withDialog
309 // Load startup data....
310 // Don't bother talking to Hatch if it's not there.
311 if (!egCore.hatch.hatchAvailable) return;
313 // fetch info on all remote printers
314 egCore.hatch.getPrinters()
315 .then(function(printers) {
316 $scope.printers = printers;
318 var def = $scope.getPrinterByAttr('is-default', true);
319 if (!def && printers.length) def = printers[0];
322 $scope.defaultPrinter = def;
323 loadPrinterOptions(def.name);
327 ['default','receipt','label','mail','offline'],
329 egCore.hatch.getPrintConfig(ctx).then(function(conf) {
331 $scope.printConfig[ctx] = conf;
333 $scope.resetPrinterSettings(ctx);
342 .controller('PrintTemplatesCtrl',
343 ['$scope','$q','egCore','ngToast',
344 function($scope , $q , egCore , ngToast) {
347 template_name : 'bills_current',
348 template_output : '',
349 template_context : 'default'
352 // print preview scope data
353 // TODO: consider moving the template-specific bits directly
354 // into the templates or storing template- specific script files
355 // alongside the templates.
356 // NOTE: A lot of this data can be shared across templates.
359 first_given_name : 'Slow',
360 second_given_name : 'Joe',
361 family_name : 'Jones',
364 barcode : '30393830393'
367 balance_owed : 4, // This is currently how these values are returned to the client
368 total_billed : '5.00',
371 expire_date : '2020-12-31',
375 dob : '1984-11-07T00:00:00-8:00',
377 usrname : '30393830393',
378 day_phone : '111-222-3333',
379 evening_phone : '222-333-1111',
380 other_phone : '333-111-2222',
381 email : 'user@example.com',
382 ident_value2 : 'Carol',
383 home_ou : {name: function() {return 'BR1'}},
384 profile : {name: function() {return 'Patrons'}},
385 net_access_level : {name: function() {return 'Filtered'}},
388 master_account : 'f',
389 claims_returned_count : '0',
390 claims_never_checked_out_count : '0',
391 alert_message : 'Very slow',
392 ident_type: {name: function() {return 'Other'}},
393 ident_value: '11332445',
397 stat_cat : {'name' : 'Favorite Donut'},
398 'stat_cat_entry' : 'Maple'
400 stat_cat : {'name' : 'Favorite Book'},
401 'stat_cat_entry' : 'Beasts Made of Night'
407 address_type : 'MAILING',
408 street1 : '123 Apple Rd',
415 within_city_limits: 't'
418 seed_user.addresses.push(seed_addr);
421 title : 'Traveling Pants!!',
422 author : 'Jane Jones',
427 barcode : '33434322323',
432 'title' : 'Test Title'
437 name : 'General Collection'
439 // flattened versions for item status template
440 // TODO - make this go away
441 'call_number.label' : '636.8 JON',
442 'call_number.record.simple_record.title' : 'Test Title',
443 'location.name' : 'General Colleciton'
448 phone_notify : '111-222-3333',
449 sms_notify : '111-222-3333',
450 email_notify : 'user@example.org',
451 request_time : new Date().toISOString(),
453 shelf_expire_time : new Date().toISOString()
460 holds_address : seed_addr
465 holds_address : seed_addr
467 source_send_time : new Date().toISOString(),
468 target_copy : seed_copy
471 $scope.preview_scope = {
476 xact_start : new Date().toISOString(),
478 xact_type : 'circulation',
479 last_billing_type : 'Overdue materials',
481 last_payment_note : 'Test Note 1',
482 last_payment_type : 'cash_payment',
488 xact_start : new Date().toISOString(),
490 xact_type : 'circulation',
491 last_billing_type : 'Overdue materials',
493 last_payment_note : 'Test Note 2',
494 last_payment_type : 'credit_payment',
502 copies : [ seed_copy ],
506 due_date : new Date().toISOString(),
509 target_copy : seed_copy,
510 copy_barcode : seed_copy.barcode,
511 call_number : seed_copy.call_number,
512 title : seed_record.title
519 due_date : new Date().toISOString(),
524 title : seed_record.title,
525 author : seed_record.author
539 title : seed_record.title
543 previous_balance : 8.45,
544 payment_total : 2.00,
545 payment_applied : 2.00,
549 payment_type : 'cash_payment',
550 payment_note : 'Here is a payment note',
552 create_date : new Date().toISOString(),
553 title : 'Test Note Title',
555 value : 'This patron is super nice!'
558 transit : seed_transit,
559 transits : [ seed_transit ],
560 title : seed_record.title,
561 author : seed_record.author,
564 dest_location : egCore.idl.toHash(egCore.org.get(egCore.auth.user().ws_ou())),
565 dest_address : seed_addr,
569 hold : one_hold, title : 'Some Title 1', author : 'Some Author 1',
570 volume : { label : '646.4 SOM' }, copy : seed_copy,
571 part : { label : 'v. 1' },
572 patron_barcode : 'S52802662',
573 patron_alias : 'XYZ', patron_last : 'Smith', patron_first : 'Jane',
574 status_string : 'Ready for Pickup'
577 hold : one_hold, title : 'Some Title 2', author : 'Some Author 2',
578 volume : { label : '646.4 SOM' }, copy : seed_copy,
579 part : { label : 'v. 1' },
580 patron_barcode : 'S52802662',
581 patron_alias : 'XYZ', patron_last : 'Smith', patron_first : 'Jane',
582 status_string : 'Ready for Pickup'
585 hold : one_hold, title : 'Some Title 3', author : 'Some Author 3',
586 volume : { label : '646.4 SOM' }, copy : seed_copy,
587 part : { label : 'v. 1' },
588 patron_barcode : 'S52802662',
589 patron_alias : 'XYZ', patron_last : 'Smith', patron_first : 'Jane',
590 status_string : 'Canceled'
595 $scope.preview_scope.payments = [
596 {amount : 1.00, xact : $scope.preview_scope.transactions[0]},
597 {amount : 1.00, xact : $scope.preview_scope.transactions[1]}
599 $scope.preview_scope.payments[0].xact.title = 'Hali Bote Azikaban de tao fan';
600 $scope.preview_scope.payments[0].xact.copy_barcode = '334343434';
601 $scope.preview_scope.payments[1].xact.title = seed_record.title;
602 $scope.preview_scope.payments[1].xact.copy_barcode = seed_copy.barcode;
604 // today, staff, current_location, etc.
605 egCore.print.fleshPrintScope($scope.preview_scope);
607 $scope.template_changed = function() {
608 $scope.print.load_failed = false;
609 egCore.print.getPrintTemplate($scope.print.template_name)
612 $scope.print.template_content = html;
613 console.log('set template content');
616 $scope.print.template_content = '';
617 $scope.print.load_failed = true;
620 egCore.print.getPrintTemplateContext($scope.print.template_name)
621 .then(function(template_context) {
622 $scope.print.template_context = template_context;
626 $scope.reset_to_default = function() {
627 egCore.print.removePrintTemplate(
628 $scope.print.template_name
630 egCore.print.removePrintTemplateContext(
631 $scope.print.template_name
633 $scope.template_changed();
636 $scope.save_locally = function() {
637 egCore.print.storePrintTemplate(
638 $scope.print.template_name,
639 $scope.print.template_content
641 egCore.print.storePrintTemplateContext(
642 $scope.print.template_name,
643 $scope.print.template_context
647 $scope.exportable_templates = function() {
650 var deferred = $q.defer();
652 egCore.hatch.getKeys('eg.print.template').then(function(keys) {
653 angular.forEach(keys, function(key) {
654 if (key.match(/^eg\.print\.template\./)) {
655 promises.push(egCore.hatch.getItem(key).then(function(value) {
656 templates[key.replace('eg.print.template.', '')] = value;
659 promises.push(egCore.hatch.getItem(key).then(function(value) {
660 contexts[key.replace('eg.print.template_context.', '')] = value;
664 $q.all(promises).then(function() {
665 if (Object.keys(templates).length) {
667 templates: templates,
671 ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_EXPORT);
676 return deferred.promise;
679 $scope.imported_print_templates = { data : '' };
680 $scope.$watch('imported_print_templates.data', function(newVal, oldVal) {
681 if (newVal && newVal != oldVal) {
683 var data = JSON.parse(newVal);
684 angular.forEach(data.templates, function(template_content, template_name) {
685 egCore.print.storePrintTemplate(template_name, template_content);
687 angular.forEach(data.contexts, function(template_context, template_name) {
688 egCore.print.storePrintTemplateContext(template_name, template_context);
690 $scope.template_changed(); // refresh
691 ngToast.create(egCore.strings.PRINT_TEMPLATES_SUCCESS_IMPORT);
693 ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_IMPORT);
698 $scope.template_changed(); // load the default
702 .directive('egPrintTemplateOutput', ['$compile',function($compile) {
703 return function(scope, element, attrs) {
706 return scope.$eval(attrs.content);
709 // create an isolate scope and copy the print context
710 // data into the new scope.
711 // TODO: see also print security concerns in egHatch
712 var result = element.html(value);
713 var context = scope.$eval(attrs.context);
714 var print_scope = scope.$new(true);
715 angular.forEach(context, function(val, key) {
716 print_scope[key] = val;
718 $compile(element.contents())(print_scope);
724 .controller('StoredPrefsCtrl',
725 ['$scope','$q','egCore','egConfirmDialog',
726 function($scope , $q , egCore , egConfirmDialog) {
727 console.log('StoredPrefsCtrl');
729 $scope.setContext = function(ctx) {
730 $scope.context = ctx;
732 $scope.setContext('local');
734 // grab the edit perm
735 $scope.userHasDeletePerm = false;
736 egCore.perm.hasPermHere('ADMIN_WORKSTATION')
737 .then(function(bool) { $scope.userHasDeletePerm = bool });
741 function refreshKeys() {
742 $scope.keys = {local : [], remote : []};
744 if (egCore.hatch.hatchAvailable) {
745 egCore.hatch.getRemoteKeys().then(
746 function(keys) { $scope.keys.remote = keys.sort() })
749 // local calls are non-async
750 $scope.keys.local = egCore.hatch.getLocalKeys();
754 $scope.selectKey = function(key) {
755 $scope.currentKey = key;
756 $scope.currentKeyContent = null;
758 if ($scope.context == 'local') {
759 $scope.currentKeyContent = egCore.hatch.getLocalItem(key);
761 egCore.hatch.getRemoteItem(key)
762 .then(function(content) {
763 $scope.currentKeyContent = content
768 $scope.getCurrentKeyContent = function() {
769 return JSON.stringify($scope.currentKeyContent, null, 2);
772 $scope.removeKey = function(key) {
773 egConfirmDialog.open(
774 egCore.strings.PREFS_REMOVE_KEY_CONFIRM, '',
777 if ($scope.context == 'local') {
778 egCore.hatch.removeLocalItem(key);
781 egCore.hatch.removeItem(key)
782 .then(function() { refreshKeys() });
785 cancel : function() {} // user canceled, nothing to do
791 .controller('WSRegCtrl',
792 ['$scope','$q','$window','$location','egCore','egAlertDialog','workstationSvc',
793 function($scope , $q , $window , $location , egCore , egAlertDialog , workstationSvc) {
795 var all_workstations = [];
796 var reg_perm_orgs = [];
798 $scope.page_loaded = false;
799 $scope.contextOrg = egCore.org.get(egCore.auth.user().ws_ou());
800 $scope.wsOrgChanged = function(org) { $scope.contextOrg = org; }
802 console.log('set context org to ' + $scope.contextOrg);
804 // fetch workstation reg perms
805 egCore.perm.hasPermAt('REGISTER_WORKSTATION', true)
806 .then(function(orgList) {
807 reg_perm_orgs = orgList;
809 // hide orgs in the context org selector where this login
810 // does not have the reg_ws perm or the org can't have users
811 $scope.wsOrgHidden = function(id) {
812 return reg_perm_orgs.indexOf(id) == -1
813 || $scope.cant_have_users(id);
816 // fetch the locally stored workstation data
818 return workstationSvc.get_all()
820 }).then(function(all) {
821 all_workstations = all || [];
822 $scope.workstations =
823 all_workstations.map(function(w) { return w.name });
824 return workstationSvc.get_default()
826 // fetch the default workstation
827 }).then(function(def) {
828 $scope.defaultWS = def;
829 $scope.activeWS = $scope.selectedWS = egCore.auth.workstation() || def;
831 // Handle any URL commands.
833 var remove = $location.search().remove;
835 console.log('Removing WS via URL request: ' + remove);
836 return $scope.remove_ws(remove).then(
837 function() { $scope.page_loaded = true; });
839 $scope.page_loaded = true;
842 $scope.get_ws_label = function(ws) {
843 return ws == $scope.defaultWS ?
844 egCore.strings.$replace(egCore.strings.DEFAULT_WS_LABEL, {ws:ws}) : ws;
847 $scope.set_default_ws = function(name) {
848 delete $scope.removing_ws;
849 $scope.defaultWS = name;
850 workstationSvc.set_default(name);
853 $scope.cant_have_users =
854 function (id) { return !egCore.org.CanHaveUsers(id); };
855 $scope.cant_have_volumes =
856 function (id) { return !egCore.org.CanHaveVolumes(id); };
858 // Log out and return to login page with selected WS
859 $scope.use_now = function() {
860 egCore.auth.logout();
861 $window.location.href = $location
863 .search({ws : $scope.selectedWS})
867 $scope.can_delete_ws = function(name) {
868 var ws = all_workstations.filter(
869 function(ws) { return ws.name == name })[0];
870 return ws && reg_perm_orgs.indexOf(ws.owning_lib) != -1;
873 $scope.remove_ws = function(remove_me) {
874 $scope.removing_ws = remove_me;
876 // Perm is used to disable Remove button in UI, but have to check
877 // again here in case we're removing a WS based on URL params.
878 if (!$scope.can_delete_ws(remove_me)) return $q.when();
880 $scope.is_removing = true;
881 return workstationSvc.remove_workstation(remove_me)
884 all_workstations = all_workstations.filter(
885 function(ws) { return ws.name != remove_me });
887 $scope.workstations = $scope.workstations.filter(
888 function(ws) { return ws != remove_me });
890 if ($scope.selectedWS == remove_me)
891 $scope.selectedWS = $scope.workstations[0];
893 if ($scope.defaultWS == remove_me)
894 $scope.defaultWS = '';
896 $scope.is_removing = false;
900 $scope.register_ws = function() {
901 delete $scope.removing_ws;
904 $scope.contextOrg.shortname() + '-' + $scope.newWSName;
906 if ($scope.workstations.indexOf(full_name) > -1) {
907 // avoid duplicate local registrations
908 return egAlertDialog.open(egCore.strings.WS_USED);
911 $scope.is_registering = true;
912 workstationSvc.register_workstation(
913 $scope.newWSName, full_name,
914 $scope.contextOrg.id()
916 ).then(function(new_ws) {
917 $scope.workstations.push(new_ws.name);
918 all_workstations.push(new_ws);
919 $scope.is_registering = false;
921 if (!$scope.selectedWS) {
922 $scope.selectedWS = new_ws.name;
924 if (!$scope.defaultWS) {
925 return $scope.set_default_ws(new_ws.name);
927 $scope.newWSName = '';
929 $scope.is_registering = false;
934 .controller('HatchCtrl',
935 ['$scope','egCore','ngToast',
936 function($scope , egCore , ngToast) {
937 var hatch = egCore.hatch; // convenience
939 $scope.hatch_available = hatch.hatchAvailable;
940 $scope.hatch_printing = hatch.usePrinting();
941 $scope.hatch_settings = hatch.useSettings();
942 $scope.hatch_offline = hatch.useOffline();
944 // Apply Hatch settings as changes occur in the UI.
946 $scope.$watch('hatch_printing', function(newval) {
947 if (typeof newval != 'boolean') return;
948 hatch.setLocalItem('eg.hatch.enable.printing', newval);
951 $scope.$watch('hatch_settings', function(newval) {
952 if (typeof newval != 'boolean') return;
953 hatch.setLocalItem('eg.hatch.enable.settings', newval);
956 $scope.$watch('hatch_offline', function(newval) {
957 if (typeof newval != 'boolean') return;
958 hatch.setLocalItem('eg.hatch.enable.offline', newval);
961 $scope.copy_to_hatch = function() {
962 hatch.copySettingsToHatch().then(
964 ngToast.create(egCore.strings.HATCH_SETTINGS_MIGRATION_SUCCESS)},
966 ngToast.warning(egCore.strings.HATCH_SETTINGS_MIGRATION_FAILURE)}
970 $scope.copy_to_local = function() {
971 hatch.copySettingsToLocal().then(
973 ngToast.create(egCore.strings.HATCH_SETTINGS_MIGRATION_SUCCESS)},
975 ngToast.warning(egCore.strings.HATCH_SETTINGS_MIGRATION_FAILURE)}
982 * Home of the Latency tester
984 .controller('testsCtrl', ['$scope', '$location', 'egCore', function($scope, $location, egCore) {
985 $scope.hostname = $location.host();
988 $scope.clearTestData = function(){
993 $scope.isTesting = false;
994 $scope.avrg = 0; // avrg latency
995 $scope.canCopyCommand = document.queryCommandSupported('copy');
997 // initially fetch first 10 (gets a decent average)
999 function calcAverage(){
1001 if ($scope.tests.length == 0) return 0;
1003 if ($scope.tests.length == 1) return $scope.tests[0].l;
1006 angular.forEach($scope.tests, function(t){
1010 return sum / $scope.tests.length;
1014 $scope.isTesting = true;
1016 return egCore.net.request(
1017 "open-ils.pcrud", "opensrf.system.echo", "ping"
1018 ).then(function(resp){
1019 var t2 = Date.now();
1020 var latency = t2 - t;
1021 $scope.tests.push({t: new Date(t), l: latency});
1022 console.log("Start: " + t + " and end: " + t2);
1023 console.log("Latency: " + latency);
1026 $scope.avrg = calcAverage();
1028 $scope.isTesting = false;
1032 $scope.testLatency = function(){
1034 if (numPings >= 10){
1035 ping(); // just ping once after the initial ten
1038 .then($scope.testLatency)
1041 $scope.tests.shift(); // toss first result
1042 $scope.avrg = calcAverage();
1048 $scope.copyTests = function(){
1050 var lNode = document.querySelector('#pingData');
1051 var r = document.createRange();
1052 r.selectNode(lNode);
1053 var sel = window.getSelection();
1054 sel.removeAllRanges();
1056 document.execCommand('copy');