Skip to content

Commit

Permalink
Replace "Delete" in the actions for contacts from the contact group p…
Browse files Browse the repository at this point in the history
…age with "Remove".
  • Loading branch information
Ethan Young committed Feb 10, 2014
1 parent ae02b8d commit 3d529a6
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Source/Tests/JsTests/ContactGroups/ContactGroupsTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,21 @@
expect(instance.Members.length).toBe(1);
expect(instance.Members[0].ContactIdentifier).toBe(contactIdentifier);
});

it('should remove a contact group member when removeMember is called with a contact identifier', function() {
var contactIdentifier1 = 'id1';
var contactIdentifier2 = 'id2';
var contactIdentifier3 = 'id3';

instance.addMember(contactIdentifier1);
instance.addMember(contactIdentifier2);
instance.addMember(contactIdentifier3);

instance.removeMember(contactIdentifier2);

expect(instance.Members.length).toBe(2);
expect(instance.Members[0].ContactIdentifier).toBe(contactIdentifier1);
expect(instance.Members[1].ContactIdentifier).toBe(contactIdentifier3);
});
});
});
105 changes: 105 additions & 0 deletions Source/Tests/JsTests/Contacts/ContactsAppTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,4 +840,109 @@
expect(mockAlertsService.addInfo).toHaveBeenCalledWith('Addition of a new member to the contact group has been cancelled.');
});
});

describe('removeContactGroupMemberController', function() {
var $scope, $routeParams, createController;

var contactGroupIdentifier = 'id1';
var contactGroup = {
Identifier: contactGroupIdentifier,
Name: 'My Contacts',
removeMember: jasmine.createSpy(),
$update: function (callback) { callback(); }
};

var contactIdentifier = 'id2';
var contact = {
Identifier: contactIdentifier,
FirstName: 'Joe',
LastName: 'One'
};

beforeEach(inject(function ($injector) {
mockContactGroupsResource.get = function () { return contactGroup; };
spyOn(contactGroup, '$update').andCallThrough();

mockContactsResource.get = function () { return contact; };

$scope = $injector.get('$rootScope');

$routeParams = $injector.get('$routeParams');
$routeParams.contactGroupIdentifier = contactGroupIdentifier;
$routeParams.contactIdentifier = contactIdentifier;

var $controller = $injector.get('$controller');

createController = function () {
return $controller('removeContactGroupMemberController', { $scope: $scope, $routeParams: $routeParams });
};
}));

it('should set the default origin to the contact group overview page', function () {
var controller = createController();

expect(mockTasksService.setDefaultOrigin).toHaveBeenCalledWith('/contactGroups/' + contactGroupIdentifier);
});

it('should set a contact group on the scope when given a contact group', function () {
var controller = createController();

expect($scope.contactGroup).toBe(contactGroup);
});

it('should set a contact on the scope when given a contact', function() {
var controller = createController();

expect($scope.contact).toBe(contact);
});

it('should remove the contact from the group when continue is clicked', function() {
var controller = createController();

$scope.continue();

expect(contactGroup.removeMember).toHaveBeenCalledWith(contactIdentifier);
});

it('should update the contact group when continue is clicked', function () {
var controller = createController();

$scope.continue();

expect(contactGroup.$update).toHaveBeenCalled();
});

it('should redirect back when continue is clicked and the operation is successful', function () {

var controller = createController();

$scope.continue();

expect(mockTasksService.redirectBack).toHaveBeenCalled();
});

it('should add a success alert when continue is clicked and the operation is successful', function () {
var controller = createController();

$scope.continue();

expect(mockAlertsService.addSuccess).toHaveBeenCalledWith('The contact has been removed from the contact group.');
});

it('should redirect back when cancel is clicked', function () {
var controller = createController();

$scope.cancel();

expect(mockTasksService.redirectBack).toHaveBeenCalled();
});

it('should add an info alert when cancel is clicked', function () {
var controller = createController();

$scope.cancel();

expect(mockAlertsService.addInfo).toHaveBeenCalledWith('Removal of a contact from the contact group has been cancelled.');
});
});
});
42 changes: 41 additions & 1 deletion Source/Web/Content/ContactGroups/ContactGroupOverview.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,45 @@ <h1>Contact Group Overview</h1>
<a ng-href="#/contactGroups/{{contactGroup.Identifier}}/addMember" class="btn btn-primary btn-xs pull-right">Add New Contact</a>
Contacts
</div>
<ey-contact-list contacts="contactGroupMembers"></ey-contact-list>
<div class="panel-body" ng-hide="contactGroupMembers.length">
There are no contacts.
</div>
<table class="table table-condensed table-striped" ng-show="contactGroupMembers.length">
<thead>
<tr>
<th>Actions</th>
<th>First</th>
<th>Last</th>
<th>Primary Email</th>
<th>Primary Phone</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="contact in contactGroupMembers">
<td>
<div class="btn-group">
<a ey-start-task="/edit/{{contact.Identifier}}" class="btn btn-primary btn-xs">Edit</a>
<a class="btn btn-primary btn-xs dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li role="presentation"><a role="menuitem" tabindex="-1" ey-start-task="/contactGroups/{{contactGroup.Identifier}}/removeMember/{{contact.Identifier}}">Remove</a></li>
</ul>
</div>
</td>
<td>{{contact.FirstName}}</td>
<td>{{contact.LastName}}</td>
<td>
<span ng-repeat="contactEmailAddress in contact.EmailAddresses | filter : { IsPrimary: true }">
{{contactEmailAddress.EmailAddress}} <span ng-show="contactEmailAddress.NickName">({{contactEmailAddress.NickName}})</span>
</span>
</td>
<td>
<span ng-repeat="contactPhoneNumber in contact.PhoneNumbers | filter : { IsPrimary: true }">
{{contactPhoneNumber.PhoneNumber}} <span ng-show="contactPhoneNumber.NickName">({{contactPhoneNumber.NickName}})</span>
</span>
</td>
</tr>
</tbody>
</table>
</div>
9 changes: 9 additions & 0 deletions Source/Web/Content/ContactGroups/ContactGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ eyContactGroups.factory('ContactGroups', ['$resource', 'apiRootUrl', function ($
ContactGroups.prototype.addMember = function(contactIdentifier) {
this.Members.push({ ContactIdentifier: contactIdentifier });
};

ContactGroups.prototype.removeMember = function(contactIdentifier) {
for (var i = 0; i < this.Members.length; i++) {
if (this.Members[i].ContactIdentifier == contactIdentifier) {
this.Members.splice(i, 1);
return;
}
}
};

return ContactGroups;
}]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Remove {{contact.FirstName}} {{contact.LastName}} from {{contactGroup.Name}}</h1>
<p>
Removing a contact from a contact group will not delete the contact. Removing a contact from a contact group cannot be undone.
</p>
<button type="submit" class="btn btn-primary" ng-click="continue()">Continue</button>
<button type="submit" class="btn btn-info" ng-click="cancel()">Cancel</button>
26 changes: 26 additions & 0 deletions Source/Web/Content/Contacts/ContactsApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ contactsApp.config(['$routeProvider', function($routeProvider) {
templateUrl: '/Content/ContactGroups/AddContactGroupMemberView.html',
controller: 'addContactGroupMemberController'
}).
when('/contactGroups/:contactGroupIdentifier/removeMember/:contactIdentifier', {
templateUrl: '/Content/ContactGroups/RemoveContactGroupMemberView.html',
controller: 'removeContactGroupMemberController'
}).
otherwise({
redirectTo: '/contactGroups'
});
Expand Down Expand Up @@ -224,4 +228,26 @@ contactsApp.controller('addContactGroupMemberController', ['$scope', '$routePara
alerts.addInfo('Addition of a new member to the contact group has been cancelled.');
tasks.redirectBack();
};
}]);

