Commit 3e40d38d authored by Phil Hughes's avatar Phil Hughes

Merge branch 'fix-user-profile-tabs-showing-raw-json-instead' into 'master'

Fix user profile tabs showing raw json when navigating back and forward

See merge request !10352
parents 1f7bc0c5 5a2b3c65
...@@ -94,15 +94,17 @@ content on the Users#show page. ...@@ -94,15 +94,17 @@ content on the Users#show page.
e.preventDefault(); e.preventDefault();
$('.tab-pane.active').empty(); $('.tab-pane.active').empty();
this.loadTab($(e.target).attr('href'), this.getCurrentAction()); const endpoint = $(e.target).attr('href');
this.loadTab(this.getCurrentAction(), endpoint);
} }
tabShown(event) { tabShown(event) {
const $target = $(event.target); const $target = $(event.target);
const action = $target.data('action'); const action = $target.data('action');
const source = $target.attr('href'); const source = $target.attr('href');
this.setTab(source, action); const endpoint = $target.data('endpoint');
return this.setCurrentAction(source, action); this.setTab(action, endpoint);
return this.setCurrentAction(source);
} }
activateTab(action) { activateTab(action) {
...@@ -110,27 +112,27 @@ content on the Users#show page. ...@@ -110,27 +112,27 @@ content on the Users#show page.
.tab('show'); .tab('show');
} }
setTab(source, action) { setTab(action, endpoint) {
if (this.loaded[action]) { if (this.loaded[action]) {
return; return;
} }
if (action === 'activity') { if (action === 'activity') {
this.loadActivities(source); this.loadActivities();
} }
const loadableActions = ['groups', 'contributed', 'projects', 'snippets']; const loadableActions = ['groups', 'contributed', 'projects', 'snippets'];
if (loadableActions.indexOf(action) > -1) { if (loadableActions.indexOf(action) > -1) {
return this.loadTab(source, action); return this.loadTab(action, endpoint);
} }
} }
loadTab(source, action) { loadTab(action, endpoint) {
return $.ajax({ return $.ajax({
beforeSend: () => this.toggleLoading(true), beforeSend: () => this.toggleLoading(true),
complete: () => this.toggleLoading(false), complete: () => this.toggleLoading(false),
dataType: 'json', dataType: 'json',
type: 'GET', type: 'GET',
url: source, url: endpoint,
success: (data) => { success: (data) => {
const tabSelector = `div#${action}`; const tabSelector = `div#${action}`;
this.$parentEl.find(tabSelector).html(data.html); this.$parentEl.find(tabSelector).html(data.html);
...@@ -140,7 +142,7 @@ content on the Users#show page. ...@@ -140,7 +142,7 @@ content on the Users#show page.
}); });
} }
loadActivities(source) { loadActivities() {
if (this.loaded['activity']) { if (this.loaded['activity']) {
return; return;
} }
...@@ -155,7 +157,7 @@ content on the Users#show page. ...@@ -155,7 +157,7 @@ content on the Users#show page.
.toggle(status); .toggle(status);
} }
setCurrentAction(source, action) { setCurrentAction(source) {
let new_state = source; let new_state = source;
new_state = new_state.replace(/\/+$/, ''); new_state = new_state.replace(/\/+$/, '');
new_state += this._location.search + this._location.hash; new_state += this._location.search + this._location.hash;
......
...@@ -84,19 +84,19 @@ ...@@ -84,19 +84,19 @@
.fade-right= icon('angle-right') .fade-right= icon('angle-right')
%ul.nav-links.center.user-profile-nav.scrolling-tabs %ul.nav-links.center.user-profile-nav.scrolling-tabs
%li.js-activity-tab %li.js-activity-tab
= link_to user_path, data: {target: 'div#activity', action: 'activity', toggle: 'tab'} do = link_to user_path, data: { target: 'div#activity', action: 'activity', toggle: 'tab' } do
Activity Activity
%li.js-groups-tab %li.js-groups-tab
= link_to user_groups_path, data: {target: 'div#groups', action: 'groups', toggle: 'tab'} do = link_to user_groups_path, data: { target: 'div#groups', action: 'groups', toggle: 'tab', endpoint: user_groups_path(format: :json) } do
Groups Groups
%li.js-contributed-tab %li.js-contributed-tab
= link_to user_contributed_projects_path, data: {target: 'div#contributed', action: 'contributed', toggle: 'tab'} do = link_to user_contributed_projects_path, data: { target: 'div#contributed', action: 'contributed', toggle: 'tab', endpoint: user_contributed_projects_path(format: :json) } do
Contributed projects Contributed projects
%li.js-projects-tab %li.js-projects-tab
= link_to user_projects_path, data: {target: 'div#projects', action: 'projects', toggle: 'tab'} do = link_to user_projects_path, data: { target: 'div#projects', action: 'projects', toggle: 'tab', endpoint: user_projects_path(format: :json) } do
Personal projects Personal projects
%li.js-snippets-tab %li.js-snippets-tab
= link_to user_snippets_path, data: {target: 'div#snippets', action: 'snippets', toggle: 'tab'} do = link_to user_snippets_path, data: { target: 'div#snippets', action: 'snippets', toggle: 'tab', endpoint: user_snippets_path(format: :json) } do
Snippets Snippets
%div{ class: container_class } %div{ class: container_class }
......
---
title: Prevent user profile tabs to display raw json when going back and forward in
browser history
merge_request:
author:
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment