Skip to content

Commit

Permalink
feat:[#83] Remove default offer
Browse files Browse the repository at this point in the history
Remove creating default offer for service
Add panel `offers` in the service view
Move links to offers_path
Use wrapper in service views

Closes #83
  • Loading branch information
Pawel Gorczyca authored and goreck888 committed Sep 13, 2024
1 parent 88a588f commit d59956c
Show file tree
Hide file tree
Showing 98 changed files with 508 additions and 609 deletions.
37 changes: 11 additions & 26 deletions app/components/presentable/description_component.html.haml
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
#desc.tab-pane.container.active.desc{ "aria-labelledby" => "home-tab", role: "tabpanel" }
.row.justify-content-between
%main.col-12.col-xl-9.pr-4.pt-4{ "data-shepherd-tour-target": "service-about" }
.service-description-container
= markdown(@object.description)
.details-box-wrapper.mt-5
= render Presentable::SidebarComponent.new(@object)
.service-description-container
= markdown(@object.description)
.details-box-wrapper.mt-5
= render Presentable::SidebarComponent.new(@object)

= description_panels
.related-container
- unless @object.suspended?
.row
.col-12
= render "services/related", related_services: @related_services, title: related_services_title,
preview: @preview
%sidebar.col-12.col-xl-3{ "data-shepherd-tour-target": "service-classification" }
= render "components/presentable/explore_links", object: @object
.right-panel-links
- if [email protected]_contacts.empty? && (@question || @preview)
= render "components/presentable/header_component/ask_question", question_link: new_question_link,
question: @question,
prompt: new_question_prompt,
preview: @preview
= render Presentable::LinksComponent.new(object: @object, preview: @preview)
= additional_backoffice_info
= render Presentable::ProviderInfoComponent.new(base: @object, preview: @preview) if @object.respond_to?(:resource_organisation)
= description_panels
.related-container
- unless @object.suspended?
.row
.col-12
= render "services/related", related_services: @related_services, title: related_services_title,
preview: @preview
66 changes: 25 additions & 41 deletions app/components/presentable/details_component.html.haml
Original file line number Diff line number Diff line change
@@ -1,41 +1,25 @@
#opinions.tab-pane.container.active{ "aria-labelledby": "opinions-tab", role: "tabpanel",
"data-shepherd-tour-target": "service-details-content" }
.row.justify-content-between
%main.col-12.col-xl-9.pr-4.mb-4.pt-4
.details-box-wrapper
= render Presentable::SidebarComponent.new(@object)
- details_columns.each do |column|
- column.map do |group|
- next unless display_detail?(group, @object)
.details-box{
class: "#{group[:name]}"
}
.details-header
%h5= t("components.presentable.details_component.details.title.#{group[:name]}")
.details-content
= render "components/presentable/details_component/#{group[:template]}",
object: @object,
fields: group[:fields],
type: group[:type] || "single",
clazz: group[:clazz] || "",
nested: group[:nested] || {},
inactive: @object.suspended? && !group[:active_when_suspended],
with_desc: group[:with_desc] || false,
preview: @preview
.related-container
.row
.col-12
= render "services/related", related_services: @related_services, title: related_services_title,
preview: @preview

%sidebar.col-12.col-xl-3{ "data-shepherd-tour-target": "service-classification" }
= render "components/presentable/explore_links", object: @object
.right-panel-links
- if [email protected]_contacts.empty? && (@question || @preview)
= render "components/presentable/header_component/ask_question", question_link: new_question_link,
question: @question,
prompt: new_question_prompt,
preview: @preview
= render Presentable::LinksComponent.new(object: @object, preview: @preview)
= render Presentable::ProviderInfoComponent.new(base: @object, preview: @preview) if @object.respond_to?(:resource_organisation)
.details-box-wrapper
= render Presentable::SidebarComponent.new(@object)
- details_columns.each do |column|
- column.map do |group|
- next unless display_detail?(group, @object)
.details-box{
class: "#{group[:name]}"
}
.details-header
%h5= t("components.presentable.details_component.details.title.#{group[:name]}")
.details-content
= render "components/presentable/details_component/#{group[:template]}",
object: @object,
fields: group[:fields],
type: group[:type] || "single",
clazz: group[:clazz] || "",
nested: group[:nested] || {},
inactive: @object.suspended? && !group[:active_when_suspended],
with_desc: group[:with_desc] || false,
preview: @preview
.related-container
.row
.col-12
= render "services/related", related_services: @related_services, title: related_services_title,
preview: @preview
14 changes: 14 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,18 @@ def turbo_frame_request?
def action
@action ||= action_name
end

