Skip to content

Commit

Permalink
Merge pull request #52 from rockandror/ciudades-abiertas/installation…
Browse files Browse the repository at this point in the history
…-wizard

Ciudades abiertas/installation wizard
  • Loading branch information
taitus authored Sep 30, 2019
2 parents 23cb169 + 559456a commit fcd572a
Show file tree
Hide file tree
Showing 33 changed files with 523 additions and 17 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
@import "autocomplete_overrides";
@import "jquery-ui/sortable";
@import "leaflet";
@import "wizard";
46 changes: 46 additions & 0 deletions app/assets/stylesheets/wizard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.wizard {
h3 {
margin-bottom: 0;
}

h3,
.current-step {
display: inline-block;
padding: .7em 0;
}

.current-step {
@include breakpoint(medium) {
margin-left: $line-height;
}
}

.btn-back-step {
margin-right: $line-height;
}

.btn-back-step i {
position: relative;
&:before {
position: absolute;
top: 2px;
left: -20px;
}
}

.v-aligner {
display: flex;
align-items: center;
justify-content: center;
}

.button {
margin-bottom: 0;
}

@include breakpoint(small) {
input.button {
padding: 1em 0;
}
}
}
5 changes: 1 addition & 4 deletions app/controllers/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,10 @@ def settings_by_group(group)
when "advanced"
[all_settings["advanced.auth"]] + [all_settings["advanced.tracking"]]
when "regional"
[all_settings["regional.default_locale"]] + [valid_regional_available_locales(all_settings)] + [all_settings["regional.time_zone"]]
[all_settings["regional.default_locale"]] + [all_settings["regional.available_locale"]] + [all_settings["regional.time_zone"]]
else
all_settings[group]
end
end

def valid_regional_available_locales(all_settings)
all_settings["regional.available_locale"].select { |s| s.key.rpartition(".").last.to_sym != I18n.default_locale }
end
end
51 changes: 51 additions & 0 deletions app/controllers/admin/wizards/installer_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class Admin::Wizards::InstallerController < Admin::BaseController
layout "wizard"

before_action :set_total_steps
before_action :set_settings, only: :show

def new
end

def show
render params[:id]
end

private

def set_total_steps
@total_steps = 7
end

def set_settings
case params[:id]
when "general_settings"
@settings = [Setting.find_by(key: "org_name"),
Setting.find_by(key: "min_age_to_participate")]
when "participation_process"
@settings = [[Setting.find_by(key: "process.debates"),
Setting.find_by(key: "process.proposals"),
Setting.find_by(key: "votes_for_proposal_success"),
Setting.find_by(key: "process.polls"),
Setting.find_by(key: "process.budgets")]]
when "map"
@settings = [[Setting.find_by(key: "feature.map"),
Setting.find_by(key: "map.latitude"),
Setting.find_by(key: "map.longitude"),
Setting.find_by(key: "map.zoom")]]
when "smtp"
@settings = [Setting.find_by(key: "feature.smtp_configuration"),
Setting.find_by(key: "smtp.address"),
Setting.find_by(key: "smtp.port"),
Setting.find_by(key: "smtp.domain"),
Setting.find_by(key: "smtp.username"),
Setting.find_by(key: "smtp.password"),
Setting.find_by(key: "smtp.authentication"),
Setting.find_by(key: "smtp.enable_starttls_auto")]
when "regional"
all_settings = Setting.all.group_by { |setting| setting.type }
@settings = [all_settings["regional.default_locale"]] + [all_settings["regional.available_locale"]] + [all_settings["regional.time_zone"]]
end
end

end
7 changes: 7 additions & 0 deletions app/controllers/admin/wizards_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Admin::WizardsController < Admin::BaseController

def index
@wizards = ["installation"].freeze
end

end
2 changes: 1 addition & 1 deletion app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def menu_profiles?

def menu_settings?
controllers_names = ["settings", "tags", "geozones", "images", "content_blocks",
"local_census_records", "imports"]
"local_census_records", "imports", "wizards"]
controllers_names.include?(controller_name) &&
controller.class.parent != Admin::Poll::Questions::Answers
end
Expand Down
27 changes: 22 additions & 5 deletions app/helpers/settings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,35 @@ def setting
@all_settings ||= Hash[Setting.all.map { |s| [s.key, s.value.presence] }]
end

def is_feature?(setting)
social_feature?(setting) ||
advanced_feature?(setting) ||
smtp_feature?(setting) ||
regional_feature?(setting) ||
process_feature?(setting) ||
map_feature?(setting)
end

def social_feature?(setting)
key = setting.key.split(".")
key.first == "social" && key.last == "login"
end

