Skip to content
This repository has been archived by the owner on Apr 5, 2018. It is now read-only.

Commit

Permalink
Feature/multi test json support (#113)
Browse files Browse the repository at this point in the history
Adds multi test parameters support:
* View test parameter files in file tab
* Add/Update/Delete test parameter files for a given version
  • Loading branch information
agduncan94 authored Nov 23, 2016
1 parent 73f7d8a commit 6eb808d
Show file tree
Hide file tree
Showing 19 changed files with 553 additions and 277 deletions.
37 changes: 21 additions & 16 deletions app/scripts/controllers/containerfileviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,17 @@ angular.module('dockstore.ui')
);
};

$scope.getTestJson = function(containerId, tagName, descType) {
$scope.getTestJson = function(containerId, tagName, descType, filePath, fileType) {
return ContainerService.getTestJson(containerId, tagName, descType)
.then(
function(testJson) {
$scope.fileContents = testJson;
return testJson;
for (var i = 0; i < testJson.length; i++) {
if (testJson[i].path === filePath && testJson[i].type === fileType) {
$scope.fileContents = testJson[i].content;
return testJson[i].content;
}
}
return undefined;
},
function(response) {
return $q.reject(response);
Expand Down Expand Up @@ -308,13 +313,13 @@ angular.module('dockstore.ui')
* This extracts a list of valid secondary files for a given tool, filtered by the selected tag and descriptor type
* Returns an empty array if there are not valid tags
*/
function extracted(){
function extracted(fileType){
if($scope.containerObj.tags.length !==0){
return $scope.containerObj.tags.filter(
function(a) {
return a.name === $scope.selTagName;})[0].sourceFiles.filter(
function(a) {
return a.type === 'DOCKSTORE_'+$scope.selDescriptorName.toUpperCase();}).map(
return a.type === '' + fileType;}).map(
function(a) {
return a.path;
}).sort();
Expand All @@ -332,13 +337,18 @@ angular.module('dockstore.ui')
$scope.descriptors = descriptors;
$scope.selDescriptorName = descriptors[0];
// prepare Descriptor Imports drop-down
$scope.secondaryDescriptors = extracted();
var fileType = $scope.selDescriptorName === 'cwl' ? 'DOCKSTORE_CWL' : 'DOCKSTORE_WDL';

$scope.secondaryDescriptors = extracted(fileType);
$scope.selSecondaryDescriptorName = $scope.secondaryDescriptors[0];
};

$scope.refreshDocument = function(versionChange) {
$scope.fileLoaded = false;
$scope.fileContents = null;
var testFileType = $scope.selDescriptorName === 'cwl' ? 'CWL_TEST_JSON' : 'WDL_TEST_JSON';
var fileType = $scope.selDescriptorName === 'cwl' ? 'DOCKSTORE_CWL' : 'DOCKSTORE_WDL';

switch ($scope.type) {
case 'dockerfile':
$scope.expectedFilename = 'Dockerfile';
Expand All @@ -347,24 +357,19 @@ angular.module('dockstore.ui')
case 'descriptor':
$scope.expectedFilename = 'Descriptor';
// prepare Descriptor Imports drop-down
$scope.secondaryDescriptors = extracted();
$scope.secondaryDescriptors = extracted(fileType);
if (versionChange === true) {
$scope.selSecondaryDescriptorName = $scope.secondaryDescriptors[0];
}
var file = $scope.getSecondaryDescriptorFile($scope.containerObj.id, $scope.selTagName, $scope.selDescriptorName, $scope.selSecondaryDescriptorName);
break;
case 'testparameter':
$scope.expectedFilename = 'Test Parameter File';
var testjson = $scope.getTestJson($scope.containerObj.id, $scope.selTagName, $scope.selDescriptorName);
if(testjson !== undefined){
testjson.then(function(s){
$scope.totalLines = s.split(/\n/).length;
$scope.setupLineNumbers();
},
function(e){
// console.log("error refreshDocument",e);
});
$scope.secondaryDescriptors = extracted(testFileType);
if (versionChange === true) {
$scope.selSecondaryDescriptorName = $scope.secondaryDescriptors[0];
}
var testjson = $scope.getTestJson($scope.containerObj.id, $scope.selTagName, $scope.selDescriptorName,$scope.selSecondaryDescriptorName, testFileType);
break;
default:
// ...
Expand Down
186 changes: 185 additions & 1 deletion app/scripts/controllers/tageditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,136 @@ angular.module('dockstore.ui')
$scope.getHRSize = FrmttSrvc.getHRSize;
$scope.getDateTimeString = FrmttSrvc.getDateTimeString;

// Items are the test parameter paths to display
$scope.cwlItems = [];
$scope.wdlItems = [];
// Values in database are the currently stored test parameter paths in the database
$scope.cwlValuesInDatabase = [];
$scope.wdlValuesInDatabase = [];

// Retrieve test parameter paths from the database and store to items array
$scope.getTestParameterFiles = function(type) {
if ($scope.tagObj !== undefined) {
return ContainerService.getTestJson($scope.containerId, $scope.tagObj.name, type)
.then(
function(testJson) {
if (type === 'CWL') {
$scope.cwlItems = [];
for (var i = 0; i < testJson.length; i++) {
$scope.cwlItems.push(testJson[i].path);
}
if (testJson.length === 0) {
$scope.cwlItems.push("");
}
} else if (type === 'WDL') {
$scope.wdlItems = [];
for (var j = 0; j < testJson.length; j++) {
$scope.wdlItems.push(testJson[j].path);
}
if (testJson.length === 0) {
$scope.wdlItems.push("");
}
}
},
function(response) {
return $q.reject(response);
}
);
}
};

// Retrieve test parameter paths from the database and store to ValuesInDatabase array
$scope.getDbTestParameterFiles = function(type) {
if ($scope.tagObj !== undefined) {
return ContainerService.getTestJson($scope.containerId, $scope.tagObj.name, type)
.then(
function(testJson) {
if (type === 'CWL') {
$scope.cwlValuesInDatabase = [];
for (var i = 0; i < testJson.length; i++) {
$scope.cwlValuesInDatabase.push(testJson[i].path);
}
} else if (type === 'WDL') {
$scope.wdlValuesInDatabase = [];
for (var j = 0; j < testJson.length; j++) {
$scope.wdlValuesInDatabase.push(testJson[j].path);
}
}
},
function(response) {
return $q.reject(response);
}
);
}
};

// Adds a blank text input for a new test parameter file
$scope.addTestParameterFile = function(type) {
if (type === 'CWL') {
if ($scope.cwlItems[$scope.cwlItems.length - 1] !== "") {
$scope.cwlItems.push("");
}
} else if (type === 'WDL') {
if ($scope.wdlItems[$scope.wdlItems.length - 1] !== "") {
$scope.wdlItems.push("");
}
}
};

// Removes a text input for a test parameter file
$scope.removeTestParameterFile = function(index, type) {
if (type === 'CWL') {
if (index > -1) {
$scope.cwlItems.splice(index, 1);
}
if ($scope.cwlItems.length === 0) {
$scope.cwlItems.push("");
}
} else if (type === 'WDL') {
if (index > -1) {
$scope.wdlItems.splice(index, 1);
}
if ($scope.wdlItems.length === 0) {
$scope.wdlItems.push("");
}
}
};

// Updates the database with the new set of test parameter files, removes any that have been deleted
$scope.updateTestParameterFiles = function() {
$scope.getDbTestParameterFiles('CWL').then(function() {
$scope.getDbTestParameterFiles('WDL').then(function() {
// Remove all blanks
while ($scope.cwlItems.indexOf("") !== -1) {
$scope.cwlItems.splice($scope.cwlItems.indexOf(""), 1);
}
while ($scope.wdlItems.indexOf("") !== -1) {
$scope.wdlItems.splice($scope.wdlItems.indexOf(""), 1);
}
var toRemoveCwl = [];
var toAddCwl = [];
var toRemoveWdl = [];
var toAddWdl = [];

toRemoveCwl = $($scope.cwlValuesInDatabase).not($scope.cwlItems);
toAddCwl = $scope.cwlItems;
toRemoveWdl = $($scope.wdlValuesInDatabase).not($scope.wdlItems);
toAddWdl = $scope.wdlItems;

$scope.removeTestParameterFileToDb(toRemoveCwl.toArray(), toAddCwl, 'CWL');
$scope.removeTestParameterFileToDb(toRemoveWdl.toArray(), toAddWdl, 'WDL');
});
});
};

$scope.saveTagChanges = function() {
if ($scope.savingActive) return;
$scope.savingActive = true;
return ContainerService.updateContainerTag($scope.containerId, $scope.tagObj)
.then(
function(versionTags) {
$scope.closeEditTagModal(true);
$scope.$emit('tagEditorRefreshContainer', $scope.containerId);
$scope.updateTestParameterFiles();
return versionTags;
},
function(response) {
Expand Down Expand Up @@ -120,4 +242,66 @@ angular.module('dockstore.ui')

$scope.setTagEditError(null);

// Initializes items with test parameter files from the version
$scope.setItems = function() {
$scope.getTestParameterFiles('CWL');
$scope.getTestParameterFiles('WDL');
};

// Update db with new test parameter files for the given tool and version
$scope.addTestParameterFileToDb = function(toAdd, type) {
if ($scope.tagObj !== undefined) {
return ContainerService.addTestJson($scope.containerId, $scope.tagObj.name, toAdd, type)
.then(
function(testParameterFiles) {
// Only refresh after WDL was checked
if (type === 'WDL') {
$scope.$emit('tagEditorRefreshContainer', $scope.containerId);
}
},
function(response) {
$scope.setTagEditError(
'The webservice encountered an error trying to modify test ' +
'parameter files for this tool, please ensure that the ' +
'test parameter paths are properly-formatted and do not ' +
'contain prohibited characters of words.',
'[HTTP ' + response.status + '] ' + response.statusText + ': ' +
response.data
);
return $q.reject(response);
}
);
}
};

// Remove from db test parameter files for the given tool and version
$scope.removeTestParameterFileToDb = function(toRemove, toAdd, type) {
if ($scope.tagObj !== undefined) {
return ContainerService.removeTestJson($scope.containerId, $scope.tagObj.name, toRemove, type)
.then(
function(testParameterFiles) {
$scope.addTestParameterFileToDb(toAdd, type);
},
function(response) {
$scope.setTagEditError(
'The webservice encountered an error trying to modify test ' +
'parameter files for this tool, please ensure that the ' +
'test parameter paths are properly-formatted and do not ' +
'contain prohibited characters of words.',
'[HTTP ' + response.status + '] ' + response.statusText + ': ' +
response.data
);
return $q.reject(response);
}
);
}
};

$scope.hasBlankPath = function(type) {
if (type === 'CWL') {
return ($scope.cwlItems.indexOf("") !== -1);
} else if (type === 'WDL') {
return ($scope.wdlItems.indexOf("") !== -1);
}
};
}]);
Loading

0 comments on commit 6eb808d

Please sign in to comment.