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
Remove old slide toggle and replace it with spot-switch
Benjamin Bädorf4c78a8a9b044
diff --git a/app/views/projects/filters/_boolean.html.erb b/app/views/projects/filters/_boolean.html.erbindex 803ff54509e..8ca036ece5f 100644--- a/app/views/projects/filters/_boolean.html.erb+++ b/app/views/projects/filters/_boolean.html.erb@@ -1,6 +1,10 @@-<slide-toggle data-active="<%= filter.values.first == 't' %>"- data-container-classes="advanced-filters--filter-value"- data-input-name="v-<%= filter.class.key %>"- data-filter-name="boolean">-</slide-toggle>+<label class="advanced-filters--filter-value">+ <%= angular_component_tag 'spot-switch',+ inputs: {+ name: "v-" + filter.class.key.to_s,+ checked: filter.values.first == 't',+ filterName: 'boolean',+ }+ %>+</label><div class="advanced-filters--filter-operator" style="visibility: hidden"></div>diff --git a/frontend/src/app/core/setup/global-dynamic-components.const.ts b/frontend/src/app/core/setup/global-dynamic-components.const.tsindex b18637a4f18..3c02c6cc893 100644--- a/frontend/src/app/core/setup/global-dynamic-components.const.ts+++ b/frontend/src/app/core/setup/global-dynamic-components.const.ts@@ -142,9 +142,9 @@ import {WorkPackageQuickinfoMacroComponent,} from 'core-app/shared/components/fields/macros/work-package-quickinfo-macro.component';import {- SlideToggleComponent,- slideToggleSelector,-} from 'core-app/shared/components/slide-toggle/slide-toggle.component';+ SpotSwitchComponent,+ spotSwitchSelector,+} from 'core-app/spot/components/switch/switch.component';import { BackupComponent, backupSelector } from 'core-app/core/setup/globals/components/admin/backup.component';import {EnterpriseBaseComponent,@@ -250,7 +250,7 @@ export const globalDynamicComponents:OptionalBootstrapDefinition[] = [{ selector: attributeLabelMacro, cls: AttributeLabelMacroComponent, embeddable: true },{ selector: quickInfoMacroSelector, cls: WorkPackageQuickinfoMacroComponent, embeddable: true },{ selector: editableQueryPropsSelector, cls: EditableQueryPropsComponent },- { selector: slideToggleSelector, cls: SlideToggleComponent },+ { selector: spotSwitchSelector, cls: SpotSwitchComponent },{ selector: backupSelector, cls: BackupComponent },{ selector: opInAppNotificationBellSelector, cls: InAppNotificationBellComponent },{ selector: ianMenuSelector, cls: IanMenuComponent },diff --git a/frontend/src/app/features/work-packages/components/filters/filter-boolean-value/filter-boolean-value.component.html b/frontend/src/app/features/work-packages/components/filters/filter-boolean-value/filter-boolean-value.component.htmlindex ee714ba53ea..3e2a96619e4 100644--- a/frontend/src/app/features/work-packages/components/filters/filter-boolean-value/filter-boolean-value.component.html+++ b/frontend/src/app/features/work-packages/components/filters/filter-boolean-value/filter-boolean-value.component.html@@ -1,6 +1,5 @@-<slide-toggle [active]="value"- containerId="div-values-{{filter.id}}"- inputId="values-{{filter.name}}"- inputName="v[{{filter.name}}]"- (valueChanged)="onFilterUpdated($event)">-</slide-toggle>\ No newline at end of file+<spot-switch+ [checked]="value"+ name="v[{{filter.name}}]"+ (checkedChanged)="onFilterUpdated($event)"+></spot-switch>diff --git a/frontend/src/app/shared/components/dataset-inputs.ts b/frontend/src/app/shared/components/dataset-inputs.tsindex 30151b89309..379c6ae0be6 100644--- a/frontend/src/app/shared/components/dataset-inputs.ts+++ b/frontend/src/app/shared/components/dataset-inputs.ts@@ -59,7 +59,8 @@ export function populateInputsFromDataset(instance:DatasetInputsDecorated):any {.find((key:string) => typeof (cstr[key] as ɵDirectiveDef<unknown>).declaredInputs === 'object');if (!declaredInputsParentKey) {- throw new Error('Could not find declared inputs for component');+ console.warn('Could not find declared inputs for component');+ return;}const input = cstr[declaredInputsParentKey] as ɵDirectiveDef<unknown>;diff --git a/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.html b/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.htmldeleted file mode 100644index 02ddfd908f9..00000000000--- a/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.html+++ /dev/null@@ -1,13 +0,0 @@-<div [attr.id]="containerId"- class="slide-toggle {{ containerClasses }}"- [ngClass]="{ '-active': active }">- <label class="switch">- <input type="checkbox"- [ngModel]="active"- [attr.id]="inputId || undefined"- [attr.name]="inputName || undefined"- (ngModelChange)="onValueChanged($event)" />- <span class="slider round"></span>- </label>-</div>-\ No newline at end of filediff --git a/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.sass b/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.sassdeleted file mode 100644index 249debe9024..00000000000--- a/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.sass+++ /dev/null@@ -1,56 +0,0 @@-/* The switch - the box around the slider */-.switch- position: relative- display: inline-block- width: 50px- height: 24px---/* Hide default HTML checkbox */-.switch input- opacity: 0- width: 0- height: 0---/* The slider */-.slider- position: absolute- cursor: pointer- top: 0- left: 0- right: 0- bottom: 0- background-color: #ccc- -webkit-transition: .4s- transition: .4s--- &:before- position: absolute- content: ""- height: 16px- width: 16px- left: 4px- bottom: 4px- background-color: white- -webkit-transition: .4s- transition: .4s---.slide-toggle.-active .slider- background-color: darkblue-- &:before- -webkit-transform: translateX(26px)- -ms-transform: translateX(26px)- transform: translateX(26px)---/* Rounded sliders */-.slider.round- border-radius: 34px---.slider.round:before- border-radius: 50%diff --git a/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.spec.ts b/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.spec.tsdeleted file mode 100644index e0e8ee9881e..00000000000--- a/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.spec.ts+++ /dev/null@@ -1,48 +0,0 @@-import { ComponentFixture, TestBed } from '@angular/core/testing';-import { ChangeDetectionStrategy, DebugElement } from '@angular/core';-import { FormsModule } from '@angular/forms';-import { SlideToggleComponent } from './slide-toggle.component';--describe('slide toggler', () => {- let app:SlideToggleComponent;- let fixture:ComponentFixture<SlideToggleComponent>;- let element:DebugElement;-- beforeEach(() => {- TestBed- .configureTestingModule({- declarations: [SlideToggleComponent],- imports: [FormsModule],- })- .overrideComponent(SlideToggleComponent, { set: { changeDetection: ChangeDetectionStrategy.Default } })- .compileComponents();-- fixture = TestBed.createComponent(SlideToggleComponent);- app = fixture.debugElement.componentInstance;- element = fixture.debugElement;- });-- it('should set the input correctly', (() => {- app.active = false;- fixture.detectChanges();-- const container = document.querySelector('.slide-toggle')!;- expect(container.classList.contains('-active')).toBeFalse();- expect(document.contains(container)).toBeTruthy();- }));-- it('should emit the value correctly', (() => {- app.active = true;- fixture.detectChanges();-- let container = document.querySelector('.slide-toggle')!;- expect(container.classList.contains('-active')).toBeTrue();-- app.active = false;- fixture.detectChanges();-- expect(app.active).toBeFalse();- container = document.querySelector('.slide-toggle')!;- expect(container.classList.contains('-active')).toBeFalse();- }));-});diff --git a/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.ts b/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.tsdeleted file mode 100644index 36a77000a8b..00000000000--- a/frontend/src/app/shared/components/slide-toggle/slide-toggle.component.ts+++ /dev/null@@ -1,90 +0,0 @@-// -- copyright-// OpenProject is an open source project management software.-// Copyright (C) 2012-2022 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 {- ChangeDetectionStrategy,- ChangeDetectorRef,- Component,- ElementRef,- EventEmitter,- Input,- OnChanges,- OnInit,- Output,- SimpleChanges,-} from '@angular/core';--export const slideToggleSelector = 'slide-toggle';--@Component({- templateUrl: './slide-toggle.component.html',- selector: slideToggleSelector,- styleUrls: ['./slide-toggle.component.sass'],- changeDetection: ChangeDetectionStrategy.OnPush,-})--export class SlideToggleComponent implements OnInit, OnChanges {- @Input() containerId:string;-- @Input() containerClasses:string;-- @Input() inputId:string;-- @Input() inputName:string;-- @Input() active:boolean;-- @Output() valueChanged = new EventEmitter();-- constructor(private elementRef:ElementRef,- private cdRef:ChangeDetectorRef) {- }-- ngOnChanges(changes:SimpleChanges) {- console.warn(JSON.stringify(changes));- }-- ngOnInit() {- const { dataset } = this.elementRef.nativeElement;-- // Allow taking over values from dataset (Rails)- if (dataset.inputName) {- this.containerId = dataset.containerId;- this.containerClasses = dataset.containerClasses;- this.inputId = dataset.inputId;- this.inputName = dataset.inputName;- this.active = dataset.active.toString() === 'true';- }- }-- public onValueChanged(val:any) {- this.active = val;- this.valueChanged.emit(val);- this.cdRef.detectChanges();- }-}diff --git a/frontend/src/app/shared/shared.module.ts b/frontend/src/app/shared/shared.module.tsindex 97c4b40358b..44049a236e6 100644--- a/frontend/src/app/shared/shared.module.ts+++ b/frontend/src/app/shared/shared.module.ts@@ -76,7 +76,6 @@ import { AddSectionDropdownComponent } from './components/hide-section/add-sectiimport { HideSectionLinkComponent } from './components/hide-section/hide-section-link/hide-section-link.component';import { RemoteFieldUpdaterComponent } from './components/remote-field-updater/remote-field-updater.component';import { ShowSectionDropdownComponent } from './components/hide-section/show-section-dropdown.component';-import { SlideToggleComponent } from './components/slide-toggle/slide-toggle.component';import { DynamicBootstrapModule } from './components/dynamic-bootstrap/dynamic-bootstrap.module';import { OpCheckboxFieldComponent } from './components/forms/checkbox-field/checkbox-field.component';import { OpFormFieldComponent } from './components/forms/form-field/form-field.component';@@ -189,10 +188,6 @@ export function bootstrapModule(injector:Injector):void {DynamicModule,- // filter-- SlideToggleComponent,-OpCheckboxFieldComponent,OpFormFieldComponent,OpFormBindingDirective,@@ -251,9 +246,6 @@ export function bootstrapModule(injector:Injector):void {HomescreenNewFeaturesBlockComponent,- // filter- SlideToggleComponent,-OpCheckboxFieldComponent,OpFormFieldComponent,OpFormBindingDirective,diff --git a/frontend/src/app/spot/components/switch/switch.component.ts b/frontend/src/app/spot/components/switch/switch.component.tsindex e0007d7f09d..b00b4ab5a44 100644--- a/frontend/src/app/spot/components/switch/switch.component.ts+++ b/frontend/src/app/spot/components/switch/switch.component.ts@@ -12,11 +12,14 @@ import {ControlValueAccessor,NG_VALUE_ACCESSOR,} from '@angular/forms';+import { populateInputsFromDataset } from 'core-app/shared/components/dataset-inputs';export type SpotSwitchState = boolean;+export const spotSwitchSelector = 'spot-switch';+@Component({- selector: 'spot-switch',+ selector: spotSwitchSelector,templateUrl: './switch.component.html',providers: [{provide: NG_VALUE_ACCESSOR,@@ -39,6 +42,12 @@ export class SpotSwitchComponent implements ControlValueAccessor {@Input() public checked = false;+ constructor(+ public elementRef:ElementRef,+ ) {+ populateInputsFromDataset(this);+ }+onStateChange():void {const value = (this.input.nativeElement as HTMLInputElement).checked;this.checkedChange.emit(value);diff --git a/frontend/src/app/spot/spot.module.ts b/frontend/src/app/spot/spot.module.tsindex c8ccdd98554..32a8044ea50 100644--- a/frontend/src/app/spot/spot.module.ts+++ b/frontend/src/app/spot/spot.module.ts@@ -1,11 +1,11 @@import { NgModule } from '@angular/core';import { FormsModule } from '@angular/forms';import { CommonModule } from '@angular/common';-import { A11yModule } from '@angular/cdk/a11y';import { UIRouterModule } from '@uirouter/angular';import { I18nService } from 'core-app/core/i18n/i18n.service';import { SPOT_DOCS_ROUTES } from './spot.routes';import { SpotCheckboxComponent } from './components/checkbox/checkbox.component';+import { SpotSwitchComponent } from './components/switch/switch.component';import { SpotToggleComponent } from './components/toggle/toggle.component';import { SpotTextFieldComponent } from './components/text-field/text-field.component';import { SpotFilterChipComponent } from './components/filter-chip/filter-chip.component';@@ -20,21 +20,26 @@ import { SpotDocsComponent } from './spot-docs.component';FormsModule,CommonModule,],+providers: [I18nService,],+declarations: [SpotDocsComponent,SpotCheckboxComponent,+ SpotSwitchComponent,SpotToggleComponent,SpotTextFieldComponent,SpotFilterChipComponent,SpotDropModalComponent,SpotTooltipComponent,],+exports: [SpotCheckboxComponent,+ SpotSwitchComponent,SpotToggleComponent,SpotTextFieldComponent,SpotFilterChipComponent,diff --git a/frontend/src/app/spot/styles/sass/components/switch.sass b/frontend/src/app/spot/styles/sass/components/switch.sassindex 7084b02b472..4565e9567cb 100644--- a/frontend/src/app/spot/styles/sass/components/switch.sass+++ b/frontend/src/app/spot/styles/sass/components/switch.sass@@ -1,3 +1,5 @@+@use "sass:math"+.spot-switchdisplay: inline-flexjustify-content: center@@ -27,7 +29,7 @@align-items: centerheight: $spot-spacing-1 + $spot-spacing-0_25width: $spot-spacing-2 + $spot-spacing-0_25- border-radius: ($spot-spacing-1 + $spot-spacing-0_25) / 2+ border-radius: math.div($spot-spacing-1 + $spot-spacing-0_25, 2)border: 1px solid $spot-color-basic-gray-3background-color: $spot-color-basic-gray-5cursor: pointer