Skip to content

Commit c0ebbe6

Browse files
committed
Added some tweaks to review page to accomodate tables,
moved the check for footer rows in SessionPerformMappingJob from if(row) to its parent for loop, as we were having an issue where an empty row in the table footer (i.e. the row immediately below the table) was giving an error.
1 parent 3270499 commit c0ebbe6

5 files changed

Lines changed: 91 additions & 26 deletions

File tree

lib/importer/src/dudk/backend.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,11 @@ exports.SessionSuggestDataRange = (sid, headerRange, footerRange) => {
247247
const dimensions = getDimensions(sid);
248248

249249
if (headerRange) {
250+
console.debug(headerRange)
250251
const sheetName = headerRange.sheet;
251252
const sheetDimensions = dimensions.sheetDimensions.get(sheetName);
252253
if (footerRange) {
254+
console.debug(footerRange)
253255
// FIXME: Ensure footer is in same sheet as header, and is below the
254256
// header. Not sure how fussy we need to be about the columns in
255257
// the footer. Perhaps they should at least overlap the columns in
@@ -785,13 +787,13 @@ exports.SessionPerformMappingJob = (sid, range, mapping, includeErrorRow = false
785787
let row = getMergedRow(data, merges, rowIdx);
786788
let recordCells = {};
787789
let foundSomeValues = false;
790+
// Ensure we exclude footer rows from the validation as they may not
791+
// have values in them.
792+
if (rowIdx == range.end.row && footerRange) {
793+
continue;
794+
}
788795

789796
if (row) {
790-
// Ensure we exclude footer rows from the validation as they may not
791-
// have the same number of columns as the header row.
792-
if (rowIdx == range.end.row && footerRange) {
793-
continue;
794-
}
795797

796798
if (row.length < expectedColumnCount) {
797799
warnings.push({row: rowIdx, field: "", type: errorTypes.ValidationError.ShortRow({ expected: expectedColumnCount, actual: row.length})});
@@ -880,6 +882,9 @@ exports.JobGetSummary = (sid, jid) => {
880882
assert(session.jobs.has(jid), `No such job ${jid} when getting job summary`);
881883

882884
let job = session.jobs.get(jid);
885+
console.debug(job)
886+
console.debug(job.records)
887+
console.debug(job.records.length)
883888

884889
return {
885890
recordCount: job.records.length,

lib/importer/src/dudk/sheets.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ exports.GetTableHeader = (sid, sheet, table) => {
257257

258258
}
259259

260+
exports.GetTableFooter = (sid, sheet, table) => {
261+
const tableRangeContainer = backend.SessionGetInputTableRanges(sid, sheet).get(table);
262+
const sheetDimensions = backend.SessionGetInputDimensions(sid)
263+
.sheetDimensions.get(sheet);
264+
assert(tableRangeContainer, `Table Range ${table} not found in ${sheet}` )
265+
const tableRange = tableRangeContainer.range
266+
267+
const footerRange = {
268+
start: { row: tableRange.end.row + 1, column: tableRange.start.column },
269+
end: {row: tableRange.end.row + 1, column: tableRange.end.column }
270+
}
271+
272+
return footerRange;
273+
274+
}
275+
260276

261277

262278
// Given a session id and a sheet returns up to count rows.
@@ -293,7 +309,7 @@ exports.GetRowsTable = (sid, sheet, start = 0, count = 10, table=null) => {
293309
};
294310

295311
exports.GetRowRangeFromEnd = (sid, sheet, count = 10, table = null) => {
296-
if (table) {
312+
if (table && table != null) {
297313
const tableRangeContainer = backend.SessionGetInputTableRanges(sid, sheet).get(table);
298314
const tableRange = tableRangeContainer.range
299315
console.debug('Table range:', tableRange)
@@ -412,6 +428,7 @@ exports.MapData = (sid, sheet, mapping, fields, previewLimit = DEFAULT_PREVIEW_L
412428

413429
// Construct the range to be mapped - everything but the first row
414430
const rowRange = backend.SessionSuggestDataRange(sid, hRange, fRange);
431+
console.debug('Final row range:', rowRange)
415432

416433
// Convert source mapping (a map from column index -> attribute name) into a mapping for the backend
417434
let rewrittenMapping = RewriteMapping(mapping, fields)

lib/importer/src/functions.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ const importerErrorMappingData = (error, key) => {
7777
const importerGetRows = (data, start, count) => {
7878
const session_data = data[IMPORTER_SESSION_KEY];
7979
const session = new session_lib.Session(session_data)
80-
if (session.table & session.table != null) {
80+
if (session.table && session.table != null) {
81+
console.debug('showing table rows')
8182
return sheets_lib.GetRowsTable(session.backendSid, session.sheet, start, count, session.table)
8283
}
8384
return sheets_lib.GetRows(session.backendSid, session.sheet, start, count);
@@ -90,7 +91,9 @@ const importerGetRows = (data, start, count) => {
9091
const importerGetTrailingRows = (data, count) => {
9192
const session_data = data[IMPORTER_SESSION_KEY];
9293
const session = new session_lib.Session(session_data)
93-
if (session.table & session.table != null) {
94+
console.debug('Table name for footer:', session.table)
95+
if (session.table && session.table != null) {
96+
console.debug('showing table footer')
9497
return sheets_lib.GetTrailingRowsTable(session.backendSid, session.sheet, session.table, count);
9598
}
9699
return sheets_lib.GetTrailingRows(session.backendSid, session.sheet, count);

lib/importer/src/index.js

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,25 @@ exports.Initialise = (config, router, prototypeKit) => {
241241

242242
// Ensure the session is persisted. Currently in session, eventually another way
243243
request.session.data[IMPORTER_SESSION_KEY] = session;
244+
245+
tableList = []
246+
247+
tableList = sheets_lib.ListTables(session.backendSid, session.sheet)
248+
console.debug('Table List:', tableList)
249+
console.debug(tableList.length)
250+
251+
if (tableList.length != 0) {
252+
253+
redirectOnwards(request, response);
254+
return;
255+
}
256+
257+
258+
if ("other" in request.query) {
259+
const otherPage = decodeURIComponent(request.query.other)
260+
if (otherPage) { request.query.next = request.query.other }
261+
console.debug(request.query.other)
262+
}
244263
redirectOnwards(request, response);
245264
},
246265
);
@@ -273,6 +292,10 @@ exports.Initialise = (config, router, prototypeKit) => {
273292
session.table = null
274293
//redirectOnwards(request, response); //if no table is selected we don't need to persist one
275294
//return;
295+
// Ensure the session is persisted. Currently in session, eventually another way
296+
request.session.data[IMPORTER_SESSION_KEY] = session;
297+
redirectOnwards(request, response);
298+
return;
276299
} else {
277300
session.table = request.body.table;
278301
let check = sheets_lib.GetTablePreview(session.backendSid, session.sheet, session.table);
@@ -285,28 +308,39 @@ exports.Initialise = (config, router, prototypeKit) => {
285308
// Get header range, for tables this will check the column names against the first row of the table.
286309
// If they match that first row will be designated as the headerRange, otherwise it will be null.
287310
headerRange = sheets_lib.GetTableHeader(session.backendSid, session.sheet, session.table)
288-
console.debug(headerRange)
311+
console.debug('Table header:', headerRange)
289312
if (headerRange != null) {
290313
session.headerRange = headerRange //overwrite assumed header range with table header range
291314
}
292-
}
293-
294-
// The user
315+
316+
//Set a footer range, this may be overridden later
317+
footerRange = sheets_lib.GetTableFooter(session.backendSid, session.sheet, session.table)
318+
console.debug('Assumed footer:', footerRange)
319+
if (footerRange != null) {
320+
session.footerRange = footerRange
321+
}
322+
323+
// The user
295324

296-
// Ensure the session is persisted. Currently in session, eventually another way
297-
request.session.data[IMPORTER_SESSION_KEY] = session;
325+
// Ensure the session is persisted. Currently in session, eventually another way
326+
request.session.data[IMPORTER_SESSION_KEY] = session;
298327

299-
if (headerRange == null) {
300-
redirectOnwards(request, response);
301-
return;
328+
if (!headerRange | headerRange == null) {
329+
redirectOnwards(request, response);
330+
return;
331+
}
332+
333+
if ("other" in request.query) {
334+
const otherPage = decodeURIComponent(request.query.other)
335+
if (otherPage) { request.query.next = request.query.other }
336+
console.debug(request.query.other)
337+
}
338+
redirectOnwards(request, response);
302339
}
340+
341+
342+
303343

304-
if ("other" in request.query) {
305-
const otherPage = decodeURIComponent(request.query.other)
306-
if (otherPage) { request.query.next = request.query.other }
307-
console.debug(request.query.other)
308-
}
309-
redirectOnwards(request, response);
310344
},
311345
);
312346

@@ -371,10 +405,15 @@ exports.Initialise = (config, router, prototypeKit) => {
371405
redirectOnwards(request, response);
372406
return;
373407
}
374-
408+
409+
previewRange = {}
375410
// We will assume we asked for the default of 10 rows, and calculate the offset
376411
// we need to apply to the selection range so that it is valid
377-
let previewRange = sheets_lib.GetRowRangeFromEnd(session.backendSid, session.sheet, 10);
412+
if (session.table && session.table != null) {
413+
previewRange = sheets_lib.GetRowRangeFromEnd(session.backendSid, session.sheet, 10, session.table);
414+
} else {
415+
previewRange = sheets_lib.GetRowRangeFromEnd(session.backendSid, session.sheet, 10);
416+
};
378417
selectionRange.start.row += previewRange.start.row - 1;
379418
selectionRange.end.row += previewRange.start.row - 1;
380419

@@ -386,6 +425,7 @@ exports.Initialise = (config, router, prototypeKit) => {
386425
}
387426

388427
session.footerRange = selectionRange;
428+
console.debug('Footer range:', session.footerRange)
389429

390430
// Ensure the session is persisted. Currently in session, eventually another way
391431
request.session.data[IMPORTER_SESSION_KEY] = session;

lib/importer/templates/select_sheet.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{% block content %}
1111
<div class="govuk-grid-row">
1212
<div class="govuk-grid-column-full">
13-
<form action="{{ importerSelectSheetPath('/select_table') }}" method="post">
13+
<form action="{{ importerSelectSheetPath('/select_table', '/select_header_row') }}" method="post">
1414
<div class="govuk-form-group">
1515
<fieldset class="govuk-fieldset">
1616
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">

0 commit comments

Comments
 (0)