Skip to content

Commit

Permalink
[frontend] Replace global totalStorage with native localStorage imple…
Browse files Browse the repository at this point in the history
…mentation

This takes care of an issue related to web components where global JQuery plugins aren't detected and included during packaging.

$.totalStorage has also become redundant as our target browsers support native localStorage now.
  • Loading branch information
JohanAhlen committed Nov 26, 2020
1 parent ad3eefe commit 2bb10a2
Show file tree
Hide file tree
Showing 83 changed files with 441 additions and 445 deletions.
56 changes: 28 additions & 28 deletions apps/beeswax/src/beeswax/static/beeswax/js/autocomplete.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function hac_getTableAliases(textScanned) {
return _aliases;
}

function hac_getTotalStorageUserPrefix() {
function hac_getLocalStorageUserPrefix() {
var _app = "";
if (typeof HIVE_AUTOCOMPLETE_APP != "undefined") {
_app = HIVE_AUTOCOMPLETE_APP;
Expand All @@ -80,9 +80,9 @@ function hac_getTableColumns(databaseName, tableName, textScanned, callback) {
tableName = _aliases[tableName];
}

if ($.totalStorage(hac_getTotalStorageUserPrefix() + 'columns_' + databaseName + '_' + tableName) != null && $.totalStorage(hac_getTotalStorageUserPrefix() + 'extended_columns_' + databaseName + '_' + tableName) != null) {
callback($.totalStorage(hac_getTotalStorageUserPrefix() + 'columns_' + databaseName + '_' + tableName), $.totalStorage(hac_getTotalStorageUserPrefix() + 'extended_columns_' + databaseName + '_' + tableName));
if ($.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_columns_' + databaseName + '_' + tableName) == null || hac_hasExpired($.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_columns_' + databaseName + '_' + tableName))){
if (hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'columns_' + databaseName + '_' + tableName) != null && hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'extended_columns_' + databaseName + '_' + tableName) != null) {
callback(hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'columns_' + databaseName + '_' + tableName), hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'extended_columns_' + databaseName + '_' + tableName));
if (hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_columns_' + databaseName + '_' + tableName) == null || hac_hasExpired(hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_columns_' + databaseName + '_' + tableName))){
hac_jsoncalls({
database: databaseName,
table: tableName,
Expand All @@ -94,9 +94,9 @@ function hac_getTableColumns(databaseName, tableName, textScanned, callback) {
hac_errorHandler(data);
}
else {
$.totalStorage(hac_getTotalStorageUserPrefix() + 'columns_' + databaseName + '_' + tableName, (data.columns ? "* " + data.columns.join(" ") : "*"));
$.totalStorage(hac_getTotalStorageUserPrefix() + 'extended_columns_' + databaseName + '_' + tableName, (data.extended_columns ? data.extended_columns : []));
$.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_columns_' + databaseName + '_' + tableName, (new Date()).getTime());
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'columns_' + databaseName + '_' + tableName, (data.columns ? "* " + data.columns.join(" ") : "*"));
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'extended_columns_' + databaseName + '_' + tableName, (data.extended_columns ? data.extended_columns : []));
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_columns_' + databaseName + '_' + tableName, (new Date()).getTime());
}
}
});
Expand All @@ -114,10 +114,10 @@ function hac_getTableColumns(databaseName, tableName, textScanned, callback) {
hac_errorHandler(data);
}
else {
$.totalStorage(hac_getTotalStorageUserPrefix() + 'columns_' + databaseName + '_' + tableName, (data.columns ? "* " + data.columns.join(" ") : "*"));
$.totalStorage(hac_getTotalStorageUserPrefix() + 'extended_columns_' + databaseName + '_' + tableName, (data.extended_columns ? data.extended_columns : []));
$.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_columns_' + databaseName + '_' + tableName, (new Date()).getTime());
callback($.totalStorage(hac_getTotalStorageUserPrefix() + 'columns_' + databaseName + '_' + tableName), $.totalStorage(hac_getTotalStorageUserPrefix() + 'extended_columns_' + databaseName + '_' + tableName));
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'columns_' + databaseName + '_' + tableName, (data.columns ? "* " + data.columns.join(" ") : "*"));
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'extended_columns_' + databaseName + '_' + tableName, (data.extended_columns ? data.extended_columns : []));
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_columns_' + databaseName + '_' + tableName, (new Date()).getTime());
callback(hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'columns_' + databaseName + '_' + tableName), hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'extended_columns_' + databaseName + '_' + tableName));
}
}
});
Expand All @@ -135,9 +135,9 @@ function hac_tableHasAlias(tableName, textScanned) {
}

function hac_getTables(databaseName, callback) {
if ($.totalStorage(hac_getTotalStorageUserPrefix() + 'tables_' + databaseName) != null) {
callback($.totalStorage(hac_getTotalStorageUserPrefix() + 'tables_' + databaseName));
if ($.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_tables_' + databaseName) == null || hac_hasExpired($.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_tables_' + databaseName))){
if (hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'tables_' + databaseName) != null) {
callback(hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'tables_' + databaseName));
if (hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_tables_' + databaseName) == null || hac_hasExpired(hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_tables_' + databaseName))){
hac_jsoncalls({
database: databaseName,
onDataReceived: function (data) {
Expand All @@ -148,8 +148,8 @@ function hac_getTables(databaseName, callback) {
hac_errorHandler(data);
}
else {
$.totalStorage(hac_getTotalStorageUserPrefix() + 'tables_' + databaseName, data.tables.join(" "));
$.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_tables_' + databaseName, (new Date()).getTime());
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'tables_' + databaseName, data.tables.join(" "));
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_tables_' + databaseName, (new Date()).getTime());
}
}
});
Expand All @@ -167,9 +167,9 @@ function hac_getTables(databaseName, callback) {
}
else {
if (data.tables) {
$.totalStorage(hac_getTotalStorageUserPrefix() + 'tables_' + databaseName, data.tables.join(" "));
$.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_tables_' + databaseName, (new Date()).getTime());
callback($.totalStorage(hac_getTotalStorageUserPrefix() + 'tables_' + databaseName));
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'tables_' + databaseName, data.tables.join(" "));
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_tables_' + databaseName, (new Date()).getTime());
callback(hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'tables_' + databaseName));
}
}
}
Expand All @@ -178,9 +178,9 @@ function hac_getTables(databaseName, callback) {
}

