- Updated TaxonomyNavigationService to set hideTagsNotAvailableForTagging to true. - Modified getAllTerms call to include the updated parameter for hiding unavailable tags. - Removed external CSS loading functionality from MegaMenuApplicationCustomizer. - Updated cache prefixes in SPTermStorePickerService for versioning. - Bumped version in package.json and package-lock.json to 1.1.2. - Updated deployment manifest files to reflect the new version.
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: true,
|
|
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,
|
|
true,
|
|
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;
|
|
}
|
|
}
|