Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/importer/nunjucks/importer/macros/table_view.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% set rows = data.rows %}
{% set moreRowsAvailable = data.extraRecordCount > 0 %}
{% set moreRowsCount = data.extraRecordCount %}

<p>.{{data}}.</p>
{% set tableHeaders = importerHeaderRowDisplay(session, headerMode) %}

<table class="selectable govuk-body" data-persist-selection="true">
Expand Down
34 changes: 34 additions & 0 deletions lib/importer/src/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

const fs = require("node:fs")
const path = require("node:path")

const session_lib = require("./session.js");

exports.CreateSessionWithFileFixture = (plugin_config, request, filename) => {
const sourceFile = path.join(path.resolve(process.cwd()), "../../fixtures/", filename);
const targetFile = path.join(plugin_config.uploadPath, filename);

fs.copyFileSync(sourceFile, targetFile);
const fstats = fs.statSync(targetFile)

let encoding = "utf8";
let mimetype = "text/csv"

if (!filename.toLowerCase().endsWith(".csv")) {
encoding = "7bit";
mimetype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
}

request.file = {
fieldname: "file",
originalname: filename,
mimetype: mimetype,
encoding: encoding,
path: targetFile,
size: fstats.size,
destination: plugin_config.uploadPath,
filename: filename
};

return session_lib.CreateSession(plugin_config, request)
}
1 change: 0 additions & 1 deletion lib/importer/src/dudk/sheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ exports.MapData = (sid, sheet, mapping, fields, previewLimit = DEFAULT_PREVIEW_L
// Convert source mapping (a map from column index -> attribute name) into a mapping for the backend
let rewrittenMapping = RewriteMapping(mapping, fields)


// Apply the mapping
const backendJid = backend.SessionPerformMappingJob(sid, rowRange, rewrittenMapping);

Expand Down
3 changes: 2 additions & 1 deletion lib/importer/src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ const importerGetHeaders = (data) => {
const importerMappedData = (data) => {
const session_data = data[IMPORTER_SESSION_KEY];
const session = new session_lib.Session(session_data)

const mapResults = sheets_lib.MapData(session.backendSid, session.sheet, session.mapping, session.fields);
const headers = session.fields;

return {
rows: mapResults.resultRecords,
headers: headers,
Expand All @@ -174,6 +174,7 @@ const importerMappedData = (data) => {
}

const importerHeaderRowDisplay = (data, mode) => {
console.log(data)
const session_data = data[IMPORTER_SESSION_KEY];
const session = new session_lib.Session(session_data)

Expand Down
46 changes: 46 additions & 0 deletions lib/importer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,52 @@ exports.Initialise = (config, router, prototypeKit) => {
}
}

//--------------------------------------------------------------------
// Debug routes for testing presentation
//--------------------------------------------------------------------
const debug_lib = require("./debug.js")
const funcs_lib = require("./functions.js")

// debug routes ...
router.get('/importer/debug', function (request, response) {
response.render("debug/index.html", {})
})


// Valid, with headers, only warnings
router.get('/importer/debug/valid', function (request, response) {

const sess = debug_lib.CreateSessionWithFileFixture(plugin_config, request, "validation-test.csv").session

sess.sheet = "Sheet1"
sess.headerRange = {
sheet: "Sheet1",
start: { row: 0, column: 0 },
end: { row: 0, column: 7 }
}

sess.mapping = {
0: "Employee number",
1: "Title",
2: "First name",
3: "Surname",
4: "Employment start date",
5: "Salary",
6: "Contribution percentage",
}

const local_data = {}
local_data[IMPORTER_SESSION_KEY] = sess

const res = funcs_lib.importerMappedData(local_data)

// request.session.data[IMPORTER_SESSION_KEY] = sess

response.render("debug/valid.html", { debug_data: { result: res, session: sess } })
})




//--------------------------------------------------------------------
// Review the processing for the current session before continuing.
Expand Down
1 change: 0 additions & 1 deletion lib/importer/src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ exports.CreateSession = (config, request) => {
createResponse.error = err;
return createResponse;
}

createResponse.id = getFilenameHash(file.filename);
createResponse.session = new Session({
id: createResponse.id,
Expand Down
17 changes: 17 additions & 0 deletions lib/importer/views/debug/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "../layouts/main.html" %}

{% set pageName="Debug" %}

{% block content %}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Debug views</h1>

<p class="govuk-body">
<a href="/importer/debug/valid">/fixtures/validation-test.csv</a> with headers specified and missing row warnings
</p>
</div>
</div>

{% endblock %}
24 changes: 24 additions & 0 deletions lib/importer/views/debug/valid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "../layouts/main.html" %}

{% from "importer/macros/table_view.njk" import importerTableView %}

{% set pageName="Debug - Valid" %}

{% block beforeContent %}
<a href="/importer/debug" class="govuk-back-link">Back</a>
{% endblock %}

{% block content %}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Valid, with headers, only warnings</h1>

<p class="govuk-body">
{{ importerTableView(debug_data.session, debug_data.result, caption="test", headerMode="none") }}
</p>

</div>
</div>

{% endblock %}
1 change: 0 additions & 1 deletion prototypes/basic/app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
const govukPrototypeKit = require("govuk-prototype-kit");
const router = govukPrototypeKit.requests.setupRouter();


// Below 3 lines added by the Data Upload Design Kit plugin.
// If you uninstall the plugin, remove the 3 lines below.
const importer = require("@register-dynamics/importer");
Expand Down
Loading