gitprep / templates / labels.html.ep /
Newer Older
264 lines | 8.122kb
add labels page
Yuki Kimoto authored on 2016-07-25
1
<%
2
  # API
3
  my $api = gitprep_api;
4
  
5
  # Parameters
6
  my $user_id = param('user');
7
  my $project_id = param('project');
8
  
add label remove feature
Yuki Kimoto authored on 2016-07-29
9
  # Can write access
10
  my $session_user_id = $api->session_user_id;
11
  my $can_write_access = $api->can_write_access($session_user_id, $user_id, $project_id);
12
  
add create label
Yuki Kimoto authored on 2016-07-28
13
  my $errors;
14
  if (lc $self->req->method eq 'post') {
add label remove feature
Yuki Kimoto authored on 2016-07-29
15
    unless ($can_write_access) {
16
      Carp::croak("Don't have write access");
17
    }
18

            
add create label
Yuki Kimoto authored on 2016-07-28
19
    my $op = param('op') // '';
20

            
21
    my $project_row_id = app->dbi->model('project')->select(
22
      'project.row_id',
23
      where => {'user.id' => $user_id, 'project.id' => $project_id}
24
    )->value;
25
    
26
    if ($op eq 'create') {
27
      my $id = param('label-id');
28
      my $color = param('color');
29
      
30
      my $vc = app->vc;
31
      my $validation = $vc->validation;
32
      
33
      if (!length $id) {
34
        $validation->add_failed(id => "Name can't be blank");
35
      }
36
      elsif (length $id > 100) {
37
        $validation->add_failed(id => "Name is too long");
38
      }
39
      else {
40
        my $label = app->dbi->model('label')->select(
41
          where => {
42
            project => $project_row_id,
43
            id => $id
44
          }
45
        )->one;
46
        
47
        if ($label) {
48
          $validation->add_failed(id => "Name has already been taken");
49
        }
50
      }
51
      
52
      if (!length $color) {
53
        $validation->add_failed(color => "Color can't be blank");
54
      }
55
      
56
      if ($validation->is_valid) {
57
        
58
        my $new_label = {
59
          id => $id,
60
          color => $color,
61
          project => $project_row_id
62
        };
63
        
64
        app->dbi->model('label')->insert($new_label);
65
        
66
        $self->redirect_to;
67
        return;
68
      }
69
      else {
70
        $errors = $validation->messages;
71
      }
72
    }
add label remove feature
Yuki Kimoto authored on 2016-07-29
73
    elsif ($op eq 'api-delete') {
add label update
Yuki Kimoto authored on 2016-07-29
74
      my $row_id = param('row-id');
add label remove feature
Yuki Kimoto authored on 2016-07-29
75
      
76
      app->dbi->model('label')->delete(where => {row_id => $row_id});
77
      
78
      $self->render(json => {success => 1});
79
      return;
80
    }
add label update
Yuki Kimoto authored on 2016-07-29
81
    elsif ($op eq 'api-update') {
82
      my $row_id = param('row-id');
83
      my $id = param('id');
84
      my $color = param('color');
85
      
86
      my $vc = app->vc;
87
      my $validation = $vc->validation;
88
      
89
      if (!length $id) {
90
        $validation->add_failed(id => "Name can't be blank");
91
      }
92
      elsif (length $id > 100) {
93
        $validation->add_failed(id => "Name is too long");
94
      }
95
      else {
96
        my $label = app->dbi->model('label')->select(
97
          where => {
98
            project => $project_row_id,
99
            id => $id
100
          }
101
        )->one;
102
        
103
        if ($label && $id ne $label->{id}) {
104
          $validation->add_failed(id => "Name has already been taken");
105
        }
106
      }
107
      
108
      if (!length $color) {
109
        $validation->add_failed(color => "Color can't be blank");
110
      }
111
      
112
      if ($validation->is_valid) {
113
        app->dbi->model('label')->update({id => $id, color => $color}, where => {row_id => $row_id});
114
        
115
        $self->render(json => {success => 1, id => $id, color => $color});
116
        return;
117
      }
118
      else {
119
        $self->render(json => {success => 0, message => $validation->messages->[0]});
120
        return;
121
      }
122
    }
add create label
Yuki Kimoto authored on 2016-07-28
123
  }
