From dd833d28ad91498070b4c72243c57022f4513544 Mon Sep 17 00:00:00 2001 From: VSizov Date: Sat, 15 Oct 2011 19:56:53 +0300 Subject: [PATCH 1/3] Sortable issues --- Gemfile | 1 + Gemfile.lock | 2 ++ app/assets/javascripts/dashboard.js.coffee | 3 --- app/assets/javascripts/issues.js.coffee | 3 --- app/assets/javascripts/profile.js.coffee | 3 --- app/assets/javascripts/projects.js | 1 + app/assets/stylesheets/projects.css.scss | 4 ++++ app/controllers/issues_controller.rb | 10 +++++++++ app/models/issue.rb | 2 ++ app/models/project.rb | 2 +- app/views/issues/_show.html.haml | 2 +- app/views/issues/index.html.haml | 26 ++++++++++++++++++++++ app/views/issues/index.js.haml | 1 + config/initializers/rails_footnotes.rb | 6 ++--- config/routes.rb | 6 ++++- db/schema.rb | 3 ++- 16 files changed, 59 insertions(+), 16 deletions(-) delete mode 100644 app/assets/javascripts/dashboard.js.coffee delete mode 100644 app/assets/javascripts/issues.js.coffee delete mode 100644 app/assets/javascripts/profile.js.coffee diff --git a/Gemfile b/Gemfile index 374b5031..523793e7 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,7 @@ gem "albino", :git => "git://github.com/gitlabhq/albino.git" gem "kaminari" gem "thin" gem "git" +gem "acts_as_list" group :assets do gem 'sass-rails', " ~> 3.1.0" diff --git a/Gemfile.lock b/Gemfile.lock index c02ad3cd..2aa894aa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,6 +61,7 @@ GEM activesupport (= 3.1.0) activesupport (3.1.0) multi_json (~> 1.0) + acts_as_list (0.1.4) addressable (2.2.6) ansi (1.3.0) archive-tar-minitar (0.5.2) @@ -240,6 +241,7 @@ PLATFORMS ruby DEPENDENCIES + acts_as_list albino! annotate! autotest diff --git a/app/assets/javascripts/dashboard.js.coffee b/app/assets/javascripts/dashboard.js.coffee deleted file mode 100644 index 76156794..00000000 --- a/app/assets/javascripts/dashboard.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/issues.js.coffee b/app/assets/javascripts/issues.js.coffee deleted file mode 100644 index 76156794..00000000 --- a/app/assets/javascripts/issues.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/profile.js.coffee b/app/assets/javascripts/profile.js.coffee deleted file mode 100644 index 76156794..00000000 --- a/app/assets/javascripts/profile.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/projects.js b/app/assets/javascripts/projects.js index dc13d006..74f0e643 100644 --- a/app/assets/javascripts/projects.js +++ b/app/assets/javascripts/projects.js @@ -34,6 +34,7 @@ $(document).ready(function(){ e.preventDefault(); } }); + }); function focusSearch() { diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index 0ee40f51..fdfd2b86 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -539,3 +539,7 @@ tbody tr:nth-child(2n) td, tbody tr.even td { float:left; } } + +.handle:hover{ + cursor: move; +} diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index f8b47198..3e5f2898 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -69,4 +69,14 @@ class IssuesController < ApplicationController format.js { render :nothing => true } end end + + def sort + @issues = @project.issues.all + @issues.each do |issue| + issue.position = params['issue'].index(issue.id.to_s) + 1 + issue.save + end + + render :nothing => true + end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 0399607e..9b1b923e 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -21,6 +21,8 @@ class Issue < ActiveRecord::Base scope :opened, where(:closed => false) scope :closed, where(:closed => true) scope :assigned, lambda { |u| where(:assignee_id => u.id)} + + acts_as_list end # == Schema Information # diff --git a/app/models/project.rb b/app/models/project.rb index 17b556c3..06a36a27 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -3,7 +3,7 @@ require "grit" class Project < ActiveRecord::Base belongs_to :owner, :class_name => "User" - has_many :issues, :dependent => :destroy + has_many :issues, :dependent => :destroy, :order => "position" has_many :users_projects, :dependent => :destroy has_many :users, :through => :users_projects has_many :notes, :dependent => :destroy diff --git a/app/views/issues/_show.html.haml b/app/views/issues/_show.html.haml index 131d0d4c..cf010208 100644 --- a/app/views/issues/_show.html.haml +++ b/app/views/issues/_show.html.haml @@ -1,6 +1,6 @@ %tr{ :id => dom_id(issue), :class => "issue", :url => project_issue_path(@project, issue) } %td - = image_tag gravatar_icon(issue.assignee.email), :class => "left", :width => 40, :style => "padding:0 5px;" + = image_tag gravatar_icon(issue.assignee.email), :class => ["left", "handle"], :width => 40, :style => "padding:0 5px;" = truncate issue.assignee.name, :lenght => 20 %td ##{issue.id} %td= html_escape issue.title diff --git a/app/views/issues/index.html.haml b/app/views/issues/index.html.haml index 7157d2c3..6f4548a8 100644 --- a/app/views/issues/index.html.haml +++ b/app/views/issues/index.html.haml @@ -22,3 +22,29 @@ :javascript $('.delete-issue').live('ajax:success', function() { $(this).closest('tr').fadeOut(); }); + + function setSortable(){ + $('#issues-table>tbody').sortable({ + axis: 'y', + dropOnEmpty: false, + handle: '.handle', + cursor: 'crosshair', + items: 'tr', + opacity: 0.4, + scroll: true, + update: function(){ + $.ajax({ + type: 'post', + data: $('#issues-table>tbody').sortable('serialize'), + dataType: 'script', + complete: function(request){ + $('#issues-table>tbody').effect('highlight'); + }, + url: "#{sort_project_issues_path(@project)}"}) + } + }); + } + + $(function(){ + setSortable(); + }); diff --git a/app/views/issues/index.js.haml b/app/views/issues/index.js.haml index 1f051309..bc18ac15 100644 --- a/app/views/issues/index.js.haml +++ b/app/views/issues/index.js.haml @@ -1,2 +1,3 @@ :plain $('#issues-table-holder').html("#{escape_javascript(render('issues'))}"); + setSortable(); diff --git a/config/initializers/rails_footnotes.rb b/config/initializers/rails_footnotes.rb index da9d58e4..db71e39c 100644 --- a/config/initializers/rails_footnotes.rb +++ b/config/initializers/rails_footnotes.rb @@ -1,5 +1,5 @@ -if defined?(Footnotes) && Rails.env.development? - Footnotes.run! # first of all +#if defined?(Footnotes) && Rails.env.development? + #Footnotes.run! # first of all # ... other init code -end +#end diff --git a/config/routes.rb b/config/routes.rb index 00106b11..bdfdff5f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -40,7 +40,11 @@ Gitlab::Application.routes.draw do end resources :commits resources :team_members - resources :issues + resources :issues do + collection do + post :sort + end + end resources :notes, :only => [:create, :destroy] end root :to => "projects#index" diff --git a/db/schema.rb b/db/schema.rb index befe0b2a..ed37dbbb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111009111204) do +ActiveRecord::Schema.define(:version => 20111015154310) do create_table "issues", :force => true do |t| t.string "title" @@ -22,6 +22,7 @@ ActiveRecord::Schema.define(:version => 20111009111204) do t.datetime "created_at" t.datetime "updated_at" t.boolean "closed", :default => false, :null => false + t.integer "position", :default => 0 end create_table "keys", :force => true do |t| From df016465cdce1bab78536e7f8faa63f5eace718e Mon Sep 17 00:00:00 2001 From: VSizov Date: Sat, 15 Oct 2011 20:13:51 +0300 Subject: [PATCH 2/3] ability for sortable --- app/controllers/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 3e5f2898..1f507660 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -5,7 +5,7 @@ class IssuesController < ApplicationController # Authorize before_filter :add_project_abilities before_filter :authorize_read_issue! - before_filter :authorize_write_issue!, :only => [:new, :create, :close, :edit, :update] + before_filter :authorize_write_issue!, :only => [:new, :create, :close, :edit, :update, :sort] before_filter :authorize_admin_issue!, :only => [:destroy] respond_to :js From e6bba9be4f0400471170e9d86f3ef15344416f2f Mon Sep 17 00:00:00 2001 From: VSizov Date: Sat, 15 Oct 2011 20:41:38 +0300 Subject: [PATCH 3/3] icon for handler of sortable --- app/assets/images/move.png | Bin 0 -> 260 bytes app/assets/stylesheets/projects.css.scss | 6 ++++++ app/views/issues/_show.html.haml | 3 ++- .../20111015154310_add_position_to_issues.rb | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 app/assets/images/move.png create mode 100644 db/migrate/20111015154310_add_position_to_issues.rb diff --git a/app/assets/images/move.png b/app/assets/images/move.png new file mode 100644 index 0000000000000000000000000000000000000000..9d2d55ddf0b460d8effa80bca82340f5a6ca3341 GIT binary patch literal 260 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1G%RF5iLn02poqmz?fC7)p-2)S?vfN&Ih#mZhV+8y*yN3R;9b3Rt`Fm-U`44i&Z04h&32%=!$C z3ttL6n7d0^>w$afvm-ty&cyXfhZ%pE%hb;j{2(RHu{Hg*tjyeRtIE%{xc4QB%L%&Z z$w(eO{9*T}G{%fgf0-1SzRbTA$oVSI;cnlG--@NqaZT~tEq}-F75I7u=wb#>S3j3^ HP6 dom_id(issue), :class => "issue", :url => project_issue_path(@project, issue) } %td - = image_tag gravatar_icon(issue.assignee.email), :class => ["left", "handle"], :width => 40, :style => "padding:0 5px;" + = image_tag "move.png" , :class => [:handle, :left] + = image_tag gravatar_icon(issue.assignee.email), :class => "left", :width => 40, :style => "padding:0 5px;" = truncate issue.assignee.name, :lenght => 20 %td ##{issue.id} %td= html_escape issue.title diff --git a/db/migrate/20111015154310_add_position_to_issues.rb b/db/migrate/20111015154310_add_position_to_issues.rb new file mode 100644 index 00000000..41451a0c --- /dev/null +++ b/db/migrate/20111015154310_add_position_to_issues.rb @@ -0,0 +1,5 @@ +class AddPositionToIssues < ActiveRecord::Migration + def change + add_column :issues, :position, :integer, :default => 0 + end +end