From 4dfded8934b9ba04317bf53c2ad1f9bd3a31cc6d Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Fri, 10 Jul 2015 13:07:24 +0200
Subject: [PATCH] Make left menu more hierarchical and less contextual by
 adding back item at top

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
---
 CHANGELOG                                |  1 +
 app/views/layouts/nav/_group.html.haml   |  8 ++++++++
 app/views/layouts/nav/_profile.html.haml |  8 ++++++++
 app/views/layouts/nav/_project.html.haml | 15 +++++++++++++++
 features/groups.feature                  |  4 ++++
 features/project/project.feature         |  9 +++++++++
 features/steps/groups.rb                 |  4 ++++
 features/steps/project/project.rb        | 14 ++++++++++++++
 8 files changed, 63 insertions(+)

diff --git a/CHANGELOG b/CHANGELOG
index 5daee9830ed..80d0a1f954e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -41,6 +41,7 @@ v 7.13.0 (unreleased)
   - Allow users to be blocked and unblocked via the API
   - Use native Postgres database cleaning during backup restore
   - Redesign project page. Show README as default instead of activity. Move project activity to separate page
+  - Make left menu more hierarchical and less contextual by adding back item at top
 
 v 7.12.2
   - Correctly show anonymous authorized applications under Profile > Applications.
diff --git a/app/views/layouts/nav/_group.html.haml b/app/views/layouts/nav/_group.html.haml
index 9d216be151a..691bd12ecab 100644
--- a/app/views/layouts/nav/_group.html.haml
+++ b/app/views/layouts/nav/_group.html.haml
@@ -1,4 +1,12 @@
 %ul.nav.nav-sidebar
+  = nav_link do
+    = link_to root_path, title: 'Back to dashboard', data: {placement: 'right'} do
+      = icon('caret-square-o-left fw')
+      %span
+        Back to Dashboard
+
+  %li.separate-item
+
   = nav_link(path: 'groups#show', html_options: {class: 'home'}) do
     = link_to group_path(@group), title: 'Home', data: {placement: 'right'} do
       = icon('dashboard fw')
diff --git a/app/views/layouts/nav/_profile.html.haml b/app/views/layouts/nav/_profile.html.haml
index de5544268a1..00d3cb300d4 100644
--- a/app/views/layouts/nav/_profile.html.haml
+++ b/app/views/layouts/nav/_profile.html.haml
@@ -1,4 +1,12 @@
 %ul.nav.nav-sidebar
+  = nav_link do
+    = link_to root_path, title: 'Back to dashboard', data: {placement: 'right'} do
+      = icon('caret-square-o-left fw')
+      %span
+        Back to Dashboard
+
+  %li.separate-item
+
   = nav_link(path: 'profiles#show', html_options: {class: 'home'}) do
     = link_to profile_path, title: 'Profile', data: {placement: 'right'} do
       = icon('user fw')
diff --git a/app/views/layouts/nav/_project.html.haml b/app/views/layouts/nav/_project.html.haml
index 2012478eba9..a92d618284d 100644
--- a/app/views/layouts/nav/_project.html.haml
+++ b/app/views/layouts/nav/_project.html.haml
@@ -1,4 +1,19 @@
 %ul.nav.nav-sidebar
+  - if @project.group
+    = nav_link do
+      = link_to group_path(@project.group), title: 'Back to group', data: {placement: 'right'} do
+        = icon('caret-square-o-left fw')
+        %span
+          Back to Group
+  - else
+    = nav_link do
+      = link_to root_path, title: 'Back to dashboard', data: {placement: 'right'} do
+        = icon('caret-square-o-left fw')
+        %span
+          Back to Dashboard
+
+  %li.separate-item
+
   = nav_link(path: 'projects#show', html_options: {class: 'home'}) do
     = link_to project_path(@project), title: 'Project', class: 'shortcuts-project', data: {placement: 'right'} do
       = icon('home fw')
diff --git a/features/groups.feature b/features/groups.feature
index 415e43d6ae7..299e846edb0 100644
--- a/features/groups.feature
+++ b/features/groups.feature
@@ -4,6 +4,10 @@ Feature: Groups
     And "John Doe" is owner of group "Owned"
     And "John Doe" is guest of group "Guest"
 
+  Scenario: I should have back to group button
+    When I visit group "Owned" page
+    Then I should see back to dashboard button
+
   @javascript
   Scenario: I should see group "Owned" dashboard list
     When I visit group "Owned" page
diff --git a/features/project/project.feature b/features/project/project.feature
index 5fb2c67401e..089ffcba14a 100644
--- a/features/project/project.feature
+++ b/features/project/project.feature
@@ -18,6 +18,15 @@ Feature: Project
     Then I should see the default project avatar
     And I should not see the "Remove avatar" button
 
+  Scenario: I should have back to group button
+    And project "Shop" belongs to group
+    And I visit project "Shop" page
+    Then I should see back to group button
+
+  Scenario: I should have back to group button
+    And I visit project "Shop" page
+    Then I should see back to dashboard button
+
   Scenario: I should have readme on page
     And I visit project "Shop" page
     Then I should see project "Shop" README
diff --git a/features/steps/groups.rb b/features/steps/groups.rb
index 2812c5473e9..46e1f4d0990 100644
--- a/features/steps/groups.rb
+++ b/features/steps/groups.rb
@@ -5,6 +5,10 @@ class Spinach::Features::Groups < Spinach::FeatureSteps
   include SharedUser
   include Select2Helper
 
+  step 'I should see back to dashboard button' do
+    expect(page).to have_content 'Back to Dashboard'
+  end
+
   step 'gitlab user "Mike"' do
     create(:user, name: "Mike")
   end
diff --git a/features/steps/project/project.rb b/features/steps/project/project.rb
index e8f9a80737f..0404fd5e594 100644
--- a/features/steps/project/project.rb
+++ b/features/steps/project/project.rb
@@ -116,4 +116,18 @@ class Spinach::Features::Project < Spinach::FeatureSteps
   step 'I should not see "Snippets" button' do
     expect(page).not_to have_link 'Snippets'
   end
+
+  step 'project "Shop" belongs to group' do
+    group = create(:group)
+    @project.namespace = group
+    @project.save!
+  end
+
+  step 'I should see back to dashboard button' do
+    expect(page).to have_content 'Back to Dashboard'
+  end
+
+  step 'I should see back to group button' do
+    expect(page).to have_content 'Back to Group'
+  end
 end
-- 
GitLab