Skip to content

Commit

Permalink
[frontend] Replace the use of jHueNotify with the new Alert component
Browse files Browse the repository at this point in the history
With this change I've changed all alert usage throughout the code to use the new pubsub and Alert component. By doing this we can now get rid of some old code like the jquery.notify.js plugin as well as page events.
  • Loading branch information
JohanAhlen committed Mar 21, 2024
1 parent 0269dd9 commit 56f13d2
Show file tree
Hide file tree
Showing 80 changed files with 438 additions and 675 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,9 @@ ${ layout.metastore_menubar() }
ko.applyBindings(viewModel);
if (hueUtils.getParameter("error") != "") {
$.jHueNotify.error(hueUtils.getParameter("error"));
huePubSub.publish('hue.global.error', {
message: hueUtils.getParameter('error')
});
}
if ($(".removeBtn").length == 1) {
Expand Down
12 changes: 9 additions & 3 deletions apps/beeswax/src/beeswax/templates/execute.mako
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,9 @@ $(document).ready(function () {
$("#download-excel").click(function () {
if (viewModel.design.results.columns().length > 255) {
$.jHueNotify.warn("${ _('Results exceeds maximum number of columns permitted by Excel, will truncate results to 255 columns.') }")
huePubSub.publish('hue.global.warning', {
message: "${ _('Results exceeds maximum number of columns permitted by Excel, will truncate results to 255 columns.') }"
});
}
});
Expand Down Expand Up @@ -2248,7 +2250,9 @@ function trySaveAsDesign() {
$('#saveAs').find('.control-group').removeClass('error');
hueAnalytics.log('beeswax', 'design/save-as');
} else if (viewModel.design.name()) {
$.jHueNotify.error("${_('No query provided to save.')}");
huePubSub.publish('hue.global.error', {
message: "${_('No query provided to save.')}"
});
$('#saveAs').modal('hide');
} else {
$('#saveas-query-name').addClass('error');
Expand Down Expand Up @@ -2355,7 +2359,9 @@ function formatQuery() {
}
viewModel.design.query.value(codeMirror.getValue());
} else {
$.jHueNotify.error(data);
huePubSub.publish('hue.global.error', {
message: data
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ ${ layout.metastore_menubar() }
ko.applyBindings(viewModel);
if (hueUtils.getParameter("error") != "") {
$.jHueNotify.error(hueUtils.getParameter("error"));
huePubSub.publish('hue.global.error', {
message: hueUtils.getParameter('error')
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ ${ layout.metastore_menubar() }
ko.applyBindings(viewModel);
if (hueUtils.getParameter("error") != "") {
$.jHueNotify.error(hueUtils.getParameter("error"));
huePubSub.publish('hue.global.error', {
message: hueUtils.getParameter('error')
});
}
$(".fileChooserBtn").click(function (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ ${ layout.metastore_menubar() }
ko.applyBindings(viewModel);
if (hueUtils.getParameter("error") != "") {
$.jHueNotify.error(hueUtils.getParameter("error"));
huePubSub.publish('hue.global.error', {
message: hueUtils.getParameter('error')
});
}
$("[rel='tooltip']").tooltip();
Expand Down
8 changes: 6 additions & 2 deletions apps/filebrowser/src/filebrowser/templates/display.mako
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ ${ fb_components.menubar() }
}
if (self.upperPage() - self.page() > self.MAX_ALLOWED_PAGES_PER_REQUEST) {
self.upperPage(self.page() + self.MAX_ALLOWED_PAGES_PER_REQUEST);
$.jHueNotify.info("${_('Sorry, you cannot request for more than %s pages.' % MAX_ALLOWED_PAGES_PER_REQUEST)}");
huePubSub.publish('hue.global.info', {
message: "${_('Sorry, you cannot request for more than %s pages.' % MAX_ALLOWED_PAGES_PER_REQUEST)}"
});
}
self.changePage();
};
Expand Down Expand Up @@ -503,7 +505,9 @@ ${ fb_components.menubar() }
% if not is_embeddable:
$(document).ajaxError(function () {
$.jHueNotify.error("${_('There was an unexpected server error.')}");
huePubSub.publish('hue.global.error', {
message: "${_('There was an unexpected server error.')}"
});
});
% endif
Expand Down
8 changes: 6 additions & 2 deletions apps/filebrowser/src/filebrowser/templates/edit.mako
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ ${ fb_components.menubar() }
success: function (data) {
if (data && data.exists) {
resetPrimaryButtonsStatus();
$.jHueNotify.info(data.path + " ${ _('saved correctly') }")
huePubSub.publish('hue.global.info', {
message: data.path + " ${ _('saved correctly') }"
});
}
}
});
Expand All @@ -147,7 +149,9 @@ ${ fb_components.menubar() }
if (data && data.exists) {
resetPrimaryButtonsStatus();
$("#saveAsModal").modal("hide");
$.jHueNotify.info(data.path + " ${ _('saved correctly') }")
huePubSub.publish('hue.global.info', {
message: data.path + " ${ _('saved correctly') }"
});
}
}
});
Expand Down
48 changes: 36 additions & 12 deletions apps/filebrowser/src/filebrowser/templates/listdir_components.mako
Original file line number Diff line number Diff line change
Expand Up @@ -1533,14 +1533,18 @@ else:
self.retrieveData(true);
},
error: function(xhr){
$.jHueNotify.error(xhr.responseText);
huePubSub.publish('hue.global.error', {
message: xhr.responseText
});
resetPrimaryButtonsStatus();
$('#moveDestination').val('');
}
});
if (mode === 'nomodal') {
$.jHueNotify.info('${ _('Items moving to') } "' + $('#moveDestination').val() + '"');
huePubSub.publish('hue.global.info', {
message: "${ _('Items moving to') } \"" + $('#moveDestination').val() + '"'
});
$("#moveForm").submit();
} else {
$("#moveModal").modal({
Expand Down Expand Up @@ -1573,7 +1577,9 @@ else:
}
}
else {
$.jHueNotify.warn("${ _('You cannot copy a folder into itself.') }");
huePubSub.publish('hue.global.warning', {
message: "${ _('You cannot copy a folder into itself.') }"
});
$('#moveDestination').val('');
}
};
Expand Down Expand Up @@ -1602,7 +1608,9 @@ else:
self.retrieveData(true);
},
error: function(xhr){
$.jHueNotify.error(xhr.responseText);
huePubSub.publish('hue.global.error', {
message: xhr.responseText
});
resetPrimaryButtonsStatus();
}
});
Expand Down Expand Up @@ -1791,7 +1799,9 @@ else:
const path = $('<input>').val(self.selectedFile().path).appendTo('body').select()
document.execCommand('copy');
path.remove();
$.jHueNotify.info('${_('Path copied successfully to the clipboard')}');
huePubSub.publish('hue.global.info', {
message: "${_('Path copied successfully to the clipboard')}"
});
}
self.openInImporter = function () {
Expand All @@ -1810,7 +1820,9 @@ else:
$('#submit-wf-modal').modal('show');
});
% else:
$.jHueNotify.warn("${ _('Submitting is not available as the Oozie app is disabled') }");
huePubSub.publish('hue.global.warning', {
message: "${ _('Submitting is not available as the Oozie app is disabled') }"
});
% endif
};
Expand Down Expand Up @@ -1863,7 +1875,9 @@ else:
"start_time": ko.mapping.toJSON((new Date()).getTime())
}, function (data) {
if (data.status == 0) {
$.jHueNotify.info("${ _('Task ') }" + data.history_uuid + "${_(' submitted.') }");
huePubSub.publish('hue.global.info', {
message: "${ _('Task ') }" + data.history_uuid + "${_(' submitted.') }"
});
huePubSub.publish('notebook.task.submitted', data);
} else {
huePubSub.publish('hue.global.error', {message: data.message});
Expand Down Expand Up @@ -1899,7 +1913,9 @@ else:
"start_time": ko.mapping.toJSON((new Date()).getTime())
}, function (data) {
if (data.status == 0) {
$.jHueNotify.info("${ _('Task ') }" + data.history_uuid + "${_(' submitted.') }");
huePubSub.publish('hue.global.info', {
message: "${ _('Task ') }" + data.history_uuid + "${_(' submitted.') }"
});
huePubSub.publish('notebook.task.submitted', data);
} else {
huePubSub.publish('hue.global.error', {message: data.message});
Expand Down Expand Up @@ -2366,7 +2382,9 @@ else:
$('#progressStatusBar div').width(progress.toFixed() + "%");
},
canceled: function () {
$.jHueNotify.info(I18n('The upload has been canceled'));
huePubSub.publish('hue.global.info', {
message: I18n('The upload has been canceled')
});
},
complete: function (data) {
if (data.xhr.response != '') {
Expand Down Expand Up @@ -2509,7 +2527,9 @@ else:
}
});
if(isMoveOnSelf){
$.jHueNotify.warn("${ _('You cannot copy a folder into itself.') }");
huePubSub.publish('hue.global.warning', {
message: "${ _('You cannot copy a folder into itself.') }"
});
$('#moveDestination').val('');
return false;
}
Expand Down Expand Up @@ -2573,7 +2593,9 @@ else:
huePubSub.subscribe('submit.popup.return', function (data) {
if (data.type == 'external_workflow') {
$.jHueNotify.info('${_('Workflow submitted.')}');
huePubSub.publish('hue.global.info', {
message: "${_('Workflow submitted.')}"
});
huePubSub.publish('open.link', '/jobbrowser/#!id=' + data.job_id);
huePubSub.publish('browser.job.open.link', data.job_id);
$('.submit-modal').modal('hide');
Expand Down Expand Up @@ -2668,7 +2690,9 @@ else:
onEnter: function (el) {
var target_path = stripHashes(el.val());
if (el.val().split('/')[2] === '' && window.RAZ_IS_ENABLED){
$.jHueNotify.warn("${ _('Listing of buckets is not allowed. Redirecting to the home directory.') }");
huePubSub.publish('hue.global.warning', {
message: "${ _('Listing of buckets is not allowed. Redirecting to the home directory.') }"
});
target_path = window.USER_HOME_DIR;
}
fileBrowserViewModel.targetPath("${url('filebrowser:filebrowser.views.view', path='')}" + encodeURIComponent(target_path));
Expand Down
2 changes: 1 addition & 1 deletion apps/oozie/src/oozie/static/oozie/js/bundle-editor.ko.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ var BundleEditorViewModel = function (bundle_json, coordinators_json, can_edit_j

self.showSubmitPopup = function () {
// If self.bundle.id() == null, need to save wf for now
$(".jHueNotify").remove();
huePubSub.publish('hide.global.alerts');
if (!self.bundle.isDirty()) {
hueAnalytics.log('oozie/editor/bundle', 'submit');
$.get("/oozie/editor/bundle/submit/" + self.bundle.id(), {
Expand Down
6 changes: 3 additions & 3 deletions apps/oozie/src/oozie/static/oozie/js/coordinator-editor.ko.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ var CoordinatorEditorViewModel = (function () {
self.save = function (cb) {
if (!self.isSaving()) {
self.isSaving(true);
$(".jHueNotify").remove();
huePubSub.publish('hide.global.alerts');
$.post("/oozie/editor/coordinator/save/", {
"coordinator": ko.mapping.toJSON(self.coordinator, COORDINATOR_MAPPING)
}, function (data) {
Expand Down Expand Up @@ -277,7 +277,7 @@ var CoordinatorEditorViewModel = (function () {
};

self.gen_xml = function () {
$(".jHueNotify").remove();
huePubSub.publish('hide.global.alerts');
hueAnalytics.log('oozie/editor/coordinator', 'gen_xml');

$.post("/oozie/editor/coordinator/gen_xml/", {
Expand All @@ -295,7 +295,7 @@ var CoordinatorEditorViewModel = (function () {
};

self.showSubmitPopup = function () {
$(".jHueNotify").remove();
huePubSub.publish('hide.global.alerts');

if (!self.coordinator.isDirty()) {
hueAnalytics.log('oozie/editor/coordinator', 'submit');
Expand Down
6 changes: 3 additions & 3 deletions apps/oozie/src/oozie/static/oozie/js/workflow-editor.ko.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ var WorkflowEditorViewModel = function (layout_json, workflow_json, credentials_
self.save = function () {
if (! self.isSaving()) {
self.isSaving(true);
$(".jHueNotify").remove();
huePubSub.publish('hide.global.alerts');
$.post("/oozie/editor/workflow/save/", {
"layout": ko.mapping.toJSON(self.oozieColumns),
"workflow": ko.mapping.toJSON(self.workflow)
Expand Down Expand Up @@ -1246,7 +1246,7 @@ var WorkflowEditorViewModel = function (layout_json, workflow_json, credentials_
};

self.showSubmitPopup = function () {
$(".jHueNotify").remove();
huePubSub.publish('hide.global.alerts');
$.get("/oozie/editor/workflow/submit/" + self.workflow.id(), {
format: 'json',
cluster: self.compute() ? ko.mapping.toJSON(self.compute()) : '{}'
Expand All @@ -1258,7 +1258,7 @@ var WorkflowEditorViewModel = function (layout_json, workflow_json, credentials_
};

self.showSubmitActionPopup = function (w) {
$(".jHueNotify").remove();
huePubSub.publish('hide.global.alerts');
$.get("/oozie/editor/workflow/submit_single_action/" + self.workflow.id() + "/" + self.workflow.getNodeById(w.id()).id(), {
format: 'json'
}, function (data) {
Expand Down
4 changes: 3 additions & 1 deletion apps/oozie/src/oozie/templates/editor/submit_job_popup.mako
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@
if (data.message) {
message = data.message;
}
$.jHueNotify.error(data.message + (data.detail ? (': ' + data.detail) : ''));
huePubSub.publish('hue.global.error', {
message: data.message + (data.detail ? (': ' + data.detail) : '')
});
}
}
});
Expand Down
4 changes: 3 additions & 1 deletion apps/oozie/src/oozie/templates/editor2/bundle_editor.mako
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ ${ utils.submit_popup_event() }
huePubSub.subscribe('submit.popup.return', function (data) {
if (data.type == 'bundle') {
$.jHueNotify.info('${_('Bundle submitted.')}');
huePubSub.publish('hue.global.info', {
message: "${_('Bundle submitted.')}"
});
huePubSub.publish('open.link', '/jobbrowser/#!id=' + data.job_id);
huePubSub.publish('browser.job.open.link', data.job_id);
$('.submit-modal').modal('hide');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ ${ scheduler.import_sla_cron(coordinator_json) }
huePubSub.subscribe('submit.popup.return', function (data) {
if (data.type == 'schedule') {
$.jHueNotify.info('${_('Schedule submitted.')}');
huePubSub.publish('hue.global.info', {
message: "${_('Schedule submitted.')}"
});
huePubSub.publish('open.link', '/jobbrowser/#!id=' + data.job_id);
huePubSub.publish('browser.job.open.link', data.job_id);
$('.submit-modal').modal('hide');
Expand Down
4 changes: 3 additions & 1 deletion apps/oozie/src/oozie/templates/editor2/submit_job_popup.mako
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@
if (data.message) {
message = data.message;
}
$.jHueNotify.error(data.message + (data.detail ? (': ' + data.detail) : ''));
huePubSub.publish('hue.global.error', {
message: data.message + (data.detail ? (': ' + data.detail) : '')
});
}
}
});
Expand Down
4 changes: 3 additions & 1 deletion apps/oozie/src/oozie/templates/editor2/workflow_editor.mako
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,9 @@ ${ utils.submit_popup_event() }
huePubSub.subscribe('submit.popup.return', function (data) {
if (data.type == 'workflow') {
$.jHueNotify.info('${_('Workflow submitted.')}');
huePubSub.publish('hue.global.info', {
message: "${_('Workflow submitted.')}"
});
huePubSub.publish('open.link', '/jobbrowser/#!id=' + data.job_id);
huePubSub.publish('browser.job.open.link', data.job_id);
$('.submit-modal').modal('hide');
Expand Down
Loading

0 comments on commit 56f13d2

Please sign in to comment.