Skip to content

Commit

Permalink
edit study titles
Browse files Browse the repository at this point in the history
  • Loading branch information
chinook25 committed May 13, 2019
1 parent 69a3ca7 commit e0587bf
Show file tree
Hide file tree
Showing 18 changed files with 436 additions and 33 deletions.
7 changes: 5 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus" : false, // true: Prohibit use of `++` and `--`
"quotmark" : false, // Quotation mark consistency:
"quotmark" : "single", // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : true, // Unused variables:
"unused" : "strict", // Unused variables:
// true : all variables, last function parameter
// "vars" : all variables only
// "strict" : all variables, all function parameters
Expand Down Expand Up @@ -72,10 +72,12 @@
"devel" : true, // Development/debugging (alert, confirm, etc)
"dojo" : false, // Dojo Toolkit
"jasmine" : true, // Jasmine
"jquery" : true, // jQuery
"mocha" : true, // Mocha
"mootools" : false, // MooTools
"node" : true, // Node.js
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
"phantom" : false, // PhantomJS
"prototypejs" : false, // Prototype and Scriptaculous
"qunit" : false, // QUnit
"rhino" : false, // Rhino
Expand All @@ -88,6 +90,7 @@
// Custom Globals
"globals" : {
"define" : false,
"describe" : true,
"require" : false,
"inject" : false,
"module" : false
Expand Down
3 changes: 3 additions & 0 deletions app/js/analyses/analyses.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define([
'./editAnalysisTitleController',
'./editOutcomeNameController',
'./deleteAnalysisController',
'./editStudyTitleController',
'./analysisResource',
'./problemResource',
'./analysisService',
Expand All @@ -25,6 +26,7 @@ define([
EditAnalysisTitleController,
EditOutcomeNameController,
DeleteAnalysisController,
EditStudyTitleController,
AnalysisResource,
ProblemResource,
AnalysisService,
Expand All @@ -45,6 +47,7 @@ define([
.controller('EditAnalysisTitleController', EditAnalysisTitleController)
.controller('EditOutcomeNameController', EditOutcomeNameController)
.controller('DeleteAnalysisController', DeleteAnalysisController)
.controller('EditStudyTitleController', EditStudyTitleController)

// resources
.factory('AnalysisResource', AnalysisResource)
Expand Down
4 changes: 4 additions & 0 deletions app/js/analyses/analysisResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ define([], function() {
setOutcome: {
url: '/analyses/:analysisId/setOutcome',
method: 'PUT'
},
setProblem: {
url: '/analyses/:analysisId/setProblem',
method: 'PUT'
}
});
};
Expand Down
29 changes: 29 additions & 0 deletions app/js/analyses/editStudyTitle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<form id="edit-study-title-form" novalidate ng-submit="editTitle(title.new)">
<div class="grid-container">
<div class="grid-x">
<div class="cell">
<h3>Edit study title</h3>
</div>
<div class="cell">
<label>Study title</label>
</div>
<div class="cell alert">
Changing the study title will delete all model results!
</div>
<div class="cell large-6">
<input autofocus="true" type="text" ng-model="title.new" ng-change="checkTitle(title.new)">
</div>
<div class="cell">
<button ng-disabled="error" ng-click="editTitle(title.new)" class="button" type="button">
Edit
</button>
</div>
<div class="cell alert" ng-if="error">
{{error}}
</div>
</div>
</div>
<button ng-click="cancel()" class="close-button" aria-label="Close reveal" type="button">
<span aria-hidden="true">&times;</span>
</button>
</form>
47 changes: 47 additions & 0 deletions app/js/analyses/editStudyTitleController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';
define(['lodash'], function(_) {
var dependencies = [
'$scope',
'$modalInstance',
'studyTitle',
'entries',
'callback'
];
var EditStudyTitleController = function(
$scope,
$modalInstance,
studyTitle,
entries,
callback
) {
// functions
$scope.cancel = $modalInstance.close;
$scope.editTitle = editTitle;
$scope.checkTitle = checkTitle;

// init
$scope.title = {
new: studyTitle
};

function checkTitle(newTitle) {
if (newTitle === '') {
$scope.error = 'Title is empty';
} else if (newTitle !== studyTitle && _.some(entries, ['study', newTitle])) {
$scope.error = 'Study with that title already exists';
} else {
$scope.error = undefined;
}
}

function editTitle() {
if ($scope.error) {
return;
}
callback($scope.title.new);
$modalInstance.close();
}

};
return dependencies.concat(EditStudyTitleController);
});
5 changes: 4 additions & 1 deletion app/js/analyses/evidenceTable.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<td rowspan="{{treatment.studyRowSpan}}" ng-show="{{treatment.showStudyColumn}}"
style="vertical-align: top;">
{{treatment.studyTitle}}
<a ng-click="editStudyTitle(treatment.studyTitle)" tooltip="Edit study title" ng-if="!editmode.disableEditing">
<i class="fa fa-edit"></i>
</a>
</td>
<td ng-repeat="covariate in treatment.covariatesColumns" rowspan="{{treatment.studyRowSpan}}"
ng-show="{{treatment.showStudyColumn}}" style="vertical-align:top" class="text-center">
Expand Down Expand Up @@ -59,4 +62,4 @@
</table>
</div>
</div>
</div>
</div>
56 changes: 49 additions & 7 deletions app/js/analyses/evidenceTableController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@
define(['lodash'], function(_) {
var dependencies = [
'$scope',
'$modal',
'$stateParams',
'AnalysisService',
'AnalysisResource',
'EvidenceTableService'
];
var EvidenceTableController = function(
$scope,
$modal,
$stateParams,
AnalysisService,
AnalysisResource,
EvidenceTableService
) {
// functions
$scope.editStudyTitle = editStudyTitle;

function matcherFactory(arg) {
return function(row) {
return row.evidence[arg];
};
}
// init
$scope.analysis.$promise.then(createEvidenceTable);

$scope.analysis.$promise.then(function() {
function createEvidenceTable() {
var studyMap = AnalysisService.problemToStudyMap($scope.analysis.problem);
var studies = EvidenceTableService.studyMapToStudyArray(studyMap);
$scope.outcomeType = EvidenceTableService.determineOutcomeType(studies);
Expand All @@ -27,8 +32,45 @@ define(['lodash'], function(_) {
$scope.showStdErr = _.find($scope.tableRows, matcherFactory('stdErr'));
$scope.showSampleSize = _.find($scope.tableRows, matcherFactory('sampleSize'));
$scope.showExposure = _.find($scope.tableRows, matcherFactory('exposure'));
});
}

function matcherFactory(arg) {
return function(row) {
return row.evidence[arg];
};
}

function editStudyTitle(title) {
$modal.open({
templateUrl: './editStudyTitle.html',
controller: 'EditStudyTitleController',
resolve: {
studyTitle: function() {
return title;
},
entries: function() {
var relativeEntries = $scope.analysis.problem.relativeEffectData ? EvidenceTableService.getRelativeEntries($scope.analysis.problem.relativeEffectData.data) : [];
return relativeEntries.concat($scope.analysis.problem.entries);
},
callback: function() {
return function(newTitle) {
var entries = $scope.analysis.problem.entries;
$scope.analysis.problem.entries = EvidenceTableService.getNewEntries(title, newTitle, entries);
var oldCovariate = $scope.analysis.problem.studyLevelCovariates[title];
delete $scope.analysis.problem.studyLevelCovariates[title];
$scope.analysis.problem.studyLevelCovariates[newTitle] = oldCovariate;
AnalysisResource.setProblem($stateParams, $scope.analysis.problem, function() {
_.forEach($scope.models, function(model) {
delete model.taskUrl;
delete model.runStatus;
});
createEvidenceTable();
});
};
}
}
});
}
};
return dependencies.concat(EvidenceTableController);
});
25 changes: 23 additions & 2 deletions app/js/analyses/evidenceTableService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ define(['angular', 'lodash'], function(angular, _) {
var EvidenceTableService = function() {

function determineOutcomeType(studyList) {
if(studyList[0].arms[0].data.responders) {
if (studyList[0].arms[0].data.responders) {
return studyList[0].arms[0].data.exposure ? 'survival' : 'dichotomous';
}
return 'continuous';
Expand Down Expand Up @@ -134,12 +134,33 @@ define(['angular', 'lodash'], function(angular, _) {
return tableRows;
}

function getRelativeEntries(relativeData) {
return _.map(relativeData, function(entry, title) {
return _.merge({}, entry, {
study: title
});
});
}

function getNewEntries(oldTitle, newTitle, entries) {
return _.map(entries, function(entry) {
if (entry.study !== oldTitle) {
return entry;
} else {
return _.merge({}, entry, {
study: newTitle
});
}
});
}

return {
determineOutcomeType: determineOutcomeType,
studyMapToStudyArray: studyMapToStudyArray,
studyListToEvidenceRows: studyListToEvidenceRows,
buildRelativeEffectDataRows: buildRelativeEffectDataRows
buildRelativeEffectDataRows: buildRelativeEffectDataRows,
getRelativeEntries: getRelativeEntries,
getNewEntries: getNewEntries
};

};
Expand Down
38 changes: 37 additions & 1 deletion app/js/analyses/evidenceTableServiceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ define(['angular', 'angular-mocks', 'gemtc-web/analyses/analyses'], function(ang
headerTitle: 'LENGTH_OF_FOLLOW_UP'
}, {
data: 1,
headerTitle: 'BLINDING_AT_LEAST_DOUBLE_BLIND'
headerTitle: 'BLINDING_AT_LEAST_DOUBLE_BLIND'
}]
};

Expand Down Expand Up @@ -359,5 +359,41 @@ define(['angular', 'angular-mocks', 'gemtc-web/analyses/analyses'], function(ang

});

describe('getRelativeEntries', function() {
it('should mutate the relative data object into an array of entries each with their key on them as a study parameter', function() {
var relativeData = {
study1: {},
study2: {}
};
var result = evidenceTableService.getRelativeEntries(relativeData);
var expectedResult = [{
study: 'study1'
}, {
study: 'study2'
}];
expect(result).toEqual(expectedResult);
});
});

describe('getNewEntries', function() {
it('should replace the study parameter with a given value for all entries with studies matching the old value', function() {
var oldTitle = 'old title';
var newTitle = 'new title';
var unchangedTitle = 'not changed';
var entries = [{
study: oldTitle
}, {
study: unchangedTitle
}];
var result = evidenceTableService.getNewEntries(oldTitle, newTitle, entries);
var expectedResult = [{
study: newTitle
}, {
study: unchangedTitle
}];
expect(result).toEqual(expectedResult);
});
});

});
});
5 changes: 4 additions & 1 deletion app/js/analyses/relativeEvidenceTable.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<td rowspan="{{treatment.studyRowSpan}}" ng-show="{{treatment.showStudyColumn}}"
style="vertical-align: top;">
{{treatment.studyTitle}}
<a ng-click="editStudyTitle(treatment.studyTitle)" tooltip="Edit study title" ng-if="!editmode.disableEditing">
<i class="fa fa-edit"></i>
</a>
</td>
<td ng-repeat="covariate in treatment.covariatesColumns" rowspan="{{treatment.studyRowSpan}}"
ng-show="{{treatment.showStudyColumn}}" style="vertical-align:top" class="text-center">
Expand All @@ -44,4 +47,4 @@
</table>
</div>
</div>
</div>
</div>
Loading

0 comments on commit e0587bf

Please sign in to comment.