Skip to content

Commit

Permalink
Merge branch 'develop' into remove_toggle_button
Browse files Browse the repository at this point in the history
  • Loading branch information
AmTryingMyBest authored Apr 17, 2020
2 parents ed1b222 + 1362818 commit 0064aaf
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 13 deletions.
6 changes: 4 additions & 2 deletions app/common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1520,8 +1520,10 @@
"save_attribute_success" : "Field {{name}} added",
"edit_form_success" : "Survey {{name}} updated",
"edit_stage_success" : "Survey task {{name}} updated",
"delete_form_confirm" : "Are you sure you want to delete this survey?",
"delete_form_confirm_desc" : "This action cannot be undone. Deleting this survey will remove all of its data, including posts.",
"delete_form_confirm" : "Are you sure you want to delete this survey and all of its data?",
"delete_form_confirm_desc" : "This action cannot be undone. Deleting this survey will remove all of its data, including posts. Write the name of the survey: <br><br><strong>{{check_name}}</strong><br><br>in the box below to confirm deletion.",
"delete_form_error": "The text you entered does not match the survey-name, please try again",
"delete_form_button": "Delete this survey",
"destroy_form_success" : "Survey {{name}} deleted",
"delete_stage_confirm" : "Are you sure you want to delete this task?",
"delete_stage_confirm_desc" : "This action cannot be undone. Deleting this task will remove all of its fields, and any data in them.",
Expand Down
46 changes: 44 additions & 2 deletions app/common/notifications/notify.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function Notify(_, $q, $rootScope, $translate, SliderService, ModalService, Demo
infoModal: infoModal,
confirmLeave: confirmLeave,
demo: demo,
notifyPermanent: notifyPermanent
notifyPermanent: notifyPermanent,
deleteWithInput: deleteWithInput
};

