Showing 3 changed files with 115 additions and 22 deletions
+4
lib/Gitprep.pm
... ...
@@ -245,6 +245,10 @@ sub startup {
245 245
         'left join project on label.project = project.row_id',
246 246
         'left join user as project__user on project.user = project__user.row_id'
247 247
       ]
248
+    },
249
+    {
250
+      table => 'issue_label',
251
+      primary_key => 'row_id'
248 252
     }
249 253
   ];
250 254
   $dbi->create_model($_) for @$models;
+40
public/css/common.css
... ...
@@ -241,6 +241,46 @@
241 241
   color:#767676;
242 242
 }
243 243
 
244
+.issue-labels-popup {
245
+  border:1px solid #d8d8d8;
246
+  border-radius:3px;
247
+  box-shadow: 0 0 10px rgba(0,0,0,.1);
248
+  width:350px;
249
+}
250
+.issue-labels-popup-title {
251
+  border-bottom:1px solid #d8d8d8;
252
+  background:#f7f7f7;
253
+  padding:10px;
254
+  
255
+}
256
+.issue-labels-popup-body {
257
+  
258
+}
259
+.issue-labels-popup-body li {
260
+  padding:10px 10px;
261
+  border-top:1px solid #d8d8d8;
262
+  overflow:hidden;
263
+  cursor:pointer;
264
+}
265
+.issue-labels-popup-body li:first-child {
266
+  border-top:none;
267
+}
268
+.issue-labels-popup-check {
269
+  float:left;
270
+  width:20px;
271
+  height:1px;
272
+}
273
+.issue-labels-popup-pallet {
274
+  width:15px;
275
+  height:15px;
276
+  float:left;
277
+  margin-left:2px;
278
+}
279
+.issue-labels-popup-pallet-id {
280
+  float:left;
281
+  margin-left:5px;
282
+  width:50%;
283
+}
244 284
 .issue-add-comment-title {
245 285
   margin-bottom:5px;
246 286
 }
+71 -22
templates/issue.html.ep
... ...
@@ -7,6 +7,8 @@
7 7
   my $project_id = param('project');
8 8
   my $issue_number = param('number');
9 9
   my $op = param('op') // '';
10
+
11
+  my $project_row_id = $api->get_project_row_id($user_id, $project_id);
10 12
   
11 13
   my $session_id = $api->session_user_id;
12 14
 
... ...
@@ -17,38 +19,21 @@
17 19
       {open_user => ['id']}
18 20
     ],
19 21
     where => {
20
-      'project.id' => $project_id,
22
+      project => $project_row_id,
21 23
       'issue.number' => $issue_number
22 24
     }
23 25
   )->one;
26
+  my $issue_row_id = $issue->{row_id};
24 27
   
25 28
   my $errors;
26 29
   if (lc $self->req->method eq 'post') {
27 30
     if ($op eq 'reopen-issue') {
28
-      my $issue_row_id = app->dbi->model('issue')->select(
29
-        'issue.row_id',
30
-        where => {
31
-          'project__user.id' => $user_id,
32
-          'project.id' => $project_id,
33
-          number => $number
34
-        }
35
-      )->value;
36
-      
37 31
       app->dbi->model('issue')->update({open => 1}, where => {row_id => $issue_row_id});
38 32
       
39 33
       $self->redirect_to;
40 34
       return;
41 35
     }
42 36
     elsif ($op eq 'close-issue') {
43
-      my $issue_row_id = app->dbi->model('issue')->select(
44
-        'issue.row_id',
45
-        where => {
46
-          'project__user.id' => $user_id,
47
-          'project.id' => $project_id,
48
-          number => $number
49
-        }
50
-      )->value;
51
-            
52 37
       app->dbi->model('issue')->update({open => 0}, where => {row_id => $issue_row_id});
53 38
       
54 39
       $self->redirect_to;
... ...
@@ -97,6 +82,27 @@
97 82
       
98 83
       my $json = $api->api_update_issue_message($issue_message_row_id, $message, $user_id);
99 84
       
85
+      $self->render(json => $json);
86
+      return;
87
+    }
88
+    elsif ($op eq 'api-toggle-label') {
89
+      my $label_row_id = param('label-row-id');
90
+      
91
+      my $label_checked = app->dbi->model('issue_label')->select(
92
+        where => {issue => $issue_row_id, label => $label_row_id}
93
+      )->one;
94
+      
95
+      my $json = {};
96
+      if ($label_checked) {
97
+        app->dbi->model('issue_label')->delete(where => {issue => $issue_row_id, label => $label_row_id});
98
+        $json->{checked} = 0;
99
+      }
100
+      else {
101
+        app->dbi->model('issue_label')->insert({issue => $issue_row_id, label => $label_row_id});
102
+        $json->{checked} = 1
103
+      }
104
+      $json->{success} = 1;
105
+      
100 106
       $self->render(json => $json);
101 107
       return;
102 108
     }
... ...
@@ -124,15 +130,40 @@
124 130
     where => {issue => $issue->{row_id}},
125 131
   )->values;
126 132
   
133
+  # Labels
134
+  my $labels = app->dbi->model('label')->select(
135
+    {__MY__ => '*'},
136
+    where => {project => $project_row_id}
137
+  )->all;
138
+  
127 139
   layout 'common', title => "Issue - $user_id/$project_id #$issue_number";
128 140
 %>
129 141
 
130 142
 %= javascript begin
131
-
132
-
133
-
134 143
   $(document).ready(function() {
135 144
     %= include '/include/js/issue';
145
+    
146
+    // Click labels btn
147
+    $('.issue-labels-setting-btn').on('click', function () {
148
+      alert('aaa');
149
+    });
150
+    
151
+    // Click label check btn
152
+    $('.issue-labels-popup-body li').on('click', function () {
153
+      var that = this;
154
+      
155
+      var label_row_id = $(this).attr('label-row-id');
156
+      $.post('<%= url_for %>', {'label-row-id' : label_row_id, op : 'api-toggle-label'}, function (result) {
157
+        if (result.success) {
158
+          if (result.checked) {
159
+            $(that).find('.issue-labels-popup-check i').css('display', 'block');
160
+          }
161
+          else {
162
+            $(that).find('.issue-labels-popup-check i').css('display', 'none');
163
+          }
164
+        }
165
+      });
166
+    });
136 167
   });
137 168
 % end
138 169
 
... ...
@@ -231,6 +262,24 @@
231 262
       </ul>
232 263
     </div>
233 264
   </div>
265
+
266
+  <div class="issue-labels-popup"">
267
+    <div class="issue-labels-popup-title">
268
+      Apply labels to this issue
269
+    </div>
270
+    <ul class="issue-labels-popup-body">
271
+      % for my $label (@$labels) {
272
+        % my $checked = app->dbi->model('issue_label')->select(where => {issue => $issue_row_id, label => $label->{row_id}})->one;
273
+        <li label-row-id="<%= $label->{row_id} %>">
274
+          <div class="issue-labels-popup-check"><i class="icon icon-ok" style="display:<%= $checked ? 'block' : 'none' %>"></i></div>
275
+          <div class="issue-labels-popup-pallet" style="background:<%= $label->{color} %>"></div>
276
+          <div class="issue-labels-popup-pallet-id"><%= $label->{id} %></div>
277
+        </li>
278
+      % }
279
+    </ul>
280
+  </div>
234 281
 </div>
235 282
 
283
+
284
+
236 285
 %= include '/include/footer';