From 53cdbc2638964bcc214d5557cd7420acd21ada59 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Mon, 29 Aug 2016 13:45:54 +0200 Subject: [PATCH 1/7] fixes notification when adding new sample --- .../javascripts/samples/sample_datatable.js | 1 + app/controllers/samples_controller.rb | 24 +++++++++++++++++-- config/locales/en.yml | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/samples/sample_datatable.js b/app/assets/javascripts/samples/sample_datatable.js index dc5c18d96..547469f68 100644 --- a/app/assets/javascripts/samples/sample_datatable.js +++ b/app/assets/javascripts/samples/sample_datatable.js @@ -398,6 +398,7 @@ function onClickSave() { dataType: "json", data: data, success: function (data) { + sampleAlertMsg(data.flash); onClickCancel(); }, error: function (e, eData, status, xhr) { diff --git a/app/controllers/samples_controller.rb b/app/controllers/samples_controller.rb index e20b081b8..21e8cae0f 100644 --- a/app/controllers/samples_controller.rb +++ b/app/controllers/samples_controller.rb @@ -80,7 +80,17 @@ class SamplesController < ApplicationController errors.delete_if { |k, v| v.blank? } if errors.empty? - format.json { render json: {}, status: :ok } + format.json { + render json: { + id: sample.id, + flash: t( + 'samples.create.success_flash', + sample: sample.name, + organization: @organization.name + ) + }, + status: :ok + } else format.json { render json: errors, status: :bad_request } end @@ -227,7 +237,17 @@ class SamplesController < ApplicationController # Now we can destroy empty scfs scf_to_delete.map(&:destroy) - format.json { render json: {}, status: :ok } + format.json { + render json: { + id: sample.id, + flash: t( + 'samples.update.success_flash', + sample: sample.name, + organization: @organization.name + ) + }, + status: :ok + } else format.json { render json: errors, status: :bad_request } end diff --git a/config/locales/en.yml b/config/locales/en.yml index 7353228bb..0f1ba935a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -909,7 +909,7 @@ en: create: "Edit sample" scf_does_not_exist: "This field does not exists." create: - success_flash: "Successfully added sample to team %{organization}" + success_flash: "Successfully added sample %{sample} to team %{organization}" update: success_flash: "Successfully updated sample %{sample} to team %{organization}" destroy: From 60b0d69a722991b9aa968af2c26a13c835c3f493 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Mon, 29 Aug 2016 13:56:05 +0200 Subject: [PATCH 2/7] fixes hound --- app/controllers/samples_controller.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/app/controllers/samples_controller.rb b/app/controllers/samples_controller.rb index 21e8cae0f..045f87011 100644 --- a/app/controllers/samples_controller.rb +++ b/app/controllers/samples_controller.rb @@ -80,17 +80,15 @@ class SamplesController < ApplicationController errors.delete_if { |k, v| v.blank? } if errors.empty? - format.json { - render json: { + format.json + render json: id: sample.id, flash: t( 'samples.create.success_flash', sample: sample.name, organization: @organization.name - ) - }, + ), status: :ok - } else format.json { render json: errors, status: :bad_request } end @@ -237,17 +235,15 @@ class SamplesController < ApplicationController # Now we can destroy empty scfs scf_to_delete.map(&:destroy) - format.json { - render json: { + format.json + render json: id: sample.id, flash: t( 'samples.update.success_flash', sample: sample.name, organization: @organization.name - ) - }, + ), status: :ok - } else format.json { render json: errors, status: :bad_request } end From 7f8bb9be53c5bc658bd6ec8cc5f2086c3b376979 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Mon, 29 Aug 2016 13:59:51 +0200 Subject: [PATCH 3/7] fixes hound again --- app/controllers/samples_controller.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/samples_controller.rb b/app/controllers/samples_controller.rb index 045f87011..8e69cb746 100644 --- a/app/controllers/samples_controller.rb +++ b/app/controllers/samples_controller.rb @@ -81,13 +81,14 @@ class SamplesController < ApplicationController errors.delete_if { |k, v| v.blank? } if errors.empty? format.json - render json: + render json: { id: sample.id, flash: t( 'samples.create.success_flash', sample: sample.name, organization: @organization.name - ), + ) + }, status: :ok else format.json { render json: errors, status: :bad_request } @@ -236,13 +237,14 @@ class SamplesController < ApplicationController scf_to_delete.map(&:destroy) format.json - render json: + render json: { id: sample.id, flash: t( 'samples.update.success_flash', sample: sample.name, organization: @organization.name - ), + ) + }, status: :ok else format.json { render json: errors, status: :bad_request } From b07f1af90fe17a3f3be304a218064a6454425e47 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Mon, 29 Aug 2016 17:08:00 +0200 Subject: [PATCH 4/7] fixes hound again again --- app/controllers/samples_controller.rb | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/controllers/samples_controller.rb b/app/controllers/samples_controller.rb index 8e69cb746..3cb5b5e59 100644 --- a/app/controllers/samples_controller.rb +++ b/app/controllers/samples_controller.rb @@ -81,15 +81,15 @@ class SamplesController < ApplicationController errors.delete_if { |k, v| v.blank? } if errors.empty? format.json - render json: { - id: sample.id, - flash: t( - 'samples.create.success_flash', - sample: sample.name, - organization: @organization.name - ) - }, - status: :ok + render json: { + id: sample.id, + flash: t( + 'samples.create.success_flash', + sample: sample.name, + organization: @organization.name + ) + }, + status: :ok else format.json { render json: errors, status: :bad_request } end @@ -237,15 +237,15 @@ class SamplesController < ApplicationController scf_to_delete.map(&:destroy) format.json - render json: { - id: sample.id, - flash: t( - 'samples.update.success_flash', - sample: sample.name, - organization: @organization.name - ) - }, - status: :ok + render json: { + id: sample.id, + flash: t( + 'samples.update.success_flash', + sample: sample.name, + organization: @organization.name + ) + }, + status: :ok else format.json { render json: errors, status: :bad_request } end From a35bf7182f9380cb930571f0656bff5e54b3150b Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Tue, 30 Aug 2016 09:43:39 +0200 Subject: [PATCH 5/7] fixes troubles --- app/controllers/samples_controller.rb | 42 ++++++++++++++------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/app/controllers/samples_controller.rb b/app/controllers/samples_controller.rb index 3cb5b5e59..5622d9572 100644 --- a/app/controllers/samples_controller.rb +++ b/app/controllers/samples_controller.rb @@ -80,16 +80,17 @@ class SamplesController < ApplicationController errors.delete_if { |k, v| v.blank? } if errors.empty? - format.json - render json: { - id: sample.id, - flash: t( - 'samples.create.success_flash', - sample: sample.name, - organization: @organization.name - ) - }, - status: :ok + format.json do + render json: { + id: sample.id, + flash: t( + 'samples.create.success_flash', + sample: sample.name, + organization: @organization.name + ) + }, + status: :ok + end else format.json { render json: errors, status: :bad_request } end @@ -236,16 +237,17 @@ class SamplesController < ApplicationController # Now we can destroy empty scfs scf_to_delete.map(&:destroy) - format.json - render json: { - id: sample.id, - flash: t( - 'samples.update.success_flash', - sample: sample.name, - organization: @organization.name - ) - }, - status: :ok + format.json do + render json: { + id: sample.id, + flash: t( + 'samples.update.success_flash', + sample: sample.name, + organization: @organization.name + ) + }, + status: :ok + end else format.json { render json: errors, status: :bad_request } end From 1b1e6daa212cf0793bbc83340c1673ba12a1da89 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Tue, 30 Aug 2016 16:55:59 +0200 Subject: [PATCH 6/7] fixes notification disappearance and error notifications --- .../javascripts/samples/sample_datatable.js | 19 ++++++--------- app/assets/javascripts/samples/samples.js | 23 +++++++++++++++---- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/samples/sample_datatable.js b/app/assets/javascripts/samples/sample_datatable.js index 547469f68..985c3b6c5 100644 --- a/app/assets/javascripts/samples/sample_datatable.js +++ b/app/assets/javascripts/samples/sample_datatable.js @@ -336,7 +336,7 @@ function onClickEdit() { }, error: function (e, data, status, xhr) { if (e.status == 403) { - showAlertMessage(I18n.t("samples.js.permission_error")); + sampleAlertMsg(I18n.t("samples.js.permission_error"), "danger"); changeToViewMode(); updateButtons(); } @@ -398,20 +398,21 @@ function onClickSave() { dataType: "json", data: data, success: function (data) { - sampleAlertMsg(data.flash); + sampleAlertMsg(data.flash, "success"); onClickCancel(); }, error: function (e, eData, status, xhr) { var data = e.responseJSON; clearAllErrors(); + sampleAlertMsgHide(); if (e.status == 404) { - showAlertMessage(I18n.t("samples.js.not_found_error")); + sampleAlertMsg(I18n.t("samples.js.not_found_error"), "danger"); changeToViewMode(); updateButtons(); } else if (e.status == 403) { - showAlertMessage(I18n.t("samples.js.permission_error")); + sampleAlertMsg(I18n.t("samples.js.permission_error"), "danger"); changeToViewMode(); updateButtons(); } @@ -611,7 +612,7 @@ function onClickAddSample() { }, error: function (e, eData, status, xhr) { if (e.status == 403) - showAlertMessage(I18n.t("samples.js.permission_error")); + sampleAlertMsg(I18n.t("samples.js.permission_error"), "danger"); changeToViewMode(); updateButtons(); } @@ -705,10 +706,4 @@ function changeToEditMode() { // Table specific stuff table.button(0).enable(false); -} - -// Shows alert and changes -function showAlertMessage(msg) { - $("#alert-container").append("
Error! " + msg + "
"); -} - +} \ No newline at end of file diff --git a/app/assets/javascripts/samples/samples.js b/app/assets/javascripts/samples/samples.js index 973cd15b7..41ab8b6a4 100644 --- a/app/assets/javascripts/samples/samples.js +++ b/app/assets/javascripts/samples/samples.js @@ -45,7 +45,7 @@ $("#modal-create-sample-type").on("shown.bs.modal", function(event) { $("form#new_sample_type").on("ajax:success", function(ev, data, status) { $("#modal-create-sample-type").modal("hide"); updateSamplesTypesandGroups(); - sampleAlertMsg(data.flash); + sampleAlertMsg(data.flash, "success"); currentMode = "viewMode"; updateButtons(); }); @@ -76,7 +76,7 @@ $("#modal-create-sample-group").on("shown.bs.modal", function(event) { $("form#new_sample_group").on("ajax:success", function(ev, data, status) { $("#modal-create-sample-group").modal("hide"); updateSamplesTypesandGroups(); - sampleAlertMsg(data.flash); + sampleAlertMsg(data.flash, "success"); currentMode = "viewMode"; updateButtons(); }); @@ -147,11 +147,19 @@ function updateSamplesTypesandGroups() { }); } -function sampleAlertMsg(message) { - var html_snippet = '
' + +function sampleAlertMsg(message, type) { + var alert_type, glyph_sign; + if (type == "success") { + alert_type = " alert-success "; + glyph_sign = " glyphicon-ok-sign "; + } else if (type == "danger") { + alert_type = " alert-danger "; + glyph_sign = " glyphicon-exclamation-sign "; + } + var html_snippet = '
' + '
' + '' + - '' + + '' + ''+ message +'' + '
' + '
'; @@ -159,6 +167,11 @@ function sampleAlertMsg(message) { $('#content-wrapper').addClass('alert-shown'); } +function sampleAlertMsgHide() { + $('#notifications').html('
'); + $('#content-wrapper').removeClass('alert-shown'); +} + function initTutorial() { var currentStep = parseInt(Cookies.get('current_tutorial_step'), 10); if (currentStep == 8) From dd8e5d5e12fd36824ed99dd6b5901cc6436b2864 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Tue, 30 Aug 2016 17:12:26 +0200 Subject: [PATCH 7/7] fixes hound --- app/assets/javascripts/samples/samples.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/samples/samples.js b/app/assets/javascripts/samples/samples.js index 41ab8b6a4..ab48e2462 100644 --- a/app/assets/javascripts/samples/samples.js +++ b/app/assets/javascripts/samples/samples.js @@ -148,22 +148,22 @@ function updateSamplesTypesandGroups() { } function sampleAlertMsg(message, type) { - var alert_type, glyph_sign; - if (type == "success") { - alert_type = " alert-success "; - glyph_sign = " glyphicon-ok-sign "; - } else if (type == "danger") { - alert_type = " alert-danger "; - glyph_sign = " glyphicon-exclamation-sign "; + var alertType, glyphSign; + if (type == 'success') { + alertType = ' alert-success '; + glyphSign = ' glyphicon-ok-sign '; + } else if (type == 'danger') { + alertType = ' alert-danger '; + glyphSign = ' glyphicon-exclamation-sign '; } - var html_snippet = '
' + + var htmlSnippet = '
' + '
' + '' + - '' + + '' + ''+ message +'' + '
' + '
'; - $('#notifications').html(html_snippet); + $('#notifications').html(htmlSnippet); $('#content-wrapper').addClass('alert-shown'); }