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
Rewrite angular sections with stimulus
Oliver Güntherb45f34063059
diff --git a/app/views/custom_actions/_form.html.erb b/app/views/custom_actions/_form.html.erbindex 672ae2651c8..ee0a0fd0ddc 100644--- a/app/views/custom_actions/_form.html.erb+++ b/app/views/custom_actions/_form.html.erb@@ -1,7 +1,5 @@-<% initialize_hide_sections_with(- @custom_action.all_actions.map { |a| { key: a.key, label: a.human_name } },- @custom_action.actions.map { |a| { key: a.key, label: a.human_name } }- ) %>+<% content_controller "hide-sections", dynamic: true %>+<% active_section_keys = @custom_action.actions.map(&:key) %><div class="form--field -required"><%= f.text_field :name, required: true, container_class: "-middle" %>@@ -60,7 +58,11 @@<div id="custom-actions-form--active-actions"><% @custom_action.all_actions.each do |action| %>- <section class="hide-section" hidden data-section-name="<%= action.key %>">+ <section class="hide-section"+ data-hide-sections-target="section"+ data-name="<%= action.key %>"+ <%= tag.attributes(data: { section_name: action.key }, hidden: active_section_keys.include?(action.key) ? nil : true) %>+ ><div class="form--field"><%= styled_label_tag("custom_action_actions_#{action.key}", action.human_name, class: "-top") %>@@ -134,7 +136,12 @@step: 1 %></div><% end %>- <opce-hide-section-link data-section-name="<%= action.key %>"></opce-hide-section-link>+ <button type="button"+ class="spot-link"+ title="<%= t(:button_close) %>"+ data-action="click->hide-sections#hide">+ <%= op_icon("icon-close icon-small") %>+ </button></div></section><% end %>@@ -148,9 +155,18 @@<%= I18n.t(:"custom_actions.actions.add") %></label><span class="form--field-container">- <span class="form--text-field-container -middle">- <opce-add-section-dropdown data-html-id="custom-actions-form--add-action">- </opce-add-section-dropdown>+ <span class="form--select-container -middle">+ <%= select_tag "add_action",+ options_for_select(+ @custom_action.all_actions.map { |a| { key: a.key, label: a.human_name } },+ disabled: active_section_keys+ ),+ prompt: t(:"custom_actions.actions.add"),+ data: {+ "hide-sections-target": "select",+ action: "change->hide-sections#add"+ },+ class: "form--select" %></span></span></div>diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.tsindex 1837931c2d5..b2e528b7dd0 100644--- a/frontend/src/app/app.module.ts+++ b/frontend/src/app/app.module.ts@@ -203,12 +203,6 @@ import {import { CopyToClipboardComponent } from 'core-app/shared/components/copy-to-clipboard/copy-to-clipboard.component';import { GlobalSearchTitleComponent } from 'core-app/core/global_search/title/global-search-title.component';import { ContentTabsComponent } from 'core-app/shared/components/tabs/content-tabs/content-tabs.component';-import {- AddSectionDropdownComponent,-} from 'core-app/shared/components/hide-section/add-section-dropdown/add-section-dropdown.component';-import {- HideSectionLinkComponent,-} from 'core-app/shared/components/hide-section/hide-section-link/hide-section-link.component';import { PersistentToggleComponent } from 'core-app/shared/components/persistent-toggle/persistent-toggle.component';import { TypeFormConfigurationComponent } from 'core-app/features/admin/types/type-form-configuration.component';import { ToastsContainerComponent } from 'core-app/shared/components/toaster/toasts-container.component';@@ -232,7 +226,9 @@ import { CurrentProjectService } from 'core-app/core/current-project/current-proimport {TimeEntriesWorkPackageAutocompleterComponent,} from 'core-app/shared/components/autocompleter/time-entries-work-package-autocompleter/time-entries-work-package-autocompleter.component';-import { OpWpDatePickerInstanceComponent } from 'core-app/shared/components/datepicker/wp-date-picker-modal/wp-date-picker-instance.component';+import {+ OpWpDatePickerInstanceComponent,+} from 'core-app/shared/components/datepicker/wp-date-picker-modal/wp-date-picker-instance.component';export function initializeServices(injector:Injector) {return () => {@@ -475,8 +471,6 @@ export class OpenProjectModule implements DoBootstrap {registerCustomElement('opce-copy-to-clipboard', CopyToClipboardComponent, { injector });registerCustomElement('opce-global-search-title', GlobalSearchTitleComponent, { injector });registerCustomElement('opce-content-tabs', ContentTabsComponent, { injector });- registerCustomElement('opce-add-section-dropdown', AddSectionDropdownComponent, { injector });- registerCustomElement('opce-hide-section-link', HideSectionLinkComponent, { injector });registerCustomElement('opce-persistent-toggle', PersistentToggleComponent, { injector });registerCustomElement('opce-admin-type-form-configuration', TypeFormConfigurationComponent, { injector });registerCustomElement('opce-toasts-container', ToastsContainerComponent, { injector });diff --git a/frontend/src/app/shared/components/hide-section/add-section-dropdown/add-section-dropdown.component.html b/frontend/src/app/shared/components/hide-section/add-section-dropdown/add-section-dropdown.component.htmldeleted file mode 100644index 283d8682447..00000000000--- a/frontend/src/app/shared/components/hide-section/add-section-dropdown/add-section-dropdown.component.html+++ /dev/null@@ -1,7 +0,0 @@-<select [id]="htmlId"- class="form--select"- (change)="show($event.target.value)">- <option #fallbackOption value='' [textContent]="placeholder" selected disabled></option>- <option *ngFor="let entry of selectable; trackByKey" [value]="entry.key" [textContent]="entry.label"></option>-</select>-diff --git a/frontend/src/app/shared/components/hide-section/add-section-dropdown/add-section-dropdown.component.ts b/frontend/src/app/shared/components/hide-section/add-section-dropdown/add-section-dropdown.component.tsdeleted file mode 100644index 7e1e64ed519..00000000000--- a/frontend/src/app/shared/components/hide-section/add-section-dropdown/add-section-dropdown.component.ts+++ /dev/null@@ -1,84 +0,0 @@-//-- 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 { I18nService } from 'core-app/core/i18n/i18n.service';-import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';-import {- HideSectionDefinition,- HideSectionService,-} from 'core-app/shared/components/hide-section/hide-section.service';-import { trackByProperty } from 'core-app/shared/helpers/angular/tracking-functions';-import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';---@Component({- selector: 'opce-add-section-dropdown',- templateUrl: './add-section-dropdown.component.html',-})-export class AddSectionDropdownComponent extends UntilDestroyedMixin implements OnInit {- @ViewChild('fallbackOption', { static: true }) private option:ElementRef;-- trackByKey = trackByProperty('key');-- selectable:HideSectionDefinition[] = [];-- active:string[] = [];-- public htmlId:string;-- public placeholder = this.I18n.t('js.placeholders.selection');-- constructor(- protected hideSectionService:HideSectionService,- protected elementRef:ElementRef,- protected I18n:I18nService,- ) {- super();- }-- ngOnInit():void {- this.htmlId = this.elementRef.nativeElement.dataset.htmlId;-- this.hideSectionService- .displayed- .values$()- .pipe(- this.untilDestroyed(),- ).subscribe((displayed) => {- this.selectable = this.hideSectionService.all- .filter((el) => displayed.indexOf(el.key) === -1)- .sort((a, b) => a.label.localeCompare(b.label));-- (this.option.nativeElement as HTMLOptionElement).selected = true;- });- }-- show(value:string) {- this.hideSectionService.show(value);- }-}diff --git a/frontend/src/app/shared/components/hide-section/hide-section-link/hide-section-link.component.html b/frontend/src/app/shared/components/hide-section/hide-section-link/hide-section-link.component.htmldeleted file mode 100644index e8fe605ed99..00000000000--- a/frontend/src/app/shared/components/hide-section/hide-section-link/hide-section-link.component.html+++ /dev/null@@ -1,8 +0,0 @@-<button- type="button"- class="spot-link"- [title]="text.remove"- (click)="hideSection()"->- <op-icon icon-classes="icon-close icon-small"></op-icon>-</button>diff --git a/frontend/src/app/shared/components/hide-section/hide-section-link/hide-section-link.component.ts b/frontend/src/app/shared/components/hide-section/hide-section-link/hide-section-link.component.tsdeleted file mode 100644index d9d00618bd6..00000000000--- a/frontend/src/app/shared/components/hide-section/hide-section-link/hide-section-link.component.ts+++ /dev/null@@ -1,59 +0,0 @@-//-- 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 { Component, ElementRef, OnInit } from '@angular/core';-import { HideSectionService } from 'core-app/shared/components/hide-section/hide-section.service';-import { I18nService } from 'core-app/core/i18n/i18n.service';---@Component({- selector: 'opce-hide-section-link',- templateUrl: './hide-section-link.component.html',-})-export class HideSectionLinkComponent implements OnInit {- displayed = true;-- public sectionName:string;-- text = {- remove: this.I18n.t('js.label_remove'),- };-- constructor(protected elementRef:ElementRef,- protected hideSectionService:HideSectionService,- protected I18n:I18nService) {}-- ngOnInit():void {- this.sectionName = this.elementRef.nativeElement.dataset.sectionName;- }-- hideSection() {- this.hideSectionService.hide(this.sectionName);- return false;- }-}diff --git a/frontend/src/app/shared/components/hide-section/hide-section.service.ts b/frontend/src/app/shared/components/hide-section/hide-section.service.tsdeleted file mode 100644index 133a5d57fe9..00000000000--- a/frontend/src/app/shared/components/hide-section/hide-section.service.ts+++ /dev/null@@ -1,94 +0,0 @@-//-- 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 { GonService } from 'core-app/core/gon/gon.service';-import { Injectable } from '@angular/core';-import { input } from '@openproject/reactivestates';--export interface HideSectionDefinition {- key:string;- label:string;-}--@Injectable({ providedIn: 'root' })-export class HideSectionService {- public displayed = input<string[]>();-- public all:HideSectionDefinition[] = [];-- constructor(Gon:GonService) {- const sections:any = Gon.get('hideSections');- this.all = sections.all;- this.displayed.putValue(sections.active.map((el:HideSectionDefinition) => {- this.toggleVisibility(el.key, true);- return el.key;- }));-- this.removeHiddenOnSubmit();- }-- section(key:string):HTMLElement|null {- return document.querySelector(`section.hide-section[data-section-name="${key}"]`);- }-- hide(key:string) {- this.displayed.doModify((displayed) => displayed.filter((el) => el !== key));- this.toggleVisibility(key, false);- }-- show(key:string) {- this.displayed.doModify((displayed) => [...displayed, key]);- this.toggleVisibility(key, true);- }-- private toggleVisibility(key:string, visible:boolean) {- const section = this.section(key);-- if (section) {- section.hidden = !visible;- }- }-- private removeHiddenOnSubmit() {- jQuery(document.body)- .on('submit', 'form', function (evt:any) {- const form = jQuery(this);- const sections = form.find('section.hide-section:hidden');-- if (form.data('hideSectionRemoved') || sections.length === 0) {- return true;- }-- form.data('hideSectionRemoved', true);- sections.remove();- form.trigger('submit');- evt.preventDefault();- return false;- });- }-}diff --git a/frontend/src/app/shared/shared.module.ts b/frontend/src/app/shared/shared.module.tsindex 2fd5edc8b05..b42cc06d905 100644--- a/frontend/src/app/shared/shared.module.ts+++ b/frontend/src/app/shared/shared.module.ts@@ -74,10 +74,6 @@ import { CollapsibleSectionComponent } from './components/collapsible-section/coimport { NoResultsComponent } from './components/no-results/no-results.component';import { EditableToolbarTitleComponent } from './components/editable-toolbar-title/editable-toolbar-title.component';import { PersistentToggleComponent } from './components/persistent-toggle/persistent-toggle.component';-import {- AddSectionDropdownComponent,-} from './components/hide-section/add-section-dropdown/add-section-dropdown.component';-import { HideSectionLinkComponent } from './components/hide-section/hide-section-link/hide-section-link.component';import { RemoteFieldUpdaterComponent } from './components/remote-field-updater/remote-field-updater.component';import { OpOptionListComponent } from './components/option-list/option-list.component';import { OpProjectIncludeComponent } from './components/project-include/project-include.component';@@ -224,8 +220,6 @@ export function bootstrapModule(injector:Injector):void {EditableToolbarTitleComponent,PersistentToggleComponent,- HideSectionLinkComponent,- AddSectionDropdownComponent,RemoteFieldUpdaterComponent,// Enterprise Editiondiff --git a/frontend/src/stimulus/controllers/dynamic/hide-sections.controller.ts b/frontend/src/stimulus/controllers/dynamic/hide-sections.controller.tsnew file mode 100644index 00000000000..bb4590c4663--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/hide-sections.controller.ts@@ -0,0 +1,45 @@+import { Controller } from '@hotwired/stimulus';++export default class extends Controller {+ static targets = ['section', 'select'];++ declare readonly sectionTargets:HTMLElement[];++ declare readonly selectTarget:HTMLSelectElement;++ add(event:Event) {+ const selectedValue = (event.target as HTMLSelectElement).value;+ if (!selectedValue) {+ return;+ }++ const section = this.sectionTargets.find((s) => s.dataset.sectionName === selectedValue);+ if (section) {+ section.hidden = false;+ }++ this.toggleOption(selectedValue);+ }++ hide(event:MouseEvent) {+ const section = (event.target as HTMLElement).closest('.hide-section') as HTMLElement;+ if (section) {+ section.hidden = true;+ }++ const name = section.dataset.name as string;+ this.toggleOption(name);+ }++ toggleOption(name:string) {+ const option = Array+ .from(this.selectTarget.options)+ .find((opt:HTMLOptionElement) => opt.value === name);++ if (!option) {+ return;+ }++ option.disabled = !option.disabled;+ }+}