Skip to content

Commit

Permalink
[Dashboard] Load Navigation Groups from externel module (#4479)
Browse files Browse the repository at this point in the history
* add: navigation-groups extensionpoint and handler

* fix: corrected the group uri
  • Loading branch information
Mrgoblings authored Nov 29, 2024
1 parent e7566bc commit 4651e0a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { extensions } from "sdk/extensions";
import { response } from "sdk/http";

const groupList = [];
const groupExtensions = extensions.getExtensions("dashboard-navigation-groups");

for (let i = 0; i < groupExtensions.length; i++) {
const extensionPath = groupExtensions[i];

let path = `../../../${extensionPath}`;

const { getGroup } = await import(path);

try {
const group = getGroup();
groupList.push(group);
} catch (err) {
console.error(err)
}
}

response.println(JSON.stringify(groupList));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "dashboard-navigation-groups",
"description": "ExtensionPoint For the Navigation Groups"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,81 @@ navigation.controller("LaunchpadViewController", ["$scope", "messageHub", "$http

$scope.extraExtensionPoints = ['app', "dashboard-navigations", "dashboard-widgets"];
$scope.groups = [];

$scope.switchView = function (id, event) {
if (event) event.stopPropagation();
$scope.currentViewId = id;
};

$scope.isGroupVisible = function (group) {
const items = $scope.groupItems[group.label.toLowerCase()];
return items.some(function (item) {
return $scope.currentViewId === item.id;
});
};

messageHub.onDidReceiveMessage('launchpad.switch.perspective', function (msg) {
$scope.$apply(function () {
$scope.switchView(msg.data.viewId);
});
}, true)

$scope.groupItems = [];
$scope.groupItems['assets'] = [];
$scope.groupItems["purchasing"] = [];
$scope.groupItems["sales"] = [];
$scope.groupItems["inventory"] = [];
$scope.groupItems["reports"] = [];
$scope.groupItems["products"] = [];
$scope.groupItems["employees"] = [];
$scope.groupItems["partners"] = [];
$scope.groupItems["configurations"] = [];


$scope.groups = [
{ "label": "Assets", "icon": "it-host" },
{ "label": "Purchasing", "icon": "credit-card" },
{ "label": "Sales", "icon": "currency" },
{ "label": "Inventory", "icon": "retail-store" },
{ "label": "Reports", "icon": "area-chart" },
{ "label": "Products", "icon": "product" },
{ "label": "Employees", "icon": "company-view" },
{ "label": "Partners", "icon": "customer-and-contacts" },
{ "label": "Configurations", "icon": "wrench" }
]
function loadNavigationGroups() {
return $http.get("/services/js/portal/api/NavigationGroupsExtension/NavigationGroupsService.js")
.then(function (response) {
$scope.groups = response.data;

$http.get("/services/js/portal/api/NavigationExtension/NavigationService.js")
.then(function (response) {
$scope.navigationList = response.data;
response.data.forEach(elem => {
$scope.groupItems[elem.label.toLowerCase()] = [];
});
})
.catch(function (error) {
console.error('Error fetching navigation groups:', error);
$scope.state = { error: true, errorMessage: 'Failed to load navigation groups' };
return async () => { };
});
}

$scope.navigationList.forEach(e => addNavigationItem(e));
function loadNavigationItems() {
return $http.get("/services/js/portal/api/NavigationExtension/NavigationService.js")
.then(function (response) {
$scope.navigationList = response.data;

$scope.groupItems.forEach(e => e.sort((a, b) => a.order - b.order));
$scope.navigationList.forEach(e => addNavigationItem(e));

})
.catch(function (error) {
console.error('Error fetching navigation list:', error);
$scope.state.error = true;
$scope.errorMessage = 'Failed to load navigation list';
});
Object.values($scope.groupItems).forEach(items => {
items.sort((a, b) => a.order - b.order);
});
})
.catch(function (error) {
console.error('Error fetching navigation items:', error);
$scope.state = { error: true, errorMessage: 'Failed to load navigation items' };
});
}

function addNavigationItem(itemData) {
if (!itemData || !itemData.label || !itemData.group || !itemData.order || !itemData.link) {
console.error('Invalid item data:', itemData);
return;
}

itemData.group = itemData.group.toLowerCase();
if (!$scope.groupItems[itemData.group]) {
console.error('Group key not found:', itemData.group);
const groupKey = itemData.group.toLowerCase();
if (!$scope.groupItems[groupKey]) {
console.error('Group key not found:', groupKey);
return;
}

$scope.groupItems[itemData.group].push({
"id": itemData.id,
"label": itemData.label,
"link": itemData.link
$scope.groupItems[groupKey].push({
id: itemData.id,
label: itemData.label,
link: itemData.link
});
}

loadNavigationGroups()
.then(loadNavigationItems)
.catch(function (error) {
console.error('Error during initialization:', error);
});

$scope.switchView = function (id, event) {
if (event) event.stopPropagation();
$scope.currentViewId = id;
};

$scope.isGroupVisible = function (group) {
const items = $scope.groupItems[group.label.toLowerCase()];
return items.some(function (item) {
return $scope.currentViewId === item.id;
});
};

messageHub.onDidReceiveMessage('launchpad.switch.perspective', function (msg) {
$scope.$apply(function () {
$scope.switchView(msg.data.viewId);
});
}, true)
}]);

0 comments on commit 4651e0a

Please sign in to comment.