}
return new Promise((resolve, reject) => {
- const workstations =
- this.store.getLocalItem('eg.workstation.all');
+ return this.store.getWorkstations().then(workstations => {
- if (workstations) {
- const ws = workstations.filter(
- w => Number(w.id) === Number(this.user().wsid()))[0];
+ if (workstations) {
+ const ws = workstations.filter(
+ w => Number(w.id) === Number(this.user().wsid()))[0];
- if (ws) {
- this.activeUser.workstation = ws.name;
- this.workstationState = AuthWsState.VALID;
- return resolve();
+ if (ws) {
+ this.activeUser.workstation = ws.name;
+ this.workstationState = AuthWsState.VALID;
+ return resolve();
+ }
}
- }
- this.workstationState = AuthWsState.NOT_FOUND_LOCAL;
- reject();
+ this.workstationState = AuthWsState.NOT_FOUND_LOCAL;
+ reject();
+ });
});
}
--- /dev/null
+import {Injectable, EventEmitter} from '@angular/core';
+
+export class HatchMessage {
+ msgid: number;
+ resolver: (HatchMessage) => void; // promise resolver
+ rejector: (HatchMessage) => void; // promise rejector
+ status: number;
+ message: string; // error message
+ from: string;
+ action: string;
+ settings: any;
+ content: string;
+ // Response from Hatch.
+ response: any;
+ contentType: string;
+ showDialog: boolean;
+
+ constructor(hash: any) {
+ if (hash) {
+ Object.keys(hash).forEach(key => this[key] = hash[key]);
+ }
+ }
+}
+
+@Injectable({providedIn: 'root'})
+export class HatchService {
+
+ isAvailable: boolean;
+ msgId: number;
+ messages: {[msgid: number]: HatchMessage};
+
+ constructor() {
+ this.isAvailable = null;
+ this.messages = {};
+ this.msgId = 1;
+ }
+
+ connect(): boolean {
+
+ if (this.isAvailable !== null) {
+ return this.isAvailable;
+ }
+
+ // When the Hatch extension loads, it tacks an attribute onto
+ // the top-level documentElement to indicate it's available.
+ if (!window.document.documentElement.getAttribute('hatch-is-open')) {
+ console.debug('Could not connect to Hatch');
+ return this.isAvailable = false;
+ }
+
+ window.addEventListener('message', event => {
+
+ // We only accept messages from our own content script.
+ if (event.source !== window) { return; }
+
+ // We only care about messages from the Hatch extension.
+ if (event.data && event.data.from === 'extension') {
+
+ // Avoid logging full Hatch responses. they can get large.
+ console.debug(
+ `Hatch responded to message ID ${event.data.msgid}`);
+
+ this.handleResponse(event.data);
+ }
+ });
+
+ return this.isAvailable = true;
+ }
+
+ // Send a request from the browser to Hatch.
+ sendRequest(msg: HatchMessage): Promise<HatchMessage> {
+ if (this.isAvailable === false) {
+ return Promise.reject('Hatch is not connected');
+ }
+
+ msg.msgid = this.msgId++;
+ msg.from = 'page';
+ this.messages[msg.msgid] = msg;
+ window.postMessage(msg, window.location.origin);
+
+ return new Promise((resolve, reject) => {
+ msg.resolver = resolve;
+ msg.rejector = reject;
+ });
+ }
+
+ // Handle the data sent back to the browser from Hatch.
+ handleResponse(data: any) {
+
+ const msg = this.messages[data.msgid];
+ if (!msg) {
+ console.warn(`No Hatch request found with ID ${data.msgid}`);
+ return;
+ }
+
+ delete this.messages[data.msgid];
+ msg.response = data.content;
+ msg.message = data.message;
+ msg.status = Number(data.status);
+
+ if (msg.status === 200) {
+ msg.resolver(msg);
+ } else {
+ console.error(`Hatch request returned status ${msg.status}`, msg);
+ msg.rejector(msg);
+ }
+ }
+
+ getItem(key: string): Promise<any> {
+ const msg = new HatchMessage({action: 'get', key: key});
+ return this.sendRequest(msg).then((m: HatchMessage) => m.response);
+ }
+
+ setItem(key: string, val: any): Promise<any> {
+ const msg = new HatchMessage({action: 'set', key: key, content: val});
+ return this.sendRequest(msg).then((m: HatchMessage) => m.response);
+ }
+
+ removeItem(key: string): Promise<any> {
+ const msg = new HatchMessage({action: 'remove', key: key});
+ return this.sendRequest(msg).then((m: HatchMessage) => m.response);
+ }
+}
+
*/
import {Injectable} from '@angular/core';
import {CookieService} from 'ngx-cookie';
+import {HatchService} from './hatch.service';
+
+const WS_ALL_KEY = 'eg.workstation.all';
+const WS_DEF_KEY = 'eg.workstation.default';
@Injectable({providedIn: 'root'})
export class StoreService {
];
constructor(
- private cookieService: CookieService) {
+ private cookieService: CookieService,
+ private hatch: HatchService) {
}
private parseJson(valJson: string): any {
{path : this.loginSessionBasePath, secure: true});
}
+ setWorkstations(val: any, isJson?: boolean): Promise<any> {
+ if (this.hatch.isAvailable) {
+ return this.hatch.setItem(WS_ALL_KEY, val).then(
+ ok => {
+ // When clearing workstations, remove the default.
+ if (!val || val.length === 0) {
+ return this.hatch.removeItem(WS_DEF_KEY);
+ }
+ }
+ );
+ } else {
+ return Promise.resolve(
+ this.setLocalItem(WS_ALL_KEY, val, isJson));
+ }
+ }
+
+ setDefaultWorkstation(val: string, isJson?: boolean): Promise<any> {
+ if (this.hatch.isAvailable) {
+ return this.hatch.setItem(WS_DEF_KEY, val);
+ } else {
+ return Promise.resolve(
+ this.setLocalItem(WS_DEF_KEY, val, isJson));
+ }
+ }
+
getLocalItem(key: string): any {
return this.parseJson(window.localStorage.getItem(key));
}
return this.parseJson(this.cookieService.get(key));
}
+ getWorkstations(): Promise<any> {
+ if (this.hatch.isAvailable) {
+ return this.mergeWorkstations().then(ok => {
+ this.removeLocalItem(WS_ALL_KEY);
+ return this.hatch.getItem(WS_ALL_KEY);
+ });
+ } else {
+ return Promise.resolve(this.getLocalItem(WS_ALL_KEY));
+ }
+ }
+
+ // See if any workstatoins are stored in local storage. If so, also
+ // see if we have any stored in Hatch. If both, merged workstations
+ // from localStorage in Hatch storage, skipping any whose name
+ // collide with a workstation in Hatch. If none exist in Hatch,
+ // copy the localStorage workstations over wholesale.
+ mergeWorkstations(): Promise<any> {
+ const existing = this.getLocalItem(WS_ALL_KEY);
+
+ if (!existing || existing.length === 0) {
+ return Promise.resolve();
+ }
+
+ return this.hatch.getItem(WS_ALL_KEY).then(inHatch => {
+
+ if (!inHatch || inHatch.length === 0) {
+ // Nothing to merge, copy the data over directly
+ return this.hatch.setItem('eg.workstation.all', existing);
+ }
+
+ const addMe: any = [];
+ existing.forEach(ws => {
+ const match = inHatch.filter(w => w.name === ws.name)[0];
+ if (!match) {
+ console.log(
+ 'Migrating workstation from local storage to hatch: '
+ + ws.name
+ );
+ addMe.push(ws);
+ }
+ });
+ inHatch = inHatch.concat(addMe);
+ return this.hatch.setItem(WS_ALL_KEY, inHatch);
+ });
+ }
+
+ getDefaultWorkstation(): Promise<any> {
+ if (this.hatch.isAvailable) {
+ return this.hatch.getItem(WS_DEF_KEY).then(name => {
+ if (name) {
+ // We have a default in Hatch, remove any lingering
+ // value from localStorage.
+ this.removeLocalItem(WS_DEF_KEY);
+ return name;
+ } else {
+ // Nothing in Hatch, see if we have a localStorage
+ // value to migrate to Hatch
+ name = this.getLocalItem(WS_DEF_KEY);
+ if (name) {
+ console.debug(
+ 'Migrating default workstation to Hatch ' + name);
+ return this.hatch.setItem(WS_DEF_KEY, name)
+ .then(ok => name);
+ } else {
+ return null;
+ }
+ }
+ });
+ } else {
+ return Promise.resolve(this.getLocalItem(WS_DEF_KEY));
+ }
+ }
+
removeLocalItem(key: string): void {
window.localStorage.removeItem(key);
}
this.cookieService.remove(key, {path : this.loginSessionBasePath});
}
+ removeDefaultWorkstation(val: string, isJson?: boolean): Promise<any> {
+ if (this.hatch.isAvailable) {
+ return this.hatch.removeItem(WS_DEF_KEY);
+ } else {
+ return Promise.resolve(
+ this.removeLocalItem(WS_DEF_KEY));
+ }
+ }
+
+
clearLoginSessionItems(): void {
this.loginSessionKeys.forEach(
key => this.removeLoginSessionItem(key)
+++ /dev/null
-import {Injectable, EventEmitter} from '@angular/core';
-
-export class HatchMessage {
- msgid: number;
- resolver: (HatchMessage) => void; // promise resolver
- rejector: (HatchMessage) => void; // promise rejector
- status: number;
- message: string; // error message
- from: string;
- action: string;
- settings: any;
- content: string;
- // Response from Hatch.
- response: any;
- contentType: string;
- showDialog: boolean;
-
- constructor(hash: any) {
- if (hash) {
- Object.keys(hash).forEach(key => this[key] = hash[key]);
- }
- }
-}
-
-@Injectable()
-export class HatchService {
-
- isAvailable: boolean;
- msgId: number;
- messages: {[msgid: number]: HatchMessage};
-
- constructor() {
- this.isAvailable = null;
- this.messages = {};
- this.msgId = 1;
- }
-
- connect(): boolean {
-
- if (this.isAvailable !== null) {
- return this.isAvailable;
- }
-
- // When the Hatch extension loads, it tacks an attribute onto
- // the top-level documentElement to indicate it's available.
- if (!window.document.documentElement.getAttribute('hatch-is-open')) {
- console.warn('Could not connect to Hatch');
- return this.isAvailable = false;
- }
-
- window.addEventListener('message', event => {
-
- // We only accept messages from our own content script.
- if (event.source !== window) { return; }
-
- // We only care about messages from the Hatch extension.
- if (event.data && event.data.from === 'extension') {
-
- // Avoid logging full Hatch responses. they can get large.
- console.debug(
- `Hatch responded to message ID ${event.data.msgid}`);
-
- this.handleResponse(event.data);
- }
- });
-
- return this.isAvailable = true;
- }
-
- // Send a request from the browser to Hatch.
- sendRequest(msg: HatchMessage): Promise<HatchMessage> {
- if (this.isAvailable === false) {
- return Promise.reject('Hatch is not connected');
- }
-
- msg.msgid = this.msgId++;
- msg.from = 'page';
- this.messages[msg.msgid] = msg;
- window.postMessage(msg, window.location.origin);
-
- return new Promise((resolve, reject) => {
- msg.resolver = resolve;
- msg.rejector = reject;
- });
- }
-
- // Handle the data sent back to the browser from Hatch.
- handleResponse(data: any) {
-
- const msg = this.messages[data.msgid];
- if (!msg) {
- console.warn(`No Hatch request found with ID ${data.msgid}`);
- return;
- }
-
- delete this.messages[data.msgid];
- msg.response = data.content;
- msg.message = data.message;
- msg.status = Number(data.status);
-
- if (msg.status === 200) {
- msg.resolver(msg);
- } else {
- console.error(`Hatch request returned status ${msg.status}`, msg);
- msg.rejector(msg);
- }
- }
-}
-
import {PrintService, PrintRequest} from './print.service';
import {StoreService} from '@eg/core/store.service';
import {ServerStoreService} from '@eg/core/server-store.service';
-import {HatchService, HatchMessage} from './hatch.service';
+import {HatchService, HatchMessage} from '@eg/core/hatch.service';
import {ToastService} from '@eg/share/toast/toast.service';
import {StringService} from '@eg/share/string/string.service';
printQueue: PrintRequest[];
+ useHatch: boolean;
+
constructor(
private renderer: Renderer2,
private elm: ElementRef,
this.htmlContainer =
this.renderer.selectRootElement('#eg-print-html-container');
+
+ this.serverStore.getItem('eg.hatch.enable.printing')
+ .then(use => this.useHatch = use);
}
handlePrintRequest(printReq: PrintRequest) {
show_dialog: printReq.showDialog
});
- if (this.useHatch()) {
+ if (this.useHatch) {
this.printViaHatch(printReq);
} else {
// Here the needed HTML is already in the page.
}
}
- useHatch(): boolean {
- return this.store.getLocalItem('eg.hatch.enable.printing')
- && this.hatch.connect();
- }
-
printViaHatch(printReq: PrintRequest) {
// Send a full HTML document to Hatch
) {}
ngOnInit() {
- this.workstations = this.store.getLocalItem('eg.workstation.all') || [];
- this.defaultName = this.store.getLocalItem('eg.workstation.default');
- this.selectedName = this.auth.workstation() || this.defaultName;
- const rm = this.route.snapshot.paramMap.get('remove');
- if (rm) {
- this.removeSelected(this.removeWorkstation = rm);
- }
+ this.store.getWorkstations()
+
+ .then(wsList => {
+ this.workstations = wsList || [];
+ return this.store.getDefaultWorkstation();
+
+ }).then(def => {
+ this.defaultName = def;
+ this.selectedName = this.auth.workstation() || this.defaultName;
+ const rm = this.route.snapshot.paramMap.get('remove');
+ if (rm) { this.removeSelected(this.removeWorkstation = rm); }
+ });
// TODO: use the org selector limitPerm option
this.perm.hasWorkPermAt(['REGISTER_WORKSTATION'], true)
setDefault(): void {
if (this.selected()) {
this.defaultName = this.selected().name;
- this.store.setLocalItem('eg.workstation.default', this.defaultName);
+ this.store.setDefaultWorkstation(this.defaultName);
}
}
}
this.workstations = this.workstations.filter(w => w.name !== name);
- this.store.setLocalItem('eg.workstation.all', this.workstations);
+ this.store.setWorkstations(this.workstations);
if (this.defaultName === name) {
this.defaultName = null;
- this.store.removeLocalItem('eg.workstation.default');
+ this.store.removeWorkstations();
}
}
};
this.workstations.push(ws);
- this.store.setLocalItem('eg.workstation.all', this.workstations);
+ this.store.setWorkstations(this.workstations);
this.newName = '';
// when registering our first workstation, mark it as the
// default and show it as selected in the ws selector.
// Focus username
this.renderer.selectRootElement('#username').focus();
- this.workstations = this.store.getLocalItem('eg.workstation.all');
- this.args.workstation =
- this.store.getLocalItem('eg.workstation.default');
- this.applyWorkstation();
+ this.store.getWorkstations()
+ .then(wsList => {
+ this.workstations = wsList;
+ return this.store.getDefaultWorkstation();
+ }).then(def => {
+ this.args.workstation = def;
+ this.applyWorkstation();
+ });
}
applyWorkstation() {
import {PermService} from '@eg/core/perm.service';
import {OrgService} from '@eg/core/org.service';
import {FormatService} from '@eg/core/format.service';
+import {HatchService} from '@eg/core/hatch.service';
const LOGIN_PATH = '/staff/login';
const WS_MANAGE_PATH = '/staff/admin/workstation/workstations/manage';
private router: Router,
private route: ActivatedRoute,
private ngLocation: Location,
+ private hatch: HatchService,
private store: StoreService,
private org: OrgService,
private net: NetService,
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<any> {
+ this.hatch.connect();
+
// Staff cookies stay in /$base/staff/
// NOTE: storing session data at '/' so it can be shared by
// Angularjs apps.
'Grid Config: circ.patron.xact_details_details_payments',
'cwst', 'label')
);
+
+INSERT INTO config.workstation_setting_type (name, grp, datatype, label)
+VALUES (
+ 'eg.hatch.enable.printing', 'gui', 'bool',
+ oils_i18n_gettext(
+ 'eg.hatch.enable.printing',
+ 'Use Hatch for printing',
+ 'cwst', 'label'
+ )
+);
+
--- /dev/null
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version);
+
+INSERT INTO config.workstation_setting_type (name, grp, datatype, label)
+VALUES (
+ 'eg.hatch.enable.printing', 'gui', 'bool',
+ oils_i18n_gettext(
+ 'eg.hatch.enable.printing',
+ 'Use Hatch for printing',
+ 'cwst', 'label'
+ )
+);
+
+
+COMMIT;
+
+
var service = {};
service.get_all = function() {
- return egCore.hatch.getItem('eg.workstation.all')
+ return egCore.hatch.getWorkstations()
.then(function(all) { return all || [] });
}
service.get_default = function() {
- return egCore.hatch.getItem('eg.workstation.default');
+ return egCore.hatch.getDefaultWorkstation();
}
service.set_default = function(name) {
- return egCore.hatch.setItem('eg.workstation.default', name);
+ return egCore.hatch.setDefaultWorkstation(name);
}
service.register_workstation = function(base_name, name, org_id) {
return service.get_all()
.then(function(all) {
all.push(new_ws);
- return egCore.hatch.setItem('eg.workstation.all', all)
+ return egCore.hatch.setWorkstations(all)
.then(function() { return new_ws });
});
}
service.remove_workstation = function(name) {
console.debug('Removing workstation: ' + name);
- return egCore.hatch.getItem('eg.workstation.all')
+ return egCore.hatch.getWorkstations()
// remove from list of all workstations
.then(function(all) {
if (!all) all = [];
var keep = all.filter(function(ws) {return ws.name != name});
- return egCore.hatch.setItem('eg.workstation.all', keep)
+ return egCore.hatch.setWorkstations(keep);
}).then(function() {
}).then(function(def) {
if (def == name) {
console.debug('Removing default workstation: ' + name);
- return egCore.hatch.removeItem('eg.workstation.default');
+ return egCore.hatch.removeDefaultWorkstation();
}
});
}
$scope.setContentType = function(type) { $scope.contentType = type }
$scope.setContentType('text/plain');
+ var hatchPrinting = false;
+ egCore.hatch.usePrinting().then(function(answer) {
+ hatchPrinting = answer;
+ });
+
$scope.useHatchPrinting = function() {
- return egCore.hatch.usePrinting();
+ return hatchPrinting;
}
$scope.hatchIsOpen = function() {
var hatch = egCore.hatch; // convenience
$scope.hatch_available = hatch.hatchAvailable;
- $scope.hatch_printing = hatch.usePrinting();
$scope.hatch_settings = hatch.useSettings();
$scope.hatch_offline = hatch.useOffline();
+ hatch.usePrinting().then(function(answer) {
+ $scope.hatch_printing = answer;
+ });
+
// Apply Hatch settings as changes occur in the UI.
$scope.$watch('hatch_printing', function(newval) {
if (typeof newval != 'boolean') return;
- hatch.setLocalItem('eg.hatch.enable.printing', newval);
+ hatch.setItem('eg.hatch.enable.printing', newval);
});
$scope.$watch('hatch_settings', function(newval) {
// if the user is already logged in, jump to splash page
if (egCore.auth.user()) $location.path('/');
- egCore.hatch.getItem('eg.workstation.all')
+ egCore.hatch.getWorkstations()
.then(function(all) {
if (all && all.length) {
$scope.workstations = all.map(function(a) { return a.name });
}
} else {
// no workstation requested; use the default
- egCore.hatch.getItem('eg.workstation.default')
+ egCore.hatch.getDefaultWorkstation()
.then(function(ws) {
$scope.args = {workstation : ws}
});
if (setting !== undefined) $scope.do_check_changed = true;
});
- egCore.hatch.getItem('eg.workstation.all')
+ egCore.hatch.getWorkstations()
.then(function(all) {
if (all && all.length) {
$scope.workstations = all;
}
} else {
// no workstation requested; use the default
- egCore.hatch.getItem('eg.workstation.default')
+ egCore.hatch.getDefaultWorkstation()
.then(function(ws) {
var ws_obj = all.filter(function(w) {
return ws == w.name
service.serverSettingSummaries = {};
/**
- * List string prefixes for On-Call storage keys. On-Call keys
- * are those that can be set/get/remove'd from localStorage when
- * Hatch is not avaialable, even though Hatch is configured as the
- * primary storage location for the key in question. On-Call keys
- * are those that allow the user to login and perform basic admin
- * tasks (like disabling Hatch) even when Hatch is down.
- * AKA Browser Staff Run Level 3.
- * Note that no attempt is made to synchronize data between Hatch
- * and localStorage for On-Call keys. Only one destation is active
- * at a time and each maintains its own data separately.
- */
- service.onCallPrefixes = ['eg.workstation'];
-
- // Returns true if the key can be set/get in localStorage even when
- // Hatch is not available.
- service.keyIsOnCall = function(key) {
- var oncall = false;
- angular.forEach(service.onCallPrefixes, function(pfx) {
- if (key.match(new RegExp('^' + pfx)))
- oncall = true;
- });
- return oncall;
- }
-
- /**
* Settings with these prefixes will always live in the browser.
*/
service.browserOnlyPrefixes = [
- 'eg.workstation',
- 'eg.hatch',
+ 'eg.hatch.enable.settings', // deprecated
+ 'eg.hatch.enable.offline', // deprecated
'eg.cache',
'current_tag_table_marc21_biblio',
'FFPos',
);
}
- // TODO: once Hatch is printing-only, should probably store
- // this preference on the server.
service.usePrinting = function() {
- return service.getLocalItem('eg.hatch.enable.printing');
+ return service.getItem('eg.hatch.enable.printing');
}
+ // DEPRECATED
service.useSettings = function() {
return service.getLocalItem('eg.hatch.enable.settings');
}
+ // DEPRECATED
service.useOffline = function() {
return service.getLocalItem('eg.hatch.enable.offline');
}
+ service.getWorkstations = function() {
+ if (service.hatchAvailable) {
+ return service.mergeWorkstations().then(
+ function() {
+ service.removeLocalItem('eg.workstation.all');
+ return service.getRemoteItem('eg.workstation.all');
+ }
+ );
+ } else {
+ return $q.when(service.getLocalItem('eg.workstation.all'));
+ }
+ }
+
+ // See if any workstations are stored in local storage. If so, also
+ // see if we have any stored in Hatch. If both, merged workstations
+ // from localStorage in Hatch storage, skipping any whose name
+ // collide with a workstation in Hatch. If none exist in Hatch,
+ // copy the localStorage workstations over wholesale.
+ service.mergeWorkstations = function() {
+ var existing = service.getLocalItem('eg.workstation.all');
+
+ if (!existing || existing.length === 0) {
+ return $q.when();
+ }
+
+ return service.getRemoteItem('eg.workstation.all')
+ .then(function(inHatch) {
+
+ if (!inHatch || inHatch.length === 0) {
+ // Nothing to merge, copy the data over directly
+ console.debug('No workstations in hatch to merge');
+ return service.setRemoteItem('eg.workstation.all', existing);
+ }
+
+ var addMe = [];
+ existing.forEach(function(ws) {
+ var match = inHatch.filter(
+ function(w) {return w.name === ws.name})[0];
+ if (!match) {
+ console.log(
+ 'Migrating workstation from local storage to hatch: '
+ + ws.name
+ );
+ addMe.push(ws);
+ }
+ });
+ inHatch = inHatch.concat(addMe);
+ return service.setRemoteItem('eg.workstation.all', inHatch);
+ });
+ }
+
+ service.getDefaultWorkstation = function() {
+
+ if (service.hatchAvailable) {
+ return service.getRemoteItem('eg.workstation.default')
+ .then(function(name) {
+ if (name) {
+ // We have a default in Hatch, remove any lingering
+ // value from localStorage.
+ service.removeLocalItem('eg.workstation.default');
+ return name;
+ }
+
+ name = service.getLocalItem('eg.workstation.default');
+ if (name) {
+ console.log('Migrating default workstation to Hatch ' + name);
+ return service.setRemoteItem('eg.workstation.default', name)
+ .then(function() {return name;});
+ }
+
+ return null;
+ });
+ } else {
+ return $q.when(service.getLocalItem('eg.workstation.default'));
+ }
+ }
+
+ service.setWorkstations = function(workstations, isJson) {
+ if (service.hatchAvailable) {
+ return service.setRemoteItem('eg.workstation.all', workstations);
+ } else {
+ return $q.when(
+ service.setLocalItem('eg.workstation.all', workstations, isJson));
+ }
+ }
+
+ service.setDefaultWorkstation = function(name, isJson) {
+ if (service.hatchAvailable) {
+ return service.setRemoteItem('eg.workstation.default', name);
+ } else {
+ return $q.when(
+ service.setLocalItem('eg.workstation.default', name, isJson));
+ }
+ }
+
+ service.removeWorkstations = function() {
+ if (service.hatchAvailable) {
+ return service.removeRemoteItem('eg.workstation.all');
+ } else {
+ return $q.when(
+ service.removeLocalItem('eg.workstation.all'));
+ }
+ }
+
+ service.removeDefaultWorkstation = function() {
+ if (service.hatchAvailable) {
+ return service.removeRemoteItem('eg.workstation.default');
+ } else {
+ return $q.when(
+ service.removeLocalItem('eg.workstation.default'));
+ }
+ }
+
+
+ // Workstation actions always use Hatch when it's available
+ service.getWorkstationItem = function(key) {
+ if (service.hatchAvailable) {
+ return service.getRemoteItem(key);
+ } else {
+ return $q.when(service.getLocalItem(key));
+ }
+ }
+
+ service.setWorkstationItem = function(key, value) {
+ if (service.hatchAvailable) {
+ return service.setRemoteItem(key, value);
+ } else {
+ return $q.when(service.setLocalItem(key, value));
+ }
+ }
+
+ service.removeWorkstationItem = function(key) {
+ if (service.hatchAvailable) {
+ return service.removeRemoteItem(key);
+ } else {
+ return $q.when(service.removeLocalItem(key));
+ }
+ }
+
+ service.keyIsWorkstation = function(key) {
+ return Boolean(key.match(/eg.workstation/));
+ }
+
// get the value for a stored item
service.getItem = function(key) {
- console.debug('getting item: ' + key);
+ if (service.keyIsWorkstation(key)) {
+ return service.getWorkstationItem(key);
+ }
if (!service.keyStoredInBrowser(key)) {
return service.getServerItem(key);
service.getBrowserItem(key).then(
function(val) { deferred.resolve(val); },
-
function() { // Hatch error
- if (service.keyIsOnCall(key)) {
- console.warn("Unable to getItem from Hatch: " + key +
- ". Retrieving item from local storage instead");
- deferred.resolve(service.getLocalItem(key));
- }
-
deferred.reject("Unable to getItem from Hatch: " + key);
}
);
*/
service.setItem = function(key, value) {
+ if (service.keyIsWorkstation(key)) {
+ return service.setWorkstationItem(key, value);
+ }
+
if (!service.keyStoredInBrowser(key)) {
return service.setServerItem(key, value);
}
function(val) {deferred.resolve(val);},
function() { // Hatch error
-
- if (service.keyIsOnCall(key)) {
- console.warn("Unable to setItem in Hatch: " +
- key + ". Setting in local storage instead");
-
- deferred.resolve(service.setLocalItem(key, value));
- }
deferred.reject("Unable to setItem in Hatch: " + key);
}
);
if (service.hatchAvailable)
return service.appendRemoteItem(key, value);
- if (service.keyIsOnCall(key)) {
- console.warn("Unable to appendItem in Hatch: " +
- key + ". Setting in local storage instead");
-
- return $q.when(service.appendLocalItem(key, value));
- }
-
console.error("Unable to appendItem in Hatch: " + key);
return $q.reject();
}
// remove a stored item
service.removeItem = function(key) {
+ if (service.keyIsWorkstation(key)) {
+ return service.removeWorkstationItem(key);
+ }
+
if (!service.keyStoredInBrowser(key)) {
return service.removeServerItem(key);
}
service.removeBrowserItem(key).then(
function(response) {deferred.resolve(response);},
function() { // Hatch error
-
- if (service.keyIsOnCall(key)) {
- console.warn("Unable to removeItem from Hatch: " + key +
- ". Removing item from local storage instead");
-
- deferred.resolve(service.removeLocalItem(key));
- }
-
deferred.reject("Unable to removeItem from Hatch: " + key);
}
);