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/tests', {
42 templateUrl: './admin/workstation/t_tests',
43 controller: 'testsCtrl',
48 $routeProvider.otherwise({
49 templateUrl : './admin/workstation/t_splash',
50 controller : 'SplashCtrl',
55 .config(['ngToastProvider', function(ngToastProvider) {
56 ngToastProvider.configure({
57 verticalPosition: 'bottom',
62 .factory('workstationSvc',
63 ['$q','$timeout','$location','egCore','egConfirmDialog',
64 function($q , $timeout , $location , egCore , egConfirmDialog) {
68 service.get_all = function() {
69 return egCore.hatch.getWorkstations()
70 .then(function(all) { return all || [] });
73 service.get_default = function() {
74 return egCore.hatch.getDefaultWorkstation();
77 service.set_default = function(name) {
78 return egCore.hatch.setDefaultWorkstation(name);
81 service.register_workstation = function(base_name, name, org_id) {
82 return service.register_ws_api(base_name, name, org_id)
83 .then(function(ws_id) {
84 return service.track_new_ws(ws_id, name, org_id);
88 service.register_ws_api =
89 function(base_name, name, org_id, override, deferred) {
90 if (!deferred) deferred = $q.defer();
92 var method = 'open-ils.actor.workstation.register';
93 if (override) method += '.override';
96 'open-ils.actor', method, egCore.auth.token(), name, org_id)
98 .then(function(resp) {
100 if (evt = egCore.evt.parse(resp)) {
101 console.log('register returned ' + evt.toString());
103 if (evt.textcode == 'WORKSTATION_NAME_EXISTS' && !override) {
105 egConfirmDialog.open(
106 egCore.strings.WS_EXISTS, base_name, {
108 service.register_ws_api(
109 base_name, name, org_id, true, deferred)
111 cancel : function() {
118 alert(evt.toString());
122 console.log('Resolving register promise with: ' + resp);
123 deferred.resolve(resp);
127 return deferred.promise;
130 service.track_new_ws = function(ws_id, ws_name, owning_lib) {
131 console.log('Tracking newly created WS with ID ' + ws_id);
132 var new_ws = {id : ws_id, name : ws_name, owning_lib : owning_lib};
134 return service.get_all()
135 .then(function(all) {
137 return egCore.hatch.setWorkstations(all)
138 .then(function() { return new_ws });
142 // Remove all traces of the workstation locally.
143 // This does not remove the WS from the server.
144 service.remove_workstation = function(name) {
145 console.debug('Removing workstation: ' + name);
147 return egCore.hatch.getWorkstations()
149 // remove from list of all workstations
150 .then(function(all) {
152 var keep = all.filter(function(ws) {return ws.name != name});
153 return egCore.hatch.setWorkstations(keep);
157 return service.get_default()
159 }).then(function(def) {
161 console.debug('Removing default workstation: ' + name);
162 return egCore.hatch.removeDefaultWorkstation();
171 .controller('SplashCtrl',
172 ['$scope','$window','$location','egCore','egConfirmDialog',
173 function($scope , $window , $location , egCore , egConfirmDialog) {
175 egCore.hatch.getItem('eg.audio.disable').then(function(val) {
176 $scope.disable_sound = val;
179 egCore.hatch.getItem('eg.orgselect.show_combined_names').then(function(val) {
180 $scope.orgselect_combo_names = val;
183 egCore.hatch.getItem('eg.search.search_lib').then(function(val) {
184 $scope.search_lib = egCore.org.get(val);
186 $scope.handle_search_lib_changed = function(org) {
187 egCore.hatch.setItem('eg.search.search_lib', org.id());
190 egCore.hatch.getItem('eg.search.pref_lib').then(function(val) {
191 $scope.pref_lib = egCore.org.get(val);
193 $scope.handle_pref_lib_changed = function(org) {
194 egCore.hatch.setItem('eg.search.pref_lib', org.id());
197 $scope.adv_pane = 'advanced'; // default value if not explicitly set
198 egCore.hatch.getItem('eg.search.adv_pane').then(function(val) {
199 $scope.adv_pane = val;
201 $scope.$watch('adv_pane', function(newVal, oldVal) {
202 if (typeof newVal != 'undefined' && newVal != oldVal) {
203 egCore.hatch.setItem('eg.search.adv_pane', newVal);
207 $scope.apply_sound = function() {
208 if ($scope.disable_sound) {
209 egCore.hatch.setItem('eg.audio.disable', true);
211 egCore.hatch.removeItem('eg.audio.disable');
215 $scope.apply_orgselect_combob_names = function() {
216 if ($scope.orgselect_combo_names) {
217 egCore.hatch.setItem('eg.orgselect.show_combined_names', true);
219 egCore.hatch.removeItem('eg.orgselect.show_combined_names');
223 $scope.test_audio = function(sound) {
224 egCore.audio.play(sound);
229 .controller('PrintConfigCtrl',
231 function($scope , egCore) {
233 $scope.printConfig = {};
234 $scope.setContext = function(ctx) {
235 $scope.context = ctx;
236 $scope.isTestView = false;
238 $scope.setContext('default');
240 $scope.setContentType = function(type) { $scope.contentType = type }
241 $scope.setContentType('text/plain');
243 var hatchPrinting = false;
244 egCore.hatch.usePrinting().then(function(answer) {
245 hatchPrinting = answer;
248 $scope.useHatchPrinting = function() {
249 return hatchPrinting;
252 $scope.hatchIsOpen = function() {
253 return egCore.hatch.hatchAvailable;
256 $scope.getPrinterByAttr = function(attr, value) {
258 angular.forEach($scope.printers, function(p) {
259 if (p[attr] == value) printer = p;
264 $scope.resetPrinterSettings = function(context) {
265 $scope.printConfig[context] = {
267 printer : $scope.defaultPrinter ? $scope.defaultPrinter.name : null,
274 $scope.savePrinterSettings = function(context) {
275 return egCore.hatch.setPrintConfig(
276 context, $scope.printConfig[context]);
279 $scope.printerConfString = function() {
280 if ($scope.printConfigError) return $scope.printConfigError;
281 if (!$scope.printConfig) return;
282 if (!$scope.printConfig[$scope.context]) return;
283 return JSON.stringify(
284 $scope.printConfig[$scope.context], undefined, 2);
287 function loadPrinterOptions(name) {
288 if (name == 'hatch_file_writer' || name == 'hatch_browser_printing') {
289 $scope.printerOptions = {};
291 egCore.hatch.getPrinterOptions(name).then(
292 function(options) {$scope.printerOptions = options});
296 $scope.setPrinter = function(name) {
297 $scope.printConfig[$scope.context].printer = name;
298 loadPrinterOptions(name);
301 $scope.testPrint = function(withDialog) {
302 if ($scope.contentType == 'text/plain') {
304 context : $scope.context,
305 content_type : $scope.contentType,
306 content : $scope.textPrintContent,
307 show_dialog : withDialog
311 context : $scope.context,
312 content_type : $scope.contentType,
313 content : $scope.htmlPrintContent,
315 value1 : 'Value One',
316 value2 : 'Value Two',
317 date_value : '2015-02-04T14:04:34-0400'
319 show_dialog : withDialog
324 $scope.useFileWriter = function() {
326 $scope.printConfig[$scope.context] &&
327 $scope.printConfig[$scope.context].printer == 'hatch_file_writer'
331 $scope.useBrowserPrinting = function() {
333 $scope.printConfig[$scope.context] &&
334 $scope.printConfig[$scope.context].printer == 'hatch_browser_printing'
339 // Load startup data....
340 // Don't bother talking to Hatch if it's not there.
341 if (!egCore.hatch.hatchAvailable) return;
343 // fetch info on all remote printers
344 egCore.hatch.getPrinters()
345 .then(function(printers) {
346 $scope.printers = printers;
349 // We need a static name for saving configs.
350 // Human-friendly label is set in the template.
351 name: 'hatch_file_writer'
354 printers.push({name: 'hatch_browser_printing'});
356 var def = $scope.getPrinterByAttr('is-default', true);
357 if (!def && printers.length) def = printers[0];
360 $scope.defaultPrinter = def;
361 loadPrinterOptions(def.name);
365 ['default','receipt','label','mail','offline'],
367 egCore.hatch.getPrintConfig(ctx).then(function(conf) {
369 $scope.printConfig[ctx] = conf;
371 $scope.resetPrinterSettings(ctx);
380 .controller('PrintTemplatesCtrl',
381 ['$scope','$q','egCore','ngToast',
382 function($scope , $q , egCore , ngToast) {
385 template_name : 'bills_current',
386 template_output : '',
387 template_context : 'default'
390 // print preview scope data
391 // TODO: consider moving the template-specific bits directly
392 // into the templates or storing template- specific script files
393 // alongside the templates.
394 // NOTE: A lot of this data can be shared across templates.
397 first_given_name : 'Joseph',
398 second_given_name : 'Martin',
399 family_name : 'Jones',
401 pref_first_given_name : 'Martin',
402 pref_second_given_name : 'Joe',
403 pref_family_name : 'Smith',
405 barcode : '30393830393'
408 balance_owed : 4, // This is currently how these values are returned to the client
409 total_billed : '5.00',
412 expire_date : '2020-12-31',
416 dob : '1980-01-01T00:00:00-8:00',
418 usrname : '30393830393',
419 day_phone : '111-222-3333',
420 evening_phone : '222-333-1111',
421 other_phone : '333-111-2222',
422 email : 'user@example.com',
423 home_ou : {name: function() {return 'BR1'}},
424 profile : {name: function() {return 'Patrons'}},
425 net_access_level : {name: function() {return 'Filtered'}},
428 master_account : 'f',
429 claims_returned_count : '0',
430 claims_never_checked_out_count : '0',
431 ident_type: {name: function() {return 'Drivers License'}},
432 ident_value: '11332445',
433 ident_type2: {name: function() {return 'Other'}},
434 ident_value2 : '55442211',
438 stat_cat : {'name' : 'Favorite Donut'},
439 'stat_cat_entry' : 'Maple'
441 stat_cat : {'name' : 'Favorite Book'},
442 'stat_cat_entry' : 'Beasts Made of Night'
448 'id' : function() {return '1'},
449 'description' : function() {return 'Voter Registration'},
453 'answer_date' : function() {return '2020-12-31'},
454 question : function() {return {'question' : function() {return 'Would you like to register to vote today?'}}},
455 answer : function() {return {'answer' : function() {return 'Already registered'}}}
463 address_type : 'MAILING',
464 street1 : '123 Apple Rd',
467 county : 'Great County',
472 within_city_limits: 't'
475 seed_user.addresses.push(seed_addr);
478 title : 'Traveling Pants!!',
479 author : 'Jane Jones',
484 barcode : '33434322323',
492 'title' : 'Test Title'
496 name : 'Ankers Memorial Library',
504 name : 'General Collection'
509 // flattened versions for item status template
510 // TODO - make this go away
511 'call_number.label' : '636.8 JON',
512 'call_number.record.simple_record.title' : 'Test Title',
513 'location.name' : 'General Collection',
514 'call_number.owning_lib.name' : 'Ankers Memorial Library',
515 'call_number.owning_lib.shortname' : 'Ankers',
516 'location.name' : 'General Collection'
521 phone_notify : '111-222-3333',
522 sms_notify : '111-222-3333',
523 email_notify : 'user@example.org',
524 request_time : new Date().toISOString(),
526 shelf_expire_time : new Date().toISOString()
533 holds_address : seed_addr
538 holds_address : seed_addr
540 source_send_time : new Date().toISOString(),
541 target_copy : seed_copy
544 $scope.preview_scope = {
549 xact_start : new Date().toISOString(),
550 xact_finish : new Date().toISOString(),
553 prefix : "biography",
554 suffix : "Closed Stacks",
556 name : "Mineola Public Library",
557 shortname : "Mineola"
561 xact_type : 'circulation',
562 last_billing_type : 'Overdue materials',
564 last_payment_note : 'Test Note 1',
565 last_payment_type : 'cash_payment',
566 last_payment_ts : new Date().toISOString(),
572 xact_start : new Date().toISOString(),
573 xact_finish : new Date().toISOString(),
579 name : "Rogers Reading Room",
584 xact_type : 'circulation',
585 last_billing_type : 'Overdue materials',
587 last_payment_note : 'Test Note 2',
588 last_payment_type : 'credit_payment',
589 last_payment_ts : new Date().toISOString(),
597 copies : [ seed_copy ],
601 due_date : new Date().toISOString(),
604 target_copy : seed_copy,
605 copy_barcode : seed_copy.barcode,
606 call_number : seed_copy.call_number,
607 title : seed_record.title
614 due_date : new Date().toISOString(),
617 renewal_remaining : 2
620 title : seed_record.title,
621 author : seed_record.author,
622 call_number : seed_copy.call_number
636 title : seed_record.title
640 previous_balance : 8.45,
641 payment_total : 2.00,
642 payment_applied : 2.00,
646 payment_type : 'cash_payment',
647 payment_note : 'Here is a payment note',
648 approval_code : 'CH1234567',
650 create_date : new Date().toISOString(),
651 title : 'Test Note Title',
653 value : 'This patron is super nice!'
656 transit : seed_transit,
657 transits : [ seed_transit ],
658 title : seed_record.title,
659 author : seed_record.author,
662 dest_location : egCore.idl.toHash(egCore.org.get(egCore.auth.user().ws_ou())),
663 dest_courier_code : 'ABC 123',
664 dest_address : seed_addr,
665 source_address : seed_addr,
666 source_location : egCore.idl.toHash(egCore.org.get(egCore.auth.user().ws_ou())),
670 hold : one_hold, title : 'Some Title 1', author : 'Some Author 1',
671 volume : { label : '646.4 SOM' }, copy : seed_copy,
672 part : { label : 'v. 1' },
673 patron_barcode : 'S52802662',
674 patron_alias : 'XYZ', patron_last : 'Smith', patron_first : 'Jane',
675 status_string : 'Ready for Pickup'
678 hold : one_hold, title : 'Some Title 2', author : 'Some Author 2',
679 volume : { label : '646.4 SOM' }, copy : seed_copy,
680 part : { label : 'v. 1' },
681 patron_barcode : 'S52802662',
682 patron_alias : 'XYZ', patron_last : 'Smith', patron_first : 'Jane',
683 status_string : 'Ready for Pickup'
686 hold : one_hold, title : 'Some Title 3', author : 'Some Author 3',
687 volume : { label : '646.4 SOM' }, copy : seed_copy,
688 part : { label : 'v. 1' },
689 patron_barcode : 'S52802662',
690 patron_alias : 'XYZ', patron_last : 'Smith', patron_first : 'Jane',
691 status_string : 'Canceled'
696 $scope.preview_scope.payments = [
697 {amount : 1.00, xact : $scope.preview_scope.transactions[0]},
698 {amount : 1.00, xact : $scope.preview_scope.transactions[1]}
700 $scope.preview_scope.payments[0].xact.title = 'Hali Bote Azikaban de tao fan';
701 $scope.preview_scope.payments[0].xact.copy_barcode = '334343434';
702 $scope.preview_scope.payments[1].xact.title = seed_record.title;
703 $scope.preview_scope.payments[1].xact.copy_barcode = seed_copy.barcode;
705 // today, staff, current_location, etc.
706 egCore.print.fleshPrintScope($scope.preview_scope);
708 $scope.template_changed = function() {
709 $scope.print.load_failed = false;
710 egCore.print.getPrintTemplate($scope.print.template_name)
713 $scope.print.template_content = html;
714 console.log('set template content');
717 $scope.print.template_content = '';
718 $scope.print.load_failed = true;
721 egCore.print.getPrintTemplateContext($scope.print.template_name)
722 .then(function(template_context) {
723 $scope.print.template_context = template_context;
727 $scope.reset_to_default = function() {
728 egCore.print.removePrintTemplate(
729 $scope.print.template_name
731 egCore.print.removePrintTemplateContext(
732 $scope.print.template_name
734 $scope.template_changed();
737 $scope.save_locally = function() {
738 egCore.print.storePrintTemplate(
739 $scope.print.template_name,
740 $scope.print.template_content
742 egCore.print.storePrintTemplateContext(
743 $scope.print.template_name,
744 $scope.print.template_context
748 $scope.exportable_templates = function() {
751 var deferred = $q.defer();
753 egCore.hatch.getKeys('eg.print.template').then(function(keys) {
754 angular.forEach(keys, function(key) {
755 if (key.match(/^eg\.print\.template\./)) {
756 promises.push(egCore.hatch.getItem(key).then(function(value) {
757 templates[key.replace('eg.print.template.', '')] = value;
760 promises.push(egCore.hatch.getItem(key).then(function(value) {
761 contexts[key.replace('eg.print.template_context.', '')] = value;
765 $q.all(promises).then(function() {
766 if (Object.keys(templates).length) {
768 templates: templates,
772 ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_EXPORT);
777 return deferred.promise;
780 $scope.imported_print_templates = { data : '' };
781 $scope.$watch('imported_print_templates.data', function(newVal, oldVal) {
782 if (newVal && newVal != oldVal) {
784 var data = JSON.parse(newVal);
785 angular.forEach(data.templates, function(template_content, template_name) {
786 egCore.print.storePrintTemplate(template_name, template_content);
788 angular.forEach(data.contexts, function(template_context, template_name) {
789 egCore.print.storePrintTemplateContext(template_name, template_context);
791 $scope.template_changed(); // refresh
792 ngToast.create(egCore.strings.PRINT_TEMPLATES_SUCCESS_IMPORT);
794 ngToast.warning(egCore.strings.PRINT_TEMPLATES_FAIL_IMPORT);
799 $scope.template_changed(); // load the default
803 .directive('egPrintTemplateOutput', ['$compile',function($compile) {
804 return function(scope, element, attrs) {
807 return scope.$eval(attrs.content);
810 // create an isolate scope and copy the print context
811 // data into the new scope.
812 // TODO: see also print security concerns in egHatch
813 var result = element.html(value);
814 var context = scope.$eval(attrs.context);
815 var print_scope = scope.$new(true);
816 angular.forEach(context, function(val, key) {
817 print_scope[key] = val;
819 $compile(element.contents())(print_scope);
825 .controller('StoredPrefsCtrl',
826 ['$scope','$q','egCore','egConfirmDialog',
827 function($scope , $q , egCore , egConfirmDialog) {
828 console.log('StoredPrefsCtrl');
830 $scope.setContext = function(ctx) {
831 $scope.context = ctx;
833 $scope.setContext('local');
835 // grab the edit perm
836 $scope.userHasDeletePerm = false;
837 egCore.perm.hasPermHere('ADMIN_WORKSTATION')
838 .then(function(bool) { $scope.userHasDeletePerm = bool });
842 function refreshKeys() {
843 $scope.keys = {local : [], remote : [], server_workstation: []};
845 if (egCore.hatch.hatchAvailable) {
846 egCore.hatch.getRemoteKeys().then(
847 function(keys) { $scope.keys.remote = keys.sort() })
850 // local calls are non-async
851 $scope.keys.local = egCore.hatch.getLocalKeys();
853 egCore.hatch.getServerKeys(null, {workstation_only: true}).then(
854 function(keys) {$scope.keys.server_workstation = keys});
858 $scope.selectKey = function(key) {
859 $scope.currentKey = key;
860 $scope.currentKeyContent = null;
862 if ($scope.context == 'local') {
863 $scope.currentKeyContent = egCore.hatch.getLocalItem(key);
864 } else if ($scope.context == 'remote') {
865 egCore.hatch.getRemoteItem(key)
866 .then(function(content) {
867 $scope.currentKeyContent = content
869 } else if ($scope.context == 'server_workstation') {
870 egCore.hatch.getServerItem(key).then(function(content) {
871 $scope.currentKeyContent = content;
876 $scope.getCurrentKeyContent = function() {
877 return JSON.stringify($scope.currentKeyContent, null, 2);
880 $scope.removeKey = function(key) {
881 egConfirmDialog.open(
882 egCore.strings.PREFS_REMOVE_KEY_CONFIRM, '',
885 if ($scope.context == 'local') {
886 egCore.hatch.removeLocalItem(key);
888 } else if ($scope.context == 'remote') {
889 // Honor requests to remove items from Hatch even
890 // when Hatch is configured for data storage.
891 egCore.hatch.removeRemoteItem(key)
892 .then(function() { refreshKeys() });
893 } else if ($scope.context == 'server_workstation') {
894 egCore.hatch.removeServerItem(key)
895 .then(function() { refreshKeys() });
898 cancel : function() {} // user canceled, nothing to do
904 .controller('WSRegCtrl',
905 ['$scope','$q','$window','$location','egCore','egAlertDialog','workstationSvc',
906 function($scope , $q , $window , $location , egCore , egAlertDialog , workstationSvc) {
908 var all_workstations = [];
909 var reg_perm_orgs = [];
911 $scope.page_loaded = false;
912 $scope.contextOrg = egCore.org.get(egCore.auth.user().ws_ou());
913 $scope.wsOrgChanged = function(org) { $scope.contextOrg = org; }
915 console.log('set context org to ' + $scope.contextOrg);
917 egCore.hatch.hostname().then(function(name) {
918 $scope.newWSName = name || '';
921 // fetch workstation reg perms
922 egCore.perm.hasPermAt('REGISTER_WORKSTATION', true)
923 .then(function(orgList) {
924 reg_perm_orgs = orgList;
926 // hide orgs in the context org selector where this login
927 // does not have the reg_ws perm or the org can't have users
928 $scope.wsOrgHidden = function(id) {
929 return reg_perm_orgs.indexOf(id) == -1
930 || $scope.cant_have_users(id);
933 // fetch the locally stored workstation data
935 return workstationSvc.get_all()
937 }).then(function(all) {
938 all_workstations = all || [];
939 $scope.workstations =
940 all_workstations.map(function(w) { return w.name });
941 return workstationSvc.get_default()
943 // fetch the default workstation
944 }).then(function(def) {
945 $scope.defaultWS = def;
946 $scope.activeWS = $scope.selectedWS = egCore.auth.workstation() || def;
948 // Handle any URL commands.
950 var remove = $location.search().remove;
952 console.log('Removing WS via URL request: ' + remove);
953 return $scope.remove_ws(remove).then(
954 function() { $scope.page_loaded = true; });
956 $scope.page_loaded = true;
959 $scope.get_ws_label = function(ws) {
960 return ws == $scope.defaultWS ?
961 egCore.strings.$replace(egCore.strings.DEFAULT_WS_LABEL, {ws:ws}) : ws;
964 $scope.set_default_ws = function(name) {
965 delete $scope.removing_ws;
966 $scope.defaultWS = name;
967 workstationSvc.set_default(name);
970 $scope.cant_have_users =
971 function (id) { return !egCore.org.CanHaveUsers(id); };
972 $scope.cant_have_volumes =
973 function (id) { return !egCore.org.CanHaveVolumes(id); };
975 // Log out and return to login page with selected WS
976 $scope.use_now = function() {
977 egCore.auth.logout();
978 $window.location.href = $location
980 .search({ws : $scope.selectedWS})
984 $scope.can_delete_ws = function(name) {
985 var ws = all_workstations.filter(
986 function(ws) { return ws.name == name })[0];
987 return ws && reg_perm_orgs.indexOf(ws.owning_lib) != -1;
990 $scope.remove_ws = function(remove_me) {
991 $scope.removing_ws = remove_me;
993 // Perm is used to disable Remove button in UI, but have to check
994 // again here in case we're removing a WS based on URL params.
995 if (!$scope.can_delete_ws(remove_me)) return $q.when();
997 $scope.is_removing = true;
998 return workstationSvc.remove_workstation(remove_me)
1001 all_workstations = all_workstations.filter(
1002 function(ws) { return ws.name != remove_me });
1004 $scope.workstations = $scope.workstations.filter(
1005 function(ws) { return ws != remove_me });
1007 if ($scope.selectedWS == remove_me)
1008 $scope.selectedWS = $scope.workstations[0];
1010 if ($scope.defaultWS == remove_me)
1011 $scope.defaultWS = '';
1013 $scope.is_removing = false;
1017 $scope.register_ws = function() {
1018 delete $scope.removing_ws;
1021 $scope.contextOrg.shortname() + '-' + $scope.newWSName;
1023 if ($scope.workstations.indexOf(full_name) > -1) {
1024 // avoid duplicate local registrations
1025 return egAlertDialog.open(egCore.strings.WS_USED);
1028 $scope.is_registering = true;
1029 workstationSvc.register_workstation(
1030 $scope.newWSName, full_name,
1031 $scope.contextOrg.id()
1033 ).then(function(new_ws) {
1034 $scope.workstations.push(new_ws.name);
1035 all_workstations.push(new_ws);
1036 $scope.is_registering = false;
1038 if (!$scope.selectedWS) {
1039 $scope.selectedWS = new_ws.name;
1041 if (!$scope.defaultWS) {
1042 return $scope.set_default_ws(new_ws.name);
1044 $scope.newWSName = '';
1046 $scope.is_registering = false;
1052 * Home of the Latency tester
1054 .controller('testsCtrl', ['$scope', '$location', 'egCore', function($scope, $location, egCore) {
1055 $scope.hostname = $location.host();
1058 $scope.clearTestData = function(){
1063 $scope.isTesting = false;
1064 $scope.avrg = 0; // avrg latency
1065 $scope.canCopyCommand = document.queryCommandSupported('copy');
1067 // initially fetch first 10 (gets a decent average)
1069 function calcAverage(){
1071 if ($scope.tests.length == 0) return 0;
1073 if ($scope.tests.length == 1) return $scope.tests[0].l;
1076 angular.forEach($scope.tests, function(t){
1080 return sum / $scope.tests.length;
1084 $scope.isTesting = true;
1086 return egCore.net.request(
1087 "open-ils.pcrud", "opensrf.system.echo", "ping"
1088 ).then(function(resp){
1089 var t2 = Date.now();
1090 var latency = t2 - t;
1091 $scope.tests.push({t: new Date(t), l: latency});
1092 console.log("Start: " + t + " and end: " + t2);
1093 console.log("Latency: " + latency);
1096 $scope.avrg = calcAverage();
1098 $scope.isTesting = false;
1102 $scope.testLatency = function(){
1104 if (numPings >= 10){
1105 ping(); // just ping once after the initial ten
1108 .then($scope.testLatency)
1111 $scope.tests.shift(); // toss first result
1112 $scope.avrg = calcAverage();
1118 $scope.copyTests = function(){
1120 var lNode = document.querySelector('#pingData');
1121 var r = document.createRange();
1122 r.selectNode(lNode);
1123 var sel = window.getSelection();
1124 sel.removeAllRanges();
1126 document.execCommand('copy');