@@ -3,8 +3,10 @@ import {
33 ElementRef ,
44 EventEmitter ,
55 Input ,
6+ OnChanges ,
67 OnInit ,
78 Output ,
9+ SimpleChanges ,
810 ViewChild
911} from '@angular/core' ;
1012import { View , ViewAction } from '@app/model' ;
@@ -15,20 +17,23 @@ import { View, ViewAction } from '@app/model';
1517 templateUrl : 'content-tab.component.html' ,
1618 styleUrls : [ 'content-tab.component.scss' ]
1719} )
18- export class ElementContentTabComponent implements OnInit {
20+ export class ElementContentTabComponent implements OnInit , OnChanges {
1921 @Input ( ) view : View ;
2022 @Output ( ) onAction : EventEmitter < ViewAction > = new EventEmitter < ViewAction > ( ) ;
2123 @ViewChild ( 'inputElement' , { static : false } ) inputElement : ElementRef ;
2224
23- public iconCls : string ;
25+ public iconCls : string [ ] = [ ] ;
2426 private shouldFocusInput = false ;
2527 private clickTimeout : any ;
28+ private static faIconCache = new Map < string , boolean > ( ) ;
2629
2730 ngOnInit ( ) : void {
28- if ( ! this . view . asset ) {
29- this . iconCls = 'fa-linux' ;
30- } else {
31- this . iconCls = 'fa-' + this . view . asset . type . value ;
31+ this . updateIconClasses ( ) ;
32+ }
33+
34+ ngOnChanges ( changes : SimpleChanges ) : void {
35+ if ( changes . view ) {
36+ this . updateIconClasses ( ) ;
3237 }
3338 }
3439
@@ -70,4 +75,57 @@ export class ElementContentTabComponent implements OnInit {
7075 this . view . editable = false ;
7176 } , 200 ) ;
7277 }
78+
79+ private updateIconClasses ( ) : void {
80+ const iconKey = this . view ?. asset ?. type ?. value || 'linux' ;
81+ const faClass = `fa-${ iconKey } ` ;
82+ const fallbackClass = this . getFallbackIconClass ( iconKey ) ;
83+ const hasFontAwesome = this . hasFontAwesomeIcon ( faClass ) ;
84+
85+ this . iconCls = hasFontAwesome ? [ 'fa' , faClass ] : [ fallbackClass ] ;
86+ }
87+
88+ private getFallbackIconClass ( iconKey : string ) : string {
89+ const normalizedKey = iconKey || 'linux' ;
90+ const overrides : Record < string , string > = {
91+ general : 'switch_ico_docu' ,
92+ website : 'website_ico_docu' ,
93+ sqlserver : 'sqlserver_ico_docu' ,
94+ postgresql : 'postgresql_ico_docu' ,
95+ mysql : 'mysql_ico_docu' ,
96+ mariadb : 'mariadb_ico_docu' ,
97+ mongodb : 'mongodb_ico_docu' ,
98+ webcloud : 'WebCloud_ico_docu' ,
99+ web_cloud : 'WebCloud_ico_docu' ,
100+ 'web-cloud' : 'WebCloud_ico_docu'
101+ } ;
102+
103+ return overrides [ normalizedKey ] || `${ normalizedKey } _ico_docu` ;
104+ }
105+
106+ private hasFontAwesomeIcon ( iconClass : string ) : boolean {
107+ const cached = ElementContentTabComponent . faIconCache . get ( iconClass ) ;
108+ if ( cached !== undefined ) {
109+ return cached ;
110+ }
111+
112+ if ( typeof document === 'undefined' || typeof window === 'undefined' ) {
113+ return true ;
114+ }
115+
116+ const el = document . createElement ( 'i' ) ;
117+ el . className = `view_icon fa ${ iconClass } ` ;
118+ el . style . position = 'absolute' ;
119+ el . style . opacity = '0' ;
120+ el . style . pointerEvents = 'none' ;
121+ document . body . appendChild ( el ) ;
122+
123+ const content = window . getComputedStyle ( el , '::before' ) . getPropertyValue ( 'content' ) ;
124+ document . body . removeChild ( el ) ;
125+
126+ const normalizedContent = ( content || '' ) . replace ( / [ ' " ] / g, '' ) ;
127+ const hasContent = normalizedContent !== '' && normalizedContent !== 'none' && normalizedContent !== 'normal' ;
128+ ElementContentTabComponent . faIconCache . set ( iconClass , hasContent ) ;
129+ return hasContent ;
130+ }
73131}
0 commit comments