Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sowmya | A-1205582341920482 | UAT Feedback - Alerts for unsaved observation #737

Merged
merged 6 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ui/app/clinical/consultation/views/bacteriology.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<i class="fa fa-info-circle"></i>
<span ng-bind-html="'BACTERIOLOGY_NOT_ALLOWED_IN_RETROSPECTIVE_MESSAGE'|translate"></span>
</div>
<div ng-repeat="newSpecimen in newSpecimens track by $id(newSpecimen)" class="sample-container">
<form class="form" name="bacteriologyForm" alert-on-exit>
<section class="section-grid">
<form class="form" name="bacteriologyForm" alert-on-exit>
<div ng-repeat="newSpecimen in newSpecimens track by $id(newSpecimen)" class="sample-container">
<section class="section-grid">
<div class="section-title-wrapper clearfix">
<h2 class="section-title fl">{{'BACTERIOLOGY_TAB_TITLE_KEY' | translate}}</h2>
<input type="button" value="{{'BACTERIOLOGY_BUTTON_CLEAR_KEY' | translate}}"
Expand Down Expand Up @@ -83,8 +83,8 @@ <h2 class="section-title fl">{{'BACTERIOLOGY_TAB_TITLE_KEY' | translate}}</h2>
</div>
</div>
</section>
</form>
</div>
</div>
</form>
<div ng-repeat="savedSpecimen in savedSpecimens" class="savedSpecimens-container clearfix" ng-hide="isOnDashboard">
<div class="fl savedSpecimens-text">
<span>{{getDisplayName(savedSpecimen)}}</span>
Expand Down
16 changes: 14 additions & 2 deletions ui/app/common/concept-set/directives/conceptSet.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

