Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<%#-- copyright
OpenProject is an open source project management software.
Copyright (C) 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 COPYRIGHT and LICENSE files for more details.

++#%>

<%=
component_wrapper do
if page_links.any?
flex_layout(mb: 3) do |container|
container.with_row do
render(
::Wikis::CollapsiblePageLinksComponent.new(
page_links,
heading: t("wikis.work_package_wikis_tab_component.inline_page_links"),
container: :inline_page_links,
linkable: work_package,
already_related_page_keys:
)
)
end
end
end
end
%>
56 changes: 56 additions & 0 deletions modules/wikis/app/components/wikis/inline_page_links_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 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 COPYRIGHT and LICENSE files for more details.
#++

# The "Mentioned in description" section of the work package wikis tab.
module Wikis
class InlinePageLinksComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable

alias_method :work_package, :model

def page_links
@page_links ||= page_link_service
.inline_page_link_infos_for(linkable: work_package)
.map { PageLinkViewModel.from_page_info_result(it) }
end

private

def already_related_page_keys
@already_related_page_keys ||= page_link_service.relation_page_link_keys_for(linkable: work_package)
end

def page_link_service
@page_link_service ||= PageLinkService.new
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,8 @@ See COPYRIGHT and LICENSE files for more details.
end
end

if inline_page_links.any?
container.with_row(mb: 3) do
render(
::Wikis::CollapsiblePageLinksComponent.new(
inline_page_links,
heading: t(".inline_page_links"),
container: :inline_page_links,
linkable: work_package,
already_related_page_keys:
)
)
end
container.with_row do
render(::Wikis::InlinePageLinksComponent.new(work_package))
end

if referencing_wiki_pages.any?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ def providers
Wikis::Provider.enabled
end

def inline_page_links
@inline_page_links ||= page_link_service.inline_page_link_infos_for(linkable: work_package)
.map { PageLinkViewModel.from_page_info_result(it) }
end