def advanced_feature?(setting)
key = setting.key.split(".")
key.first == "advanced" && key.last == "http_basic_auth"
setting.key == "advanced.auth.http_basic_auth"
end

def smtp_feature?(setting)
setting.key == "smtp.enable_starttls_auto" || setting.key == "feature.smtp_configuration"
end

def process_feature?(setting)
key = setting.key.split(".")
key.first == "smtp" && key.last == "enable_starttls_auto"
key.first == "process"
end

def is_feature?(setting)
social_feature?(setting) || advanced_feature?(setting) || smtp_feature?(setting) || regional_feature?(setting)
def map_feature?(setting)
setting.key == "feature.map"
end

def regional_feature?(setting)
Expand All @@ -42,4 +54,9 @@ def regional_setting?(setting)
setting.type.rpartition(".").first == "regional"
end

def need_disable_language?(setting)
setting_locale = setting.key.rpartition(".").last.to_sym
setting_locale == I18n.default_locale || setting_locale == I18n.locale
end

end
4 changes: 4 additions & 0 deletions app/views/admin/_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@
<li <%= "class=is-active" if submenu_local_census_records? %>>
<%= link_to t("admin.menu.local_census_records"), admin_local_census_records_path %>
</li>

<li <%= "class=is-active" if controller_name == "wizards" %>>
<%= link_to t("admin.menu.wizards"), admin_wizards_path %>
</li>
</ul>
</li>
<li class="section-title">
Expand Down
3 changes: 2 additions & 1 deletion app/views/admin/settings/_featured_settings_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<%= f.hidden_field :value, id: dom_id(feature), value: (feature.enabled? ? "" : "active") %>
<%= f.submit(t("admin.settings.index.features.#{feature.enabled? ? "disable" : "enable"}"),
class: "button expanded #{feature.enabled? ? "hollow alert" : "success"}",
data: { confirm: t("admin.actions.confirm") }) %>
disabled: need_disable_language?(feature),
data: {confirm: t("admin.actions.confirm") }) %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/admin/settings/_featured_settings_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</thead>
<tbody>
<% features.each do |feature| %>
<tr>
<tr class="setting">
<td class="small-8">
<strong><%= t("settings.#{feature.key}") %></strong>
<br>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/settings/_mixed_settings_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</thead>
<tbody>
<% settings.each do |setting| %>
<tr>
<tr class="setting">
<td class="small-6">
<strong><%= t("settings.#{setting.key}") %></strong>
<br>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/settings/_settings_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</thead>
<tbody>
<% settings.each do |setting| %>
<tr>
<tr class="setting">
<td class="small-6">
<strong><%= t("settings.#{setting.key}") %></strong>
<br>
Expand Down
19 changes: 19 additions & 0 deletions app/views/admin/wizards/_header_steps.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="columns padding v-aligner">
<div class="medium-6 columns">
<h3><%= t("wizard.header.title") %></h3>
<span class="current-step"><%= t("wizard.header.step") %> <%= current_step %> <%= t("wizard.header.step_of") %> <%= total_steps %></span>
</div>

<div class="medium-6 columns text-right">
<% if defined?(back_step) %>
<%= link_to back_step, class: "btn-back-step" do %>
<i class="icon-arrow-left"></i>
<%= t("wizard.header.back_step") %>
<% end %>
<% end %>
<% if defined?(next_step) %>
<%= link_to t("wizard.header.next_step"), next_step, class: "button" %>
<% end %>
</div>
</div>
<hr>
12 changes: 12 additions & 0 deletions app/views/admin/wizards/_wizard.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<tr id="<%= wizard %>-section">
<td class="small-9">
<strong><%= t("wizard.admin.module_title") %></strong>
<br>
<span class="small">
<%= t("wizard.admin.description") %>
</span>
</td>
<td class="small-3">
<%= link_to t("admin.actions.configure"), new_admin_wizards_installer_path, class: "button hollow" %>
</td>
</tr>
8 changes: 8 additions & 0 deletions app/views/admin/wizards/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h2><%= t("wizard.admin.title") %></h2>
<div>
<table>
<tbody>
<%= render partial: "wizard", collection: @wizards %>
</tbody>
</table>
</div>
11 changes: 11 additions & 0 deletions app/views/admin/wizards/installer/finish.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= render "admin/wizards/header_steps", current_step: 7,
total_steps: @total_steps,
back_step: admin_wizards_installer_path(:regional) %>

