75058: Added Withdrawn and Private badges for item list/grid components everywhere

This commit is contained in:
Kristof De Langhe
2020-12-07 17:54:30 +01:00
parent 32a29c4a17
commit d50dd12d3d
3 changed files with 33 additions and 9 deletions

View File

@@ -1,12 +1,7 @@
<ng-template dsListableObject> <ng-template dsListableObject>
</ng-template> </ng-template>
<div #badges class="position-absolute ml-1"> <div #badges class="position-absolute ml-1">
<div *ngIf="dso && !dso.isDiscoverable" class="private-badge"> <ng-content></ng-content>
<span class="badge badge-danger">{{ "admin.search.item.private" | translate }}</span>
</div>
<div *ngIf="dso && dso.isWithdrawn" class="withdrawn-badge">
<span class="badge badge-warning">{{ "admin.search.item.withdrawn" | translate }}</span>
</div>
</div> </div>
<ul #buttons class="list-group list-group-flush"> <ul #buttons class="list-group list-group-flush">
<li class="list-group-item"> <li class="list-group-item">

View File

@@ -1 +1,9 @@
<ng-template dsListableObject></ng-template> <div #badges>
<div *ngIf="objectAsAny && !objectAsAny.isDiscoverable" class="private-badge">
<span class="badge badge-danger">{{ "admin.search.item.private" | translate }}</span>
</div>
<div *ngIf="objectAsAny && objectAsAny.isWithdrawn" class="withdrawn-badge">
<span class="badge badge-warning">{{ "admin.search.item.withdrawn" | translate }}</span>
</div>
</div>
<ng-template dsListableObject></ng-template>

View File

@@ -1,4 +1,4 @@
import { Component, ComponentFactoryResolver, Input, OnInit, ViewChild } from '@angular/core'; import { Component, ComponentFactoryResolver, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
import { ListableObject } from '../listable-object.model'; import { ListableObject } from '../listable-object.model';
import { ViewMode } from '../../../../core/shared/view-mode.model'; import { ViewMode } from '../../../../core/shared/view-mode.model';
import { Context } from '../../../../core/shared/context.model'; import { Context } from '../../../../core/shared/context.model';
@@ -61,6 +61,19 @@ export class ListableObjectComponentLoaderComponent implements OnInit {
*/ */
@ViewChild(ListableObjectDirective, {static: true}) listableObjectDirective: ListableObjectDirective; @ViewChild(ListableObjectDirective, {static: true}) listableObjectDirective: ListableObjectDirective;
/**
* View on the badges template, to be passed on to the loaded component (which will place the badges in the desired
* location, or on top if not specified)
*/
@ViewChild('badges', { static: true }) badges: ElementRef;
/**
* The provided object as any
* This is required to access the object's "isDiscoverable" and "isWithdrawn" properties from the template without
* knowing the object's type
*/
objectAsAny: any;
constructor(private componentFactoryResolver: ComponentFactoryResolver) { constructor(private componentFactoryResolver: ComponentFactoryResolver) {
} }
@@ -68,12 +81,20 @@ export class ListableObjectComponentLoaderComponent implements OnInit {
* Setup the dynamic child component * Setup the dynamic child component
*/ */
ngOnInit(): void { ngOnInit(): void {
this.objectAsAny = this.object as any;
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.getComponent()); const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.getComponent());
const viewContainerRef = this.listableObjectDirective.viewContainerRef; const viewContainerRef = this.listableObjectDirective.viewContainerRef;
viewContainerRef.clear(); viewContainerRef.clear();
const componentRef = viewContainerRef.createComponent(componentFactory); const componentRef = viewContainerRef.createComponent(
componentFactory,
0,
undefined,
[
[this.badges.nativeElement],
]);
(componentRef.instance as any).object = this.object; (componentRef.instance as any).object = this.object;
(componentRef.instance as any).index = this.index; (componentRef.instance as any).index = this.index;
(componentRef.instance as any).linkType = this.linkType; (componentRef.instance as any).linkType = this.linkType;