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.getWorkstations()
76 .then(function(all) { return all || [] });
79 service.get_default = function() {
80 return egCore.hatch.getDefaultWorkstation();
83 service.set_default = function(name) {
84 return egCore.hatch.setDefaultWorkstation(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.setWorkstations(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.getWorkstations()
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.setWorkstations(keep);
163 return service.get_default()
165 }).then(function(def) {
167 console.debug('Removing default workstation: ' + name);
168 return egCore.hatch.removeDefaultWorkstation();
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 var hatchPrinting = false;
238 egCore.hatch.usePrinting().then(function(answer) {
239 hatchPrinting = answer;
242 $scope.useHatchPrinting = function() {
243 return hatchPrinting;
246 $scope.hatchIsOpen = function() {
247 return egCore.hatch.hatchAvailable;
250 $scope.getPrinterByAttr = function(attr, value) {
252 angular.forEach($scope.printers, function(p) {
253 if (p[attr] == value) printer = p;
258 $scope.resetPrinterSettings = function(context) {
259 $scope.printConfig[context] = {
261 printer : $scope.defaultPrinter ? $scope.defaultPrinter.name : null,
268 $scope.savePrinterSettings = function(context) {
269 return egCore.hatch.setPrintConfig(
270 context, $scope.printConfig[context]);
273 $scope.printerConfString = function() {
274 if ($scope.printConfigError) return $scope.printConfigError;
275 if (!$scope.printConfig) return;
276 if (!$scope.printConfig[$scope.context]) return;
277 return JSON.stringify(
278 $scope.printConfig[$scope.context], undefined, 2);
281 function loadPrinterOptions(name) {
282 if (name == 'hatch_file_writer') {
283 $scope.printerOptions = {};
285 egCore.hatch.getPrinterOptions(name).then(
286 function(options) {$scope.printerOptions = options});
290 $scope.setPrinter = function(name) {
291 $scope.printConfig[$scope.context].printer = name;
292 loadPrinterOptions(name);
295 $scope.testPrint = function(withDialog) {
296 if ($scope.contentType == 'text/plain') {
298 context : $scope.context,
299 content_type : $scope.contentType,
300 content : $scope.textPrintContent,
301 show_dialog : withDialog
305 context : $scope.context,
306 content_type : $scope.contentType,
307 content : $scope.htmlPrintContent,
309 value1 : 'Value One',
310 value2 : 'Value Two',
311 date_value : '2015-02-04T14:04:34-0400'
313 show_dialog : withDialog
318 $scope.useFileWriter = function() {
320 $scope.printConfig[$scope.context] &&
321 $scope.printConfig[$scope.context].printer == 'hatch_file_writer'
325 // Load startup data....
326 // Don't bother talking to Hatch if it's not there.
327 if (!egCore.hatch.hatchAvailable) return;
329 // fetch info on all remote printers
330 egCore.hatch.getPrinters()
331 .then(function(printers) {
332 $scope.printers = printers;
335 // We need a static name for saving configs.
336 // Human-friendly label is set in the template.
337 name: 'hatch_file_writer'
340 var def = $scope.getPrinterByAttr('is-default', true);
341 if (!def && printers.length) def = printers[0];
344 $scope.defaultPrinter = def;
345 loadPrinterOptions(def.name);
349 ['default','receipt','label','mail','offline'],
351 egCore.hatch.getPrintConfig(ctx).then(function(conf) {
353 $scope.printConfig[ctx] = conf;
355 $scope.resetPrinterSettings(ctx);
364 .controller('PrintTemplatesCtrl',
365 ['$scope','$q','egCore','ngToast',
366 function($scope , $q , egCore , ngToast) {
369 template_name : 'bills_current',
370 template_output : '',
371 template_context : 'default'
374 // print preview scope data
375 // TODO: consider moving the template-specific bits directly
376 // into the templates or storing template- specific script files
377 // alongside the templates.
378 // NOTE: A lot of this data can be shared across templates.
381 first_given_name : 'Joseph',
382 second_given_name : 'Martin',
383 family_name : 'Jones',
385 pref_first_given_name : 'Martin',
386 pref_second_given_name : 'Joe',
387 pref_family_name : 'Smith',
389 barcode : '30393830393'
392 balance_owed : 4, // This is currently how these values are returned to the client
393 total_billed : '5.00',
396 expire_date : '2020-12-31',
400 dob : '1980-01-01T00:00:00-8:00',
402 usrname : '30393830393',
403 day_phone : '111-222-3333',
404 evening_phone : '222-333-1111',
405 other_phone : '333-111-2222',
406 email : 'user@example.com',
407 home_ou : {name: function() {return 'BR1'}},
408 profile : {name: function() {return 'Patrons'}},
409 net_access_level : {name: function() {return 'Filtered'}},
412 master_account : 'f',
413 claims_returned_count : '0',
414 claims_never_checked_out_count : '0',
415 ident_type: {name: function() {return 'Drivers License'}},
416 ident_value: '11332445',
417 ident_type2: {name: function() {return 'Other'}},
418 ident_value2 : '55442211',
422 stat_cat : {'name' : 'Favorite Donut'},
423 'stat_cat_entry' : 'Maple'
425 stat_cat : {'name' : 'Favorite Book'},
426 'stat_cat_entry' : 'Beasts Made of Night'
432 address_type : 'MAILING',
433 street1 : '123 Apple Rd',
436 county : 'Great County',
441 within_city_limits: 't'
444 seed_user.addresses.push(seed_addr);
447 title : 'Traveling Pants!!',
448 author : 'Jane Jones',
453 barcode : '33434322323',
461 'title' : 'Test Title'
465 name : 'Ankers Memorial Library',
473 name : 'General Collection'
478 // flattened versions for item status template
479 // TODO - make this go away
480 'call_number.label' : '636.8 JON',
481 'call_number.record.simple_record.title' : 'Test Title',
482 'location.name' : 'General Collection',
483 'call_number.owning_lib.name' : 'Ankers Memorial Library',
484 'call_number.owning_lib.shortname' : 'Ankers',
485 'location.name' : 'General Collection'
490 phone_notify : '111-222-3333',
491 sms_notify : '111-222-3333',
492 email_notify : 'user@example.org',
493 request_time : new Date().toISOString(),
495 shelf_expire_time : new Date().toISOString()
502 holds_address : seed_addr
507 holds_address : seed_addr
509 source_send_time : new Date().toISOString(),
510 target_copy : seed_copy
513 $scope.preview_scope = {
518 xact_start : new Date().toISOString(),
519 xact_finish : new Date().toISOString(),
522 prefix : "biography",
523 suffix : "Closed Stacks",
525 name : "Mineola Public Library",
526 shortname : "Mineola"
530 xact_type : 'circulation',
531 last_billing_type : 'Overdue materials',
533 last_payment_note : 'Test Note 1',
534 last_payment_type : 'cash_payment',
535 last_payment_ts : new Date().toISOString(),
541 xact_start : new Date().toISOString(),
542 xact_finish : new Date().toISOString(),
548 name : "Rogers Reading Room",
553 xact_type : 'circulation',
554 last_billing_type : 'Overdue materials',
556 last_payment_note : 'Test Note 2',
557 last_payment_type : 'credit_payment',
558 last_payment_ts : new Date().toISOString(),
566 copies : [ seed_copy ],
570 due_date : new Date().toISOString(),
573 target_copy : seed_copy,
574 copy_barcode : seed_copy.barcode,
575 call_number : seed_copy.call_number,
576 title : seed_record.title
583 due_date : new Date().toISOString(),
586 renewal_remaining : 2
589 title : seed_record.title,
590 author : seed_record.author,
591 call_number : seed_copy.call_number
605 title : seed_record.title
609 previous_balance : 8.45,
610 payment_total : 2.00,
611 payment_applied : 2.00,
615 payment_type : 'cash_payment',
616 payment_note : 'Here is a payment note',
617 approval_code : 'CH1234567',
619 create_date : new Date().toISOString(),
620 title : 'Test Note Title',
622 value : 'This patron is super nice!'
625 transit : seed_transit,
626 transits : [ seed_transit ],
627 title : seed_record.title,
628 author : seed_record.author,
631 dest_location : egCore.idl.toHash(egCore.org.get(egCore.auth.user().ws_ou())),
632 dest_courier_code : 'ABC 123',
633 dest_address : seed_addr,
637 hold : one_hold, title : 'Some Title 1', author : 'Some Author 1',
638 volume : { label : '646.4 SOM' }, copy : seed_copy,
639 part : { label : 'v. 1' },
640 patron_barcode : 'S52802662',
641 patron_alias : 'XYZ', patron_last : 'Smith', patron_first : 'Jane',
642 status_string : 'Ready for Pickup'
645 hold : one_hold, title : 'Some Title 2', author : 'Some Author 2',
646 volume : { label : '646.4 SOM' }, copy : seed_copy,
647 part : { label : 'v. 1' },
648 patron_barcode : 'S52802662',
649 patron_alias : 'XYZ', patron_last : 'Smith', patron_first : 'Jane',
650 status_string : 'Ready for Pickup'
653 hold : one_hold, title : 'Some Title 3', author : 'Some Author 3',
654 volume : { label : '646.4 SOM' }, copy : seed_copy,
655 part : { label : 'v. 1' },
656 patron_barcode : 'S52802662',
657 patron_alias : 'XYZ', patron_last : 'Smith', patron_first : 'Jane',
658 status_string : 'Canceled'
663 $scope.preview_scope.payments = [
664 {amount : 1.00, xact : $scope.preview_scope.transactions[0]},
665 {amount : 1.00, xact : $scope.preview_scope.transactions[1]}
667 $scope.preview_scope.payments[0].xact.title = 'Hali Bote Azikaban de tao fan';
668 $scope.preview_scope.payments[0].xact.copy_barcode = '334343434';
669 $scope.preview_scope.payments[1].xact.title = seed_record.title;
670 $scope.preview_scope.payments[1].xact.copy_barcode = seed_copy.barcode;
672 // today, staff, current_location, etc.
673 egCore.print.fleshPrintScope($scope.preview_scope);
675 $scope.template_changed = function() {
676 $scope.print.load_failed = false;
677 egCore.print.getPrintTemplate($scope.print.template_name)
680 $scope.print.template_content = html;
681 console.log('set template content');
684 $scope.print.template_content = '';
685 $scope.print.load_failed = true;
688 egCore.print.getPrintTemplateContext($scope.print.template_name)
689 .then(function(template_context) {
690 $scope.print.template_context = template_context;
694 $scope.reset_to_default = function() {
695 egCore.print.removePrintTemplate(
696 $scope.print.template_name
698 egCore.print.removePrintTemplateContext(
699 $scope.print.template_name
701 $scope.template_changed();
704 $scope.save_locally = function() {
705 egCore.print.storePrintTemplate(
706 $scope.print.template_name,
707 $scope.print.template_content
709 egCore.print.storePrintTemplateContext(
710 $scope.print.template_name,
711 $scope.print.template_context
715 $scope.exportable_templates = function() {
718 var deferred = $q.defer();
720 egCore.hatch.getKeys('eg.print.template').then(function(keys) {
721 angular.forEach(keys, function(key) {
722 if (key.match(/^eg\.print\.template\./)) {
723 promises.push(egCore.hatch.getItem(key).then(function(value) {
724 templates[key.replace('eg.print.template.', '')] = value;
727 promises.push(egCore.hatch.getItem(key).then(function(value) {
728 contexts[key.replace('eg.print.template_context.', '')] = value;
732 $q.all(promises).then(function() {
733 if (Object.keys(templates).length) {
735 templates: templates,
739 ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_EXPORT);
744 return deferred.promise;
747 $scope.imported_print_templates = { data : '' };
748 $scope.$watch('imported_print_templates.data', function(newVal, oldVal) {
749 if (newVal && newVal != oldVal) {
751 var data = JSON.parse(newVal);
752 angular.forEach(data.templates, function(template_content, template_name) {
753 egCore.print.storePrintTemplate(template_name, template_content);
755 angular.forEach(data.contexts, function(template_context, template_name) {
756 egCore.print.storePrintTemplateContext(template_name, template_context);
758 $scope.template_changed(); // refresh
759 ngToast.create(egCore.strings.PRINT_TEMPLATES_SUCCESS_IMPORT);
761 ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_IMPORT);
766 $scope.template_changed(); // load the default
770 .directive('egPrintTemplateOutput', ['$compile',function($compile) {
771 return function(scope, element, attrs) {
774 return scope.$eval(attrs.content);
777 // create an isolate scope and copy the print context
778 // data into the new scope.
779 // TODO: see also print security concerns in egHatch
780 var result = element.html(value);
781 var context = scope.$eval(attrs.context);
782 var print_scope = scope.$new(true);
783 angular.forEach(context, function(val, key) {
784 print_scope[key] = val;
786 $compile(element.contents())(print_scope);
792 .controller('StoredPrefsCtrl',
793 ['$scope','$q','egCore','egConfirmDialog',
794 function($scope , $q , egCore , egConfirmDialog) {
795 console.log('StoredPrefsCtrl');
797 $scope.setContext = function(ctx) {
798 $scope.context = ctx;
800 $scope.setContext('local');
802 // grab the edit perm
803 $scope.userHasDeletePerm = false;
804 egCore.perm.hasPermHere('ADMIN_WORKSTATION')
805 .then(function(bool) { $scope.userHasDeletePerm = bool });
809 function refreshKeys() {
810 $scope.keys = {local : [], remote : [], server_workstation: []};
812 if (egCore.hatch.hatchAvailable) {
813 egCore.hatch.getRemoteKeys().then(
814 function(keys) { $scope.keys.remote = keys.sort() })
817 // local calls are non-async
818 $scope.keys.local = egCore.hatch.getLocalKeys();
820 egCore.hatch.getServerKeys(null, {workstation_only: true}).then(
821 function(keys) {$scope.keys.server_workstation = keys});
825 $scope.selectKey = function(key) {
826 $scope.currentKey = key;
827 $scope.currentKeyContent = null;
829 if ($scope.context == 'local') {
830 $scope.currentKeyContent = egCore.hatch.getLocalItem(key);
831 } else if ($scope.context == 'remote') {
832 egCore.hatch.getRemoteItem(key)
833 .then(function(content) {
834 $scope.currentKeyContent = content
836 } else if ($scope.context == 'server_workstation') {
837 egCore.hatch.getServerItem(key).then(function(content) {
838 $scope.currentKeyContent = content;
843 $scope.getCurrentKeyContent = function() {
844 return JSON.stringify($scope.currentKeyContent, null, 2);
847 $scope.removeKey = function(key) {
848 egConfirmDialog.open(
849 egCore.strings.PREFS_REMOVE_KEY_CONFIRM, '',
852 if ($scope.context == 'local') {
853 egCore.hatch.removeLocalItem(key);
855 } else if ($scope.context == 'remote') {
856 // Honor requests to remove items from Hatch even
857 // when Hatch is configured for data storage.
858 egCore.hatch.removeRemoteItem(key)
859 .then(function() { refreshKeys() });
860 } else if ($scope.context == 'server_workstation') {
861 egCore.hatch.removeServerItem(key)
862 .then(function() { refreshKeys() });
865 cancel : function() {} // user canceled, nothing to do
871 .controller('WSRegCtrl',
872 ['$scope','$q','$window','$location','egCore','egAlertDialog','workstationSvc',
873 function($scope , $q , $window , $location , egCore , egAlertDialog , workstationSvc) {
875 var all_workstations = [];
876 var reg_perm_orgs = [];
878 $scope.page_loaded = false;
879 $scope.contextOrg = egCore.org.get(egCore.auth.user().ws_ou());
880 $scope.wsOrgChanged = function(org) { $scope.contextOrg = org; }
882 console.log('set context org to ' + $scope.contextOrg);
884 egCore.hatch.hostname().then(function(name) {
885 $scope.newWSName = name || '';
888 // fetch workstation reg perms
889 egCore.perm.hasPermAt('REGISTER_WORKSTATION', true)
890 .then(function(orgList) {
891 reg_perm_orgs = orgList;
893 // hide orgs in the context org selector where this login
894 // does not have the reg_ws perm or the org can't have users
895 $scope.wsOrgHidden = function(id) {
896 return reg_perm_orgs.indexOf(id) == -1
897 || $scope.cant_have_users(id);
900 // fetch the locally stored workstation data
902 return workstationSvc.get_all()
904 }).then(function(all) {
905 all_workstations = all || [];
906 $scope.workstations =
907 all_workstations.map(function(w) { return w.name });
908 return workstationSvc.get_default()
910 // fetch the default workstation
911 }).then(function(def) {
912 $scope.defaultWS = def;
913 $scope.activeWS = $scope.selectedWS = egCore.auth.workstation() || def;
915 // Handle any URL commands.
917 var remove = $location.search().remove;
919 console.log('Removing WS via URL request: ' + remove);
920 return $scope.remove_ws(remove).then(
921 function() { $scope.page_loaded = true; });
923 $scope.page_loaded = true;
926 $scope.get_ws_label = function(ws) {
927 return ws == $scope.defaultWS ?
928 egCore.strings.$replace(egCore.strings.DEFAULT_WS_LABEL, {ws:ws}) : ws;
931 $scope.set_default_ws = function(name) {
932 delete $scope.removing_ws;
933 $scope.defaultWS = name;
934 workstationSvc.set_default(name);
937 $scope.cant_have_users =
938 function (id) { return !egCore.org.CanHaveUsers(id); };
939 $scope.cant_have_volumes =
940 function (id) { return !egCore.org.CanHaveVolumes(id); };
942 // Log out and return to login page with selected WS
943 $scope.use_now = function() {
944 egCore.auth.logout();
945 $window.location.href = $location
947 .search({ws : $scope.selectedWS})
951 $scope.can_delete_ws = function(name) {
952 var ws = all_workstations.filter(
953 function(ws) { return ws.name == name })[0];
954 return ws && reg_perm_orgs.indexOf(ws.owning_lib) != -1;
957 $scope.remove_ws = function(remove_me) {
958 $scope.removing_ws = remove_me;
960 // Perm is used to disable Remove button in UI, but have to check
961 // again here in case we're removing a WS based on URL params.
962 if (!$scope.can_delete_ws(remove_me)) return $q.when();
964 $scope.is_removing = true;
965 return workstationSvc.remove_workstation(remove_me)
968 all_workstations = all_workstations.filter(
969 function(ws) { return ws.name != remove_me });
971 $scope.workstations = $scope.workstations.filter(
972 function(ws) { return ws != remove_me });
974 if ($scope.selectedWS == remove_me)
975 $scope.selectedWS = $scope.workstations[0];
977 if ($scope.defaultWS == remove_me)
978 $scope.defaultWS = '';
980 $scope.is_removing = false;
984 $scope.register_ws = function() {
985 delete $scope.removing_ws;
988 $scope.contextOrg.shortname() + '-' + $scope.newWSName;
990 if ($scope.workstations.indexOf(full_name) > -1) {
991 // avoid duplicate local registrations
992 return egAlertDialog.open(egCore.strings.WS_USED);
995 $scope.is_registering = true;
996 workstationSvc.register_workstation(
997 $scope.newWSName, full_name,
998 $scope.contextOrg.id()
1000 ).then(function(new_ws) {
1001 $scope.workstations.push(new_ws.name);
1002 all_workstations.push(new_ws);
1003 $scope.is_registering = false;
1005 if (!$scope.selectedWS) {
1006 $scope.selectedWS = new_ws.name;
1008 if (!$scope.defaultWS) {
1009 return $scope.set_default_ws(new_ws.name);
1011 $scope.newWSName = '';
1013 $scope.is_registering = false;
1018 .controller('HatchCtrl',
1019 ['$scope','egCore','ngToast',
1020 function($scope , egCore , ngToast) {
1021 var hatch = egCore.hatch; // convenience
1023 $scope.hatch_available = hatch.hatchAvailable;
1025 hatch.usePrinting().then(function(answer) {
1026 $scope.hatch_printing = answer;
1029 // Apply Hatch settings as changes occur in the UI.
1031 $scope.$watch('hatch_printing', function(newval) {
1032 if (typeof newval != 'boolean') return;
1033 hatch.setItem('eg.hatch.enable.printing', newval);
1038 * Home of the Latency tester
1040 .controller('testsCtrl', ['$scope', '$location', 'egCore', function($scope, $location, egCore) {
1041 $scope.hostname = $location.host();
1044 $scope.clearTestData = function(){
1049 $scope.isTesting = false;
1050 $scope.avrg = 0; // avrg latency
1051 $scope.canCopyCommand = document.queryCommandSupported('copy');
1053 // initially fetch first 10 (gets a decent average)
1055 function calcAverage(){
1057 if ($scope.tests.length == 0) return 0;
1059 if ($scope.tests.length == 1) return $scope.tests[0].l;
1062 angular.forEach($scope.tests, function(t){
1066 return sum / $scope.tests.length;
1070 $scope.isTesting = true;
1072 return egCore.net.request(
1073 "open-ils.pcrud", "opensrf.system.echo", "ping"
1074 ).then(function(resp){
1075 var t2 = Date.now();
1076 var latency = t2 - t;
1077 $scope.tests.push({t: new Date(t), l: latency});
1078 console.log("Start: " + t + " and end: " + t2);
1079 console.log("Latency: " + latency);
1082 $scope.avrg = calcAverage();
1084 $scope.isTesting = false;
1088 $scope.testLatency = function(){
1090 if (numPings >= 10){
1091 ping(); // just ping once after the initial ten
1094 .then($scope.testLatency)
1097 $scope.tests.shift(); // toss first result
1098 $scope.avrg = calcAverage();
1104 $scope.copyTests = function(){
1106 var lNode = document.querySelector('#pingData');
1107 var r = document.createRange();
1108 r.selectNode(lNode);
1109 var sel = window.getSelection();
1110 sel.removeAllRanges();
1112 document.execCommand('copy');