Skip to content

Commit

Permalink
Merge c373dc3 into 2137751
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Apr 16, 2019
2 parents 2137751 + c373dc3 commit d8b91a3
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 43 deletions.
9 changes: 9 additions & 0 deletions changelog.md
Expand Up @@ -2,6 +2,15 @@

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

RecordEditor.editItem, RecordEditor.editItem and RecordEditor.openEditItemModal to take a url argument.
This is the url of the template that should be opened with the edit item controller.

RecordEditor.editItem also 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
10 changes: 8 additions & 2 deletions doc/docs/reference/javascript/episode_service.md
Expand Up @@ -56,14 +56,20 @@ Example usage:

Takes a string, opens a modal from which the user can create a new subrecord of type `name`.

It takes the optional argument of `url` which is the url of the template to be opened. This defaults
to the modal form template for the subrecord of `name`.

```js
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 item of type `name`.

Open a modal from which the user may edit the `index-th` item of type `name`.
It takes the optional argument of `url` which is the url of the template to be opened. This defaults
to the modal form template for the subrecord of `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
25 changes: 17 additions & 8 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 All @@ -13,9 +13,11 @@ angular.module('opal.services').factory('RecordEditor', function(
}
};

self.openEditItemModal = function(item, name){
self.openEditItemModal = function(item, name, template_url){
$rootScope.state = 'modal';
var template_url = '/templates/modals/' + name + '.html/';
if(!template_url){
template_url = '/templates/modals/' + name + '.html/';
}

if($routeParams.slug){
template_url += $routeParams.slug;
Expand Down Expand Up @@ -55,12 +57,19 @@ angular.module('opal.services').factory('RecordEditor', function(
return deferred.promise;
};

self.editItem = function(name, iix){
var item = self.getItem(name, iix);
return self.openEditItemModal(item, name);
self.editItem = function(name, iix, url){
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, url);
};

self.newItem = function(name){
self.newItem = function(name, url){
var iix = episode[name].length;
var item = self.getItem(name, iix);

Expand All @@ -69,7 +78,7 @@ angular.module('opal.services').factory('RecordEditor', function(
deferred.resolve();
return deferred.promise;
}
return self.openEditItemModal(item, name);
return self.openEditItemModal(item, name, url);
};
};

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
64 changes: 46 additions & 18 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,40 +106,69 @@ 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();
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', 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 accept a url that is passed through to the modal open', function(){
var deferred, callArgs;
deferred = $q.defer();
deferred.resolve();
var modalPromise = deferred.promise;
spyOn($modal, 'open').and.returnValue({result: modalPromise} );
episode.recordEditor.editItem('diagnosis', 1, '/custom_template/');
$scope.$digest();
callArgs = $modal.open.calls.mostRecent().args;
expect(callArgs[0].templateUrl).toBe("/custom_template/")
});

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 +269,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 d8b91a3

Please sign in to comment.