From a99e5cd810b28dda83d3b7809fdf9f0f8031ef7a Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Tue, 28 Jun 2016 12:17:29 -0600 Subject: [PATCH 1/3] Split Cropper.js from the main JavaScript manifest. --- app/assets/javascripts/application.js.coffee | 1 - app/assets/javascripts/dispatcher.js.coffee | 1 - app/assets/javascripts/lib/cropper.js.coffee | 1 + app/assets/javascripts/profile/application.js.coffee | 2 ++ app/assets/javascripts/{ => profile}/gl_crop.js.coffee | 0 app/assets/javascripts/{ => profile}/profile.js.coffee | 3 +++ app/views/profiles/show.html.haml | 4 ++++ config/application.rb | 1 + 8 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/lib/cropper.js.coffee create mode 100644 app/assets/javascripts/profile/application.js.coffee rename app/assets/javascripts/{ => profile}/gl_crop.js.coffee (100%) rename app/assets/javascripts/{ => profile}/profile.js.coffee (96%) diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index b6dbf2d0cc..715d71b565 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -54,7 +54,6 @@ #= require_directory ./u2f #= require_directory . #= require fuzzaldrin-plus -#= require cropper #= require u2f window.slugify = (text) -> diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee index 7fbff9214c..6f0ebf4322 100644 --- a/app/assets/javascripts/dispatcher.js.coffee +++ b/app/assets/javascripts/dispatcher.js.coffee @@ -129,7 +129,6 @@ class Dispatcher when 'dashboard', 'root' shortcut_handler = new ShortcutsDashboardNavigation() when 'profiles' - new Profile() new NotificationsForm() new NotificationsDropdown() when 'projects' diff --git a/app/assets/javascripts/lib/cropper.js.coffee b/app/assets/javascripts/lib/cropper.js.coffee new file mode 100644 index 0000000000..32536d23fe --- /dev/null +++ b/app/assets/javascripts/lib/cropper.js.coffee @@ -0,0 +1 @@ +#= require cropper diff --git a/app/assets/javascripts/profile/application.js.coffee b/app/assets/javascripts/profile/application.js.coffee new file mode 100644 index 0000000000..91cacfece4 --- /dev/null +++ b/app/assets/javascripts/profile/application.js.coffee @@ -0,0 +1,2 @@ +# +#= require_tree . diff --git a/app/assets/javascripts/gl_crop.js.coffee b/app/assets/javascripts/profile/gl_crop.js.coffee similarity index 100% rename from app/assets/javascripts/gl_crop.js.coffee rename to app/assets/javascripts/profile/gl_crop.js.coffee diff --git a/app/assets/javascripts/profile.js.coffee b/app/assets/javascripts/profile/profile.js.coffee similarity index 96% rename from app/assets/javascripts/profile.js.coffee rename to app/assets/javascripts/profile/profile.js.coffee index 1583d1ba6f..b276242f50 100644 --- a/app/assets/javascripts/profile.js.coffee +++ b/app/assets/javascripts/profile/profile.js.coffee @@ -78,3 +78,6 @@ $ -> if comment && comment.length > 1 && $title.val() == '' $title.val(comment[1]).change() + + if $('body').attr('data-page').split(':').first() == 'profiles' + new Profile() diff --git a/app/views/profiles/show.html.haml b/app/views/profiles/show.html.haml index eef50d887c..e8a70cfd84 100644 --- a/app/views/profiles/show.html.haml +++ b/app/views/profiles/show.html.haml @@ -1,3 +1,7 @@ +- content_for :page_specific_javascripts do + = page_specific_javascript_tag('lib/cropper.js') + = page_specific_javascript_tag('profile/application.js') + = form_for @user, url: profile_path, method: :put, html: { multipart: true, class: "edit-user prepend-top-default" }, authenticity_token: true do |f| = form_errors(@user) diff --git a/config/application.rb b/config/application.rb index 2b0595ede2..21e7cc7b6e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -84,6 +84,7 @@ module Gitlab config.assets.precompile << "graphs/application.js" config.assets.precompile << "users/application.js" config.assets.precompile << "network/application.js" + config.assets.precompile << "profile/application.js" config.assets.precompile << "lib/utils/*.js" config.assets.precompile << "lib/*.js" From 7b9b2ce3c520df8475f1fe4b8aa72a8ce3a687b4 Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Wed, 29 Jun 2016 15:32:52 -0600 Subject: [PATCH 2/3] Add a helper function for getting the page path from JS. --- app/assets/javascripts/lib/utils/common_utils.js.coffee | 7 +++++-- app/assets/javascripts/profile/profile.js.coffee | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/lib/utils/common_utils.js.coffee b/app/assets/javascripts/lib/utils/common_utils.js.coffee index e39dcb2daa..d4dd3dc329 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js.coffee +++ b/app/assets/javascripts/lib/utils/common_utils.js.coffee @@ -5,12 +5,12 @@ w.gl.utils.isInGroupsPage = -> - return $('body').data('page').split(':')[0] is 'groups' + return gl.utils.getPagePath() is 'groups' w.gl.utils.isInProjectPage = -> - return $('body').data('page').split(':')[0] is 'projects' + return gl.utils.getPagePath() is 'projects' w.gl.utils.getProjectSlug = -> @@ -40,6 +40,9 @@ e.stopImmediatePropagation() return false + gl.utils.getPagePath = -> + return $('body').data('page').split(':')[0] + jQuery.timefor = (time, suffix, expiredLabel) -> diff --git a/app/assets/javascripts/profile/profile.js.coffee b/app/assets/javascripts/profile/profile.js.coffee index b276242f50..f3b05f2c64 100644 --- a/app/assets/javascripts/profile/profile.js.coffee +++ b/app/assets/javascripts/profile/profile.js.coffee @@ -79,5 +79,5 @@ $ -> if comment && comment.length > 1 && $title.val() == '' $title.val(comment[1]).change() - if $('body').attr('data-page').split(':').first() == 'profiles' + if gl.utils.getPagePath() == 'profiles' new Profile() From a87b229b5d6da23e12e34d899f824f1f7e2dc28a Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Thu, 30 Jun 2016 10:42:07 -0600 Subject: [PATCH 3/3] Fix preferences tests. --- app/views/profiles/_head.html.haml | 3 +++ app/views/profiles/accounts/show.html.haml | 1 + app/views/profiles/audit_log.html.haml | 1 + app/views/profiles/emails/index.html.haml | 1 + app/views/profiles/keys/show.html.haml | 1 + app/views/profiles/notifications/show.html.haml | 1 + app/views/profiles/personal_access_tokens/index.html.haml | 1 + app/views/profiles/preferences/show.html.haml | 1 + app/views/profiles/show.html.haml | 4 +--- app/views/profiles/two_factor_auths/show.html.haml | 1 + 10 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 app/views/profiles/_head.html.haml diff --git a/app/views/profiles/_head.html.haml b/app/views/profiles/_head.html.haml new file mode 100644 index 0000000000..003884a5bd --- /dev/null +++ b/app/views/profiles/_head.html.haml @@ -0,0 +1,3 @@ +- content_for :page_specific_javascripts do + = page_specific_javascript_tag('lib/cropper.js') + = page_specific_javascript_tag('profile/application.js') diff --git a/app/views/profiles/accounts/show.html.haml b/app/views/profiles/accounts/show.html.haml index 8efe486e01..57d16d2915 100644 --- a/app/views/profiles/accounts/show.html.haml +++ b/app/views/profiles/accounts/show.html.haml @@ -1,4 +1,5 @@ - page_title "Account" += render 'profiles/head' - if current_user.ldap_user? .alert.alert-info diff --git a/app/views/profiles/audit_log.html.haml b/app/views/profiles/audit_log.html.haml index 9c404b6935..9fe86e6b29 100644 --- a/app/views/profiles/audit_log.html.haml +++ b/app/views/profiles/audit_log.html.haml @@ -1,4 +1,5 @@ - page_title "Audit Log" += render 'profiles/head' .row.prepend-top-default .col-lg-3.profile-settings-sidebar diff --git a/app/views/profiles/emails/index.html.haml b/app/views/profiles/emails/index.html.haml index 6f7fefdb46..dc499be885 100644 --- a/app/views/profiles/emails/index.html.haml +++ b/app/views/profiles/emails/index.html.haml @@ -1,4 +1,5 @@ - page_title "Emails" += render 'profiles/head' .row.prepend-top-default .col-lg-3.profile-settings-sidebar diff --git a/app/views/profiles/keys/show.html.haml b/app/views/profiles/keys/show.html.haml index 89f6f01581..6283ceebf1 100644 --- a/app/views/profiles/keys/show.html.haml +++ b/app/views/profiles/keys/show.html.haml @@ -1,2 +1,3 @@ - page_title @key.title, "SSH Keys" += render 'profiles/head' = render "key_details" diff --git a/app/views/profiles/notifications/show.html.haml b/app/views/profiles/notifications/show.html.haml index f77738f97f..844fce5970 100644 --- a/app/views/profiles/notifications/show.html.haml +++ b/app/views/profiles/notifications/show.html.haml @@ -1,4 +1,5 @@ - page_title "Notifications" += render 'profiles/head' %div - if @user.errors.any? diff --git a/app/views/profiles/personal_access_tokens/index.html.haml b/app/views/profiles/personal_access_tokens/index.html.haml index 1b45548bd0..71ac367830 100644 --- a/app/views/profiles/personal_access_tokens/index.html.haml +++ b/app/views/profiles/personal_access_tokens/index.html.haml @@ -1,4 +1,5 @@ - page_title "Personal Access Tokens" += render 'profiles/head' .row.prepend-top-default .col-lg-3.profile-settings-sidebar diff --git a/app/views/profiles/preferences/show.html.haml b/app/views/profiles/preferences/show.html.haml index 1b1b16d656..b4d35dc9a3 100644 --- a/app/views/profiles/preferences/show.html.haml +++ b/app/views/profiles/preferences/show.html.haml @@ -1,4 +1,5 @@ - page_title 'Preferences' += render 'profiles/head' = form_for @user, url: profile_preferences_path, remote: true, method: :put, html: {class: 'row prepend-top-default js-preferences-form'} do |f| .col-lg-3.profile-settings-sidebar diff --git a/app/views/profiles/show.html.haml b/app/views/profiles/show.html.haml index e8a70cfd84..d9fa74fad9 100644 --- a/app/views/profiles/show.html.haml +++ b/app/views/profiles/show.html.haml @@ -1,6 +1,4 @@ -- content_for :page_specific_javascripts do - = page_specific_javascript_tag('lib/cropper.js') - = page_specific_javascript_tag('profile/application.js') += render 'profiles/head' = form_for @user, url: profile_path, method: :put, html: { multipart: true, class: "edit-user prepend-top-default" }, authenticity_token: true do |f| = form_errors(@user) diff --git a/app/views/profiles/two_factor_auths/show.html.haml b/app/views/profiles/two_factor_auths/show.html.haml index 593be2617c..5890456bee 100644 --- a/app/views/profiles/two_factor_auths/show.html.haml +++ b/app/views/profiles/two_factor_auths/show.html.haml @@ -1,5 +1,6 @@ - page_title 'Two-Factor Authentication', 'Account' - header_title "Two-Factor Authentication", profile_two_factor_auth_path += render 'profiles/head' .row.prepend-top-default .col-lg-3