Skip to content

Commit

Permalink
104 add happening question (#109)
Browse files Browse the repository at this point in the history
* Update (#108)

* 103 aggiungere tipi di domande integer e data (#107)

* aggiunte tipologie di domande per allegati, date, numeri

* Aggiunti devcontainer

* navbar title configuration with RAILS_TITLE and RAILS_ICON (#106)

* attivati tasti per aggiungere e rimuovere le domande per gli happening

* removed codeql external flow
  • Loading branch information
MdreW authored Dec 18, 2024
1 parent 03f1826 commit 6a21667
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 118 deletions.
94 changes: 0 additions & 94 deletions .github/workflows/codeql.yml

This file was deleted.

20 changes: 12 additions & 8 deletions app/components/editor/questions/sub_form_component.html.haml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
.field
= @form.label :title
.control
= @form.text_field :title, class: 'input ', required: true

.field.is-horizontal
.field-body
.field
= @form.label :title
.control
= @form.text_field :title, class: 'input ', required: true
.field
= @form.label :category
.control
= @form.select :category, [['String',:string],['Text box',:text], ['Selezione', :select], ['File', :file]], {}, mandatory: true, data: {controller: 'slim', target: 'slim.simple'}
.select.is-fullwidth= @form.select :category, [['Stringa',:string],['Box testo',:text], ['Selezione', :select], ['File', :file],['Data', :date],['Numero', :number]], {}, mandatory: true
.field
= @form.label :madatory
= @form.label :mandatory
.control
= @form.select :mandatory, [['Si',true],['No',false]], {}, mandatory: true, data: {controller: 'slim', target: 'slim.simple'}
.select.is-fullwidth= @form.select :mandatory, [['Si',true],['No',false]], {}, mandatory: true
.field
= @form.label :weight
.control
= @form.number_field :weight, class: 'input', required: true
.field
= @form.label :_destroy
.control
.select.is-fullwidth= @form.select :_destroy, [['Mantieni', nil],['Elimina', 1]]

6 changes: 4 additions & 2 deletions app/controllers/editor/happenings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def new
end

# GET /editor/events/:event_id/happenings/:id/edit
def edit; end
def edit
@happening.questions.new
end

# POST /editor/happenings
def create
Expand Down Expand Up @@ -85,7 +87,7 @@ def set_happening

# Filter params for set an {Happening}
def happening_params
params.require(:happening).permit(:title, :image, :event_id, :max_tickets, :max_tickets_for_user, :start_at, :start_sale_at, :stop_sale_at, questions_attributes: [ :id, :title, :category, :mandatory, :weight ])
params.require(:happening).permit(:title, :image, :event_id, :max_tickets, :max_tickets_for_user, :start_at, :start_sale_at, :stop_sale_at, questions_attributes: [ :id, :title, :category, :mandatory, :weight, :_destroy ])
end

def massive_create_params
Expand Down
26 changes: 17 additions & 9 deletions app/javascript/controllers/nested_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ import { Controller } from "@hotwired/stimulus"

// Connects to data-controller="nested"
export default class extends Controller {
static targets = ["row"] // 1
static targets = [ 'content', 'template' ]

connect() {
}

deleteRow() { // 2
event.preventDefault(); // 3

let index = event.currentTarget.getAttribute("data-index"); // 4, 5
this.bookRowTargets[index].classList.toggle("hidden"); // 6, 7
add() {
event.preventDefault()
let clone = document.createElement('div')
clone.setAttribute('class', this.templateTarget.getAttribute('class'))
clone.dataset.target = 'nested.entry'
clone.innerHTML = this.templateTarget.innerHTML
this.contentTarget.appendChild(clone)
let index = this.templateTarget.dataset.index
let newIndex = this.contentTarget.children.length + 1
clone.querySelectorAll('[name]').forEach( (field) => {
field.setAttribute('name', field.getAttribute('name').replace(`[${index}]`, `[${newIndex}]`))
field.setAttribute('id', field.getAttribute('name').replace(`[${index}]`, `[${newIndex}]`))
} )
clone.querySelectorAll('[for]').forEach( (field) => {
field.setAttribute('for', field.getAttribute('for').replace(`_${index}_`, `_${newIndex}_`))
} )
}
}
2 changes: 1 addition & 1 deletion app/models/happening.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Happening < ApplicationRecord
attachable.variant :ticket, resize_to_limit: [ 150, 68 ]
end

accepts_nested_attributes_for :questions, reject_if: :all_blank
accepts_nested_attributes_for :questions, reject_if: :all_blank, allow_destroy: true

validates :event, presence: true
validates :start_at, presence: true
Expand Down
2 changes: 1 addition & 1 deletion app/views/editor/events/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%h3.title.is-size-3.has-text-centered
%i.fas.fa-ticket-alt
= t 'editor'
= t('activerecord.models.events.other')
= t('activerecord.models.event.other')
.columns
%aside.column.is-3
= render Layout::SearchComponent.new(url: editor_events_url, turbo_frame: 'events', categories: @categories, editor: true)
Expand Down
11 changes: 8 additions & 3 deletions app/views/editor/happenings/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

%turbo-frame#happening
.box
= form_with(model: [:editor, @happening], data: {turbo_frame: 'happening'}) do |form|
= form_with(model: [:editor, @happening], data: {turbo_frame: 'happening', controller: 'nested'}) do |form|
= form.hidden_field :event_id, value: @event.id
.field.is-horizontal
.field-body
Expand Down Expand Up @@ -65,10 +65,15 @@
%i.fas.fa-chair
%p.help.is-danger= @happening.errors[:max_tickets_for_user].join(' - ')
.divider Domande
= form.fields_for :questions do |sub_form|
= render Editor::Questions::SubFormComponent.new form: sub_form
.div{data: {nested_target: 'content'}}
= form.fields_for :questions do |sub_form|
- if sub_form.object.persisted?
= render Editor::Questions::SubFormComponent.new form: sub_form
- else
%template{data: {nested_target: 'template'}}= render Editor::Questions::SubFormComponent.new form: sub_form
.buttons.has-text-centered
= form.button fas_icon('save', text: t('site.generic.save')), class: 'button is-success'
%a.button.is-link{href: editor_happening_path(@happening)}= fas_icon 'chevron-left', text: 'Indietro'
= link_to fas_icon('trash', text: 'Elimina'), editor_happening_path(@happening), class: 'button is-warning', data: {turbo_confirm: 'Attenzione la data e tutte le prenotazioni saranno eliminate, confermi?', turbo_method: :delete, turbo_frame: 'yield'}
%a.is-success.button{data: {action: 'nested#add'}}= fas_icon 'plus', text: 'Aggiungi domanda'

9 changes: 9 additions & 0 deletions config/locales/activerecord.it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ it:
stop_sale_at: Data di fine prenotazioni
repeat_in: Giorni in cui ripetere la data
repeat_fo: N. di giorni per cui ripetere l'evento
question:
title: Titolo
category: Categorie
mandatory: Obbligatorio
weight: Ordine
_destroy: Elimina
template:
title: Titolo
data: Struttura domande
Expand All @@ -42,6 +48,9 @@ it:
happening:
one: Data
other: Date
question:
one: Domanda
other: Domande
template:
one: Template domande
other: Template domande
Expand Down

0 comments on commit 6a21667

Please sign in to comment.