124
  
show labels
Yuki Kimoto authored on 2016-07-26
125
  my $labels = app->dbi->model('label')->select(
126
    {__MY__ => '*'},
127
    where => {'project__user.id' => $user_id, 'project.id' => $project_id},
128
    append => 'order by id'
129
  )->all;
130
  
add color pallette
Yuki Kimoto authored on 2016-07-28
131
  # Default color;
132
  my $default_color = "#" . sprintf('%02x', int rand 255) . sprintf('%02x', int rand 255) . sprintf('%02x', int rand 255);
133

            
add labels page
Yuki Kimoto authored on 2016-07-25
134
  layout 'common', title => "Labels - $user_id/$project_id";
135
%>
136

            
cleanup new label
Yuki Kimoto authored on 2016-07-27
137
%= javascript begin
138
  $(document).ready(function () {
139
    $('.labels-new-btn').on('click', function () {
140
      $('.labels-create-panel').toggle();
141
    });
implement edit area
Yuki Kimoto authored on 2016-07-27
142

            
cleanup new label
Yuki Kimoto authored on 2016-07-27
143
    $('.labels-create-cancel-btn').on('click', function () {
144
      $('.labels-create-panel').hide();
145
    });
implement edit area
Yuki Kimoto authored on 2016-07-27
146
    
147
    $('.labels-edit').on('click', function () {
148
      $(this).closest('li').find('.labels-display-area').hide();
149
      $(this).closest('li').find('.labels-edit-area').show();
150
    });
151

            
152
    $('.labels-edit-cancel-btn').on('click', function () {
153
      $(this).closest('li').find('.labels-display-area').show();
154
      $(this).closest('li').find('.labels-edit-area').hide();
155
    });
156
    
add label remove feature
Yuki Kimoto authored on 2016-07-29
157
    $('.labels-delete').on('click', function () {
158
      var li = $(this).closest('li');
add label update
Yuki Kimoto authored on 2016-07-29
159
      var row_id = li.attr('row-id');
160
      $.post('<%= url_for %>', {'row-id' : row_id, op : 'api-delete'}, function (result) {
add label remove feature
Yuki Kimoto authored on 2016-07-29
161
        if (result.success) {
162
          li.fadeOut();
163
        }
164
      });
165
    });
add label update
Yuki Kimoto authored on 2016-07-29
166
    
167
    $('.labels-edit-save-btn').on('click', function () {
168
      var li = $(this).closest('li');
169
      var row_id = li.attr('row-id');
170
      var id = li.find('[name=label-id]').val();
171
      var color = li.find('[name=color]').val();
172
      
173
      $.post('<%= url_for %>', {'row-id' : row_id, op : 'api-update', id : id, color : color}, function (result) {
174
        
175
        if (result.success) {
176
          li.find('.labels-label-id').text(result.id);
177
          li.find('.labels-tag').css('background', result.color);
178

            
179
          li.find('.labels-display-area').show();
180
          li.find('.labels-edit-area').hide();
181
        }
182
        else {
183
          li.find('.labels-error').text(result.message);
184
        }
185
      });
186
    });
cleanup new label
Yuki Kimoto authored on 2016-07-27
187
  });
188
% end
189

            
add labels page
Yuki Kimoto authored on 2016-07-25
190
%= include '/include/header';
191

            
192
<div class="container">
add create label
Yuki Kimoto authored on 2016-07-28
193
  %= include '/include/errors', errors => $errors;
add label remove feature
Yuki Kimoto authored on 2016-07-29
194
  % if ($can_write_access) {
195
    <div class="labels-new-panel">
improve button design
Yuki Kimoto authored on 2016-11-30
196
      <div class="labels-new-btn btn btn-green btn-new">
add label remove feature
Yuki Kimoto authored on 2016-07-29
197
        New label
198
      </div>
add labels delete edit new b...
Yuki Kimoto authored on 2016-07-27
199
    </div>
add label remove feature
Yuki Kimoto authored on 2016-07-29
200
  % }
201
  
fix label update padding
Yuki Kimoto authored on 2016-07-28
202
  <form class="labels-create-panel" action="<%= url_for %>" method="post" style="display:none">
add create label
Yuki Kimoto authored on 2016-07-28
203
    <%= hidden_field op => 'create' %>
add create label form
Yuki Kimoto authored on 2016-07-27
204
    <div class="labels-create-left">
205
      <%= input_tag 'label-id', class => 'labels-create-label-id' %>
add color pallette
Yuki Kimoto authored on 2016-07-28
206
      <div class="labels-create-label-color-area">
207
        <%= input_tag 'color' => $default_color, class => 'labels-create-label-color' %>
208
        <div class ="labels-create-label-color-palette" style="background:<%= $default_color %>;"></div>
add create label
Yuki Kimoto authored on 2016-07-28
209
        <div class="error"></div>
add color pallette
Yuki Kimoto authored on 2016-07-28
210
      </div>
add create label form
Yuki Kimoto authored on 2016-07-27
211
    </div>
212
    <div class="labels-create-right">
cleanup new label
Yuki Kimoto authored on 2016-07-27
213
      <div class="labels-create-cancel-btn btn">
add create label form
Yuki Kimoto authored on 2016-07-27
214
        Cancel
215
      </div>
rename btn-success to btn-gr...
Yuki Kimoto authored on 2016-11-30
216
      <input type="submit" value="Create label" class="labels-create-create-btn btn btn-green">
add create label form
Yuki Kimoto authored on 2016-07-27
217
    </div>
218
  </form>
show labels
Yuki Kimoto authored on 2016-07-26
219
  <ul class="labels">
220
    <li><%= @$labels %> labels</li>
221
    % for my $label (@$labels) {
add label remove feature
Yuki Kimoto authored on 2016-07-29
222
      <li row-id="<%= $label->{row_id} %>">
implement edit area
Yuki Kimoto authored on 2016-07-27
223
        <div class="labels-display-area">
224
          <div class="labels-left">
225
            <div class="labels-tag" style="background:<%= $label->{color} %>;">
226
              <i class="icon icon-tag"></i>
add label update
Yuki Kimoto authored on 2016-07-29
227
              <span class="labels-label-id"><%= $label->{id} %></span>
implement edit area
Yuki Kimoto authored on 2016-07-27
228
            </div>
229
          </div>
230
          <div class="labels-right">
add label remove feature
Yuki Kimoto authored on 2016-07-29
231
            % if ($can_write_access) {
232
              <div class="labels-edit">
233
                <a href="javascript:void(0)"><i class="icon icon-edit"></i> Edit</a>
234
              </div>
235
              <div class="labels-delete">
236
                <a href="javascript:void(0)"><i class="icon icon-remove"></i> Delete</a>
237
              </div>
238
            % }
add labels delete edit new b...
Yuki Kimoto authored on 2016-07-27
239
          </div>
240
        </div>
implement edit area
Yuki Kimoto authored on 2016-07-27
241
        <div class="labels-edit-area" style="display:none">
242
          <div class="labels-left">
243
            <%= input_tag 'label-id' => $label->{id}, class => 'labels-edit-label-id' %>
add color pallette
Yuki Kimoto authored on 2016-07-28
244
            <div class="labels-edit-label-color-area">
245
              <%= input_tag 'color' => $label->{color}, class => 'labels-edit-label-color' %>
246
              <div class ="labels-edit-label-color-palette" style="background:<%= $label->{color} %>;"></div>
247
            </div>
add label update
Yuki Kimoto authored on 2016-07-29
248
            <div class="labels-error" style="display:inline-block;color:red;"></div>
add labels delete edit new b...
Yuki Kimoto authored on 2016-07-27
249
          </div>
implement edit area
Yuki Kimoto authored on 2016-07-27
250
          <div class="labels-right">
251
            <div class="labels-edit-cancel-btn btn">
252
              Cancel
253
            </div>
rename btn-success to btn-gr...
Yuki Kimoto authored on 2016-11-30
254
            <div class="labels-edit-save-btn btn btn-green">
implement edit area
Yuki Kimoto authored on 2016-07-27
255
              Save changes
256
            </div>
add labels delete edit new b...
Yuki Kimoto authored on 2016-07-27
257
          </div>
show labels
Yuki Kimoto authored on 2016-07-26
258
        </div>
259
      </li>
260
    % }
261
  </ul>
add labels page
Yuki Kimoto authored on 2016-07-25
262
</div>
263

            
264
%= include '/include/footer';