On Cumulocity v.10.15, we developed a custom Navigator Service, to replace the Cockpit’s default left Nav-column. This is mainly to have a nav-column with filtered items, expanded groups and customized groups icons. The column is perfectly visible, except after login, only the “Home” tab is visible and the rest of the column disappears. After refreshing, the column would be visible once again.
We are providing a CustomNavigationService in the NgModule, which fetches all assets groups and filter all items, then adds filtered items and groups as items. Groups are added with all properties, and functionality works well.
No errors are thrown at both scenarios. Trying to delay the adding of all items to the navigator items until groups are fetched didn’t fix the issue, and still only the “Home” tab would appear alone.
Nav-column after login:
Nav-column after refresh:
Custom Navigator Service code:
@Injectable()
export class CustomNavigationService extends NavigatorService {
/**
* contains all of the downloaded groups
*/
groups: {managedObjects: any[]};
constructor(rootInjector: Injector, router: Router, private fetchClient: FetchClient) {
super(rootInjector, router);
this.fetchGroups();
//setTimeout(() => {
this.items$ = this.items$.pipe(map((items) => {
// filters unwanted menu items
let filteredItems = items.filter(item =>
item.label !== 'Alarms'
&& item.label !== 'Groups'
&& item.label !== 'Reports'
&& item.label !== 'Data explorer'
&& item.label !== 'Configuration');
if (isArray(this.groups?.managedObjects)) {
// adds new items to the menu based on the downloaded groups
filteredItems.push(...this.groups?.managedObjects?.map(group => {
return {
label: group.name,
path: 'group/' + group.id,
icon: 'group',
children: group.childAssets.references.map(device => { // creates children menu items based on the gruops devices
return {
label: device.managedObject.name,
path: 'device/' + device.managedObject.id,
open: false,
routerLinkExact: false,
children: [],
destroy() {
},
openOnStart(url: string): boolean {
return false;
},
click() {
router.navigate(['device', device.managedObject.id])
},
find() {
}
}
}),
open: true,
routerLinkExact: false,
openOnStart(url: string): boolean {
return true;
},
click(options?: ClickOptions) {
// this.open = true;
router.navigate(['group', group.id]);
},
find(predicate: any, findBy?: keyof Pick<NavigatorNode, "label" | "featureId">): any {
}
} as AssetNode
}));
}
return filteredItems;
}));
//}, 5000);
}
/**
* downloads all of the gruops from the backend and puts them into the 'groups' field
*/
async fetchGroups() {
this.groups = await (await this.fetchClient.fetch('/inventory/managedObjects/', {
params: {
pageSize: 2000,
withTotalPages: true,
query: 'has(c8y_IsDeviceGroup)'
}
})).json();
};
}