Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/app/elements/content/content-tab/content-tab.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,19 @@ li {
.view_icon {
margin-right: 5px;
font-style: normal;
width: 16px;
height: 16px;
display: inline-block;
background-repeat: no-repeat;
background-position: center;
background-size: 16px 16px;
vertical-align: middle;

&::before {
display: inline-block;
width: 16px;
line-height: 16px;
text-align: center;
color: var(--el-icon-color);
font-family: FontAwesome;
}
Expand Down
70 changes: 64 additions & 6 deletions src/app/elements/content/content-tab/content-tab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {
ElementRef,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges,
ViewChild
} from '@angular/core';
import { View, ViewAction } from '@app/model';
Expand All @@ -15,20 +17,23 @@ import { View, ViewAction } from '@app/model';
templateUrl: 'content-tab.component.html',
styleUrls: ['content-tab.component.scss']
})
export class ElementContentTabComponent implements OnInit {
export class ElementContentTabComponent implements OnInit, OnChanges {
@Input() view: View;
@Output() onAction: EventEmitter<ViewAction> = new EventEmitter<ViewAction>();
@ViewChild('inputElement', { static: false }) inputElement: ElementRef;

public iconCls: string;
public iconCls: string[] = [];
private shouldFocusInput = false;
private clickTimeout: any;
private static faIconCache = new Map<string, boolean>();

ngOnInit(): void {
if (!this.view.asset) {
this.iconCls = 'fa-linux';
} else {
this.iconCls = 'fa-' + this.view.asset.type.value;
this.updateIconClasses();
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.view) {
this.updateIconClasses();
}
}

Expand Down Expand Up @@ -70,4 +75,57 @@ export class ElementContentTabComponent implements OnInit {
this.view.editable = false;
}, 200);
}

private updateIconClasses(): void {
const iconKey = this.view?.asset?.type?.value || 'linux';
const faClass = `fa-${iconKey}`;
const fallbackClass = this.getFallbackIconClass(iconKey);
const hasFontAwesome = this.hasFontAwesomeIcon(faClass);

this.iconCls = hasFontAwesome ? ['fa', faClass] : [fallbackClass];
}

private getFallbackIconClass(iconKey: string): string {
const normalizedKey = iconKey || 'linux';
const overrides: Record<string, string> = {
general: 'switch_ico_docu',
website: 'website_ico_docu',
sqlserver: 'sqlserver_ico_docu',
postgresql: 'postgresql_ico_docu',
mysql: 'mysql_ico_docu',
mariadb: 'mariadb_ico_docu',
mongodb: 'mongodb_ico_docu',
webcloud: 'WebCloud_ico_docu',
web_cloud: 'WebCloud_ico_docu',
'web-cloud': 'WebCloud_ico_docu'
};

return overrides[normalizedKey] || `${normalizedKey}_ico_docu`;
}

private hasFontAwesomeIcon(iconClass: string): boolean {
const cached = ElementContentTabComponent.faIconCache.get(iconClass);
if (cached !== undefined) {
return cached;
}

if (typeof document === 'undefined' || typeof window === 'undefined') {
return true;
}

const el = document.createElement('i');
el.className = `view_icon fa ${iconClass}`;
el.style.position = 'absolute';
el.style.opacity = '0';
el.style.pointerEvents = 'none';
document.body.appendChild(el);

const content = window.getComputedStyle(el, '::before').getPropertyValue('content');
document.body.removeChild(el);

const normalizedContent = (content || '').replace(/['"]/g, '');
const hasContent = normalizedContent !== '' && normalizedContent !== 'none' && normalizedContent !== 'normal';
ElementContentTabComponent.faIconCache.set(iconClass, hasContent);
return hasContent;
}
}