Added new Unit form
This commit is contained in:
parent
2cd9900cea
commit
b0789e6217
@ -1,13 +1,10 @@
|
||||
class BodyTrackersController < ApplicationController
|
||||
before_action :find_project, only: [:index, :units]
|
||||
before_action :find_project, only: [:index]
|
||||
before_action :authorize
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def units
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# :find_* methods are called before :authorize,
|
||||
|
@ -1,7 +1,28 @@
|
||||
class UnitsController < ApplicationController
|
||||
before_action :find_project, only: [:new, :index, :create]
|
||||
before_action :authorize
|
||||
|
||||
def new
|
||||
@unit = Unit.new
|
||||
end
|
||||
|
||||
def index
|
||||
@unit = Unit.new
|
||||
end
|
||||
|
||||
def create
|
||||
end
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# :find_* methods are called before :authorize,
|
||||
# @project is required for :authorize to succeed
|
||||
def find_project
|
||||
@project = Project.find(params[:project_id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
@ -5,5 +5,5 @@
|
||||
|
||||
<h3><%= t ".heading_common" %></h3>
|
||||
<ul>
|
||||
<li><%= link_to t(".link_units"), units_project_body_trackers_path(@project) %></li>
|
||||
<li><%= link_to t(".link_units"), project_units_path(@project) %></li>
|
||||
</ul>
|
||||
|
@ -1,5 +0,0 @@
|
||||
<h2><%= t ".heading" %></h2>
|
||||
|
||||
<% content_for :sidebar do %>
|
||||
<%= render :partial => 'body_trackers/sidebar' %>
|
||||
<% end %>
|
7
app/views/units/_form.html.erb
Normal file
7
app/views/units/_form.html.erb
Normal file
@ -0,0 +1,7 @@
|
||||
<%= error_messages_for @unit %>
|
||||
|
||||
<div class="box tabular">
|
||||
<p><%= f.text_field :name, :required => true, :size => 40 %></p>
|
||||
<p><%= f.text_field :shortname, :required => true, :size => 10 %></p>
|
||||
<p><%#= f.select :summary, :cols => 60, :rows => 2 %></p>
|
||||
</div>
|
26
app/views/units/index.html.erb
Normal file
26
app/views/units/index.html.erb
Normal file
@ -0,0 +1,26 @@
|
||||
<% content_for :sidebar do %>
|
||||
<%= render :partial => 'body_trackers/sidebar' %>
|
||||
<% end %>
|
||||
|
||||
<div class="contextual">
|
||||
<% if @project && User.current.allowed_to?(:manage_units, @project) %>
|
||||
<%= link_to t(".heading_new_unit"), new_project_unit_path(@project),
|
||||
:class => 'icon icon-add',
|
||||
:onclick => 'showAndScrollTo("add-unit", "unit_name"); return false;' %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div id="add-unit" style="display:none;">
|
||||
<h2><%= t ".heading_new_unit" %></h2>
|
||||
|
||||
<%= labelled_form_for @unit,
|
||||
:url => project_units_path(@project),
|
||||
:html => { :id => 'unit-form', :multipart => true } do |f| %>
|
||||
<%= render :partial => 'units/form', :locals => { :f => f } %>
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-unit").hide()' %>
|
||||
<% end %>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<h2><%= t ".heading" %></h2>
|
@ -1,6 +1,7 @@
|
||||
# English strings go here for Rails i18n
|
||||
en:
|
||||
body_trackers_menu_caption: 'Body trackers'
|
||||
field_shortname: 'Short name'
|
||||
body_trackers:
|
||||
index:
|
||||
heading: 'Summary'
|
||||
@ -9,5 +10,7 @@ en:
|
||||
heading_common: 'Common'
|
||||
link_summary: 'Summary'
|
||||
link_units: 'Units'
|
||||
units:
|
||||
units:
|
||||
index:
|
||||
heading: 'Units'
|
||||
heading_new_unit: 'New unit'
|
||||
|
@ -3,10 +3,7 @@
|
||||
|
||||
resources :projects do
|
||||
shallow do
|
||||
resources :body_trackers, :controller => 'body_trackers', :only => [:index] do
|
||||
collection do
|
||||
get 'units'
|
||||
end
|
||||
end
|
||||
resources :body_trackers, :only => [:index]
|
||||
resources :units, :only => [:new, :index, :create, :destroy]
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,7 @@
|
||||
class CreateUnits < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :units do |t|
|
||||
t.references :project_id
|
||||
t.string :name
|
||||
t.string :shortname
|
||||
t.integer :type
|
||||
|
3
init.rb
3
init.rb
@ -7,7 +7,8 @@ Redmine::Plugin.register :body_tracking do
|
||||
author_url 'https://github.com/cryptogopher'
|
||||
|
||||
project_module :body_tracking do
|
||||
permission :view_body_trackers, {:body_trackers => [:index, :units]}, read: true
|
||||
permission :view_body_trackers, {:body_trackers => [:index], :units => [:index]}, read: true
|
||||
permission :manage_units, {:units => [:new, :create, :destroy]}, require: :loggedin
|
||||
end
|
||||
|
||||
menu :project_menu, :body_trackers, {:controller => 'body_trackers', :action => 'index'},
|
||||
|
Reference in New Issue
Block a user