diff --git a/plasmid/source/core-plugins/newbrowser/1/as/initialize-master-data.py b/plasmid/source/core-plugins/newbrowser/1/as/initialize-master-data.py index 90d740da575c411e3bfdf13fa3af6e50c07b6142..84c12bedda6bf950b8a93cd508f6955e927bdd15 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/initialize-master-data.py +++ b/plasmid/source/core-plugins/newbrowser/1/as/initialize-master-data.py @@ -30,4 +30,7 @@ elnExperimentTypeS.setGeneratedCodePrefix('C') # The default experiment used by the UI, assigned automatically to new samples folderType = tr.getOrCreateNewExperimentType("ELN_FOLDER") -folderType.setDescription("Folder") \ No newline at end of file +folderType.setDescription("Folder") + +# Preview Image +tr.getOrCreateNewDataSetType("ELN_PREVIEW") diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/img/image_loading.gif b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/img/image_loading.gif new file mode 100644 index 0000000000000000000000000000000000000000..cf370f3bab7181e92f1ba61b2ada3a7776494f33 Binary files /dev/null and b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/img/image_loading.gif differ diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/img/image_unavailable.png b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/img/image_unavailable.png new file mode 100644 index 0000000000000000000000000000000000000000..937697162b18c8f81191e773e418e02c7e6d5cda Binary files /dev/null and b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/img/image_unavailable.png differ diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js index c1df34659ebb49a20f83a96019dfb413c950495b..22d54e9f84b16d3ced0972e539a80cbbcc06c5f3 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js @@ -248,6 +248,47 @@ function ServerFacade(openbisServer) { return result; } + this.searchDataSetsWithTypeForSamples = function(dataSetTypeCode, samplesPermIds, callbackFunction) + { + var sampleMatchClauses = [] + + samplesPermIds.forEach(function(samplesPermId){ + sampleMatchClauses.push({ + "@type":"AttributeMatchClause", + fieldType : "ATTRIBUTE", + attribute : "PERM_ID", + desiredValue : samplesPermId + }); + }); + + var sampleCriteria = { + matchClauses : sampleMatchClauses, + operator : "MATCH_ANY_CLAUSES" + } + + var sampleSubCriteria = { + "@type" : "SearchSubCriteria", + "targetEntityKind" : "SAMPLE", + "criteria" : sampleCriteria + } + + var dataSetMatchClauses = [{ + "@type":"AttributeMatchClause", + fieldType : "ATTRIBUTE", + attribute : "TYPE", + desiredValue : dataSetTypeCode + }] + + var dataSetCriteria = + { + matchClauses : dataSetMatchClauses, + subCriterias : [ sampleSubCriteria ], + operator : "MATCH_ALL_CLAUSES" + }; + + this.openbisServer.searchForDataSets(dataSetCriteria, callbackFunction) + } + this.searchWithUniqueId = function(sampleIdentifier, callbackFunction) { var matchClauses = [ diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleTable.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleTable.js index 9bf3a0774384ad6b556440d5d9c8e6b250b25eb5..40ec3d6a0df723b67bf6d0ece7d9d5b2638bc4ee 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleTable.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleTable.js @@ -145,7 +145,7 @@ function SampleTable(serverFacade, sampleTableId, profile, sampleTypeCode, inspe Util.blockUI(); var localReference = this; this.serverFacade.searchWithType(this.sampleTypeCode, null, function(data) { - localReference.reloadWithSamples(data); + localReference.reloadWithSamples(data); Util.unblockUI(); }); } @@ -205,7 +205,7 @@ function SampleTable(serverFacade, sampleTableId, profile, sampleTypeCode, inspe $("#tableContainer").append("<div class='wrapper' style='clear: both; padding-top: 10px;'>"); var tableTemplate = "<table style='width:100%;' class='table table-hover' id=\"sample-table\"><thead>"; - tableTemplate += "<tr class=\"sample-table-header interactive\"><th sort-attribute='code'>Code</th>"; + tableTemplate += "<tr class=\"sample-table-header interactive\"><th sort-attribute='code'>Code</th><th sort-attribute=''>Preview</th>"; for (var i = 0; i < sampleTypePropertiesDisplayNames.length; i++) { tableTemplate += "<th sort-property='" + sampleTypeProperties[i] + "'>" + sampleTypePropertiesDisplayNames[i]+ "</th>"; } @@ -371,11 +371,10 @@ function SampleTable(serverFacade, sampleTableId, profile, sampleTypeCode, inspe .on("click", onClickFunction) .selectAll("td").data(function(sample) { var tableFields = null; - if(localReference.isSearch) { - tableFields = [sample.code, sample.sampleTypeCode, sample.properties, sample.properties ]; + tableFields = [sample.code, "<img data-preview-loaded='false' id='preview"+sample.identifier.replace(/\//g,'-')+"' src='./img/image_loading.gif' style='height:80px;'></img>", sample.sampleTypeCode, sample.properties, sample.properties ]; } else { - tableFields = [sample.code]; + tableFields = [sample.code, "<img data-preview-loaded='false' id='preview"+sample.identifier.replace(/\//g,'-')+"' src='./img/image_loading.gif' style='height:80px;'></img>"]; for(var i=0; i<sampleTypeProperties.length; i++) { var tableFieldValue = sample.properties[sampleTypeProperties[i]]; if(!tableFieldValue) { @@ -450,7 +449,7 @@ function SampleTable(serverFacade, sampleTableId, profile, sampleTypeCode, inspe .attr("class", "sample-table-data-cell") .html( function(d, index) { - if (localReference.isSearch && index == 2) { + if (localReference.isSearch && index == 3) { if (searchText && searchText.length > 0 && d) { for (propertyName in d) { var propertyValue = d[propertyName]; @@ -473,7 +472,7 @@ function SampleTable(serverFacade, sampleTableId, profile, sampleTypeCode, inspe } } } - } else if (localReference.isSearch && index == 3) { + } else if (localReference.isSearch && index == 4) { if (searchText && searchText.length > 0 && d) { for (propertyName in d) { @@ -745,5 +744,51 @@ function SampleTable(serverFacade, sampleTableId, profile, sampleTypeCode, inspe this._start = start; this._samplesToPaint = this._filteredSamples.slice(this._start, this._start + this._limit); this.repaint(); + this._reloadPreviewImages(); + } + + this._updateLoadingToNotAvailableImage = function() { + var notLoadedImages = $("[data-preview-loaded='false']"); + notLoadedImages.attr('src', "./img/image_unavailable.png"); + } + + this._reloadPreviewImages = function() { + var _this = this; + var previewCallback = function(data) { + var requestChain = []; + data.result.forEach(function(dataset) { requestChain.push( + function() { + var listFilesForDataSetCallback = function(dataFiles) { + var elementId = 'preview'+dataset.sampleIdentifierOrNull.replace(/\//g,'-'); + var downloadUrl = _this.profile.allDataStores[0].downloadUrl + '/' + dataset.code + "/" + dataFiles.result[1].pathInDataSet + "?sessionID=" + _this.serverFacade.getSession(); + + var img = $("#" + elementId); + img.attr('src', downloadUrl); + img.attr('data-preview-loaded', 'true'); + + //Run next + var next = requestChain.pop(); + if (next) { + next(); + } else { + _this._updateLoadingToNotAvailableImage(); + } + }; + _this.serverFacade.listFilesForDataSet(dataset.code, "/", true, listFilesForDataSetCallback); + } + );}); + //Run first + var next = requestChain.pop(); + if (next) { + next(); + } else { + _this._updateLoadingToNotAvailableImage(); + } + }; + + var samplePermIds = []; + this._samplesToPaint.forEach(function(sample) {samplePermIds.push(sample.permId);}); + + this.serverFacade.searchDataSetsWithTypeForSamples("ELN_PREVIEW", samplePermIds, previewCallback); } }