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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#39772] decoupled query-select component from wp
Eric Schubert629fe131a2ed
diff --git a/app/views/work_packages/_menu_query_select.html.erb b/app/views/work_packages/_menu_query_select.html.erbindex 4f99966bdcc..ca9ecc4d710 100644--- a/app/views/work_packages/_menu_query_select.html.erb+++ b/app/views/work_packages/_menu_query_select.html.erb@@ -1 +1,7 @@-<op-query-select data-project-identifier="<%= @project ? @project.identifier : '' %>"></op-query-select>+<%= content_tag 'op-query-select', '',+ data: {+ 'project-identifier': (@project ? @project.identifier : '').to_json,+ 'menu-items': [parent_name, name].to_json,+ 'base-route': 'work-packages'.to_json+ }+%>diff --git a/frontend/src/app/features/bim/ifc_models/openproject-ifc-models.routes.ts b/frontend/src/app/features/bim/ifc_models/openproject-ifc-models.routes.tsindex 8c0f525b142..eb105fcd565 100644--- a/frontend/src/app/features/bim/ifc_models/openproject-ifc-models.routes.ts+++ b/frontend/src/app/features/bim/ifc_models/openproject-ifc-models.routes.ts@@ -40,12 +40,13 @@ export const IFC_ROUTES:Ng2StateDeclaration[] = [{name: 'bim',parent: 'optional_project',- url: '/bcf?query_props&models&viewpoint',+ url: '/bcf?query_id&query_props&models&viewpoint',abstract: true,component: WorkPackagesBaseComponent,redirectTo: 'bim.partitioned',params: {// Use custom encoder/decoder that ensures validity of URL string+ query_id: { type: 'query', dynamic: true },query_props: { type: 'opQueryString', dynamic: true },models: { type: 'opQueryString', dynamic: true },viewpoint: { type: 'int', dynamic: true },diff --git a/frontend/src/app/features/work-packages/routing/work-packages-routes.ts b/frontend/src/app/features/work-packages/routing/work-packages-routes.tsindex 2d8e59d3b9e..8a4135e5e60 100644--- a/frontend/src/app/features/work-packages/routing/work-packages-routes.ts+++ b/frontend/src/app/features/work-packages/routing/work-packages-routes.ts@@ -133,6 +133,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [bodyClasses: 'router--work-packages-partitioned-split-view',menuItem: menuItemClass,partition: '-left-only',+ module: 'work-packages',},},...makeSplitViewRoutes(diff --git a/frontend/src/app/shared/components/dataset-inputs.decorator.spec.ts b/frontend/src/app/shared/components/dataset-inputs.decorator.spec.tsnew file mode 100644index 00000000000..c9d08b9c72c--- /dev/null+++ b/frontend/src/app/shared/components/dataset-inputs.decorator.spec.ts@@ -0,0 +1,88 @@+import {+ ComponentFixture,+ TestBed,+} from '@angular/core/testing';+import {+ ChangeDetectionStrategy,+ Component,+ DebugElement,+ ElementRef,+ Input,+ Type,+} from '@angular/core';+import { DatasetInputs } from 'core-app/shared/components/dataset-inputs.decorator';++@Component({+ selector: 'op-test-input',+ template: '<op-test [foo]="bar"></op-test>',+ changeDetection: ChangeDetectionStrategy.OnPush,+})+export class TestInputComponent {+ bar = 'foo';+}++@Component({+ selector: 'op-test-data',+ template: `<op-test data-foo='"input from data"'></op-test>`,+ changeDetection: ChangeDetectionStrategy.OnPush,+})+export class TestDataComponent {+}++@DatasetInputs+@Component({+ selector: 'op-test',+ template: '<span [textContent]="foo"></span>',+ changeDetection: ChangeDetectionStrategy.OnPush,+})+export class TestComponent {+ @Input() foo:string;++ constructor(readonly elementRef:ElementRef<HTMLElement>) {}+}++fdescribe('DatasetInputs decorator', () => {+ let fixture:ComponentFixture<unknown>;+ let element:DebugElement;+ let htmlElement:HTMLElement;++ const setup = async (componentClass:Type<unknown>) => {+ console.log("SETUP")+ await TestBed.configureTestingModule({+ declarations: [+ TestComponent,+ TestInputComponent,+ TestDataComponent,+ ],+ })+ .compileComponents();++ fixture = TestBed.createComponent(componentClass);+ element = fixture.debugElement;+ htmlElement = element.nativeElement as HTMLElement;++ fixture.detectChanges();+ };++ describe('with an input', () => {+ beforeEach(async () => {+ await setup(TestInputComponent);+ });++ it('renders the input', () => {+ expect(htmlElement.querySelector('op-test-input op-test span')?.textContent)+ .toEqual('foo', 'Expected op-test with a span[textContent=foo]');+ });+ });++ describe('with a data field', () => {+ beforeEach(async () => {+ await setup(TestDataComponent);+ });++ it('renders the input', () => {+ expect(htmlElement.querySelector('op-test-input op-test span')?.textContent)+ .toEqual('input from data', 'Expected op-test with a span[textContent=input from data]');+ });+ });+});diff --git a/frontend/src/app/shared/components/dataset-inputs.decorator.ts b/frontend/src/app/shared/components/dataset-inputs.decorator.tsindex 60a86d5f371..72440528992 100644--- a/frontend/src/app/shared/components/dataset-inputs.decorator.ts+++ b/frontend/src/app/shared/components/dataset-inputs.decorator.ts@@ -60,6 +60,9 @@ export function DatasetInputs<T extends { new(...args:any[]):DatasetInputsDecoraconst declaredInputsParentKey = Object.keys(cstr).find((key:string) => typeof (cstr[key] as ɵDirectiveDef<unknown>).declaredInputs === 'object');+ console.log((cstr as any).propDecorators);+ console.log(Object.keys(cstr));+if (!declaredInputsParentKey) {throw new Error('Could not find declared inputs for component');}diff --git a/frontend/src/app/shared/components/op-query-select/op-query-select.component.ts b/frontend/src/app/shared/components/op-query-select/op-query-select.component.tsindex 9f8f1a3e8a1..c7f42de0332 100644--- a/frontend/src/app/shared/components/op-query-select/op-query-select.component.ts+++ b/frontend/src/app/shared/components/op-query-select/op-query-select.component.ts@@ -30,14 +30,20 @@ import {ChangeDetectionStrategy,ChangeDetectorRef,Component,+ ElementRef,+ Input,OnInit,} from '@angular/core';import { map } from 'rxjs/operators';-import { BehaviorSubject, combineLatest, Observable } from 'rxjs';+import {+ BehaviorSubject,+ combineLatest,+ Observable,+} from 'rxjs';import { States } from 'core-app/core/states/states.service';import { I18nService } from 'core-app/core/i18n/i18n.service';import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';-import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';+import { DatasetInputs } from 'core-app/shared/components/dataset-inputs.decorator';import { MainMenuNavigationService } from 'core-app/core/main-menu/main-menu-navigation.service';import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';import { IOpSidemenuItem } from 'core-app/shared/components/sidemenu/sidemenu.component';@@ -46,6 +52,7 @@ import { StaticQueriesService } from 'core-app/shared/components/op-query-selectexport const opQuerySelectSelector = 'op-query-select';+@DatasetInputs@Component({selector: opQuerySelectSelector,changeDetection: ChangeDetectionStrategy.OnPush,@@ -64,6 +71,12 @@ export class QuerySelectComponent extends UntilDestroyedMixin implements OnInitpublic $queries:Observable<IOpSidemenuItem[]>;+ @Input() menuItems:string[] = [];++ @Input() projectIdentifier:string;++ @Input() baseRoute:string;+private $queryCategories = new BehaviorSubject<IOpSidemenuItem[]>([]);private $search = new BehaviorSubject<string>('');@@ -71,10 +84,10 @@ export class QuerySelectComponent extends UntilDestroyedMixin implements OnInitprivate initialized = false;constructor(+ readonly elementRef:ElementRef,readonly apiV3Service:APIV3Service,readonly I18n:I18nService,readonly states:States,- readonly CurrentProject:CurrentProjectService,readonly opStaticQueries:StaticQueriesService,readonly mainMenuService:MainMenuNavigationService,readonly cdRef:ChangeDetectorRef,@@ -92,7 +105,7 @@ export class QuerySelectComponent extends UntilDestroyedMixin implements OnInit// When activating the work packages submenu,// either initially or through click on the toggle, load the resultsthis.mainMenuService- .onActivate('work_packages', 'work_packages_query_select')+ .onActivate(...this.menuItems).subscribe(() => this.initializeAutocomplete());this.$queries = combineLatest(@@ -147,7 +160,7 @@ export class QuerySelectComponent extends UntilDestroyedMixin implements OnInit// TODO: use global query storethis.apiV3Service.queries- .filterNonHidden(this.CurrentProject.identifier)+ .filterNonHidden(this.projectIdentifier).pipe(this.untilDestroyed()).subscribe((queryCollection) => {queryCollection.elements.forEach((query) => {@@ -159,22 +172,23 @@ export class QuerySelectComponent extends UntilDestroyedMixin implements OnInitcat = 'starred';}- categories[cat].push(QuerySelectComponent.toOpSideMenuItem(query));+ categories[cat].push(this.toOpSideMenuItem(query));});+ const staticQueries = this.opStaticQueries.getStaticQueries(this.baseRoute);this.$queryCategories.next([{ title: this.text.scope_starred, children: categories.starred, collapsible: true },- { title: this.text.scope_default, children: this.opStaticQueries.all, collapsible: true },+ { title: this.text.scope_default, children: staticQueries, collapsible: true },{ title: this.text.scope_global, children: categories.public, collapsible: true },{ title: this.text.scope_private, children: categories.private, collapsible: true },]);});}- private static toOpSideMenuItem(query:QueryResource):IOpSidemenuItem {+ private toOpSideMenuItem(query:QueryResource):IOpSidemenuItem {return {title: query.name,- uiSref: 'work-packages',+ uiSref: this.baseRoute,uiParams: { query_id: query.id, query_props: '' },};}diff --git a/frontend/src/app/shared/components/op-query-select/op-static-queries.service.ts b/frontend/src/app/shared/components/op-query-select/op-static-queries.service.tsindex c2d389ea268..62cc2297c2a 100644--- a/frontend/src/app/shared/components/op-query-select/op-static-queries.service.ts+++ b/frontend/src/app/shared/components/op-query-select/op-static-queries.service.ts@@ -60,32 +60,53 @@ export class StaticQueriesService {summary: this.I18n.t('js.work_packages.default_queries.summary'),};- public get all():IOpSidemenuItem[] {+ public getStaticName(query:QueryResource):string {+ if (this.$state.params.query_props) {+ const queryProps = JSON.parse(this.$state.params.query_props);+ delete queryProps.pp;+ delete queryProps.pa;+ const queryPropsString = JSON.stringify(queryProps);++ // TODO: Get module route from query+ const matched = this.getStaticQueries('work-packages').find((item) => {+ const uiParams = item.uiParams as { query_id:string, query_props:string };+ return uiParams && uiParams.query_props === queryPropsString;+ });++ if (matched) {+ return matched.title;+ }+ }++ // Try to detect the all open filter+ if (query.filters.length === 1 // Only one filter+ && query.filters[0].id === 'status' // that is status+ && query.filters[0].operator.id === 'o') { // and is open+ return this.text.all_open;+ }++ // Otherwise, fall back to work packages+ return this.text.work_packages;+ }++ public getStaticQueries(module:string):IOpSidemenuItem[] {let items:IOpSidemenuItem[] = [{title: this.text.all_open,- uiSref: 'work-packages',+ uiSref: module,uiParams: { query_id: '', query_props: '' },},{title: this.text.latest_activity,- uiSref: 'work-packages',+ uiSref: module,uiParams: {query_id: '',query_props: '{"c":["id","subject","type","status","assignee","updatedAt"],"hi":false,"g":"","t":"updatedAt:desc","f":[{"n":"status","o":"o","v":[]}]}',},},- {- title: this.text.gantt,- uiSref: 'work-packages',- uiParams: {- query_id: '',- query_props: '{"c":["id","type","subject","status","startDate","dueDate"],"tv":true,"tzl":"auto","tll":"{\\"left\\":\\"startDate\\",\\"right\\":\\"dueDate\\",\\"farRight\\":\\"subject\\"}","hi":true,"g":"","t":"startDate:asc","f":[{"n":"status","o":"o","v":[]}]}',- },- },{title: this.text.recently_created,- uiSref: 'work-packages',+ uiSref: module,uiParams: {query_id: '',query_props: '{"c":["id","subject","type","status","assignee","createdAt"],"hi":false,"g":"","t":"createdAt:desc","f":[{"n":"status","o":"o","v":[]}]}',@@ -93,12 +114,23 @@ export class StaticQueriesService {},];- const projectIdentifier = this.CurrentProject.identifier;- if (projectIdentifier) {+ if (module === 'work-packages') {items.push({- title: this.text.summary,- href: `${this.PathHelper.projectWorkPackagesPath(projectIdentifier)}/report`,+ title: this.text.gantt,+ uiSref: module,+ uiParams: {+ query_id: '',+ query_props: '{"c":["id","type","subject","status","startDate","dueDate"],"tv":true,"tzl":"auto","tll":"{\\"left\\":\\"startDate\\",\\"right\\":\\"dueDate\\",\\"farRight\\":\\"subject\\"}","hi":true,"g":"","t":"startDate:asc","f":[{"n":"status","o":"o","v":[]}]}',+ },});++ const projectIdentifier = this.CurrentProject.identifier;+ if (projectIdentifier) {+ items.push({+ title: this.text.summary,+ href: `${this.PathHelper.projectWorkPackagesPath(projectIdentifier)}/report`,+ });+ }}if (this.CurrentUser.isLoggedIn) {@@ -106,7 +138,7 @@ export class StaticQueriesService {...items,{title: this.text.created_by_me,- uiSref: 'work-packages',+ uiSref: module,uiParams: {query_id: '',query_props: '{"c":["id","subject","type","status","assignee","updatedAt"],"hi":false,"g":"","t":"updatedAt:desc,id:asc","f":[{"n":"status","o":"o","v":[]},{"n":"author","o":"=","v":["me"]}]}',@@ -114,7 +146,7 @@ export class StaticQueriesService {},{title: this.text.assigned_to_me,- uiSref: 'work-packages',+ uiSref: module,uiParams: {query_id: '',query_props: '{"c":["id","subject","type","status","author","updatedAt"],"hi":false,"g":"","t":"updatedAt:desc,id:asc","f":[{"n":"status","o":"o","v":[]},{"n":"assigneeOrGroup","o":"=","v":["me"]}]}',@@ -125,32 +157,4 @@ export class StaticQueriesService {return items;}-- public getStaticName(query:QueryResource):string {- if (this.$state.params.query_props) {- const queryProps = JSON.parse(this.$state.params.query_props);- delete queryProps.pp;- delete queryProps.pa;- const queryPropsString = JSON.stringify(queryProps);-- const matched = this.all.find((item) => {- const uiParams = item.uiParams as { query_id:string, query_props:string };- return uiParams && uiParams.query_props === queryPropsString;- });-- if (matched) {- return matched.title;- }- }-- // Try to detect the all open filter- if (query.filters.length === 1 // Only one filter- && query.filters[0].id === 'status' // that is status- && query.filters[0].operator.id === 'o') { // and is open- return this.text.all_open;- }-- // Otherwise, fall back to work packages- return this.text.work_packages;- }}diff --git a/lib/redmine/menu_manager/menu_helper.rb b/lib/redmine/menu_manager/menu_helper.rbindex f3948e837d8..8796e2bf508 100644--- a/lib/redmine/menu_manager/menu_helper.rb+++ b/lib/redmine/menu_manager/menu_helper.rb@@ -231,7 +231,10 @@ module Redmine::MenuManager::MenuHelperdef render_single_node_or_partial(node, project)if node.partial- content_tag('li', render(partial: node.partial), class: "partial", data: { name: node.name })+ content_tag('li',+ render(partial: node.partial, locals: { name: node.name, parent_name: node.parent.name }),+ class: "partial",+ data: { name: node.name })elsecontent_tag('li', render_single_menu_node(node, project), data: { name: node.name })enddiff --git a/modules/bim/app/views/bim/ifc_models/ifc_models/_panels.html.erb b/modules/bim/app/views/bim/ifc_models/ifc_models/_panels.html.erbindex f3ae4e2cf16..5bd67a1bbf4 100644--- a/modules/bim/app/views/bim/ifc_models/ifc_models/_panels.html.erb+++ b/modules/bim/app/views/bim/ifc_models/ifc_models/_panels.html.erb@@ -1 +1,13 @@-<div class="op-ifc-viewer--tree-panel active" data-qa-selector="op-ifc-viewer--tree-panel"></div>+<div class="op-ifc-viewer--sidemenu">+ <%= content_tag 'op-query-select', '',+ data: {+ 'project-identifier': (@project ? @project.identifier : '').to_json,+ 'menu-items': [parent_name, name].to_json,+ 'base-route': 'bim.partitioned.split'.to_json+ }+ %>++ <hr>++ <div class="op-ifc-viewer--tree-panel active" data-qa-selector="op-ifc-viewer--tree-panel"></div>+</div>