- Deleted obsolete localization file for English (en-us). - Updated version number from 1.0.4 to 1.1.0 in manifests.js and manifests.json. - Added localization support for German (de-de) in a new localization file. - Removed unnecessary dependencies from manifests. - Added .gitignore to exclude build artifacts and temporary files.
73 lines
2.7 KiB
TypeScript
73 lines
2.7 KiB
TypeScript
import { ITaxonomyNavigationService } from './ITaxonomyNavigationService';
|
|
import { IMenuItem } from './IMenuItem';
|
|
import { sp } from '@pnp/sp';
|
|
import { MenuItem } from './MenuItem';
|
|
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
|
|
import SPTermStorePickerService from './SPTermStorePickerService';
|
|
import { ITerm, ITermSet } from './ISPTermStorePickerService';
|
|
import { ItemDictionary } from './ItemDictionary';
|
|
import { debugWarn } from './MegaMenuDebug';
|
|
|
|
const LOG_SOURCE: string = 'TaxonomyNavigationService';
|
|
|
|
export class TaxonomyNavigationService implements ITaxonomyNavigationService {
|
|
private _taxonomyPickerService: SPTermStorePickerService;
|
|
constructor(
|
|
private context: ApplicationCustomizerContext,
|
|
private termSetNameOrId: string,
|
|
private debug: boolean = false,
|
|
private cacheMinutes: number = 15
|
|
) {
|
|
sp.setup({
|
|
spfxContext: context
|
|
});
|
|
this._taxonomyPickerService = new SPTermStorePickerService(
|
|
{
|
|
anchorId: '',
|
|
termsetNameOrID: termSetNameOrId,
|
|
useSessionStorage: true,
|
|
hideDeprecatedTags: true,
|
|
hideTagsNotAvailableForTagging: false,
|
|
cacheMinutes: cacheMinutes
|
|
},
|
|
this.context,
|
|
this.debug
|
|
);
|
|
}
|
|
|
|
public async getMenuItems(): Promise<IMenuItem[]> {
|
|
const siteCollectionUrl: string = this.context.pageContext.site.absoluteUrl;
|
|
const termset: ITermSet = await this._taxonomyPickerService.getAllTerms(
|
|
this.termSetNameOrId,
|
|
true,
|
|
false,
|
|
true,
|
|
this.cacheMinutes
|
|
);
|
|
const itemsDict: ItemDictionary<IMenuItem> = new ItemDictionary<IMenuItem>();
|
|
const menuItems: IMenuItem[] = [];
|
|
|
|
if (!termset || !termset.Terms || termset.Terms.length === 0) {
|
|
debugWarn(this.debug, LOG_SOURCE, 'No terms found in the term set.');
|
|
throw new Error('The configured navigation term set was not found or contains no terms.');
|
|
}
|
|
|
|
termset.Terms.forEach((term: ITerm) => {
|
|
const menuItem: IMenuItem = new MenuItem(term, 0, siteCollectionUrl);
|
|
itemsDict.Add(term.Id, menuItem);
|
|
if (menuItem.pathDepth === 1) {
|
|
menuItems.push(menuItem);
|
|
} else {
|
|
const parentItem: IMenuItem = itemsDict.Get(term.ParentId);
|
|
if (parentItem) {
|
|
parentItem.items.push(menuItem);
|
|
} else {
|
|
debugWarn(this.debug, LOG_SOURCE, 'Item without parent:', term.PathOfTerm);
|
|
}
|
|
}
|
|
});
|
|
|
|
return menuItems;
|
|
}
|
|
}
|