def bundled
if @service.offers.published.select(&:bundled?).present?
@service
.offers
.published
.select(&:bundled?)
.map { |o| policy_scope(o.bundles).reject { |b| b.service.status.in?(Statusable::HIDEABLE_STATUSES) } }
.flatten
.uniq
else
[]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Backoffice::Services::Bundles::DraftsController < Backoffice::ApplicationC
def create
if Bundle::Unpublish.call(@bundle)
flash[:notice] = "Bundle unpublished successfully"
redirect_to backoffice_service_path(@service)
redirect_to backoffice_service_offers_path(@service)
else
flash[:alert] = "Bundle cannot be unpublished. Please ensure your form is properly completed. " +
"#{@bundle.errors.messages.each.map { |k, v| "The field #{k} #{v.join(", ")}" }.join(", ")}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Backoffice::Services::Bundles::PublishesController < Backoffice::Applicati
def create
if Bundle::Publish.call(@bundle)
flash[:notice] = "Bundle published successfully"
redirect_to backoffice_service_path(@service)
redirect_to backoffice_service_offers_path(@service)
else
flash[:alert] = "Bundle cannot be published. Please ensure your form is properly completed. " +
"#{@bundle.errors.messages.each.map { |k, v| "The field #{k} #{v.join(", ")}" }.join(", ")}"
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/backoffice/services/bundles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
@bundle = Bundle::Create.call(template)

if @bundle.persisted?
redirect_to backoffice_service_path(@service), notice: "New bundle created successfully"
redirect_to backoffice_service_offers_path(@service), notice: "New bundle created successfully"
else
render :new, status: :unprocessable_entity
end
Expand All @@ -29,7 +29,7 @@ def edit
def update
template = permitted_attributes(Bundle.new)
if Bundle::Update.call(@bundle, transform_attributes(template))
redirect_to backoffice_service_path(@service), notice: "Bundle updated successfully"
redirect_to backoffice_service_offers_path(@service), notice: "Bundle updated successfully"
else
render :edit, status: :unprocessable_entity
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/backoffice/services/drafts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create
flash[:alert] = "Service not #{params[:suspend] ? "suspended" : "unpublished"}. " +
"Reason: #{@service.errors.full_messages.join(", ")}"
end
redirect_to backoffice_service_path(@service)
redirect_to backoffice_service_offers_path(@service)
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Backoffice::Services::Offers::DraftsController < Backoffice::ApplicationCo
def create
if Offer::Unpublish.call(@offer)
flash[:notice] = "Offer unpublished successfully"
redirect_to backoffice_service_path(@service)
redirect_to backoffice_service_offers_path(@service)
else
flash[:alert] = "Offer cannot be unpublished. Please ensure your form is properly completed. " +
"#{@offer.errors.messages.each.map { |k, v| "The field #{k} #{v.join(", ")}" }.join(", ")}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Backoffice::Services::Offers::PublishesController < Backoffice::Applicatio
def create
if Offer::Publish.call(@offer)
flash[:notice] = "Offer published successfully"
redirect_to backoffice_service_path(@service)
redirect_to backoffice_service_offers_path(@service)
else
flash[:alert] = "Offer cannot be published. Please ensure your form is properly completed. " +
"#{@offer.errors.messages.each.map { |k, v| "The field #{k} #{v.join(", ")}" }.join(", ")}"
Expand Down
12 changes: 9 additions & 3 deletions app/controllers/backoffice/services/offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class Backoffice::Services::OffersController < Backoffice::ApplicationController
before_action :load_form_data, only: %i[fetch_subtypes]
after_action :reindex_offer, only: %i[create update destroy]

def index
@offers = policy_scope(@service.offers)
@bundles = policy_scope(@service.bundles)
@question = Service::Question.new(service: @service)
end

def new
@offer = Offer.new(service: @service)
authorize(@offer)
Expand All @@ -18,7 +24,7 @@ def create
@offer = Offer::Create.call(template)

if @offer.persisted?
redirect_to backoffice_service_path(@service), notice: "New offer created successfully"
redirect_to backoffice_service_offers_path(@service), notice: "New offer created successfully"
else
render :new, status: :bad_request
end
Expand All @@ -36,7 +42,7 @@ def edit
def update
template = permitted_attributes(Offer)
if Offer::Update.call(@offer, transform_attributes(template, @service))
redirect_to backoffice_service_path(@service), notice: "Offer updated successfully"
redirect_to backoffice_service_offers_path(@service), notice: "Offer updated successfully"
else
render :edit, status: :bad_request
end
Expand All @@ -45,7 +51,7 @@ def update
def destroy
@offer = @service.offers.find_by(iid: params[:id])
if Offer::Delete.call(@offer)
redirect_to backoffice_service_path(@service), notice: "Offer removed successfully"
redirect_to backoffice_service_offers_path(@service), notice: "Offer removed successfully"
else
render :edit, status: :bad_request
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def create
else
flash[:alert] = "Service not published. Reason: #{@service.errors.full_messages.join(", ")}"
end
redirect_to backoffice_service_path(@service)
redirect_to backoffice_service_offers_path(@service)
end

