Skip to content

Commit

Permalink
Merge pull request ngageoint#635 in WV/opensphere from ~SALANKEYJ/ope…
Browse files Browse the repository at this point in the history
…nsphere:THIN-12767 to master

* commit '10b0ae7db7153b7476b6463afde9ed2c8e40c03f':
  refactor(states): refactors/renames all of the state manager classes, other minor state refactors
  • Loading branch information
jsalankey committed Feb 12, 2019
2 parents b94a6ec + 10b0ae7 commit c22cab5
Show file tree
Hide file tree
Showing 26 changed files with 111 additions and 109 deletions.
4 changes: 2 additions & 2 deletions src/os/mainctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ os.MainCtrl = function($scope, $element, $compile, $timeout, $injector) {
os.ui.exportManager.registerPersistenceMethod(new os.file.persist.FilePersistence());

// set state manager global reference
os.ui.stateManager = os.state.StateManager.getInstance();
os.stateManager = os.state.StateManager.getInstance();

// set up clear control
os.ui.clearManager.addEntry(new os.ui.clear.ClearEntry('exclusionAreas', 'Exclusion Areas',
Expand Down Expand Up @@ -757,7 +757,7 @@ os.MainCtrl.prototype.handleKeyEvent_ = function(event) {
if (ctrlOr) {
os.metrics.Metrics.getInstance().updateMetric(os.metrics.keys.Map.SAVE_STATE_KB, 1);
event.preventDefault();
os.ui.stateManager.startExport();
os.stateManager.startExport();
os.ui.apply(this.scope);
}
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
goog.provide('os.state.BaseStateManager');
goog.provide('os.state.BaseStateManager.EventType');
goog.provide('os.state.Versions');
goog.provide('os.ui.state.StateManager');
goog.provide('os.ui.state.StateManager.EventType');

goog.require('goog.async.Deferred');
goog.require('goog.events.EventTarget');
Expand All @@ -19,9 +19,9 @@ goog.require('os.ui.window');

/**
* Global state manager reference. Set this in each application with the app-specific manager reference.
* @type {os.ui.state.StateManager}
* @type {os.state.BaseStateManager}
*/
os.ui.stateManager = null;
os.stateManager = null;



Expand All @@ -31,8 +31,8 @@ os.ui.stateManager = null;
* @constructor
* @template T,S
*/
os.ui.state.StateManager = function() {
os.ui.state.StateManager.base(this, 'constructor');
os.state.BaseStateManager = function() {
os.state.BaseStateManager.base(this, 'constructor');

/**
* Content type to use when saving state files.
Expand Down Expand Up @@ -64,10 +64,10 @@ os.ui.state.StateManager = function() {
* @type {goog.log.Logger}
* @protected
*/
this.log = os.ui.state.StateManager.LOGGER_;
this.log = os.state.BaseStateManager.LOGGER_;
};
goog.inherits(os.ui.state.StateManager, goog.events.EventTarget);
goog.addSingletonGetter(os.ui.state.StateManager);
goog.inherits(os.state.BaseStateManager, goog.events.EventTarget);
goog.addSingletonGetter(os.state.BaseStateManager);


/**
Expand All @@ -76,7 +76,7 @@ goog.addSingletonGetter(os.ui.state.StateManager);
* @private
* @const
*/
os.ui.state.StateManager.LOGGER_ = goog.log.getLogger('os.ui.state.StateManager');
os.state.BaseStateManager.LOGGER_ = goog.log.getLogger('os.state.BaseStateManager');


/**
Expand All @@ -95,7 +95,7 @@ os.state.Versions = {
* Event types
* @enum {string}
*/
os.ui.state.StateManager.EventType = {
os.state.BaseStateManager.EventType = {
CLEAR: 'clear',
DELETE: 'delete'
};
Expand All @@ -105,7 +105,7 @@ os.ui.state.StateManager.EventType = {
* Sets the state export version used by the application.
* @param {string} version The state version string
*/
os.ui.state.StateManager.prototype.setVersion = function(version) {
os.state.BaseStateManager.prototype.setVersion = function(version) {
this.version_ = version;
};

Expand All @@ -115,7 +115,7 @@ os.ui.state.StateManager.prototype.setVersion = function(version) {
* @return {string}
* @protected
*/
os.ui.state.StateManager.prototype.getVersion = function() {
os.state.BaseStateManager.prototype.getVersion = function() {
return this.version_;
};

Expand All @@ -125,7 +125,7 @@ os.ui.state.StateManager.prototype.getVersion = function() {
* @param {string} key The object key
* @param {!function(new:os.IPersistable)} clazz The persistable class
*/
os.ui.state.StateManager.prototype.registerPersistable = function(key, clazz) {
os.state.BaseStateManager.prototype.registerPersistable = function(key, clazz) {
if (!(key in this.persistableMap_)) {
this.persistableMap_[key] = clazz;
} else {
Expand All @@ -139,7 +139,7 @@ os.ui.state.StateManager.prototype.registerPersistable = function(key, clazz) {
* @param {string} key The object key
* @return {os.IPersistable}
*/
os.ui.state.StateManager.prototype.getPersistable = function(key) {
os.state.BaseStateManager.prototype.getPersistable = function(key) {
if (key in this.persistableMap_) {
return new this.persistableMap_[key]();
}
Expand All @@ -154,7 +154,7 @@ os.ui.state.StateManager.prototype.getPersistable = function(key) {
* @param {function(new:os.state.IState)} clazz The state class
* @param {string=} opt_type The state type
*/
os.ui.state.StateManager.prototype.addStateImplementation = function(version, clazz, opt_type) {
os.state.BaseStateManager.prototype.addStateImplementation = function(version, clazz, opt_type) {
if (!version) {
throw new Error('version cannot be empty or null!');
}
Expand Down Expand Up @@ -187,15 +187,15 @@ os.ui.state.StateManager.prototype.addStateImplementation = function(version, cl
/**
* Deactivates all states in the application.
*/
os.ui.state.StateManager.prototype.clearStates = function() {
os.state.BaseStateManager.prototype.clearStates = function() {
// applications should extend this to actually do something, assuming they can save locally
};


/**
* Deletes all local states
*/
os.ui.state.StateManager.prototype.deleteStates = function() {
os.state.BaseStateManager.prototype.deleteStates = function() {
// applications should extend this to actually do something, assuming they can save locally
};

Expand All @@ -205,7 +205,7 @@ os.ui.state.StateManager.prototype.deleteStates = function() {
* @param {boolean=} opt_allVersions Whether to get all versions.
* @return {!Array.<!os.state.IState>} The states
*/
os.ui.state.StateManager.prototype.getAvailable = function(opt_allVersions) {
os.state.BaseStateManager.prototype.getAvailable = function(opt_allVersions) {
var list = [];

if (!opt_allVersions) {
Expand Down Expand Up @@ -236,7 +236,7 @@ os.ui.state.StateManager.prototype.getAvailable = function(opt_allVersions) {
* @param {!os.file.File} file The state file
* @param {S} options The state save options
*/
os.ui.state.StateManager.prototype.addImportedState = function(file, options) {
os.state.BaseStateManager.prototype.addImportedState = function(file, options) {
var url = file.getUrl();
if (url && os.file.isLocal(url)) {
// local file, so store it before finishing the import
Expand All @@ -253,7 +253,7 @@ os.ui.state.StateManager.prototype.addImportedState = function(file, options) {
* @param {string} title The title
* @return {boolean} If the title has been used
*/
os.ui.state.StateManager.prototype.hasState = function(title) {
os.state.BaseStateManager.prototype.hasState = function(title) {
return false;
};

Expand All @@ -263,7 +263,7 @@ os.ui.state.StateManager.prototype.hasState = function(title) {
* @param {!os.file.File} file The stored file
* @param {S} options The save options
*/
os.ui.state.StateManager.prototype.finishImport = function(file, options) {
os.state.BaseStateManager.prototype.finishImport = function(file, options) {
// applications should override this function so it does something
};

Expand All @@ -272,7 +272,7 @@ os.ui.state.StateManager.prototype.finishImport = function(file, options) {
* Initiate the state export process.
* @param {os.ex.IPersistenceMethod=} opt_method The persistence method
*/
os.ui.state.StateManager.prototype.startExport = function(opt_method) {
os.state.BaseStateManager.prototype.startExport = function(opt_method) {
var scopeOptions = {
'defaultMethod': opt_method
};
Expand Down Expand Up @@ -302,7 +302,7 @@ os.ui.state.StateManager.prototype.startExport = function(opt_method) {
* @param {string=} opt_tags The tags
* @param {Array.<!os.state.IState>=} opt_states The states to save
*/
os.ui.state.StateManager.prototype.saveStates = function(method, title, opt_desc, opt_tags, opt_states) {
os.state.BaseStateManager.prototype.saveStates = function(method, title, opt_desc, opt_tags, opt_states) {
var obj = this.createStateObject(method, title, opt_desc, opt_tags);
var options = this.createStateOptions(method, title, obj, opt_desc, opt_tags);

Expand Down Expand Up @@ -331,7 +331,7 @@ os.ui.state.StateManager.prototype.saveStates = function(method, title, opt_desc
* @param {S} options The state save options
* @protected
*/
os.ui.state.StateManager.prototype.onSaveSuccess = function(options) {
os.state.BaseStateManager.prototype.onSaveSuccess = function(options) {
var content = this.serializeContent(options);
var stateFileName = this.getStateFileName(options);
goog.asserts.assert(content != null, 'No state content to save!');
Expand Down Expand Up @@ -367,7 +367,7 @@ os.ui.state.StateManager.prototype.onSaveSuccess = function(options) {
* @param {string} errorMsg The error message
* @protected
*/
os.ui.state.StateManager.prototype.onSaveError = function(errorMsg) {
os.state.BaseStateManager.prototype.onSaveError = function(errorMsg) {
goog.log.error(this.log, 'Failed saving state: ' + errorMsg);
};

Expand All @@ -376,7 +376,7 @@ os.ui.state.StateManager.prototype.onSaveError = function(errorMsg) {
* Removes components of a state file from the application.
* @param {string} id The base state id
*/
os.ui.state.StateManager.prototype.removeState = function(id) {
os.state.BaseStateManager.prototype.removeState = function(id) {
var list = this.getAvailable(true);
for (var i = 0, n = list.length; i < n; i++) {
try {
Expand All @@ -395,7 +395,7 @@ os.ui.state.StateManager.prototype.removeState = function(id) {
* @param {S} options The save options
* @return {boolean} If the operation is supported and succeeded
*/
os.ui.state.StateManager.prototype.saveLocal = function(file, options) {
os.state.BaseStateManager.prototype.saveLocal = function(file, options) {
// always replace. if we got here the application should have done duplicate file detection already.
var fs = os.file.FileStorage.getInstance();
fs.storeFile(file, true).addCallbacks(goog.partial(this.finishImport, file, options), this.onFileError_, this);
Expand All @@ -409,7 +409,7 @@ os.ui.state.StateManager.prototype.saveLocal = function(file, options) {
* @param {*} error
* @private
*/
os.ui.state.StateManager.prototype.onFileError_ = function(error) {
os.state.BaseStateManager.prototype.onFileError_ = function(error) {
if (typeof error === 'string') {
goog.log.error(this.log, 'Unable to store state file locally: ' + error);
} else {
Expand All @@ -423,7 +423,7 @@ os.ui.state.StateManager.prototype.onFileError_ = function(error) {
* @param {T|string} obj The state
* @return {!Array.<!os.state.IState>} Supported states
*/
os.ui.state.StateManager.prototype.analyze = goog.abstractMethod;
os.state.BaseStateManager.prototype.analyze = goog.abstractMethod;


/**
Expand All @@ -435,7 +435,7 @@ os.ui.state.StateManager.prototype.analyze = goog.abstractMethod;
* @return {T} The save options
* @protected
*/
os.ui.state.StateManager.prototype.createStateObject = goog.abstractMethod;
os.state.BaseStateManager.prototype.createStateObject = goog.abstractMethod;


/**
Expand All @@ -448,15 +448,15 @@ os.ui.state.StateManager.prototype.createStateObject = goog.abstractMethod;
* @return {S} The save options
* @protected
*/
os.ui.state.StateManager.prototype.createStateOptions = goog.abstractMethod;
os.state.BaseStateManager.prototype.createStateOptions = goog.abstractMethod;


/**
* Gets the state file name.
* @param {S} options The state options
* @return {?string} The file name
*/
os.ui.state.StateManager.prototype.getStateFileName = goog.abstractMethod;
os.state.BaseStateManager.prototype.getStateFileName = goog.abstractMethod;


/**
Expand All @@ -466,12 +466,12 @@ os.ui.state.StateManager.prototype.getStateFileName = goog.abstractMethod;
* @param {string} stateId The state's identifier
* @param {?string=} opt_title The state's title
*/
os.ui.state.StateManager.prototype.loadState = goog.abstractMethod;
os.state.BaseStateManager.prototype.loadState = goog.abstractMethod;


/**
* Serializes the state file content to a string.
* @param {S} options The state options
* @return {?string} The serialized content
*/
os.ui.state.StateManager.prototype.serializeContent = goog.abstractMethod;
os.state.BaseStateManager.prototype.serializeContent = goog.abstractMethod;
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
goog.provide('os.ui.state.JSONStateManager');
goog.provide('os.state.JSONStateManager');

goog.require('goog.log');
goog.require('goog.log.Logger');
goog.require('os.config');
goog.require('os.file.FileManager');
goog.require('os.file.mime.jsonstate');
goog.require('os.state');
goog.require('os.state.BaseStateManager');
goog.require('os.state.JSONStateOptions');
goog.require('os.state.Tag');
goog.require('os.tag');
goog.require('os.ui.im.ImportManager');
goog.require('os.ui.state.StateManager');



/**
* Base JSON state manager.
* @extends {os.ui.state.StateManager.<!Object.<string, *>, !os.state.JSONStateOptions>}
* @extends {os.state.BaseStateManager.<!Object.<string, *>, !os.state.JSONStateOptions>}
* @constructor
*/
os.ui.state.JSONStateManager = function() {
os.ui.state.JSONStateManager.base(this, 'constructor');
os.state.JSONStateManager = function() {
os.state.JSONStateManager.base(this, 'constructor');
this.contentType = 'application/json';
this.log = os.ui.state.JSONStateManager.LOGGER_;
this.log = os.state.JSONStateManager.LOGGER_;

// register the import UI
var im = os.ui.im.ImportManager.getInstance();
im.registerImportDetails(os.config.getAppName('Application') + ' state files.');
im.registerImportUI(os.file.mime.jsonstate.TYPE, new os.ui.state.StateImportUI());
};
goog.inherits(os.ui.state.JSONStateManager, os.ui.state.StateManager);
goog.inherits(os.state.JSONStateManager, os.state.BaseStateManager);


/**
Expand All @@ -37,13 +38,13 @@ goog.inherits(os.ui.state.JSONStateManager, os.ui.state.StateManager);
* @private
* @const
*/
os.ui.state.JSONStateManager.LOGGER_ = goog.log.getLogger('os.ui.state.JSONStateManager');
os.state.JSONStateManager.LOGGER_ = goog.log.getLogger('os.state.JSONStateManager');


/**
* @inheritDoc
*/
os.ui.state.JSONStateManager.prototype.analyze = function(obj) {
os.state.JSONStateManager.prototype.analyze = function(obj) {
if (typeof obj === 'string') {
var actualObject = /** @type {Object} */ (JSON.parse(obj));
if (actualObject) {
Expand Down Expand Up @@ -82,7 +83,7 @@ os.ui.state.JSONStateManager.prototype.analyze = function(obj) {
/**
* @inheritDoc
*/
os.ui.state.JSONStateManager.prototype.loadState = function(obj, states, stateId, opt_title) {
os.state.JSONStateManager.prototype.loadState = function(obj, states, stateId, opt_title) {
if (obj && states) {
if (typeof obj === 'string') {
var actualObject = /** @type {Object} */ (JSON.parse(obj));
Expand Down Expand Up @@ -114,7 +115,7 @@ os.ui.state.JSONStateManager.prototype.loadState = function(obj, states, stateId
/**
* @inheritDoc
*/
os.ui.state.JSONStateManager.prototype.createStateObject = function(method, title, opt_desc, opt_tags) {
os.state.JSONStateManager.prototype.createStateObject = function(method, title, opt_desc, opt_tags) {
var appName = os.config.getAppName('Unknown Application');
var version = os.config.getAppVersion('Unknown Version');
var object = {};
Expand All @@ -137,7 +138,7 @@ os.ui.state.JSONStateManager.prototype.createStateObject = function(method, titl
/**
* @inheritDoc
*/
os.ui.state.JSONStateManager.prototype.createStateOptions = function(method, title, obj, opt_desc, opt_tags) {
os.state.JSONStateManager.prototype.createStateOptions = function(method, title, obj, opt_desc, opt_tags) {
var options = new os.state.JSONStateOptions(title, obj);
options.description = opt_desc || null;
options.method = method;
Expand All @@ -151,14 +152,14 @@ os.ui.state.JSONStateManager.prototype.createStateOptions = function(method, tit
/**
* @inheritDoc
*/
os.ui.state.JSONStateManager.prototype.serializeContent = function(options) {
os.state.JSONStateManager.prototype.serializeContent = function(options) {
return options.obj ? JSON.stringify(options.obj) : null;
};


/**
* @inheritDoc
*/
os.ui.state.JSONStateManager.prototype.getStateFileName = function(options) {
os.state.JSONStateManager.prototype.getStateFileName = function(options) {
return options.obj ? options.obj[os.state.Tag.TITLE] + '_state.json' : null;
};
Loading

0 comments on commit c22cab5

Please sign in to comment.