MOBILE-4207 search: Allow hiding course in results

main
Noel De Martin 2023-07-18 16:28:49 +09:00
parent 022c57d6ff
commit 596365da9c
3 changed files with 29 additions and 8 deletions

View File

@ -11,14 +11,14 @@
<core-format-text [text]="result.title"></core-format-text>
</h3>
<core-format-text *ngIf="result.content && !result.course && !result.user" [text]="result.content"></core-format-text>
<div *ngIf="result.context" class="flex-row">
<div *ngIf="result.context.courseName" class="result-context">
<div *ngIf="renderedContext" class="flex-row">
<div *ngIf="renderedContext.courseName" class="result-context">
<ion-icon name="fas-graduation-cap" aria-hidden="true"></ion-icon>
<core-format-text [text]="result.context.courseName"></core-format-text>
<core-format-text [text]="renderedContext.courseName"></core-format-text>
</div>
<div *ngIf="result.context.userName" class="result-context">
<div *ngIf="renderedContext.userName" class="result-context">
<ion-icon name="fas-user" aria-hidden="true"></ion-icon>
<span>{{ 'core.search.resultby' | translate: { $a: result.context.userName } }}</span>
<span>{{ 'core.search.resultby' | translate: { $a: renderedContext.userName } }}</span>
</div>
</div>
</ion-label>

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { Component, Input, Output, EventEmitter, OnChanges } from '@angular/core';
import { CoreSearchGlobalSearchResult } from '@features/search/services/global-search';
import { CoreSearchGlobalSearchResult, CoreSearchGlobalSearchResultContext } from '@features/search/services/global-search';
@Component({
selector: 'core-search-global-search-result',
@ -23,6 +23,9 @@ import { CoreSearchGlobalSearchResult } from '@features/search/services/global-s
export class CoreSearchGlobalSearchResultComponent implements OnChanges {
@Input() result!: CoreSearchGlobalSearchResult;
@Input() showCourse?: boolean;
renderedContext: CoreSearchGlobalSearchResultContext | null = null;
renderedIcon: string | null = null;
@Output() onClick = new EventEmitter();
@ -31,9 +34,25 @@ export class CoreSearchGlobalSearchResultComponent implements OnChanges {
* @inheritdoc
*/
ngOnChanges(): void {
this.renderedContext = this.computeRenderedContext();
this.renderedIcon = this.computeRenderedIcon();
}
/**
* Calculate the value of the context to render.
*
* @returns Rendered context.
*/
private computeRenderedContext(): CoreSearchGlobalSearchResultContext | null {
const context = this.result.context ?? {};
if (this.showCourse === false) {
delete context.courseName;
}
return Object.keys(context).length > 0 ? context : null;
}
/**
* Calculate the value of the icon to render.
*

View File

@ -37,6 +37,7 @@ interface Args {
module: 'forum-activity' | 'forum-post' | 'assign' | 'none';
courseContext: boolean;
userContext: boolean;
showCourse: boolean;
}
export default <Meta<Args>> {
@ -79,6 +80,7 @@ export default <Meta<Args>> {
module: 'none',
courseContext: false,
userContext: false,
showCourse: true,
},
parameters: {
design: {
@ -88,7 +90,7 @@ export default <Meta<Args>> {
},
};
const Template = story<Args>(({ image, courseContext, userContext, module, ...args }) => {
const Template = story<Args>(({ image, courseContext, userContext, module, showCourse, ...args }) => {
const result: CoreSearchGlobalSearchResult = {
...args,
id: 1,
@ -126,7 +128,7 @@ const Template = story<Args>(({ image, courseContext, userContext, module, ...ar
return {
component: CoreSearchGlobalSearchResultComponent,
props: { result },
props: { result, showCourse },
};
});