mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
add attachment & characteristics to spaces
This commit is contained in:
parent
560bb46383
commit
46fbcc06f3
@ -5,8 +5,8 @@
|
||||
- TODO bug: calendar (github#59)
|
||||
- TODO bug: delete event (github#61)
|
||||
- ONGOING spaces reservation
|
||||
- [TODO DEPLOY] `rake db:migrate`
|
||||
- [TODO DEPLOY] `rake db:seed`
|
||||
- [TODO DEPLOY] `rake db:migrate`, then `rake db:seed`
|
||||
|
||||
## v2.4.10 2017 January 9
|
||||
|
||||
- Optimized notifications system
|
||||
|
@ -4,6 +4,8 @@ class Space < ActiveRecord::Base
|
||||
|
||||
has_one :space_image, as: :viewable, dependent: :destroy
|
||||
accepts_nested_attributes_for :space_image, allow_destroy: true
|
||||
has_many :space_files, as: :viewable, dependent: :destroy
|
||||
accepts_nested_attributes_for :space_files, allow_destroy: true, reject_if: :all_blank
|
||||
|
||||
has_and_belongs_to_many :projects, join_table: :projects_spaces
|
||||
|
||||
|
3
app/models/space_file.rb
Normal file
3
app/models/space_file.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class SpaceFile < Asset
|
||||
mount_uploader :attachment, SpaceFileUploader
|
||||
end
|
49
app/uploaders/space_file_uploader.rb
Normal file
49
app/uploaders/space_file_uploader.rb
Normal file
@ -0,0 +1,49 @@
|
||||
class SpaceFileUploader < CarrierWave::Uploader::Base
|
||||
# Include RMagick or MiniMagick support:
|
||||
# include CarrierWave::RMagick
|
||||
#include CarrierWave::MiniMagick
|
||||
include UploadHelper
|
||||
|
||||
# Choose what kind of storage to use for this uploader:
|
||||
storage :file
|
||||
after :remove, :delete_empty_dirs
|
||||
# storage :fog
|
||||
|
||||
# Override the directory where uploaded files will be stored.
|
||||
# This is a sensible default for uploaders that are meant to be mounted:
|
||||
def store_dir
|
||||
"#{base_store_dir}/#{model.id}"
|
||||
end
|
||||
|
||||
def base_store_dir
|
||||
"uploads/#{model.class.to_s.underscore}"
|
||||
end
|
||||
|
||||
# Provide a default URL as a default if there hasn't been a file uploaded:
|
||||
# def default_url
|
||||
# # For Rails 3.1+ asset pipeline compatibility:
|
||||
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
||||
#
|
||||
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
||||
# end
|
||||
|
||||
# Process files as they are uploaded:
|
||||
# process :scale => [200, 300]
|
||||
#
|
||||
# def scale(width, height)
|
||||
# # do something
|
||||
# end
|
||||
|
||||
|
||||
# Add a white list of extensions which are allowed to be uploaded.
|
||||
# For images you might use something like this:
|
||||
def extension_white_list
|
||||
%w(pdf)
|
||||
end
|
||||
|
||||
# Override the filename of the uploaded files:
|
||||
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
||||
#def filename
|
||||
#"avatar.#{file.extension}" if original_filename
|
||||
#end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddCharacteristicsToSpace < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :spaces, :characteristics, :text
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170213103438) do
|
||||
ActiveRecord::Schema.define(version: 20170213142543) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -557,8 +557,9 @@ ActiveRecord::Schema.define(version: 20170213103438) do
|
||||
t.integer "default_places"
|
||||
t.text "description"
|
||||
t.string "slug"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.text "characteristics"
|
||||
end
|
||||
|
||||
create_table "spaces_availabilities", force: :cascade do |t|
|
||||
|
@ -430,5 +430,4 @@ unless StatisticIndex.find_by(es_type_key: 'space')
|
||||
{statistic_index_id: index.id, key: 'booking', label:I18n.t('statistics.bookings'), graph: true, simple: true},
|
||||
{statistic_index_id: index.id, key: 'hour', label:I18n.t('statistics.hours_number'), graph: true, simple: false}
|
||||
])
|
||||
|
||||
end
|
@ -1,8 +1,14 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SpaceTest < ActiveSupport::TestCase
|
||||
bio_lab = {
|
||||
name: 'Bio-lab',
|
||||
description: 'An biological laboratory to experiment bio-technologies',
|
||||
default_places: 5
|
||||
}
|
||||
|
||||
test 'create a space' do
|
||||
space = Space.create!({name: 'Bio-lab', description: 'An biological laboratory to experiment bio-technologies', default_places: 5})
|
||||
space = Space.create!(bio_lab)
|
||||
assert_not_nil space
|
||||
subtype = StatisticSubType.find_by(key: space.slug)
|
||||
assert_not_nil subtype
|
||||
@ -10,14 +16,14 @@ class SpaceTest < ActiveSupport::TestCase
|
||||
|
||||
test 'update a space' do
|
||||
new_name = 'Bio-tech lab'
|
||||
space = Space.create!({name: 'Bio-lab', description: 'An biological laboratory to experiment bio-technologies', default_places: 5})
|
||||
space = Space.create!(bio_lab)
|
||||
space.update_attributes({name: new_name})
|
||||
subtype = StatisticSubType.find_by(key: space.slug)
|
||||
assert_equal new_name, subtype.label
|
||||
end
|
||||
|
||||
test 'delete a space' do
|
||||
space = Space.create!({name: 'Bio-lab', description: 'An biological laboratory to experiment bio-technologies', default_places: 5})
|
||||
space = Space.create!(bio_lab)
|
||||
slug = space.slug
|
||||
space.destroy!
|
||||
assert_nil Space.find_by(slug: slug)
|
||||
|
Loading…
x
Reference in New Issue
Block a user