Showing 4 changed files with 65 additions and 7 deletions
+1 -1
lib/Gitprep.pm
... ...
@@ -197,7 +197,7 @@ EOS
197 197
     $r->get('/compare/(#rev1)...(#rev2)')->to('#compare');
198 198
     
199 199
     # Settings
200
-    $r->get('/settings')->to('#settings');
200
+    $r->any('/settings')->to('#settings');
201 201
   }
202 202
 }
203 203
 
+14 -5
lib/Gitprep/Git.pm
... ...
@@ -583,15 +583,24 @@ sub rep {
583 583
 }
584 584
 
585 585
 sub description {
586
-  my ($self, $user, $project) = @_;
586
+  my ($self, $user, $project, $description) = @_;
587 587
   
588 588
   my $rep = $self->rep($user, $project);
589
-  
590
-  # Project Description
591 589
   my $file = "$rep/description";
592
-  my $description = $self->_slurp($file) || '';
593 590
   
594
-  return $description;
591
+  if (defined $description) {
592
+    # Write description
593
+    open my $fh, '>',$file
594
+      or croak "Can't open file $rep: $!";
595
+    print $fh encode('UTF-8', $description)
596
+      or croak "Can't write description: $!";
597
+    close $fh;
598
+  }
599
+  else {
600
+    # Read description
601
+    my $description = $self->_slurp($file) || '';
602
+    return $description;
603
+  }
595 604
 }
596 605
 
597 606
 sub last_activity {
+3 -1
templates/main/raw.html.ep
... ...
@@ -63,5 +63,7 @@
63 63
   $self->res->headers->content_disposition($content_disposition);
64 64
   $self->res->headers->content_type($type);
65 65
   
66
-  return $content;
66
+  $self->render(text => $content);
67
+  
68
+  return $self->res->body;
67 69
 %>
+47
templates/main/settings.html.ep
... ...
@@ -1,9 +1,46 @@
1 1
 <%
2
+  my $api = gitprep_api;
3
+  my $logined = $api->logined;
4
+  my $user_is_valid = $logined && $user eq session('user_id');
5
+
2 6
   my $git = app->git;
7
+
8
+  my $op = param('op') || '';
9
+  
10
+  $api->croak("Fobbiden") if !$user_is_valid;
11
+  
12
+  if ($op eq 'change_description') {
13
+    my $description = param('description');
14
+    $description = '' unless defined $description;
15
+    
16
+    $git->description($user, $project, $description);
17
+    $self->render(json => {ok => 1});
18
+    return $self->res->body;
19
+  }
3 20
 %>
4 21
 
5 22
 % layout 'common';
6 23
   
24
+  %= javascript begin
25
+  
26
+    $(document).ready(function () {
27
+    
28
+      // Change description
29
+      $('a[href="#description"]').on('click', function () {
30
+        var description = $('input[name="description"]').val();
31
+        var url = "<%= url_for %>?op=change_description&description=" + description;
32
+        $.post(url, function (result) {
33
+          if (result.ok) {
34
+            $('#modal-message').text('Description is changed');
35
+            $('#success').modal('show');
36
+          }
37
+        });
38
+      });
39
+      
40
+    });
41
+  
42
+  % end
43
+  
7 44
   %= include '/include/header';
8 45
   
9 46
   <div class="container">
... ...
@@ -32,6 +69,7 @@
32 69
       </div>
33 70
       <div class="border-gray padding5" style="border-top:none">
34 71
         Default Branch
72
+        % my $branches = $git->branches($user, $project);
35 73
         % my $branch_names = [map { $_->{name} } @$branches];
36 74
         %= select_field 'default_branch' => $branch_names, style => 'margin-top:5px';
37 75
       </div>
... ...
@@ -50,4 +88,13 @@
50 88
     </div>
51 89
   </div>
52 90
   
91
+  <div id="success" class="modal hide">
92
+    <div class="modal-header">
93
+      <div id="modal-message" style="font-weight:bold"></div>
94
+    </div>
95
+    <div class="modal-body">
96
+      <button class="btn" data-dismiss="modal" aria-hidden="true">OK</button>
97
+    </div>
98
+  </div>
99
+
53 100
   %= include '/include/footer';