Add Measurements tab and #new form

This commit is contained in:
cryptogopher 2025-01-22 16:03:26 +01:00
parent 3d7daa8944
commit 9d60eee16b
11 changed files with 74 additions and 16 deletions

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" id="icon" viewBox="0 0 24 24"><path d="M6,11H11V6H17V11H22V17H17V22H11V17H6V11M13,15V20H15V15H20V13H15V8H13V13H8V15H13M2,13V7H7V2H13V4H9V9H4V13H2Z" /></svg>

After

Width:  |  Height:  |  Size: 197 B

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" id="icon" viewBox="0 0 24 24"><path d="M5,2H19A2,2 0 0,1 21,4V20A2,2 0 0,1 19,22H5A2,2 0 0,1 3,20V4A2,2 0 0,1 5,2M12,4A4,4 0 0,0 8,8H11.26L10.85,5.23L12.9,8H16A4,4 0 0,0 12,4M5,10V20H19V10H5Z" /></svg>

After

Width:  |  Height:  |  Size: 242 B

View File

@ -200,9 +200,7 @@ textarea:read-only {
}
.header {
display: flex;
gap: 0.8em;
header {
grid-area: header;
}
@ -243,6 +241,18 @@ textarea:read-only {
}
.buttongrid {
display: grid;
gap: 0.4em;
grid-template-areas: "context empty tools";
grid-template-columns: auto 1fr auto;
grid-template-rows: max-content;
}
.tools {
grid-area: tools;
}
#flashes {
display: grid;
gap: 0.2em;
@ -502,6 +512,10 @@ table.items select:focus-visible {
.extendedright {
margin-right: auto;
}
.htoolbox {
display: flex;
gap: 0.8em;
}
[disabled] {
border-color: var(--color-border-gray) !important;
color: var(--color-border-gray) !important;
@ -512,15 +526,3 @@ table.items select:focus-visible {
.unwrappable {
white-space: nowrap;
}
.buttongrid {
display: grid;
gap: 0.4em;
grid-template-areas: "context empty tools";
grid-template-columns: auto 1fr auto;
grid-template-rows: max-content;
}
.tools {
grid-area: tools;
}

View File

@ -0,0 +1,14 @@
class MeasurementsController < ApplicationController
def index
@quantities = current_user.quantities.ordered
end
def new
end
def create
end
def destroy
end
end

View File

@ -125,6 +125,7 @@ module ApplicationHelper
def navigation_menu
menu_tabs = [
['measurements', 'scale-bathroom', :restricted],
['quantities', 'axis-arrow', :restricted, 'right'],
['units', 'weight-gram', :restricted],
['users', 'account-multiple-outline', :admin],
@ -144,6 +145,11 @@ module ApplicationHelper
button_to name, options, html_options
end
def image_button_tag(name, image = nil, html_options = {})
name, html_options = link_or_button_options(:button, name, image, html_options)
button_tag name, html_options
end
def image_link_to(name, image = nil, options = nil, html_options = {})
name, html_options = link_or_button_options(:link, name, image, html_options)
link_to name, options, html_options

View File

@ -0,0 +1,2 @@
module MeasurementsHelper
end

View File

@ -23,7 +23,7 @@
</head>
<body>
<header class="header">
<header class="htoolbox">
<%= image_link_to t(".source_code"), "code-braces", source_code_url %>
<%= image_link_to t(".issue_tracker"), "bug-outline", issue_tracker_url,
class: "extendedright" %>

View File

@ -0,0 +1,16 @@
<div class="main">
<% if current_user.at_least(:active) %>
<%# TODO: show hint when no quantities/units defined %>
<%= form_tag new_measurement_path, method: :get, class: "htoolbox",
data: {turbo_stream: true} do %>
<%= select_tag :id,
options_from_collection_for_select(@quantities, :id,
->(q) { sanitize('-&nbsp;'*q.depth + q.name) }) %>
<%= image_button_tag t('.new_quantity'), 'plus-outline', name: :scope -%>
<%= image_button_tag t('.new_children'), 'plus-multiple-outline', name: :scope,
value: :children -%>
<%= image_button_tag t('.new_subtree'), 'plus-multiple-outline', name: :scope,
value: :subtree -%>
<% end %>
<% end %>
</div>

View File

@ -62,6 +62,12 @@ en:
revert: Revert
sign_out: Sign out
source_code: Get code
measurements:
navigation: Measurements
index:
new_quantity: Add selected
new_children: Add children
new_subtree: Add subtree
quantities:
navigation: Quantities
no_items: There are no configured quantities. You can Add some or Import from defaults.

View File

@ -1,4 +1,6 @@
Rails.application.routes.draw do
resources :measurements
resources :quantities, except: [:show], path_names: {new: '(/:id)/new'} do
member { post :reparent }
end

View File

@ -0,0 +1,8 @@
require "test_helper"
class MeasurementsControllerTest < ActionDispatch::IntegrationTest
#test "should get index" do
# get measurements_index_url
# assert_response :success
#end
end