{"action":"created","comment":{"url":"https://api.github.com/repos/ageuk/companion-app/pulls/comments/71010131","id":71010131,"diff_hunk":"@@ -0,0 +1,199 @@\n+/* global Handlebars */\n+// general purpose utils\n+var utils = {};\n+\n+utils.safeParse = function (obj, reviver) {\n+  var json;\n+  var error = null;\n+  try {\n+    json = JSON.parse(obj, reviver);\n+  } catch (err) {\n+    error = err;\n+  }\n+  return [error, json];\n+};\n+\n+utils.merge = function (x, y) {\n+  return Object.assign({}, x, y);\n+};\n+\n+// dbHelpers for transforming data into a more usable format\n+var dbHelpers = {};\n+\n+dbHelpers.filterTopicId = function (action, prompts) {\n+  return prompts.filter(function (prompt) {\n+    return prompt.id === action.promptID;\n+  })[0].topicID;\n+};\n+\n+dbHelpers.addTopicId = function (actions, prompts) {\n+  return actions.map(function (action) {\n+    var topicID = dbHelpers.filterTopicId(action, prompts);\n+    action.topicID = topicID;\n+    return action;\n+  });\n+};\n+\n+dbHelpers.addActionDetails = function (clientActions, actions) {\n+  return clientActions.map(function (selectedAction) {\n+    var actionDescription = actions.filter(function (action) {\n+      return action.id === selectedAction.action_id;\n+    })[0].value;\n+    selectedAction.value = actionDescription;\n+    return selectedAction;\n+  });\n+};\n+\n+// localStorage functions\n+var db = {};\n+\n+db.setData = function (key, data) {\n+  window.localStorage[key] = JSON.stringify(data);\n+};\n+\n+db.getData = function (key) {\n+  var data = window.localStorage[key];\n+  return utils.safeParse(data);\n+};\n+\n+db.updateNotes = function (clientId, updatedNote, dataObj) {\n+  dataObj.clients.map(function (client) {\n+    return client.id === clientId ? utils.merge(client, {notes: updatedNote}) : client;\n+  });\n+};\n+\n+db.updateClientActions = function (selectedActions, clientID, dataObj) {\n+  dataObj.client_actions = selectedActions.map(function (actionID, i) {\n+    return {\n+      id: i,\n+      client_id: clientID,\n+      action_id: actionID\n+    };\n+  });\n+  db.setData('db', dataObj);\n+};\n+\n+db.filterCurrentClient = function (clientId, dataObj) {\n+  var filtered = dataObj.clients.filter(function (client) {\n+    return client.id === Number(clientId);\n+  });\n+  return utils.merge(dataObj, { clients: filtered });\n+};\n+\n+db.filterPrompts = function (selectedTopicId, dataObj) {\n+  var filtered = dataObj.prompts.filter(function (prompt) {\n+    return prompt.topicID === Number(selectedTopicId);\n+  });\n+  return utils.merge(dataObj, { prompts: filtered });\n+};\n+\n+db.filterActions = function (selectedPromptId, dataObj) {\n+  var filtered = dataObj.actions.filter(function (action) {\n+    return action.promptID === Number(selectedPromptId);\n+  });\n+  return utils.merge(dataObj, { actions: filtered });\n+};\n+\n+// functions to set up and manipulate DOM\n+var ui = {};\n+\n+ui.addListeners = function (type, onclick, cb) {\n+  var $el = document.querySelectorAll('[data_' + type + ']');\n+  $el = [].slice.call($el);\n+  $el.forEach(function ($) {\n+    $.addEventListener('click', function (e) {\n+      onclick(e, cb);\n+    });\n+  });\n+};\n+\n+ui.clientOnClick = function (e) {\n+  var selectedClientId = e.target.getAttribute('data_client-id');\n+  db.setData('selectedClientId', Number(selectedClientId));\n+  window.location.href = '/topics';\n+};\n+\n+ui.topicOnClick = function (e) {\n+  var currentTopic = e.target.getAttribute('data_topic-id');\n+  db.setData('currentTopic', Number(currentTopic));\n+  window.location.href = '/prompts';\n+};\n+\n+ui.promptOnClick = function (e) {\n+  var currentPrompt = e.target.getAttribute('data_prompt-id');\n+  db.setData('currentPrompt', Number(currentPrompt));\n+  window.location.href = '/actions';\n+};\n+\n+ui.actionsOnClick = function (e) {\n+  var actionsToAdd = ui.updateActions(e);\n+  var [ err, data ] = db.getData('db');\n+  if (err) {\n+    throw err;\n+  } else {\n+    var updatedActions = dbHelpers.addActionDetails(actionsToAdd, data.actions);\n+    var updatedData = utils.merge(data, { client_actions: updatedActions });\n+    db.setData('db', updatedData);\n+  }\n+};\n+\n+ui.toggleSelectedActions = function (actionId, clientId, clientActions) {\n+  var actionIndex = clientActions.reduce(function (previous, current, i) {\n+    return current.action_id === actionId ? i : previous;\n+  }, -1);","path":"public/src/js/helpers.js","position":143,"original_position":143,"commit_id":"18342bca5a6cf8dd07c5d1739db144b8c58d970a","original_commit_id":"18342bca5a6cf8dd07c5d1739db144b8c58d970a","user":{"login":"rjmk","id":12041390,"avatar_url":"https://avatars.githubusercontent.com/u/12041390?v=3","gravatar_id":"","url":"https://api.github.com/users/rjmk","html_url":"https://github.com/rjmk","followers_url":"https://api.github.com/users/rjmk/followers","following_url":"https://api.github.com/users/rjmk/following{/other_user}","gists_url":"https://api.github.com/users/rjmk/gists{/gist_id}","starred_url":"https://api.github.com/users/rjmk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjmk/subscriptions","organizations_url":"https://api.github.com/users/rjmk/orgs","repos_url":"https://api.github.com/users/rjmk/repos","events_url":"https://api.github.com/users/rjmk/events{/privacy}","received_events_url":"https://api.github.com/users/rjmk/received_events","type":"User","site_admin":false},"body":"`-1` for not found is a bit ugly, but it is the JavaScript convention, so OOK","created_at":"2016-07-15T17:31:21Z","updated_at":"2016-07-15T17:31:21Z","html_url":"https://github.com/ageuk/companion-app/pull/78#discussion_r71010131","pull_request_url":"https://api.github.com/repos/ageuk/companion-app/pulls/78","_links":{"self":{"href":"https://api.github.com/repos/ageuk/companion-app/pulls/comments/71010131"},"html":{"href":"https://github.com/ageuk/companion-app/pull/78#discussion_r71010131"},"pull_request":{"href":"https://api.github.com/repos/ageuk/companion-app/pulls/78"}}},"pull_request":{"url":"https://api.github.com/repos/ageuk/companion-app/pulls/78","id":77438485,"html_url":"https://github.com/ageuk/companion-app/pull/78","diff_url":"https://github.com/ageuk/companion-app/pull/78.diff","patch_url":"https://github.com/ageuk/companion-app/pull/78.patch","issue_url":"https://api.github.com/repos/ageuk/companion-app/issues/78","number":78,"state":"open","locked":false,"title":"Selecting actions","user":{"login":"katbow","id":1287388,"avatar_url":"https://avatars.githubusercontent.com/u/1287388?v=3","gravatar_id":"","url":"https://api.github.com/users/katbow","html_url":"https://github.com/katbow","followers_url":"https://api.github.com/users/katbow/followers","following_url":"https://api.github.com/users/katbow/following{/other_user}","gists_url":"https://api.github.com/users/katbow/gists{/gist_id}","starred_url":"https://api.github.com/users/katbow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/katbow/subscriptions","organizations_url":"https://api.github.com/users/katbow/orgs","repos_url":"https://api.github.com/users/katbow/repos","events_url":"https://api.github.com/users/katbow/events{/privacy}","received_events_url":"https://api.github.com/users/katbow/received_events","type":"User","site_admin":false},"body":"Selected actions will be added to or removed from localStorage as they are clicked.\r\nAction plan now renders to a view.\r\nFront end testing is now set up as well to at least run locally.\r\nDrafted out functions for reorganising data from localStorage.","created_at":"2016-07-14T11:10:24Z","updated_at":"2016-07-15T17:31:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8049e7f8ae832d4067bdb1cbedf9851a7fe14b90","assignee":{"login":"rjmk","id":12041390,"avatar_url":"https://avatars.githubusercontent.com/u/12041390?v=3","gravatar_id":"","url":"https://api.github.com/users/rjmk","html_url":"https://github.com/rjmk","followers_url":"https://api.github.com/users/rjmk/followers","following_url":"https://api.github.com/users/rjmk/following{/other_user}","gists_url":"https://api.github.com/users/rjmk/gists{/gist_id}","starred_url":"https://api.github.com/users/rjmk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjmk/subscriptions","organizations_url":"https://api.github.com/users/rjmk/orgs","repos_url":"https://api.github.com/users/rjmk/repos","events_url":"https://api.github.com/users/rjmk/events{/privacy}","received_events_url":"https://api.github.com/users/rjmk/received_events","type":"User","site_admin":false},"assignees":[{"login":"rjmk","id":12041390,"avatar_url":"https://avatars.githubusercontent.com/u/12041390?v=3","gravatar_id":"","url":"https://api.github.com/users/rjmk","html_url":"https://github.com/rjmk","followers_url":"https://api.github.com/users/rjmk/followers","following_url":"https://api.github.com/users/rjmk/following{/other_user}","gists_url":"https://api.github.com/users/rjmk/gists{/gist_id}","starred_url":"https://api.github.com/users/rjmk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjmk/subscriptions","organizations_url":"https://api.github.com/users/rjmk/orgs","repos_url":"https://api.github.com/users/rjmk/repos","events_url":"https://api.github.com/users/rjmk/events{/privacy}","received_events_url":"https://api.github.com/users/rjmk/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ageuk/companion-app/pulls/78/commits","review_comments_url":"https://api.github.com/repos/ageuk/companion-app/pulls/78/comments","review_comment_url":"https://api.github.com/repos/ageuk/companion-app/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ageuk/companion-app/issues/78/comments","statuses_url":"https://api.github.com/repos/ageuk/companion-app/statuses/18342bca5a6cf8dd07c5d1739db144b8c58d970a","head":{"label":"ageuk:select-actions","ref":"select-actions","sha":"18342bca5a6cf8dd07c5d1739db144b8c58d970a","user":{"login":"ageuk","id":20108238,"avatar_url":"https://avatars.githubusercontent.com/u/20108238?v=3","gravatar_id":"","url":"https://api.github.com/users/ageuk","html_url":"https://github.com/ageuk","followers_url":"https://api.github.com/users/ageuk/followers","following_url":"https://api.github.com/users/ageuk/following{/other_user}","gists_url":"https://api.github.com/users/ageuk/gists{/gist_id}","starred_url":"https://api.github.com/users/ageuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ageuk/subscriptions","organizations_url":"https://api.github.com/users/ageuk/orgs","repos_url":"https://api.github.com/users/ageuk/repos","events_url":"https://api.github.com/users/ageuk/events{/privacy}","received_events_url":"https://api.github.com/users/ageuk/received_events","type":"Organization","site_admin":false},"repo":{"id":61796793,"name":"companion-app","full_name":"ageuk/companion-app","owner":{"login":"ageuk","id":20108238,"avatar_url":"https://avatars.githubusercontent.com/u/20108238?v=3","gravatar_id":"","url":"https://api.github.com/users/ageuk","html_url":"https://github.com/ageuk","followers_url":"https://api.github.com/users/ageuk/followers","following_url":"https://api.github.com/users/ageuk/following{/other_user}","gists_url":"https://api.github.com/users/ageuk/gists{/gist_id}","starred_url":"https://api.github.com/users/ageuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ageuk/subscriptions","organizations_url":"https://api.github.com/users/ageuk/orgs","repos_url":"https://api.github.com/users/ageuk/repos","events_url":"https://api.github.com/users/ageuk/events{/privacy}","received_events_url":"https://api.github.com/users/ageuk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ageuk/companion-app","description":"An application for guided conversation between a companion and a client.","fork":false,"url":"https://api.github.com/repos/ageuk/companion-app","forks_url":"https://api.github.com/repos/ageuk/companion-app/forks","keys_url":"https://api.github.com/repos/ageuk/companion-app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ageuk/companion-app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ageuk/companion-app/teams","hooks_url":"https://api.github.com/repos/ageuk/companion-app/hooks","issue_events_url":"https://api.github.com/repos/ageuk/companion-app/issues/events{/number}","events_url":"https://api.github.com/repos/ageuk/companion-app/events","assignees_url":"https://api.github.com/repos/ageuk/companion-app/assignees{/user}","branches_url":"https://api.github.com/repos/ageuk/companion-app/branches{/branch}","tags_url":"https://api.github.com/repos/ageuk/companion-app/tags","blobs_url":"https://api.github.com/repos/ageuk/companion-app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ageuk/companion-app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ageuk/companion-app/git/refs{/sha}","trees_url":"https://api.github.com/repos/ageuk/companion-app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ageuk/companion-app/statuses/{sha}","languages_url":"https://api.github.com/repos/ageuk/companion-app/languages","stargazers_url":"https://api.github.com/repos/ageuk/companion-app/stargazers","contributors_url":"https://api.github.com/repos/ageuk/companion-app/contributors","subscribers_url":"https://api.github.com/repos/ageuk/companion-app/subscribers","subscription_url":"https://api.github.com/repos/ageuk/companion-app/subscription","commits_url":"https://api.github.com/repos/ageuk/companion-app/commits{/sha}","git_commits_url":"https://api.github.com/repos/ageuk/companion-app/git/commits{/sha}","comments_url":"https://api.github.com/repos/ageuk/companion-app/comments{/number}","issue_comment_url":"https://api.github.com/repos/ageuk/companion-app/issues/comments{/number}","contents_url":"https://api.github.com/repos/ageuk/companion-app/contents/{+path}","compare_url":"https://api.github.com/repos/ageuk/companion-app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ageuk/companion-app/merges","archive_url":"https://api.github.com/repos/ageuk/companion-app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ageuk/companion-app/downloads","issues_url":"https://api.github.com/repos/ageuk/companion-app/issues{/number}","pulls_url":"https://api.github.com/repos/ageuk/companion-app/pulls{/number}","milestones_url":"https://api.github.com/repos/ageuk/companion-app/milestones{/number}","notifications_url":"https://api.github.com/repos/ageuk/companion-app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ageuk/companion-app/labels{/name}","releases_url":"https://api.github.com/repos/ageuk/companion-app/releases{/id}","deployments_url":"https://api.github.com/repos/ageuk/companion-app/deployments","created_at":"2016-06-23T10:31:42Z","updated_at":"2016-07-12T12:03:13Z","pushed_at":"2016-07-15T16:44:22Z","git_url":"git://github.com/ageuk/companion-app.git","ssh_url":"git@github.com:ageuk/companion-app.git","clone_url":"https://github.com/ageuk/companion-app.git","svn_url":"https://github.com/ageuk/companion-app","homepage":"http://ageuk-companion-app.herokuapp.com/","size":260,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":37,"forks":0,"open_issues":37,"watchers":4,"default_branch":"master"}},"base":{"label":"ageuk:master","ref":"master","sha":"98aa96286ec5b2f88797215a4a6008d4d7d7a284","user":{"login":"ageuk","id":20108238,"avatar_url":"https://avatars.githubusercontent.com/u/20108238?v=3","gravatar_id":"","url":"https://api.github.com/users/ageuk","html_url":"https://github.com/ageuk","followers_url":"https://api.github.com/users/ageuk/followers","following_url":"https://api.github.com/users/ageuk/following{/other_user}","gists_url":"https://api.github.com/users/ageuk/gists{/gist_id}","starred_url":"https://api.github.com/users/ageuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ageuk/subscriptions","organizations_url":"https://api.github.com/users/ageuk/orgs","repos_url":"https://api.github.com/users/ageuk/repos","events_url":"https://api.github.com/users/ageuk/events{/privacy}","received_events_url":"https://api.github.com/users/ageuk/received_events","type":"Organization","site_admin":false},"repo":{"id":61796793,"name":"companion-app","full_name":"ageuk/companion-app","owner":{"login":"ageuk","id":20108238,"avatar_url":"https://avatars.githubusercontent.com/u/20108238?v=3","gravatar_id":"","url":"https://api.github.com/users/ageuk","html_url":"https://github.com/ageuk","followers_url":"https://api.github.com/users/ageuk/followers","following_url":"https://api.github.com/users/ageuk/following{/other_user}","gists_url":"https://api.github.com/users/ageuk/gists{/gist_id}","starred_url":"https://api.github.com/users/ageuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ageuk/subscriptions","organizations_url":"https://api.github.com/users/ageuk/orgs","repos_url":"https://api.github.com/users/ageuk/repos","events_url":"https://api.github.com/users/ageuk/events{/privacy}","received_events_url":"https://api.github.com/users/ageuk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ageuk/companion-app","description":"An application for guided conversation between a companion and a client.","fork":false,"url":"https://api.github.com/repos/ageuk/companion-app","forks_url":"https://api.github.com/repos/ageuk/companion-app/forks","keys_url":"https://api.github.com/repos/ageuk/companion-app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ageuk/companion-app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ageuk/companion-app/teams","hooks_url":"https://api.github.com/repos/ageuk/companion-app/hooks","issue_events_url":"https://api.github.com/repos/ageuk/companion-app/issues/events{/number}","events_url":"https://api.github.com/repos/ageuk/companion-app/events","assignees_url":"https://api.github.com/repos/ageuk/companion-app/assignees{/user}","branches_url":"https://api.github.com/repos/ageuk/companion-app/branches{/branch}","tags_url":"https://api.github.com/repos/ageuk/companion-app/tags","blobs_url":"https://api.github.com/repos/ageuk/companion-app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ageuk/companion-app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ageuk/companion-app/git/refs{/sha}","trees_url":"https://api.github.com/repos/ageuk/companion-app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ageuk/companion-app/statuses/{sha}","languages_url":"https://api.github.com/repos/ageuk/companion-app/languages","stargazers_url":"https://api.github.com/repos/ageuk/companion-app/stargazers","contributors_url":"https://api.github.com/repos/ageuk/companion-app/contributors","subscribers_url":"https://api.github.com/repos/ageuk/companion-app/subscribers","subscription_url":"https://api.github.com/repos/ageuk/companion-app/subscription","commits_url":"https://api.github.com/repos/ageuk/companion-app/commits{/sha}","git_commits_url":"https://api.github.com/repos/ageuk/companion-app/git/commits{/sha}","comments_url":"https://api.github.com/repos/ageuk/companion-app/comments{/number}","issue_comment_url":"https://api.github.com/repos/ageuk/companion-app/issues/comments{/number}","contents_url":"https://api.github.com/repos/ageuk/companion-app/contents/{+path}","compare_url":"https://api.github.com/repos/ageuk/companion-app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ageuk/companion-app/merges","archive_url":"https://api.github.com/repos/ageuk/companion-app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ageuk/companion-app/downloads","issues_url":"https://api.github.com/repos/ageuk/companion-app/issues{/number}","pulls_url":"https://api.github.com/repos/ageuk/companion-app/pulls{/number}","milestones_url":"https://api.github.com/repos/ageuk/companion-app/milestones{/number}","notifications_url":"https://api.github.com/repos/ageuk/companion-app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ageuk/companion-app/labels{/name}","releases_url":"https://api.github.com/repos/ageuk/companion-app/releases{/id}","deployments_url":"https://api.github.com/repos/ageuk/companion-app/deployments","created_at":"2016-06-23T10:31:42Z","updated_at":"2016-07-12T12:03:13Z","pushed_at":"2016-07-15T16:44:22Z","git_url":"git://github.com/ageuk/companion-app.git","ssh_url":"git@github.com:ageuk/companion-app.git","clone_url":"https://github.com/ageuk/companion-app.git","svn_url":"https://github.com/ageuk/companion-app","homepage":"http://ageuk-companion-app.herokuapp.com/","size":260,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":37,"forks":0,"open_issues":37,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ageuk/companion-app/pulls/78"},"html":{"href":"https://github.com/ageuk/companion-app/pull/78"},"issue":{"href":"https://api.github.com/repos/ageuk/companion-app/issues/78"},"comments":{"href":"https://api.github.com/repos/ageuk/companion-app/issues/78/comments"},"review_comments":{"href":"https://api.github.com/repos/ageuk/companion-app/pulls/78/comments"},"review_comment":{"href":"https://api.github.com/repos/ageuk/companion-app/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ageuk/companion-app/pulls/78/commits"},"statuses":{"href":"https://api.github.com/repos/ageuk/companion-app/statuses/18342bca5a6cf8dd07c5d1739db144b8c58d970a"}}}}
{"actor":{"display_login":"rjmk"}}