diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8a11c67cc5d2bb77031a4fce34e1385ed8d7dcd2..30c510f1807da28a412e283488e002f11b32b428 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ image: docker:19.03.12 variables: DOCKER_TLS_CERTDIR: "/certs" - IMAGE_VER: 1.9.3 + IMAGE_VER: 1.10.0 services: - docker:19.03.12-dind diff --git a/lib/PiTube.pm b/lib/PiTube.pm index 2642188e7ee216a6b6108e17104f5775068805be..190a70e703c372a987b61b9beb576031015caa70 100644 --- a/lib/PiTube.pm +++ b/lib/PiTube.pm @@ -85,6 +85,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->put('/api/records/:id')->to('Record#update'); $r->get('/archive/:id')->to('Record#player'); # $r->get('/streams/add')->over( is => 'administrator' )->to('Stream#add'); diff --git a/lib/PiTube/Controller/Record.pm b/lib/PiTube/Controller/Record.pm index 545feb1b65bb9e273ebc174bbebb96272d7fb11a..28b241d7ee3c2765982337d4679d8dceee357552 100644 --- a/lib/PiTube/Controller/Record.pm +++ b/lib/PiTube/Controller/Record.pm @@ -5,8 +5,10 @@ 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; +use feature 'signatures'; +no warnings 'experimental::signatures'; + +sub list ($c) { my $readable = $c->schema->resultset('ACL')->user_acl( $c->session->{user}, 4 @@ -56,8 +58,7 @@ sub list { }); } -sub player { - my $c = shift; +sub player ($c) { # vzdy aktualizovat $c->session->{user}{acl} = $c->schema->resultset('ACL')->user_acl( @@ -77,6 +78,7 @@ sub player { $c->stash->{record} = { $record->get_columns, is_editable => $record->is_editable( $c->session->{user}{id} ), + is_deletable => $record->is_deletable( $c->session->{user}{id} ), }; if ( ! ( $c->session->{user}{acl}{ $record->stream_key } & 4 ) ) { # TODO:constant @@ -87,6 +89,26 @@ sub player { $c->render(); } +sub update ($c) { + my $args = $c->req->params->to_hash(); + + my $record = $c->schema->resultset('Record')->search({ + id => $c->stash->{id}, + publish_user_id => $c->session->{user}{id} + })->first; + + if ( ! $record ) { + $c->render( status => 404, text => ''); + return; + } + + $record->update({ + description => $args->{description}, + }); + + $c->render( status => 204, text => '' ); +} + sub delete { my $c = shift; diff --git a/templates/archive.html.ep b/templates/archive.html.ep index f24f1f66e0c89df867a1f7c4bf2d8f8bcbdf49cb..a65b587d69691086fa49083af2a1a60431e4e643 100644 --- a/templates/archive.html.ep +++ b/templates/archive.html.ep @@ -9,10 +9,9 @@ <thead> <tr> <th data-field="stream_name" data-width="25" data-width-unit="%" data-sortable="true">Stream</th> - <th data-field="description" data-width="30" data-width-unit="%" data-sortable="true">Popis</th> <th data-field="publish_user_name" data-width="20" data-width-unit="%" data-sortable="true">Vysílal</th> + <th data-field="description" data-width="40" data-width-unit="%" data-sortable="true">Popis</th> <th data-field="begin" data-width="15" data-width-unit="%" data-sortable="true">Odvysíláno</th> - <th data-field="id" data-width="5" data-width-unit="%" data-formatter="formatterActions"></th> </tr> </thead> </table> @@ -25,18 +24,7 @@ $('#Records').bootstrapTable({ 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; - } }, }); @@ -48,10 +36,5 @@ 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> diff --git a/templates/record/player.html.ep b/templates/record/player.html.ep index 46ca6e571bca9f72ffbb471d7fafb5ce250381f2..7a6c69da5926cf4d699e0220f14068b5d77574b8 100644 --- a/templates/record/player.html.ep +++ b/templates/record/player.html.ep @@ -1,3 +1,57 @@ % layout 'default'; % title $c->stash->{record}{stream_name} . ' - ' . $c->stash->{record}{begin}; %= include 'includes/player', src => $c->stash->{record}{path}, live => 0; + +% if ( $c->stash->{record}{is_editable} ) { +<div class="grid grid-cols-8 gap-4 row-gap-6" style="padding-top: 2em;"> + +<div class="form-field col-span-8"> + +<form> +<label class="form-field__label" for="description">Kratký popis videa</label> + <div class="form-field__wrapper form-field__wrapper--shadowed"> +<input type="text" name="description" id="description" class="text-input form-field__control" value="<%= $c->stash->{record}{description} %>" placeholder="" /> + </div> +</form> +</div> + +<button class="btn col-span-2 text-lg max-w-full btn--black-100" id="buttonSave"> + <div class="btn__body ">Uložit</div> +</button> +<button class="btn col-span-2 text-lg max-w-full btn--black-100" id="buttonDownload"> + <div class="btn__body "><a href="<%= $c->stash->{record}{path} %>">Stahnout</a></div> +</button> +% if ( $c->stash->{record}{is_deletable} ) { +<button class="btn col-span-2 text-lg max-w-full btn--red-100" id="buttonDelete"> + <div class="btn__body ">Smazat</div> +</button> +% } + +</div> + +% } +<script> +$(function() { + $('#buttonSave').on('click', function (e) { + var data = $("form").serialize(); + $.ajax({ + method: 'put', + data: data, + url: '/api/records/<%= $c->stash->{record}{id} %>', + success: function(rc) { + console.log('updated'); + } + }); + }); + + $('#buttonDelete').on('click', function (e) { + $.ajax({ + method: 'delete', + url: '/api/records/<%= $c->stash->{record}{id} %>', + success: function(rc) { + window.location.href ='/archive/'; + } + }); + }); +}) +</script>