diff options
author | Simon Knox <psimyn@gmail.com> | 2017-12-11 15:31:01 +1100 |
---|---|---|
committer | Simon Knox <psimyn@gmail.com> | 2017-12-12 22:40:52 +1100 |
commit | 07271c094d21904aeda0c0cde571b984b4ede9a0 (patch) | |
tree | 43eeb44141818643bf2a7d5690df3638c18eec99 | |
parent | 806a68a81f1baeed07c146b1b5d9eb77796c46ba (diff) | |
download | gitlab-ce-40985-notes-data.tar.gz |
simplify notes app creation40985-notes-data
-rw-r--r-- | app/assets/javascripts/notes/index.js | 27 | ||||
-rw-r--r-- | app/views/projects/issues/_discussion.html.haml | 18 |
2 files changed, 27 insertions, 18 deletions
diff --git a/app/assets/javascripts/notes/index.js b/app/assets/javascripts/notes/index.js index a94163a5f87..6b3327527fe 100644 --- a/app/assets/javascripts/notes/index.js +++ b/app/assets/javascripts/notes/index.js @@ -17,18 +17,27 @@ document.addEventListener('DOMContentLoaded', () => new Vue({ path: parsedUserData.path, } : {}; + function camelize(string) { + return string.replace(/(_\w)/g, match => match[1].toUpperCase()); + } + + function camelizeKeys(notesData) { + return Object.keys(notesData).reduce( + (acc, curr) => ({ + ...acc, + [camelize(curr)]: notesData[curr], + }), + {}, + ); + } + + const notesDataOrig = JSON.parse(notesDataset.notesData); + const notesData = camelizeKeys(notesDataOrig); + return { noteableData: JSON.parse(notesDataset.noteableData), currentUserData, - notesData: { - lastFetchedAt: notesDataset.lastFetchedAt, - discussionsPath: notesDataset.discussionsPath, - newSessionPath: notesDataset.newSessionPath, - registerPath: notesDataset.registerPath, - notesPath: notesDataset.notesPath, - markdownDocsPath: notesDataset.markdownDocsPath, - quickActionsDocsPath: notesDataset.quickActionsDocsPath, - }, + notesData, }; }, render(createElement) { diff --git a/app/views/projects/issues/_discussion.html.haml b/app/views/projects/issues/_discussion.html.haml index 9779c1985d5..e43ce656510 100644 --- a/app/views/projects/issues/_discussion.html.haml +++ b/app/views/projects/issues/_discussion.html.haml @@ -6,12 +6,12 @@ = link_to 'Close issue', issue_path(@issue, issue: {state_event: :close}, format: 'json'), data: {original_text: "Close issue", alternative_text: "Comment & close issue"}, class: "btn btn-nr btn-close btn-comment js-note-target-close #{issue_button_visibility(@issue, true)}", title: 'Close issue' %section.js-vue-notes-event - #js-vue-notes{ data: { discussions_path: discussions_project_issue_path(@project, @issue, format: :json), - register_path: new_session_path(:user, redirect_to_referer: 'yes', anchor: 'register-pane'), - new_session_path: new_session_path(:user, redirect_to_referer: 'yes'), - markdown_docs_path: help_page_path('user/markdown'), - quick_actions_docs_path: help_page_path('user/project/quick_actions'), - notes_path: notes_url, - last_fetched_at: Time.now.to_i, - noteable_data: serialize_issuable(@issue), - current_user_data: UserSerializer.new.represent(current_user, only_path: true).to_json } } + #js-vue-notes{ data: { noteable_data: serialize_issuable(@issue), + current_user_data: UserSerializer.new.represent(current_user, only_path: true).to_json, + notes_data: { discussions_path: discussions_project_issue_path(@project, @issue, format: :json), + register_path: new_session_path(:user, redirect_to_referer: 'yes', anchor: 'register-pane'), + new_session_path: new_session_path(:user, redirect_to_referer: 'yes'), + markdown_docs_path: help_page_path('user/markdown'), + quick_actions_docs_path: help_page_path('user/project/quick_actions'), + notes_path: notes_url, + last_fetched_at: Time.now.to_i }.to_json } } |