{"action":"created","comment":{"url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/comments/42042137","id":42042137,"diff_hunk":"@@ -0,0 +1,205 @@\n+angular.module('bhima.services')\n+.service('JournalDataviewService', ['JournalDataLoaderService', 'JournalManagerService', '$translate',\n+  function (dataLoaderService, managerService, $translate) {\n+    var dataviewService = this;\n+    var inlineFilter = true;\n+\n+    dataviewService.aggregates = true;    \n+    dataviewService.gimp = new Slick.Data.GroupItemMetadataProvider(); //plugin to group metadata for slick grid\n+    dataviewService.dataLoaderService = dataLoaderService;\n+    dataviewService.managerService = managerService;\n+    dataviewService.dataview = new Slick.Data.DataView({\n+      groupItemMetadataProvider: dataviewService.gimp,\n+      inlineFilter: inlineFilter\n+    });\n+\n+\n+    dataviewService.setAggregate = function setAggregate (ans){\n+      dataviewService.aggregates = ans;\n+    };\n+\n+    dataviewService.getAggregate = function getAggregate (){\n+      return dataviewService.aggregates;\n+    };\n+\n+    dataviewService.subscribeToOnRowCountChanged = function subscribeToOnRowCountChanged (grid){\n+      if(!grid){throw 'Undefined grid';}\n+      dataviewService.dataview.onRowCountChanged.subscribe(function (e, args) {\n+        grid.updateRowCount();\n+        grid.render();\n+      });      \n+    };\n+\n+    dataviewService.subscribeToOnRowsChanged = function subscribeToOnRowsChanged (grid){\n+      if(!grid){throw 'Undefined grid';}\n+      dataviewService.dataview.onRowsChanged.subscribe(function (e, args) {\n+        grid.invalidateRows(args.rows);\n+        grid.render();\n+      });\n+    };\n+\n+    dataviewService.populate = function populate () {\n+      return dataviewService.dataLoaderService.loadJournalRecord()\n+      .then(function (data){\n+        data.journalRecord.data = data.journalRecord.data.map(function (item) {\n+          item.trans_date = new Date(item.trans_date);\n+          return item;\n+        });\n+        dataviewService.dataview.beginUpdate();\n+        dataviewService.dataview.setItems(data.journalRecord.data, 'uuid');\n+        dataviewService.dataview.endUpdate();   \n+      });      \n+    };\n+\n+    dataviewService.addNewItem = function addNewItem(row){\n+      dataviewService.dataview.addItem(row);\n+    };\n+\n+    dataviewService.getItem = function getItem(row){\n+      return dataviewService.dataview.getItem(row);\n+    };\n+\n+    dataviewService.getItems = function getItem(){","path":"client/src/js/services/journalDataviewService.js","position":62,"original_position":62,"commit_id":"a6e4b44bb1905fa5caf36902a431cf1507d63ad7","original_commit_id":"a6e4b44bb1905fa5caf36902a431cf1507d63ad7","user":{"login":"jniles","id":896472,"avatar_url":"https://avatars.githubusercontent.com/u/896472?v=3","gravatar_id":"","url":"https://api.github.com/users/jniles","html_url":"https://github.com/jniles","followers_url":"https://api.github.com/users/jniles/followers","following_url":"https://api.github.com/users/jniles/following{/other_user}","gists_url":"https://api.github.com/users/jniles/gists{/gist_id}","starred_url":"https://api.github.com/users/jniles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jniles/subscriptions","organizations_url":"https://api.github.com/users/jniles/orgs","repos_url":"https://api.github.com/users/jniles/repos","events_url":"https://api.github.com/users/jniles/events{/privacy}","received_events_url":"https://api.github.com/users/jniles/received_events","type":"User","site_admin":false},"body":"I notice that you duplicate a lot of methods from dataview --> dataviewService.  Is this easier than having a controller call `dataviewService.dataview.getItems()`? \r\n\r\nIf you think aliasing is advantageous, I recommend you use the exact same API as dataview. So, you can write this:\r\n```js\r\n// alias dataview properties for faster lookups\r\nservice.getItems = service.dataview.getItems;\r\nservice.getItem = service.dataview.getItem;\r\nservice.addItem = service.dataview.addItem;\r\nservice.updateItem = service.dataview.updateItem;\r\n// etc...\r\n```\r\nAvoiding changing the API will cause less confusion among programmers.  It also allows you to write compact code.  However, I'm not certain why a controller shouldn't just call `DataviewService.dataview.getItems()` anyway.","created_at":"2015-10-14T19:39:54Z","updated_at":"2015-10-14T19:39:54Z","html_url":"https://github.com/IMA-WorldHealth/bhima/pull/812#discussion_r42042137","pull_request_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/812","_links":{"self":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/comments/42042137"},"html":{"href":"https://github.com/IMA-WorldHealth/bhima/pull/812#discussion_r42042137"},"pull_request":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/812"}}},"pull_request":{"url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/812","id":47675159,"html_url":"https://github.com/IMA-WorldHealth/bhima/pull/812","diff_url":"https://github.com/IMA-WorldHealth/bhima/pull/812.diff","patch_url":"https://github.com/IMA-WorldHealth/bhima/pull/812.patch","issue_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/812","number":812,"state":"open","locked":false,"title":"Posting Journal Refactoring","user":{"login":"DedrickEnc","id":5418919,"avatar_url":"https://avatars.githubusercontent.com/u/5418919?v=3","gravatar_id":"","url":"https://api.github.com/users/DedrickEnc","html_url":"https://github.com/DedrickEnc","followers_url":"https://api.github.com/users/DedrickEnc/followers","following_url":"https://api.github.com/users/DedrickEnc/following{/other_user}","gists_url":"https://api.github.com/users/DedrickEnc/gists{/gist_id}","starred_url":"https://api.github.com/users/DedrickEnc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DedrickEnc/subscriptions","organizations_url":"https://api.github.com/users/DedrickEnc/orgs","repos_url":"https://api.github.com/users/DedrickEnc/repos","events_url":"https://api.github.com/users/DedrickEnc/events{/privacy}","received_events_url":"https://api.github.com/users/DedrickEnc/received_events","type":"User","site_admin":false},"body":"This PR is for the posting journal refactoring, the goal was to decrease the number of controller and to prioritize services using.\r\nSo after the refactoring, I created services to do : \r\n1. loading data\r\n2. handling grid\r\n3. handling the dataview\r\n4. handling session managent\r\n5. handling validation\r\nI will probably create an other service for ```Editor```\r\nWe have now three controllers : ```PostingJournalController, JournalUtilitieController``` and ```Journal.print```(not refactored yet, may be it will be transformed to a service).\r\n\r\nIt is very probable to find some mistakes that why the review is necessary also.","created_at":"2015-10-14T15:32:16Z","updated_at":"2015-10-14T19:39:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8ca978d5b2f5f77585e7167096b54d7340131f20","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/812/commits","review_comments_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/812/comments","review_comment_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/comments{/number}","comments_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/812/comments","statuses_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/statuses/a6e4b44bb1905fa5caf36902a431cf1507d63ad7","head":{"label":"DedrickEnc:pjournal","ref":"pjournal","sha":"a6e4b44bb1905fa5caf36902a431cf1507d63ad7","user":{"login":"DedrickEnc","id":5418919,"avatar_url":"https://avatars.githubusercontent.com/u/5418919?v=3","gravatar_id":"","url":"https://api.github.com/users/DedrickEnc","html_url":"https://github.com/DedrickEnc","followers_url":"https://api.github.com/users/DedrickEnc/followers","following_url":"https://api.github.com/users/DedrickEnc/following{/other_user}","gists_url":"https://api.github.com/users/DedrickEnc/gists{/gist_id}","starred_url":"https://api.github.com/users/DedrickEnc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DedrickEnc/subscriptions","organizations_url":"https://api.github.com/users/DedrickEnc/orgs","repos_url":"https://api.github.com/users/DedrickEnc/repos","events_url":"https://api.github.com/users/DedrickEnc/events{/privacy}","received_events_url":"https://api.github.com/users/DedrickEnc/received_events","type":"User","site_admin":false},"repo":{"id":26802027,"name":"bhima","full_name":"DedrickEnc/bhima","owner":{"login":"DedrickEnc","id":5418919,"avatar_url":"https://avatars.githubusercontent.com/u/5418919?v=3","gravatar_id":"","url":"https://api.github.com/users/DedrickEnc","html_url":"https://github.com/DedrickEnc","followers_url":"https://api.github.com/users/DedrickEnc/followers","following_url":"https://api.github.com/users/DedrickEnc/following{/other_user}","gists_url":"https://api.github.com/users/DedrickEnc/gists{/gist_id}","starred_url":"https://api.github.com/users/DedrickEnc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DedrickEnc/subscriptions","organizations_url":"https://api.github.com/users/DedrickEnc/orgs","repos_url":"https://api.github.com/users/DedrickEnc/repos","events_url":"https://api.github.com/users/DedrickEnc/events{/privacy}","received_events_url":"https://api.github.com/users/DedrickEnc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/DedrickEnc/bhima","description":"A full-featured hospital information system for developing countries.","fork":true,"url":"https://api.github.com/repos/DedrickEnc/bhima","forks_url":"https://api.github.com/repos/DedrickEnc/bhima/forks","keys_url":"https://api.github.com/repos/DedrickEnc/bhima/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DedrickEnc/bhima/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DedrickEnc/bhima/teams","hooks_url":"https://api.github.com/repos/DedrickEnc/bhima/hooks","issue_events_url":"https://api.github.com/repos/DedrickEnc/bhima/issues/events{/number}","events_url":"https://api.github.com/repos/DedrickEnc/bhima/events","assignees_url":"https://api.github.com/repos/DedrickEnc/bhima/assignees{/user}","branches_url":"https://api.github.com/repos/DedrickEnc/bhima/branches{/branch}","tags_url":"https://api.github.com/repos/DedrickEnc/bhima/tags","blobs_url":"https://api.github.com/repos/DedrickEnc/bhima/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DedrickEnc/bhima/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DedrickEnc/bhima/git/refs{/sha}","trees_url":"https://api.github.com/repos/DedrickEnc/bhima/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DedrickEnc/bhima/statuses/{sha}","languages_url":"https://api.github.com/repos/DedrickEnc/bhima/languages","stargazers_url":"https://api.github.com/repos/DedrickEnc/bhima/stargazers","contributors_url":"https://api.github.com/repos/DedrickEnc/bhima/contributors","subscribers_url":"https://api.github.com/repos/DedrickEnc/bhima/subscribers","subscription_url":"https://api.github.com/repos/DedrickEnc/bhima/subscription","commits_url":"https://api.github.com/repos/DedrickEnc/bhima/commits{/sha}","git_commits_url":"https://api.github.com/repos/DedrickEnc/bhima/git/commits{/sha}","comments_url":"https://api.github.com/repos/DedrickEnc/bhima/comments{/number}","issue_comment_url":"https://api.github.com/repos/DedrickEnc/bhima/issues/comments{/number}","contents_url":"https://api.github.com/repos/DedrickEnc/bhima/contents/{+path}","compare_url":"https://api.github.com/repos/DedrickEnc/bhima/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DedrickEnc/bhima/merges","archive_url":"https://api.github.com/repos/DedrickEnc/bhima/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DedrickEnc/bhima/downloads","issues_url":"https://api.github.com/repos/DedrickEnc/bhima/issues{/number}","pulls_url":"https://api.github.com/repos/DedrickEnc/bhima/pulls{/number}","milestones_url":"https://api.github.com/repos/DedrickEnc/bhima/milestones{/number}","notifications_url":"https://api.github.com/repos/DedrickEnc/bhima/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DedrickEnc/bhima/labels{/name}","releases_url":"https://api.github.com/repos/DedrickEnc/bhima/releases{/id}","created_at":"2014-11-18T09:37:59Z","updated_at":"2015-03-24T13:13:08Z","pushed_at":"2015-10-14T15:12:34Z","git_url":"git://github.com/DedrickEnc/bhima.git","ssh_url":"git@github.com:DedrickEnc/bhima.git","clone_url":"https://github.com/DedrickEnc/bhima.git","svn_url":"https://github.com/DedrickEnc/bhima","homepage":"","size":102876,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"development"}},"base":{"label":"IMA-WorldHealth:development","ref":"development","sha":"40ce6dc1faf417ffb644bcadf89b6b4c8037f233","user":{"login":"IMA-WorldHealth","id":5330583,"avatar_url":"https://avatars.githubusercontent.com/u/5330583?v=3","gravatar_id":"","url":"https://api.github.com/users/IMA-WorldHealth","html_url":"https://github.com/IMA-WorldHealth","followers_url":"https://api.github.com/users/IMA-WorldHealth/followers","following_url":"https://api.github.com/users/IMA-WorldHealth/following{/other_user}","gists_url":"https://api.github.com/users/IMA-WorldHealth/gists{/gist_id}","starred_url":"https://api.github.com/users/IMA-WorldHealth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IMA-WorldHealth/subscriptions","organizations_url":"https://api.github.com/users/IMA-WorldHealth/orgs","repos_url":"https://api.github.com/users/IMA-WorldHealth/repos","events_url":"https://api.github.com/users/IMA-WorldHealth/events{/privacy}","received_events_url":"https://api.github.com/users/IMA-WorldHealth/received_events","type":"Organization","site_admin":false},"repo":{"id":15043926,"name":"bhima","full_name":"IMA-WorldHealth/bhima","owner":{"login":"IMA-WorldHealth","id":5330583,"avatar_url":"https://avatars.githubusercontent.com/u/5330583?v=3","gravatar_id":"","url":"https://api.github.com/users/IMA-WorldHealth","html_url":"https://github.com/IMA-WorldHealth","followers_url":"https://api.github.com/users/IMA-WorldHealth/followers","following_url":"https://api.github.com/users/IMA-WorldHealth/following{/other_user}","gists_url":"https://api.github.com/users/IMA-WorldHealth/gists{/gist_id}","starred_url":"https://api.github.com/users/IMA-WorldHealth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IMA-WorldHealth/subscriptions","organizations_url":"https://api.github.com/users/IMA-WorldHealth/orgs","repos_url":"https://api.github.com/users/IMA-WorldHealth/repos","events_url":"https://api.github.com/users/IMA-WorldHealth/events{/privacy}","received_events_url":"https://api.github.com/users/IMA-WorldHealth/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/IMA-WorldHealth/bhima","description":"A hospital information system for developing countries.","fork":false,"url":"https://api.github.com/repos/IMA-WorldHealth/bhima","forks_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/forks","keys_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/keys{/key_id}","collaborators_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/teams","hooks_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/hooks","issue_events_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/events{/number}","events_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/events","assignees_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/assignees{/user}","branches_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/branches{/branch}","tags_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/tags","blobs_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/git/refs{/sha}","trees_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/git/trees{/sha}","statuses_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/statuses/{sha}","languages_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/languages","stargazers_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/stargazers","contributors_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/contributors","subscribers_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/subscribers","subscription_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/subscription","commits_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/commits{/sha}","git_commits_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/git/commits{/sha}","comments_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/comments{/number}","issue_comment_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/comments{/number}","contents_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/contents/{+path}","compare_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/compare/{base}...{head}","merges_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/merges","archive_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/downloads","issues_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues{/number}","pulls_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls{/number}","milestones_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/milestones{/number}","notifications_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/labels{/name}","releases_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/releases{/id}","created_at":"2013-12-09T10:07:16Z","updated_at":"2015-08-26T12:16:26Z","pushed_at":"2015-10-14T15:32:17Z","git_url":"git://github.com/IMA-WorldHealth/bhima.git","ssh_url":"git@github.com:IMA-WorldHealth/bhima.git","clone_url":"https://github.com/IMA-WorldHealth/bhima.git","svn_url":"https://github.com/IMA-WorldHealth/bhima","homepage":"","size":104707,"stargazers_count":6,"watchers_count":6,"language":"Groff","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":91,"forks":10,"open_issues":91,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/812"},"html":{"href":"https://github.com/IMA-WorldHealth/bhima/pull/812"},"issue":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/812"},"comments":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/812/comments"},"review_comments":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/812/comments"},"review_comment":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/812/commits"},"statuses":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/statuses/a6e4b44bb1905fa5caf36902a431cf1507d63ad7"}}}}