2017-01-10 18:02:20 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-arrow-callback, wrap-iife, no-shadow, consistent-return, one-var, one-var-declaration-per-line, camelcase, default-case, no-new, quotes, no-duplicate-case, no-case-declarations, no-fallthrough, max-len */
|
2017-10-24 00:56:39 -04:00
|
|
|
import Flash from './flash';
|
2017-05-16 14:42:06 -04:00
|
|
|
import GfmAutoComplete from './gfm_auto_complete';
|
2018-01-19 12:18:51 -05:00
|
|
|
import { convertPermissionToBoolean } from './lib/utils/common_utils';
|
2017-10-10 04:09:01 -04:00
|
|
|
import GlFieldErrors from './gl_field_errors';
|
2017-10-10 05:10:11 -04:00
|
|
|
import Shortcuts from './shortcuts';
|
2017-12-13 04:26:44 -05:00
|
|
|
import SearchAutocomplete from './search_autocomplete';
|
2017-01-25 22:13:01 -05:00
|
|
|
|
2018-02-01 22:28:50 -05:00
|
|
|
var Dispatcher;
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2018-02-01 22:28:50 -05:00
|
|
|
(function() {
|
2016-07-24 16:45:11 -04:00
|
|
|
Dispatcher = (function() {
|
|
|
|
function Dispatcher() {
|
|
|
|
this.initSearch();
|
2016-09-09 08:21:00 -04:00
|
|
|
this.initFieldErrors();
|
2016-07-24 16:45:11 -04:00
|
|
|
this.initPageScripts();
|
|
|
|
}
|
|
|
|
|
|
|
|
Dispatcher.prototype.initPageScripts = function() {
|
2018-01-12 04:11:03 -05:00
|
|
|
var path, shortcut_handler;
|
2017-10-10 07:06:42 -04:00
|
|
|
const page = $('body').attr('data-page');
|
2016-07-24 16:45:11 -04:00
|
|
|
if (!page) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-01 09:55:16 -04:00
|
|
|
|
2017-12-20 18:20:51 -05:00
|
|
|
const fail = () => Flash('Error loading dynamic module');
|
2018-01-08 16:55:28 -05:00
|
|
|
const callDefault = m => m.default();
|
2017-12-20 18:20:51 -05:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
path = page.split(':');
|
|
|
|
shortcut_handler = null;
|
2017-03-13 18:46:21 -04:00
|
|
|
|
2017-08-14 06:35:58 -04:00
|
|
|
$('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
|
2017-06-12 15:42:12 -04:00
|
|
|
const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
|
2017-09-06 12:14:34 -04:00
|
|
|
const enableGFM = convertPermissionToBoolean(el.dataset.supportsAutocomplete);
|
2017-06-12 15:42:12 -04:00
|
|
|
gfm.setup($(el), {
|
|
|
|
emojis: true,
|
|
|
|
members: enableGFM,
|
|
|
|
issues: enableGFM,
|
|
|
|
milestones: enableGFM,
|
|
|
|
mergeRequests: enableGFM,
|
|
|
|
labels: enableGFM,
|
|
|
|
});
|
|
|
|
});
|
2017-05-16 14:42:06 -04:00
|
|
|
|
2018-02-22 16:48:15 -05:00
|
|
|
const shortcutHandlerPages = [
|
|
|
|
'projects:activity',
|
|
|
|
'projects:artifacts:browse',
|
|
|
|
'projects:artifacts:file',
|
|
|
|
'projects:blame:show',
|
|
|
|
'projects:blob:show',
|
|
|
|
'projects:commit:show',
|
|
|
|
'projects:commits:show',
|
|
|
|
'projects:find_file:show',
|
|
|
|
'projects:issues:edit',
|
|
|
|
'projects:issues:index',
|
|
|
|
'projects:issues:new',
|
|
|
|
'projects:issues:show',
|
|
|
|
'projects:merge_requests:creations:diffs',
|
|
|
|
'projects:merge_requests:creations:new',
|
|
|
|
'projects:merge_requests:edit',
|
|
|
|
'projects:merge_requests:index',
|
|
|
|
'projects:merge_requests:show',
|
|
|
|
'projects:network:show',
|
|
|
|
'projects:show',
|
|
|
|
'projects:tree:show',
|
|
|
|
'groups:show',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (shortcutHandlerPages.indexOf(page) !== -1) {
|
|
|
|
shortcut_handler = true;
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2018-02-22 16:48:15 -05:00
|
|
|
|
2017-08-04 04:07:05 -04:00
|
|
|
switch (path[0]) {
|
2016-07-24 16:45:11 -04:00
|
|
|
case 'admin':
|
|
|
|
switch (path[1]) {
|
2017-10-13 05:44:03 -04:00
|
|
|
case 'broadcast_messages':
|
2018-01-11 05:28:54 -05:00
|
|
|
import('./pages/admin/broadcast_messages')
|
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
2017-10-13 05:44:03 -04:00
|
|
|
break;
|
2017-04-05 06:24:15 -04:00
|
|
|
case 'cohorts':
|
2018-01-11 05:28:54 -05:00
|
|
|
import('./pages/admin/cohorts')
|
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
2017-04-05 08:29:48 -04:00
|
|
|
break;
|
2016-07-24 16:45:11 -04:00
|
|
|
case 'groups':
|
2018-01-09 07:10:53 -05:00
|
|
|
switch (path[2]) {
|
|
|
|
case 'show':
|
2018-01-11 05:28:54 -05:00
|
|
|
import('./pages/admin/groups/show')
|
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
2018-01-09 07:10:53 -05:00
|
|
|
break;
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
break;
|
|
|
|
case 'projects':
|
2018-01-11 05:28:54 -05:00
|
|
|
import('./pages/admin/projects')
|
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
2016-07-26 18:59:55 -04:00
|
|
|
break;
|
|
|
|
case 'labels':
|
2016-07-27 04:24:11 -04:00
|
|
|
switch (path[2]) {
|
2016-08-31 18:54:06 -04:00
|
|
|
case 'new':
|
2018-01-11 05:28:54 -05:00
|
|
|
import('./pages/admin/labels/new')
|
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
2018-01-09 07:10:53 -05:00
|
|
|
break;
|
2016-07-27 04:24:11 -04:00
|
|
|
case 'edit':
|
2018-01-11 05:28:54 -05:00
|
|
|
import('./pages/admin/labels/edit')
|
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
2018-01-09 07:10:53 -05:00
|
|
|
break;
|
2016-07-27 04:24:11 -04:00
|
|
|
}
|
2016-06-30 22:18:52 -04:00
|
|
|
case 'abuse_reports':
|
2018-01-11 05:28:54 -05:00
|
|
|
import('./pages/admin/abuse_reports')
|
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
2016-06-30 22:18:52 -04:00
|
|
|
break;
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'profiles':
|
2018-02-01 18:23:03 -05:00
|
|
|
import('./pages/profiles/index')
|
2018-01-09 12:36:10 -05:00
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
2016-07-24 16:45:11 -04:00
|
|
|
break;
|
|
|
|
case 'projects':
|
2018-01-11 07:38:30 -05:00
|
|
|
import('./pages/projects')
|
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
|
|
|
shortcut_handler = true;
|
2016-07-24 16:45:11 -04:00
|
|
|
switch (path[1]) {
|
|
|
|
case 'compare':
|
2018-01-16 07:01:10 -05:00
|
|
|
import('./pages/projects/compare')
|
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
2016-07-24 16:45:11 -04:00
|
|
|
break;
|
2018-01-11 07:38:30 -05:00
|
|
|
case 'create':
|
|
|
|
case 'new':
|
|
|
|
import('./pages/projects/new')
|
2018-01-08 18:08:32 -05:00
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
2016-07-24 16:45:11 -04:00
|
|
|
break;
|
|
|
|
case 'wikis':
|
2018-01-11 07:38:30 -05:00
|
|
|
import('./pages/projects/wikis')
|
|
|
|
.then(callDefault)
|
|
|
|
.catch(fail);
|
|
|
|
shortcut_handler = true;
|
2016-07-24 16:45:11 -04:00
|
|
|
break;
|
|
|
|
}
|
2017-07-18 18:27:01 -04:00
|
|
|
break;
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2016-07-26 23:32:10 -04:00
|
|
|
// If we haven't installed a custom shortcut handler, install the default one
|
2016-07-24 16:45:11 -04:00
|
|
|
if (!shortcut_handler) {
|
2017-01-23 19:06:17 -05:00
|
|
|
new Shortcuts();
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2017-07-06 15:37:31 -04:00
|
|
|
|
|
|
|
if (document.querySelector('#peek')) {
|
2018-01-23 04:11:41 -05:00
|
|
|
import('./performance_bar')
|
|
|
|
.then(m => new m.default({ container: '#peek' })) // eslint-disable-line new-cap
|
|
|
|
.catch(fail);
|
2017-07-06 15:37:31 -04:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
Dispatcher.prototype.initSearch = function() {
|
2016-07-26 23:32:10 -04:00
|
|
|
// Only when search form is present
|
2016-07-24 16:45:11 -04:00
|
|
|
if ($('.search').length) {
|
2017-12-13 04:26:44 -05:00
|
|
|
return new SearchAutocomplete();
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-09 08:21:00 -04:00
|
|
|
Dispatcher.prototype.initFieldErrors = function() {
|
2016-11-02 06:35:21 -04:00
|
|
|
$('.gl-show-field-errors').each((i, form) => {
|
2017-10-10 04:09:01 -04:00
|
|
|
new GlFieldErrors(form);
|
2016-10-12 12:47:31 -04:00
|
|
|
});
|
2016-09-09 08:21:00 -04:00
|
|
|
};
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
return Dispatcher;
|
|
|
|
})();
|
2018-02-01 22:28:50 -05:00
|
|
|
})();
|
2017-08-03 16:31:53 -04:00
|
|
|
|
2018-02-01 22:28:50 -05:00
|
|
|
export default function initDispatcher() {
|
|
|
|
return new Dispatcher();
|
|
|
|
}
|