This repository was archived by the owner on Mar 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Feature/sup 2754 allow hiding external links #597
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9822510
SUP-2754, [Edit Profile] Allow user to hide external links
4b96b72
Merge branch 'dev' into feature/sup-2754-allow-hiding-external-links
5d3b509
SUP-2754, [Edit Profile] Allow user to hide external links
140d7a7
SUP-2754, [Edit Profile] Allow user to hide external links
9d14022
SUP-2754, [Edit Profile] Allow user to hide external links
39051ac
SUP-2754, [Edit Profile] Allow user to hide external links
4a94b47
SUP-2754, [Edit Profile] Allow user to hide external links
1d8d029
SUP-2754, [Edit Profile] Allow user to hide external links
c91a8ee
Merge branch 'dev' into feature/sup-2754-allow-hiding-external-links
8ab9096
Merge branch 'dev' into feature/sup-2754-allow-hiding-external-links
c114361
SUP-2754, [Edit Profile] Allow user to hide external links
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 6 additions & 2 deletions
8
app/directives/external-account/external-link-data.directive.jade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/directives/external-account/external-link-deletion-confirm.jade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.deletion-confirmation | ||
.deletion-confirmation-title Heads Up! | ||
.deletion-confirmation-message Are you sure you want to delete the external link #[span.deletion-confirmation-account-title "{{vm.account.title}}"]? This action can't be undone later. | ||
.deletion-confirmation-buttons | ||
.deletion-confirmation-button-yes | ||
button.tc-btn.tc-btn-s.tc-btn-ghost(ng-click="vm.deleteAccount() && closeThisDialog()") Yes, Delete Link | ||
.deletion-confirmation-button-no | ||
button.tc-btn.tc-btn-s(ng-click="closeThisDialog()") Cancel |
51 changes: 51 additions & 0 deletions
51
app/directives/external-account/external-link-deletion.controller.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(function () { | ||
|
||
angular | ||
.module('tcUIComponents') | ||
.controller('ExternalLinkDeletionController', ExternalLinkDeletionController); | ||
|
||
ExternalLinkDeletionController.$inject = ['ExternalWebLinksService', '$q', '$log', 'toaster', 'ngDialog', 'userHandle', 'account', 'linkedAccountsData']; | ||
|
||
function ExternalLinkDeletionController(ExternalWebLinksService, $q, $log, toaster, ngDialog, userHandle, account, linkedAccountsData) { | ||
var vm = this; | ||
vm.account = account; | ||
$log = $log.getInstance("ExternalLinkDeletionController"); | ||
|
||
vm.deleteAccount = function() { | ||
$log.debug('Deleting Account...'); | ||
if (account && account.deletingAccount) { | ||
$log.debug('Another deletion is already in progress.'); | ||
return; | ||
} | ||
if (account && account.provider === 'weblink') { | ||
account.deletingAccount = true; | ||
$log.debug('Deleting weblink...'); | ||
return ExternalWebLinksService.removeLink(userHandle, account.key).then(function(data) { | ||
account.deletingAccount = false; | ||
$log.debug("Web link removed: " + JSON.stringify(data)); | ||
var toRemove = _.findIndex(linkedAccountsData, function(la) { | ||
return la.provider === 'weblink' && la.key === account.key; | ||
}); | ||
if (toRemove > -1) { | ||
// remove from the linkedAccountsData array | ||
linkedAccountsData.splice(toRemove, 1); | ||
} | ||
toaster.pop('success', "Success", "Your link has been removed."); | ||
}) | ||
.catch(function(resp) { | ||
var msg = resp.msg; | ||
if (resp.status === 'WEBLINK_NOT_EXIST') { | ||
$log.info("Weblink does not exist"); | ||
msg = "Weblink is not linked to your account. If you think this is an error please contact <a href=\"mailTo:[email protected]\">[email protected]</a>."; | ||
} else { | ||
$log.error("Fatal error: _unlink: " + msg); | ||
msg = "Sorry! We are unable to remove your weblink. If problem persists, please contact <a href=\"mailTo:[email protected]\">[email protected]</a>"; | ||
} | ||
|
||
account.deletingAccount = false; | ||
toaster.pop('error', "Whoops!", msg); | ||
}); | ||
} | ||
} | ||
} | ||
})(); |
190 changes: 190 additions & 0 deletions
190
app/directives/external-account/external-link-deletion.controller.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
/* jshint -W117, -W030 */ | ||
describe('External Link Deletion Controller', function() { | ||
var scope; | ||
var element; | ||
var toasterSvc, extLinkSvc, ngDialogSvc; | ||
var mockLinkedAccounts = [ | ||
{ | ||
provider: 'github', | ||
data: { | ||
handle: "github-handle", | ||
followers: 1, | ||
publicRepos: 1 | ||
} | ||
}, | ||
{ provider: 'stackoverflow', | ||
data: { | ||
handle: 'so-handle', | ||
reputation: 2, | ||
answers: 2 | ||
} | ||
}, | ||
{ | ||
provider: 'behance', | ||
data: { | ||
name: 'behance name', | ||
projectViews: 3, | ||
projectAppreciations: 3 | ||
} | ||
}, | ||
{ | ||
provider: 'dribbble', | ||
data: { | ||
handle: 'dribbble-handle', | ||
followers: 4, | ||
likes: 4 | ||
} | ||
}, | ||
{ | ||
provider: 'bitbucket', | ||
data: { | ||
username: 'bitbucket-username', | ||
followers: 5, | ||
repositories: 5 | ||
} | ||
}, | ||
{ | ||
provider: 'twitter', | ||
data: { | ||
handle: 'twitter-handle', | ||
noOfTweets: 6, | ||
followers: 6 | ||
} | ||
}, | ||
{ | ||
provider: 'linkedin', | ||
data: { | ||
status: 'pending' | ||
} | ||
}, | ||
{ | ||
provider: 'weblink', | ||
key: 'somekey' | ||
} | ||
]; | ||
var createController = function(toDelete, linkedAccounts) { | ||
return $controller('ExternalLinkDeletionController', { | ||
ExternalWebLinksService : extLinkSvc, | ||
toaster: toasterSvc, | ||
userHandle: 'test', | ||
account: toDelete, | ||
linkedAccountsData: linkedAccounts | ||
}); | ||
} | ||
|
||
beforeEach(function() { | ||
bard.appModule('topcoder'); | ||
bard.inject(this, '$compile', '$rootScope', 'toaster', 'ExternalWebLinksService', '$q', 'ngDialog', '$controller'); | ||
scope = $rootScope.$new(); | ||
|
||
extLinkSvc = ExternalWebLinksService; | ||
|
||
sinon.stub(extLinkSvc, 'removeLink', function(handle, key) { | ||
var $deferred = $q.defer(); | ||
if (key === 'throwNotExistsError') { | ||
$deferred.reject({ | ||
status: 'WEBLINK_NOT_EXIST', | ||
msg: 'profile not exists' | ||
}); | ||
} else if(key === 'throwFatalError') { | ||
$deferred.reject({ | ||
status: 'FATAL_ERROR', | ||
msg: 'fatal error' | ||
}); | ||
} else { | ||
$deferred.resolve({ | ||
status: 'SUCCESS' | ||
}); | ||
} | ||
return $deferred.promise; | ||
}); | ||
|
||
toasterSvc = toaster; | ||
bard.mockService(toaster, { | ||
pop: $q.when(true), | ||
default: $q.when(true) | ||
}); | ||
|
||
ngDialogSvc = ngDialog; | ||
sinon.stub(ngDialog, 'open', function() { | ||
ngDialog.deferredClose = $q.defer(); | ||
return { closePromise : ngDialog.deferredClose.promise }; | ||
}); | ||
sinon.stub(ngDialog, 'close', function() { | ||
ngDialog.deferredClose.resolve('closing'); | ||
return | ||
}) | ||
}); | ||
|
||
bard.verifyNoOutstandingHttpRequests(); | ||
|
||
describe('Linked external accounts', function() { | ||
var linkedAccounts = null; | ||
var externalLinksData; | ||
|
||
beforeEach(function() { | ||
linkedAccounts = angular.copy(mockLinkedAccounts); | ||
}); | ||
|
||
afterEach(function() { | ||
linkedAccounts = angular.copy(mockLinkedAccounts); | ||
}); | ||
|
||
it('should remove weblink ', function() { | ||
var toDelete = {key: 'somekey', provider: 'weblink'}; | ||
ctrl = createController(toDelete, linkedAccounts); | ||
ctrl.deleteAccount(); | ||
$rootScope.$apply(); | ||
expect(toasterSvc.pop).to.have.been.calledWith('success').calledOnce; | ||
expect(linkedAccounts).to.have.length(7); | ||
}); | ||
|
||
it('should show success if controller doesn\'t have weblink but API returns success ', function() { | ||
var toDelete = {key: 'somekey1', provider: 'weblink'}; | ||
ctrl = createController(toDelete, linkedAccounts); | ||
ctrl.deleteAccount(); | ||
$rootScope.$apply(); | ||
expect(toasterSvc.pop).to.have.been.calledWith('success').calledOnce; | ||
expect(linkedAccounts).to.have.length(8); | ||
}); | ||
|
||
it('should NOT remove weblink with fatal error ', function() { | ||
var toDelete = {key: 'throwFatalError', provider: 'weblink'}; | ||
ctrl = createController(toDelete, linkedAccounts); | ||
ctrl.deleteAccount(); | ||
$rootScope.$apply(); | ||
expect(toasterSvc.pop).to.have.been.calledWith('error', "Whoops!", sinon.match('Sorry!')).calledOnce; | ||
expect(linkedAccounts).to.have.length(8); | ||
}); | ||
|
||
it('should NOT remove weblink with already removed weblink ', function() { | ||
var toDelete = {key: 'throwNotExistsError', provider: 'weblink'}; | ||
ctrl = createController(toDelete, linkedAccounts); | ||
ctrl.deleteAccount(); | ||
$rootScope.$apply(); | ||
expect(toasterSvc.pop).to.have.been.calledWith('error', "Whoops!", sinon.match('not linked')).calledOnce; | ||
expect(linkedAccounts).to.have.length(8); | ||
}); | ||
|
||
it('should not do any thing when already a deletion is in progress ', function() { | ||
var toDelete = {key: 'somekey', provider: 'weblink', deletingAccount: true}; | ||
ctrl = createController(toDelete, linkedAccounts); | ||
ctrl.deleteAccount(); | ||
$rootScope.$apply(); | ||
expect(extLinkSvc.removeLink).not.to.be.called; | ||
expect(toasterSvc.pop).not.to.be.called; | ||
expect(linkedAccounts).to.have.length(8); | ||
}); | ||
|
||
it('should not do any thing for non weblink provider ', function() { | ||
var toDelete = {key: 'somekey', provider: 'stackoverflow'}; | ||
ctrl = createController(toDelete, linkedAccounts); | ||
ctrl.deleteAccount(); | ||
$rootScope.$apply(); | ||
expect(extLinkSvc.removeLink).not.to.be.called; | ||
expect(toasterSvc.pop).not.to.be.called; | ||
expect(linkedAccounts).to.have.length(8); | ||
}); | ||
|
||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing account to be deleted & deleteAccount() on scope, provide a controller to handle this. Additional tracking with $scope.toDelete seems error prone and not "encapsulated".
https://github.com/likeastore/ngDialog#controller-string--array--object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parthshah I thought of the same, but reason behind not using controller for this as of now, is that I was thinking of creating a generic directive for showing a confirmation popup. May be we can use ngDialog's openConfirm itself for this. However, I was not sure, if I can style it as per our requirements and it can take some more time, hence, I chose to implement directly in external links data directive. Please let me know, if you think it would be a good idea to have a generic directive for showing the confirmation popup.