allow following links in custom text widget

pull/7654/head
ulferts 5 years ago
parent b7442d6571
commit 31e4beeef1
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 19
      frontend/src/app/modules/grids/widgets/custom-text/custom-text.component.html
  2. 17
      frontend/src/app/modules/grids/widgets/custom-text/custom-text.component.ts
  3. 8
      modules/dashboards/spec/features/custom_text_spec.rb
  4. 6
      modules/my_page/spec/features/my/custom_text_spec.rb

@ -9,7 +9,8 @@
</widget-header> </widget-header>
<ng-template #text> <ng-template #text>
<span class="inplace-edit--read-value -default"> <span #displayContainer
class="inplace-edit--read-value -default">
<span <span
*ngIf="!textEmpty" *ngIf="!textEmpty"
[innerHTML]="customText"></span> [innerHTML]="customText"></span>
@ -33,17 +34,15 @@
</attachments> </attachments>
<div *ngIf="!active" <div *ngIf="!active"
class="inplace-edit--read"> class="inplace-edit--read -no-label"
<accessible-by-keyboard [ngClass]="{'wp-edit-field--container': isTextEditable}">
*ngIf="isTextEditable" <div *ngIf="isTextEditable"
class="inplace-editing--trigger-container" (accessibleClick)="activate($event)"
[spanClass]="inplaceEditClasses" [accessibleClickStopEvent]="false"
[linkClass]="'inplace-editing--trigger-link'" [ngClass]="inplaceEditClasses">
(execute)="activate()">
<ng-container *ngTemplateOutlet="text"></ng-container> <ng-container *ngTemplateOutlet="text"></ng-container>
</accessible-by-keyboard> </div>
<ng-container *ngIf="!isTextEditable"> <ng-container *ngIf="!isTextEditable">
<ng-container *ngTemplateOutlet="text"></ng-container> <ng-container *ngTemplateOutlet="text"></ng-container>

