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
[33677] Reduce complexity of boolean filters (#8601)
Behrokh Satarnejadc03176df18b4
diff --git a/frontend/src/app/components/filters/filter-boolean-value/filter-boolean-value.component.html b/frontend/src/app/components/filters/filter-boolean-value/filter-boolean-value.component.htmlindex 791f0d1213e..a0b2c84045a 100644--- a/frontend/src/app/components/filters/filter-boolean-value/filter-boolean-value.component.html+++ b/frontend/src/app/components/filters/filter-boolean-value/filter-boolean-value.component.html@@ -1,16 +1,4 @@-<div id="div-values-{{filter.name}}">- <select [(ngModel)]="value"- [focus]="shouldFocus"- class="advanced-filters--select-field"- id="values-{{filter.name}}"- name="v[{{filter.name}}]" >- <option value=""- disabled- [textContent]="text.placeholder"- *ngIf="hasNoValue">- </option>- <option *ngFor="let value of availableOptions"- [textContent]="text[value]"- [ngValue]="value"></option>- </select>-</div>+<slide-toggle [filterValue]="value"+ [filterName]="filter.name"+ (valueChanged)="onFilterUpdated($event)">+</slide-toggle>\ No newline at end of filediff --git a/frontend/src/app/components/filters/filter-boolean-value/filter-boolean-value.component.ts b/frontend/src/app/components/filters/filter-boolean-value/filter-boolean-value.component.tsindex 9d6966e6802..f56e308c076 100644--- a/frontend/src/app/components/filters/filter-boolean-value/filter-boolean-value.component.ts+++ b/frontend/src/app/components/filters/filter-boolean-value/filter-boolean-value.component.ts@@ -40,12 +40,6 @@ export class FilterBooleanValueComponent {@Input() public filter:QueryFilterInstanceResource;@Output() public filterChanged = new EventEmitter<QueryFilterInstanceResource>();- public text = {- placeholder: this.I18n.t('js.placeholders.selection'),- true: this.I18n.t('js.general_text_Yes'),- false: this.I18n.t('js.general_text_No')- };-constructor(readonly I18n:I18nService) {}@@ -53,16 +47,9 @@ export class FilterBooleanValueComponent {return this.filter.values[0];}- public set value(val) {+ public onFilterUpdated(val:string | HalResource) {this.filter.values[0] = val;this.filterChanged.emit(this.filter);}- public get hasNoValue() {- return _.isEmpty(this.filter.values);- }-- public get availableOptions() {- return [true, false];- }}diff --git a/frontend/src/app/components/filters/query-filter/query-filter.component.html b/frontend/src/app/components/filters/query-filter/query-filter.component.htmlindex 7df3d8584fc..962a39c08fd 100644--- a/frontend/src/app/components/filters/query-filter/query-filter.component.html+++ b/frontend/src/app/components/filters/query-filter/query-filter.component.html@@ -16,6 +16,7 @@</label><select required+ *ngIf="valueType !== '[1]Boolean'"class="advanced-filters--select"id="operators-{{filter.id}}"name="op[{{filter.id}}]"@@ -28,6 +29,12 @@[ngValue]="operator"></option></select>++ <filter-boolean-value *ngIf="valueType == '[1]Boolean'"+ (filterChanged)="onFilterUpdated($event)"+ [shouldFocus]="shouldFocus"+ [filter]="filter"></filter-boolean-value>+</div><!-- Values -->@@ -68,10 +75,6 @@[shouldFocus]="shouldFocus"[filter]="filter"></filter-string-value>- <filter-boolean-value *ngSwitchCase="'[1]Boolean'"- (filterChanged)="onFilterUpdated($event)"- [shouldFocus]="shouldFocus"- [filter]="filter"></filter-boolean-value><filter-toggled-multiselect-value *ngSwitchDefault(filterChanged)="onFilterUpdated($event)"diff --git a/frontend/src/app/components/filters/query-filter/query-filter.component.ts b/frontend/src/app/components/filters/query-filter/query-filter.component.tsindex 3a495b51053..ad67ef93127 100644--- a/frontend/src/app/components/filters/query-filter/query-filter.component.ts+++ b/frontend/src/app/components/filters/query-filter/query-filter.component.ts@@ -68,7 +68,7 @@ export class QueryFilterComponent implements OnInit {public onFilterUpdated(filter:QueryFilterInstanceResource) {this.filter = filter;- this.showValuesInput = this.filter.currentSchema!.isValueRequired();+ this.showValuesInput = this.showValues(this.filter);this.filterChanged.emit(this.filter);}@@ -87,6 +87,10 @@ export class QueryFilterComponent implements OnInit {ngOnInit() {this.eeShowBanners = this.bannerService.eeShowBanners;this.availableOperators = this.schemaCache.of(this.filter).availableOperators;- this.showValuesInput = this.filter.currentSchema!.isValueRequired();+ this.showValuesInput = this.showValues(this.filter);+ }++ private showValues(filter:QueryFilterInstanceResource) {+ return this.filter.currentSchema!.isValueRequired() && this.filter.currentSchema!.values!.type !== '[1]Boolean';}}diff --git a/frontend/src/app/modules/common/openproject-common.module.ts b/frontend/src/app/modules/common/openproject-common.module.tsindex 593e7d4ac4a..7e0aca43595 100644--- a/frontend/src/app/modules/common/openproject-common.module.ts+++ b/frontend/src/app/modules/common/openproject-common.module.ts@@ -83,6 +83,7 @@ import {WorkPackageAutocompleterComponent} from "core-app/modules/common/autocomimport {TimeEntryWorkPackageAutocompleterComponent} from "core-app/modules/common/autocomplete/te-work-package-autocompleter.component";import {DraggableAutocompleteComponent} from "core-app/modules/common/draggable-autocomplete/draggable-autocomplete.component";import {DragulaModule} from "ng2-dragula";+import {SlideToggleComponent} from "core-app/modules/common/slide-toggle/slide-toggle.component";export function bootstrapModule(injector:Injector) {// Ensure error reporter is run@@ -192,6 +193,10 @@ export function bootstrapModule(injector:Injector) {WorkPackageAutocompleterComponent,DraggableAutocompleteComponent,++ // filter++ SlideToggleComponent,],declarations: [OpDatePickerComponent,@@ -262,6 +267,9 @@ export function bootstrapModule(injector:Injector) {HomescreenNewFeaturesBlockComponent,BoardVideoTeaserModalComponent,++ //filter+ SlideToggleComponent,]})export class OpenprojectCommonModule {diff --git a/frontend/src/app/modules/common/slide-toggle/slide-toggle.component.html b/frontend/src/app/modules/common/slide-toggle/slide-toggle.component.htmlnew file mode 100644index 00000000000..01a53ecc820--- /dev/null+++ b/frontend/src/app/modules/common/slide-toggle/slide-toggle.component.html@@ -0,0 +1,9 @@+<div id="div-values-{{filterName}}">+ <label class="switch">+ <input type="checkbox" [ngModel]="filterValue" id="values-{{filterName}}"+ name="v[{{filterName}}]"+ (ngModelChange)="onValueChanged($event)">+ <span class="slider round"></span>+ </label>+ </div>+\ No newline at end of filediff --git a/frontend/src/app/modules/common/slide-toggle/slide-toggle.component.sass b/frontend/src/app/modules/common/slide-toggle/slide-toggle.component.sassnew file mode 100644index 00000000000..9f1f7bf2135--- /dev/null+++ b/frontend/src/app/modules/common/slide-toggle/slide-toggle.component.sass@@ -0,0 +1,56 @@+/* 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+++.slider:before+ position: absolute+ content: ""+ height: 16px+ width: 16px+ left: 4px+ bottom: 4px+ background-color: white+ -webkit-transition: .4s+ transition: .4s+++input:checked + .slider+ background-color: darkblue++input:checked + .slider: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/modules/common/slide-toggle/slide-toggle.component.spec.ts b/frontend/src/app/modules/common/slide-toggle/slide-toggle.component.spec.tsnew file mode 100644index 00000000000..0e5f1fe59e5--- /dev/null+++ b/frontend/src/app/modules/common/slide-toggle/slide-toggle.component.spec.ts@@ -0,0 +1,51 @@+import { ComponentFixture, fakeAsync, TestBed, async } from '@angular/core/testing';+import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';+import { SlideToggleComponent } from './slide-toggle.component';+import {FormsModule} from '@angular/forms';++describe('slide toggler', () => {+ let app:SlideToggleComponent;+ let fixture:ComponentFixture<SlideToggleComponent>;+ let element:DebugElement;++ beforeEach(() => {+ TestBed.configureTestingModule({+ declarations: [SlideToggleComponent],+ imports: [ FormsModule ],+ }).compileComponents();++ fixture = TestBed.createComponent(SlideToggleComponent);+ app = fixture.debugElement.componentInstance;+ element = fixture.debugElement;+ });+++ it('should set the input correctly', async(() => {+ app.filterName = 'foo';+ fixture.detectChanges();+ fixture.whenStable().then(() => {+ let container = document.querySelector('#div-values-foo');+ expect(document.contains(container)).toBeTruthy();+ });+ }));++ it('should emit the value correctly', async(() => {+ app.filterValue = true;+ fixture.detectChanges();+ fixture.whenStable().then(() => {+ let slider = document.querySelector('.slider');+ if (slider) {+ let style = getComputedStyle(slider);+ let backgroundColor = style.backgroundColor;+ expect(backgroundColor).toBe('rgb(0, 0, 139)');+ app.filterValue = false;+ fixture.detectChanges();+ setTimeout(() => {+ style = getComputedStyle(slider!!);+ backgroundColor = style.backgroundColor;+ expect(backgroundColor).toBe('rgb(204, 204, 204)'); }, 1000);+ }+ });+ }));++});\ No newline at end of filediff --git a/frontend/src/app/modules/common/slide-toggle/slide-toggle.component.ts b/frontend/src/app/modules/common/slide-toggle/slide-toggle.component.tsnew file mode 100644index 00000000000..2f995b34a93--- /dev/null+++ b/frontend/src/app/modules/common/slide-toggle/slide-toggle.component.ts@@ -0,0 +1,45 @@+//-- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2020 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 docs/COPYRIGHT.rdoc for more details.+//++++import {Component, Input, Output, EventEmitter, OnInit} from '@angular/core';+@Component({+ templateUrl: './slide-toggle.component.html',+ selector: 'slide-toggle',+ styleUrls: ['./slide-toggle.component.sass'],+})+++export class SlideToggleComponent {+ @Input() filterName:string;+ @Input() filterValue:boolean;+ @Output() valueChanged = new EventEmitter();++ public onValueChanged(val:any) {+ this.valueChanged.emit(val);+ }+}