« blib/lib/Yukki/Web/Controller/Admin/User.pm
↑ Summary
blib/lib/Yukki/Web/Controller/Attachment.pm »
| 1 | package Yukki::Web::View::Admin::Repository; | ||
| 2 | $Yukki::Web::View::Admin::Repository::VERSION = '0.991_007'; # TRIAL | ||
| 3 | $Yukki::Web::View::Admin::Repository::VERSION = '0.991007'; | ||
| 4 | use v5.24; | ||
| 5 | use utf8; | ||
| 6 | use Moo; | ||
| 7 | |||
| 8 | use Type::Utils qw( class_type ); | ||
| 9 | use Yukki::TemplateUtil qw( field form_error mark_radio_checked ); | ||
| 10 | |||
| 11 | use namespace::clean; | ||
| 12 | |||
| 13 | extends 'Yukki::Web::View'; | ||
| 14 | |||
| 15 | with 'Yukki::Web::View::Role::Navigation'; | ||
| 16 | |||
| 17 | # ABSTRACT: display repository admin screens | ||
| 18 | |||
| 19 | |||
| 20 | has list_template => ( | ||
| 21 | is => 'ro', | ||
| 22 | isa => class_type('Template::Pure'), | ||
| 23 | lazy => 1, | ||
| 24 | builder => '_build_list_template', | ||
| 25 | ); | ||
| 26 | |||
| 27 | sub _build_list_template { | ||
| 28 | shift->prepare_template( | ||
| 29 | template => 'admin/repository/list.html', | ||
| 30 | directives => [ | ||
| 31 | '.repository' => { | ||
| 32 | 'repo<-repositories' => [ | ||
| 33 | '.name' => 'repo.name', | ||
| 34 | '.title' => 'repo.name', | ||
| 35 | '.branch' => 'repo.branch', | ||
| 36 | '.default_page' => 'repo.default_page', | ||
| 37 | '.remotes' => 'repo.remotes | encoded_string', | ||
| 38 | '.action' => 'repo.action | encoded_string', | ||
| 39 | ], | ||
| 40 | }, | ||
| 41 | ], | ||
| 42 | ); | ||
| 43 | } | ||
| 44 | |||
| 45 | has edit_template => ( | ||
| 46 | is => 'ro', | ||
| 47 | isa => class_type('Template::Pure'), | ||
| 48 | lazy => 1, | ||
| 49 | builder => '_build_edit_template', | ||
| 50 | ); | ||
| 51 | |||
| 52 | sub _build_edit_template { | ||
| 53 | my @edit_fields = qw( | ||
| 54 | name title branch default_page sort | ||
| 55 | read_groups write_groups | ||
| 56 | ); | ||
| 57 | |||
| 58 | shift->prepare_template( | ||
| 59 | template => 'admin/repository/edit.html', | ||
| 60 | directives => [ | ||
| 61 | (map { form_error($_) } (@edit_fields, 'anonymous_access_level')), | ||
| 62 | (map { ("#$_\@value" => field(["repository.$_", "form.$_", "default.$_"])) } @edit_fields), | ||
| 63 | mark_radio_checked( | ||
| 64 | 'anonymous_access_level', | ||
| 65 | 'repository.anonymous_access_level', | ||
| 66 | 'form.anonymous_access_level', | ||
| 67 | 'default.anonymous_access_level', | ||
| 68 | ), | ||
| 69 | ], | ||
| 70 | ); | ||
| 71 | } | ||
| 72 | |||
| 73 | has remotes_template => ( | ||
| 74 | is => 'ro', | ||
| 75 | isa => class_type('Template::Pure'), | ||
| 76 | lazy => 1, | ||
| 77 | builder => '_build_remotes_template', | ||
| 78 | ); | ||
| 79 | |||
| 80 | sub _build_remotes_template { | ||
| 81 | shift->prepare_template( | ||
| 82 | template => 'admin/repository/remotes.html', | ||
| 83 | directives => [ | ||
| 84 | '.remote' => { | ||
| 85 | 'remote<-remotes' => [ | ||
| 86 | '.@title' => 'remote', | ||
| 87 | '.' => 'i.index', | ||
| 88 | ], | ||
| 89 | }, | ||
| 90 | ], | ||
| 91 | ); | ||
| 92 | } | ||
| 93 | |||
| 94 | |||
| 95 | sub standard_menu { | ||
| 96 | return map { | ||
| 97 | +{ | ||
| 98 | action => $_, | ||
| 99 | href => "admin/repository/$_", | ||
| 100 | }, | ||
| 101 | } qw( add list ); | ||
| 102 | } | ||
| 103 | |||
| 104 | |||
| 105 | sub list { | ||
| 106 | my ($self, $ctx, $vars) = @_; | ||
| 107 | |||
| 108 | $ctx->response->page_title('List Repositories'); | ||
| 109 | $self->page_navigation($ctx->response, 'list'); | ||
| 110 | |||
| 111 | my @repos = map { | ||
| 112 | my $repo = $_; | ||
| 113 | my $action = $self->render_links( | ||
| 114 | context => $ctx, | ||
| 115 | links => [ | ||
| 116 | ($repo->repository_exists ? { | ||
| 117 | label => 'View', | ||
| 118 | href => '/page/view/' . $repo->name, | ||
| 119 | } : ()), | ||
| 120 | ($repo->repository_exists ? () : | ||
| 121 | { | ||
| 122 | label => 'Initialize', | ||
| 123 | href => '/admin/repository/initialize/' . $repo->name, | ||
| 124 | }), | ||
| 125 | ($repo->repository_exists ? () : | ||
| 126 | { | ||
| 127 | label => 'Remove', | ||
| 128 | href => '/admin/repository/remove/' . $repo->name, | ||
| 129 | }), | ||
| 130 | ($repo->repository_exists ? | ||
| 131 | { | ||
| 132 | label => 'Kill', | ||
| 133 | href => '/admin/repository/kill/' . $repo->name, | ||
| 134 | class => 'scary kill-action', | ||
| 135 | } : ()), | ||
| 136 | ], | ||
| 137 | ); | ||
| 138 | |||
| 139 | my $remotes = ''; | ||
| 140 | $remotes = $self->render( | ||
| 141 | template => $self->remotes_template, | ||
| 142 | context => $ctx, | ||
| 143 | vars => { | ||
| 144 | remotes => $repo->remote_config, | ||
| 145 | }, | ||
| 146 | ) if $repo->repository_exists; | ||
| 147 | |||
| 148 | { | ||
| 149 | name => $repo->name, | ||
| 150 | title => $repo->repository_settings->name, | ||
| 151 | branch => $repo->repository_settings->site_branch, | ||
| 152 | default_page => $repo->repository_settings->default_page, | ||
| 153 | remotes => $remotes, | ||
| 154 | action => $action, | ||
| 155 | } | ||
| 156 | } sort { | ||
| 157 | $a->repository_settings->sort <=> $b->repository_settings->sort | ||
| 158 | || $a->repository_settings->name cmp $b->repository_settings->name | ||
| 159 | } @{ $vars->{repositories} || [] }; | ||
| 160 | |||
| 161 | |||
| 162 | return $self->render_page( | ||
| 163 | template => $self->list_template, | ||
| 164 | context => $ctx, | ||
| 165 | vars => { | ||
| 166 | repositories => \@repos | ||
| 167 | }, | ||
| 168 | ); | ||
| 169 | } | ||
| 170 | |||
| 171 | |||
| 172 | sub edit { | ||
| 173 | my ($self, $ctx, $vars) = @_; | ||
| 174 | |||
| 175 | $ctx->response->page_title('Add Repository'); | ||
| 176 | $self->page_navigation($ctx->response, 'add'); | ||
| 177 | $ctx->response->breadcrumb($vars->{breadcrumb}); | ||
| 178 | |||
| 179 | return $self->render_page( | ||
| 180 | template => $self->edit_template, | ||
| 181 | context => $ctx, | ||
| 182 | vars => { | ||
| 183 | form => $vars->{form}, | ||
| 184 | form_errors => $vars->{form_errors}, | ||
| 185 | default => $vars->{default}, | ||
| 186 | }, | ||
| 187 | ); | ||
| 188 | } | ||
| 189 | |||
| 190 | |||
| 191 | sub initialize { | ||
| 192 | my ($self, $ctx, $vars) = @_; | ||
| 193 | |||
| 194 | $ctx->response->page_title($vars->{title}); | ||
| 195 | $ctx->response->breadcrumb($vars->{breadcrumb}); | ||
| 196 | |||
| 197 | $self->page_navigation($ctx->response, 'initialize'); | ||
| 198 | |||
| 199 | my $repo_name = $vars->{repo}->title; | ||
| 200 | return $self->render_confirmation( | ||
| 201 | context => $ctx, | ||
| 202 | title => "Initialize $repo_name?", | ||
| 203 | question => "Are you sure you want to create the git repository for storing files in $repo_name?", | ||
| 204 | yes_label => 'Initialize Now', | ||
| 205 | no_link => $vars->{return_link}, | ||
| 206 | ); | ||
| 207 | } | ||
| 208 | |||
| 209 | |||
| 210 | sub kill_it_with_fire { | ||
| 211 | my ($self, $ctx, $vars) = @_; | ||
| 212 | |||
| 213 | $ctx->response->page_title($vars->{title}); | ||
| 214 | $ctx->response->breadcrumb($vars->{breadcrumb}); | ||
| 215 | |||
| 216 | $self->page_navigation($ctx->response, 'kill'); | ||
| 217 | |||
| 218 | my $repo_name = $vars->{repo}->title; | ||
| 219 | return $self->render_confirmation( | ||
| 220 | context => $ctx, | ||
| 221 | title => "Kill $repo_name?", | ||
| 222 | question => qq[Are you sure you want to kill the git repository for storing files in $repo_name? <br><br> <strong class="scary">This operation will permanently destroy the data in your wiki. You should be very sure you want to do this before clicking KILL NOW.</strong>], | ||
| 223 | double_confirm => 1, | ||
| 224 | yes_label => 'KILL NOW. CANNOT BE UNDONE.', | ||
| 225 | no_link => $vars->{return_link}, | ||
| 226 | ); | ||
| 227 | } | ||
| 228 | |||
| 229 | |||
| 230 | sub remove { | ||
| 231 | my ($self, $ctx, $vars) = @_; | ||
| 232 | |||
| 233 | $ctx->response->page_title($vars->{title}); | ||
| 234 | $ctx->response->breadcrumb($vars->{breadcrumb}); | ||
| 235 | |||
| 236 | $self->page_navigation($ctx->response, 'remove'); | ||
| 237 | |||
| 238 | my $repo_name = $vars->{repo}->title; | ||
| 239 | return $self->render_confirmation( | ||
| 240 | context => $ctx, | ||
| 241 | title => "Remove $repo_name?", | ||
| 242 | question => qq[Are you sure you want to remove the configuration for $repo_name?], | ||
| 243 | yes_label => 'Remove Now', | ||
| 244 | no_link => $vars->{return_link}, | ||
| 245 | ); | ||
| 246 | } | ||
| 247 | |||
| 248 | 1; | ||
| 249 | |||
| 250 | __END__ |