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
Add search highlighting to project include, add disabled spot-list item
Benjamin Bädorfd71b43ecd1bb
diff --git a/frontend/src/app/shared/components/project-include/project-include.component.html b/frontend/src/app/shared/components/project-include/project-include.component.htmlindex 6ea532409db..9bbaa62178a 100644--- a/frontend/src/app/shared/components/project-include/project-include.component.html+++ b/frontend/src/app/shared/components/project-include/project-include.component.html@@ -48,6 +48,7 @@op-project-list[projects]="projects$ | async"[selected]="selectedProjects"+ [query]="query"(update)="selectedProjects = $event"data-qa-selector="project-include-list"></ul>diff --git a/frontend/src/app/shared/components/project-include/project-list.component.html b/frontend/src/app/shared/components/project-include/project-list.component.htmlindex a1e697ccd83..59d5fa8a2b4 100644--- a/frontend/src/app/shared/components/project-include/project-list.component.html+++ b/frontend/src/app/shared/components/project-include/project-list.component.html@@ -2,16 +2,22 @@class="spot-list--item"*ngFor="let project of projects">- <label class="spot-list--item-action op-project-list--item-action">+ <label+ class="spot-list--item-action op-project-list--item-action"+ [ngClass]="{ 'spot-list--item-action_disabled': !project.found }"+ ><spot-checkbox*ngFor="let checked of [isChecked(project.href)]"[checked]="checked"(change)="changeSelected(project.href)"- [disabled]="project.href === currentProjectHref"+ [disabled]="!project.found || project.href === currentProjectHref"[attr.data-qa-project-include-id]="project.id"[attr.data-qa-project-include-checked]="checked ? 1 : 0"></spot-checkbox>- <div class="spot-list--item-title">{{ project.name }}</div>+ <div+ class="spot-list--item-title"+ [opSearchHighlight]="query"+ >{{ project.name }}</div></label><ul@@ -19,6 +25,7 @@op-project-list[projects]="project.children"[selected]="selected"+ [query]="query"(update)="updateSelected($event)"></ul></li>diff --git a/frontend/src/app/shared/components/project-include/project-list.component.ts b/frontend/src/app/shared/components/project-include/project-list.component.tsindex 8c9d281ac84..009383fdcff 100644--- a/frontend/src/app/shared/components/project-include/project-list.component.ts+++ b/frontend/src/app/shared/components/project-include/project-list.component.ts@@ -27,6 +27,8 @@ export class OpProjectListComponent {@Input() selected:string[] = [];+ @Input() query:string = '';+public get currentProjectHref():string|null {return this.currentProjectService.apiv3Path;}diff --git a/frontend/src/app/shared/directives/search-highlight.directive.sass b/frontend/src/app/shared/directives/search-highlight.directive.sassnew file mode 100644index 00000000000..9bcfa217ee9--- /dev/null+++ b/frontend/src/app/shared/directives/search-highlight.directive.sass@@ -0,0 +1,2 @@+.op-search-highlight+ color: $spot-color-maindiff --git a/frontend/src/app/shared/directives/search-highlight.directive.ts b/frontend/src/app/shared/directives/search-highlight.directive.tsnew file mode 100644index 00000000000..073dc43bdf0--- /dev/null+++ b/frontend/src/app/shared/directives/search-highlight.directive.ts@@ -0,0 +1,42 @@+import {+ AfterViewChecked,+ Directive,+ ElementRef,+ Input,+} from '@angular/core';++@Directive({+ selector: '[opSearchHighlight]',+})+export class OpSearchHighlightDirective implements AfterViewChecked {+ @Input('opSearchHighlight') public query = '';++ constructor(readonly elementRef:ElementRef) { }++ ngAfterViewChecked() {+ if (!this.query) {+ return;+ }+++ const textNode = Array.from(this.elementRef.nativeElement.childNodes).find((n:Node) => n.nodeType === n.TEXT_NODE) as Node|undefined;+ const content = textNode?.textContent?.toLowerCase() || '';+ if (!content) {+ return;+ }++ const query = this.query.toLowerCase();+ const startIndex = content.indexOf(query);+ if (startIndex < 0) {+ return;+ }++ const start = content.slice(0, startIndex);+ const result = content.slice(startIndex, startIndex + query.length);+ const end = content.slice(startIndex + query.length);++ const newNode = document.createElement('span');+ newNode.innerHTML = `${start}<span class="op-search-highlight">${result}</span>${end}`;+ this.elementRef.nativeElement.replaceChild(newNode, textNode);+ }+}diff --git a/frontend/src/app/shared/shared.module.ts b/frontend/src/app/shared/shared.module.tsindex 6b52d521748..cd00b6b3134 100644--- a/frontend/src/app/shared/shared.module.ts+++ b/frontend/src/app/shared/shared.module.ts@@ -64,6 +64,7 @@ import {highlightColSelector,OpHighlightColDirective,} from './directives/highlight-col/highlight-col.directive';+import { OpSearchHighlightDirective } from './directives/search-highlight.directive';import { CopyToClipboardDirective } from './components/copy-to-clipboard/copy-to-clipboard.directive';import { OpDateTimeComponent } from './components/date/op-date-time.component';@@ -166,6 +167,8 @@ export function bootstrapModule(injector:Injector) {// Table highlightOpHighlightColDirective,+ OpSearchHighlightDirective,+ResizerComponent,TablePaginationComponent,@@ -226,6 +229,8 @@ export function bootstrapModule(injector:Injector) {TablePaginationComponent,SortHeaderDirective,+ OpSearchHighlightDirective,+// Zen mode buttonZenModeButtonComponent,diff --git a/frontend/src/app/spot/spot-docs.component.html b/frontend/src/app/spot/spot-docs.component.htmlindex f8a5e7e68aa..3f310e05d6b 100644--- a/frontend/src/app/spot/spot-docs.component.html+++ b/frontend/src/app/spot/spot-docs.component.html@@ -121,6 +121,12 @@ Currently selected value is {{ toggleValue }}<div class="spot-list--item-title">Second child checkbox item</div></label></li>+ <li class="spot-list--item">+ <label class="spot-list--item-action spot-list--item-action_disabled">+ <spot-checkbox [(ngModel)]="listCheckboxValue" disabled></spot-checkbox>+ <div class="spot-list--item-title">Disabled item</div>+ </label>+ </li></ul></li></ul>diff --git a/frontend/src/app/spot/styles/sass/components/list.sass b/frontend/src/app/spot/styles/sass/components/list.sassindex 9ca6fcee261..afd4210bf2d 100644--- a/frontend/src/app/spot/styles/sass/components/list.sass+++ b/frontend/src/app/spot/styles/sass/components/list.sass@@ -18,6 +18,10 @@border: 0cursor: pointer+ &_disabled+ color: $spot-color-basic-gray-3+ cursor: default+&-title&:not(:first-child)margin-left: $spot-spacing-0_5diff --git a/frontend/src/global_styles/openproject.sass b/frontend/src/global_styles/openproject.sassindex 8305e166b8d..4c2b06deed6 100644--- a/frontend/src/global_styles/openproject.sass+++ b/frontend/src/global_styles/openproject.sass@@ -9,6 +9,7 @@@import "./common/openproject-common.module"@import "../app/shared/components/modal/modal.module"+@import "../app/shared/directives/search-highlight.directive"// Dynamically linked plugin styles from Rails plugins@import "../app/features/plugins/linked-plugins.styles"