Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[35527] Add quick-menu to top menu (#9058)

Oliver Günther6944affca8aa
diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index f7ad69fb6ab..afe6ff4c82f 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -135,6 +135,7 @@ See docs/COPYRIGHT.rdoc for more details.
</div>
<%= call_hook :view_layouts_base_top_menu %>
<div class="top-menu-items-right">
+ <%= render_quick_add_menu %>
<%= render partial: 'search/mini_form' %>
<%= render_top_menu_right %>
</div>
diff --git a/app/views/projects/form/_project_attributes.html.erb b/app/views/projects/form/_project_attributes.html.erb
index 02e9410aaa3..2eeccd3fb31 100644
--- a/app/views/projects/form/_project_attributes.html.erb
+++ b/app/views/projects/form/_project_attributes.html.erb
@@ -39,7 +39,7 @@ See docs/COPYRIGHT.rdoc for more details.
<%= render partial: "customizable/form",
locals: { form: form, help_text: { 'attribute-scope': :Project }, all_fields: all_fields, only_required: render_advanced } %>
<% if render_advanced %>
-<fieldset id="advanced-settings" class="form--fieldset -collapsible collapsed">
+<fieldset id="advanced-project-settings" class="form--fieldset -collapsible collapsed">
<legend class="form--fieldset-legend" title="<%=t(:label_show_hide)%>" >
<a href="#"><%= t(:label_advanced_settings) %></a>
</legend>
@@ -67,6 +67,6 @@ See docs/COPYRIGHT.rdoc for more details.
<% unless form.object.errors[:identifier].blank? %>
<%= nonced_javascript_tag do %>
- jQuery('#advanced-settings > .advanced-settings-inner').show();
+ jQuery('#advanced-project-settings > .advanced-settings-inner').show();
<% end %>
<% end %>
diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb
index 8e0f524312a..bd7ad3a7c68 100644
--- a/config/initializers/menus.rb
+++ b/config/initializers/menus.rb
@@ -62,10 +62,33 @@ Redmine::MenuManager.map :top_menu do |menu|
icon: 'icon5 icon-help',
html: { accesskey: OpenProject::AccessKeys.key_for(:help),
title: I18n.t('label_help'),
- class: 'menu-item--help',
+ class: 'top-menu-help',
target: '_blank' }
end
+Redmine::MenuManager.map :quick_add_menu do |menu|
+ menu.push :new_project,
+ Proc.new { |project|
+ { controller: '/projects', action: :new, id: nil, parent_id: project&.id }
+ },
+ caption: ->(*) { Project.model_name.human },
+ icon: "icon-add icon3",
+ html: {
+ aria: { label: I18n.t(:label_project_new) },
+ title: I18n.t(:label_project_new)
+ },
+ if: Proc.new { User.current.allowed_to_globally?(:add_project) }
+
+ menu.push :invite_user,
+ nil,
+ caption: :label_invite_user,
+ icon: 'icon3 icon-user-plus',
+ html: {
+ 'invite-user-modal-augment': 'invite-user-modal-augment'
+ },
+ if: Proc.new { User.current.allowed_to_globally?(:manage_members) }
+end
+
Redmine::MenuManager.map :account_menu do |menu|
menu.push :my_page,
:my_page_path,
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 6022872d7a2..622f19c8457 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1266,6 +1266,10 @@ en:
instructions_after_logout: "You can sign in again by clicking %{signin}."
instructions_after_error: "You can try to sign in again by clicking %{signin}. If the error persists, ask your admin for help."
+ menus:
+ quick_add:
+ label: "Open quick add menu"
+
my_account:
access_tokens:
no_results:
diff --git a/frontend/angular.json b/frontend/angular.json
index 3a9ffe60dd0..c64f46cd6cd 100644
--- a/frontend/angular.json
+++ b/frontend/angular.json
@@ -133,11 +133,15 @@
"defaultProject": "OpenProject",
"schematics": {
"@schematics/angular:component": {
- "prefix": "app",
- "style": "css"
+ "prefix": "op",
+ "style": "sass",
+ "changeDetection": "OnPush",
+ "skipTests": true,
+ "flat": true
},
"@schematics/angular:directive": {
- "prefix": "app"
+ "prefix": "op",
+ "skipTests": true
}
},
"cli": {
diff --git a/frontend/src/app/globals/onboarding/tours/menu_tour.ts b/frontend/src/app/globals/onboarding/tours/menu_tour.ts
index 99888108113..818b86d0640 100644
--- a/frontend/src/app/globals/onboarding/tours/menu_tour.ts
+++ b/frontend/src/app/globals/onboarding/tours/menu_tour.ts
@@ -11,7 +11,7 @@ export function menuTourSteps() {
'nextButton': { text: I18n.t('js.onboarding.buttons.next') },
},
{
- 'next .menu-item--help': I18n.t('js.onboarding.steps.help_menu'),
+ 'next .top-menu-help': I18n.t('js.onboarding.steps.help_menu'),
'shape': 'circle',
'showSkip': false,
'nextButton': { text: I18n.t('js.onboarding.buttons.got_it') }
diff --git a/frontend/src/app/modules/augmenting/dynamic-scripts/project_form_listener.js b/frontend/src/app/modules/augmenting/dynamic-scripts/project_form_listener.js
index 93cab282ae6..e5cba83dbde 100644
--- a/frontend/src/app/modules/augmenting/dynamic-scripts/project_form_listener.js
+++ b/frontend/src/app/modules/augmenting/dynamic-scripts/project_form_listener.js
@@ -106,7 +106,7 @@
function observeTemplateChanges() {
jQuery('#project-select-template').on('change', function() {
const name = document.getElementById('project_name');
- const fieldset = document.getElementById('advanced-settings');
+ const fieldset = document.getElementById('advanced-project-settings');
// When the advanced settings were opened once, we assume they were changed
// and show an alert before switching the template
@@ -126,9 +126,19 @@
}
}
+ function expandAdvancedOnParams() {
+ const fieldset = document.getElementById('advanced-project-settings');
+ let params = new URLSearchParams(location.search);
+
+ if (params.has('parent_id')) {
+ fieldset.querySelector('.form--fieldset-legend').click();
+ }
+ }
+
observeProjectIdentifier();
observeProjectName();
observeTemplateChanges();
+ expandAdvancedOnParams();
focusOnName();
});
}(jQuery));
diff --git a/frontend/src/app/modules/invite-user-modal/invite-user-modal-augment.service.ts b/frontend/src/app/modules/invite-user-modal/invite-user-modal-augment.service.ts
new file mode 100644
index 00000000000..e97b84ab528
--- /dev/null
+++ b/frontend/src/app/modules/invite-user-modal/invite-user-modal-augment.service.ts
@@ -0,0 +1,81 @@
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2021 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See docs/COPYRIGHT.rdoc for more details.
+//++
+
+
+import {Inject, Injectable, Injector} from "@angular/core";
+import {DOCUMENT} from "@angular/common";
+import {DynamicContentModal} from "core-components/modals/modal-wrapper/dynamic-content.modal";
+import {OpModalService} from "core-app/modules/modal/modal.service";
+import {InviteUserModalComponent} from "core-app/modules/invite-user-modal/invite-user.component";
+import {CurrentProjectService} from "core-components/projects/current-project.service";
+import ClickEvent = JQuery.ClickEvent;
+
+const attributeSelector = '[invite-user-modal-augment]';
+
+/**
+ * This service triggers user-invite modals to clicks on elements
+ * with the attribute [invite-user-modal-augment] set.
+ */
+@Injectable({ providedIn: 'root' })
+export class OpInviteUserModalAugmentService {
+
+ constructor(@Inject(DOCUMENT) protected documentElement:Document,
+ protected opModalService:OpModalService,
+ protected currentProjectService:CurrentProjectService) {
+ }
+
+ /**
+ * Create initial listeners for Rails-rendered modals
+ */
+ public setupListener() {
+ const matches = this.documentElement.querySelectorAll(attributeSelector);
+ for (let i = 0; i < matches.length; ++i) {
+ const el = matches[i] as HTMLElement;
+ el.addEventListener('click', this.spawnModal.bind(this));
+ }
+ }
+
+ private spawnModal(event:ClickEvent) {
+ event.preventDefault();
+
+ const modal = this.opModalService.show(
+ InviteUserModalComponent,
+ 'global',
+ { projectId: this.currentProjectService.id }
+ );
+
+ modal
+ .closingEvent
+ .subscribe((modal) => {
+ // Just reload the page for now if we saved anything
+ if (modal.data) {
+ window.location.reload();
+ }
+ });
+ }
+}
diff --git a/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts b/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts
index 7947ed08996..d07fc87aa48 100644
--- a/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts
+++ b/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts
@@ -1,4 +1,4 @@
-import { NgModule } from "@angular/core";
+import { APP_INITIALIZER, Injector, NgModule } from "@angular/core";
import { ReactiveFormsModule } from "@angular/forms";
import { OpenprojectModalModule } from "core-app/modules/modal/modal.module";
import { InviteUserModalComponent } from "./invite-user.component";
@@ -14,6 +14,14 @@ import { SuccessComponent } from "./success/success.component";
import { NgSelectModule } from "@ng-select/ng-select";
import { OpenprojectCommonModule } from "core-app/modules/common/openproject-common.module";
import { InviteUserButtonComponent } from "core-app/modules/invite-user-modal/button/invite-user-button.component";
+import { OpInviteUserModalAugmentService } from "core-app/modules/invite-user-modal/invite-user-modal-augment.service";
+
+export function initializeServices(injector:Injector) {
+ return function () {
+ const inviteUserAugmentService = injector.get(OpInviteUserModalAugmentService);
+ inviteUserAugmentService.setupListener();
+ }
+}
@NgModule({
imports: [
@@ -37,6 +45,10 @@ import { InviteUserButtonComponent } from "core-app/modules/invite-user-modal/bu
MessageComponent,
SuccessComponent,
SummaryComponent,
- ]
+ ],
+ providers: [
+ { provide: APP_INITIALIZER, useFactory: initializeServices, deps: [Injector], multi: true },
+ ],
})
-export class OpenprojectInviteUserModalModule { }
+export class OpenprojectInviteUserModalModule {
+}
diff --git a/frontend/src/global_styles/layout/_index.sass b/frontend/src/global_styles/layout/_index.sass
index d6b32e1a098..56d19ef2bec 100644
--- a/frontend/src/global_styles/layout/_index.sass
+++ b/frontend/src/global_styles/layout/_index.sass
@@ -33,8 +33,6 @@
@import grid
@import tree_menu
@import warning_bar
-@import top_menu
-@import top_menu_mobile
@import breadcrumb
@import main_menu
@import main_menu_mobile
@@ -46,6 +44,9 @@
@import toolbar_mobile
@import zen_mode
+// Top menu styles
+@import top_menu/index
+
// Work packages page layouts
@import work_packages/index
diff --git a/frontend/src/global_styles/layout/top_menu/_dropdown.sass b/frontend/src/global_styles/layout/top_menu/_dropdown.sass
new file mode 100644
index 00000000000..0caafc00002
--- /dev/null
+++ b/frontend/src/global_styles/layout/top_menu/_dropdown.sass
@@ -0,0 +1,44 @@
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2021 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See docs/COPYRIGHT.rdoc for more details.
+//++
+
+.top-menu-dropdown
+ &--link
+ @extend %top-menu-link-styles
+
+ &--headline
+ padding-left: 10px
+ font-size: 12px
+ color: var(--gray-dark)
+ text-transform: uppercase
+
+ &--separator
+ background: none
+ border-bottom: 1px solid var(--content-form-separator-color)
+ margin: 0 0 10px
+ &+ li
+ margin-bottom: 5px
diff --git a/frontend/src/global_styles/layout/top_menu/_help_menu.sass b/frontend/src/global_styles/layout/top_menu/_help_menu.sass
new file mode 100644
index 00000000000..2a534ced41e
--- /dev/null
+++ b/frontend/src/global_styles/layout/top_menu/_help_menu.sass
@@ -0,0 +1,14 @@
+.top-menu-help
+ &--icon
+ border-width: 2px
+ border-style: solid
+ color: var(--header-item-font-color)
+ border-color: var(--header-item-font-color)
+ border-radius: 50%
+ width: 26px
+ height: 26px
+ display: inline-flex
+
+ &--dropdown
+ left: auto
+ right: 0
diff --git a/frontend/src/global_styles/layout/top_menu/_index.sass b/frontend/src/global_styles/layout/top_menu/_index.sass
new file mode 100644
index 00000000000..c66b5544307
--- /dev/null
+++ b/frontend/src/global_styles/layout/top_menu/_index.sass
@@ -0,0 +1,38 @@
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2021 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See docs/COPYRIGHT.rdoc for more details.
+//++
+
+// General top_menu
+@import mixins
+@import top_menu_legacy
+@import dropdown
+@import top_menu_mobile
+
+// Specifics for certain menus
+@import quick_add_menu
+@import help_menu
+@import overridden_help_link
diff --git a/frontend/src/global_styles/layout/top_menu/_mixins.sass b/frontend/src/global_styles/layout/top_menu/_mixins.sass
new file mode 100644
index 00000000000..c6c93d07824
--- /dev/null
+++ b/frontend/src/global_styles/layout/top_menu/_mixins.sass
@@ -0,0 +1,48 @@
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2021 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See docs/COPYRIGHT.rdoc for more details.
+//++
+
+%top-menu-hover-styles
+ background: var(--header-item-bg-hover-color)
+ color: var(--header-item-font-hover-color)
+ border-bottom-width: var(--header-border-bottom-width)
+ border-bottom-color: var(--header-border-bottom-color)
+ border-bottom-style: solid
+ text-decoration: none
+
+%top-menu-link-styles
+ display: block
+ height: var(--header-height)
+ line-height: var(--header-height)
+ zoom: 1
+ color: var(--header-item-font-color)
+ font-size: var(--header-item-font-size)
+ text-decoration: none
+ padding: 0 15px
+ &:hover
+ @extend %top-menu-hover-styles
+
diff --git a/frontend/src/global_styles/layout/top_menu/_overridden_help_link.sass b/frontend/src/global_styles/layout/top_menu/_overridden_help_link.sass
new file mode 100644
index 00000000000..df6d1b348a3
--- /dev/null
+++ b/frontend/src/global_styles/layout/top_menu/_overridden_help_link.sass
@@ -0,0 +1,7 @@
+.overridden-help-menu
+ // We have no control over the menu item being rendered
+ // so we cannot enforce bem element here
+ .help-menu-item
+ @extend %top-menu-link-styles
+
+
diff --git a/frontend/src/global_styles/layout/top_menu/_quick_add_menu.sass b/frontend/src/global_styles/layout/top_menu/_quick_add_menu.sass
new file mode 100644
index 00000000000..3ea994cef12
--- /dev/null
+++ b/frontend/src/global_styles/layout/top_menu/_quick_add_menu.sass
@@ -0,0 +1,45 @@
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2021 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See docs/COPYRIGHT.rdoc for more details.
+//++
+
+.quick-add-menu
+ &--icon
+ background: var(--button--alt-highlight-background-color)
+ color: var(--button--alt-highlight-font-color)
+ border-width: 2px
+ border-style: solid
+ border-color: var(--button--alt-highlight-background-color)
+ border-radius: 50%
+ padding: 0.25rem
+ width: 26px
+ height: 26px
+ display: inline-flex
+
+ &:hover
+ background: var(--button--alt-highlight-background-hover-color)
+ border-color: var(--button--alt-highlight-background-hover-color)
+ color: var(--button--alt-highlight-font-color)
diff --git a/frontend/src/global_styles/layout/_top_menu.sass b/frontend/src/global_styles/layout/top_menu/_top_menu_legacy.sass
similarity index 79%
rename from frontend/src/global_styles/layout/_top_menu.sass
rename to frontend/src/global_styles/layout/top_menu/_top_menu_legacy.sass
index fb7848241bb..364e3a34511 100644
--- a/frontend/src/global_styles/layout/_top_menu.sass
+++ b/frontend/src/global_styles/layout/top_menu/_top_menu_legacy.sass
@@ -26,24 +26,9 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-%top-menu-hover-styles
- background: var(--header-item-bg-hover-color)
- color: var(--header-item-font-hover-color)
- border-bottom-width: var(--header-border-bottom-width)
- border-bottom-color: var(--header-border-bottom-color)
- border-bottom-style: solid
-%top-menu-link-styles
- display: block
- height: var(--header-height)
- line-height: var(--header-height)
- zoom: 1
- color: var(--header-item-font-color)
- font-size: var(--header-item-font-size)
- text-decoration: none
- padding: 0 15px
- &:hover
- @extend %top-menu-hover-styles
+// These styles do not follow BEM
+// instead of modifying, please extract into BEM pieces when you touch these
#logo
width: 230px
@@ -77,19 +62,13 @@
border-top: 0
flex: 1 1 auto
li.drop-down,
- li.top-menu--login,
- li.help-menu--overridden-link
+ li.top-menu--login
float: left
list-style-type: none
white-space: nowrap
position: relative
z-index: 5
padding: 0
- > a
- @extend %top-menu-link-styles
-
- &:hover .icon-help:before
- border-color: var(--header-item-font-hover-color)
> ul
min-width: 270px
@@ -114,7 +93,6 @@
@include icon-mixin-pulldown-up
li.last-child > ul,
- .drop-down--help,
.drop-down--modules
left: auto
right: 0
@@ -124,21 +102,6 @@
&:nth-last-child(2)
margin-bottom: 6px
- .drop-down--help
- .form--separator
- margin-bottom: 10px
- &+ li
- margin-bottom: 5px
- .drop-down--help-headline
- padding-left: 10px
- font-size: 12px
- color: var(--gray-dark)
- text-transform: uppercase
-
- #loggedas
- float: right
- margin-right: 0.5em
- color: #fff
#nav-login-content
width: 506px
position: relative
@@ -173,10 +136,6 @@
.top-menu-items-right
display: flex
-#header
- .chzn-container .chzn-results .highlighted
- background-color: #24b3e7
-
.account-nav
display: block
li
@@ -222,15 +181,6 @@
border: 1px solid
border-color: var(--header-item-font-color)
- .icon-help:before
- border-width: 2px
- border-style: solid
- border-color: var(--header-item-font-color)
- border-radius: 50%
- width: 26px
- height: 26px
- display: inline-block
-
.icon-user
font-size: 18px
[class*="icon-"]:before
diff --git a/frontend/src/global_styles/layout/_top_menu_mobile.sass b/frontend/src/global_styles/layout/top_menu/_top_menu_mobile.sass
similarity index 100%
rename from frontend/src/global_styles/layout/_top_menu_mobile.sass
rename to frontend/src/global_styles/layout/top_menu/_top_menu_mobile.sass
diff --git a/lib/redmine/menu_manager/menu_helper.rb b/lib/redmine/menu_manager/menu_helper.rb
index c141f89d733..ce6c1e9b571 100644
--- a/lib/redmine/menu_manager/menu_helper.rb
+++ b/lib/redmine/menu_manager/menu_helper.rb
@@ -80,13 +80,13 @@ module Redmine::MenuManager::MenuHelper
# Render a dropdown menu item with the given MenuItem children.
# Caller may add additional items through the optional block.
# Remaining options are passed through to +render_menu_dropdown+.
- def render_menu_dropdown_with_items(label:, label_options:, items:, options: {})
+ def render_menu_dropdown_with_items(label:, label_options:, items:, options: {}, project: nil)
selected = any_item_selected?(items)
label_node = render_drop_down_label_node(label, selected, label_options)
render_menu_dropdown(label_node, options) do
items.each do |item|
- concat render_menu_node(item)
+ concat render_menu_node(item, project)
end
concat(yield) if block_given?
@@ -100,7 +100,7 @@ module Redmine::MenuManager::MenuHelper
# menu_item_class: Additional classes for the menu item li wrapper
# drop_down_class: Additional classes for the hidden drop down
def render_menu_dropdown(label_node, options = {}, &block)
- content_tag :li, class: "#{options[:menu_item_class]} drop-down" do
+ content_tag :li, class: "top-menu-dropdown #{options[:menu_item_class]} drop-down" do
concat(label_node)
concat(content_tag(:ul,
style: 'display:none',
@@ -113,13 +113,13 @@ module Redmine::MenuManager::MenuHelper
def render_drop_down_label_node(label, selected, options = {})
options[:title] ||= selected ? t(:description_current_position) + label : label
options[:aria] = { haspopup: 'true' }
- options[:class] = "#{options[:class]} #{selected ? 'selected' : ''}"
+ options[:class] = "top-menu-dropdown--link #{options[:class]} #{selected ? 'selected' : ''}"
link_to('', options) do
concat(op_icon(options[:icon])) if options[:icon]
concat(you_are_here_info(selected).html_safe)
concat(content_tag(:span, label, class: 'button--dropdown-text'))
- concat('<i class="button--dropdown-indicator"></i>'.html_safe) unless options[:icon]
+ concat('<i class="button--dropdown-indicator"></i>'.html_safe) unless options.key?(:icon)
end
end
@@ -270,6 +270,8 @@ module Redmine::MenuManager::MenuHelper
engine = node_engine(node)
case node.url(project)
+ when NilClass
+ '#'
when Hash
engine.url_for(project.nil? ? node.url(project) : { node.param => project }.merge(node.url(project)))
when Symbol
@@ -326,7 +328,10 @@ module Redmine::MenuManager::MenuHelper
end
def node_action_allowed?(node, project, user)
- user&.allowed_to?(node.url(project), project)
+ url = node.url(project)
+ return true unless url
+
+ user&.allowed_to?(url, project)
end
def visible_node?(menu, node)
diff --git a/lib/redmine/menu_manager/top_menu/help_menu.rb b/lib/redmine/menu_manager/top_menu/help_menu.rb
index 401e093f2d0..3f880e18755 100644
--- a/lib/redmine/menu_manager/top_menu/help_menu.rb
+++ b/lib/redmine/menu_manager/top_menu/help_menu.rb
@@ -35,8 +35,7 @@ module Redmine::MenuManager::TopMenu::HelpMenu
OpenProject::Cache.fetch(cache_key) do
if OpenProject::Static::Links.help_link_overridden?
- render_menu_node(item)
- content_tag('li', render_single_menu_node(item), class: 'help-menu--overridden-link')
+ content_tag('li', render_single_menu_node(item), class: 'overridden-help-menu')
else
render_help_dropdown
end
@@ -46,15 +45,15 @@ module Redmine::MenuManager::TopMenu::HelpMenu
def render_help_dropdown
link_to_help_pop_up = link_to '',
title: I18n.t(:label_help),
- class: 'menu-item--help',
+ class: 'top-menu-dropdown--link',
aria: { haspopup: 'true' } do
- op_icon('icon-help')
+ op_icon('icon-help top-menu-help--icon')
end
render_menu_dropdown(
link_to_help_pop_up,
- menu_item_class: 'hidden-for-mobile',
- drop_down_class: 'drop-down--help'
+ menu_item_class: 'hidden-for-mobile top-menu-help',
+ drop_down_class: 'top-menu-help--dropdown'
) do
result = ''.html_safe
render_onboarding result
@@ -70,11 +69,11 @@ module Redmine::MenuManager::TopMenu::HelpMenu
def render_onboarding(result)
result << content_tag(:li) do
content_tag(:span, I18n.t('top_menu.getting_started'),
- class: 'drop-down--help-headline',
+ class: 'top-menu-dropdown--headline',
title: I18n.t('top_menu.getting_started'))
end
result << render_onboarding_menu_item
- result << content_tag(:hr, '', class: 'form--separator')
+ result << content_tag(:hr, '', class: 'top-menu-dropdown--separator')
end
def render_onboarding_menu_item
@@ -84,7 +83,7 @@ module Redmine::MenuManager::TopMenu::HelpMenu
def render_help_and_support(result)
result << content_tag(:li) do
content_tag :span, I18n.t('top_menu.help_and_support'),
- class: 'drop-down--help-headline',
+ class: 'top-menu-dropdown--headline',
title: I18n.t('top_menu.help_and_support')
end
if EnterpriseToken.show_banners?
@@ -101,14 +100,14 @@ module Redmine::MenuManager::TopMenu::HelpMenu
result << static_link_item(:shortcuts)
result << static_link_item(:forums)
result << static_link_item(:professional_support)
- result << content_tag(:hr, '', class: 'form--separator')
+ result << content_tag(:hr, '', class: 'top-menu-dropdown--separator')
end
def render_additional_resources(result)
result << content_tag(:li) do
content_tag :span,
I18n.t('top_menu.additional_resources'),
- class: 'drop-down--help-headline',
+ class: 'top-menu-dropdown--headline',
title: I18n.t('top_menu.additional_resources')
end
diff --git a/lib/redmine/menu_manager/top_menu/quick_add_menu.rb b/lib/redmine/menu_manager/top_menu/quick_add_menu.rb
new file mode 100644
index 00000000000..afee2f19eca
--- /dev/null
+++ b/lib/redmine/menu_manager/top_menu/quick_add_menu.rb
@@ -0,0 +1,118 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+module Redmine::MenuManager::TopMenu::QuickAddMenu
+ include OpenProject::StaticRouting::UrlHelpers
+
+ def render_quick_add_menu
+ return unless show_quick_add_menu?
+
+ content_tag :ul, class: 'menu_root account-nav quick-add-menu' do
+ render_quick_add_dropdown
+ end
+ end
+
+ private
+
+ def render_quick_add_dropdown
+ render_menu_dropdown_with_items(
+ label: '',
+ label_options: {
+ title: I18n.t('menus.quick_add.label'),
+ icon: 'icon-add quick-add-menu--icon',
+ class: 'quick-add-menu--button'
+ },
+ items: first_level_menu_items_for(:quick_add_menu),
+ options: { drop_down_id: 'quick-add-menu' },
+ project: @project
+ ) do
+ work_package_quick_add_items
+ # Return nil as the yield result is concat as well
+ nil
+ end
+ end
+
+ def work_package_quick_add_items
+ return unless visible_types.any?
+
+ concat content_tag(:hr, '', class: 'top-menu-dropdown--separator')
+ concat work_package_type_heading
+
+ visible_types
+ .pluck(:id, :name)
+ .each do |id, name|
+ concat work_package_create_link(id, name)
+ end
+ end
+
+ def work_package_type_heading
+ content_tag(:li) do
+ content_tag :span,
+ I18n.t(:label_work_package_plural),
+ class: 'top-menu-dropdown--headline'
+ end
+ end
+
+ def visible_types
+ @visible_types ||= begin
+ if user_can_create_work_package?
+ in_project_context? ? @project.types : Type.all
+ else
+ Type.none
+ end
+ end
+ end
+
+ def work_package_create_link(type_id, type_name)
+ content_tag(:li) do
+ if in_project_context?
+ link_to type_name,
+ new_project_work_packages_path(project_id: @project.identifier, type: type_id),
+ class: "__hl_inline_type_#{type_id}"
+ else
+ link_to type_name,
+ new_work_packages_path(type: type_id),
+ class: "__hl_inline_type_#{type_id}"
+ end
+ end
+ end
+
+ def user_can_create_work_package?
+ User.current.allowed_to?(:add_work_packages, @project, global: !in_project_context?)
+ end
+
+ def show_quick_add_menu?
+ %i[add_work_packages add_project manage_members].any? do |permission|
+ User.current.allowed_to_globally?(permission)
+ end
+ end
+
+ def in_project_context?
+ @project&.persisted?
+ end
+end
diff --git a/lib/redmine/menu_manager/top_menu_helper.rb b/lib/redmine/menu_manager/top_menu_helper.rb
index 7de13059677..633fe7c36b9 100644
--- a/lib/redmine/menu_manager/top_menu_helper.rb
+++ b/lib/redmine/menu_manager/top_menu_helper.rb
@@ -29,16 +29,17 @@
module Redmine::MenuManager::TopMenuHelper
include Redmine::MenuManager::TopMenu::HelpMenu
include Redmine::MenuManager::TopMenu::ProjectsMenu
+ include Redmine::MenuManager::TopMenu::QuickAddMenu
def render_top_menu_left
- content_tag :ul, id: 'account-nav-left', class: 'menu_root account-nav' do
+ content_tag :ul, id: 'account-nav-left', class: 'menu_root account-nav top-menu' do
[render_main_top_menu_nodes,
render_projects_top_menu_node].join.html_safe
end
end
def render_top_menu_right
- content_tag :ul, id: 'account-nav-right', class: 'menu_root account-nav' do
+ content_tag :ul, id: 'account-nav-right', class: 'menu_root account-nav top-menu-right' do
[render_module_top_menu_node,
render_help_top_menu_node,
render_user_top_menu_node].join.html_safe
@@ -60,7 +61,7 @@ module Redmine::MenuManager::TopMenuHelper
def render_login_drop_down
url = { controller: '/account', action: 'login' }
link = link_to url,
- class: 'login',
+ class: 'top-menu-dropdown--link login',
title: I18n.t(:label_login) do
concat('<span class="button--dropdown-text hidden-for-mobile">'.concat(I18n.t(:label_login)).concat('</span>').html_safe)
concat('<i class="button--dropdown-indicator hidden-for-mobile"></i>'.html_safe)
diff --git a/spec/features/menu_items/help_menu_spec.rb b/spec/features/menu_items/help_menu_spec.rb
index 21507257173..e71ef0cdc2a 100644
--- a/spec/features/menu_items/help_menu_spec.rb
+++ b/spec/features/menu_items/help_menu_spec.rb
@@ -30,7 +30,7 @@ require 'spec_helper'
feature 'Help menu items' do
let(:user) { FactoryBot.create :admin }
- let(:help_item) { find('.menu-item--help') }
+ let(:help_item) { find('.top-menu-help') }
before do
login_as user
@@ -41,7 +41,7 @@ feature 'Help menu items' do
visit home_path
help_item.click
- expect(page).to have_selector('.drop-down--help li',
+ expect(page).to have_selector('.top-menu-help li',
text: I18n.t('homescreen.links.user_guides'))
end
end
@@ -56,7 +56,7 @@ feature 'Help menu items' do
visit home_path
expect(help_item[:href]).to eq(custom_url)
- expect(page).to have_no_selector('.drop-down--help', visible: false)
+ expect(page).to have_no_selector('.top-menu-help .top-menu-dropdown--link', visible: false)
end
end
end
diff --git a/spec/features/menu_items/quick_add_menu_spec.rb b/spec/features/menu_items/quick_add_menu_spec.rb
new file mode 100644
index 00000000000..4ff6867954f
--- /dev/null
+++ b/spec/features/menu_items/quick_add_menu_spec.rb
@@ -0,0 +1,151 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+feature 'Quick-add menu', js: true, selenium: true do
+ let(:quick_add) { ::Components::QuickAddMenu.new }
+
+ context 'as a logged in user with add_project permission' do
+ current_user { FactoryBot.create :user, global_permission: %i[add_project] }
+
+ it 'shows the add project option' do
+ visit home_path
+
+ quick_add.expect_visible
+ quick_add.toggle
+ quick_add.expect_add_project
+ quick_add.expect_user_invite present: false
+ quick_add.expect_no_work_package_types
+
+ quick_add.click_link 'Project'
+ expect(page).to have_current_path new_project_path
+ end
+
+ context 'with an existing project' do
+ let(:project) { FactoryBot.create :project }
+ current_user do
+ FactoryBot.create :user,
+ member_in_project: project,
+ member_with_permissions: %i[add_project view_project add_subprojects]
+ end
+
+ it 'moves to a form with parent_id set' do
+ visit project_path(project)
+
+ quick_add.expect_visible
+ quick_add.toggle
+ quick_add.expect_add_project
+
+ quick_add.click_link 'Project'
+ expect(page).to have_current_path new_project_path(parent_id: project.id)
+
+ expect(page).to have_select('project_parent_id', selected: project.name, visible: true)
+ end
+ end
+ end
+
+ context 'with current user as member with permission :manage_members in one project' do
+ let!(:project) { FactoryBot.create :project }
+ let(:invite_modal) { ::Components::Users::InviteUserModal.new project: project, role: nil, principal: nil }
+
+ current_user do
+ FactoryBot.create :user,
+ member_in_project: project,
+ member_with_permissions: %i[manage_members]
+ end
+
+ it 'shows the user invite screen' do
+ visit home_path
+
+ quick_add.expect_visible
+ quick_add.toggle
+ quick_add.expect_add_project present: false
+ quick_add.expect_no_work_package_types
+ quick_add.expect_user_invite
+
+ quick_add.click_link 'Invite user'
+ invite_modal.expect_open
+ end
+ end
+
+ context 'with a project with one of two work package types' do
+ let!(:type_bug) { FactoryBot.create :type_bug }
+ let!(:other_type) { FactoryBot.create :type_task }
+ let!(:project) { FactoryBot.create :project, types: [type_bug] }
+
+ current_user do
+ FactoryBot.create :user,
+ member_in_project: project,
+ member_with_permissions: %i[add_work_packages]
+ end
+
+ it 'shows both types outside and the one within' do
+ visit project_path(project)
+
+ quick_add.expect_visible
+ quick_add.toggle
+ quick_add.expect_add_project present: false
+ quick_add.expect_user_invite present: false
+ quick_add.expect_work_package_type type_bug.name
+ quick_add.expect_work_package_type other_type.name, present: false
+ quick_add.click_link type_bug.name
+
+ expect(page)
+ .to have_current_path new_project_work_packages_path(project_id: project, type: type_bug.id)
+
+ visit home_path
+
+ quick_add.expect_visible
+ quick_add.toggle
+ quick_add.expect_work_package_type type_bug.name
+ quick_add.expect_work_package_type other_type.name
+
+ quick_add.click_link other_type.name
+ expect(page).to have_current_path new_work_packages_path(type: other_type.id)
+ end
+ end
+
+ context 'as a logged in user with no permissions' do
+ current_user { FactoryBot.create :user }
+
+ it 'does not show the quick add menu on the home screen' do
+ visit home_path
+ quick_add.expect_invisible
+ end
+ end
+
+ context 'as an anonymous user' do
+ current_user { FactoryBot.create :anonymous }
+
+ it 'does not show the quick add menu on the home screen' do
+ visit home_path
+ quick_add.expect_invisible
+ end
+ end
+end
diff --git a/spec/features/projects/projects_spec.rb b/spec/features/projects/projects_spec.rb
index b58c5047c2a..421964c74fa 100644
--- a/spec/features/projects/projects_spec.rb
+++ b/spec/features/projects/projects_spec.rb
@@ -200,7 +200,7 @@ describe 'Projects', type: :feature do
click_on 'Advanced settings'
- within('#advanced-settings') do
+ within('#advanced-project-settings') do
expect(page).to have_content 'Optional Foo'
expect(page).not_to have_content 'Required Foo'
end
diff --git a/spec/features/projects/template_spec.rb b/spec/features/projects/template_spec.rb
index 84d8f691ec9..b13c3e33d9b 100644
--- a/spec/features/projects/template_spec.rb
+++ b/spec/features/projects/template_spec.rb
@@ -89,7 +89,7 @@ describe 'Project templates', type: :feature, js: true do
expect(page).to have_select 'project-select-template', selected: 'My template'
# Updates the identifier in advanced settings
- page.find('#advanced-settings').click
+ page.find('#advanced-project-settings').click
expect(page).to have_field 'project_identifier', with: 'foo-bar'
expect(page).to have_select 'project_status_code', selected: 'On track'
@@ -105,7 +105,7 @@ describe 'Project templates', type: :feature, js: true do
expect(page).to have_select 'project-select-template', selected: 'My template'
# Expend advanced settings
- page.find('#advanced-settings').click
+ page.find('#advanced-project-settings').click
expect(page).to have_field 'project_identifier', with: 'foo-bar'
expect(page).to have_select 'project_status_code', selected: 'On track'
diff --git a/spec/support/components/menu/dropdown.rb b/spec/support/components/menu/dropdown.rb
new file mode 100644
index 00000000000..0b9c4bbb785
--- /dev/null
+++ b/spec/support/components/menu/dropdown.rb
@@ -0,0 +1,56 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+module Components
+ class Dropdown
+ include Capybara::DSL
+ include RSpec::Matchers
+
+ def initialize; end
+
+ def toggle
+ trigger_element.click
+ end
+
+ def expect_closed
+ expect(page).to have_no_selector('ul.menu-drop-down-container')
+ end
+
+ def expect_open
+ expect(page).to have_selector('ul.menu-drop-down-container')
+ end
+
+ def within_dropdown(&block)
+ page.within('ul.menu-drop-down-container', &block)
+ end
+
+ def trigger_element
+ raise NotImplementedError
+ end
+ end
+end
diff --git a/spec/support/components/menu/quick_add_menu.rb b/spec/support/components/menu/quick_add_menu.rb
new file mode 100644
index 00000000000..ea90fd5bca5
--- /dev/null
+++ b/spec/support/components/menu/quick_add_menu.rb
@@ -0,0 +1,85 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+require_relative './dropdown'
+
+module Components
+ class QuickAddMenu < Dropdown
+
+ def expect_visible
+ expect(trigger_element).to be_present
+ end
+
+ def expect_invisible
+ expect { trigger_element }.to raise_error(Capybara::ElementNotFound)
+ end
+
+ def expect_add_project(present: true)
+ expect_link 'New project', present: present
+ end
+
+ def expect_user_invite(present: true)
+ expect_link 'Invite user', present: present
+ end
+
+ def expect_work_package_type(*names, present: true)
+ within_dropdown do
+ expect(page).to have_text 'WORK PACKAGES'
+ end
+
+ names.each do |name|
+ expect_link name, present: present
+ end
+ end
+
+ def expect_no_work_package_types
+ within_dropdown do
+ expect(page).to have_no_text 'Work packages'
+ end
+ end
+
+ def click_link(matcher)
+ within_dropdown do
+ page.click_link matcher
+ end
+ end
+
+ def expect_link(matcher, present: true)
+ within_dropdown do
+ if present
+ expect(page).to have_link matcher
+ else
+ expect(page).to have_no_link matcher
+ end
+ end
+ end
+
+ def trigger_element
+ page.find('a[title="Open quick add menu"]')
+ end
+ end
+end