Skip to content

Commit

Permalink
nit, #1398
Browse files Browse the repository at this point in the history
  • Loading branch information
njkim committed Nov 8, 2023
1 parent 252afca commit 371e75c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ define([
],
},
{
title: 'Download Files',
title: 'Select Files',
name: 'download-project-files',
informationboxdata: {
heading: 'Download Files',
text: 'Download from a list of files related to the project',
heading: 'Select Files',
text: 'Select files from a list of files related to the project',
},
layoutSections: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ define([

if (ko.unwrap(params.value)) {
const files = params.value().files;
files?.forEach((file)=>{
files?.forEach((file) => {
self.startIds.push(file.fileid);
self.selectedFiles.push(file);
});
};

this.selectedFiles.subscribe(val => {
this.selectedFiles.subscribe((val) => {
params.value({ files: val });
});

Expand All @@ -55,8 +55,8 @@ define([

const addSelectedFiles = () => {
self.selectedFiles.removeAll();
self.relatedObservations().forEach((observation)=>{
observation.relatedFiles().forEach((file)=>{
self.relatedObservations().forEach((observation) => {
observation.relatedFiles().forEach((file) => {
if (file.selected()) {
self.selectedFiles.push({'name': file.name, 'fileid': file.file_id, 'project': self.projectName});
}
Expand All @@ -66,8 +66,8 @@ define([

params.form.reset = () => {
self.selectedFiles.removeAll();
self.relatedObservations().forEach((observation)=>{
observation.relatedFiles().forEach((file)=>{
self.relatedObservations().forEach((observation) => {
observation.relatedFiles().forEach((file) => {
if (self.startIds().includes(file.file_id)) {
file.selected(true);
} else {
Expand All @@ -82,26 +82,26 @@ define([
const projectResponse = await window.fetch(arches.urls.related_resources + self.projectValue + "?paginate=false");
const projectJson = await projectResponse.json();

const collectionForProject = projectJson.related_resources.find(res => res.graph_id === collectionGraphId).resourceinstanceid;
const collectionForProject = projectJson.related_resources.find((res) => res.graph_id === collectionGraphId).resourceinstanceid;
const collectionResponse = await window.fetch(arches.urls.related_resources + collectionForProject + "?paginate=false");
const collectionJson = await collectionResponse.json();

const projectPhysicalThings = collectionJson.related_resources.filter(res => res.graph_id === physicalThingGraphId)
.filter(res => {
const removedFromTile = res.tiles.find(tile => tile.nodegroup_id === removalFromObjectNodegroupId);
const removedFrom = removedFromTile?.data[removedFromNodeId].map(rr => rr.resourceId);
return removedFrom?.some(res => physicalThings.includes(res)) || physicalThings.includes(res.resourceinstanceid);
}).map(res => res.resourceinstanceid);
const projectPhysicalThings = collectionJson.related_resources.filter((res) => res.graph_id === physicalThingGraphId)
.filter((res) => {
const removedFromTile = res.tiles.find((tile) => tile.nodegroup_id === removalFromObjectNodegroupId);
const removedFrom = removedFromTile?.data[removedFromNodeId].map((rr) => rr.resourceId);
return removedFrom?.some((res) => physicalThings.includes(res)) || physicalThings.includes(res.resourceinstanceid);
}).map((res) => res.resourceinstanceid);

self.projectName = projectJson.resource_instance.displayname;
const projectObservations = projectJson.related_resources.filter(res => res.graph_id == observationGraphId)
.filter(res => {
const objectTile = res.tiles.find(tile => tile.nodegroup_id === objectObservedNodeId);
const projectObservations = projectJson.related_resources.filter((res) => res.graph_id == observationGraphId)
.filter((res) => {
const objectTile = res.tiles.find((tile) => tile.nodegroup_id === objectObservedNodeId);
const object = objectTile?.data[objectObservedNodeId][0]['resourceId'];
return projectPhysicalThings.includes(object);
});

const selectedFileIds = self.selectedFiles().map((file)=>file.fileid);
const selectedFileIds = self.selectedFiles().map((file) => file.fileid);
for (const projectObservation of projectObservations) {
const relatedFiles = ko.observableArray();
const response = await window.fetch(arches.urls.related_resources + projectObservation.resourceinstanceid + "?paginate=false");
Expand All @@ -111,14 +111,14 @@ define([
const observation = json.resource_instance;
observation.expanded = ko.observable();
observation.description = observation.descriptors[arches.activeLanguage].description;
const digitalResources = json.related_resources.filter(res => res.graph_id == digitalResourcegGraphId);
const digitalResources = json.related_resources.filter((res) => res.graph_id == digitalResourcegGraphId);
digitalResources.forEach((res) =>
res.tiles.forEach((tile) => {
if (tile.nodegroup_id == fileNodeId) {
const selected = ko.observable();
if (selectedFileIds.includes(tile.data[fileNodeId][0].file_id)) { selected(true); }
selected.subscribe(() => addSelectedFiles());
const interpretation = res.tiles.find(tile2 => tile2.parenttile_id == tile.tileid)?.data[fileStatementContentNodeId][arches.activeLanguage].value;
const interpretation = res.tiles.find((tile2) => tile2.parenttile_id == tile.tileid)?.data[fileStatementContentNodeId][arches.activeLanguage].value;
const file = { ...tile.data[fileNodeId][0], interpretation, selected };
relatedFiles.push(file);
}
Expand Down
2 changes: 1 addition & 1 deletion arches_for_science/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def download_project_files_task(userid, files, temp_files, project_name):
search_history_obj = SearchExportHistory.objects.get(pk=exportid) if exportid else None

msg = _(
"The report(s) and the related file(s) for the project '{}' are ready to download. You have 24 hours to download your files before they are automatically removed."
"The report(s) and the related file(s) for the project '{}' are ready for download."
).format(project_name)
notiftype_name = "Search Export Download Ready"
context = dict(
Expand Down
15 changes: 10 additions & 5 deletions arches_for_science/views/download_project_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import arches_for_science.tasks as tasks
from arches_templating.views.template import TemplateView

logger = logging.getLogger(__name__)


class FileDownloader(View):
def post(self, request):
Expand Down Expand Up @@ -47,7 +49,7 @@ def post(self, request):
screenshots = [{"fileid": i["fileId"], "name": i["imageName"]} for i in json_data["annotationScreenshots"]]
temp_files = generated_reports + screenshots

project_name = files[0]["project"]
project_name = json_data["projectDetails"][0]["displayname"]
userid = request.user.id

if len(files) + len(temp_files) == 0:
Expand Down Expand Up @@ -89,10 +91,13 @@ def create_download_zipfile(self, user, files, temp_files, project_name):
skipped_files = []
size_limit = 104857600 # 100MByte
for file in all_files:
if file["file"].size >= size_limit:
skipped_files.append({"name": file["name"], "fileid": file["fileid"]})
else:
download_files.append({"name": file["name"], "downloadfile": file["file"]})
try:
if file["file"].size >= size_limit:
skipped_files.append({"name": file["name"], "fileid": file["fileid"]})
else:
download_files.append({"name": file["name"], "downloadfile": file["file"]})
except:
logger.warn(_("Unable to locate {}".format(file["name"])))

if len(download_files) > 0:
zip_stream = zip_utils.create_zip_file(download_files, "downloadfile")
Expand Down

0 comments on commit 371e75c

Please sign in to comment.