Commit 90276c6f authored by Greg Gard's avatar Greg Gard

fixing nav header and adding validations

parent dc2bdf73
main { @extend .container };
.emt {
&-navbar {
@extend .navbar, .navbar-default;
@extend .navbar, .navbar-inverse, .navbar-static-top;
> div {
@extend .navbar-header;
@extend .container;
> ul {
@extend .nav, .navbar-nav;
}
}
.brand {
......@@ -13,6 +15,9 @@ main { @extend .container };
}
}
&-main {
@extend .container;
}
&-grid-3 {
@extend .row;
......
#
# rails 5.2 ajax by default
#
class FacilitiesController < ApplicationController
def index
@facilities = Facility.kept.order(:name).page params[:page]
end
def new
end
def create
@facility.save!
render :edit, status: :created, location: @facility
# rescue *user_errors => e
# render json: @facility.errors, status: :unprocessable_entity
#
# rescue => e
# log_stack_error e
# render json: @facility.errors, status: :unprocessable_entity
end
def show
redirect_to edit_facility_path(@facility)
end
def edit
rescue *user_errors => e
redirect_to facilities_path, notice: e
rescue => e
log_stack_error e
redirect_to facilities_path, notice: stack_error_message
end
def update
@facility.update! resource_params
redirect_to facilities_path, notice: "Facility updated"
rescue *user_errors => e
render :edit
rescue => e
log_stack_error e
stack_error_message(:now)
render :edit
end
# TODO: undiscard
def destroy
@facility.discard
redirect_to facilities_path, notice: "Facility deleted"
rescue *user_errors => e
redirect_to facilities_path, notice: e
rescue => e
log_stack_error e
redirect_to facilities_path, notice: stack_error_message
end
end
\ No newline at end of file
class FacilitiesController < ApplicationController
def index
end
def new
end
def create
end
def show
end
def edit
end
def update
end
def destroy
end
end
\ No newline at end of file
......@@ -4,9 +4,26 @@ module ApplicationHelper
def emt_navbar
return if skip_navbar
# navbar > container-fluid > ul nav navbar-nav > li > a
%Q[<div class='emt-navbar'>
<div>
#{link_to EMT::APP_NAME, root_path, class: 'brand'}
<ul>
<li>
#{link_to EMT::APP_NAME, root_path, class: 'brand'}
</li>
</ul>
<ul>
<li>
#{link_to "source", EMT::GITHUB_SOURCE_URL}
</li>
<li>
#{link_to "gardwired", EMT::GARDWIRED_URL}
</li>
</ul>
</div>
</div>].html_safe
end
......
......@@ -9,6 +9,7 @@ module EMT
# ***************************
# custom errors
DEFAULT_STACK_ERROR_MESSAGE = "There was a system error."
class UserError < StandardError
......
module EMT
module Validations
# try to avoid using \A\z and other regex implementation-specific functionality
# so these can be exported to js as is for client-side validations
# - these allow fine-grained validations as well as setting limits on field lengths since db no longer
# uses varchar(x) by default with AR. a good thing but we don't want someone posting "return of the king."
# - try to avoid using \A\z and other regex implementation-specific functionality
# so these can be exported to js as is for client-side validations
# - these don't map to specific fields but are definitions of our application data types (eg like xml schema, but
# without the xml part :)
#
# TODO: abstract out the limits on these so they can be used in tooltips/validation error messages
# or make these hashes with message -- maybe a validate_name(m, v, opts) which also sets error in validation block
REGEXES = {
person_name_part: /^[0-9a-zA-Z.-]{1,50}$/
name: /^[0-9a-zA-Z.-]{1,200}$/,
person_name_part: /^[0-9a-zA-Z.-]{1,50}$/,
description: /^[0-9a-zA-Z.-]{1,500}$/
}.freeze
......
class Facility < ApplicationRecord
include Discard::Model
def self.params_whitelist
[:name, :description]
end
# *************************
# validations/callbacks
#
validate do |m|
m.errors.add :name, "missing/invalid" unless valid_name(m, :name)
m.errors.add :first_name, "missing/invalid" unless valid_description(m, :description, required: false)
end
# ****************************
# instance methods
#
has_many :admissions
end
\ No newline at end of file
<%= form_with model: facility, class: 'emt-facilities-form emt-form' do |f| %>
<%= emt_form_errors(facility) %>
<div>
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div>
<%= f.label :description %>
<%= f.text_field :description %>
</div>
<%= emt_form_button(facility) %>
<%= emt_delete_button(facility) %>
<% end %>
<div class='emt-patients-edit'>
<%= render 'form', facility: @facility %>
</div>
\ No newline at end of file
<div class='emt-facilities'>
<%= link_to "Add Facility", new_facility_path, class: 'emt-btn emt-brand' %>
<%= paginate @facilities %>
<table class='emt-table'>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
<% @facilities.each_with_index do |f, idx| %>
<tr>
<td><%= link_to f.name, edit_facility_path(f) %></td>
<td><%= f.description %></td>
</tr>
<% end %>
</table>
</div>
\ No newline at end of file
<div class='emt-patients-new'>
<%= render 'form', facility: @facility %>
</div>
\ No newline at end of file
......@@ -10,11 +10,11 @@
</head>
<body>
<main>
<%= emt_navbar %>
<%= emt_navbar %>
<div class='emt-main'>
<%= emt_page_notifications %>
<%= emt_page_title %>
<%= yield %>
</main>
</div>
</body>
</html>
......@@ -24,8 +24,16 @@
<div></div>
</div>
</div>
</div>
<div class='emt-grid-3'>
<div>
<div class='emt-card'>
<div><%= link_to "Facilities", facilities_path %></div>
<div></div>
<div></div>
</div>
</div>
</div>
</div>
\ No newline at end of file
......@@ -7,6 +7,9 @@ Bundler.require(*Rails.groups)
module EMT
APP_NAME = "Emergency Transfers"
GITHUB_SOURCE_URL = "https://github.com/gardwired/emergency_transfer"
GARDWIRED_URL = "http://gardwired.com"
#
class Application < Rails::Application
......
Markdown is supported
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