diff --git a/lib/Brass.pm b/lib/Brass.pm index fec65e7..613e7df 100644 --- a/lib/Brass.pm +++ b/lib/Brass.pm @@ -825,6 +825,22 @@ any ['get', 'post'] => '/docread' => require_role doc => sub { }; }; +any ['get', 'post'] => '/docreadstatus' => require_role user_admin => sub { + + my $schema = schema; + my $docschema = schema('doc'); + + my @doc_ids = map $_->doc_id, $schema->resultset('DocDocreadtype')->all; + my $docs = $docschema->resultset('Doc')->active->search({ + id => \@doc_ids, + }); + template 'docreadstatus' => { + docs => [$docs->all], + users => [$schema->resultset('User')->active->docread->all], + page => 'docread', + }; +}; + get '/doc' => require_role doc => sub { my $schema = schema('doc'); diff --git a/lib/Brass/DocSchema/Result/Doc.pm b/lib/Brass/DocSchema/Result/Doc.pm index 0a831f6..613039d 100644 --- a/lib/Brass/DocSchema/Result/Doc.pm +++ b/lib/Brass/DocSchema/Result/Doc.pm @@ -188,6 +188,7 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +# Last read date for a particular user sub last_read { my ($self, $user) = @_; my $lr = $user->docreads->search({ @@ -197,7 +198,15 @@ sub last_read rows => 1, })->next or return; - $lr->datetime; + my $dt = $lr->datetime; + my $expiry = DateTime->now->subtract(years => 1); + my $status = $dt > $expiry->clone->add(months => 1) ? 'success' + : $dt > $expiry ? 'warning' + : 'danger'; + { + date => $dt, + status => $status, + } } 1; diff --git a/lib/Brass/DocSchema/ResultSet/Doc.pm b/lib/Brass/DocSchema/ResultSet/Doc.pm new file mode 100644 index 0000000..68c7fd1 --- /dev/null +++ b/lib/Brass/DocSchema/ResultSet/Doc.pm @@ -0,0 +1,26 @@ +package Brass::DocSchema::ResultSet::Doc; + +use strict; +use warnings; + +use Log::Report; + +use base qw(DBIx::Class::ResultSet); + +sub active +{ my $self = shift; + + $self->search_rs({ + retired => undef, + },{ + order_by => 'me.title', + }); +} + +sub required_reading +{ my $self = shift; + $self->active->search_rs({ + }); +} + +1; diff --git a/lib/Brass/Schema/Result/Docreadtype.pm b/lib/Brass/Schema/Result/Docreadtype.pm index 69e9b4f..23fa63f 100644 --- a/lib/Brass/Schema/Result/Docreadtype.pm +++ b/lib/Brass/Schema/Result/Docreadtype.pm @@ -26,7 +26,7 @@ __PACKAGE__->has_many( __PACKAGE__->has_many( "doc_docreadtypes", - "Brass::Schema::Result::UserDocreadtype", + "Brass::Schema::Result::DocDocreadtype", { "foreign.docreadtype_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); diff --git a/lib/Brass/Schema/Result/User.pm b/lib/Brass/Schema/Result/User.pm index 2ebabaf..ca28c28 100644 --- a/lib/Brass/Schema/Result/User.pm +++ b/lib/Brass/Schema/Result/User.pm @@ -422,6 +422,11 @@ sub has_docreadtype (grep { $_->docreadtype_id == $docreadtype_id } $self->user_docreadtypes) ? 1 : 0; } +sub must_read_doc +{ my ($self, $doc_id) = @_; + (grep { $_->docreadtype->doc_docreadtypes->search({doc_id => $doc_id})->count } $self->user_docreadtypes) ? 1 : 0; +} + sub servertypes_as_string { my $self = shift; join ', ', map $_->servertype->name, $self->user_servertypes->all; diff --git a/lib/Brass/Schema/ResultSet/User.pm b/lib/Brass/Schema/ResultSet/User.pm index bab3873..020eef4 100644 --- a/lib/Brass/Schema/ResultSet/User.pm +++ b/lib/Brass/Schema/ResultSet/User.pm @@ -18,6 +18,16 @@ sub active }); } +sub docread +{ my $self = shift; + $self->search_rs({ + 'user_docreadtypes.id' => { '!=' => undef }, + },{ + join => 'user_docreadtypes', + collapse => 1, + }); +} + sub keys { my $self = shift; $self->search_rs({ diff --git a/views/docreadstatus.tt b/views/docreadstatus.tt new file mode 100644 index 0000000..2bf833f --- /dev/null +++ b/views/docreadstatus.tt @@ -0,0 +1,28 @@ +

Document reading status

+ + + + + [% FOREACH user IN users %] + + [% END %] + + [% FOREACH doc IN docs %] + + + + [% FOREACH user IN users %] + [% IF user.must_read_doc(doc.id) %] + [% lr = doc.last_read(user) %] + [% IF lr %] + + [% ELSE %] + + [% END %] + [% ELSE %] + + [% END %] + [% END %] + + [% END %] +
IDTitle[% user.name | html %]
[% doc.id %][% doc.title | html %][% lr.date.ymd | html %]Not yet readNope
diff --git a/views/layouts/main.tt b/views/layouts/main.tt index d5da9cb..2f9bd99 100644 --- a/views/layouts/main.tt +++ b/views/layouts/main.tt @@ -50,6 +50,9 @@