def referencing_wiki_pages
@referencing_wiki_pages ||= page_link_service.referencing_wiki_page_references_for(linkable: work_package)
.map { PageLinkViewModel.from_page_reference_result(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def index
end
end

def inline_page_links
replace_via_turbo_stream(component: Wikis::InlinePageLinksComponent.new(@work_package))

respond_to_with_turbo_streams
end

private

def set_work_package
Expand Down
4 changes: 3 additions & 1 deletion modules/wikis/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
resources :work_packages, only: %i[] do
resources :wikis, only: %i[] do
collection do
resources :tab, only: %i[index], controller: "work_package_wikis_tab", as: "wikis_tab"
resources :tab, only: %i[index], controller: "work_package_wikis_tab", as: "wikis_tab" do
get :inline_page_links, on: :collection
end
end
end
end
Expand Down
127 changes: 127 additions & 0 deletions modules/wikis/frontend/module/wikis-tab/wikis-tab.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//-- copyright
// OpenProject is an open source project management software.
// Copyright (C) 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 COPYRIGHT and LICENSE files for more details.
//++

import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Subject } from 'rxjs';
import { vi, type Mock } from 'vitest';

import { I18nService } from 'core-app/core/i18n/i18n.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { HalEvent, HalEventsService } from 'core-app/features/hal/services/hal-events.service';
import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { WikisTabComponent } from 'core-app/features/plugins/linked/openproject-wikis/wikis-tab/wikis-tab.component';

const TAB_PATH = '/projects/1/work_packages/42/wikis/tab';
const REFRESH_URL = `${TAB_PATH}/inline_page_links`;

describe('WikisTabComponent', () => {
let component:WikisTabComponent;
let fixture:ComponentFixture<WikisTabComponent>;
let events$:Subject<HalEvent[]>;
let request:Mock;

const workPackage = { id: '42', project: { id: '1' } } as WorkPackageResource;
const descriptionEdit = {
id: '42',
eventType: 'updated',
resourceType: 'WorkPackage',
commit: { changes: { description: {} } },
} as unknown as HalEvent;

beforeEach(async () => {
events$ = new Subject<HalEvent[]>();
request = vi.fn().mockResolvedValue({ html: '', headers: new Headers() });

await TestBed
.configureTestingModule({
declarations: [WikisTabComponent],
providers: [
{ provide: I18nService, useValue: { t: (key:string) => key } },
{ provide: PathHelperService, useValue: { projectWorkPackagePath: () => '/projects/1/work_packages/42' } },
{ provide: HalEventsService, useValue: { aggregated$: () => events$.asObservable() } },
{ provide: TurboRequestsService, useValue: { request } },
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
.compileComponents();

fixture = TestBed.createComponent(WikisTabComponent);
component = fixture.componentInstance;
component.workPackage = workPackage;

fixture.detectChanges();
});

it('points the tab frame at the wikis tab', () => {
expect(component.turboFrameSrc).toEqual(TAB_PATH);
});

it('refreshes only the mentioned pages when a description edit is persisted', () => {
events$.next([descriptionEdit]);

expect(request).toHaveBeenCalledTimes(1);
expect(request.mock.calls[0][0]).toEqual(REFRESH_URL);
});

it('asks for a turbo stream, so that the section is swapped in place', () => {
events$.next([descriptionEdit]);

expect(request.mock.calls[0][1]).toMatchObject({
method: 'GET',
headers: { Accept: 'text/vnd.turbo-stream.html' },
});
});

it('ignores edits that did not touch the description', () => {
events$.next([{ ...descriptionEdit, commit: { changes: { subject: {} } } } as unknown as HalEvent]);

expect(request).not.toHaveBeenCalled();
});

it('ignores edits of other work packages', () => {
events$.next([{ ...descriptionEdit, id: '43' } as HalEvent]);

expect(request).not.toHaveBeenCalled();
});

it('refreshes on updates pushed without a commit, which do not name their changed attributes', () => {
events$.next([{ id: '42', eventType: 'updated', resourceType: 'WorkPackage' } as HalEvent]);

expect(request).toHaveBeenCalledTimes(1);
});

it('stops refreshing once the tab is closed', () => {
fixture.destroy();

events$.next([descriptionEdit]);

expect(request).not.toHaveBeenCalled();
});
});
36 changes: 34 additions & 2 deletions modules/wikis/frontend/module/wikis-tab/wikis-tab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,59 @@
//++

import { ChangeDetectionStrategy, Component, ElementRef, Input, OnInit, inject } from '@angular/core';
import { filter } from 'rxjs/operators';

import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { TabComponent } from 'core-app/features/work-packages/components/wp-tabs/components/wp-tab-wrapper/tab';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { HalEventsService } from 'core-app/features/hal/services/hal-events.service';
import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';

@Component({
selector: 'op-wikis-tab',
templateUrl: './wikis-tab.template.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class WikisTabComponent implements OnInit, TabComponent {
export class WikisTabComponent extends UntilDestroyedMixin implements OnInit, TabComponent {
private elementRef = inject(ElementRef);
private halEvents = inject(HalEventsService);
private turboRequests = inject(TurboRequestsService);
readonly PathHelper = inject(PathHelperService);
readonly I18n = inject(I18nService);

@Input() public workPackage:WorkPackageResource;
turboFrameSrc:string;

ngOnInit():void {
this.turboFrameSrc = `${this.PathHelper.projectWorkPackagePath(this.workPackage.project.id as string, this.workPackage.id as string)}/wikis/tab`;
const tabPath = `${this.PathHelper.projectWorkPackagePath(this.workPackage.project.id as string, this.workPackage.id as string)}/wikis/tab`;
const refreshUrl = `${tabPath}/inline_page_links`;
this.turboFrameSrc = tabPath;

this
.halEvents
.aggregated$('WorkPackage')
.pipe(
filter((events) => events.some((event) => event.eventType === 'updated'
&& event.id === this.workPackage.id
&& (!event.commit || 'description' in event.commit.changes))),
this.untilDestroyed(),
)
.subscribe(() => {
// Deliberately not `requestStream`, which flashes Turbo's page-load
// progress bar — misleading for a background refresh of one section.
void this.turboRequests.request(
refreshUrl,
{
method: 'GET',
headers: { Accept: 'text/vnd.turbo-stream.html' },
credentials: 'same-origin',
},
false,
refreshUrl,
);
});
}
}
Loading
Loading