84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import {Directive, Input, OnDestroy} from '@angular/core';
|
|
import {Plugin} from "../../../utils/entities/adminTool/plugin";
|
|
import {PluginTemplate} from "../../../utils/entities/adminTool/pluginTemplate";
|
|
import {EnvProperties} from "../../../utils/properties/env-properties";
|
|
import {properties} from 'src/environments/environment';
|
|
import {Subscriber} from "rxjs";
|
|
|
|
export class PluginBaseInfo {
|
|
title: string = "Lorem ipsum";
|
|
constructor() {
|
|
}
|
|
compare(oldObject){
|
|
if(!oldObject) {
|
|
oldObject = Object.assign(this)
|
|
}else{
|
|
for (let attrKey of Object.keys(this)) {
|
|
if (!oldObject[attrKey] && oldObject[attrKey] != false) {
|
|
if(typeof this[attrKey] === "string" || typeof this[attrKey] === "boolean" ){
|
|
oldObject[attrKey] = this[attrKey];
|
|
}else {
|
|
oldObject[attrKey] = Object.assign(this[attrKey])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return oldObject;
|
|
}
|
|
}
|
|
export class PluginURL {
|
|
url:string;
|
|
linkText: string;
|
|
target:string;
|
|
route:boolean;
|
|
constructor(url,linkText, target = "_blank",route = false) {
|
|
this.url = url;
|
|
this.linkText = linkText;
|
|
this.target = target;
|
|
this.route = route;
|
|
}
|
|
|
|
}
|
|
|
|
export class PluginInfoCards{
|
|
tag?:string;
|
|
title:string;
|
|
description:string;
|
|
urlsArray:PluginURL[];
|
|
image?:string;
|
|
show:boolean;
|
|
}
|
|
@Directive()
|
|
export abstract class PluginBaseComponent<T extends PluginBaseInfo> implements OnDestroy {
|
|
public properties: EnvProperties = properties;
|
|
@Input() plugin:Plugin;
|
|
@Input() pluginTemplate:PluginTemplate;
|
|
@Input() pluginObject:T;
|
|
subscriptions = [];
|
|
constructor() {
|
|
|
|
}
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.subscriptions.forEach(subscription => {
|
|
if (subscription instanceof Subscriber) {
|
|
subscription.unsubscribe()
|
|
} else if (subscription instanceof Function) {
|
|
subscription();
|
|
} else if (typeof IntersectionObserver !== 'undefined' && subscription instanceof IntersectionObserver) {
|
|
subscription.disconnect();
|
|
} else if (typeof ResizeObserver !== 'undefined' && subscription instanceof ResizeObserver) {
|
|
subscription.disconnect();
|
|
}
|
|
});
|
|
}
|
|
|
|
isVisible(field){
|
|
return (this.plugin && this.pluginObject && this.pluginObject[field] == true) /* plugin is on anyway */
|
|
|| (!this.plugin && this.pluginTemplate && this.pluginObject && this.pluginObject[field] == true) /* template is on */
|
|
}
|
|
|
|
}
|