diff options
author | Christopher Baines <mail@cbaines.net> | 2018-05-28 20:37:27 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2018-05-30 20:17:50 +0100 |
commit | de6535e52fb0eb92689d19e4025997bf090ebc75 (patch) | |
tree | ff348ae72c38a3aeffaa8dbb80429b31db555367 /app | |
parent | 3b135d15e48eafb99395b3f1a62e15e5de1c5a4f (diff) | |
download | govuk-mini-environment-admin-de6535e52fb0eb92689d19e4025997bf090ebc75.tar govuk-mini-environment-admin-de6535e52fb0eb92689d19e4025997bf090ebc75.tar.gz |
Enable editing the services when creating a mini environment
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/mini_environments_controller.rb | 69 | ||||
-rw-r--r-- | app/models/govuk_guix/revision.rb | 8 | ||||
-rw-r--r-- | app/views/mini_environments/new.html.erb | 31 | ||||
-rw-r--r-- | app/views/mini_environments/services.html.erb | 133 | ||||
-rw-r--r-- | app/views/mini_environments/show.html.erb | 23 |
5 files changed, 261 insertions, 3 deletions
diff --git a/app/controllers/mini_environments_controller.rb b/app/controllers/mini_environments_controller.rb index 94aa18c..237e8c5 100644 --- a/app/controllers/mini_environments_controller.rb +++ b/app/controllers/mini_environments_controller.rb @@ -19,6 +19,43 @@ # <http://www.gnu.org/licenses/>. class MiniEnvironmentsController < ApplicationController + DEFAULT_SERVICES = %w( + collections-publisher + contacts-admin + content-tagger + local-links-manager + manuals-publisher + maslow + policy-publisher + publisher + service-manual-publisher + short-url-manager + specialist-publisher + travel-advice-publisher + whitehall + + calculators + calendars + collections + email-alert-frontend + feedback + finder-frontend + frontend + government-frontend + licencefinder + manuals-frontend + service-manual-frontend + smartanswers + + draft-collections + draft-email-alert-frontend + draft-frontend + draft-government-frontend + draft-finder-frontend + draft-manuals-frontend + draft-service-manual-frontend + ).freeze + def show @mini_environment = MiniEnvironment.find(params[:id]) end @@ -58,9 +95,37 @@ class MiniEnvironmentsController < ApplicationController @mini_environment.signon_users[0]['passphrase'] = SecureRandom.hex @mini_environment.save! - @mini_environment.backend.build(@mini_environment) + redirect_to services_mini_environment_path(@mini_environment) + end + + def services + @mini_environment = MiniEnvironment.find(params[:id]) + + @mini_environment.transaction do + @mini_environment.govuk_guix_revision.all_available_services + .each do |service| - redirect_to @mini_environment + name = service['name'] + + next if params["#{name}-selected"] != 'on' + + revision = params["#{name}-revision"] + + @mini_environment.services.where( + name: name + ).delete_all + + @mini_environment.services.create( + name: name, + revision: revision + ) + end + end + + if request.put? + @mini_environment.backend.build(@mini_environment) + redirect_to @mini_environment + end end def perform_action diff --git a/app/models/govuk_guix/revision.rb b/app/models/govuk_guix/revision.rb index d58e6ad..1072e0d 100644 --- a/app/models/govuk_guix/revision.rb +++ b/app/models/govuk_guix/revision.rb @@ -36,4 +36,12 @@ class GovukGuix::Revision < ApplicationRecord default_scope { order(:created_at).reverse_order } has_many :mini_environments, foreign_key: 'govuk_guix_revision_id' + + def all_available_services + service_lists = available_services.map do |group| + group['services'] + end + + service_lists.flatten + end end diff --git a/app/views/mini_environments/new.html.erb b/app/views/mini_environments/new.html.erb index 971d3af..b8674fe 100644 --- a/app/views/mini_environments/new.html.erb +++ b/app/views/mini_environments/new.html.erb @@ -29,6 +29,35 @@ License along with the GOV.UK Mini Environment Admin. If not, see <h1>Create a new mini environment</h1> <div class="row"> + <div class="panel panel-default"> + <div class="panel-body"> + <div class="progress"> + <div class="progress-bar" + role="progressbar" + aria-valuenow="1" + aria-valuemin="0" + aria-valuemax="3" + style="width: 33.3%;"> + Step 1 of 3 + </div> + </div> + + <div class="col-md-4 text-center"> + <strong style="font-size: medium"> + Choose name + </strong> + </div> + <div class="col-md-4 text-center"> + Select services + </div> + <div class="col-md-4 text-center"> + Launch + </div> + </div> + </div> +</div> + +<div class="row"> <div class="col-md-8"> <%= form_with(model: @mini_environment, url: { action: "create" }, @@ -47,7 +76,7 @@ License along with the GOV.UK Mini Environment Admin. If not, see <div class="form-group form-group-lg"> <div class="col-sm-offset-2 col-sm-10"> - <%= f.submit "Create", class: 'btn btn-lg btn-success' %> + <%= f.submit "Next: Select services", class: 'btn btn-lg btn-success' %> </div> </div> diff --git a/app/views/mini_environments/services.html.erb b/app/views/mini_environments/services.html.erb new file mode 100644 index 0000000..3a9ab12 --- /dev/null +++ b/app/views/mini_environments/services.html.erb @@ -0,0 +1,133 @@ +<%# + +GOV.UK Mini Environment Admin +Copyright © 2018 Christopher Baines <mail@cbaines.net> + +This file is part of the GOV.UK Mini Environment Admin. + +The GOV.UK Mini Environment Admin is free software: you can +redistribute it and/or modify it under the terms of the GNU Affero +General Public License as published by the Free Software Foundation, +either version 3 of the License, or (at your option) any later +version. + +The GOV.UK Mini Environment Admin is distributed in the hope that it +will be useful, but WITHOUT ANY WARRANTY; without even the implied +warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +the GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public +License along with the GOV.UK Mini Environment Admin. If not, see +<http://www.gnu.org/licenses/>. + +%> + +<h1>Create a new mini environment</h1> + +<div class="row"> + <div class="panel panel-default"> + <div class="panel-body"> + <div class="progress"> + <div class="progress-bar" + role="progressbar" + aria-valuenow="2" + aria-valuemin="0" + aria-valuemax="3" + style="width: 66.6%;"> + Step 2 of 3 + </div> + </div> + + <div class="col-md-4 text-center"> + Choose name + </div> + <div class="col-md-4 text-center"> + <strong style="font-size: medium"> + Select services + </strong> + </div> + <div class="col-md-4 text-center"> + Launch + </div> + </div> + </div> +</div> + +<%= form_with(method: 'put', + url: { action: "services" }) do |f| %> + <div class="row"> + <div class="col-md-9"> + <p> + A default set of services have been selected. Review the list + below if you'd like to change the available services. + </p> + <p> + Note that services can be dependant on other services, so only + select the services you want, and all other necessary services + will be automatically added. + </p> + </div> + + <div class="col-md-3"> + <%= f.submit "Next: Review and launch", class: 'btn btn-lg btn-success' %> + </div> + </div> + + <% ( + @mini_environment.govuk_guix_revision.available_services || [] + ).each do |group| %> + <h3><%= group["name"] %></h3> + <p><%= group["description"] %></p> + + <table class="table"> + <thead> + <tr> + <th>Select?</th> + <th>Service</th> + <th>Package</th> + </tr> + </thead> + <tbody> + <% group["services"].each do |service| %> + <tr> + <td class="col-md-1"> + <input type="checkbox" + name="<%= service["name"] %>-selected" + <%= 'checked' if MiniEnvironmentsController::DEFAULT_SERVICES.include? service["name"] %>> + </td> + + <td class="col-md-5"> + <strong><%= service["name"] %></strong> + <br> + <%= service["description"] %> + </td> + + <% package = service["package"] %> + <td class="col-md-5"> + <input type="text" + name="<%= service["name"] %>-revision" + class="form-control" + placeholder="<%= package["version"] %>" + value="<%= package["version"] %>"> + </td> + + <td class="col-md-1"> + <a class="pull-right" + href="<%= package["homepage"] %>"> + [homepage] + </a> + </td> + </tr> + <% end %> + </tbody> + </table> + <% end %> + + <div class="row"> + <div class="col-md-9"></div> + + <div class="col-md-3"> + <%= f.submit "Next: Review and launch", class: 'btn btn-lg btn-success' %> + </div> + </div> +<% end %> diff --git a/app/views/mini_environments/show.html.erb b/app/views/mini_environments/show.html.erb index 848b401..d680a46 100644 --- a/app/views/mini_environments/show.html.erb +++ b/app/views/mini_environments/show.html.erb @@ -58,6 +58,29 @@ License along with the GOV.UK Mini Environment Admin. If not, see </div> </div> +<h2>Services</h2> + +<% customised_services = @mini_environment.services.select(&:customised?) %> +<% uncustomised_services = @mini_environment.services.reject(&:customised?) %> + +<ul> + <% customised_services.each do |service| %> + <li><%= service.name %> (<%= service.revision %>)</li> + <% end %> +</ul> + +Plus <%= uncustomised_services.length %> other services at the revision specified in the revision of GOV.UK Guix +(<a + href="<%= govuk_guix_revision_path @mini_environment.govuk_guix_revision %>" + >show revision details</a>): + +<% multi_column = (uncustomised_services.length > 6) %> +<ul <% if multi_column %>class="row"<% end %>> + <% uncustomised_services.each do |service| %> + <li <% if multi_column %>class="col-xs-12 col-sm-6 col-md-3"<% end %>><%= service.name %></li> + <% end %> +</ul> + <h2>Initial Signon Users</h2> <table class="table table-bordered table-hover"> |