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

Replace repository_navigation with stimulus

Oliver Günther84e75ab4a73c
diff --git a/app/views/repositories/_dir_list.html.erb b/app/views/repositories/_dir_list.html.erb
index a9e4064fd83..1cb9ebdcfe9 100644
--- a/app/views/repositories/_dir_list.html.erb
+++ b/app/views/repositories/_dir_list.html.erb
@@ -28,7 +28,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<div class="generic-table--container">
<div class="generic-table--results-container">
- <table class="generic-table" id="browser">
+ <table class="generic-table" data-repository-navigation-target="repoBrowser">
<colgroup>
<col opHighlightCol>
<col>
diff --git a/app/views/repositories/_dir_list_content.html.erb b/app/views/repositories/_dir_list_content.html.erb
index 2be35d8f571..a00882a15a4 100644
--- a/app/views/repositories/_dir_list_content.html.erb
+++ b/app/views/repositories/_dir_list_content.html.erb
@@ -41,25 +41,29 @@ See COPYRIGHT and LICENSE files for more details.
<% @entries.each do |entry| %>
<% tr_id = Digest::MD5.hexdigest(entry.path)
depth = params[:depth].to_i %>
- <% ent_path = replace_invalid_utf8(entry.path) %>
- <% ent_name = replace_invalid_utf8(entry.name) %>
- <tr id="<%= tr_id %>" class="<%= h params[:parent_id] %> <%= h(entry.kind) %>">
+ <% ent_path = replace_invalid_utf8(entry.path) %>
+ <% ent_name = replace_invalid_utf8(entry.name) %>
+ <% parent_ref = params[:parent_id] ? "dir_#{h(params[:parent_id])}" : '' %>
+ <tr id="dir_<%= tr_id %>" class="<%= parent_ref %> <%= h(entry.kind) %>">
<td class="filename" style="padding-left: <%=18 * depth%>px;">
<% if entry.dir? %>
- <a class="icon-context dir-expander"
- title="<%= I18n.t('js.label_expand') %>"
- href="#"
- data-element="<%= "##{tr_id}" %>"
- aria-label="<%= I18n.t('js.label_expand') %>"
- data-url="<%= url_for(action: 'show',
- project_id: @project,
- repo_path: to_path_param(ent_path),
- rev: @rev,
- depth: (depth + 1),
- parent_id: tr_id) %>">
+ <%= link_to '#',
+ class: 'icon-context dir-expander',
+ title: I18n.t('js.label_expand'),
+ 'aria-label': I18n.t('js.label_expand'),
+ data: {
+ action: 'repository-navigation#toggleDirectory',
+ element: "dir_#{tr_id}",
+ url: url_for(action: 'show',
+ project_id: @project,
+ repo_path: to_path_param(ent_path),
+ rev: @rev,
+ depth: (depth + 1),
+ parent_id: tr_id),
+ } do %>
<%= op_icon('icon-context') %>
- &nbsp
- </a>
+ &nbsp;
+ <% end %>
<% end %>
<%= link_to({ action: (entry.dir? ? 'show' : 'changes'), project_id: @project, repo_path: to_path_param(ent_path), rev: @rev },
class: 'icon-context',
diff --git a/app/views/repositories/_repository_header.html.erb b/app/views/repositories/_repository_header.html.erb
index 5ccb5a6ac14..2cd08936dc1 100644
--- a/app/views/repositories/_repository_header.html.erb
+++ b/app/views/repositories/_repository_header.html.erb
@@ -27,10 +27,6 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
-<% content_for :header_tags do %>
- <meta name="required_script" content="repository_navigation" />
-<% end %>
-
<persistent-toggle data-identifier="repository.checkout_instructions"></persistent-toggle>
<%= toolbar title: t('repositories.named_repository',
vendor_name: @repository.class.vendor_name) do %>
diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb
index d8039787fb5..d6da41cb2b3 100644
--- a/app/views/repositories/show.html.erb
+++ b/app/views/repositories/show.html.erb
@@ -27,6 +27,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
+<% page_controller 'repository-navigation', dynamic: true %>
<%= render partial: 'repository_header', locals: { empty: false } %>
<div class="repository-breadcrumbs">
@@ -55,7 +56,14 @@ See COPYRIGHT and LICENSE files for more details.
<div>
<%= label_tag 'rev', I18n.t('repositories.go_to_revision') %>
</div>
- <%= text_field_tag :rev, @rev, id: 'revision-identifier-input', placeholder: t(:label_revision) %>
+ <%= text_field_tag :rev,
+ @rev,
+ id: 'revision-identifier-input',
+ placeholder: t(:label_revision),
+ data: {
+ 'repository-navigation-target': 'revision',
+ action: 'keydown.enter->repository-navigation#sendForm'
+ } %>
</li>
<% if [email protected]? && @repository.branches.length > 0 %>
<li class="toolbar-item toolbar-input-group hidden-for-mobile">
@@ -65,7 +73,11 @@ See COPYRIGHT and LICENSE files for more details.
<%= select_tag :branch,
options_for_select(@repository.branches, @rev),
include_blank: "--- #{t(:actionview_instancetag_blank_option)} ---",
- id: 'revision-branch-select' %>
+ id: 'revision-branch-select',
+ data: {
+ 'repository-navigation-target': 'branch'
+ }
+ %>
</li>
<% end %>
<% if [email protected]? && @repository.tags.length > 0 %>
@@ -76,11 +88,15 @@ See COPYRIGHT and LICENSE files for more details.
<%= select_tag :tag,
options_for_select(@repository.tags, @rev),
include_blank: "--- #{t(:actionview_instancetag_blank_option)} ---",
- id: 'revision-tag-select' %>
+ id: 'revision-tag-select',
+ data: {
+ 'repository-navigation-target': 'tag'
+ }
+ %>
</li>
<% end %>
<li class="toolbar-item -icon-only">
- <%= link_to({ url: { action: 'revisions', project_id: @project,
+ <%= link_to({ url: { action: 'revision#revision-identifier-inputs', project_id: @project,
key: User.current.rss_key } },
{ class: 'button', title: t('repositories.atom_revision_feed') }) do %>
<%= op_icon('button--icon icon-export-atom') %>
diff --git a/frontend/src/app/features/plugins/plugin-context.ts b/frontend/src/app/features/plugins/plugin-context.ts
index e3d98ad4f8c..181976dfa9b 100644
--- a/frontend/src/app/features/plugins/plugin-context.ts
+++ b/frontend/src/app/features/plugins/plugin-context.ts
@@ -25,6 +25,7 @@ import { DynamicContentModalComponent } from '../../shared/components/modals/mod
import { PasswordConfirmationModalComponent } from '../../shared/components/modals/request-for-confirmation/password-confirmation.modal';
import { DomAutoscrollService } from 'core-app/shared/helpers/drag-and-drop/dom-autoscroll.service';
import { AttachmentsResourceService } from 'core-app/core/state/attachments/attachments.service';
+import { HttpClient } from '@angular/common/http';
/**
* Plugin context bridge for plugins outside the CLI compiler context
@@ -58,6 +59,7 @@ export class OpenProjectPluginContext {
apiV3Service: this.injector.get<ApiV3Service>(ApiV3Service),
configurationService: this.injector.get<ConfigurationService>(ConfigurationService),
attachmentsResourceService: this.injector.get(AttachmentsResourceService),
+ http: this.injector.get(HttpClient),
};
public readonly helpers = {
diff --git a/frontend/src/stimulus/controllers/dynamic/repository-navigation.controller.ts b/frontend/src/stimulus/controllers/dynamic/repository-navigation.controller.ts
index 6ec29d440b4..079ec643686 100644
--- a/frontend/src/stimulus/controllers/dynamic/repository-navigation.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/repository-navigation.controller.ts
@@ -29,42 +29,161 @@
*/
import { Controller } from '@hotwired/stimulus';
+import { HttpClient } from '@angular/common/http';
-export default class MeetingContentController extends Controller {
+export default class RepositoryNavigationController extends Controller {
static targets = [
- 'renderedText',
- 'editor',
- 'attachments',
- 'editButton',
+ 'revision',
+ 'branch',
+ 'tag',
+ 'form',
+ 'repoBrowser',
];
- static values = {
- editState: { type: Boolean, default: false },
- };
+ declare readonly branchTarget:HTMLSelectElement;
- declare editStateValue:boolean;
+ declare readonly hasBranchTarget:boolean;
- declare readonly renderedTextTarget:HTMLElement;
+ declare readonly revisionTarget:HTMLSelectElement;
- declare readonly editorTarget:HTMLElement;
+ declare readonly tagTarget:HTMLSelectElement;
- declare readonly attachmentsTarget:HTMLElement;
+ declare readonly hasTagTaget:boolean;
- declare readonly editButtonTarget:HTMLLinkElement;
+ declare readonly formTarget:HTMLFormElement;
- enableEditState() {
- this.editStateValue = true;
+ declare readonly repoBrowserTarget:HTMLFormElement;
+
+ private http:HttpClient;
+
+ async connect() {
+ // If we're viewing a tag or branch, don't display it in the revision box
+ if (this.tagSelected || this.branchSelected) {
+ this.revisionTarget.value = '';
+ }
+
+ const context = await window.OpenProject.getPluginContext();
+ this.http = context.services.http;
+ }
+
+ sendForm() {
+ this.branchTarget.disabled = true;
+ this.tagTarget.disabled = true;
+ this.formTarget.submit();
+
+ this.branchTarget.disabled = false;
+ this.tagTarget.disabled = false;
+ }
+
+ /**
+ Copy the branch/tag value into the revision box, then disable
+ the dropdowns before submitting the form
+ */
+ applyValue(evt:InputEvent) {
+ this.revisionTarget.value = (evt.target as HTMLSelectElement).value;
+ this.sendForm();
+ }
+
+ toggleDirectory(evt:MouseEvent) {
+ const el = (evt.target as HTMLElement).closest('a') as HTMLAnchorElement;
+ const id = el.dataset.element as string;
+ const content = document.getElementById(id) as HTMLElement;
+
+ if (this.expandDir(content)) {
+ content.classList.add('loading');
+
+ this
+ .http
+ .get(el.dataset.url as string, { responseType: 'text' })
+ .subscribe((response:string) => {
+ content.insertAdjacentHTML('afterend', response);
+ content.classList.remove('loading');
+ this.expandItem(content);
+ });
+ }
+ }
+
+ private get branchSelected():boolean {
+ return this.hasBranchTarget && this.branchTarget.value === this.revisionTarget.value;
+ }
+
+ private get tagSelected():boolean {
+ return this.hasTagTaget && this.tagTarget.value === this.revisionTarget.value;
+ }
+
+ /**
+ * Determines whether a dir-expander should load content
+ * or simply expand already loaded content.
+ */
+ private expandDir(content:HTMLElement) {
+ if (content.classList.contains('open')) {
+ this.collapseScmEntry(content);
+ return false;
+ }
+
+ if (content.classList.contains('loaded')) {
+ this.expandScmEntry(content);
+ return false;
+ }
+
+ return !content.classList.contains('loading');
}
- cancelEditState() {
- this.editStateValue = false;
- window.OpenProject.pageWasEdited = false;
+ /**
+ * Collapses a directory listing in the repository module
+ */
+ private collapseScmEntry(content:HTMLElement) {
+ this
+ .repoBrowserTarget
+ .querySelectorAll(`.${content.id}`)
+ .forEach((el:HTMLElement) => {
+ if (el.classList.contains('open')) {
+ this.collapseScmEntry(el);
+ }
+
+ el.style.display = 'none';
+ this.collapseItem(el);
+ });
+
+ this.collapseItem(content);
}
- editStateValueChanged() {
- this.renderedTextTarget.hidden = this.editStateValue;
- this.attachmentsTarget.hidden = this.editStateValue;
- this.editorTarget.hidden = !this.editStateValue;
- this.editButtonTarget.classList.toggle('-active', this.editStateValue);
+ /**
+ * Expands an SCM entry if its loaded
+ */
+ private expandScmEntry(content:HTMLElement) {
+ this
+ .repoBrowserTarget
+ .querySelectorAll(`.${content.id}`)
+ .forEach((el:HTMLElement) => {
+ el.style.removeProperty('display');
+ if (el.classList.contains('loaded') && !el.classList.contains('collapsed')) {
+ this.expandScmEntry(el);
+ }
+
+ this.collapseItem(el);
+ });
+
+ this.expandItem(content);
+ }
+
+ private expandItem(el:HTMLElement) {
+ el.classList.add('open');
+ el.classList.remove('collapsed');
+
+ const expander = el.querySelector<HTMLElement>('a.dir-expander');
+ if (expander) {
+ expander.title = I18n.t('js.label_collapse');
+ }
+ }
+
+ private collapseItem(el:HTMLElement) {
+ el.classList.remove('open');
+ el.classList.add('collapsed');
+
+ const expander = el.querySelector<HTMLElement>('a.dir-expander');
+ if (expander) {
+ expander.title = I18n.t('js.label_expand');
+ }
}
}
diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.ts
index 16c33919354..12d16fc6ff9 100644
--- a/frontend/src/stimulus/setup.ts
+++ b/frontend/src/stimulus/setup.ts
@@ -15,7 +15,7 @@ window.Stimulus = instance;
instance.debug = !environment.production;
instance.handleError = (error, message, detail) => {
- console.warn(message, detail);
+ console.warn(error, message, detail);
};
instance.register('application', OpApplicationController);