Skip to content

Commit

Permalink
Merge a838e80 into b6880ef
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Mar 28, 2019
2 parents b6880ef + a838e80 commit a3c797e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 21 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Expand Up @@ -2,6 +2,9 @@

A User's UserProfile is now automatically created when you create a user in a post save signal.

RecordEditor.editItem will now take an item or an index rather than just an index.
Taking an index has been deprecated and will be removed in v0.15.0

### 0.13.1 (Minor Release)

Upgrades the setup.py Django version from 2.0.9 to 2.0.13. Removes the six library dependency from setup.py.
Expand Down
13 changes: 10 additions & 3 deletions opal/static/js/opal/controllers/patient_list.js
Expand Up @@ -378,9 +378,16 @@ angular.module('opal.controllers').controller(
}
};

episode.recordEditor.editItem(name, iix).then(function(result){
reset_state(result);
});
if(iix === episode[name].length){
episode.recordEditor.newItem(name);
}
else{
var item = episode[name][iix];

episode.recordEditor.editItem(name, item).then(function(result){
reset_state(result);
});
}
};

function goUp() {
Expand Down
11 changes: 9 additions & 2 deletions opal/static/js/opal/services/record_editor.js
@@ -1,5 +1,5 @@
angular.module('opal.services').factory('RecordEditor', function(
$http, $q, Item, $modal, $rootScope, $routeParams,
$http, $q, Item, $modal, $rootScope, $routeParams, $log,
UserProfile){
"use strict";
var RecordEditor = function(episode){
Expand Down Expand Up @@ -56,7 +56,14 @@ angular.module('opal.services').factory('RecordEditor', function(
};

self.editItem = function(name, iix){
var item = self.getItem(name, iix);
var item;
if(_.isNumber(iix)){
$log.warn("The ability to pass in an index to recordEditor.editItem will be removed in Opal v0.15.0, please pass in an item");
item = self.getItem(name, iix);
}
else{
item = iix;
}
return self.openEditItemModal(item, name);
};

Expand Down
8 changes: 4 additions & 4 deletions opal/static/js/test/patient_list.controller.test.js
Expand Up @@ -59,6 +59,7 @@ describe('PatientListCtrl', function() {
var promise = deferred.promise

spyOn(episode.recordEditor, 'editItem').and.returnValue(promise);
spyOn(episode.recordEditor, 'newItem').and.returnValue(promise);
spyOn($cookies, 'put').and.stub();


Expand Down Expand Up @@ -791,7 +792,6 @@ describe('PatientListCtrl', function() {

describe('newNamedItem', function(){
it('should pass through the current scopes tags', function(){
spyOn(episode.recordEditor, "newItem");
$scope.newNamedItem(episode, "someName");
expect(episode.recordEditor.newItem).toHaveBeenCalledWith("someName")
});
Expand All @@ -812,7 +812,7 @@ describe('PatientListCtrl', function() {
it('should call through to the record editor', function(){
$scope.editNamedItem($scope.episode, 'demographics', 0);
expect($scope.episode.recordEditor.editItem).toHaveBeenCalledWith(
'demographics', 0
'demographics', $scope.episode.demographics[0]
);
});

Expand All @@ -828,8 +828,8 @@ describe('PatientListCtrl', function() {
it('should call through to the record editor when we add an item', function() {
var iix = episodeData.diagnosis.length;
$scope.editNamedItem($scope.episode, "diagnosis", iix);
expect($scope.episode.recordEditor.editItem).toHaveBeenCalledWith(
'diagnosis', iix
expect($scope.episode.recordEditor.newItem).toHaveBeenCalledWith(
'diagnosis'
);
});
});
Expand Down
44 changes: 34 additions & 10 deletions opal/static/js/test/record_editor_test.js
Expand Up @@ -6,7 +6,7 @@ describe('RecordEditor', function(){
var Flow, Episode, episode;
var controller, UserProfile;
var opalTestHelper;
var profile;
var profile, $log;

var episodeData = {
id: 123,
Expand Down Expand Up @@ -95,6 +95,7 @@ describe('RecordEditor', function(){
$q = $injector.get('$q');
UserProfile = $injector.get('UserProfile');
opalTestHelper = $injector.get('opalTestHelper');
$log = $injector.get('$log');
});

profile = opalTestHelper.getUserProfile();
Expand All @@ -105,14 +106,15 @@ describe('RecordEditor', function(){
};
});

spyOn($log, "warn");

episode = opalTestHelper.newEpisode($rootScope);
// $rootScope.fields = fields;
// episode = new Episode(angular.copy(episodeData));
});

describe("edit item", function(){
describe("edit item", function(){
it('should open the EditItemCtrl', function(){
it('should open the EditItemCtrl with an index but warn', function(){
var deferred, callArgs;
deferred = $q.defer();
deferred.resolve();
Expand All @@ -129,16 +131,40 @@ describe('RecordEditor', function(){
episode.recordEditor.editItem('diagnosis', 1);
$scope.$digest();
callArgs = $modal.open.calls.mostRecent().args;
var expected = "The ability to pass in an index to recordEditor.editItem will be removed in Opal v0.15.0, please pass in an item";
expect($log.warn).toHaveBeenCalledWith(expected);
expect(callArgs.length).toBe(1);
expect(callArgs[0].controller).toBe('EditItemCtrl');
expect(callArgs[0].templateUrl).toBe('/templates/modals/diagnosis.html/');
var resolves = callArgs[0].resolve;
expect(resolves.item()).toEqual(episode.recordEditor.getItem('diagnosis', 1));
expect(resolves.episode()).toEqual(episode);
expect(resolves.metadata(fakeMetadaa)).toEqual("some metadata");
expect(resolves.referencedata(fakeReferencedata)).toEqual( "some reference data");
});

it('should open the EditItemCtrl with an item', function(){
var deferred, callArgs;
deferred = $q.defer();
deferred.resolve();
var modalPromise = deferred.promise;
var fakeMetadaa = {
load: function(){ return "some metadata"; }
};

var fakeReferencedata = {
load: function(){ return "some reference data"; }
};

spyOn($modal, 'open').and.returnValue({result: modalPromise} );
episode.recordEditor.editItem('diagnosis', episode.diagnosis[0]);
$scope.$digest();
callArgs = $modal.open.calls.mostRecent().args;
expect(callArgs.length).toBe(1);
expect(callArgs[0].controller).toBe('EditItemCtrl');
expect(callArgs[0].templateUrl).toBe('/templates/modals/diagnosis.html/');
var resolves = callArgs[0].resolve;
expect(resolves.item()).toEqual(episode.diagnosis[0]);
expect(resolves.episode()).toEqual(episode);
expect(resolves.metadata(fakeMetadaa)).toEqual("some metadata");
expect(resolves.referencedata(fakeReferencedata)).toEqual( "some reference data");
});

it('should pull modal size through from the schema if it exists', function() {
var deferred, callArgs;
deferred = $q.defer();
Expand Down Expand Up @@ -239,8 +265,6 @@ describe('RecordEditor', function(){
expect($rootScope.state).toBe('normal');
expect(called).toBe(true);
});
});

});

describe("get item", function(){
Expand Down
2 changes: 1 addition & 1 deletion opal/templates/_helpers/record_panel.html
Expand Up @@ -42,7 +42,7 @@ <h3>
<span ng-show="{{ editable }}" >
{% if not singleton %}
<i class="fa fa-pencil edit pull-right pointer"
ng-click="parent.recordEditor.editItem('{{ name }}', $index)"></i>
ng-click="parent.recordEditor.editItem('{{ name }}', item)"></i>
{% endif %}
</span>
</div>
Expand Down
Expand Up @@ -164,7 +164,7 @@ <h4 class="print-only">
{% if column.model_column %}
<ul>
<li ng-repeat="item in row.{{column.name}} {% if column.list_limit %} |limitTo:{{ column.list_limit }}{% endif %} track by $index"
ng-dblclick="editNamedItem(row, '{{column.name}}', $index);$event.stopPropagation()"
ng-dblclick="editNamedItem(row, item);$event.stopPropagation()"
>
{% include column.template_path %}
</li>
Expand Down

0 comments on commit a3c797e

Please sign in to comment.