Skip to content

Commit

Permalink
Notices for discarding and undiscarding scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
noracato committed Oct 29, 2024
1 parent 66e9b49 commit 45648f6
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 21 deletions.
7 changes: 7 additions & 0 deletions app/components/notice_banner/component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="rounded-md border flex border-grey-200 p-2 px-5 mt-5 text-sm text-midnight-800">
<span class="mr-5"><%= heroicon @icon, options: { class: 'w-5 h-5' } %></span>
<span class="mr-2"><%= @text %></span>
<% if @path %>
<span class="underline hover:text-midnight-980"><%= link_to @button_text, @path, method: :put, data: { 'turbo-method': :put }%></span>
<% end %>
</div>
8 changes: 8 additions & 0 deletions app/components/notice_banner/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module NoticeBanner
class Component < ApplicationComponent
option :text
option :path, default: proc { "" }
option :button_text, default: proc { "" }
option :icon, default: proc { 'information-circle' }
end
end
5 changes: 5 additions & 0 deletions app/components/notice_banner/trash_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module NoticeBanner
class TrashComponent < Component
option :icon, default: proc { "trash" }
end
end
2 changes: 1 addition & 1 deletion app/components/saved_scenarios/nav_item/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def css_classes
elsif @static
"text-midnight-800 hover:underline"
else
"text-midnight-400 hover:text-midnight-800"
"text-midnight-450 hover:text-midnight-800"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/components/sidebar_item/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Component < ApplicationComponent
option :title
option :icon
option :active, default: proc { false }
option :text, default: proc { "text-midnight-400" }
option :text, default: proc { "text-midnight-450" }

def css_classes
if @active
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/discarded_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Index of all discarded scenarios and collections
class DiscardedController < ApplicationController
before_action :require_user

def index
@resources = current_user
.saved_scenarios
.discarded
.includes(:featured_scenario, :users)
.order('updated_at DESC')
end
end
10 changes: 5 additions & 5 deletions app/controllers/saved_scenarios_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def discard
@saved_scenario.discarded_at = Time.zone.now
@saved_scenario.save(touch: false)

flash.notice = t('scenario.trash.discarded_flash')
flash[:undo_params] = [undiscard_saved_scenario_path(@saved_scenario), { method: :put }]
flash.notice = t('trash.discarded_flash')
flash[:undo_params] = undiscard_saved_scenario_path(@saved_scenario)
end

redirect_back(fallback_location: saved_scenarios_path)
Expand All @@ -129,11 +129,11 @@ def undiscard
@saved_scenario.discarded_at = nil
@saved_scenario.save(touch: false)

flash.notice = t('scenario.trash.undiscarded_flash')
flash[:undo_params] = [discard_saved_scenario_path(@saved_scenario), { method: :put }]
flash.notice = t('trash.undiscarded_flash')
flash[:undo_params] = discard_saved_scenario_path(@saved_scenario)
end

redirect_back(fallback_location: discarded_saved_scenarios_path)
redirect_back(fallback_location: discarded_path)
end

private
Expand Down
12 changes: 12 additions & 0 deletions app/views/discarded/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- content_for :title, t('trash.title')
- content_for :menu_title, t('trash.title')
- content_for :block_right, "FILTERS"

- if @resources.present?
- @resources.each do |resource|
- if resource.is_a?(SavedScenario)
= render(SavedScenarios::Row::Component.new(path: saved_scenario_path(resource), saved_scenario: resource))
- else
.text-sm.text-midnight-400.mb-2=t('trash.empty.title')

=t('trash.empty.description', deleted_after: SavedScenario::AUTO_DELETES_AFTER.in_days.to_i)
2 changes: 1 addition & 1 deletion app/views/layouts/_sidebar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

= render(SidebarItem::Component.new(path: saved_scenarios_path, title: t('sidebar.collections'), icon: 'chart-bar-square', active: controller_name == 'collections'))

= render(SidebarItem::Component.new(path: saved_scenarios_path, title: t('sidebar.discarded'), icon: 'trash', active: controller_name == 'discarded'))
= render(SidebarItem::Component.new(path: discarded_path, title: t('sidebar.discarded'), icon: 'trash', active: controller_name == 'discarded'))