contactsApp.controller('removeContactGroupMemberController', ['$scope', '$routeParams', 'tasks', 'alerts', 'ContactGroups', 'Contacts', function($scope, $routeParams, tasks, alerts, ContactGroups, Contacts) {
tasks.setDefaultOrigin('/contactGroups/' + $routeParams.contactGroupIdentifier);

$scope.contactGroup = ContactGroups.get({ contactGroupIdentifier: $routeParams.contactGroupIdentifier });

$scope.contact = Contacts.get({ contactIdentifier: $routeParams.contactIdentifier });

$scope.continue = function () {
$scope.contactGroup.removeMember($routeParams.contactIdentifier);

$scope.contactGroup.$update(function () {
alerts.addSuccess('The contact has been removed from the contact group.');
tasks.redirectBack();
});
};

$scope.cancel = function () {
alerts.addInfo('Removal of a contact from the contact group has been cancelled.');
tasks.redirectBack();
};
}]);
1 change: 1 addition & 0 deletions Source/Web/Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
<Content Include="Content\ContactGroups\AddContactGroupMemberView.html" />
<Content Include="Content\ContactGroups\ContactGroupOverview.html" />
<Content Include="Content\ContactGroups\ContactGroups.js" />
<Content Include="Content\ContactGroups\RemoveContactGroupMemberView.html" />
<Content Include="Content\ContactGroups\RenameContactGroupView.html" />
<Content Include="Content\ContactGroups\CreateContactGroupView.html" />
<Content Include="Content\ContactGroups\DeleteContactGroupView.html" />
Expand Down

0 comments on commit 3d529a6

Please sign in to comment.