Commit 058a5f22 authored by Klaus Stein's avatar Klaus Stein
Browse files

Add image upload for maps (very simple first step)

We need to add image anchoring etc.
parent 129459c2
......@@ -76,6 +76,6 @@ class MapsController < ApplicationController
puts params.require(:map).inspect
params.require(:map).permit(:title, :place_id, :repository_id,
:description, :district, :basemap, :scale, :orientation, :papersize, :techniques, :platenumber, :creator, :legend, :damage_categories, :doi, :repository, :repo_location, :repo_doc_ref, :repo_url, :copyright, :copyright_holder, category_ids: [], itemdates_attributes: [:id, :edtfdate, :description])
:description, :district, :basemap, :scale, :orientation, :papersize, :techniques, :platenumber, :creator, :legend, :damage_categories, :doi, :repository, :repo_location, :repo_doc_ref, :repo_url, :copyright, :copyright_holder, category_ids: [], itemdates_attributes: [:id, :edtfdate, :description, :_destroy], image_maps_attributes: [:id, :name, :anchors, :clip, :image, :_destroy])
end
end
......@@ -98,4 +98,15 @@ form.map {
font-style: normal;
}
}
.imgupload {
border: 1px solid grey;
width: 100%;
.img {
width: 100%;
img {
max-width: 100%;
}
}
}
}
......@@ -42,6 +42,7 @@ class Map < ApplicationRecord
has_many :itemdates, as: :dated
accepts_nested_attributes_for :itemdates, reject_if: :all_blank, allow_destroy: true
has_many :image_maps, dependent: :destroy
accepts_nested_attributes_for :image_maps, reject_if: :all_blank, allow_destroy: true
has_and_belongs_to_many :categories
def dates
......
<%= form_with(model: map, class: 'map', data: { controller: 'nested-form' }) do |form| %>
<%= form_with(model: map, class: 'map') do |form| %>
<% if map.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(map.errors.count, "error") %> prohibited this map from being saved:</h2>
......@@ -10,25 +10,39 @@
</div>
<% end %>
<template data-nested-form-target="template">
<%= form.fields_for :itemdates, Itemdate.new, child_index: 'NEW_RECORD' do |itemdate_fields| %>
<%= render "itemdates_form", form: itemdate_fields %>
<% end %>
</template>
<table>
<tr class="field"><th><%= form.label :title %></th><td><%= form.text_field :title %></td></tr>
<tr class="field" data-controller="nested-form"><th>Images</th><td>
<template data-nested-form-target="template">
<%= form.fields_for :image_maps, ImageMap.new, child_index: 'NEW_RECORD' do |image_map_fields| %>
<%= render "image_maps_form", form: image_map_fields %>
<% end %>
</template>
<%= form.fields_for :image_maps do |image_map_fields| %>
<%= render "image_maps_form", form: image_map_fields %>
<% end %>
<div data-nested-form-target="target"></div>
<button type="button" data-action="nested-form#add">
Add image
</button>
</td></tr>
<tr class="field"><th><%= form.label :place_id %></th><td><%= form.collection_select(:place_id, Place.with_name, :id, :name, {include_blank: true}) %></td></tr>
<tr class="field"><th><%= form.label :categories %></th><td><%= form.collection_select(:category_ids, Category.all, :id, :name, {label: 'Category(s)'}, {multiple: true}) %></td></tr>
<tr class="field"><th><%= form.label :description %></th><td><%= form.text_area :description %></td></tr>
<tr class="field"><th>Dates:</th>
<tr class="field" data-controller="nested-form"><th>Dates:</th>
<td><div class="instructions">[Date format: <kbd>yyyy-mm-dd</kbd> (e.g. <kbd>1944-02-11</kbd>)]</div>
<template data-nested-form-target="template">
<%= form.fields_for :itemdates, Itemdate.new, child_index: 'NEW_RECORD' do |itemdate_fields| %>
<%= render "itemdates_form", form: itemdate_fields %>
<% end %>
</template>
<%= form.fields_for :itemdates do |itemdate_fields| %>
<%= render "itemdates_form", form: itemdate_fields %>
<% end %>
<div data-nested-form-target="target"></div>
<button type="button" data-action="nested-form#add">
Add date
</button>
<%= render "itemdates_form", form: itemdate_fields %>
<% end %>
<div data-nested-form-target="target"></div>
<button type="button" data-action="nested-form#add">
Add date
</button>
</td></tr>
<tr class="field"><th><%= form.label :district %></th><td><%= form.text_field :district %></td></tr>
<tr class="field"><th><%= form.label :basemap %></th><td><%= form.text_field :basemap %></td></tr>
......
<table class="nested-form-wrapper imgupload" data-new-record="<%= form.object.new_record? %>">
<tr>
<td class="img"><%=
im=form.object.image
if im.attached?
image_tag im.variant(resize_to_limit: [10000, 200],
auto_orient: true,
format: :jpg).processed
else
form.file_field :image, direct_upload: true
end
%></td>
<td><button type="button" data-action="nested-form#remove">
Remove image
</button></td>
</tr>
<%= form.hidden_field :_destroy %>
</table>
......@@ -3,4 +3,4 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
Mime::Type.register "application/json", :geojson
Mime::Type.register "application/geo+json", :geojson
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment