Skip to content
Snippets Groups Projects
Verified Commit d3cca1bb authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Pridano razeni, strankovani, mazani zaznamu

parent d35cbd2d
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,7 @@ sub startup {
$r->get('/archive')->to(cb => sub { shift->render('archive'); });
$r->get('/api/records')->to('Record#list');
$r->delete('/api/records/:id')->to('Record#delete');
$r->get('/archive/:id')->to('Record#player');
# $r->get('/streams/add')->over( is => 'administrator' )->to('Stream#add');
......
package PiTube::Controller::Record;
use Mojo::Base 'Mojolicious::Controller';
use constant PAGE_SIZE => 5;
use constant SORT_COLUMNS => qr/stream_name|publish_user_name|begin/;
use constant SORT_DIRS => qr/asc|desc/;
sub list {
my $c = shift;
......@@ -16,9 +20,21 @@ sub list {
]
};
my $count = $c->schema->resultset('Record_view')->count($cond);
my $sort = { -desc => 'begin' };
if ( $c->param('sort') =~ SORT_COLUMNS && $c->param('order') =~ SORT_DIRS ) {
$sort = { '-' . $c->param('order') => $c->param('sort') };
}
my $records = $c->schema->resultset('Record_view')->search(
$cond,
{ order_by => { -desc => 'begin' }}
{
order_by => $sort,
offset => $c->param('offset') // 0,
rows => $c->param('limit') // PAGE_SIZE,
}
);
my @records = ();
......@@ -28,12 +44,16 @@ sub list {
my %record = (
$record->get_columns(),
is_deletable => $record->is_deletable( $c->session->{user}{id} ),
);
push @records, \%record;
}
$c->render( json => \@records );
$c->render( json => {
total => $count,
rows => \@records,
});
}
sub player {
......@@ -66,4 +86,25 @@ sub player {
$c->render();
}
sub delete {
my $c = shift;
my $record = $c->schema->resultset('Record')->search({
id => $c->stash->{id},
is_protected => 'f',
publish_user_id => $c->session->{user}{id}
})->first;
if ( ! $record ) {
$c->render( status => 404, text => '');
return;
}
$record->update({
is_active => 'f'
});
$c->render( status => 204, text => '' );
}
1;
......@@ -39,5 +39,12 @@ __PACKAGE__->belongs_to(
__PACKAGE__->set_primary_key('id');
sub is_deletable {
my $self = shift;
my $user_id = shift // 0;
return 0 if $self->is_protected;
return $user_id == $self->publish_user_id;
}
1;
......@@ -8,9 +8,10 @@
data-url="/api/records">
<thead>
<tr>
<th data-field="stream_name" data-width="50" data-width-unit="%">Stream</th>
<th data-field="publish_user_name" data-width="30" data-width-unit="%">Vysílal</th>
<th data-field="begin" data-width="20" data-width-unit="%">Datum vysílání</th>
<th data-field="stream_name" data-width="45" data-width-unit="%" data-sortable="true">Stream</th>
<th data-field="publish_user_name" data-width="30" data-width-unit="%" data-sortable="true">Vysílal</th>
<th data-field="begin" data-width="20" data-width-unit="%" data-sortable="true">Datum vysílání</th>
<th data-field="id" data-width="5" data-width-unit="%" data-formatter="formatterActions"></th>
</tr>
</thead>
</table>
......@@ -18,8 +19,24 @@
<script>
$('#Records').bootstrapTable({
sortable: true,
pagination: true,
pageSize: 10,
paginationParts: ['pageInfo', 'pageList'],
sidePagination: 'server',
onClickCell: function (field, value, row, $element) {
if ( field == 'id' ) {
$.ajax({
method: 'delete',
url: '/api/records/' + row.id,
success: function(rc) {
$('#Records').bootstrapTable('refresh', {silent: true})
}
});
}
else {
window.location.href ='/archive/' + row.id;
}
},
});
......@@ -31,5 +48,10 @@ function rowStyle(row, index) {
}
}
function formatterActions(value, row) {
if ( row.is_deletable ) {
return '<i class="fas fa-trash-alt text-3xl" title="Smazat"></i>';
}
}
</script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment