render :action => 'index'
end
+ def create_form
+ prepare_metrics_and_domains
+
+ if params['id']
+ @metric=Metric.find(params['id'].to_i)
+ params['domain']=@metric.domain(false)
+ else
+ @metric=Metric.new
+ end
+ render :partial => 'metrics/create_form'
+ end
+
+ def edit_form
+ prepare_metrics_and_domains
+
+ @metric=Metric.find(params['id'].to_i)
+ params['domain']=@metric.domain(false)
+
+ render :partial => 'metrics/edit_form'
+ end
+
+ def reactivate_form
+ render :partial => 'metrics/reactivate_form'
+ end
+
def save_from_web
short_name = params[:metric][:short_name]
metric_name = short_name.downcase.gsub(/\s/, '_')[0..59]
end
end
rescue
- flash[:error] = metric.errors.full_messages.join("<br/>\n")
+ @errors = []
+ @errors << metric.errors.full_messages.join("<br/>\n")
end
if @reactivate_metric
prepare_metrics_and_domains
- render :action => 'index'
+ render :partial => 'metrics/reactivate_form', :status => 400
+ elsif @errors
+ @metric = metric
+ @domains = metric.domain
+ render :partial => 'metrics/create_form', :status => 400
else
redirect_to :action => 'index', :domain => metric.domain(false)
end
redirect_to :action => 'index', :domain => metric.domain(false)
end
+
def delete_from_web
metric = Metric.by_id(params[:id].to_i) if params[:id] && params[:id].size > 0
if metric
Metric.delete_with_manual_measures(params[:id].to_i)
flash[:notice] = 'Successfully deleted.'
Metric.clear_cache
+ else
+ flash[:error] = 'Sorry there was a problem with deleting'
end
redirect_to :action => 'index'
end
--- /dev/null
+<% form_for :metric, @metric, :url => { :action => 'save_from_web', :id => @metric.id }, :html => { :id =>'metric_create_form', :method => 'post'} do |f| %>
+ <fieldset>
+ <div class="modal-head">
+ <h2>Create Manual Metric</h2>
+ </div>
+ <div class="modal-body">
+ <% if @errors %>
+ <p class="error"><%= @errors -%></p>
+ <% end %>
+
+ <div class="modal-field">
+ <label for="user[login]">Name <em class="mandatory">*</em></label><%= f.text_field :short_name %><br/>
+ </div>
+ <div class="modal-field">
+ <label for="user[login]"> Description</label><%= f.text_area :description, :size => 40, :cols => 25, :rows => 2 %><br/>
+ </div>
+ <div class="modal-field">
+ <label for="user[login]">Domain</label><%= f.select( :domain, @domains, :include_blank => true) %>
+ <span class="desc">or</span> <input id="newdomain" name="newdomain" size="15" type="text"><br/><br/>
+ </div>
+ <div class="modal-field">
+ <label for="user[login]">Type</label><%= f.select( :val_type, Metric.value_type_names.invert) %><br/>
+ </div>
+ </div>
+
+ <div class="modal-foot">
+ <%= submit_tag 'create'%>
+ <%= link_to message('cancel'), { :controller => 'metrics', :action => 'index', :id => nil}, { :class => 'action' } %>
+ </div>
+ </fieldset>
+<% end %>
+
+<script>
+ $j("#metric_create_form").modalForm();
+</script>
--- /dev/null
+<% form_for :metric, @metric, :url => { :action => 'save_from_web', :id => @metric.id }, :html => { :id =>'metric_edit_form', :method => 'post'} do |f| %>
+ <fieldset>
+ <div class="modal-head">
+ <h2>Edit Manual Metric: <%= @metric.key -%></h2>
+ </div>
+ <div class="modal-body">
+ <% if @errors %>
+ <p class="error"><%= @errors -%></p>
+ <% end %>
+
+ <div class="modal-field">
+ <label for="user[login]">Name <em class="mandatory">*</em></label><%= f.text_field :short_name %><br/>
+ </div>
+ <div class="modal-field">
+ <label for="user[login]"> Description</label><%= f.text_area :description, :size => 40, :cols => 25, :rows => 2 %><br/>
+ </div>
+ <div class="modal-field">
+ <label for="user[login]">Domain</label><%= f.select( :domain, @domains, :include_blank => true) %>
+ <span class="desc">or</span> <input id="newdomain" name="newdomain" size="15" type="text"><br/><br/>
+ </div>
+ <div class="modal-field">
+ <label for="user[login]">Type</label><%= f.select( :val_type, Metric.value_type_names.invert) %><br/>
+ </div>
+ </div>
+
+ <div class="modal-foot">
+ <%= submit_tag 'Save' %>
+ <%= link_to message('cancel'), { :controller => 'metrics', :action => 'index', :id => nil}, { :class => 'action' } %>
+ </div>
+ </fieldset>
+<% end %>
+
+<script>
+ $j("#metric_edit_form").modalForm();
+</script>
--- /dev/null
+<% form_for :metric, @reactivate_metric, :url => { :action => 'reactivate', :id => @reactivate_metric.id }, :html => { :id =>'metric_reactivate_form', :method => 'post'} do |f| %>
+ <fieldset>
+ <div class="modal-head">
+ <h2>Reactivate Manual Metric: <%= @reactivate_metric.key -%></h2>
+ </div>
+ <div class="modal-body">
+ <p class="error">
+ A metric named "<%= @reactivate_metric.short_name(false) -%>" already exists in the database but is deactivated.<br/>
+ <br/>
+ Do you really want to reactivate this metric?
+ </p>
+ </div>
+ <div class="modal-foot">
+ <%= submit_tag 'Reactivate' %>
+ <%= link_to message('cancel'), { :controller => 'metrics', :action => 'index', :id => nil}, { :class => 'action' } %>
+ </div>
+ </fieldset>
+<% end %>
+
+<script>
+ $j("#metric_reactivate_form").modalForm();
+</script>
+<div class="line-block">
+ <% if profiles_administrator? %>
+ <ul style="float: right" class="horizontal">
+ <li class="marginleft10 add">
+ <a id="create-link-metric" href="<%=ApplicationController.root_context-%>/metrics/create_form" id="create-link-metric" class="open-modal link-action">Add new metric</a>
+ </li>
+ </ul>
+ <% end %>
+ <h1 class="marginbottom10"><%= message('manual_metrics.page') -%></h1>
+</div>
+
<table width="100%">
<tr>
<td valign="top">
- <h1 class="marginbottom10"><%= message('manual_metrics.page') -%></h1>
<table class="sortable data width100" id="metrics">
<thead>
<tr>
</tr>
</thead>
<tbody>
- <% @metrics.each do |metric| %>
- <tr>
- <td class="left" nowrap id="metric_key_<%= metric.key -%>"><span class="note"><%= metric.key -%></span></td>
- <td class="left" nowrap id="metric_name_<%= metric.key -%>"><%= h metric.short_name -%></td>
- <td class="left" id="metric_desc_<%= metric.key -%>"><%= h metric.description -%></td>
- <td class="left" id="metric_domain_<%= metric.key -%>"><%= metric.domain -%></td>
- <td class="left" id="metric_type_name<%= metric.key -%>"><%= metric.value_type_name -%></td>
- <td class="right thin nowrap">
- <% if is_admin? %>
- <%= link_to 'Edit', {:action => 'index', :id => metric.id}, {:class => 'link-action', :id => "edit_#{h(metric.short_name)}", :method => 'get'} %>
-
- <%= link_to 'Delete', {:action => 'delete_from_web', :id => metric.id}, {:confirm => "Warning : all the measures will be deleted.", :class => 'link-action link-red', :id => "delete_#{h(metric.short_name)}"} %>
- <% end %>
- </td>
- </tr>
- <% end %>
- </tbody>
- </table>
- <script>TableKit.Sortable.init('metrics');</script>
- </td>
-<% if is_admin? %>
- <td class="sep"> </td>
- <td valign="top" align="right" width="210">
- <table class="admintable" width="100%">
- <% if @reactivate_metric %>
- <% form_for :metric, @reactivate_metric, :url => { :action => 'reactivate', :id => @reactivate_metric.id } do |f| %>
- <tbody>
- <tr>
- <td>
- <p class="error">
- A metric named "<%= @reactivate_metric.short_name(false) -%>" already exists in the database but is deactivated.<br/>
- <br/>
- Do you really want to reactivate this metric?
- </p>
- </td>
- <tr>
- <tr>
- <td class="left" valign="top">
- <input type="hidden" name="reactivate" value="true"/>
- <%= submit_tag 'Reactivate metric' %>
- <%= link_to 'Cancel', { :controller => 'metrics', :action => 'index'}, { :class => 'action' } %><br/>
- </td>
- </tr>
- </tbody>
- <% end %>
- <% else %>
- <% form_for :metric, @metric, :url => { :action => 'save_from_web', :id => @metric.id } do |f| %>
- <tbody>
- <tr>
- <td class="left"><h1 class="marginbottom10"><%= @metric && @metric.id.nil? ? 'Create Manual Metric' : 'Edit Manual Metric' -%></h1></td>
- </tr>
- <tr>
- <td class="left" valign="top">
- Name:<br/><%= f.text_field :short_name %><br/>
- <span class="desc">Ex. : Configuration management</span>
- </td>
- </tr>
- <tr>
- <td class="left" valign="top">
- Description:<br/>
- <%= f.text_area :description, :size => 40, :cols => 25, :rows => 2 %><br/>
- <span class="desc">Ex. : Respect level of the configuration management procedure (branch, label, ...), from 0% (worst) to 100% (best).</span>
- </td>
- </tr>
- <tr>
- <td class="left" valign="top">
- Domain:<br/>
- <%= f.select( :domain, @domains, :include_blank => true) %>
- <span class="desc">or</span> <input id="newdomain" name="newdomain" size="15" type="text">
- </td>
- </tr>
- <tr>
- <td class="left" valign="top">
- Type:<br/>
- <%= f.select( :val_type, Metric.value_type_names.invert) %>
- </td>
- </tr>
- <tr>
- <td class="left" valign="top">
- <%= submit_tag @metric.id.nil? ? message('create') : message('edit') %>
- <%= link_to message('cancel'), { :controller => 'metrics', :action => 'index', :id => nil}, { :class => 'action' } %>
- </td>
- </tr>
- </tbody>
- <% end %>
- <% end %>
- </table>
- </td>
-<% end %>
+ <% @metrics.each do |metric| %>
+ <tr>
+ <td class="left" nowrap id="metric_key_<%= metric.key -%>"><span class="note"><%= metric.key -%></span></td>
+ <td class="left" nowrap id="metric_name_<%= metric.key -%>"><%= h metric.short_name -%></td>
+ <td class="left" id="metric_desc_<%= metric.key -%>"><%= h metric.description -%></td>
+ <td class="left" id="metric_domain_<%= metric.key -%>"><%= metric.domain -%></td>
+ <td class="left" id="metric_type_name<%= metric.key -%>"><%= metric.value_type_name -%></td>
+ <td class="right thin nowrap">
+ <% if is_admin? %>
+ <a id="create-link-metric" href="<%=ApplicationController.root_context-%>/metrics/edit_form/<%= metric.id -%>" id="edit_<%= h(metric.short_name)-%>" class="open-modal link-action">Edit</a>
+
+ <%= link_to_action message('delete'), "#{ApplicationController.root_context}/metrics/delete_from_web/#{metric.id}",
+ :class => 'link-action link-red',
+ :id => "delete_#{h(metric.short_name)}",
+ :confirm_button => message('delete'),
+ :confirm_title => 'Delete manual metric: '+ metric.key,
+ :confirm_msg => 'Warning : all the measures will be deleted.',
+ :confirm_msg_params => [metric.id]
+ -%>
+ <% end %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+ <script>TableKit.Sortable.init('metrics');</script>
+ </td>
</tr>
</table>