private
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/backoffice/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def index
anchor: ("offer-#{params["anchor"]}" if params["anchor"].present?)
)
when "service"
redirect_to backoffice_service_path(
redirect_to backoffice_service_offers_path(
Service.friendly.find(params["object_id"]),
anchor: ("offer-#{params["anchor"]}" if params["anchor"].present?)
)
when "datasource"
redirect_to backoffice_service_path(Datasource.friendly.find(params["object_id"]))
redirect_to backoffice_service_offers_path(Datasource.friendly.find(params["object_id"]))
end
end
@services, @offers = search(scope)
Expand Down Expand Up @@ -81,7 +81,7 @@ def create
end

remove_temp_data!
redirect_to backoffice_service_path(@service), notice: "New service created successfully"
redirect_to backoffice_service_offers_path(@service), notice: "New service created successfully"
end

def edit
Expand All @@ -108,14 +108,14 @@ def update
end
@service.store_analytics
remove_temp_data!
redirect_to backoffice_service_path(@service), notice: "Service updated successfully"
redirect_to backoffice_service_offers_path(@service), notice: "Service updated successfully"
end

def destroy
if Service::Delete.new(@service).call
redirect_to backoffice_services_path, notice: "Service removed successfully"
else
redirect_to backoffice_service_path(@service),
redirect_to backoffice_service_offers_path(@service),
alert: "Could not remove service. Reason: #{@service.errors.full_messages}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/projects/services/opinions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def create
if @service_opinion.persisted?
Matomo::SendRequestJob.perform_later(@project_item, "Rate", @service_opinion.service_rating)
format.html do
redirect_to project_service_path(@project, @project_item), notice: "Rating submitted successfully"
redirect_to project_service_offers_path(@project, @project_item), notice: "Rating submitted successfully"
end
else
format.html { render :new, status: :unprocessable_entity }
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/services/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Services::ApplicationController < ApplicationController
helper_method :step_title, :prev_title, :next_title

STEP_TITLES = {
offers: "Offer selection",
choose_offer: "Offer selection",
information: "Access instructions",
configuration: "Configuration",
summary: "Final details"
Expand All @@ -27,7 +27,7 @@ def session_key
end

def ensure_in_session!
redirect_to service_offers_path(@service), alert: "Service request template not found" unless @saved_state
redirect_to service_choose_offer_path(@service), alert: "Service request template not found" unless @saved_state
end

def load_and_authenticate_service!
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/services/cancels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ def destroy
session.delete(session_key)
session.delete(:selected_project)

redirect_to service_path(@service)
redirect_to service_offers_path(@service)
end
end
59 changes: 59 additions & 0 deletions app/controllers/services/choose_offers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

class Services::ChooseOffersController < Services::ApplicationController
skip_before_action :authenticate_user!

def show
init_step_data

unless step.visible?
if @offers.inclusive.size.positive?
params[:customizable_project_item] = { offer_id: @offers.inclusive.first.iid }
elsif @bundles.published.size.positive?
params[:customizable_project_item] = { bundle_id: @bundles.published.first.iid }
end

update
end
end

def update
@step = step(step_params)

if @step.valid?
save_in_session(@step)
redirect_to url_for([@service, next_step_key])
else
init_step_data
flash[:alert] = @step.error
render :show
end
end

private

def step_key
:choose_offer
end

def step_params
{ offer_id: offer&.id, bundle_id: bundle&.id, project_id: session[:selected_project] }
end

def offer
form_params = params.fetch(:customizable_project_item, session[session_key] || {}).permit(:offer_id)
@service.offers.find_by(iid: form_params[:offer_id] || bundle&.main_offer&.iid)
end

def bundle
form_params = params.fetch(:customizable_project_item, session[session_key] || {}).permit(:bundle_id)
@service.bundles.find_by(iid: form_params[:bundle_id])
end

def init_step_data
@offers = policy_scope(@service.offers.inclusive).order(:iid)
@bundles = policy_scope(@service.bundles.published).order(:iid)
@bundled = policy_scope(@service.offers.published).order(:iid).select(&:bundled?).map(&:bundles)&.flatten
@step = step(session[session_key])
end
end
Loading

0 comments on commit d59956c

Please sign in to comment.