diff --git a/app/models/solr_document.rb b/app/models/solr_document.rb
index ce473891..0535d5bf 100644
--- a/app/models/solr_document.rb
+++ b/app/models/solr_document.rb
@@ -70,8 +70,14 @@ def parse_note_paragraphs(notes)
# Sometimes note paragraphs are returned as a simple JSON string, and other times, as an array.
# Ensure we always have an array by wrapping the paragraphs in an array, then flatten the array,
# so we only return a single dimensional array of paragraphs.
- notes.map! { |note| Array.wrap(JSON.parse(note)["p"]) }
- .flatten!
+ notes.map! { |note|
+ json_note = JSON.parse(note)
+ extracted_notes = Array.wrap(json_note["p"])
+ if json_note["chronlist"].present? && json_note["chronlist"]["head"].present?
+ extracted_notes += Array.wrap({chronlist: json_note["chronlist"]})
+ end
+ extracted_notes
+ }.compact.flatten
end
def wrap_paragraphs_in_html(paragraphs)
diff --git a/app/presenters/rendering/chronlist.rb b/app/presenters/rendering/chronlist.rb
index 38b0c415..c859e827 100644
--- a/app/presenters/rendering/chronlist.rb
+++ b/app/presenters/rendering/chronlist.rb
@@ -2,6 +2,8 @@
module Rendering
class Chronlist < Blacklight::Rendering::AbstractStep
+ DEFAULT_HEADERS = %w[Date Event]
+
def render
next_step(render_chronlist)
end
@@ -9,20 +11,28 @@ def render
private
def render_chronlist
- header_keys = []
- values["listhead"].each do |header|
- header_keys << header[1].downcase
+ col_headers = []
+ if values["listhead"].present?
+ values["listhead"].each { |header| col_headers << header[1] }
+ else
+ col_headers = DEFAULT_HEADERS
end
fragment = Nokogiri::HTML::DocumentFragment.parse("")
Nokogiri::HTML::Builder.with(fragment) do |doc|
+ if values["head"].present?
+ doc.h3 {
+ doc.text values["head"]
+ }
+ end
+
doc.table(class: "table table-light table-responsive table-striped table-hover") do
doc.thead(class: "table-purple") {
doc.tr {
- header_keys.each do |header|
+ col_headers.each do |header|
doc.th {
- doc.text header.titleize
+ doc.text header
}
end
}
@@ -31,14 +41,28 @@ def render_chronlist
doc.tbody(class: "table-group-divider") {
values["chronitem"].map! do |item|
doc.tr {
- header_keys.each do |key|
- doc.td(class: (key == "date") ? "text-nowrap" : "") {
- # sometimes the value contains a calendar element
- if item[key].is_a?(Hash)
- doc.text item[key]["content"]
- else
- doc.text item[key]
- end
+ doc.td(class: "text-nowrap") {
+ # sometimes the value contains a calendar element
+ if item["date"].is_a?(Hash)
+ doc.text item["date"]["content"]
+ else
+ doc.text item["date"]
+ end
+ }
+
+ if item["eventgrp"].present?
+ doc.td {
+ doc.ul(class: "list-unstyled") {
+ Array.wrap(item["eventgrp"]["event"]).map! do |event|
+ doc.li do |list_item|
+ list_item << event
+ end
+ end
+ }
+ }
+ else
+ doc.td {
+ doc.text item["event"]
}
end
}
diff --git a/app/presenters/rendering/table.rb b/app/presenters/rendering/table.rb
index 7d435d81..6ea71f81 100644
--- a/app/presenters/rendering/table.rb
+++ b/app/presenters/rendering/table.rb
@@ -26,7 +26,7 @@ def render_table
doc.tbody(class: "table-group-divider") {
values["tgroup"]["tbody"]["row"].map! do |row|
doc.tr {
- row["entry"]&.map! do |entry|
+ row["entry"].map! do |entry|
doc.td {
doc.text entry
}
diff --git a/spec/files/notes/chronlist_no-header_eventgrp.json b/spec/files/notes/chronlist_no-header_eventgrp.json
new file mode 100644
index 00000000..6bd07916
--- /dev/null
+++ b/spec/files/notes/chronlist_no-header_eventgrp.json
@@ -0,0 +1,58 @@
+{
+ "chronlist": {
+ "head": "Honours and Awards",
+ "chronitem": [
+ {
+ "date": 1965,
+ "eventgrp": {
+ "event": "The Queen Elizabeth Award - Royal Academy of Dancing, London"
+ }
+ },
+ {
+ "date": 1966,
+ "eventgrp": {
+ "event": "Order of the British Empire (OBE) for services to ballet"
+ }
+ },
+ {
+ "date": 1970,
+ "eventgrp": {
+ "event": "Dame Commander of the Order of the British Empire (DBE) for services to ballet"
+ }
+ },
+ {
+ "date": 1970,
+ "eventgrp": {
+ "event": "Encyclopaedia Britannica (Australia) Award for the Arts"
+ }
+ },
+ {
+ "date": 1974,
+ "eventgrp": {
+ "event": "Doctor of Letters (Honoris Causa) University of New England"
+ }
+ },
+ {
+ "date": 1975,
+ "eventgrp": {
+ "event": "Distinguished Artist Award from the Australia Council"
+ }
+ },
+ {
+ "date": 1981,
+ "eventgrp": {
+ "event": "Doctor of Laws (Honoris Causa) Melbourne University"
+ }
+ },
+ {
+ "date": 1981,
+ "eventgrp": {
+ "event": [
+ "Dummy 1",
+ "Dummy 2"
+ ]
+ }
+ }
+ ]
+ }
+}
diff --git a/spec/models/solr_document_spec.rb b/spec/models/solr_document_spec.rb
index 6a1f87a2..df6adc1a 100644
--- a/spec/models/solr_document_spec.rb
+++ b/spec/models/solr_document_spec.rb
@@ -209,7 +209,7 @@
end
end
- context "when note doesn't contains a chronlist" do
+ context "when chronlist is outside of the Text subnote" do
subject(:notes_value) do
document.extract_notes_by_header("biog")
end
@@ -217,16 +217,13 @@
let(:document) {
described_class.new(
note_json_ssm: [
- "{\"head\":\"Biographical Note\",\"p\":{\"chronlist\":{\"listhead\":{\"head01\":\"Date\",\"head02\":\"Event\"},\"chronitem\":[{\"date\":1925,\"event\":\"Born in Yarram, Victoria, on 26 October\"},{\"date\":\"1942-1943\",\"event\":\"Student teacher, Department of Education, Victoria\"},{\"date\":\"1943-1946\",\"event\":\"Navigator, Royal Australian Air Force\"},{\"date\":1948,\"event\":\"Bachelor of Arts (Honours), University of Melbourne\"},{\"date\":\"1949-1951\",\"event\":\"Tutor in History, University of Melbourne\"},{\"date\":1951,\"event\":\"Master of Arts (Honours), University of Melbourne\"},{\"date\":\"\",\"event\":\"Inaugural Archbishop Mannix Travelling Scholar\"},{\"date\":\"1951-1953\",\"event\":\"Australian National University Research Scholar, University of Cambridge\"},{\"date\":1953,\"event\":\"Bachelor of Arts, University of Cambridge\"},{\"date\":\"1953-1958\",\"event\":\"Lecturer in History, University of Melbourne\"},{\"date\":\"1959-1964\",\"event\":\"Senior Lecturer in History, University of Melbourne\"},{\"date\":1960,\"event\":\"Master of Arts, University of Cambridge\"},{\"date\":1961,\"event\":\"Foundation Member, Australian Institute of Aboriginal Studies\"},{\"date\":\"\",\"event\":\"Nuffield Foundation Dominion Fellow, Institute of Archaeology (London)\"},{\"date\":1963,\"event\":\"Royal Society of Victoria Research Medal\"},{\"date\":\"1964-1980\",\"event\":\"Council Member, Australian Institute of Aboriginal Studies\"},{\"date\":\"1965-1970\",\"event\":\"Senior Fellow in Prehistory, Research School of Pacific Studies, Australian National University\"},{\"date\":\"1965-1976\",\"event\":\"Executive Member, Australian Institute of Aboriginal Studies\"},{\"date\":1969,\"event\":\"Australian Literature Society Dame Mary Gilmore Medal\"},{\"date\":1970,\"event\":\"Doctor of Philosophy, University of Cambridge\"},{\"date\":\"\",\"event\":\"Fellow, Australian Academy of the Humanities\"},{\"date\":1971,\"event\":\"Acting Principal, Australian Institute of Aboriginal Studies\"},{\"date\":\"1971-1985\",\"event\":\"Foundation Professor of Prehistory, Faculty of Arts, Australian National University\"},{\"date\":\"1972-1974\",\"event\":\"Council Member, Australian Academy of the Humanities\"},{\"date\":\"1972-1976\",\"event\":\"Deputy Chairman, Australian Institute of Aboriginal Studies\"},{\"date\":\"1974-1975\",\"event\":\"Member, Committee of Inquiry into Museums and National Collections\"},{\"date\":1975,\"event\":\"Chairman, Planning Committee, Gallery of Aboriginal Australia\"},{\"date\":\"1975-1976\",\"event\":\"Deputy Chairman, Museums Association, Canberra Division\"},{\"date\":\"1976-1977\",\"event\":\"Commonwealth Visiting Professor, University of Cambridge\"},{\"date\":\"1976-1982\",\"event\":\"Australian Heritage Commissioner\"},{\"date\":1977,\"event\":\"Fellow, Society of Antiquaries of London\"},{\"date\":1981,\"event\":\"President, Section 25A (Archaeology), ANZAAS Conference\"},{\"date\":\"1981-1983\",\"event\":\"Member, Interim Council of the Museum of Australia\"},{\"date\":1982,\"event\":\"Companion of the Order of St Michael and St George\"},{\"date\":\"1982-1984\",\"event\":\"Chairman, Australian Institute of Aboriginal Studies\"},{\"date\":1983,\"event\":\"Corresponding Fellow of the British Academy\"},{\"date\":\"1984-1985\",\"event\":\"Visiting Professor in Australian Studies, Harvard University\"},{\"date\":1985,\"event\":\"Whitely Book Award for biography, Royal Zoological Society (NSW)\"},{\"date\":1986,\"event\":\"Emeritus Professor of Prehistory, Australian National University\"},{\"date\":1986,\"event\":\"Honorary Member, Australian Archaeological Association\"},{\"date\":\"\",\"event\":\"Victorian Premier's Literary Award for Australian Studies (with J. H. Calaby)\"},{\"date\":\"1986-1988\",\"event\":\"Chairman, ACT Heritage Committee\"},{\"date\":\"1986-1990\",\"event\":\"Honorary Fellow, Department of History, Research School of Pacific Studies, Australian National University\"},{\"date\":\"1987-1990\",\"event\":\"Honorary Fellow, Museum of Victoria\"},{\"date\":1988,\"event\":\"ANZAAS Medal\"},{\"date\":\"1989-1992\",\"event\":\"Member, Editorial Board, Australian Institute of Aboriginal Studies\"},{\"date\":\"1989-1996\",\"event\":\"Secretary, Australian Academy of the Humanities\"},{\"date\":1990,\"event\":\"Honorary Member, Indo-Pacific Prehistory Association\"},{\"date\":\"\",\"event\":\"Honorary Member, Prehistoric Society (London)\"},{\"date\":1991,\"event\":\"Order of Australia\"},{\"date\":1996,\"event\":\"Honorary Fellow, Royal Anthropological Institute\"},{\"date\":\"1997-1998\",\"event\":\"Ashley Fellow, Trent University (Canada)\"},{\"date\":1999,\"event\":\"Grahame Clark Medal, British Academy\"},{\"date\":2001,\"event\":\"Australian Centenary Medal\"},{\"date\":2004,\"event\":\"Rhys Jones Medal, Australian Archaeological Association\"}]},\"bibref\":\"Prehistory to Politics : John Mulvaney, the humanities and the public intellectual, edited by Tim Bonyhady and Tom Griffiths. Carlton South, Victoria : Melbourne University Press, 1996.\"}}"
+ "{\"head\":\"Biographical Note\",\"p\":[\"Margaret (Peggy) van Praagh was born in London in 1910. Her father, Harold John van Praagh, a doctor of Dutch-Jewish descent had established a successful practice in the Hampstead district.\",\"In 1916, while on summer holidays in Paignton, Devon, van Praagh appeared in a children's talent competition. She won first prize and was invited back to appear in the evening performance along with professional actors. In August of 1917, she appeared at the Torquay Pavilion and received her first press notice.\",\"From the age of seven she attended King Alfred School, Hampstead, where she was to complete her formal education and develop her creative talents. She combined her lessons in dancing with private lessons in piano and elocution. On finishing school van Praagh decided to commit herself to a life of dance.\",\"She continued training and in 1930 opened her first dance school. Around this time she began studying with Margaret Craske who introduced her to the Cecchetti Method of dance. She began studying and taking exams and became a qualified teacher of the Cecchetti Method.\",\"In 1933, she was invited by Marie Rambert to join her company, the Ballet Club, (later Ballet Rambert) which at that time was giving Sunday night performances at the small Mercury Theatre in London. The dancers were not paid for these performances and so van Praagh supported herself by teaching ballet to children. She remained with the Ballet Rambert until 1938, and was then a principal with the London Ballet in 1938-1940. In wartime London, ballet had to struggle to survive. London's famous lunch-hour series 'Ballet for a Bob' by the London Ballet was her brainchild.\",\"In 1941 van Praagh joined the Sadler's Wells Ballet. Her most notable roles with the company included Swanilda in Coppelia and the Blue Girl in Les Patineurs. She was also assigned to take company classes as well as private lessons to the principals who at that time included Margot Fonteyn, Robert Helpmann and Moira Shearer.\",\"In 1946 the Sadler's Wells Trust formed a second company known as the Sadler's Wells Theatre Ballet. Van Praagh became the company's Ballet Mistress and Producer. In 1951 she was appointed Assistant Director to Ninette de Valois and remained in this capacity until December 1956. During this period the company toured Great Britain, Europe, Rhodesia and South Africa in addition to giving its regular London seasons.\",\"On leaving the company, at the end of 1956, she became a freelance teacher, lecturer and producer of British ballet overseas. She produced Ninette de Valois' The rake's progress in Munich for the Bavarian State Opera Company, Frederick Ashton's Les rendevous for the National Ballet of Canada, The sleeping beauty for the Royal Danish Ballet in Copenhagen and Tudor's Gala performance for the Royal Swedish Ballet in Stockholm.\",\"In 1958 she became Dance Director for the Edinburgh Festival Ballet, which appeared at the Festival in August of that year. In a three week season, twelve new ballets by twelve new companies were produced.\",\"In 1959 she visited the United States of America and taught at Ted Shawn's Jacob Pillow as well as examining and giving master classes in many states.\",\"In December 1959, van Praagh was invited to direct the Borovansky Ballet in Australia and became its Artistic Director in its last two years. She did this with great success, staging Rendevous and the three-act Coppelia. After the final performance, she addressed the audience, and encouraged them to prevail upon the Australian Government to raise money for an Australian Ballet. Harold Holt, then Federal Treasurer, approached van Praagh after the show and pledged his personal support. The Australian Ballet was launched in 1962.\",\"Van Praagh was Artistic Director of the Australian Ballet in 1962-1974 and again in 1978. During this time she led the company on several exceptionally successful overseas tours, expanded the company's repertoire with a series of commissioned works from notable Australians and overseas choreographers, and invited guest artists of the stature of Margot Fonteyn and Rudolph Nureyev to perform with the company.\",\"On leaving the Australian Ballet she maintained an active role in ballet in Australia. She was a founding member of the Australian Association for Dance in Education and one of its chief architects, and she was a member of the Theatre Board of the Australia Council. Dame Peggy van Praagh died in Melbourne in 1990.\",{\"bibref\":{\"persname\":\"Sexton, Christopher\",\"content\":\"Sexton, Christopher. Peggy van Praagh, a life of dance. South Melbourne : Macmillan, 1985.\"}}],\"chronlist\":{\"head\":\"Honours and Awards\",\"chronitem\":[{\"date\":1965,\"eventgrp\":{\"event\":\"The Queen Elizabeth Award - Royal Academy of Dancing, London\"}},{\"date\":1966,\"eventgrp\":{\"event\":\"Order of the British Empire (OBE) for services to ballet\"}},{\"date\":1970,\"eventgrp\":{\"event\":\"Dame Commander of the Order of the British Empire (DBE) for services to ballet\"}},{\"date\":1970,\"eventgrp\":{\"event\":\"Encyclopaedia Britannica (Australia) Award for the Arts\"}},{\"date\":1974,\"eventgrp\":{\"event\":\"Doctor of Letters (Honoris Causa) University of New England\"}},{\"date\":1975,\"eventgrp\":{\"event\":\"Distinguished Artist Award from the Australia Council\"}},{\"date\":1981,\"eventgrp\":{\"event\":\"Doctor of Laws (Honoris Causa) Melbourne University\"}}]}}"
]
)
}
it "converts the Hash into JSON" do
- expect(notes_value[0]).to be_a(String)
- expect(JSON.parse(notes_value[0])["chronlist"]).not_to be_nil
- expect(JSON.parse(notes_value[0])["chronlist"]["listhead"]).not_to be_nil
- expect(JSON.parse(notes_value[0])["chronlist"]["chronitem"]).not_to be_nil
+ expect(notes_value.find { |note| note.is_a?(String) && note.include?("chronlist") }).not_to be_nil
end
end
end
diff --git a/spec/presenters/rendering/chronlist_spec.rb b/spec/presenters/rendering/chronlist_spec.rb
index 558f0dc4..f6a1c02b 100644
--- a/spec/presenters/rendering/chronlist_spec.rb
+++ b/spec/presenters/rendering/chronlist_spec.rb
@@ -50,5 +50,27 @@
expect(rendered).to have_css("td", text: "Attorney-General in the Dibbs Protectionist Ministry")
end
end
+
+ context "when event has eventgrp structure" do
+ let(:note) { JSON.parse(IO.read("spec/files/notes/chronlist_no-header_eventgrp.json")) }
+
+ it "renders the chronlist with just the date" do
+ expect(rendered).to have_css("h3", text: "Honours and Awards")
+ expect(rendered).to have_table(class: %w[table-light table-responsive table-striped table-hover])
+ expect(rendered).to have_css("thead.table-purple")
+ expect(rendered).to have_css("tbody.table-group-divider")
+ expect(rendered).to have_css("td.text-nowrap")
+
+ expect(rendered).to have_css("th", text: "Date")
+ expect(rendered).to have_css("th", text: "Event")
+
+ expect(rendered).to have_css("td", text: "1965")
+ expect(rendered).to have_css("td", text: "The Queen Elizabeth Award - Royal Academy of Dancing, London")
+
+ expect(rendered).to have_css("td", text: "1981")
+ expect(rendered).to have_css("li", text: "Dummy 1")
+ expect(rendered).to have_css("li", text: "Dummy 2")
+ end
+ end
end
end