function notify(message, translateValues) {
Expand Down Expand Up @@ -217,7 +218,49 @@ function Notify(_, $q, $rootScope, $translate, SliderService, ModalService, Demo

return deferred.promise;
}
function deleteWithInput (type, checkName) {
var scope = getScope();
var deferred = $q.defer();
scope.isEqual = true;

const modalText = {
survey: {
title: 'notify.form.delete_form_confirm',
modalBody: 'notify.form.delete_form_confirm_desc',
errorLabel: 'notify.form.delete_form_error',
button: 'notify.form.delete_form_button'
}
};

var texts = modalText[type];

$translate(texts.modalBody, {check_name: checkName}).then(show, show);

function show(body) {
scope.confirm = function (name) {
scope.isEqual = name === checkName;
if (scope.isEqual) {
deferred.resolve();
ModalService.close();
}
};

scope.cancel = function () {
deferred.reject();
ModalService.close();
};

ModalService.openTemplate(
`<div class="form-field">
<p>${body}</p>
<p class="alert error" ng-show="!isEqual" translate>${texts.errorLabel}</p>
<input class="form-field" type="text" name="survey" ng-model="name">
<button class="button-destructive button-flat" ng-click="$parent.confirm(name)" translate>${texts.button}</button>
<button class="button-flat" ng-click="$parent.cancel()" translate="message.button.cancel">Cancel</button>
</div>`, texts.title, false, scope, false, false);
}
return deferred.promise;
}

function confirmDelete(confirmText, confirmWarningText, translateValues) {
var deferred = $q.defer();
Expand All @@ -227,7 +270,6 @@ function Notify(_, $q, $rootScope, $translate, SliderService, ModalService, Demo
translateValues = confirmWarningText;
confirmWarningText = false;
}

$translate(confirmText, translateValues).then(show, show);

function show(confirmText) {
Expand Down
21 changes: 19 additions & 2 deletions app/main/posts/views/filters/filter-form.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ function FormSelectDirective(FormEndpoint) {
};

function FormSelectLink(scope, element, attrs, ngModel) {
scope.checkAll = true;
if (!ngModel) {
return;
}

scope.forms = [];
scope.selectedForms = [];

scope.toggleAll = toggleAll;
activate();

function toggleAll() {
if (!scope.checkAll) {
scope.checkAll = true;
Array.prototype.splice.apply(scope.selectedForms, [0, scope.selectedForms.length].concat(scope.forms.map(f => f.id).concat('none')));
} else {
scope.checkAll = false;
Array.prototype.splice.apply(scope.selectedForms, [0, scope.selectedForms.length]);
}
}
function activate() {
// Load forms
scope.forms = FormEndpoint.query();
Expand All @@ -35,6 +44,14 @@ function FormSelectDirective(FormEndpoint) {
}

function saveValueToView(selectedForms) {
// the length +1 check is because we add 'none' through ng-models for unknown survey type (messages with no post)
// this "fixes" the usecase where the user manually selected/unselected all checkboxes
const sameValues = selectedForms.length === scope.forms.length + 1;
if (!sameValues && scope.checkAll === true) {
scope.checkAll = false;
} else if (sameValues && scope.checkAll === false) {
scope.checkAll = true;
}
ngModel.$setViewValue(angular.copy(selectedForms));
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/main/posts/views/filters/filter-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

<div class="form-field checkbox" ng-show="forms.length > 5">
<label>
<input type="checkbox" name="selectedForms" ng-model="all"><em><span translate="category.select_all"></span></em>
<input type="checkbox" name="selectedForms" ng-checked="checkAll" ng-click="toggleAll()"><em><span translate="category.select_all"></span></em>
</label>
</div>
<div class="form-field checkbox" ng-repeat="(index, form) in forms">
<label>
<input checklist-value="form.id" checklist-model="selectedForms" type="checkbox" name="selectedForms" ng-checked="all"> <bdi>{{ ::form.name }}</bdi>
<input checklist-value="form.id" checklist-model="selectedForms" type="checkbox" name="selectedForms"> <bdi>{{ ::form.name }}</bdi>
</label>
</div>
<div class="form-field checkbox">
<label>
<input checklist-value="'none'" checklist-model="selectedForms" type="checkbox" name="selectedForms" ng-checked="all" > <span translate="nav.unknown">Unknown</span>
<input checklist-value="'none'" checklist-model="selectedForms" type="checkbox" name="selectedForms"> <span translate="nav.unknown">Unknown</span>
</label>
</div>
</fieldset>
2 changes: 1 addition & 1 deletion app/settings/surveys/surveys.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function (
};

$scope.deleteSurvey = function (survey) {
Notify.confirmDelete('notify.form.delete_form_confirm', 'notify.form.delete_form_confirm_desc').then(function () {
Notify.deleteWithInput('survey', survey.name).then(function () {
// If we haven't saved the survey
// just go back to the surveys views
if (!survey.id) {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/common/notifications/notify.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ describe('Notify', function () {
});
});

describe('deleteWithInput', function () {
beforeEach(function () {
spyOn(mockModalService, 'openTemplate').and.callThrough();
spyOn(mockSliderService, 'openTemplate').and.callThrough();
});

it('Calls ModalService.openTemplate with error message', function () {
mockModalService.state = false;
Notify.deleteWithInput('survey', 'this is the name of the survey');
$rootScope.$digest();
expect(mockModalService.openTemplate).toHaveBeenCalled();
});
});


describe('limit', function () {
beforeEach(function () {
spyOn(mockSliderService, 'openTemplate').and.callThrough();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ describe('user profile directive', function () {
describe('with a successful backend call', function () {
beforeEach(function () {
spyOn(UserEndpoint, 'update').and.callThrough();
spyOn(Session, 'setSessionDataEntries').and.callThrough();
spyOn(Notify, 'apiErrors')
spyOn(Notify, 'notify').and.callThrough();
});

describe('after changed values of user', function () {
beforeEach(function () {
isolateScope.user.realname = 'Changed name';
isolateScope.user.email = '[email protected]';
});

describe('after calling saveUser', function () {
Expand All @@ -60,19 +64,54 @@ describe('user profile directive', function () {
});

it('should call "update" on the UserEndpoint with id=me and the changed user profile values', function () {
expect(UserEndpoint.update).toHaveBeenCalled();
expect(UserEndpoint.update).toHaveBeenCalledWith(
{id: 'me'},
jasmine.objectContaining({
'email': '[email protected]',
'realname': 'Changed name'
}
)
);
expect(isolateScope.user.realname).toBe('Changed name');
expect(isolateScope.user.email).toBe('[email protected]');
expect(Notify.notify).toHaveBeenCalledWith('user_profile.update_success');
expect(Notify.apiErrors).toHaveBeenCalledTimes(0)
expect(Session.setSessionDataEntries).toHaveBeenCalledWith(
{'email': '[email protected]', 'realname': 'Changed name'}
);
});

it('should set user to the new data', function () {
expect(isolateScope.user.someField).toBe('addedByServer');
});
});
});

describe('after changed the password of the user', function () {
beforeEach(function () {
isolateScope.user.password = 'changed';
});

describe('after calling saveUser', function () {
beforeEach(function () {
isolateScope.saveUser(isolateScope.user);
});

it('should call "update" on the UserEndpoint with the changed password', function () {
expect(UserEndpoint.update).toHaveBeenCalledWith(
{id: 'me'},
jasmine.objectContaining({
'password': 'changed'
}
)
);
expect(Notify.apiErrors).toHaveBeenCalledTimes(0)
});
});
});
});

describe('with an error on the backend call', function () {

var errorResponse = {
status: 400,
data: {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/mock/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ module.exports = [function () {
successCallback({
realname: 'Changed name',
id: 1,
someField: 'addedByServer'
someField: 'addedByServer',
email: '[email protected]'
});
} else {
failCallback({
Expand Down

0 comments on commit 0064aaf

Please sign in to comment.