diff --git a/lib/GADS.pm b/lib/GADS.pm
index 9592bb03b..f7ddc0711 100644
--- a/lib/GADS.pm
+++ b/lib/GADS.pm
@@ -60,6 +60,7 @@ use GADS::Record;
use GADS::Records;
use GADS::RecordsGraph;
use GADS::SAML;
+use GADS::SchemaInstance;
use GADS::Type::Permissions;
use GADS::Users;
use GADS::Util;
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/Date.pm b/lib/GADS/Datum/Date.pm
index 0f8ab3bc1..675d2b94c 100644
--- a/lib/GADS/Datum/Date.pm
+++ b/lib/GADS/Datum/Date.pm
@@ -18,7 +18,6 @@ along with this program. If not, see .
package GADS::Datum::Date;
-use GADS::SchemaInstance;
use DateTime;
use DateTime::Format::DateManip;
use Log::Report 'linkspace';
@@ -29,14 +28,6 @@ use namespace::clean;
extends 'GADS::Datum';
with 'GADS::DateTime';
-has schema => (
- is => 'ro',
- lazy => 1,
- builder => sub {
- GADS::SchemaInstance->instance;
- },
-);
-
after set_value => sub {
my ($self, $all, %options) = @_;
$all ||= [];
diff --git a/lib/GADS/Datum/Daterange.pm b/lib/GADS/Datum/Daterange.pm
index 100d2a5ec..e35a99e5b 100644
--- a/lib/GADS/Datum/Daterange.pm
+++ b/lib/GADS/Datum/Daterange.pm
@@ -21,7 +21,6 @@ package GADS::Datum::Daterange;
use DateTime;
use DateTime::Format::DateManip;
use DateTime::Span;
-use GADS::SchemaInstance;
use Log::Report 'linkspace';
use Moo;
use MooX::Types::MooseLike::Base qw/ArrayRef/;
@@ -30,14 +29,6 @@ extends 'GADS::Datum';
with 'GADS::DateTime';
-has schema => (
- is => 'ro',
- lazy => 1,
- builder => sub {
- GADS::SchemaInstance->instance;
- },
-);
-
# Set datum value with value from user
after set_value => sub {
my ($self, $all, %options) = @_;
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.pm b/lib/GADS/Role/Presentation/Datum.pm
index 01b32194c..0679bce65 100644
--- a/lib/GADS/Role/Presentation/Datum.pm
+++ b/lib/GADS/Role/Presentation/Datum.pm
@@ -6,7 +6,7 @@ sub presentation { shift->presentation_base(@_) } # Default, overridden
sub presentation_base {
my ($self, %options) = @_;
- return {
+ my $return = {
type => $options{type} || ($self->isa('GADS::Datum::Count') ? 'count' : $self->column->type),
value => $self->as_string,
has_value => $self->has_value,
@@ -18,6 +18,10 @@ sub presentation_base {
column_id => $self->column && $self->column->id,
column_name => $self->column && $self->column->name,
};
+ if ($self->can('is_purged')) {
+ $return->{purged} = $self->is_purged;
+ }
+ return $return;
}
1;
diff --git a/lib/GADS/Role/Presentation/Record.pm b/lib/GADS/Role/Presentation/Record.pm
index 155d65440..823e6dbc7 100644
--- a/lib/GADS/Role/Presentation/Record.pm
+++ b/lib/GADS/Role/Presentation/Record.pm
@@ -81,6 +81,12 @@ 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 +107,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/lib/GADS/Role/Purgable.pm b/lib/GADS/Role/Purgable.pm
index 9e41aedfd..9b5461405 100644
--- a/lib/GADS/Role/Purgable.pm
+++ b/lib/GADS/Role/Purgable.pm
@@ -3,6 +3,8 @@ package GADS::Role::Purgable;
use strict;
use warnings;
+use Log::Report;
+
use MooX::Types::MooseLike::Base qw(ArrayRef);
use Moo::Role;
@@ -10,7 +12,9 @@ use Moo::Role;
has value_fields => (
is => 'lazy',
isa => ArrayRef,
- builder => sub { ['value']; }
+ builder => sub {
+ ['value'];
+ }
);
sub is_purged {
diff --git a/lib/GADS/Schema/Result/Calcval.pm b/lib/GADS/Schema/Result/Calcval.pm
index 605e674c7..eedf9fc04 100644
--- a/lib/GADS/Schema/Result/Calcval.pm
+++ b/lib/GADS/Schema/Result/Calcval.pm
@@ -72,5 +72,6 @@ sub sqlt_deploy_hook {
}
sub _build_valuefield { ('value_text','value_numeric','value_int','value_date','value_date_from','value_date_to'); }
+sub _build_value_fields { ['value_text','value_numeric','value_int','value_date','value_date_from','value_date_to'] }
1;
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 %]
+
+
+
+ This record has been archived. You can view the version history of the record to see its previous values, but you cannot edit or restore the record.
+
+
+
+ [% END %]