diff --git a/Gemfile.lock b/Gemfile.lock index 15c0a01e..8e269145 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -496,4 +496,4 @@ RUBY VERSION ruby 2.5.1p57 BUNDLED WITH - 1.15.2 + 2.0.1 diff --git a/app/admin/dashboard.rb b/app/admin/dashboard.rb index 7b280eca..89670069 100644 --- a/app/admin/dashboard.rb +++ b/app/admin/dashboard.rb @@ -2,6 +2,9 @@ menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") } + # TODO: Adding some information about events and organizations would likely + # be a welcome addition to this dashboard + content title: proc{ I18n.t("active_admin.dashboard") } do default_coins = 10 diff --git a/app/admin/event.rb b/app/admin/event.rb new file mode 100644 index 00000000..05fbe034 --- /dev/null +++ b/app/admin/event.rb @@ -0,0 +1,18 @@ +ActiveAdmin.register Event do + actions :index, :show, :new, :create, :edit, :update, :destroy + permit_params :organization_id, :name, :slug, :submission_deadline, :safety_deadline, :starts_at, :ends_at + + form do |f| + f.semantic_errors + f.inputs do + f.input :name + f.input :slug + f.input :organization, as: :select, collection: Organization.all + f.input :submission_deadline, as: :datepicker + f.input :safety_deadline, as: :datepicker + f.input :starts_at, as: :datepicker + f.input :ends_at, as: :datepicker + end + f.actions + end +end diff --git a/app/admin/membership.rb b/app/admin/membership.rb new file mode 100644 index 00000000..56c7915a --- /dev/null +++ b/app/admin/membership.rb @@ -0,0 +1,41 @@ +ActiveAdmin.register Membership do + actions :index, :show, :new, :create, :edit, :update + permit_params :user_id, :collective_id, :collective_type + + form do |f| + f.inputs + panel "hejsan" do + end + end + + # TODO: currently this doesn't quite work to create memberships the way we'd like + # A first pass solution might be to have a dropdown of users by email + # and a dropdown of all Camps and Organizations combined, so that you can choose + # who to put in what collective. + + # SUPER ROUGH mockup might be: + # New Membership + # -------------- + + # User + # ---- + # Hugi (hugi@borderlands.se) + # Kristoffer (kris@borderlands.se) + + # Collective + # ---------- + # West World (organization) + # East World (organization) + # Sea Snugs (camp) + # Health + Safety wizards (camp) + + # You should be able to find a way to modify the display_name of a model in the ActiveAdmin docs + + # ALTERNATIVELY: you could create two dashboards here, + # (maybe admin/camp_memberships.rb and admin/organization_memberships.rb) + # one for adding people to organizations, and another for adding them to camps. + + # A THIRD OPTION: Skip being able to add Camp memberships here + # (that works in the app anyway), and simply make this form + # able to add memberships to organizations +end diff --git a/app/admin/organization.rb b/app/admin/organization.rb new file mode 100644 index 00000000..435988b1 --- /dev/null +++ b/app/admin/organization.rb @@ -0,0 +1,4 @@ +ActiveAdmin.register Organization do + actions :index, :show, :new, :create, :edit, :update, :destroy + permit_params :name +end diff --git a/app/assets/javascripts/camps.js.erb b/app/assets/javascripts/camps.js.erb index c96dc3d7..cc88f4ab 100644 --- a/app/assets/javascripts/camps.js.erb +++ b/app/assets/javascripts/camps.js.erb @@ -58,8 +58,8 @@ $(document).ready(function() { $.ajax({ url: url, - type: 'POST', - data: {method:'_patch', 'camp[tag]': tag, authenticity_token:token}, + type: 'DELETE', + data: {_method:'DELETE', 'camp[tag]': tag, authenticity_token:token}, success: function(data) { refreshTags(data); } @@ -76,7 +76,7 @@ $(document).ready(function() { $.ajax({ url: url, type: 'POST', - data: {method:'_patch', 'camp[tag_list]': tags, authenticity_token:token}, + data: {'camp[tag_list]': tags, authenticity_token:token}, success: function(data) { refreshTags(data); } diff --git a/app/controllers/camps_controller.rb b/app/controllers/camps_controller.rb index 0c49d095..89d1c197 100644 --- a/app/controllers/camps_controller.rb +++ b/app/controllers/camps_controller.rb @@ -4,6 +4,7 @@ class CampsController < ApplicationController before_action :apply_filters, only: :index before_action :authenticate_user!, except: [:show, :index] + before_action :load_event! before_action :load_camp!, except: [:index, :new, :create] before_action :ensure_admin_delete!, only: [:destroy, :archive] before_action :ensure_admin_update!, only: [:update] @@ -15,6 +16,7 @@ def index def new @camp = Camp.new + @camp.event = @event end def edit @@ -30,7 +32,7 @@ def create @camp) flash[:notice] = t('created_new_dream') - redirect_to edit_camp_path(id: @camp.id) + redirect_to edit_event_camp_path(@event, @camp) else flash.now[:notice] = "#{t:errors_str}: #{@camp.errors.full_messages.uniq.join(', ')}" render :new @@ -41,36 +43,30 @@ def create def toggle_granting @camp.toggle!(:grantingtoggle) - redirect_to camp_path(@camp) + redirect_to event_camp_path(@event, @camp) end def update_grants - @camp.grants.build(user: current_user, amount: granted) - @camp.assign_attributes( - minfunded: (@camp.grants_received + granted) >= @camp.minbudget, - fullyfunded: (@camp.grants_received + granted) >= @camp.maxbudget - ) - - if @camp.save - current_user.update(grants: current_user.grants - granted) - flash[:notice] = t(:thanks_for_sending, grants: granted) + actually_granted, ok = current_user.wallet_for(@event).grant_to(@camp, granted) + if ok + flash[:notice] = t(:thanks_for_sending, grants: actually_granted) else flash[:error] = t(:errors_str, message: @camp.errors.full_messages.uniq.join(', ')) end - redirect_to camp_path(@camp) + redirect_to event_camp_path(@event, @camp) end def update if @camp.update_attributes camp_params if params[:done] == '1' - redirect_to camp_path(@camp) + redirect_to event_camp_path(@event, @camp) elsif params[:safetysave] == '1' - puts(camp_safety_sketches_path(@camp)) - redirect_to camp_safety_sketches_path(@camp) + puts(event_camp_safety_sketches_path(@event, @camp)) + redirect_to event_camp_safety_sketches_path(@event, @camp) else respond_to do |format| - format.html { redirect_to edit_camp_path(@camp) } + format.html { redirect_to edit_event_camp_path(@event, @camp) } format.json { respond_with_bip(@camp) } end end @@ -103,7 +99,7 @@ def remove_tag_params def destroy @camp.destroy! - redirect_to camps_path + redirect_to event_camps_path(@event) end # Display a camp and its users @@ -138,11 +134,16 @@ def toggle_favorite def archive @camp.update!(active: false) - redirect_to camps_path + redirect_to event_camps_path(@event) end private + def load_event! + @event = Event.find(params[:event_id]) + not_found if @event.nil? + end + # TODO: We can't permit! attributes like this, because it means that anyone # can update anything about a camp in any way (including the id, etc); recipe for disaster! # we'll have to go through and determine which attributes can actually be updated via @@ -152,9 +153,12 @@ def camp_params end def load_camp! - return if @camp = Camp.find_by(params.permit(:id)) - flash[:alert] = t(:dream_not_found) - redirect_to camps_path + @camp = Camp.includes(:event).find(params[:id]) + + if @camp.nil? or @camp.event.id != @event.id + flash[:alert] = t(:dream_not_found) + redirect_to event_camps_path(@event) + end end def ensure_admin_delete! @@ -170,11 +174,13 @@ def ensure_admin_update! end def ensure_grants! + grants_left = current_user.grants_left_for(@event) + assert(@camp.maxbudget, :dream_need_to_have_max_budget) || - assert(current_user.grants >= granted, :security_more_grants, granted: granted, current_user_grants: current_user.grants) || + assert(grants_left >= granted, :security_more_grants, granted: granted, current_user_grants: grants_left) || assert(granted > 0, :cant_send_less_then_one) || assert( - current_user.admin || (@camp.grants.where(user: current_user).sum(:amount) + granted <= app_setting('max_grants_per_user_per_dream')), + current_user.admin || (@camp.grants_for(@event).where(user: current_user).sum(:amount) + granted <= app_setting('max_grants_per_user_per_dream')), :exceeds_max_grants_per_user_for_this_dream, max_grants_per_user_per_dream: app_setting('max_grants_per_user_per_dream') ) @@ -185,7 +191,7 @@ def granted end def failure_path - camp_path(@camp) + event_camp_path(@event, @camp) end def create_camp diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb new file mode 100644 index 00000000..178d71ef --- /dev/null +++ b/app/controllers/events_controller.rb @@ -0,0 +1,37 @@ +class EventsController < ApplicationController + def index + @events = Event.all.order(starts_at: :desc) + end + + def show + # TODO: We should provide an option on the events#show page to view + # all past or future events, which will allow users to navigate to + # events which are not the current one + @event = Event.find(params[:id]) + redirect_to events_path if @event.nil? + end + + def current + @event = Event.current + render :show + end + + def future + @events = Event.future + render :index + end + + def past + @events = Event.past + render :index + end + + def redirect_to_most_relevant + e = Event.most_relevant + unless e.nil? + redirect_to event_camps_path(e) + else + redirect_to events_path + end + end +end diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index b5360226..a5b31d60 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -8,7 +8,7 @@ def index def create if Image.create(image_params) - redirect_to camp_images_path(params.permit(:camp_id)) + redirect_to event_camp_images_path(@event, @camp) else render action: :index end @@ -16,13 +16,18 @@ def create def destroy @camp.images.find(params[:id]).destroy! - redirect_to camp_images_path(params.permit(:camp_id)) + redirect_to event_camp_images_path(@event, @camp) end private def load_camp! - @camp = Camp.find(params[:camp_id]) + @event = Event.find(params[:event_id]) + not_found if @event.nil? if @event.nil? + + @camp = Camp.includes(:event).find(params[:camp_id]) + redirect_to event_camps_path(@event) if @camp.nil? or @camp.event.id != @event.id + assert(current_user == @camp.creator || current_user.admin, :security_cant_change_images_you_dont_own) end @@ -31,7 +36,7 @@ def ensure_image! end def failure_path - camp_images_path(params.permit(:camp_id)) + event_camp_images_path(@event, @camp) end def image_params diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb new file mode 100644 index 00000000..367179b9 --- /dev/null +++ b/app/controllers/organizations_controller.rb @@ -0,0 +1,13 @@ +class OrganizationsController < ApplicationController + def show + # TODO: More than likely you'll want to create a view of an organization, + # which displays the name of the org and perhaps lists the events they've done + # That goes here! + + # This will likely eventually look like an 'About the organization' page, which + # is visible to the public and provides additional info about the org to anyone + # who signs up + + @organization = Organization.find(params[:id]) + end +end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index df707280..45d4e56a 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -3,27 +3,17 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def facebook @user = User.from_omniauth(request.env["omniauth.auth"]) - - if @user.persisted? - sign_in_and_redirect @user, :event => :authentication - set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? - else - session["devise.facebook_data"] = request.env["omniauth.auth"] - redirect_to new_user_registration_url - end + + sign_in_and_redirect @user, :event => :authentication + set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? end def saml @user = User.from_omniauth(request.env["omniauth.auth"]) - if @user.persisted? - c = Rails.application.config.x.firestarter_settings - sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated - set_flash_message(:notice, :success, kind: c['saml_human_name']) if is_navigational_format? - else - session["devise.saml_data"] = request.env["omniauth.auth"] - redirect_to new_user_registration_url - end + c = Rails.application.config.x.firestarter_settings + sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated + set_flash_message(:notice, :success, kind: c['saml_human_name']) if is_navigational_format? end def failure diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 92bb664c..c0ff67b9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,8 +3,12 @@ class UsersController < ApplicationController before_action :load_lang_detector, only: [:show, :index, :me] def me - @memberships = current_user.created_camps.joins(:memberships).joins(:users) - .where('users.id != ?', current_user.id).select('users.email') + # TODO: There's a possible regression here where this list may now display + # Organization memberships as well. + # I've written a relation which may be able to replace it cleanly in user.rb#18, + # so you could start off with seeing if something like the following works: + + @memberships = current_user.collaborators.distinct.pluck(:email) - Array(current_user.email) end def show diff --git a/app/models/camp.rb b/app/models/camp.rb index 098f0c6c..bf4aa611 100644 --- a/app/models/camp.rb +++ b/app/models/camp.rb @@ -12,14 +12,17 @@ class Camp < ApplicationRecord include AppSettings extend AppSettings belongs_to :creator, class_name: 'User', foreign_key: 'user_id' + belongs_to :event - has_many :memberships, dependent: :destroy + has_many :memberships, as: :collective, dependent: :destroy has_many :users, through: :memberships has_many :favorites has_many :favorite_users, through: :favorites, source: :user has_many :images #, :dependent => :destroy has_many :safety_sketches + has_many :grants + has_many :budget_items has_many :safety_items diff --git a/app/models/event.rb b/app/models/event.rb new file mode 100644 index 00000000..c98ba4f0 --- /dev/null +++ b/app/models/event.rb @@ -0,0 +1,29 @@ +class Event < ActiveRecord::Base + SLUG_FORMAT = /([[:lower:]]|[0-9]+-?[[:lower:]])(-[[:lower:]0-9]+|[[:lower:]0-9])*/ + + belongs_to :organization + has_many :grants + has_many :camps + + has_many :participants, through: :camps, source: :users + + def self.most_relevant + @@most_relevant ||= where('ends_at > ?', Time.current).order(starts_at: :asc).first + end + + scope :past, -> { where('ends_at < ?', Time.current) } + scope :future, -> { where('starts_at > ?', Time.current) } + + validates :slug, + presence: true, + uniqueness: true, + format: {with: Regexp.new('\A' + SLUG_FORMAT.source + '\z')} + + def to_param + slug + end + + def self.find(input) + input.to_i == 0 ? find_by_slug(input) : super + end +end diff --git a/app/models/grant_wallet.rb b/app/models/grant_wallet.rb new file mode 100644 index 00000000..b3e6e623 --- /dev/null +++ b/app/models/grant_wallet.rb @@ -0,0 +1,23 @@ +class GrantWallet < ApplicationRecord + belongs_to :user + belongs_to :event + + def grant_to(camp, requested_grants) + max_grants_per_user_per_dream = Rails.configuration.x.firestarter_settings['max_grants_per_user_per_dream'] + num_grants = [requested_grants, self.grants_left, max_grants_per_user_per_dream].min + + til_funded = camp.maxbudget - num_grants + num_grants = til_funded if num_grants > til_funded + + camp.grants.build(user: self.user, amount: num_grants) + camp.assign_attributes( + minfunded: (camp.grants_received + num_grants) >= camp.minbudget, + fullyfunded: (camp.grants_received + num_grants) >= camp.maxbudget + ) + + return 0, false unless camp.save + self.update_attributes!(grants_left: self.grants_left - num_grants) + + return num_grants, true + end +end diff --git a/app/models/membership.rb b/app/models/membership.rb index 57d17a6d..9f64aed7 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -1,4 +1,9 @@ class Membership < ApplicationRecord - belongs_to :camp + enum collective_type: [ :Organization, :Camp ] + + belongs_to :collective, polymorphic: true belongs_to :user + + scope :for_camp, -> { where(collective_type: :Camp) } + scope :for_organization, -> { where(collective_type: :Organization) } end diff --git a/app/models/organization.rb b/app/models/organization.rb new file mode 100644 index 00000000..0d63303b --- /dev/null +++ b/app/models/organization.rb @@ -0,0 +1,5 @@ +class Organization < ActiveRecord::Base + has_many :events + has_many :memberships, as: :collective, dependent: :destroy + has_many :users, through: :memberships +end diff --git a/app/models/user.rb b/app/models/user.rb index df9dbd45..9120c480 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,25 +7,34 @@ class User < ApplicationRecord has_many :tickets has_many :memberships - has_many :camps, through: :memberships + has_many :camps, through: :memberships, source: :collective, source_type: :Camp + has_many :organizations, through: :memberships, source: :collective, source_type: :Organization has_many :favorites has_many :favorite_camps, through: :favorites, source: :camp has_many :created_camps, class_name: :Camp + has_many :grant_wallets + + # TODO: see if this works to replace the query in users_controller.rb#me + has_many :collaborator_memberships, through: :created_camps, source: :memberships + has_many :collaborators, through: :collaborator_memberships, source: :user + schema_validations whitelist: [:id, :created_at, :updated_at, :encrypted_password] def self.from_omniauth(auth) - u = where(email: auth.uid).first_or_create! do |user| - user.email = auth.uid # .info.email TODO for supporting other things than keycloak - user.password = Devise.friendly_token[0,20] + u = where(email: auth.uid).first_or_create! do |u| + u.email = auth.uid # .info.email TODO for supporting other things than keycloak + u.password = Devise.friendly_token[0,20] + end + end + + def wallet_for(event) + grant_wallets.find_or_create_by(event: event, user: self) do |w| + w.grants_left = ENV['DEFAULT_HEARTS'] || 10 end - # Omniauth doesn't know the keycloak schema - u.name = auth.extra.raw_info.all.fetch("urn:oid:2.5.4.42", []).fetch(0, "") - # Last name : urn:oid:2.5.4.4 - # Roles: raw_info.all["Role"] : array[string] - # avatars: get https://talk.theborderland.se/api/v1/profile/{username} - # either loomio picture or gravatar - u.save! - u + end + + def grants_left_for(event) + wallet_for(event).grants_left end end diff --git a/app/views/camps/_card.html.erb b/app/views/camps/_card.html.erb index 1c33e656..490682b1 100644 --- a/app/views/camps/_card.html.erb +++ b/app/views/camps/_card.html.erb @@ -1,10 +1,10 @@
<% if user_signed_in? %> - <%= link_to toggle_favorite_camp_path(:id => camp.id), method: :patch, class: (camp.favorite_users.include?(current_user) ? 'favorite-button starred' : 'favorite-button'), id: 'favorite-button', :remote => true do %> + <%= link_to toggle_favorite_event_camp_path(@event, camp), method: :patch, class: (camp.favorite_users.include?(current_user) ? 'favorite-button starred' : 'favorite-button'), id: 'favorite-button', :remote => true do %> <% end %> <% end %> - +
diff --git a/app/views/camps/_donate_form.html.erb b/app/views/camps/_donate_form.html.erb index a62093b1..8ca86abd 100644 --- a/app/views/camps/_donate_form.html.erb +++ b/app/views/camps/_donate_form.html.erb @@ -1,6 +1,7 @@
- <%= best_in_place_if @can_edit, @camp, :subtitle, html_attrs: {maxlength: 255, class: "form-control"},as: :textarea, display_with: :simple_format %> + <%= best_in_place_if @can_edit, [@event, @camp], :subtitle, html_attrs: {maxlength: 255, class: "form-control"},as: :textarea, display_with: :simple_format %>
<% if app_setting("multi_lang_support") %>
<%= form.label t("form_subtitle_en_label") %>
- <%= best_in_place_if @can_edit, @camp, :en_subtitle, html_attrs: {maxlength: 255, class: "form-control"},as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :en_subtitle, html_attrs: {maxlength: 255, class: "form-control"},as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
<% end %> @@ -99,7 +99,7 @@ <%= t("form_creator_name_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :contact_name, html_attrs: {maxlength: 64, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :contact_name, html_attrs: {maxlength: 64, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %>
@@ -118,20 +118,20 @@ <%= t("form_contact_phone_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :contact_phone, html_attrs: {maxlength: 64, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :contact_phone, html_attrs: {maxlength: 64, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %>
<% end %>
<%= form.label t("form_about_the_artist_label") %>
- <%= best_in_place_if @can_edit, @camp, :about_the_artist, html_attrs: {maxlength: 1024, class: "form-control"},as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :about_the_artist, html_attrs: {maxlength: 1024, class: "form-control"},as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
<%= form.label t("form_dream_website_label") %>
- <%= best_in_place_if @can_edit, @camp, :website, html_attrs: {maxlength: 512, class: "form-control"}, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :website, html_attrs: {maxlength: 512, class: "form-control"}, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
@@ -141,7 +141,7 @@ <%= t("form_description_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :description, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :description, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
<% end %> @@ -152,7 +152,7 @@ <%= t("form_electricity_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :electricity, html_attrs: {maxlength: 256, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :electricity, html_attrs: {maxlength: 256, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
<% end %> @@ -163,7 +163,7 @@ <%= t("form_fire_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :fire, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :fire, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
<% end %> @@ -174,7 +174,7 @@ <%= t("form_noise_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :noise, html_attrs: {maxlength: 256, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :noise, html_attrs: {maxlength: 256, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %>
<% end %> @@ -185,7 +185,7 @@ <%= t("form_nature_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :nature, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :nature, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
<% end %> @@ -196,7 +196,7 @@ <%= t("form_recycling_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :recycling, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :recycling, html_attrs: {maxlength: 512, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
<% end %> @@ -207,7 +207,7 @@ <%= t("form_light_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :light, html_attrs: {maxlength: 512, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :light, html_attrs: {maxlength: 512, class: "form-control"}, place_holder: t(:form_click_to_edit_html) %>
<% end %> @@ -218,7 +218,7 @@ <%= t("form_moop_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :moop, html_attrs: {maxlength: 1024, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :moop, html_attrs: {maxlength: 1024, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
<% end %> @@ -229,7 +229,7 @@ <%= t("form_cocreation_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :cocreation, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :cocreation, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
<% end %> @@ -240,7 +240,7 @@ <%= t("form_neighbors_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :neighbors, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %> + <%= best_in_place_if @can_edit, [@event, @camp], :neighbors, html_attrs: {maxlength: 4096, class: "form-control"}, as: :textarea, display_with: :simple_format, place_holder: t(:form_click_to_edit_html) %>
<% end %> @@ -264,7 +264,7 @@ <%= t("form_minigrants_realcurrency_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :minbudget_realcurrency, html_attrs: {maxlength: 6, class: "form-control"}, place_holder: t(:form_click_to_edit_html), display_with: :number_to_currency, :helper_options => {:unit => "", precision:0} %> + <%= best_in_place_if @can_edit, [@event, @camp], :minbudget_realcurrency, html_attrs: {maxlength: 6, class: "form-control"}, place_holder: t(:form_click_to_edit_html), display_with: :number_to_currency, :helper_options => {:unit => "", precision:0} %>
<% end %> <% if app_setting("granting") and !app_setting('disable_edit_budget') %> @@ -275,7 +275,7 @@ <%= t("form_maxigrants_realcurrency_guidetext_html") %>
- <%= best_in_place_if @can_edit, @camp, :maxbudget_realcurrency, html_attrs: {maxlength: 6, class: "form-control"}, place_holder: t(:form_click_to_edit_html), display_with: :number_to_currency, :helper_options => {:unit => "", precision:0} %> + <%= best_in_place_if @can_edit, [@event, @camp], :maxbudget_realcurrency, html_attrs: {maxlength: 6, class: "form-control"}, place_holder: t(:form_click_to_edit_html), display_with: :number_to_currency, :helper_options => {:unit => "", precision:0} %>
<% end %> <% if app_setting("granting") and app_setting("budgeting") %> diff --git a/app/views/camps/_list.html.erb b/app/views/camps/_list.html.erb index 7a07bdbe..dc29955f 100644 --- a/app/views/camps/_list.html.erb +++ b/app/views/camps/_list.html.erb @@ -1,5 +1,13 @@
+ + <%=t :sort_by%>: <%= filterrific_sorting_link(@filterrific, :updated_at) %> diff --git a/app/views/camps/_tags.html.erb b/app/views/camps/_tags.html.erb index 26a3b01e..276bfcb6 100644 --- a/app/views/camps/_tags.html.erb +++ b/app/views/camps/_tags.html.erb @@ -3,7 +3,7 @@

<%= Camp.human_attribute_name(:tags) %>

- <%= simple_form_for @camp, url: { action: 'remove_tag', :'format' => 'json' } do |f| %> + <%= simple_form_for [@event, @camp], url: tag_event_camp_path(@event, @camp, format: :json), method: :delete do |f| %>
<% @camp.tags.each do |tag| %>
@@ -13,7 +13,7 @@
<% end %> - <%= simple_form_for @camp, url: { action: 'tag', :'format' => 'json' } do |f| %> + <%= simple_form_for [@event, @camp], url: tag_event_camp_path(@event, @camp, format: :json) do |f| %> <%= f.text_field :tag_list, class: 'form-control', value: '' %> <%= f.submit t(:add_tag), id: 'tags-add', class: 'btn btn-success btn-sm' %> <% end %> diff --git a/app/views/camps/edit.html.erb b/app/views/camps/edit.html.erb index a9858ca5..f0e6ae2f 100644 --- a/app/views/camps/edit.html.erb +++ b/app/views/camps/edit.html.erb @@ -27,9 +27,9 @@ diff --git a/app/views/camps/new.html.erb b/app/views/camps/new.html.erb index 960768b1..1e2289df 100644 --- a/app/views/camps/new.html.erb +++ b/app/views/camps/new.html.erb @@ -4,7 +4,7 @@ <% @can_edit = true %> -<%= simple_form_for @camp, :html => {:dir => I18n.t(:html_direction), id: 'createDreamForm'} do |form| %> +<%= simple_form_for(@camp, url: event_camps_path(event_slug: @event.slug), html: {dir: I18n.t(:html_direction), id: 'createDreamForm'}) do |form| %>
<%= t("form_basics_headline") %>
diff --git a/app/views/camps/show.html.erb b/app/views/camps/show.html.erb index 355cb45f..4b9dedc4 100644 --- a/app/views/camps/show.html.erb +++ b/app/views/camps/show.html.erb @@ -40,7 +40,7 @@

<%= @camp.display_name %> <% if user_signed_in? %> - <%= link_to :toggle_favorite_camp, method: :patch, class: (@camp.favorite_users.include?(current_user) ? 'favorite-button starred' : 'favorite-button'), id: 'favorite-button', style: "position: absolute;", :remote => true do %> + <%= link_to toggle_favorite_event_camp_path(@event, @camp), method: :patch, class: (@camp.favorite_users.include?(current_user) ? 'favorite-button starred' : 'favorite-button'), id: 'favorite-button', style: "position: absolute;", :remote => true do %> <% end %> <% end %> @@ -65,7 +65,7 @@ <% if @camp.grantingtoggle %> - <% if current_user && current_user.grants > 0 && !@camp.fullyfunded %> + <% if current_user && current_user.grants_left_for(@event) > 0 && !@camp.fullyfunded %>