mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 17:51:39 -05:00
- Remove unused @is_public_view variable from controller - Simplify conditionals by leveraging methods that return [] when empty - Move public view from trips/public_show to shared/trips/show (Rails conventions) - Refactor trips#update to be HTML-only (remove JSON responses) - Convert sharing form to use proper Rails form helpers - Move JS controller to shared/ subdirectory with proper namespacing - Create RSpec shared examples for Shareable concern to eliminate duplication - Update request specs to match HTML-only controller behavior - Apply 'render/redirect ... and return' pattern for early returns
126 lines
5.6 KiB
Text
126 lines
5.6 KiB
Text
<div class="card bg-base-100 shadow-lg mt-6">
|
|
<div class="card-body">
|
|
<h3 class="card-title">Share This Trip</h3>
|
|
<p class="text-sm text-base-content/70 mb-4">
|
|
Generate a public link to share this trip with others.
|
|
</p>
|
|
|
|
<%= form_with model: trip, url: trip_path(trip), method: :patch, data: { turbo: false } do |f| %>
|
|
<% if trip.sharing_enabled? %>
|
|
<!-- Sharing is enabled -->
|
|
<div class="space-y-4">
|
|
<!-- Sharing Status -->
|
|
<div class="alert <%= trip.sharing_expired? ? 'alert-warning' : 'alert-success' %>">
|
|
<div>
|
|
<% if trip.sharing_expired? %>
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" /></svg>
|
|
<span>This share link has expired</span>
|
|
<% else %>
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current flex-shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
|
|
<span>Sharing is enabled</span>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Sharing URL -->
|
|
<div class="form-control">
|
|
<label class="label">
|
|
<span class="label-text">Share URL</span>
|
|
</label>
|
|
<div class="input-group">
|
|
<input
|
|
type="text"
|
|
value="<%= shared_trip_url(trip.sharing_uuid) %>"
|
|
readonly
|
|
class="input input-bordered flex-1"
|
|
id="sharing-url-<%= trip.id %>">
|
|
<button
|
|
class="btn btn-square"
|
|
onclick="navigator.clipboard.writeText(document.getElementById('sharing-url-<%= trip.id %>').value).then(() => {
|
|
const btn = this;
|
|
const original = btn.innerHTML;
|
|
btn.innerHTML = '✓';
|
|
setTimeout(() => btn.innerHTML = original, 2000);
|
|
})">
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3" /></svg>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Sharing Options -->
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<div class="form-control">
|
|
<label class="label cursor-pointer">
|
|
<span class="label-text">Share notes</span>
|
|
<input
|
|
type="checkbox"
|
|
class="toggle toggle-primary"
|
|
<%= trip.share_notes? ? 'checked' : '' %>
|
|
disabled>
|
|
</label>
|
|
</div>
|
|
<div class="form-control">
|
|
<label class="label cursor-pointer">
|
|
<span class="label-text">Share photos</span>
|
|
<input
|
|
type="checkbox"
|
|
class="toggle toggle-primary"
|
|
<%= trip.share_photos? ? 'checked' : '' %>
|
|
disabled>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Action Buttons -->
|
|
<div class="flex gap-2">
|
|
<%= f.submit "Disable Sharing",
|
|
name: 'sharing[enabled]',
|
|
value: '0',
|
|
class: "btn btn-error flex-1",
|
|
data: { turbo_confirm: "Are you sure you want to disable sharing for this trip?" } %>
|
|
</div>
|
|
</div>
|
|
<% else %>
|
|
<!-- Sharing is disabled -->
|
|
<div class="space-y-4">
|
|
<div class="form-control">
|
|
<label class="label">
|
|
<span class="label-text">Expiration</span>
|
|
</label>
|
|
<%= f.select 'sharing[expiration]',
|
|
options_for_select([
|
|
['1 hour', '1h'],
|
|
['12 hours', '12h'],
|
|
['24 hours', '24h'],
|
|
['Never (permanent)', 'permanent']
|
|
], '24h'),
|
|
{},
|
|
class: 'select select-bordered' %>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<div class="form-control">
|
|
<label class="label cursor-pointer">
|
|
<span class="label-text">Share notes</span>
|
|
<%= f.check_box 'sharing[share_notes]',
|
|
{ checked: true, class: 'toggle toggle-primary' },
|
|
'1', '0' %>
|
|
</label>
|
|
</div>
|
|
<div class="form-control">
|
|
<label class="label cursor-pointer">
|
|
<span class="label-text">Share photos</span>
|
|
<%= f.check_box 'sharing[share_photos]',
|
|
{ checked: true, class: 'toggle toggle-primary' },
|
|
'1', '0' %>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<%= f.hidden_field 'sharing[enabled]', value: '1' %>
|
|
<%= f.submit "Enable Sharing", class: "btn btn-primary w-full" %>
|
|
</div>
|
|
<% end %>
|
|
<% end %>
|
|
</div>
|
|
</div>
|