Showing 4 changed files with 55 additions and 13 deletions
+5 -5
lib/Gitprep.pm
... ...
@@ -137,19 +137,19 @@ EOS
137 137
   # Helper
138 138
   $self->helper(gitprep_api => sub { Gitprep::API->new(shift) });
139 139
 
140
+  # Routes
141
+  my $r = $self->routes;
142
+
140 143
   # DBViewer(only development)
141 144
   if ($self->mode eq 'development') {
142 145
     eval {
143 146
       $self->plugin(
144 147
         'DBViewer',
145
-        dsn => "dbi:SQLite:database=$db_file",
148
+        dsn => "dbi:SQLite:database=$db_file"
146 149
       );
147 150
     };
148 151
   }
149 152
   
150
-  # Routes
151
-  my $r = $self->routes;
152
-  
153 153
   # Auto route
154 154
   {
155 155
     my $r = $r->under(sub {
... ...
@@ -171,7 +171,7 @@ EOS
171 171
     });
172 172
     $self->plugin('AutoRoute', route => $r);
173 173
   }
174
-  
174
+
175 175
   # User defined Routes
176 176
   {
177 177
     # User
+33 -4
lib/Gitprep/RepManager.pm
... ...
@@ -85,6 +85,34 @@ sub delete_user {
85 85
   return 1;
86 86
 }
87 87
 
88
+sub original_project {
89
+  my ($self, $user, $project) = @_;
90
+  
91
+  my $dbi = $self->app->dbi;
92
+  
93
+  my $config = $dbi->model('project')
94
+    ->select('config', id => [$user, $project])
95
+    ->filter(config => 'json')
96
+    ->value;
97
+  return unless $config;
98
+  
99
+  return $config->{original_project};
100
+}
101
+
102
+sub original_user {
103
+  my ($self, $user, $project) = @_;
104
+  
105
+  my $dbi = $self->app->dbi;
106
+  
107
+  my $config = $dbi->model('project')
108
+    ->select('config', id => [$user, $project])
109
+    ->filter(config => 'json')
110
+    ->value;
111
+  return unless $config;
112
+  
113
+  return $config->{original_user};
114
+}
115
+
88 116
 sub _delete_db_user {
89 117
   my ($self, $user) = @_;
90 118
   
... ...
@@ -130,8 +158,8 @@ sub fork_project {
130 158
           $login_user,
131 159
           $project,
132 160
           {
133
-            forked_user => $user,
134
-            forked_project => $project
161
+            original_user => $user,
162
+            original_project => $project
135 163
           }
136 164
         );
137 165
       };
... ...
@@ -207,11 +235,12 @@ sub rename_project {
207 235
 }
208 236
 
209 237
 sub _create_project {
210
-  my ($self, $user, $project, $opts) = @_;
211
-  $opts ||= {};
238
+  my ($self, $user, $project, $new_config) = @_;
239
+  $new_config ||= {};
212 240
   
213 241
   # Config
214 242
   my $config = {default_branch => 'master'};
243
+  $config = {%$config, %$new_config};
215 244
   my $config_json = Mojo::JSON->new->encode($config);
216 245
   
217 246
   # Create project
+6 -4
mojo/lib/Mojolicious/Plugin/AutoRoute.pm
... ...
@@ -1,7 +1,7 @@
1 1
 package Mojolicious::Plugin::AutoRoute;
2 2
 use Mojo::Base 'Mojolicious::Plugin';
3 3
 
4
-our $VERSION = '0.07';
4
+our $VERSION = '0.08';
5 5
 
6 6
 sub register {
7 7
   my ($self, $app, $conf) = @_;
... ...
@@ -14,8 +14,10 @@ sub register {
14 14
   $top_dir =~ s#^/##;
15 15
   $top_dir =~ s#/$##;
16 16
   
17
+  my $condition_name = "__auto_route_plugin_${top_dir}_file_exists";
18
+  
17 19
   # Condition
18
-  $app->routes->add_condition(__auto_route_plugin_file_exists => sub {
20
+  $app->routes->add_condition($condition_name => sub {
19 21
     my ($r, $c, $captures, $pattern) = @_;
20 22
     
21 23
     my $path = $captures->{__auto_route_plugin_path};
... ...
@@ -35,12 +37,12 @@ sub register {
35 37
   
36 38
   # Index
37 39
   $r->route('/')
38
-    ->over('__auto_route_plugin_file_exists')
40
+    ->over($condition_name)
39 41
     ->to(cb => sub { shift->render("/$top_dir/index") });
40 42
   
41 43
   # Route
42 44
   $r->route('/(*__auto_route_plugin_path)')
43
-    ->over('__auto_route_plugin_file_exists')
45
+    ->over($condition_name)
44 46
     ->to(cb => sub {
45 47
       my $c = shift;
46 48
       
+11
templates/include/project_header.html.ep
... ...
@@ -3,6 +3,8 @@
3 3
   my $logined = $api->logined;
4 4
   my $current_user = session('user');
5 5
   my $user = stash('user');
6
+  my $original_user = app->manager->original_user($user, $project);
7
+  my $original_project = app->manager->original_project($user, $project);
6 8
 %>
7 9
 
8 10
 <div class="row">
... ...
@@ -13,6 +15,15 @@
13 15
       <li><a href="<%= url_for("/$user") %>"><%= $user %></a></li>
14 16
       /
15 17
       <li><a href="<%= url_for("/$user/$project") %>"><%= $project %></a></li>
18
+      
19
+      % if (defined $original_project) {
20
+        (
21
+          forked from
22
+          <a href="<%= url_for("/$original_user/$original_project") %>">
23
+            <%= "$original_user/$original_project" %>
24
+          </a>
25
+        )
26
+      % }
16 27
     </ul>
17 28
   </div>
18 29
   <div class="span1">