.absolute.bottom-0.left-0.inline-block.w-full
.p-5.pl-6.text-midnight-800
Expand Down
1 change: 0 additions & 1 deletion app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
= render partial: "layouts/buttons"
.text-xl.mb-5.mt-5
= yield(:menu_title)
%span.text-sm.ml-3.text-midnight-980= notice_message
.grow
.flex.h-full
%div{class: 'basis-3/4'}
Expand Down
30 changes: 21 additions & 9 deletions app/views/saved_scenarios/_block_right_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
title: t("scenario_bar.private.#{saved_scenario.private}"),
icon_on:'eye-slash',
icon_off: 'eye',
available: saved_scenario.collaborator?(current_user)
available: saved_scenario.collaborator?(current_user) && !saved_scenario.discarded?
))%>
<% end %>
<% if current_user&.admin? %>
<% if current_user&.admin? && !saved_scenario.discarded? %>
<%= render(Hovercard::Component.new(
path: '',
text: t("scenario_bar.featured.description.#{saved_scenario.featured?}")
Expand All @@ -48,7 +48,9 @@
)%>
<% end %>
<% end %>
<% if !(current_user&.admin? && saved_scenario.featured?) && saved_scenario.collaborator?(current_user)%>
<% if
!(current_user&.admin? && saved_scenario.featured?) &&
(saved_scenario.collaborator?(current_user) && !saved_scenario.discarded?)%>
<%= render(Hovercard::Component.new(
path: '',
text: t("scenario_bar.edit.description")
Expand All @@ -62,10 +64,20 @@
))%>
<% end %>
<% end %>
<%= render(SavedScenarios::NavItem::Component.new(
path: saved_scenario_path(saved_scenario),
title: t("scenario_bar.discard"),
icon: 'trash',
static: true)
)%>
<% if saved_scenario.collaborator?(current_user)%>
<%= render(Hovercard::Component.new(
path: '',
text: t("scenario_bar.discarded.description.#{saved_scenario.discarded?}")
)) do %>
<%= render(SavedScenarios::Publish::Component.new(
path_on: undiscard_saved_scenario_path(saved_scenario),
path_off: discard_saved_scenario_path(saved_scenario),
status: saved_scenario.discarded?,
title: t("scenario_bar.discarded.#{saved_scenario.discarded?}"),
icon_on: 'arrow-uturn-up',
icon_off: 'trash',
available: saved_scenario.collaborator?(current_user)
))%>
<% end %>
<% end %>
<% end %>
11 changes: 10 additions & 1 deletion app/views/saved_scenarios/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
= render(partial: "block_right_menu", locals: { saved_scenario: @saved_scenario })

= render(SavedScenarios::Info::Component.new(path: saved_scenario_path(@saved_scenario), button_title: t('saved_scenario.open'), saved_scenario: @saved_scenario, time: time_ago_in_words(@saved_scenario.updated_at)))

- if flash[:undo_params]
= render(NoticeBanner::Component.new(path: flash[:undo_params], text: notice_message, button_text: "#{t('undo')}?"))
- elsif notice_message
= render(NoticeBanner::Component.new(text: notice_message))

- if @saved_scenario.discarded?
= render(NoticeBanner::TrashComponent.new(text: t('trash.notice', deleted_after: SavedScenario::AUTO_DELETES_AFTER.in_days.to_i)))

= render(HovercardWithVersion::Component.new(version: @saved_scenario.version))

%div.mt-5.mb-5.pb-5.border-b.border-solid.border-gray-200
Expand All @@ -20,7 +29,7 @@
.mt-5.show-description
- if @saved_scenario.localized_description(I18n.locale).presence
= @saved_scenario.localized_description(I18n.locale)
- elsif @saved_scenario.description.blank? && @saved_scenario.collaborator?(current_user)
- elsif @saved_scenario.description.blank? && @saved_scenario.collaborator?(current_user) && !@saved_scenario.discarded?
=link_to edit_saved_scenario_path(@saved_scenario), class: 'hover:underline' do
= t('scenario.no_description')
= t('scenario.create_description')
Expand Down
26 changes: 24 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
# enabled: "ON"

en:
undo: Undo

time:
formats:
short: "%-d %b %H:%M"
Expand Down Expand Up @@ -74,7 +76,12 @@ en:
edit:
title: Edit
description: Edit the title and description of this scenario
discard: Discard
discarded:
true: Restore
false: Discard
description:
true: Restore from the trash bin
false: Move to trash. After 60 days it will be permanently destroyed.
private:
true: Private
false: Public
Expand All @@ -89,12 +96,13 @@ en:
true: This scenario has been featured on a home page. Edit settings here.
false: Feature this scenario on the home page
scenario:
succesful_update: updated!
succesful_update: Your scenario was succesfully updated
title: Title
save: Save
discard_changes: Discard changes
no_description: This scenario has no description.
create_description: Click here to create one.

saved_scenarios:
empty: You don't have any scenarios.
featured_scenarios:
Expand All @@ -109,9 +117,23 @@ en:
irreversible: This action is irreversible
submit: Confirm unfeaturing

trash:
title: Trash bin
notice: Scenarios in the trash will be automatically deleted after %{deleted_after} days.
discarded_flash: Your scenario was put in the trash
undiscarded_flash: Your scenario was restored
deleted_flash: Your scenario has been permanently deleted
empty:
title:
There are no items in the trash
description:
Deleted items are sent to the trash where you can choose to permanently
delete or restore them. Trashed scenarios are automatically removed after %{deleted_after}
days.
flash:
need_login: Please log in again
version:
latest: |
This scenario was created in the live version of the ETM
which includes all the latest monthly updates. Learn more..
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
member do
put :publish
put :unpublish
put :discard
put :undiscard
end
end

get :discarded, to: 'discarded#index'

# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

use_doorkeeper
Expand Down
5 changes: 5 additions & 0 deletions config/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ module.exports = {
},
colors: {
midnight: {
// light and medium background
200: "#fdfdfd",
300: "#fbf7f6",
// light gray & medium gray
400: "#aba8a7",
450: 'rgb(125, 118, 115)',
// dark background
600: "#fdece0",
// dark text
800: "#462c34",
// brand colors (blue, orange, green)
900: "#4e7be4",
Expand Down

0 comments on commit 45648f6

Please sign in to comment.