Blog history start.

master
Blog Manager Robot 3 years ago
parent afcd9939f9
commit 87359931f0
  1. 2
      Web/lib/MJB/Web.pm
  2. 14
      Web/lib/MJB/Web/Controller/Dashboard.pm
  3. 3
      Web/templates/dashboard/_blog_nav.html.ep
  4. 54
      Web/templates/dashboard/blog_history.html.ep
  5. 21
      libs/MJB-Backend-Jekyll/lib/MJB/Backend/Jekyll.pm

@ -129,6 +129,8 @@ sub startup ($self) {
$auth->get ( '/dashboard/blog/:id/media' )->to('Dashboard#blog_media' )->name('show_dashboard_blog_media' );
$auth->post( '/dashboard/blog/:id/media' )->to('Dashboard#do_blog_media' )->name('do_dashboard_blog_media' );
$auth->post( '/dashboard/blog/:id/media/*file' )->to('Dashboard#do_blog_media_remove' )->name('do_dashboard_blog_media_remove' );
$auth->get ( '/dashboard/blog/:id/history' )->to('Dashboard#blog_history' )->name('show_dashboard_blog_history' );
$auth->post( '/dashboard/blog/:id/history' )->to('Dashboard#do_blog_history' )->name('do_dashboard_blog_history' );
# Blog Management
$auth->get ( '/blog' )->to('Blog#create' )->name('show_blog_create' );

@ -349,6 +349,20 @@ sub do_blog_media ( $c ) {
$c->redirect_to( $c->url_for( 'show_dashboard_blog_media', { id => $blog->id } ) );
}
sub blog_history ( $c ) {
my $blog = $c->stash->{blog} = $c->db->blog( $c->param('id') );
if ( $blog->person->id ne $c->stash->{person}->id ) {
$c->render(
text => "Error: This blog isn't owned by you.",
status => 404,
format => 'txt',
);
return;
}
my $history = $c->stash->{history} = $c->jekyll($blog->domain->name)->history;
}
1;

@ -53,4 +53,7 @@
<li class="nav-item">
<a class="nav-link <%= $page eq 'settings' ? 'active' : '' %>" href="<%= $c->url_for( 'show_dashboard_blog_settings' ) %>">Settings</a>
</li>
<li class="nav-item">
<a class="nav-link <%= $page eq 'history' ? 'active' : '' %>" href="<%= $c->url_for( 'show_dashboard_blog_history' ) %>">History</a>
</li>
</ul>

@ -0,0 +1,54 @@
% layout 'standard', title => 'Dashboard', sb_active => 'dashboard';
%= include 'dashboard/_blog_nav', page => 'posts'
% if ( my $confirmation = flash 'confirmation' ) {
<div style="margin-top: 2em" class="alert alert-success" role="alert">
<%== $confirmation %>
</div>
% }
% if ( $c->stash->{success} ) {
<div style="margin-top: 2em" class="alert alert-success" role="alert">
<%= $c->stash->{success_message} %>
</div>
% }
% if ( $c->stash->{errors} ) {
<div style="margin-top: 2em" class="alert alert-danger" role="alert">
There were errors with your request that could not be resolved:
<ul>
% for my $error ( @{$c->stash->{errors}} ) {
<li><%= $error %></li>
% }
</ul>
</div>
% }
% if ( $history ) {
<table style="border: 1px solid #ccc" class="table mt-5">
<tbody>
<tr>
<th class="text-nowrap">When?</th>
<th class="text-nowrap">What?</th>
<th class="text-nowrap">Restore?</th>
</tr>
</thead>
<tbody>
% for my $change ( @{$history} ) {
<tr>
<td><%= $change->{dateref} %></a></td>
<td><%= $change->{message} %></a></td>
<td>
<form style="margin-top: 1.5em" method="POST" action="<%= $c->url_for( 'do_dashboard_blog_history' ) %>">
<input type="hidden" name="commit_id" value="<%= $change->{commit} %>">
<button type="submit" class="btn btn-sm btn-primary float-end">Restore</button>
</form>
</td>
</tr>
% }
</tbody>
</table>
% }

@ -310,13 +310,32 @@ sub delete_post {
}
sub history {
# Check if the repo exists
my ( $self ) = @_;
# Check if the repo exists and update the repo if needed
$self->_ensure_repository_is_latest;
# Do a git history
my $result = $self->system_command( [ qw(git log --date=relative), q|--pretty=%H %ad %s| ], {
chdir => $self->repo_path,
});
my @return;
# Format the results into a data structure
foreach my $line ( split( /\n/, $result->{stdout} ) ) {
if ( $line =~ /^([0-9a-f]{40}) (.+ ago) (.+)$/ ) {
push @return, {
commit => $1,
dateref => $2,
message => $3,
};
}
}
# Return the data structure
return [ @return ];
}
# Helper function to ensure the repo exists and has the latest

Loading…
Cancel
Save