Browse Source

notification

main
pvincent 5 months ago
parent
commit
06bed6edc4
  1. 7
      app/controllers/scores_controller.rb
  2. 3
      app/views/layouts/_coucou.html.erb
  3. 57
      app/views/layouts/_notification.html.erb

7
app/controllers/scores_controller.rb

@ -42,8 +42,11 @@ class ScoresController < ApplicationController
# DELETE /scores/1
def destroy
@score.destroy!
redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
# @score.destroy!
# redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other
flash.now[:alert] = "this is 'destroyed!'"
render turbo_stream: turbo_stream.replace('notification', partial: 'layouts/notification')
end
private

3
app/views/layouts/_coucou.html.erb

@ -0,0 +1,3 @@
NOTIFICATION
COUCOU

57
app/views/layouts/_notification.html.erb

@ -1,28 +1,35 @@
<% if flash.count.positive? %>
<script data-turbo-temporary>
document.addEventListener('turbo:load',(e)=>{
const common={
gravity: 'top',
position: 'center',
duration: 4000,
offset: { y: '1em' },
close: true
<%= turbo_frame_tag 'notification' do %>
<% if flash.count.positive? %>
<script>
var commonOptions
var noticeOptions
var alertOptions
if (typeof commonOptions === 'undefined'){
commonOptions={
gravity: 'top',
position: 'center',
duration: 4000,
offset: { y: '1em' },
close: true
}
noticeOptions={ className: 'toastify-notice', ...commonOptions }
alertOptions={ className: 'toastify-alert', ...commonOptions }
}
const notice={ className: 'toastify-notice', ...common }
const alert={ className: 'toastify-alert', ...common }
<% if flash.notice%>
Toastify({ text: '<%=flash.notice%>', ...notice}).showToast();
<%end%>
<% if flash.alert%>
Toastify({ text: '<%=flash.alert%>', ...alert}).showToast();
<%end%>
// useful to prevent flickering from turbo preview
Turbo.cache.exemptPageFromPreview()
var notice='<%= flash.notice %>'
var alert='<%= flash.alert %>'
<% flash.clear %>
}, {once: true})
</script>
<%end%>
if (notice.length>0){
console.info(`TOAST notice: ${notice}`)
Toastify({ text: notice, ...noticeOptions }).showToast();
notice=''
}
if (alert.length>0){
console.warn(`TOAST alert: ${alert}`)
Toastify({ text: alert, ...alertOptions }).showToast();
alert=''
}
</script>
<% end %>
<% end %>
Loading…
Cancel
Save