3. Constructed Attributes
@@ -403,25 +232,26 @@ declare var ResizeObserver;
`
})
-export class TerminologyComponent implements OnInit, OnDestroy {
+export class TerminologyComponent implements OnInit, OnDestroy, AfterViewInit, AfterContentChecked {
public tab: 'entities' | 'attributes' = 'entities';
private subscriptions: any[] = [];
public openaireEntities = OpenaireEntities;
public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'Resources - Terminology and construction', keepFormat: true}];
- public graph_offset: number = 0;
- public graph_height: number = 0;
+ public graph_offset: number = 0;
+ public graph_height: number = 0;
@ViewChild("graph_element") graph_element;
- public contentSections: string[] = ['entities', 'inherited-and-inferred-attributes', 'constructed-attributes'];
- public activeSection: string;
- private observer: IntersectionObserver;
- private timeout: Timeout;
+ public contentSections: string[] = ['entities', 'inherited-and-inferred-attributes', 'constructed-attributes'];
+ public activeSection: string;
+ public properties = properties;
+ public divContents: any;
constructor(private seoService: SEOService,
private meta: Meta,
private router: Router,
private route: ActivatedRoute,
private title: Title,
- private cdr: ChangeDetectorRef) {
+ private cdr: ChangeDetectorRef,
+ private helper: HelperService) {
}
ngOnInit() {
@@ -432,27 +262,25 @@ export class TerminologyComponent implements OnInit, OnDestroy {
this.breadcrumbs[0].route = '/' + (params['stakeholder']?params['stakeholder']:'');
this.breadcrumbs[0].name = (params['stakeholder']?'dashboard':'home');
}));
- this.subscriptions.push(this.route.fragment.subscribe(fragment => {
- if(fragment) {
- this.activeSection = fragment;
- } else {
- this.activeSection = 'entities';
- }
- }));
+ this.subscriptions.push(this.route.fragment.subscribe(fragment => {
+ if(fragment) {
+ this.activeSection = fragment;
+ } else {
+ this.activeSection = 'entities';
+ }
+ }));
+ this.getDivContents();
}
-
- ngAfterViewInit() {
+
+ ngAfterViewInit() {
if (typeof document !== 'undefined') {
if(this.graph_element) {
this.observeGraphElement();
}
- setTimeout(() => {
- this.setObserver();
- });
}
}
-
- ngAfterContentChecked() {
+
+ ngAfterContentChecked() {
if(this.graph_element && typeof document !== 'undefined') {
this.graph_offset = this.calcGraphOffset(this.graph_element.nativeElement);
}
@@ -464,37 +292,16 @@ export class TerminologyComponent implements OnInit, OnDestroy {
subscription.unsubscribe();
}
});
- if(this.observer) {
- this.observer.disconnect();
- }
}
-
- private setObserver() {
- if(this.observer) {
- this.observer.disconnect();
- }
- this.observer = new IntersectionObserver((entries) => {
- entries.forEach(entry => {
- if(entry.isIntersecting) {
- if(this.timeout) {
- clearTimeout(this.timeout);
- }
- this.timeout = setTimeout(() => {
- this.router.navigate(['./'], {fragment: entry.target.id, relativeTo: this.route, state: {disableScroll: true}});
- }, 200);
- }
- });
- }, {threshold: 0.25});
- this.contentSections.forEach(section => {
- let element = document.getElementById(section);
- if(element) {
- this.observer.observe(element);
- }
- });
- }
-
- public observeGraphElement() {
- let resizeObs = new ResizeObserver(entries => {
+
+ private getDivContents() {
+ this.subscriptions.push(this.helper.getDivHelpContents(this.properties, 'monitor', this.router.url).subscribe(contents => {
+ this.divContents = contents;
+ }));
+ }
+
+ public observeGraphElement() {
+ let resizeObs = new ResizeObserver(entries => {
entries.forEach(entry => {
setTimeout(() => {
this.graph_offset = this.calcGraphOffset(entry.target);
@@ -504,9 +311,9 @@ export class TerminologyComponent implements OnInit, OnDestroy {
});
this.subscriptions.push(resizeObs);
resizeObs.observe(this.graph_element.nativeElement);
- }
-
- calcGraphOffset(element) {
+ }
+
+ calcGraphOffset(element) {
this.graph_height = element.offsetHeight;
return window.innerHeight-this.graph_height;
}
diff --git a/sharedComponents/tabs/slider-tab.component.ts b/sharedComponents/tabs/slider-tab.component.ts
new file mode 100644
index 00000000..2060ccf2
--- /dev/null
+++ b/sharedComponents/tabs/slider-tab.component.ts
@@ -0,0 +1,16 @@
+import {Component, Input} from "@angular/core";
+
+@Component({
+ selector: 'slider-tab',
+ template: ``
+})
+export class SliderTabComponent {
+ @Input("tabTitle")
+ public title: string;
+ @Input("tabId")
+ public id: string;
+ @Input()
+ public active: boolean = false;
+ @Input()
+ public disabled: boolean = false;
+}
diff --git a/sharedComponents/tabs/slider-tabs.component.ts b/sharedComponents/tabs/slider-tabs.component.ts
new file mode 100644
index 00000000..d53f56cf
--- /dev/null
+++ b/sharedComponents/tabs/slider-tabs.component.ts
@@ -0,0 +1,172 @@
+import {
+ AfterViewInit,
+ ChangeDetectorRef,
+ Component,
+ ContentChildren,
+ ElementRef, EventEmitter,
+ Input, OnDestroy, Output,
+ QueryList,
+ ViewChild
+} from "@angular/core";
+import {SliderTabComponent} from "./slider-tab.component";
+import {ActivatedRoute, Router} from "@angular/router";
+import {Subscription} from "rxjs";
+import Timeout = NodeJS.Timeout;
+
+declare var UIkit;
+
+@Component({
+ selector: 'slider-tabs',
+ template: `
+
+ `,
+})
+export class SliderTabsComponent implements AfterViewInit, OnDestroy {
+ //TODO now it works only for scrollable, to be extended
+ /**
+ * Type of tabs: Static = Uikit tabs with @connect class, Dynamic = Active is defined by tabComponent.active input,
+ * Scrollable = Active is defined by the active fragment of URL and position of scroll
+ * */
+ @Input()
+ public type: 'static' | 'dynamic' | 'scrollable' = 'static';
+ /**
+ * Connect class in static type. Default: uk-switcher
+ * */
+ @Input()
+ public connect = 'uk-switcher';
+ /**
+ * Threshold between 0.0 to 1.0 for Intersection Observer
+ * */
+ @Input()
+ public scrollThreshold = 0.1;
+ /**
+ * Tabs view: Horizontal is the default.
+ * */
+ @Input()
+ public position: 'horizontal' | 'left' | 'right' = 'horizontal';
+ /**
+ * Tabs background
+ * */
+ @Input()
+ public background: string;
+ @ContentChildren(SliderTabComponent) tabs: QueryList
;
+ @ViewChild('tabsElement') tabsElement: ElementRef;
+ /**
+ * Notify regarding new active element
+ * */
+ @Output() activeEmitter: EventEmitter = new EventEmitter();
+ public init: boolean = false;
+ private subscriptions: any[] = [];
+ private observer: IntersectionObserver;
+ private timeout: Timeout;
+
+ constructor(private route: ActivatedRoute,
+ private router: Router,
+ private cdr: ChangeDetectorRef) {
+ }
+
+ ngAfterViewInit() {
+ if (typeof document !== 'undefined' && this.tabs.length > 0) {
+ setTimeout(() => {
+ if(this.position === 'horizontal') {
+ let slider = UIkit.slider(this.tabsElement.nativeElement, {finite: true});
+ slider.clsActive = 'uk-slider-active';
+ slider.updateActiveClasses();
+ this.init = true;
+ slider.slides.forEach(item => {
+ item.classList.remove('uk-active');
+ });
+ if (this.type === 'scrollable') {
+ this.scrollable(slider);
+ }
+ } else {
+ this.scrollable();
+ }
+ });
+ }
+ }
+
+ private scrollable(slider = null) {
+ this.activeFragment(this.route.snapshot.fragment, slider);
+ this.subscriptions.push(this.route.fragment.subscribe(fragment => {
+ this.activeFragment(fragment,slider);
+ }));
+ this.setObserver();
+ }
+
+ private setObserver() {
+ if (this.observer) {
+ this.observer.disconnect();
+ }
+ this.observer = new IntersectionObserver((entries) => {
+ entries.forEach(entry => {
+ if (entry.isIntersecting) {
+ if (this.timeout) {
+ clearTimeout(this.timeout);
+ }
+ this.timeout = setTimeout(() => {
+ this.router.navigate(['./'], {
+ fragment: entry.target.id,
+ relativeTo: this.route,
+ state: {disableScroll: true}
+ });
+ }, 200);
+ }
+ });
+ }, {threshold: 0.1});
+ this.tabs.forEach(tab => {
+ let element = document.getElementById(tab.id);
+ if (element) {
+ this.observer.observe(element);
+ }
+ });
+ }
+
+ private activeFragment(fragment, slider) {
+ let index = 0;
+ if (fragment) {
+ index = this.tabs.toArray().findIndex(item => item.id == fragment);
+ }
+ if(slider) {
+ slider.show(index);
+ }
+ this.tabs.forEach((tab, i) => {
+ if (index === i) {
+ tab.active = true;
+ this.activeEmitter.emit(tab.id);
+ } else {
+ tab.active = false;
+ }
+ });
+ this.cdr.detectChanges();
+ }
+
+ ngOnDestroy() {
+ this.subscriptions.forEach(subscription => {
+ if (subscription instanceof Subscription) {
+ subscription.unsubscribe();
+ }
+ });
+ if (this.observer) {
+ this.observer.disconnect();
+ }
+ }
+}
diff --git a/sharedComponents/tabs/slider-tabs.module.ts b/sharedComponents/tabs/slider-tabs.module.ts
new file mode 100644
index 00000000..4bdc8e9b
--- /dev/null
+++ b/sharedComponents/tabs/slider-tabs.module.ts
@@ -0,0 +1,13 @@
+import {NgModule} from "@angular/core";
+import {CommonModule} from "@angular/common";
+import {SliderTabsComponent} from "./slider-tabs.component";
+import {SliderTabComponent} from "./slider-tab.component";
+import {RouterModule} from "@angular/router";
+
+@NgModule({
+ imports: [CommonModule, RouterModule],
+ declarations: [SliderTabsComponent, SliderTabComponent],
+ exports: [SliderTabsComponent, SliderTabComponent]
+})
+export class SliderTabsModule {}
+