Skip to content

Commit

Permalink
Merge pull request #1339 from DFE-Digital/ER-1219-add-updated-and-pub…
Browse files Browse the repository at this point in the history
…lished-date

Er 1219 add updated and published date
  • Loading branch information
David-Feetenby authored Sep 27, 2024
2 parents 6d7d172 + 8dafb1f commit 6605dd5
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $light-blue: tint(govuk-organisation-colour('department-for-education'), 90%);
@import 'icons';
@import 'autocomplete';
@import 'assets-page';
@import 'timestamp';

// training/modules#show
@import 'progress-bar';
Expand Down
82 changes: 82 additions & 0 deletions app/assets/stylesheets/timestamp.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
.timestamp {
background: govuk-colour('light-grey');
padding: govuk-spacing(3) govuk-spacing(2) govuk-spacing(3) govuk-spacing(4);
margin-top: 60px;
border-left: govuk-spacing(1) solid govuk-organisation-colour('department-for-education');

-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-weight: 400;
font-size: 14px;
font-size: .875rem;
line-height: 1.1429;

@include govuk-media-query($from: tablet) {
font-size:16px;
font-size: 1rem;
line-height: 1.25;

a {
font-family: sans-serif;
}
}

a {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-decoration: underline;
font-weight: bold;
color: govuk-colour('black');
}

&.timestamp::after {
content: '';
display: block;
clear: both;
}

&__toggle-wrap {
display: none;
}

dl {
margin: 0;
}

dt {
box-sizing: border-box;
float: left;
clear: left;
padding-right: 5px;
margin-top: 0;
}

dd {
margin: 0;
}
}

.timestamp .timestamp__definition-link {
font-weight: normal;
}

@media print {
.timestamp {
color: govuk-colour('black');
font-family: sans-serif;
font-size: 14pt;
line-height: 1.2;
}
}

.js-enabled {
.timestamp__toggle-wrap {
display: block;
}

.timestamp__toggle-items {
.js-hidden {
display: none;
}
}
}
3 changes: 2 additions & 1 deletion app/helpers/date_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module DateHelper
# @param datetime [DateTime]
# @return [String]
def certificate_date(datetime)
def format_date(datetime)
datetime.to_date.strftime('%-d %B %Y')
end
end
22 changes: 22 additions & 0 deletions app/models/training/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ def parent
@parent ||= Training::Module.by_content_id(id)
end

# @return [Boolean]
def edited?
if Rails.application.preview?
created_at < updated_at
elsif published_at.present?
published_at < updated_at
else
false
end
end

# @return [DateTime, nil]
def published_at
module_release&.first_published_at
end

# @param mod [Course, Training::Module]
# @return [Training::Page, Training::Video, Training::Question]
def with_parent(mod)
Expand Down Expand Up @@ -69,5 +85,11 @@ def notes?
def skippable?
false
end

private

def module_release
ModuleRelease.find_by(module_position: parent.position)
end
end
end
2 changes: 1 addition & 1 deletion app/views/notes/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
= form_with(model: note, url: user_notes_path) do |f|
.govuk-grid-row
.govuk-grid-row class='govuk-!-margin-top-4'
.govuk-grid-column-three-quarters
.prompt
.govuk-grid-row
Expand Down
8 changes: 8 additions & 0 deletions app/views/training/pages/_timestamp.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- if !content.published_at.nil?
.timestamp
dl
dt Published:
dd = format_date(content.published_at)
- if content.edited?
dt Updated:
dd = format_date(content.updated_at)
2 changes: 1 addition & 1 deletion app/views/training/pages/certificate.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
h2.govuk-heading-m= mod.title

- if module_progress.completed?
p#certificate-date= t 'date_completed', date: certificate_date(module_progress.completed_at)
p#certificate-date= t 'date_completed', date: format_date(module_progress.completed_at)

p.description This module has covered:

