Added new Unit form
This commit is contained in:
parent
2cd9900cea
commit
b0789e6217
@ -1,13 +1,10 @@
|
|||||||
class BodyTrackersController < ApplicationController
|
class BodyTrackersController < ApplicationController
|
||||||
before_action :find_project, only: [:index, :units]
|
before_action :find_project, only: [:index]
|
||||||
before_action :authorize
|
before_action :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
end
|
end
|
||||||
|
|
||||||
def units
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# :find_* methods are called before :authorize,
|
# :find_* methods are called before :authorize,
|
||||||
|
@ -1,7 +1,28 @@
|
|||||||
class UnitsController < ApplicationController
|
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
|
def create
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
end
|
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
|
end
|
||||||
|
@ -5,5 +5,5 @@
|
|||||||
|
|
||||||
<h3><%= t ".heading_common" %></h3>
|
<h3><%= t ".heading_common" %></h3>
|
||||||
<ul>
|
<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>
|
</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
|
# English strings go here for Rails i18n
|
||||||
en:
|
en:
|
||||||
body_trackers_menu_caption: 'Body trackers'
|
body_trackers_menu_caption: 'Body trackers'
|
||||||
|
field_shortname: 'Short name'
|
||||||
body_trackers:
|
body_trackers:
|
||||||
index:
|
index:
|
||||||
heading: 'Summary'
|
heading: 'Summary'
|
||||||
@ -9,5 +10,7 @@ en:
|
|||||||
heading_common: 'Common'
|
heading_common: 'Common'
|
||||||
link_summary: 'Summary'
|
link_summary: 'Summary'
|
||||||
link_units: 'Units'
|
link_units: 'Units'
|
||||||
units:
|
units:
|
||||||
|
index:
|
||||||
heading: 'Units'
|
heading: 'Units'
|
||||||
|
heading_new_unit: 'New unit'
|
||||||
|
@ -3,10 +3,7 @@
|
|||||||
|
|
||||||
resources :projects do
|
resources :projects do
|
||||||
shallow do
|
shallow do
|
||||||
resources :body_trackers, :controller => 'body_trackers', :only => [:index] do
|
resources :body_trackers, :only => [:index]
|
||||||
collection do
|
resources :units, :only => [:new, :index, :create, :destroy]
|
||||||
get 'units'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
class CreateUnits < ActiveRecord::Migration
|
class CreateUnits < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
create_table :units do |t|
|
create_table :units do |t|
|
||||||
|
t.references :project_id
|
||||||
t.string :name
|
t.string :name
|
||||||
t.string :shortname
|
t.string :shortname
|
||||||
t.integer :type
|
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'
|
author_url 'https://github.com/cryptogopher'
|
||||||
|
|
||||||
project_module :body_tracking do
|
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
|
end
|
||||||
|
|
||||||
menu :project_menu, :body_trackers, {:controller => 'body_trackers', :action => 'index'},
|
menu :project_menu, :body_trackers, {:controller => 'body_trackers', :action => 'index'},
|
||||||
|
Reference in New Issue
Block a user