<div class="medium-12 columns">
<div class="columns">
<h2><%= t("wizard.finish.title") %></h2>
<p><%= t("wizard.finish.description_html") %></p>
<%= link_to t("wizard.finish.btn_finish"), admin_root_path, class: "button" %>
</div>
</div>
12 changes: 12 additions & 0 deletions app/views/admin/wizards/installer/general_settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= render "admin/wizards/header_steps", current_step: 2,
total_steps: @total_steps,
back_step: new_admin_wizards_installer_path,
next_step: admin_wizards_installer_path(:participation_process) %>

<div class="medium-12 columns">
<div id="installer-general-settings" class="columns">
<h2><%= t("admin.menu.settings") %></h2>
<p><%= t("wizard.general_settings.description_html") %></p>
<%= render "admin/settings/settings_table", settings: @settings %>
</div>
</div>
17 changes: 17 additions & 0 deletions app/views/admin/wizards/installer/map.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= render "admin/wizards/header_steps", current_step: 4,
total_steps: @total_steps,
back_step: admin_wizards_installer_path(:participation_process),
next_step: admin_wizards_installer_path(:smtp) %>

<div class="medium-12 columns">
<div id="installer-map" class="columns">
<h2><%= t("admin.settings.index.map.title") %></h2>
<p><%= t("wizard.map.description_html") %></p>
<%#= render "admin/settings/settings_table", settings: @settings %>
<% @settings.each do |setting_group| %>
<%= render "admin/settings/mixed_settings_table", settings: setting_group %>
<% end %>
<p><%= t("admin.settings.index.map.help") %></p>
<%= render "admin/settings/map_form" %>
</div>
</div>
10 changes: 10 additions & 0 deletions app/views/admin/wizards/installer/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= render "admin/wizards/header_steps", current_step: 1,
total_steps: @total_steps %>

<div class="medium-12 columns">
<div class="columns">
<h2><%= t("wizard.new.title") %></h2>
<p><%= t("wizard.new.description_html") %></p>
<%= link_to t("wizard.new.btn_start"), admin_wizards_installer_path(:general_settings), class: "button" %>
</div>
</div>
14 changes: 14 additions & 0 deletions app/views/admin/wizards/installer/participation_process.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= render "admin/wizards/header_steps", current_step: 3,
total_steps: @total_steps,
back_step: admin_wizards_installer_path(:general_settings),
next_step: admin_wizards_installer_path(:map) %>

<div class="medium-12 columns">
<div id="installer-participation-process" class="columns">
<h2><%= t("admin.settings.index.process.title") %></h2>
<p><%= t("wizard.partecipation_process.description_html") %></p>
<% @settings.each do |setting_group| %>
<%= render "admin/settings/mixed_settings_table", settings: setting_group %>
<% end %>
</div>
</div>
15 changes: 15 additions & 0 deletions app/views/admin/wizards/installer/regional.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%= render "admin/wizards/header_steps", current_step: 6,
total_steps: @total_steps,
back_step: admin_wizards_installer_path(:smtp),
next_step: admin_wizards_installer_path(:finish) %>

<div class="medium-12 columns">
<div id="installer-regional" class="columns">
<h2><%= t("wizard.regional.title") %></h2>
<p><%= t("wizard.regional.description_html") %></p>
<% @settings.each do |setting_group| %>
<h3><%= t("admin.settings.index.regional.#{setting_group.first.key.split(".").second}") %></h3>
<%= render "admin/settings/mixed_settings_table", settings: setting_group %>
<% end %>
</div>
</div>
12 changes: 12 additions & 0 deletions app/views/admin/wizards/installer/smtp.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= render "admin/wizards/header_steps", current_step: 5,
total_steps: @total_steps,
back_step: admin_wizards_installer_path(:map),
next_step: admin_wizards_installer_path(:regional) %>

<div class="medium-12 columns">
<div id="installer-smtp" class="columns">
<h2><%= t("wizard.smtp.title") %></h2>
<p><%= t("wizard.smtp.description_html") %></p>
<%= render "admin/settings/mixed_settings_table", settings: @settings %>
</div>
</div>
25 changes: 25 additions & 0 deletions app/views/layouts/wizard.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="es">

<head>
<%= render "layouts/common_head", default_title: "Admin" %>
<%= content_for :head %>
</head>

<body class="admin" data-watch-form-message="<%= I18n.t("layouts.admin.watch_form_message") %>">
<div class="off-canvas-wrapper">
<div class="off-canvas-wrapper-inner" data-off-canvas-wrapper>
<div class="off-canvas-content" data-off-canvas-content>
<%= render "layouts/admin_header" %>

<div class="no-margin-top row expanded collapse" data-equalizer>
<div class="wizard" data-equalizer-watch>
<%= render "layouts/flash" %>
<%= yield %>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Loading

0 comments on commit fcd572a

Please sign in to comment.