Skip to content

Commit 72649ae

Browse files
committed
fix download links, initial redaction in codebook
1 parent b408a48 commit 72649ae

2 files changed

Lines changed: 33 additions & 19 deletions

File tree

previewers/betatest/js/refiqdacore.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,23 +1073,18 @@ function createPdfSelectionWithTooltip(selectionName, page, firstX, firstY, seco
10731073
function createSourceReference(source) {
10741074
let sourceName = source.getAttribute("name");
10751075
let plainTextPath = source.getAttribute("plainTextPath");
1076-
1076+
let path = plainTextPath.replace("internal://","sources/")
10771077
if (isZipMode()) {
10781078
// In zip mode, create a link that uses the zip entry
1079-
if (typeof entryMap !== 'undefined' && plainTextPath && entryMap[plainTextPath] !== undefined) {
1080-
let entryIndex = entryMap[plainTextPath];
1081-
return '<a href="#" data-entry-index="' + entryIndex + '">' + sourceName + '</a>';
1079+
if (typeof entryMap !== 'undefined' && path && entryMap[path] !== undefined) {
1080+
let entryIndex = entryMap[path];
1081+
return sourceName + ' <a href="#" data-entry-index="' + entryIndex + '" data-entry-name="' + sourceName + '" title="Download Source: ' + sourceName + '"><span class="glyphicon glyphicon-download-alt"></span></a>';
10821082
} else {
10831083
// No link if file not found in zip
10841084
return sourceName;
10851085
}
10861086
} else {
1087-
// In non-zip mode, create a direct link to the file if it exists
1088-
if (plainTextPath) {
1089-
return '<a href="' + plainTextPath + '" target="_blank">' + sourceName + '</a>';
1090-
} else {
1091-
return sourceName;
1092-
}
1087+
return sourceName;
10931088
}
10941089
}
10951090

@@ -1237,10 +1232,25 @@ async function loadTextExcerpt(plainTextPath, startPos, endPos, sourceGuid) {
12371232
}
12381233

12391234
function redactSources(guidsToRedact) {
1240-
console.log("Redacting sources with GUIDs:", guidsToRedact);
1241-
alert("Redaction functionality is not yet implemented.\nSelected source GUIDs: " + guidsToRedact.join(', '));
1235+
console.log("Redacting sources with GUIDs:", guidsToRedact);
1236+
1237+
let redactedXmlDoc = xmlDoc.cloneNode(true);
1238+
1239+
for (const guid of guidsToRedact) {
1240+
// Find any source element by its GUID and remove it.
1241+
// This will also remove all its children, including annotations.
1242+
let sourceElement = redactedXmlDoc.querySelector('[guid="' + guid + '"]');
1243+
if (sourceElement && sourceElement.parentNode) {
1244+
sourceElement.parentNode.removeChild(sourceElement);
1245+
console.log("Removed source element and its annotations with GUID:", guid);
1246+
}
1247+
}
1248+
1249+
// For now, let's just log the redacted XML to the console to verify
1250+
console.log("Redacted XML:", new XMLSerializer().serializeToString(redactedXmlDoc));
1251+
alert("Redaction of XML complete. See console for redacted XML. Next steps will handle file saving.");
1252+
12421253
// In the next steps, we will implement the logic here to:
1243-
// 1. Modify the XML codebook to remove selected sources and their annotations.
1244-
// 2. If it's a zip file, remove the source files from the archive.
1245-
// 3. POST the new redacted file to Dataverse.
1254+
// 1. If it's a zip file, remove the source files from the archive.
1255+
// 2. POST the new redacted file to Dataverse.
12461256
}

previewers/betatest/js/refiqdpx.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,13 @@ async function downloadFile(event) {
128128
}
129129

130130
async function download(entry, li, a) {
131-
if (!li.classList.contains("busy")) {
131+
const parentCell = $(a).closest('td');
132+
if (!parentCell.hasClass("busy")) {
132133

133134
const controller = new AbortController();
134135
const signal = controller.signal;
135136

136-
li.classList.add("busy");
137+
parentCell.addClass("busy");
137138
try {
138139
const blobURL = URL.createObjectURL(await entry.getData(new zip.BlobWriter(), {
139140
onprogress: (index, max) => {
@@ -146,16 +147,19 @@ async function download(entry, li, a) {
146147
}))
147148
var index = a.getAttribute("data-entry-index");
148149
console.log("index: " + index);
150+
151+
const filename = a.getAttribute("data-entry-name");
152+
149153
$("a[data-entry-index='" + index + "']").attr('href',blobURL);
150-
$("a[data-entry-index='" + index + "']").attr('download',a.text);
154+
$("a[data-entry-index='" + index + "']").attr('download', filename || a.text);
151155
const clickEvent = new MouseEvent("click");
152156
a.dispatchEvent(clickEvent);
153157
} catch (error) {
154158
if (error.message != zip.ERR_ABORT) {
155159
throw error;
156160
}
157161
} finally {
158-
li.classList.remove("busy");
162+
parentCell.removeClass("busy");
159163
}
160164
}
161165
}

0 commit comments

Comments
 (0)