Skip to content
This repository
Browse code

adding drag to assign

  • Loading branch information...
commit cc5b544a09137f3bfdb3d717222d9a5f2ebb71b3 1 parent 4df1610
Ryan Rauh authored December 27, 2012
4  lib/api.rb
@@ -30,6 +30,10 @@ class API < Sinatra::Base
30 30
       json pebble.reorder_milestone params[:user], params[:repo], milestone["number"], params[:index], params[:status]
31 31
     end
32 32
 
  33
+    post '/:user/:repo/assigncard' do 
  34
+      publish "#{params[:user]}/#{params[:repo]}", "Assigned.#{params[:issue][:number]}", { issue:params[:issue], assignee: params[:assignee]}
  35
+      json pebble.assign_card params[:user], params[:repo], params[:issue], params[:assignee]
  36
+    end
33 37
     post '/:user/:repo/movecard' do 
34 38
       publish "#{params[:user]}/#{params[:repo]}", "Moved.#{params[:issue][:number]}", { issue:params[:issue], index: params[:index]}
35 39
       json pebble.move_card params[:user], params[:repo], params[:issue], params[:index]
3  public/css/scss/_board.scss
@@ -95,6 +95,9 @@
95 95
   background-color: #fff;
96 96
   border: 1px solid #e5e5e5;
97 97
   border-bottom-color: darken(#e5e5e5, 5%); 
  98
+  &.assignee-accept {
  99
+     border-color: blue;
  100
+  }
98 101
   &.dim {
99 102
     opacity: 0.5;
100 103
     @include transition (opacity 0.6s, ease-out);
14  public/css/scss/_header.scss
@@ -19,4 +19,18 @@
19 19
      font-size: 24px;
20 20
    }
21 21
 }
  22
+.assignee {
  23
+       list-style: none;
  24
+       line-height: 40px;
  25
+       float:left;
  26
+       margin:0 2px;
  27
+}
  28
+.page-header-wrapper {
  29
+   ol {
  30
+     margin: 0;
  31
+     padding: 0;
  32
+     float: right;
  33
+     list-style: none;
  34
+   }
  35
+}
22 36
 
10  public/scripts/modules/board/models/card.js
@@ -25,6 +25,16 @@ define(["../events/postal"],function(postal){
25 25
         //console.log("closed issue", data.index);
26 26
       });
27 27
     },
  28