angular.module('bahmni.common.conceptSet')
.directive('conceptSet', ['contextChangeHandler', 'appService', 'observationsService', 'messagingService', 'conceptSetService', 'conceptSetUiConfigService', 'spinner',
function (contextChangeHandler, appService, observationsService, messagingService, conceptSetService, conceptSetUiConfigService, spinner) {
.directive('conceptSet', ['contextChangeHandler', 'appService', 'observationsService', 'messagingService', 'conceptSetService', 'conceptSetUiConfigService', 'spinner', '$state',
function (contextChangeHandler, appService, observationsService, messagingService, conceptSetService, conceptSetUiConfigService, spinner, $state) {
var controller = function ($scope) {
var conceptSetName = $scope.conceptSetName;
var ObservationUtil = Bahmni.Common.Obs.ObservationUtil;
Expand Down Expand Up @@ -412,6 +412,18 @@ angular.module('bahmni.common.conceptSet')
deregisterAddMore();
cleanUpListenerShowPrevious();
});

$scope.$on('$stateChangeStart', function () {
if ($scope.obsForm && $scope.obsForm.$dirty) {
$state.dirtyConsultationForm = true;
}
});

$scope.$on("event:changes-saved", function () {
if ($scope.obsForm) {
$scope.obsForm.$dirty = false;
}
});
};

return {
Expand Down
69 changes: 67 additions & 2 deletions ui/app/common/concept-set/directives/formControls.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

angular.module('bahmni.common.conceptSet')
.directive('formControls', ['formService', 'spinner', '$timeout', '$translate',
function (formService, spinner, $timeout, $translate) {
.directive('formControls', ['formService', 'spinner', '$timeout', '$translate', '$state', 'messagingService', 'exitAlertService',
function (formService, spinner, $timeout, $translate, $state, messagingService, exitAlertService) {
var loadedFormDetails = {};
var loadedFormTranslations = {};
var unMountReactContainer = function (formUuid) {
Expand Down Expand Up @@ -78,6 +78,71 @@ angular.module('bahmni.common.conceptSet')
}
}
});
function checkGroupMembers (formObservation, consultationObservation) {
var isGroupMemberChanged = [];
if (formObservation.groupMembers && formObservation.groupMembers.length > 0 && consultationObservation.groupMembers && consultationObservation.groupMembers.length > 0) {
for (var formGroupIndex = 0; formGroupIndex < formObservation.groupMembers.length; formGroupIndex++) {
var formGroupMember = formObservation.groupMembers[formGroupIndex];
for (var consultationGroupIndex = 0; consultationGroupIndex < consultationObservation.groupMembers.length; consultationGroupIndex++) {
var consultationGroupMember = consultationObservation.groupMembers[consultationGroupIndex];
(formGroupMember.value && formGroupMember.value.uuid && consultationGroupMember.value && consultationGroupMember.value.uuid) ?
isGroupMemberChanged[formGroupIndex] = (consultationGroupMember.value.uuid === formGroupMember.value.uuid) ? false : true :
isGroupMemberChanged[formGroupIndex] = (consultationGroupMember.value === formGroupMember.value) ? false : true;
if (!isGroupMemberChanged[formGroupIndex]) {
break;
}
}
}
return isGroupMemberChanged.includes(true) ? true : false;
} else {
if (formObservation.value && formObservation.value.uuid && consultationObservation.value && consultationObservation.value.uuid) {
return (consultationObservation.value.uuid === formObservation.value.uuid) ? false : true;
} else {
return (consultationObservation.value === formObservation.value) ? false : true;
}
}
}

function checkFormChanges ($scope) {
var isChanged = [];
$scope.dirtyForm = false;
if ($scope.form.observations.length > 0) {
if ($scope.$parent.consultation.observations.length === 0) {
return true;
}
for (var formIndex = 0; formIndex < $scope.form.observations.length; formIndex++) {
var formObservation = $scope.form.observations[i];
for (var consultationIndex = 0; consultationIndex < $scope.$parent.consultation.observations.length; consultationIndex++) {
var consultationObservation = $scope.$parent.consultation.observations[consultationIndex];
isChanged[formIndex] = checkGroupMembers(formObservation, consultationObservation);
if (!isChanged[formIndex]) {
break;
}
}
}
return isChanged.includes(true);
}
}

$scope.$on('$stateChangeStart', function (event, next, current) {
var uuid = $state.params.patientUuid;
var currentUuid = current.patientUuid;
if ($scope.form.component) {
var formObservations = $scope.form.component.getValue();
$scope.form.observations = formObservations.observations;
}
if (!$scope.changesSaved) {
$scope.dirtyForm = checkFormChanges($scope);
}
var isNavigating = exitAlertService.setIsNavigating(next, uuid, currentUuid);
$state.dirtyConsultationForm = $state.discardChanges ? false : $scope.dirtyForm;
exitAlertService.showExitAlert(isNavigating, $state.dirtyConsultationForm, event, next.spinnerToken);
});

$scope.$on("event:changes-saved", function () {
$scope.changesSaved = true;
$scope.dirtyForm = false;
});
};

return {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/common/concept-set/views/conceptSet.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form novalidate>
<form name="obsForm" novalidate alert-on-exit>
<div ng-if="::showEmptyConceptSetMessage" class="placeholder-text">{{::conceptSetName}} {{ 'CONCEPT_NOT_FOUND_MESSAGE'|translate }}</div>

<concept concept-set-required="conceptSetRequired" root-observation="rootObservation" patient="::patient"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

describe("Form Controls", function () {
var element, scope, $compile, spinner, provide, formService, renderHelper, translate;
var element, scope, $compile, spinner, provide, formService, renderHelper, translate, $state;

beforeEach(
function () {
Expand All @@ -16,6 +16,7 @@ describe("Form Controls", function () {
};
provide.value('spinner', spinner);
provide.value('$translate', translate);
provide.value('$state', $state);
});

inject(function (_$compile_, $rootScope) {
Expand Down
13 changes: 12 additions & 1 deletion ui/test/unit/common/concept-set/directives/conceptSet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe("conceptSet", function () {
var appService, spinner, conceptSetUiConfigService, contextChangeHandler, observationsService,
messagingService, compile, scope, conceptSetService, httpBackend,element, compiledElementScope;
messagingService, compile, scope, conceptSetService, httpBackend,element, compiledElementScope, $state;

beforeEach(function () {
module('bahmni.common.conceptSet');
Expand All @@ -21,11 +21,22 @@ describe("conceptSet", function () {
$provide.value('messagingService', messagingService);
$provide.value('conceptSetUiConfigService', conceptSetUiConfigService);
$provide.value('spinner', spinner);
$provide.value('$state', $state);
});
inject(function ($compile, $rootScope, $httpBackend) {
compile = $compile;
scope = $rootScope.$new();
httpBackend = $httpBackend;
scope.obsForm = { $dirty: true };
});
it("should set dirtyConsultationForm flag when state changes with dirty form", function () {
scope.$broadcast("$stateChangeStart");
expect($state.dirtyConsultationForm).toBeTruthy();
});

it("should reset form's dirty state on changes saved event", function () {
scope.$broadcast("event:changes-saved");
expect(scope.obsForm.$dirty).toBe(false);
});
});
beforeEach(function () {
Expand Down