{"action":"created","issue":{"url":"https://api.github.com/repos/compucorp/civihr-employee-portal/issues/347","repository_url":"https://api.github.com/repos/compucorp/civihr-employee-portal","labels_url":"https://api.github.com/repos/compucorp/civihr-employee-portal/issues/347/labels{/name}","comments_url":"https://api.github.com/repos/compucorp/civihr-employee-portal/issues/347/comments","events_url":"https://api.github.com/repos/compucorp/civihr-employee-portal/issues/347/events","html_url":"https://github.com/compucorp/civihr-employee-portal/pull/347","id":252586531,"number":347,"title":"PCHR-2457: Document open buttons take very long to load on ssp","user":{"login":"bmnepali","id":6307362,"avatar_url":"https://avatars2.githubusercontent.com/u/6307362?v=4","gravatar_id":"","url":"https://api.github.com/users/bmnepali","html_url":"https://github.com/bmnepali","followers_url":"https://api.github.com/users/bmnepali/followers","following_url":"https://api.github.com/users/bmnepali/following{/other_user}","gists_url":"https://api.github.com/users/bmnepali/gists{/gist_id}","starred_url":"https://api.github.com/users/bmnepali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmnepali/subscriptions","organizations_url":"https://api.github.com/users/bmnepali/orgs","repos_url":"https://api.github.com/users/bmnepali/repos","events_url":"https://api.github.com/users/bmnepali/events{/privacy}","received_events_url":"https://api.github.com/users/bmnepali/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-08-24T12:33:04Z","updated_at":"2017-08-24T13:23:42Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/compucorp/civihr-employee-portal/pulls/347","html_url":"https://github.com/compucorp/civihr-employee-portal/pull/347","diff_url":"https://github.com/compucorp/civihr-employee-portal/pull/347.diff","patch_url":"https://github.com/compucorp/civihr-employee-portal/pull/347.patch"},"body":"## Overview\r\nIn SSP at the Task and Documents page we display a spinner until we get all the documents (target and assignee contact and are cached). That's why the spinner is displayed before \"open\" button is displayed.\r\n\r\nThe problem is it takes too long to load the data since we are currently collecting contacts form all documents. This PR fixes it by doing the following things:- \r\n- Displays the spinner in the button until we have at least one contact.\r\n- The contacts for the document are cached once we click open document modal button.\r\n\r\n## Before\r\n1. Takes more time to fetch and cache the contacts in the document displaying spinner longer in place of open button.\r\n![2457-before](https://user-images.githubusercontent.com/6307362/29666255-3f3d7478-88f7-11e7-87cf-5fabf91aa8f9.gif)\r\n\r\n## After\r\n1. Displays the spinner in place on button till we have at least one contact in SSP i.e current logged in contact.\r\n![2457-after](https://user-images.githubusercontent.com/6307362/29666301-6cb60424-88f7-11e7-80d8-3b083e147f47.gif)\r\n\r\n## Technical Details\r\n1. Remove code to get all the documents on `init` and replace with a code to collect the contact and cache them instead:\r\n```js\r\n/**\r\n * Collect required contact  and cache them for document modal\r\n */\r\nfunction cacheContacts (documents) {\r\n   DocumentService.cacheContactsAndAssignments(documents, 'contacts');\r\n};\r\n```\r\n2. Update the contact list when we get a document data, after we click the open button to open modal document.\r\n```js\r\nfunction modalDocument (id, role, mode) {\r\n   ...\r\n   DocumentService.get({ id: id })\r\n      .then(function(data) {\r\n         ...\r\n         vm.cacheContacts([data]);\r\n         vm.openModalDocument(data[0], role, mode);\r\n      })\r\n      ...\r\n};\r\n```\r\n## Comments\r\nAs part of this PR, few extra things have been fixed:\r\n1. Display spinner until we have at least one contact in place of open button.\r\n```js\r\n$rootScope.$watch('cache.contact', function () {\r\n    var availableContacts = $rootScope.cache.contact.arrSearch.length >= 1;\r\n    $rootScope.$broadcast('ct-spinner-' + (availableContacts ? 'hide' : 'show'));\r\n    vm.loadingModalData = !availableContacts;\r\n});\r\n```\r\n\r\n2. As the controller name of Document Modal Controller has been changed in T&A, as we are reusing it in SSP, the controller name is updated.\r\n```js\r\ncontroller: 'ModalDocumentController',\r\n```"},"comment":{"url":"https://api.github.com/repos/compucorp/civihr-employee-portal/issues/comments/324633529","html_url":"https://github.com/compucorp/civihr-employee-portal/pull/347#issuecomment-324633529","issue_url":"https://api.github.com/repos/compucorp/civihr-employee-portal/issues/347","id":324633529,"user":{"login":"bmnepali","id":6307362,"avatar_url":"https://avatars2.githubusercontent.com/u/6307362?v=4","gravatar_id":"","url":"https://api.github.com/users/bmnepali","html_url":"https://github.com/bmnepali","followers_url":"https://api.github.com/users/bmnepali/followers","following_url":"https://api.github.com/users/bmnepali/following{/other_user}","gists_url":"https://api.github.com/users/bmnepali/gists{/gist_id}","starred_url":"https://api.github.com/users/bmnepali/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmnepali/subscriptions","organizations_url":"https://api.github.com/users/bmnepali/orgs","repos_url":"https://api.github.com/users/bmnepali/repos","events_url":"https://api.github.com/users/bmnepali/events{/privacy}","received_events_url":"https://api.github.com/users/bmnepali/received_events","type":"User","site_admin":false},"created_at":"2017-08-24T13:23:42Z","updated_at":"2017-08-24T13:23:42Z","body":"@igor I think no there is no such circumstances. We are storing the contacts in $rootScope.contacts and we are using it display the contact name in modal. And when we update anything the modal and click save, the page is refreshed."}}
{"actor":{"display_login":"bmnepali"}}