+    assign: function(assignee){
  29
+      this.attributes.assignee = assignee;
  30
+      $.post("/api/" + this.attributes.repo.owner.login + "/" + this.attributes.repo.name + "/assigncard",{
  31
+        issue: this.attributes,
  32
+        assignee: assignee.login
  33
+      }, function(response) {
  34
+
  35
+      });
  36
+
  37
+    },
28 38
     reorder: function(data) {
29 39
       $.post("/api/" + this.attributes.repo.owner.login + "/" + this.attributes.repo.name + "/reorderissue",{
30 40
         index: data.order,
3  public/scripts/modules/board/templates/assignee.html
... ...
@@ -0,0 +1,3 @@
  1
+<li class="assignee" data-login="<%= login %>">
  2
+  <img src="https://secure.gravatar.com/avatar/<%= gravatar_id %>?s=24" title="<%=login %>" alt="<%= login %>"/>
  3
+</li>
2  public/scripts/modules/board/views/board.js
@@ -64,7 +64,7 @@ define(["../collections/issues","text!../templates/board.html", "./columnView","
64 64
                noneColumn = _.first(data.labels),
65 65
                rest = _.rest(data.labels),
66 66
                sidebar = new sidebarView({data:data,params:this.params}),
67  
-               searchView = new headerView(),
  67
+               searchView = new headerView({data:data, params: this.params}),
68 68
                self = this;
69 69
            
70 70
            $(noneBoard).append(new columnView({column: noneColumn, user:this.user,repo:this.repo}).render().el);
14  public/scripts/modules/board/views/cardView.js
@@ -4,7 +4,7 @@ define(["text!../templates/card.html","../models/card", "../events/postal"],func
4 4
     initialize: function ( params ) {
5 5
       this.issue = new card({model:params.issue, user:params.user,repo: params.repo});
6 6
       _.bind(this,'moved',this.moved);
7  
-      _.bind(this,'drop',this.drop);
  7
+      _.bind(this,'reorder',this.drop);
8 8
       postal.subscribe("Filter.Simple", $.proxy(this.simpleFilter, this));
9 9
       postal.subscribe("Filter.Complex", $.proxy(this.complexFilter, this));
10 10
       postal.socket(params.user + "/" + params.repo,"Moved." + params.issue.number, $.proxy(this.onMoved,this));
@@ -15,7 +15,8 @@ define(["text!../templates/card.html","../models/card", "../events/postal"],func
15 15
     events: {
16 16
       "moved" : "moved",
17 17
       "click .close": "closed",
18  
-      "drop" : "drop"
  18
+      "drop": "dropped",
  19
+      "reorder" : "drop"
19 20
     },
20 21
     tagName:"li",
21 22
     onMoved: function(data){
@@ -27,6 +28,7 @@ define(["text!../templates/card.html","../models/card", "../events/postal"],func
27 28
     },
28 29
     render: function(){
29 30
       $(this.el).html( _.template(template, this.issue.attributes))
  31
+      .droppable({scope:"assignee",hoverClass:"assignee-accept"})
30 32
       .data("issue",this.issue.attributes);
31 33
 
32 34
       if(this.issue.attributes.repo.color){
@@ -45,6 +47,14 @@ define(["text!../templates/card.html","../models/card", "../events/postal"],func
45 47
     moved: function(ev,index){
46 48
       this.issue.save({index: index});
47 49
     },
  50
+    dropped: function(ev, ui){
  51
+      console.log("i got dropped yo!",ev, ui);
  52
+      console.log($(ui.draggable).data("login"));
  53
+      this.issue.assign($(ui.draggable).data("assignee"));
  54
+      console.log(this.issue.attributes);
  55
+      this.render();
  56
+      
  57
+    },
48 58
     closed: function(ev, index){
49 59
       ev.preventDefault();
50 60
       this.issue.close({index: index});
6  public/scripts/modules/board/views/columnView.js
@@ -85,18 +85,18 @@ define(["text!../templates/column.html","./cardView","../events/postal"],functio
85 85
         // dragged it to the top
86 86
         currentData._data.order = (after || 1)/2;
87 87
         currentElement
88  
-        .trigger("drop", currentData._data.order)  
  88
+        .trigger("reorder", currentData._data.order)  
89 89
         .data("issue", currentData);  
90 90
       } else if (last) {
91 91
         // dragged to the bottom
92 92
         currentData._data.order = (before + 1);
93 93
         currentElement
94  
-        .trigger("drop", currentData._data.order)  
  94
+        .trigger("reorder", currentData._data.order)  
95 95
         .data("issue", currentData);  
96 96
       }  else {
97 97
         currentData._data.order = (((after + before) || 1)/2);
98 98
         currentElement
99  
-        .trigger("drop", currentData._data.order)  
  99
+        .trigger("reorder", currentData._data.order)  
100 100
         .data("issue", currentData);  
101 101
       }
102 102
     }
17  public/scripts/modules/board/views/headerView.js
... ...
@@ -1,12 +1,13 @@
1  
-define(["../events/postal"], function(postal){
  1
+define(["../events/postal", "text!../templates/assignee.html"], function(postal, template){
2 2
 
3 3
   return Backbone.View.extend({
4  
-     el: $(".header"),
  4
+     el: $(".page-header-wrapper"),
5 5
      events: {
6 6
        "keyup input" : "onkeyup"
7 7
      },
8  
-     initialize: function(){
  8
+     initialize: function(options){
9 9
        var self = this;
  10
+       self.data = options.data;
10 11
 
11 12
        this.publish = _.debounce(function() {
12 13
           var val = $(self.el).find("input").val();
@@ -15,6 +16,16 @@ define(["../events/postal"], function(postal){
15 16
           }, state:2});
16 17
 
17 18
        }, 300);
  19
+       self.render();
  20
+     },
  21
+     render: function() {
  22
+       var list = $(this.el).find("ol");
  23
+       var users = _(this.data.assignees).chain().map(function(assignee) {
  24
+         return $(_.template(template, assignee)).data("assignee",assignee);
  25
+       }).value();
  26
+       list.append(users);
  27
+       list.find("li").draggable({helper:"clone",scope: "assignee", zIndex:100, appendTo: 'body'});
  28
+       return this;
18 29
      },
19 30
      onkeyup : function(ev){
20 31
        this.publish();
4  stint/stint/lib/stint/github.rb
@@ -44,6 +44,10 @@ def create_label(user_name, repo, params)
44 44
       gh.repos(user_name, repo).labels.create(params)
45 45
     end
46 46
 
  47
+    def assignees(user_name, repo)
  48
+      gh.repos(user_name,repo).assignees.all
  49
+    end
  50
+
47 51
     def milestones(user_name, repo)
48 52
       response = get_issues user_name, repo
49 53
       reply = response.group_by { |issue| issue["milestone"] }.map do |milestone, issues|
5  stint/stint/lib/stint/pebble.rb
@@ -83,6 +83,7 @@ def board(user_name, repo)
83 83
         board[:other_labels] = board[:other_labels].group_by { |l| l["name"].downcase }.map{|k,v| v.first }
84 84
 
85 85
         board[:milestones] = board[:milestones].group_by { |l| l["title"].downcase }.map{|k,v| v.first }
  86
+        board[:assignees] = github.assignees(user_name, repo).map{|a| a}
86 87
         return board
87 88
     end
88 89
 
@@ -225,6 +226,10 @@ def push_card(user_name, repo, commit)
225 226
       github.update_issue user_name, repo, {"number" => issue["number"],"labels" => issue["labels"]}
226 227
     end
227 228
 
  229
+    def assign_card(user_name, repo, the_issue, assignee)
  230
+      github.update_issue user_name, repo, {"number" => the_issue["number"], "assignee" => assignee}
  231
+    end
  232
+
228 233
     def move_card(user_name, repo, the_issue, index)
229 234
       labels = github.labels user_name, repo
230 235
 
4  views/board.erb
@@ -15,9 +15,9 @@
15 15
 <% end %>
16 16
 
17 17
 <% content_for :header do %>
18  
-  <ul class="assignees">
  18
+  <ol class="assignees">
19 19
 
20  
-  </ul>
  20
+  </ol>
21 21
   <h1 class="header">
22 22
     <span class="author"><%= h @parameters[:user] %></span>
23 23
     /

0 notes on commit cc5b544

Please sign in to comment.
Something went wrong with that request. Please try again.