From ea1a7c900b12f7e688b56590dd13bc3e8ad1a395 Mon Sep 17 00:00:00 2001 From: rushirajnenuji Date: Mon, 12 Dec 2022 10:49:12 -0800 Subject: [PATCH 01/98] Add required dependencies from PackageTableView Add required dependencies from PackageTableView --- src/js/views/DataPackageView.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/js/views/DataPackageView.js b/src/js/views/DataPackageView.js index d522fbb6f..f92b9ebb7 100644 --- a/src/js/views/DataPackageView.js +++ b/src/js/views/DataPackageView.js @@ -7,16 +7,20 @@ define([ 'collections/DataPackage', 'models/DataONEObject', 'models/metadata/ScienceMetadata', - 'models/metadata/eml211/EML211', 'views/DataItemView', + 'models/metadata/eml211/EML211', + 'models/PackageModel', + 'views/DownloadButtonView', + 'views/DataItemView', 'text!templates/dataPackage.html', - 'text!templates/dataPackageStart.html'], - function($, _, Backbone, LocalForage, DataPackage, DataONEObject, ScienceMetadata, EML211, DataItemView, - DataPackageTemplate, DataPackageStartTemplate) { + 'text!templates/dataPackageStart.html', + 'text!templates/downloadContents.html'], + function($, _, Backbone, LocalForage, DataPackage, DataONEObject, ScienceMetadata, EML211, Package, DownloadButtonView, DataItemView, + DataPackageTemplate, DataPackageStartTemplate, DownloadContentsTemplate) { 'use strict'; /** * @class DataPackageView - * @classdesc The main view of a Data Package in the editor. The view is + * @classdesc The main view of a Data Package in MetacatUI. The view is * a file/folder browser * @classcategory Views * @screenshot views/DataPackageView.png @@ -63,7 +67,7 @@ define([ //The data package to render this.dataPackage = options.dataPackage || new DataPackage(); - this.parentEditorView = options.parentEditorView || null; + this.parentEditorView = options.parentEditorView || null; } //Create a new DataPackage collection if one wasn't sent else if(!this.dataPackage){ From 41519f031e381c6ee4ded71a14793075f1d12f04 Mon Sep 17 00:00:00 2001 From: rushirajnenuji Date: Mon, 12 Dec 2022 10:49:12 -0800 Subject: [PATCH 02/98] Add functions required for the metadata view display Add functions required for the metadata view display --- src/js/views/DataPackageView.js | 390 +++++++++++++++++++++++++++++++- 1 file changed, 389 insertions(+), 1 deletion(-) diff --git a/src/js/views/DataPackageView.js b/src/js/views/DataPackageView.js index f92b9ebb7..d1a749efe 100644 --- a/src/js/views/DataPackageView.js +++ b/src/js/views/DataPackageView.js @@ -28,15 +28,23 @@ define([ var DataPackageView = Backbone.View.extend( /** @lends DataPackageView.prototype */{ + template: _.template(DownloadContentsTemplate), + tagName: "table", className: "table table-striped table-hover", + metadataViewTagName : "div", + + metadataViewClassName : "download-contents", + id: "data-package-table", events: { "click .toggle-rows" : "toggleRows", // Show/hide rows associated with event's metadata row - "click .message-row .addFiles" : "handleAddFiles" + "click .message-row .addFiles" : "handleAddFiles", + "click .expand-control" : "expand", + "click .collapse-control" : "collapse" }, subviews: {}, @@ -337,6 +345,386 @@ define([ event.preventDefault(); }, + sort: function(models){ + //Default to the package model members as the models to sort + if(!models){ + var models = this.model.get("members"); + //If this model doesn't have members, return an empty array or a falsey value + if(!models) return models; + } + + // One == already sorted! + if(models.length == 1) return models; + //If there are too many models to sort (takes too much time) then just get the metadata to display first + else if(models.length > 150){ + var view = this; + + + //Find the metadata doc we are currently viewing + var currentMetadata = _.find(models, function(m){ return (m.get("id") == view.currentlyViewing) }); + //Add it to the front + if(currentMetadata){ + models = _.without(models, currentMetadata); + models.unshift(currentMetadata); + } + + //Return the newly sorted array + return models; + } + + + var view = this, + metadataView = this.onMetadataView? this.parentView : null; + + //** If this is not a nested package AND the parent view is the metadata view, then sort by order of appearance in the metadata **/ + if(!this.nested && (metadataView && !_.findWhere(metadataView.subviews, {type: "MetadataIndex"}))){ + if(metadataView.hasEntityDetails()){ + + //If we are currently viewing a metadata document, find it + if(this.currentlyViewing) + var currentMetadata = _.find(models, function(m){ return (m.get("id") == view.currentlyViewing) }); + + //For each model, find its position on the Metadata View page + var numNotFound = 0; + _.each(models, function(model){ + if(currentMetadata == model) return; + + var container = view.parentView.findEntityDetailsContainer(model); + if(container) model.offsetTop = $(container)[0].offsetTop; + else{ + model.offsetTop = window.outerHeight; + numNotFound++; + } + }); + + //Continue only if we found the entity details section for at least one model, if not, sort by the default method later + if(numNotFound < models.length-1){ //Minus 1 since we don't count the metadata + //Sort the models by this position + models = _.sortBy(models, "offsetTop"); + + //Move the metadata model that we are currently viewing in the Metadata view to the top + if(currentMetadata){ + models = _.without(models, currentMetadata); + models.unshift(currentMetadata); + } + + //Flatten the array in case we have nesting + models = _.flatten(models); + + //Return the sorted array + return models; + } + } + } + + //** For tables with no accompanying metadata (nested or not on the Metadata View), default to sorting by group then alpha by name**/ + //Split the members of this package into groups based on their format type (metaata, data, image, code, etc) + var groupedModels = _.groupBy(models, function(m){ + if(!m.get("type") || (typeof m.get("type") == "undefined")) + return "data"; + return m.get("type"); + }), + sortedModels = []; + + var rowOrder = ["metadata", "image", "PDF", "program", "data", "annotation"]; + + for(var i=0; i