refactor users bundle, remove inline javascript, and transform into an async chunk

This commit is contained in:
Mike Greiling 2017-07-18 17:27:01 -05:00
parent 339baf8f5d
commit f2c0ab398e
5 changed files with 25 additions and 50 deletions

View file

@ -516,6 +516,13 @@ import PerformanceBar from './performance_bar';
case 'protected_branches': case 'protected_branches':
shortcut_handler = new ShortcutsNavigation(); shortcut_handler = new ShortcutsNavigation();
} }
break;
case 'users':
const action = path[1];
import(/* webpackChunkName: 'user_profile' */ './users')
.then(user => user.default(action))
.catch(() => {});
break;
} }
// If we haven't installed a custom shortcut handler, install the default one // If we haven't installed a custom shortcut handler, install the default one
if (!shortcut_handler) { if (!shortcut_handler) {

View file

@ -1,5 +1,19 @@
import User from './user'; import Cookies from 'js-cookie';
import UserTabs from './user_tabs';
// use legacy exports until embedded javascript is refactored export default function initUserProfile(action) {
window.gl = window.gl || {}; // place profile avatars to top
window.gl.User = User; $('.profile-groups-avatars').tooltip({
placement: 'top',
});
// eslint-disable-next-line no-new
new UserTabs({ parentEl: '.user-profile', action });
// hide project limit message
$('.hide-project-limit-message').on('click', (e) => {
e.preventDefault();
Cookies.set('hide_project_limit_message', 'false');
$(this).parents('.project-limit-message').remove();
});
}

View file

@ -1,34 +0,0 @@
/* eslint-disable class-methods-use-this */
import Cookies from 'js-cookie';
import UserTabs from './user_tabs';
export default class User {
constructor({ action }) {
this.action = action;
this.placeProfileAvatarsToTop();
this.initTabs();
this.hideProjectLimitMessage();
}
placeProfileAvatarsToTop() {
$('.profile-groups-avatars').tooltip({
placement: 'top',
});
}
initTabs() {
return new UserTabs({
parentEl: '.user-profile',
action: this.action,
});
}
hideProjectLimitMessage() {
$('.hide-project-limit-message').on('click', (e) => {
e.preventDefault();
Cookies.set('hide_project_limit_message', 'false');
$(this).parents('.project-limit-message').remove();
});
}
}

View file

@ -1,8 +1,5 @@
- page_title @user.name - page_title @user.name
- page_description @user.bio - page_description @user.bio
- content_for :page_specific_javascripts do
= page_specific_javascript_bundle_tag('common_d3')
= page_specific_javascript_bundle_tag('users')
- header_title @user.name, user_path(@user) - header_title @user.name, user_path(@user)
- @no_container = true - @no_container = true
@ -129,10 +126,3 @@
.loading-status .loading-status
= spinner = spinner
:javascript
var userProfile;
userProfile = new gl.User({
action: "#{controller.action_name}"
});

View file

@ -66,7 +66,6 @@ var config = {
stl_viewer: './blob/stl_viewer.js', stl_viewer: './blob/stl_viewer.js',
terminal: './terminal/terminal_bundle.js', terminal: './terminal/terminal_bundle.js',
u2f: ['vendor/u2f'], u2f: ['vendor/u2f'],
users: './users/index.js',
raven: './raven/index.js', raven: './raven/index.js',
vue_merge_request_widget: './vue_merge_request_widget/index.js', vue_merge_request_widget: './vue_merge_request_widget/index.js',
test: './test.js', test: './test.js',
@ -184,7 +183,6 @@ var config = {
name: 'common_d3', name: 'common_d3',
chunks: [ chunks: [
'graphs', 'graphs',
'users',
'monitoring', 'monitoring',
], ],
}), }),