Expand Down
2 changes: 2 additions & 0 deletions app/views/training/pages/section_intro.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
.govuk-button-group
= link_to_previous
= link_to_next

= render 'timestamp'
1 change: 1 addition & 0 deletions app/views/training/pages/text_page.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
h1.govuk-heading-l= content.heading

= m(content.body)
= render 'timestamp'

= render 'debug'
= render 'content'
1 change: 1 addition & 0 deletions app/views/training/pages/video_page.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
| Transcript

= m(content.transcript)
= render 'timestamp'

= render 'debug'
= render 'content'
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ h1.govuk-heading-l Learning check
.govuk-grid-column-three-quarters
h2.govuk-heading-m Check your understanding

div class='govuk-!-margin-4'
div class='govuk-!-margin-top-4'
= m(content.legend)

= f.govuk_check_boxes_fieldset :answers, legend: { text: content.legend, hidden: true } do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ h1.govuk-heading-l Learning check
.govuk-grid-column-three-quarters
h2.govuk-heading-m Check your understanding

div class='govuk-!-margin-4'
div class='govuk-!-margin-top-4'
= m(content.legend)

= f.govuk_radio_buttons_fieldset :answers, legend: { text: content.legend, hidden: true } do
Expand Down
3 changes: 2 additions & 1 deletion app/views/training/questions/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

- if content.formative_question? && current_user_response.responded?
#formative-results= render 'assessment_banner'

- if content.formative_question?
= render 'training/pages/timestamp'
.govuk-grid-row
.govuk-grid-column-full

Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/date_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'rails_helper'

describe 'DateHelper' do
describe '#certificate_date' do
describe '#format_date' do
let(:input) { Time.zone.local(2001, 2, 3, 4, 5, 6) }

it 'returns date in format "Day(in numbers) Month(in words) Year(in numbers)" format' do
expect(helper.certificate_date(input)).to eq '3 February 2001'
expect(helper.format_date(input)).to eq '3 February 2001'
end
end
end
2 changes: 2 additions & 0 deletions spec/models/training/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
described_class.find_by(name: '1-1-1-1').first
end

it_behaves_like 'updated content', '1-1-3'

# describe 'CMS fields' do
# end

Expand Down
2 changes: 2 additions & 0 deletions spec/models/training/question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
described_class.find_by(name: '1-1-4-1').first
end

it_behaves_like 'updated content', '1-2-1-1'

describe '#parent' do
it 'returns the parent module' do
expect(question.parent).to be_a Training::Module
Expand Down
2 changes: 2 additions & 0 deletions spec/models/training/video_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
described_class.find_by(name: '1-2-1-2').first
end

it_behaves_like 'updated content', '1-2-1-2'

describe '#parent' do
it 'returns the parent module' do
expect(video.parent).to be_a Training::Module
Expand Down
44 changes: 44 additions & 0 deletions spec/support/shared/updated_content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
RSpec.shared_examples 'updated content' do |name|
let(:mod) { Training::Module.by_name(:alpha) }
let(:content) { mod.page_by_name(name) }

describe '#edited?' do
context 'when preview' do
# make Rails.application.preview? return true
it do
allow(Rails.application).to receive(:preview?).and_return(true)
expect(content).to be_edited unless content.content_type.id.eql?('video')
end
end

context 'when delivery' do
it do
create(:module_release, first_published_at: Time.zone.local(2023, 1, 1))
expect(content).to be_edited
end

it do
create(:module_release, first_published_at: Time.zone.local(3_099, 1, 1))
expect(content).not_to be_edited
end
end
end

describe '#published_at' do
context 'when unpublished' do
it do
expect(content.published_at).to be_nil
end
end

context 'when published' do
before do
create(:module_release, first_published_at: Time.zone.local(2023, 1, 1))
end

it do
expect(content.published_at.to_s).to eq '2023-01-01 00:00:00 UTC'
end
end
end
end

0 comments on commit 6605dd5

Please sign in to comment.