Metric Admin
This gem builds and edits metrics.
Updating
Bump version in version.rb Commit rake build rake release
Installation
Clone this repo to your local computer.
Add this line to your application's Gemfile:
gem 'metric_admin'
And then execute:
$ bundle install
Usage
In your application.js file add the following snippet:
$(function(){
$('a[rel="popover"]').popover();
$(".list-group").sortable({
update: function(event, ui) {
var data = $(this).sortable('serialize');
//alert(data);
$.ajax({
data: data,
type: 'POST',
url: '/metrics/sort'
});
}
});
// this excludes the div with class header from being sorted.
$(".list-group").sortable({ cancel: '.header' });
});
Also ensure that you are allowing for the CSRF Meta tags:
$(function(){
$.ajaxSetup({
beforeSend: function( xhr ) {
var token = $('meta[name="csrf-token"]').attr('content');
if (token) xhr.setRequestHeader('X-CSRF-Token', token);
}
});
});
In your config/routes.rb add the following:
map.connect "/metrics/sort", :controller => "admin/admin", :action => "sort"
Make a new css file in public/css for the gem:
h2.page-subtitle.pull-left {
margin-left: 1.1em;
}
.list-group {
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 3px;
}
.list-group-item,
.header {
background-color: #f4f4f4;
border-bottom: 1px solid #ccc;
padding: 8px 15px;
vertical-align: middle;
}
.list-group-item:last-child {
border-bottom: none;
}
.list-group-item.odd {
background-color: #f4f4f4;
}
.list-group-item.even {
background-color: #fff;
}
In the AdminController add the following:
def sort
params[:metric].each_with_index do |metric_id, i|
metric = Metric.find(metric_id)
metric.update_attribute(:public_sort, i)
end
render :json => "sorted"
end
Contributing
- Fork it ( https://github.com/analyticsforlawyers/afl_teamwork/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request