function hac_getDatabases(callback) {
if ($.totalStorage(hac_getTotalStorageUserPrefix() + 'databases') != null) {
callback($.totalStorage(hac_getTotalStorageUserPrefix() + 'databases'));
if ($.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_databases') == null || hac_hasExpired($.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_databases'))){
if (hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'databases') != null) {
callback(hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'databases'));
if (hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_databases') == null || hac_hasExpired(hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_databases'))){
hac_jsoncalls({
onDataReceived: function (data) {
if (typeof HIVE_AUTOCOMPLETE_GLOBAL_CALLBACK == "function") {
Expand All @@ -190,8 +190,8 @@ function hac_getDatabases(callback) {
hac_errorHandler(data);
}
else {
$.totalStorage(hac_getTotalStorageUserPrefix() + 'databases', data.databases);
$.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_databases', (new Date()).getTime());
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'databases', data.databases);
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_databases', (new Date()).getTime());
}
}
});
Expand All @@ -208,9 +208,9 @@ function hac_getDatabases(callback) {
}
else {
if (data.databases) {
$.totalStorage(hac_getTotalStorageUserPrefix() + 'databases', data.databases);
$.totalStorage(hac_getTotalStorageUserPrefix() + 'timestamp_databases', (new Date()).getTime());
callback($.totalStorage(hac_getTotalStorageUserPrefix() + 'databases'));
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'databases', data.databases);
hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'timestamp_databases', (new Date()).getTime());
callback(hueUtils.hueLocalStorage(hac_getLocalStorageUserPrefix() + 'databases'));
}
}
}
Expand All @@ -228,4 +228,4 @@ function hac_errorHandler(data) {
$(document).trigger('error', data.error);
}
}
}
}
2 changes: 1 addition & 1 deletion apps/beeswax/src/beeswax/templates/create_database.mako
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ ${layout.metastore_menubar()}
self.assistAvailable = ko.observable(true);
self.isLeftPanelVisible = ko.observable();
self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
self.apiHelper.withLocalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
huePubSub.subscribe("assist.table.selected", function (entry) {
location.href = '/metastore/table/' + entry.path[0] + '/' + entry.name + '?connector_id=' + entry.getConnector().id + '&namespace=' + entry.namespace.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ ${ layout.metastore_menubar() }
self.apiHelper = window.apiHelper;
self.assistAvailable = ko.observable(true);
self.isLeftPanelVisible = ko.observable();
self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
self.apiHelper.withLocalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
huePubSub.subscribe("assist.table.selected", function (entry) {
location.href = '/metastore/table/' + entry.path[0] + '/' + entry.name + '?connector_id=' + entry.getConnector().id + '&namespace=' + entry.namespace.id;
Expand Down
14 changes: 7 additions & 7 deletions apps/beeswax/src/beeswax/templates/execute.mako
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ ${ commonshare() | n,unicode }
<script type="text/javascript">
// avoid blinking of the panels
var leftPanelWidth = $.totalStorage("${app_name}_left_panel_width") != null ? $.totalStorage("${app_name}_left_panel_width") : 250;
var leftPanelWidth = hueUtils.hueLocalStorage("${app_name}_left_panel_width") != null ? hueUtils.hueLocalStorage("${app_name}_left_panel_width") : 250;
$(".left-panel").css("width", leftPanelWidth + "px");
$(".content-panel").css("left", leftPanelWidth + 20 + "px");
Expand Down Expand Up @@ -1170,7 +1170,7 @@ var autocompleter = new AceAutocompleteWrapper({
timeout: AUTOCOMPLETE_TIMEOUT
});
var totalStorageUserPrefix = apiHelper.getTotalStorageUserPrefix(snippetType);
var localStorageUserPrefix = apiHelper.getlocalStorageUserPrefix(snippetType);
var truncateOutput = function (obj) {
//default to 20 characters (column output displays first 21 chars so we need to consider the length of both column name and type
Expand Down Expand Up @@ -1709,9 +1709,9 @@ $(document).ready(function () {
});
% if not (design and design.id) and not ( query_history and query_history.id ):
if ($.totalStorage(totalStorageUserPrefix + "${app_name}_temp_query") != null && $.totalStorage(totalStorageUserPrefix + "${app_name}_temp_query") != "") {
if (hueUtils.hueLocalStorage(localStorageUserPrefix + "${app_name}_temp_query") != null && hueUtils.hueLocalStorage(localStorageUserPrefix + "${app_name}_temp_query") != "") {
viewModel.queryEditorBlank(true);
codeMirror.setValue($.totalStorage(totalStorageUserPrefix + "${app_name}_temp_query"));
codeMirror.setValue(hueUtils.hueLocalStorage(localStorageUserPrefix + "${app_name}_temp_query"));
}
% endif
Expand Down Expand Up @@ -2089,7 +2089,7 @@ function addResults(viewModel, dataTable, startRow, nextRow) {
function resultsTable(e, data) {
$("#results .dataTables_wrapper").animate({opacity: '1'}, 50);
$.totalStorage(totalStorageUserPrefix + "${app_name}_temp_query", null);
hueUtils.hueLocalStorage(localStorageUserPrefix + "${app_name}_temp_query", null);
if (viewModel.design.results.columns().length > 0) {
if (!dataTable) {
if (viewModel.design.results.columns().length < 500) {
Expand Down Expand Up @@ -2369,7 +2369,7 @@ function tryCancelQuery() {
}
function createNewQuery() {
$.totalStorage(totalStorageUserPrefix + "${app_name}_temp_query", null);
hueUtils.hueLocalStorage(localStorageUserPrefix + "${app_name}_temp_query", null);
location.href="${ url(app_name + ':execute_query') }";
}
Expand Down Expand Up @@ -2765,7 +2765,7 @@ function cacheQueryTextEvents() {
if (typeof codeMirror != "undefined") {
codeMirror.on("change", function () {
$(".query").val(codeMirror.getValue());
$.totalStorage(totalStorageUserPrefix + "${app_name}_temp_query", codeMirror.getValue());
hueUtils.hueLocalStorage(localStorageUserPrefix + "${app_name}_temp_query", codeMirror.getValue());
});
window.clearInterval(_waitForCodemirrorInit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ ${ layout.metastore_menubar() }
self.apiHelper = window.apiHelper;
self.assistAvailable = ko.observable(true);
self.isLeftPanelVisible = ko.observable();
self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
self.apiHelper.withLocalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
huePubSub.subscribe("assist.table.selected", function (entry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ ${ layout.metastore_menubar() }
self.apiHelper = window.apiHelper;
self.assistAvailable = ko.observable(true);
self.isLeftPanelVisible = ko.observable();
self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
self.apiHelper.withLocalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
huePubSub.subscribe("assist.table.selected", function (entry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ ${ layout.metastore_menubar() }
self.apiHelper = window.apiHelper;
self.assistAvailable = ko.observable(true);
self.isLeftPanelVisible = ko.observable();
self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
self.apiHelper.withLocalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
huePubSub.subscribe("assist.table.selected", function (entry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ from filebrowser.conf import ENABLE_EXTRACT_UPLOADED_ARCHIVE
self.page = ko.observable(new Page(page));
self.recordsPerPageChoices = ["15", "30", "45", "60", "100", "200", "1000"],
self.recordsPerPage = ko.observable(apiHelper.getFromTotalStorage('fb', 'records_per_page', 45));
self.recordsPerPage = ko.observable(apiHelper.getFromLocalStorage('fb', 'records_per_page', 45));
self.targetPageNum = ko.observable(1);
self.targetPath = ko.observable("${current_request_path | n,unicode }");
self.sortBy = ko.observable("name");
Expand Down Expand Up @@ -1263,7 +1263,7 @@ from filebrowser.conf import ENABLE_EXTRACT_UPLOADED_ARCHIVE
};
self.recordsPerPage.subscribe(function (newValue) {
apiHelper.setInTotalStorage('fb', 'records_per_page', newValue)
apiHelper.setInLocalStorage('fb', 'records_per_page', newValue)
self.retrieveData();
});
Expand Down
10 changes: 5 additions & 5 deletions apps/hbase/src/hbase/templates/app.mako
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ ${ commonheader(None, "hbase", user, request) | n,unicode }
editor.setOptions({
readOnly: $('#ace_target').is(':disabled')
});
editor.setTheme($.totalStorage('hue.ace.theme') || 'ace/theme/hue');
editor.setTheme(hueUtils.hueLocalStorage('hue.ace.theme') || 'ace/theme/hue');
editor.getSession().setMode(aceMode);
editor.setValue($(target).val(), -1);
Expand Down Expand Up @@ -2346,7 +2346,7 @@ ${ commonheader(None, "hbase", user, request) | n,unicode }
},
':cluster/:table/query/:query': function (cluster, table, query) {
hueAnalytics.log('hbase', 'query_table');
$.totalStorage('hbase_cluster', cluster);
hueUtils.hueLocalStorage('hbase_cluster', cluster);
app.station('table');
app.search.cur_input(query);
Router.setTable(cluster, table);
Expand All @@ -2360,7 +2360,7 @@ ${ commonheader(None, "hbase", user, request) | n,unicode }
},
':cluster/:table': function (cluster, table) {
hueAnalytics.log('hbase', 'view_table');
$.totalStorage('hbase_cluster', cluster);
hueUtils.hueLocalStorage('hbase_cluster', cluster);
Router.setTable(cluster, table);
resetSearch();
resetElements();
Expand All @@ -2373,7 +2373,7 @@ ${ commonheader(None, "hbase", user, request) | n,unicode }
routie('');
} else {
hueAnalytics.log('hbase', 'view_cluster');
$.totalStorage('hbase_cluster', cluster);
hueUtils.hueLocalStorage('hbase_cluster', cluster);
app.station('cluster');
app.cluster(cluster);
app.pageTitle(cluster);
Expand All @@ -2392,7 +2392,7 @@ ${ commonheader(None, "hbase", user, request) | n,unicode }
routed = true;
},
'': function () {
var cluster = $.totalStorage('hbase_cluster');
var cluster = hueUtils.hueLocalStorage('hbase_cluster');
if (cluster != null && $.inArray(cluster, app.clusterNames()) > -1) {
routie(cluster);
} else {
Expand Down
2 changes: 1 addition & 1 deletion apps/jobbrowser/src/jobbrowser/templates/job_browser.mako
Original file line number Diff line number Diff line change
Expand Up @@ -3884,7 +3884,7 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
self.apiHelper = window.apiHelper;
self.assistAvailable = ko.observable(true);
self.isLeftPanelVisible = ko.observable();
self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
self.apiHelper.withLocalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
self.appConfig = ko.observable();
self.clusterType = ko.observable();
self.isMini = ko.observable(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ ${ layout.menubar(section='bundles', dashboard=True) }
readOnly: true,
maxLines: Infinity
});
editor.setTheme($.totalStorage("hue.ace.theme") || "ace/theme/hue");
editor.setTheme(hueUtils.hueLocalStorage("hue.ace.theme") || "ace/theme/hue");
editor.getSession().setMode("ace/mode/xml");
$(".confirmationModal").click(function(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ ${ layout.menubar(section='coordinators', dashboard=True) }
readOnly: true,
maxLines: Infinity
});
editor.setTheme($.totalStorage("hue.ace.theme") || "ace/theme/hue");
editor.setTheme(hueUtils.hueLocalStorage("hue.ace.theme") || "ace/theme/hue");
editor.getSession().setMode("ace/mode/xml");
// force refresh on tab change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ ${ dashboard.import_layout() }
readOnly: true,
maxLines: Infinity
});
editor.setTheme($.totalStorage("hue.ace.theme") || "ace/theme/hue");
editor.setTheme(hueUtils.hueLocalStorage("hue.ace.theme") || "ace/theme/hue");
editor.getSession().setMode("ace/mode/xml");
// force refresh on tab change
Expand Down
Loading

0 comments on commit 2bb10a2

Please sign in to comment.