Page MenuHomec4science

navigation-service.service.ts
No OneTemporary

File Metadata

Created
Sat, May 18, 00:08

navigation-service.service.ts

import {EventEmitter, Injectable} from '@angular/core';
import {NavigationEntity, TlnEntity, TlnQueryParams, ApiDef, NavTreeDef
} from '../models/models';
import * as _ from 'lodash';
@Injectable()
export class NavigationServiceService {
navigationTreeDefs: NavTreeDef[] = [
{
id: 0,
isActive: true,
label: 'Manuskripte',
qParam: 'man',
description: '',
entries: [],
apiDef: {
type: 0, // rdf
baseUrl: 'http://fuseki.nie-ine.ch/nietzsche-rw/query',
dataArray: 'results.bindings',
query: 'manuscripts.rq',
mapping: { // maps the properties of the reponse to tha NavTabDef properties, which are displayed
id: 'manuscript.value', // Short id, iri in most cases
iri: 'manuscript.value', // iri
type: 'type.value',
label: 'title.value',
}
}
}, {
id: 1,
isActive: false,
label: 'Seiten',
qParam: 'page',
description: '',
entries: [],
apiDef: {
type: 0, // rdf
baseUrl: 'http://fuseki.nie-ine.ch/nietzsche-rw/query',
dataArray: 'results.bindings',
query: 'getPageData.rq',
mapping: {
id: 'page.value', // Short id, iri in most cases
iri: 'page.value', // iri
label: 'pageNumber.value',
thumb: 'thumb.value',
idx: 'pageNumber.value'
}
}
}
];
}
export class NavTree {
id: number;
label: string;
entries: NavigationEntity[];
description?: string;
apiDef?: ApiDef;
isActive?: boolean;
selectedItem?: string;
selectedItemSet: EventEmitter<SelectedItem>
constructor(id: number, label: string, entries: NavigationEntity[], description?: string, apiDef?: ApiDef, isActive?: boolean, selectedItem?: string ) {
this.id = id;
this.label = label;
this.entries = entries || [];
this.description = description;
this.apiDef = apiDef;
this.isActive = isActive;
this.selectedItem = selectedItem;
this.selectedItemSet = new EventEmitter();
}
setNavTreeData(data: any) {
this.setSelectedItemIfNone(_.get(data[0], this.apiDef.mapping.id));
this.entries = []; // resetting tree data of the given tab
data.forEach((entry, index) => {
// (id: string, iri: string, type: string, navIndex: number, label?: string)
const entity = new TlnEntity(_.get(entry, this.apiDef.mapping.id),
_.get(entry, this.apiDef.mapping.iri), _.get(entry, this.apiDef.mapping.type) ||
null, index , _.get(entry, this.apiDef.mapping.label) || '');
const thumb = _.get(entry, this.apiDef.mapping.thumb);
const navEntity = new NavigationEntity(index, entity, thumb);
this.entries.push(navEntity);
});
}
setSelectedItemIfNone(itemId?: string) {
if (!this.selectedItem) { this.selectedItem = itemId; }
this.selectedItemSet.emit({tabId: this.id, item: itemId});
}
}
export interface SelectedItem {
tabId: number;
item: string;
}

Event Timeline