diff --git a/lib/GADS/Datum.pm b/lib/GADS/Datum.pm index 03adaa040..8555ddfd6 100644 --- a/lib/GADS/Datum.pm +++ b/lib/GADS/Datum.pm @@ -294,5 +294,28 @@ sub date_for_code }; } +has schema => ( + is => 'lazy', + builder => sub { shift->record->schema }, +); + +sub _rs +{ my $self = shift; + return if $self->column->internal; + $self->schema->resultset($self->column->table)->search({ + record_id => $self->record_id, + layout_id => $self->column->id, + },{ + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + }); +} + +sub is_purged +{ my $self = shift; + my $rs = $self->_rs or return 0; + my @all = $rs->all or return 0; + !!(grep { defined $_->{purged_by} && $_->{purged_by} } @all); +} + 1; diff --git a/lib/GADS/Datum/File.pm b/lib/GADS/Datum/File.pm index 0a3f1d3b2..ece8d4899 100644 --- a/lib/GADS/Datum/File.pm +++ b/lib/GADS/Datum/File.pm @@ -66,13 +66,18 @@ after set_value => sub { if (@values == 1 && @old == 1) { my $old_value = $self->schema->resultset('Fileval')->find($old[0]); # Only do one fetch here - my $old_content = $old_value->content; - my $old_name = $old_value->name; - if(my $fl = $self->schema->resultset('Fileval')->search({ - id => $values[0], - name => $old_name - })->next) { - $changed = 0 if $fl && $fl->content eq $old_content; + # Fix - if the data is originally purged, then the fileval record will have been deleted, so we need to account for that + my $old_content = $old_value ? $old_value->content : undef; + my $old_name = $old_value ? $old_value->name : undef; + if (defined $old_content && defined $old_name) { + if(my $fl = $self->schema->resultset('Fileval')->search({ + id => $values[0], + name => $old_name + })->next) { + $changed = 0 if $fl && $fl->content eq $old_content; + } + } else { + $changed = 1; } } } @@ -167,20 +172,6 @@ sub _build_files return \@return; } -sub _files_rs -{ my $self = shift; - [$self->schema->resultset('File')->search({ - record_id => $self->record_id, - layout_id => $self->column->id, - })->all]; -} - -sub is_purged { - my $self = shift; - my @files = @{$self->_files_rs}; - return grep { $_->is_purged } @files; -} - sub _ids_to_files { my ($self, @ids) = @_; map { diff --git a/lib/GADS/Role/Presentation/Datum/Enum.pm b/lib/GADS/Role/Presentation/Datum/Enum.pm index f11cb7732..09a42274a 100644 --- a/lib/GADS/Role/Presentation/Datum/Enum.pm +++ b/lib/GADS/Role/Presentation/Datum/Enum.pm @@ -9,6 +9,7 @@ sub presentation { $base->{id_hash} = $self->id_hash; $base->{deleted_values} = $self->deleted_values; + $base->{purged} = $self->is_purged; return $base; } diff --git a/lib/GADS/Role/Presentation/Datum/File.pm b/lib/GADS/Role/Presentation/Datum/File.pm index 9e036cb2d..2c5a491f4 100644 --- a/lib/GADS/Role/Presentation/Datum/File.pm +++ b/lib/GADS/Role/Presentation/Datum/File.pm @@ -8,6 +8,7 @@ sub presentation { my $base = $self->presentation_base; $base->{files} = $self->files; + $base->{purged} = $self->is_purged; return $base; } diff --git a/lib/GADS/Role/Presentation/Datum/Person.pm b/lib/GADS/Role/Presentation/Datum/Person.pm index ca3da85e6..842619a6d 100644 --- a/lib/GADS/Role/Presentation/Datum/Person.pm +++ b/lib/GADS/Role/Presentation/Datum/Person.pm @@ -46,6 +46,7 @@ sub presentation { $base->{value} = $self->as_string; $base->{details} = [map $self->_presentation_details($_, %options), @{$self->value_hash}]; $base->{ids} = $self->ids; + $base->{purged} = $self->is_purged; return $base; } diff --git a/lib/GADS/Role/Presentation/Datum/String.pm b/lib/GADS/Role/Presentation/Datum/String.pm index 3bf0f9a02..8ba4077f7 100644 --- a/lib/GADS/Role/Presentation/Datum/String.pm +++ b/lib/GADS/Role/Presentation/Datum/String.pm @@ -20,6 +20,7 @@ sub presentation { $base->{raw} = $raw; $base->{html} = $html; + $base->{purged} = $self->is_purged; return $base; } diff --git a/lib/GADS/Role/Presentation/Datum/Tree.pm b/lib/GADS/Role/Presentation/Datum/Tree.pm index 72d8915bd..b9da2ab6e 100644 --- a/lib/GADS/Role/Presentation/Datum/Tree.pm +++ b/lib/GADS/Role/Presentation/Datum/Tree.pm @@ -9,6 +9,7 @@ sub presentation { $base->{ids} = $self->ids; $base->{ids_as_params} = $self->ids_as_params; + $base->{purged} = $self->is_purged; return $base; } diff --git a/lib/GADS/Role/Presentation/Record.pm b/lib/GADS/Role/Presentation/Record.pm index 155d65440..24cd20525 100644 --- a/lib/GADS/Role/Presentation/Record.pm +++ b/lib/GADS/Role/Presentation/Record.pm @@ -81,6 +81,8 @@ sub presentation { my @presentation_columns = $self->presentation_map_columns(%options, columns => \@columns); my @topics= $self->get_topics(\@presentation_columns); + my $has_purged = !!(grep { defined $_->{data}->{purged} && $_->{data}->{purged} } map { @{$_->{columns}} } @topics); + my $version_datetime_col = $self->layout->column_by_name_short('_version_datetime'); my $created_user_col = $self->layout->column_by_name_short('_created_user'); my $created_datetime_col = $self->layout->column_by_name_short('_created'); @@ -101,6 +103,7 @@ sub presentation { has_rag_column => !!(grep { $_->type eq 'rag' } @columns), new_entry => $self->new_entry, is_draft => $self->is_draft, + has_purged => $has_purged, }; if ($options{edit}) diff --git a/views/edit.tt b/views/edit.tt index e99bceac4..c8b988aab 100755 --- a/views/edit.tt +++ b/views/edit.tt @@ -7,6 +7,15 @@ %]
+ [% IF record.has_purged %] +
+
+ +
+
+ [% END %]
- [% IF editable AND NOT record.new_entry AND NOT edit_modal AND topic.has_editable %] + [% IF editable AND NOT record.new_entry AND NOT edit_modal AND topic.has_editable AND NOT record.has_purged %]