diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/plugins/MicroscopyTechnology.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/plugins/MicroscopyTechnology.js index 4f68c42e6d9229394f9ccdf3ae29dc9b5fd2fdd9..2db69a4ee9af6aaad9d74fe94086c6acf7ba4d13 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/plugins/MicroscopyTechnology.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/plugins/MicroscopyTechnology.js @@ -174,7 +174,7 @@ $.extend(MicroscopyTechnology.prototype, ELNLIMSPlugin.prototype, { var newThumbCol = $("<div />", { class: "col-md-3", - display: "inline", + display: "inline", "text-align": "center", id: sample.code }); @@ -246,133 +246,102 @@ $.extend(MicroscopyTechnology.prototype, ELNLIMSPlugin.prototype, { displayThumbnailForSample: function (model, sample, img_id) { - // Get the datasets with type "MICROSCOPY_IMG_THUMBNAIL" for current sample - this.getMicroscopyImgThumbnailDataSetsForMicroscopySample( - model, - sample.experimentIdentifierOrNull, - sample.code, function (dataset) { - - // Get the containers - if (dataset == null) { - return; - } + require([ + "as/dto/sample/search/SampleSearchCriteria", + "as/dto/sample/fetchoptions/SampleFetchOptions", + "as/dto/dataset/search/DataSetSearchCriteria", + "dss/dto/datasetfile/search/DataSetFileSearchCriteria", + "dss/dto/datasetfile/fetchoptions/DataSetFileFetchOptions", + ], + + function ( + SampleSearchCriteria, + SampleFetchOptions, + DataSetSearchCriteria, + DataSetFileSearchCriteria, + DataSetFileFetchOptions) { + + // First retrieve the sample again but with the associated datasets + console.log("Processing microscopy sample " + sample.code); + + // Search for the sample of type and given perm id + var criteria = new SampleSearchCriteria(); + criteria.withType().withCode().thatEquals(sample.sampleTypeCode); + criteria.withPermId().thatEquals(sample.permId); + var fetchOptions = new SampleFetchOptions(); + fetchOptions.withDataSets().withType(); + + // Query the server + mainController.openbisV3.searchSamples(criteria, fetchOptions).done(function (result) { + if (result.getTotalCount() == 0) { + return null; + } + var sample = result.getObjects()[0]; + for (var i = 0; i < sample.getDataSets().length; i++) { + var dataSet = sample.getDataSets()[i]; - // Retrieve the file for the dataset and the associated URL - mainController.openbisV1.listFilesForDataSet(dataset.code, '/', true, - function (response) { + if (dataSet.getType().code === "MICROSCOPY_IMG_THUMBNAIL") { - // Make sure that we got some results from the DSS to process - if (response.error) { + // Now retrieve the thumbnail and add display it - // Thumbnail not found! - var imD = $("#" + img_id); - imD.attr("src", "./img/error.png"); - imD.attr("title", "Could not find any files associated to this dataset!"); + // Get the file + var criteria = new DataSetFileSearchCriteria(); + var dataSetCriteria = criteria.withDataSet().withOrOperator(); + dataSetCriteria.withPermId().thatEquals(dataSet.permId.permId); - return; + var fetchOptions = new DataSetFileFetchOptions(); - } + // Query the server + mainController.openbisV3.getDataStoreFacade().searchFiles(criteria, fetchOptions).done(function (result) { - // Find the thumbnail.png file - response.result.forEach(function (f) { + // Thumbnail + var imD = $("#" + img_id); - // Thumbnail - var imD = $("#" + img_id); + // Make sure to reset the display attribute + imD.css("display", "inline"); - if (!f.isDirectory && f.pathInDataSet.toLowerCase() === "thumbnail.png") { + if (result.getTotalCount() == 0) { - // Retrieve the file URL - mainController.openbisV1.getDownloadUrlForFileForDataSetInSession( - dataset.code, f.pathInDataSet, function (url) { + // Thumbnail not found! + imD.attr("src", "./img/error.png"); + imD.attr("title", "Could not find a thumbnail for this dataset!"); - // Replace the image - var eUrl = encodeURI(url); - eUrl = eUrl.replace('+', '%2B'); - imD.attr("src", eUrl); + return; + } - }); - } else { + // Extract the files + var datasetFiles = result.getObjects(); - // Thumbnail not found! - imD.attr("src", "./img/error.png"); - imD.attr("title", "Could not find a thumbnail for this dataset!"); + // Find the only fcs file and add its name and URL to the DynaTree + datasetFiles.forEach(function (f) { - } + // // Build the download URL + // let url = f.getDataStore().getDownloadUrl() + "/datastore_server/" + + // f.permId.dataSetId.permId + "/" + f.getPath() + "?sessionID=" + + // mainController.openbisV3.getWebAppContext().sessionId; - // Make sure to reset the display attribute - imD.css("display", "inline"); - }); + if (!f.isDirectory() && f.getPath().toLowerCase() === "thumbnail.png") { - }); + // Still use the V1 API since the sessionId stored in the + // webapp context is null in V3. + mainController.openbisV1.getDownloadUrlForFileForDataSetInSession( + dataSet.code, f.getPath(), function (url) { - }); + // Replace the image + var eUrl = encodeURI(url); + eUrl = eUrl.replace('+', '%2B'); + imD.attr("src", eUrl); - }, + console.log("Adding thumbnail " + eUrl + " to " + img_id); - getMicroscopyImgThumbnailDataSetsForMicroscopySample: function (model, expCode, sampleCode, action) { - - // Experiment criteria (experiment of type "COLLECTION" and code expCode) - var experimentCriteria = new SearchCriteria(); - experimentCriteria.addMatchClause( - SearchCriteriaMatchClause.createAttributeMatch( - "CODE", expCode) - ); - experimentCriteria.addMatchClause( - SearchCriteriaMatchClause.createAttributeMatch( - "TYPE", "COLLECTION") - ); - - // Sample criteria (sample of type "MICROSCOPY_SAMPLE_TYPE" and code sampleCode) - var sampleCriteria = new SearchCriteria(); - sampleCriteria.addMatchClause( - SearchCriteriaMatchClause.createAttributeMatch( - "CODE", sampleCode) - ); - sampleCriteria.addMatchClause( - SearchCriteriaMatchClause.createAttributeMatch( - "TYPE", "MICROSCOPY_SAMPLE_TYPE") - ); - - // Dataset criteria - var datasetCriteria = new SearchCriteria(); - datasetCriteria.addMatchClause( - SearchCriteriaMatchClause.createAttributeMatch( - "TYPE", "MICROSCOPY_IMG_CONTAINER") - ); - - // Add sample and experiment search criteria as subcriteria - datasetCriteria.addSubCriteria( - SearchSubCriteria.createSampleCriteria(sampleCriteria) - ); - datasetCriteria.addSubCriteria( - SearchSubCriteria.createExperimentCriteria(experimentCriteria) - ); - - // Search - mainController.openbisV1.searchForDataSets(datasetCriteria, function (response) { - - // Get the containers - if (response.error || response.result.length === 0) { - return null; - } + }); + } - // All MICROSCOPY_IMG_CONTAINER datasets (i.e. a file series) contain a MICROSCOPY_IMG_OVERVIEW - // and a MICROSCOPY_IMG dataset; one of the series will also contain a MICROSCOPY_IMG_THUMBNAIL, - // which is what we are looking for here. - // Even though the MICROSCOPY_IMG_THUMBNAIL is always created for series 0, we cannot guarantee - // here that series zero will be returned as the first. We quickly scan through the returned - // results for the MICROSCOPY_IMG_CONTAINER that has three contained datasets. - // From there we can then quickly retrieve the MICROSCOPY_IMG_THUMBNAIL. - for (var i = 0; i < response.result.length; i++) { - var series = response.result[i]; - for (var j = 0; j < series.containedDataSets.length; j++) { - if (series.containedDataSets[j].dataSetTypeCode === "MICROSCOPY_IMG_THUMBNAIL") { - action(series.containedDataSets[j]); - return; + }); + }); + } } - } - } - }); - + }); + }); } -}); +}); \ No newline at end of file