Merge pull request #2341 from dpalou/MOBILE-3390

MOBILE-3390 database: Support URL force name and autolink
main
Juan Leyva 2020-04-27 17:40:32 +02:00 committed by GitHub
commit dc3d0d7138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -4,4 +4,7 @@
<core-input-errors *ngIf="error && mode == 'edit'" [control]="form.controls['f_'+field.id]" [errorText]="error"></core-input-errors>
</span>
<a *ngIf="isShowOrListMode() && value && value.content" [href]="value.content" core-link capture="true">{{value.content}}</a>
<ng-container *ngIf="isShowOrListMode() && value && value.content">
<a *ngIf="autoLink" [href]="value.content" core-link capture="true">{{ displayValue }}</a>
<span *ngIf="!autoLink">{{ displayValue }}</span>
</ng-container>

View File

@ -24,6 +24,9 @@ import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-
})
export class AddonModDataFieldUrlComponent extends AddonModDataFieldPluginComponent {
protected autoLink = false;
protected displayValue = '';
constructor(protected fb: FormBuilder) {
super(fb);
}
@ -43,4 +46,36 @@ export class AddonModDataFieldUrlComponent extends AddonModDataFieldPluginCompon
this.addControl('f_' + this.field.id, value);
}
/**
* Calculate data for show or list mode.
*/
protected calculateShowListData(): void {
if (!this.value || !this.value.content) {
return;
}
const url = this.value.content;
const text = this.field.param2 || this.value.content1; // Param2 forces the text to display.
this.autoLink = parseInt(this.field.param1, 10) === 1;
if (this.autoLink) {
this.displayValue = text || url;
} else {
// No auto link, always display the URL.
this.displayValue = url;
}
}
/**
* Update value being shown.
*/
protected updateValue(value: any): void {
super.updateValue(value);
if (this.isShowOrListMode()) {
this.calculateShowListData();
}
}
}