lexivo/app/views/words/index.html.erb
viktorvsk 5d1974605e
Some checks failed
CI / Lint & Test (push) Has been cancelled
Deploy Status Page / Build & Deploy (push) Has been cancelled
feat: add file upload to word import form
2026-04-23 04:56:19 +00:00

91 lines
3.4 KiB
Plaintext

<% content_for :title, "Lexivo" %>
<div class="container">
<% if notice.present? %>
<div class="flash flash-notice"><%= notice %></div>
<% end %>
<% if alert.present? %>
<div class="flash flash-alert"><%= alert %></div>
<% end %>
<div class="stats-grid">
<div class="stat-card stat-total">
<div class="stat-number"><%= @stats[:total] %></div>
<div class="stat-label">Total</div>
</div>
<div class="stat-card stat-unseen">
<div class="stat-number"><%= @stats[:unseen] %></div>
<div class="stat-label">Unseen</div>
</div>
<div class="stat-card stat-learning">
<div class="stat-number"><%= @stats[:learning] %></div>
<div class="stat-label">Learning</div>
</div>
<div class="stat-card stat-known">
<div class="stat-number"><%= @stats[:known] %></div>
<div class="stat-label">Known</div>
</div>
<div class="stat-card stat-due">
<div class="stat-number"><%= @stats[:due] %></div>
<div class="stat-label">Due Now</div>
</div>
</div>
<div class="action-row">
<% if @stats[:unseen] > 0 %>
<%= link_to "Filter words (#{@stats[:unseen]} unseen)", filter_path, class: "btn btn-primary" %>
<% end %>
<% if @stats[:due] > 0 %>
<%= link_to "Review (#{@stats[:due]} due)", review_path, class: "btn btn-success" %>
<% end %>
<% if @stats[:learning] > 0 && @stats[:due] == 0 %>
<%= link_to "Review queue (#{@stats[:learning]} upcoming)", review_path, class: "btn btn-outline" %>
<% end %>
</div>
<div class="section">
<h2>Import words</h2>
<p class="hint">
One entry per line or upload a .txt/.csv file.
Formats: <code>word - definition</code> &nbsp;|&nbsp;
<code>word: definition</code> &nbsp;|&nbsp; <code>word | definition</code> &nbsp;|&nbsp;
just <code>word</code>
</p>
<%= form_with url: words_path, method: :post, local: false, data: { turbo: false }, multipart: true do |f| %>
<div class="import-file-row">
<%= f.file_field :word_file, accept: ".txt,.csv,.tsv", class: "file-input" %>
<span class="import-or">or paste below</span>
</div>
<%= f.text_area :word_list, placeholder: "ephemeral - lasting for a very short time\npersistent\ntenacious: holding firmly to a purpose", rows: 8, class: "import-textarea" %>
<%= f.submit "Import", class: "btn btn-primary" %>
<% end %>
</div>
<% if @words.any? %>
<div class="section">
<h2>All words (<%= @words.count %>)</h2>
<table class="word-table">
<tbody>
<% @words.each do |word| %>
<tr class="word-row status-<%= word.review&.status || "new" %>">
<td class="word-text"><%= word.text %></td>
<td class="word-def"><%= word.definition.presence || "-" %></td>
<td class="word-status">
<span class="badge badge-<%= word.review&.status %>">
<%= word.review&.status || "new" %>
</span>
<% if word.review&.status == "learning" && word.review.due_at %>
<span class="due-info"><%= word.review.due_label %></span>
<% end %>
</td>
<td class="word-actions">
<%= button_to "x", word_path(word), method: :delete, class: "btn-del", data: { turbo_confirm: "Remove #{word.text}?" } %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% end %>
</div>