Skip to content

Commit

Permalink
chamnge the record editor edit item to take an item
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Mar 29, 2019
1 parent b6880ef commit 9021a31
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 29 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Expand Up @@ -2,6 +2,12 @@

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

The PatientListCtrl now does the logic of whether to create a new item or edit an item within the
controller before it calls the record editor.

### 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
4 changes: 2 additions & 2 deletions doc/docs/reference/javascript/episode_service.md
Expand Up @@ -61,9 +61,9 @@ episode.recordEditor.newItem('diagnosis'):
// -> Opens a modal with the diagnosis form and will create a new diagnosis on save
```

#### Episode.recordEditor.editItem(name, index)
#### Episode.recordEditor.editItem(name, item)

Open a modal from which the user may edit the `index-th` item of type `name`.
Open a modal from which the user may edit the item of type `name`.

```js
episode.recordEditor.editItem('diagnosis', 0);
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
4 changes: 2 additions & 2 deletions opal/templates/_helpers/record_panel.html
Expand Up @@ -14,7 +14,7 @@ <h3>
<span ng-show="{{ editable }}" >
{% if singleton %}
<i class="fa fa-pencil edit pull-right pointer"
ng-click="parent.recordEditor.editItem('{{ name }}', 0)"></i>
ng-click="parent.recordEditor.editItem('{{ name }}', parent.{{ name }}[0])"></i>
{% else %}
<i class="fa fa-plus-circle edit pull-right pointer"
ng-click="parent.recordEditor.newItem('{{ name }}')"></i>
Expand Down 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
4 changes: 2 additions & 2 deletions opal/templates/_helpers/record_timeline.html
Expand Up @@ -5,7 +5,7 @@ <h3>
{% if editable %}
{% if singleton %}
<i class="fa fa-pencil edit pull-right pointer"
ng-click="episode.recordEditor.editItem('{{ name }}', 0)"></i>
ng-click="episode.recordEditor.editItem('{{ name }}', episode.{{ name }}[0])"></i>
{% else %}
<i class="fa fa-plus-circle edit pull-right pointer"
ng-click="episode.recordEditor.newItem('{{ name }}')"></i>
Expand All @@ -29,7 +29,7 @@ <h3>
<div class="col-md-3 patient-timeline">
<a
class="pointer"
ng-click="episode.recordEditor.editItem('{{ name }}', $index)">
ng-click="episode.recordEditor.editItem('{{ name }}', item)">
<div class="patient-timeline-speech-bubble">
<i class="fa fa-comments patient-timeline-speech-bubble-icon"></i>
</div>
Expand Down
2 changes: 1 addition & 1 deletion opal/templates/detail/inpatient.html
Expand Up @@ -27,7 +27,7 @@ <h3>
<h3>
<i class="fa fa-map-marker"></i> Location
<i class="fa fa-pencil edit pull-right"
ng-click="episode.recordEditor.editItem('location', 0)"></i>
ng-click="episode.recordEditor.editItem('location', episode.location[0])"></i>
</h3>
</div>
<div class="panel-body">
Expand Down
2 changes: 1 addition & 1 deletion opal/templates/partials/_demographics_panel.html
Expand Up @@ -3,7 +3,7 @@
<h3>
<i class="fa fa-user"></i> Demographics
<i class="fa fa-pencil edit pull-right"
ng-click="patient.recordEditor.editItem('demographics', 0)"></i>
ng-click="patient.recordEditor.editItem('demographics', patient.demographics[0])"></i>
</h3>
</div>
<div class="panel-body">
Expand Down
2 changes: 1 addition & 1 deletion opal/templates/partials/_location_panel.html
Expand Up @@ -3,7 +3,7 @@
<h3>
<i class="fa fa-map-marker"></i> Location
<i class="fa fa-pencil edit pull-right"
ng-click="episode.recordEditor.editItem('location', 0)"></i>
ng-click="episode.recordEditor.editItem('location', episode.location[0])"></i>
</h3>
</div>
<div class="panel-body">
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 9021a31

Please sign in to comment.