@ -1,5 +1,5 @@
import {AbstractWidgetComponent} from "core-app/modules/grids/widgets/abstract-widget.component"; import {AbstractWidgetComponent} from "core-app/modules/grids/widgets/abstract-widget.component";
import {Component, ChangeDetectionStrategy, Injector, OnInit, OnDestroy, SimpleChanges, ChangeDetectorRef} from '@angular/core'; import {Component, ChangeDetectionStrategy, Injector, OnInit, OnDestroy, SimpleChanges, ChangeDetectorRef, ElementRef, ViewChild} from '@angular/core';
import {CustomTextEditFieldService} from "core-app/modules/grids/widgets/custom-text/custom-text-edit-field.service"; import {CustomTextEditFieldService} from "core-app/modules/grids/widgets/custom-text/custom-text-edit-field.service";
import {I18nService} from "core-app/modules/common/i18n/i18n.service"; import {I18nService} from "core-app/modules/common/i18n/i18n.service";
import {HalResource} from "core-app/modules/hal/resources/hal-resource"; import {HalResource} from "core-app/modules/hal/resources/hal-resource";
@ -19,6 +19,8 @@ export class WidgetCustomTextComponent extends AbstractWidgetComponent implement
protected currentRawText:string; protected currentRawText:string;
public customText:SafeHtml; public customText:SafeHtml;
@ViewChild('displayContainer', { static: false }) readonly displayContainer:ElementRef;
constructor (protected i18n:I18nService, constructor (protected i18n:I18nService,
protected injector:Injector, protected injector:Injector,
public handler:CustomTextEditFieldService, public handler:CustomTextEditFieldService,
@ -55,7 +57,12 @@ export class WidgetCustomTextComponent extends AbstractWidgetComponent implement
} }
} }
public activate() { public activate(event:MouseEvent) {
// Prevent opening the edit mode if a link was clicked
if (this.clickedElementIsLinkWithinDisplayContainer(event)) {
return;
}
// load the attachments so that they are displayed in the list; // load the attachments so that they are displayed in the list;
this.resource.grid.updateAttachments(); this.resource.grid.updateAttachments();
@ -67,7 +74,7 @@ export class WidgetCustomTextComponent extends AbstractWidgetComponent implement
} }
public get inplaceEditClasses() { public get inplaceEditClasses() {
let classes = 'inplace-editing--container wp-edit-field--display-field'; let classes = 'inplace-editing--container wp-edit-field--display-field wp-table--cell-span -editable';
if (this.textEmpty) { if (this.textEmpty) {
classes += ' -placeholder'; classes += ' -placeholder';
@ -113,4 +120,8 @@ export class WidgetCustomTextComponent extends AbstractWidgetComponent implement
private memorizeCustomText() { private memorizeCustomText() {
this.customText = this.sanitization.bypassSecurityTrustHtml(this.handler.htmlText); this.customText = this.sanitization.bypassSecurityTrustHtml(this.handler.htmlText);
} }
private clickedElementIsLinkWithinDisplayContainer(event:any) {
return this.displayContainer.nativeElement.contains(event.target.closest('a,macro'));
}
} }

@ -72,7 +72,7 @@ describe 'Project description widget on dashboard', type: :feature, js: true do
custom_text_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)') custom_text_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)')
within custom_text_widget.area do within custom_text_widget.area do
find('.inplace-editing--trigger-container').click find('.inplace-editing--container ').click
field.set_value('My own little text') field.set_value('My own little text')
field.save! field.save!
@ -80,7 +80,7 @@ describe 'Project description widget on dashboard', type: :feature, js: true do
expect(page) expect(page)
.to have_selector('.wp-edit-field--display-field', text: 'My own little text') .to have_selector('.wp-edit-field--display-field', text: 'My own little text')
find('.inplace-editing--trigger-container').click find('.inplace-editing--container').click
field.set_value('My new text') field.set_value('My new text')
field.cancel_by_click field.cancel_by_click
@ -89,7 +89,7 @@ describe 'Project description widget on dashboard', type: :feature, js: true do
.to have_selector('.wp-edit-field--display-field', text: 'My own little text') .to have_selector('.wp-edit-field--display-field', text: 'My own little text')
# adding an image # adding an image
find('.inplace-editing--trigger-container').click find('.inplace-editing--container').click
sleep(0.1) sleep(0.1)
end end
@ -134,7 +134,7 @@ describe 'Project description widget on dashboard', type: :feature, js: true do
.to have_content(dashboard.widgets.first.options[:text]) .to have_content(dashboard.widgets.first.options[:text])
expect(page) expect(page)
.to have_no_selector('.inplace-editing--trigger-container') .to have_no_selector('.inplace-editing--container')
end end
end end
end end

@ -70,7 +70,7 @@ describe 'Custom text widget on my page', type: :feature, js: true do
custom_text_widget.expect_to_span(1, 1, 2, 2) custom_text_widget.expect_to_span(1, 1, 2, 2)
within custom_text_widget.area do within custom_text_widget.area do
find('.inplace-editing--trigger-container').click find('.inplace-editing--container').click
field.set_value('My own little text') field.set_value('My own little text')
field.save! field.save!
@ -78,7 +78,7 @@ describe 'Custom text widget on my page', type: :feature, js: true do
expect(page) expect(page)
.to have_selector('.wp-edit-field--display-field', text: 'My own little text') .to have_selector('.wp-edit-field--display-field', text: 'My own little text')
find('.inplace-editing--trigger-container').click find('.inplace-editing--container').click
field.set_value('My new text') field.set_value('My new text')
field.cancel_by_click field.cancel_by_click
@ -87,7 +87,7 @@ describe 'Custom text widget on my page', type: :feature, js: true do
.to have_selector('.wp-edit-field--display-field', text: 'My own little text') .to have_selector('.wp-edit-field--display-field', text: 'My own little text')
# adding an image # adding an image
find('.inplace-editing--trigger-container').click find('.inplace-editing--container').click
sleep(0.1) sleep(0.1)
end end

Loading…
Cancel
Save