diff --git a/docs/en/UI/Angular/Modifying-the-Menu.md b/docs/en/UI/Angular/Modifying-the-Menu.md index b0a3b760fa..c59ce0d650 100644 --- a/docs/en/UI/Angular/Modifying-the-Menu.md +++ b/docs/en/UI/Angular/Modifying-the-Menu.md @@ -88,14 +88,65 @@ function configureRoutes(routes: RoutesService) { } ``` +We can also define a group for navigation elements. It's an optional property + - **Note:** It'll also include groups that were defined at the modules + +```js +// route.provider.ts +import { RoutesService } from '@abp/ng.core'; + +function configureRoutes(routes: RoutesService) { + return () => { + routes.add([ + { + //etc.. + group: 'ModuleName::GroupName' + }, + { + path: '/your-path/child', + name: 'Your child navigation', + parentName: 'Your navigation', + requiredPolicy: 'permission key here', + order: 1, + }, + ]); + }; +} +``` + +To get the route items as grouped we can use the `groupedVisible` (or Observable one `groupedVisible$`) getter methods + - It returns `RouteGroup[]` if there is any group in the route tree, otherwise it returns `undefined` + +```js +import { ABP, RoutesService, RouteGroup } from "@abp/ng.core"; +import { Component } from "@angular/core"; + +@Component(/* component metadata */) +export class AppComponent { + visible: RouteGroup[] | undefined = this.routes.groupedVisible; + //Or + visible$:Observable[] | undefined> = this.routes.groupedVisible$; + + constructor(private routes: RoutesService) {} +} +``` + ...and then in app.module.ts... + - The `groupedVisible` method will return the `Others` group for ungrouped items, the default key is `AbpUi::OthersGroup`, we can change this `key` via the `OTHERS_GROUP` injection token ```js import { NgModule } from '@angular/core'; +import { OTHERS_GROUP } from '@abp/ng.core'; import { APP_ROUTE_PROVIDER } from './route.provider'; @NgModule({ - providers: [APP_ROUTE_PROVIDER], + providers: [ + APP_ROUTE_PROVIDER, + { + provide: OTHERS_GROUP, + useValue: 'ModuleName::MyOthersGroupKey', + }, + ], // imports, declarations, and bootstrap }) export class AppModule {} @@ -109,8 +160,9 @@ Here is what every property works as: - `requiredPolicy` is the permission key to access the page. See the [Permission Management document](./Permission-Management.md) - `order` is the order of the navigation element. "Administration" has an order of `100`, so keep that in mind when ordering top level menu items. - `iconClass` is the class of the `i` tag, which is placed to the left of the navigation label. -- `layout` defines in which layout the route will be loaded. (default: `eLayoutType.empty`) +- `layout` defines in which layout the route is loaded. (default: `eLayoutType.empty`) - `invisible` makes the item invisible in the menu. (default: `false`) +- `group` is an optional property that is used to group together related routes in an application. (type: `string`, default: `AbpUi::OthersGroup`) ### Via `routes` Property in `AppRoutingModule` diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ar.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ar.json index 4717b1fe9b..bcbab76211 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ar.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ar.json @@ -48,6 +48,7 @@ "Search": "بحث", "ItemWillBeDeletedMessageWithFormat": "سيتم حذف {0}!", "ItemWillBeDeletedMessage": "سوف يتم حذف هذا البند!", - "ManageYourAccount": "إدارة حسابك" + "ManageYourAccount": "إدارة حسابك", + "OthersGroup": "آخرون" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/cs.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/cs.json index 1fe7ea6a23..5dc41952a6 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/cs.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/cs.json @@ -48,6 +48,7 @@ "Search": "Vyhledávání", "ItemWillBeDeletedMessageWithFormat": "{0} bude smazáno!", "ItemWillBeDeletedMessage": "Tato položka bude smazána!", - "ManageYourAccount": "Spravujte svůj účet" + "ManageYourAccount": "Spravujte svůj účet", + "OthersGroup": "Jiný" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/de.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/de.json index edb4f7563a..dc99f75586 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/de.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/de.json @@ -48,6 +48,7 @@ "Search": "Suche", "ItemWillBeDeletedMessageWithFormat": "{0} wird gelöscht!", "ItemWillBeDeletedMessage": "Dieses Element wird gelöscht!", - "ManageYourAccount": "Verwalten Sie Ihr Benutzerkonto" + "ManageYourAccount": "Verwalten Sie Ihr Benutzerkonto", + "OthersGroup":"Andere" } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/el.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/el.json index 6bba8ee140..24a7642eb0 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/el.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/el.json @@ -48,6 +48,7 @@ "Search": "Αναζήτηση", "ItemWillBeDeletedMessageWithFormat": "Το {0} θα διαγραφεί", "ItemWillBeDeletedMessage": "Αυτό το στοιχείο θα διαγραφεί!", - "ManageYourAccount": "Διαχείριση Λογαριασμού" + "ManageYourAccount": "Διαχείριση Λογαριασμού", + "OthersGroup":"άλλος" } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en-GB.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en-GB.json index a26c5ddf9e..4b88af7d26 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en-GB.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en-GB.json @@ -48,6 +48,7 @@ "Search": "Search", "ItemWillBeDeletedMessageWithFormat": "{0} will be deleted!", "ItemWillBeDeletedMessage": "This item will be deleted!", - "ManageYourAccount": "Manage your account" + "ManageYourAccount": "Manage your account", + "OthersGroup": "Other" } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json index 706b4ef3cd..b97ca73d1d 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json @@ -49,6 +49,7 @@ "ItemWillBeDeletedMessageWithFormat": "{0} will be deleted!", "ItemWillBeDeletedMessage": "This item will be deleted!", "ManageYourAccount": "Manage your account", + "OthersGroup": "Other", "Today": "Today", "Apply": "Apply" } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/es.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/es.json index f2b40a785b..c28e8049bc 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/es.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/es.json @@ -48,6 +48,7 @@ "Search": "Buscar", "ItemWillBeDeletedMessageWithFormat": "{0} serán borrados!", "ItemWillBeDeletedMessage": "Este elemento será borrado", - "ManageYourAccount": "Administrar cuenta" + "ManageYourAccount": "Administrar cuenta", + "OthersGroup": "Otra" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fa.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fa.json index c2f81b9c52..4fd179573b 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fa.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fa.json @@ -48,6 +48,7 @@ "Search": "جستجو", "ItemWillBeDeletedMessageWithFormat": "{0} حذف خواهد شد!", "ItemWillBeDeletedMessage": "این مورد حذف خواهد شد!", - "ManageYourAccount": "حساب خود را مدیریت کنید" + "ManageYourAccount": "حساب خود را مدیریت کنید", + "OthersGroup": "دیگر" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fi.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fi.json index 6f8e5732be..25811c92eb 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fi.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fi.json @@ -48,6 +48,7 @@ "Search": "Hae", "ItemWillBeDeletedMessageWithFormat": "{0} poistetaan!", "ItemWillBeDeletedMessage": "Tämä kohde poistetaan!", - "ManageYourAccount": "Hallitse tiliäsi" + "ManageYourAccount": "Hallitse tiliäsi", + "OthersGroup": "Muut" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fr.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fr.json index 0fc43162b2..b850315dfe 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fr.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/fr.json @@ -48,6 +48,7 @@ "Search": "Recherche", "ItemWillBeDeletedMessageWithFormat": "{0} sera supprimé!", "ItemWillBeDeletedMessage": "Cet objet va être supprimé!", - "ManageYourAccount": "Gérer votre compte" + "ManageYourAccount": "Gérer votre compte", + "OthersGroup": "Autre" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hi.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hi.json index 2c451bc797..0a20f1dcbb 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hi.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hi.json @@ -48,6 +48,7 @@ "Search": "खोज", "ItemWillBeDeletedMessageWithFormat": "{0} हटा दिया जाएगा!", "ItemWillBeDeletedMessage": "यह आइटम हटा दिया जाएगा!", - "ManageYourAccount": "अपने खाते का प्रबंधन" + "ManageYourAccount": "अपने खाते का प्रबंधन", + "OthersGroup": "अन्य" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hr.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hr.json index 9cbef79b12..a6285a4cee 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hr.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hr.json @@ -48,6 +48,7 @@ "Search": "Pretraga", "ItemWillBeDeletedMessageWithFormat": "{0} zapis će biti obrisan!", "ItemWillBeDeletedMessage": "Ovaj zapis će biti obrisan!", - "ManageYourAccount": "Upravljaj korisničkim računom" + "ManageYourAccount": "Upravljaj korisničkim računom", + "OthersGroup": "Drugi" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hu.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hu.json index 595e2f8b62..98c0c46f54 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hu.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/hu.json @@ -48,6 +48,7 @@ "Search": "Keresés", "ItemWillBeDeletedMessageWithFormat": "{0} törlésre kerül!", "ItemWillBeDeletedMessage": "Ez az elem törlődik!", - "ManageYourAccount": "Kezelje fiókját" + "ManageYourAccount": "Kezelje fiókját", + "OthersGroup": "Egyéb" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/is.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/is.json index a931570496..12b1565c2e 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/is.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/is.json @@ -48,6 +48,7 @@ "Search": "Leita", "ItemWillBeDeletedMessageWithFormat": "{0} verður eytt!", "ItemWillBeDeletedMessage": "Þessum lið verður eytt!", - "ManageYourAccount": "Stillingar notandaaðgangs" + "ManageYourAccount": "Stillingar notandaaðgangs", + "OthersGroup": "Annað" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/it.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/it.json index 3c4328619e..f07bf67e2d 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/it.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/it.json @@ -48,6 +48,7 @@ "Search": "Ricerca", "ItemWillBeDeletedMessageWithFormat": "{0} sarà eliminato!", "ItemWillBeDeletedMessage": "Questo elemento sarà eliminato!", - "ManageYourAccount": "Gestisci il tuo account" + "ManageYourAccount": "Gestisci il tuo account", + "OthersGroup": "Altra" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/nl.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/nl.json index d23d2356b4..5875fe07b9 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/nl.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/nl.json @@ -48,6 +48,7 @@ "Search": "Zoeken", "ItemWillBeDeletedMessageWithFormat": "{0} wordt verwijderd!", "ItemWillBeDeletedMessage": "Dit item wordt verwijderd!", - "ManageYourAccount": "Beheer uw account" + "ManageYourAccount": "Beheer uw account", + "OthersGroup": "Ander" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pl-PL.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pl-PL.json index e7cd503b4f..f2b8227137 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pl-PL.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pl-PL.json @@ -48,6 +48,7 @@ "Search": "Szukaj", "ItemWillBeDeletedMessageWithFormat": "{0} zostanie usunięty!", "ItemWillBeDeletedMessage": "Ten element zostanie usunięty!", - "ManageYourAccount": "Zarządzaj kontem" + "ManageYourAccount": "Zarządzaj kontem", + "OthersGroup": "Inny" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pt-BR.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pt-BR.json index 03855ec698..928c9299fb 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pt-BR.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/pt-BR.json @@ -48,6 +48,7 @@ "Search": "Procurar", "ItemWillBeDeletedMessageWithFormat": "{0} será excluído!", "ItemWillBeDeletedMessage": "Este item será excluído!", - "ManageYourAccount": "Gerenciar sua conta" + "ManageYourAccount": "Gerenciar sua conta", + "OthersGroup": "Outra" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ro-RO.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ro-RO.json index 7064064671..544b893c39 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ro-RO.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ro-RO.json @@ -48,6 +48,7 @@ "Search": "Caută", "ItemWillBeDeletedMessageWithFormat": "{0} va fi şters!", "ItemWillBeDeletedMessage": "Acest articol va fi şters!", - "ManageYourAccount": "Administraţi-vă contul" + "ManageYourAccount": "Administraţi-vă contul", + "OthersGroup": "Alte" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ru.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ru.json index dc648a2138..66f24ca65d 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ru.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/ru.json @@ -48,6 +48,7 @@ "Search": "поиск", "ItemWillBeDeletedMessageWithFormat": "{0} будет удален!", "ItemWillBeDeletedMessage": "Этот предмет будет удален!", - "ManageYourAccount": "Настройте свой аккаунт" + "ManageYourAccount": "Настройте свой аккаунт", + "OthersGroup": "Другой" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sk.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sk.json index 59b2628310..28278f04f2 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sk.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sk.json @@ -48,6 +48,7 @@ "Search": "Hľadať", "ItemWillBeDeletedMessageWithFormat": "{0} sa vymaže!", "ItemWillBeDeletedMessage": "Táto položka bude vymazaná!", - "ManageYourAccount": "Spravovať svoje konto" + "ManageYourAccount": "Spravovať svoje konto", + "OthersGroup": "Iné" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sl.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sl.json index 7a50fbaf25..c05c1dc202 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sl.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/sl.json @@ -48,6 +48,7 @@ "Search": "Iskanje", "ItemWillBeDeletedMessageWithFormat": "{0} bo izbrisan!", "ItemWillBeDeletedMessage": "Ta element bo izbrisan!", - "ManageYourAccount": "Upravljajte svoj račun" + "ManageYourAccount": "Upravljajte svoj račun", + "OthersGroup": "Ostalo" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json index e122b9b531..9dc46b85a8 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json @@ -49,6 +49,7 @@ "ItemWillBeDeletedMessageWithFormat": "{0} silinecektir!", "ItemWillBeDeletedMessage": "Bu nesne silinecektir!", "ManageYourAccount": "Hesap yönetimi", + "OthersGroup": "Diğer", "Today": "Bugün", "Apply": "Uygula" } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/vi.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/vi.json index 4062990743..1b8bc5fb5b 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/vi.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/vi.json @@ -48,6 +48,7 @@ "Search": "Tìm kiếm", "ItemWillBeDeletedMessageWithFormat": "{0} sẽ bị xóa!", "ItemWillBeDeletedMessage": "Vật phẩm này sẽ bị xoá!", - "ManageYourAccount": "Quản lý tài khoản của bạn" + "ManageYourAccount": "Quản lý tài khoản của bạn", + "OthersGroup": "Khác" } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hans.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hans.json index 7c9d2798ff..133faa7386 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hans.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hans.json @@ -48,6 +48,7 @@ "Search": "搜索", "ItemWillBeDeletedMessageWithFormat": "{0} 将被删除!", "ItemWillBeDeletedMessage": "此项将被删除!", - "ManageYourAccount": "管理你的账户" + "ManageYourAccount": "管理你的账户", + "OthersGroup": "其他" } } diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hant.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hant.json index 449dd67480..7bac7da3b8 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hant.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/zh-Hant.json @@ -48,6 +48,7 @@ "Search": "查詢", "ItemWillBeDeletedMessageWithFormat": "{0} 將被刪除!", "ItemWillBeDeletedMessage": "此項目將被刪除!", - "ManageYourAccount": "管理個人帳號" + "ManageYourAccount": "管理個人帳號", + "OthersGroup": "其他" } } diff --git a/npm/ng-packs/packages/core/src/lib/core.module.ts b/npm/ng-packs/packages/core/src/lib/core.module.ts index 9655be6c5f..c2d497ae7b 100644 --- a/npm/ng-packs/packages/core/src/lib/core.module.ts +++ b/npm/ng-packs/packages/core/src/lib/core.module.ts @@ -24,6 +24,7 @@ import { ToInjectorPipe } from './pipes/to-injector.pipe'; import { CookieLanguageProvider } from './providers/cookie-language.provider'; import { LocaleProvider } from './providers/locale.provider'; import { LocalizationService } from './services/localization.service'; +import { OTHERS_GROUP } from './tokens'; import { localizationContributor, LOCALIZATIONS } from './tokens/localization.token'; import { CORE_OPTIONS, coreOptionsFactory } from './tokens/options.token'; import { TENANT_KEY } from './tokens/tenant-key.token'; @@ -179,6 +180,10 @@ export class CoreModule { provide: QUEUE_MANAGER, useClass: DefaultQueueManager, }, + { + provide: OTHERS_GROUP, + useValue: options.othersGroup || 'AbpUi::OthersGroup', + }, IncludeLocalizationResourcesProvider, ], }; diff --git a/npm/ng-packs/packages/core/src/lib/models/common.ts b/npm/ng-packs/packages/core/src/lib/models/common.ts index 12318357dd..7a285b4461 100644 --- a/npm/ng-packs/packages/core/src/lib/models/common.ts +++ b/npm/ng-packs/packages/core/src/lib/models/common.ts @@ -12,6 +12,7 @@ export namespace ABP { sendNullsAsQueryParam?: boolean; tenantKey?: string; localizations?: Localization[]; + othersGroup?: string; } export interface Child { @@ -70,6 +71,7 @@ export namespace ABP { path?: string; layout?: eLayoutType; iconClass?: string; + group?: string; } export interface Tab extends Nav { diff --git a/npm/ng-packs/packages/core/src/lib/services/routes.service.ts b/npm/ng-packs/packages/core/src/lib/services/routes.service.ts index 32f8b473d0..329d2a370c 100644 --- a/npm/ng-packs/packages/core/src/lib/services/routes.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/routes.service.ts @@ -1,13 +1,20 @@ import { Injectable, Injector, OnDestroy } from '@angular/core'; -import { BehaviorSubject, Observable, Subscription } from 'rxjs'; +import { BehaviorSubject, Observable, Subscription, map } from 'rxjs'; import { ABP } from '../models/common'; +import { OTHERS_GROUP } from '../tokens'; import { pushValueTo } from '../utils/array-utils'; -import { BaseTreeNode, createTreeFromList, TreeNode } from '../utils/tree-utils'; +import { + BaseTreeNode, + createTreeFromList, + TreeNode, + RouteGroup, + createGroupMap, +} from '../utils/tree-utils'; import { ConfigStateService } from './config-state.service'; import { PermissionService } from './permission.service'; // eslint-disable-next-line @typescript-eslint/ban-types -export abstract class AbstractTreeService { +export abstract class AbstractTreeService { abstract id: string; abstract parentId: string; abstract hide: (item: T) => boolean; @@ -17,6 +24,8 @@ export abstract class AbstractTreeService[]>([]); private _visible$ = new BehaviorSubject[]>([]); + protected othersGroup: string; + get flat(): T[] { return this._flat$.value; } @@ -50,6 +59,15 @@ export abstract class AbstractTreeService[]): RouteGroup[] | undefined { + const map = createGroupMap(list, this.othersGroup); + if (!map) { + return undefined; + } + + return Array.from(map, ([key, items]) => ({ group: key, items })); + } + private filterWith(setOrMap: Set | Map): T[] { return this._flat$.value.filter(item => !setOrMap.has(item[this.id])); } @@ -157,6 +175,7 @@ export abstract class AbstractNavTreeService .createOnUpdateStream(state => state) .subscribe(() => this.refresh()); this.permissionService = injector.get(PermissionService); + this.othersGroup = injector.get(OTHERS_GROUP); } protected isGranted({ requiredPolicy }: T): boolean { @@ -180,4 +199,19 @@ export abstract class AbstractNavTreeService } @Injectable({ providedIn: 'root' }) -export class RoutesService extends AbstractNavTreeService {} +export class RoutesService extends AbstractNavTreeService { + private hasPathOrChild(item: TreeNode): boolean { + return Boolean(item.path) || this.hasChildren(item.name); + } + + get groupedVisible(): RouteGroup[] | undefined { + return this.createGroupedTree(this.visible.filter(item => this.hasPathOrChild(item))); + } + + get groupedVisible$(): Observable[] | undefined> { + return this.visible$.pipe( + map(items => items.filter(item => this.hasPathOrChild(item))), + map(visible => this.createGroupedTree(visible)), + ); + } +} diff --git a/npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts index 51c81a5b3c..ab9c6a76ae 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/routes.service.spec.ts @@ -1,4 +1,4 @@ -import { Subject } from 'rxjs'; +import { Subject, lastValueFrom } from 'rxjs'; import { take } from 'rxjs/operators'; import { RoutesService } from '../services/routes.service'; import { DummyInjector } from './utils/common.utils'; @@ -10,6 +10,7 @@ export const mockRoutesService = (injectorPayload = {} as { [key: string]: any } const injector = new DummyInjector({ PermissionService: mockPermissionService(), ConfigStateService: { createOnUpdateStream: () => updateStream$ }, + OTHERS_GROUP: 'OthersGroup', ...injectorPayload, }); return new RoutesService(injector); @@ -17,6 +18,11 @@ export const mockRoutesService = (injectorPayload = {} as { [key: string]: any } describe('Routes Service', () => { let service: RoutesService; + + const fooGroup = 'FooGroup'; + const barGroup = 'BarGroup'; + const othersGroup = 'OthersGroup'; + const routes = [ { path: '/foo', name: 'foo' }, { path: '/foo/bar', name: 'bar', parentName: 'foo', invisible: true, order: 2 }, @@ -25,6 +31,14 @@ describe('Routes Service', () => { { path: '/foo/x', name: 'x', parentName: 'foo', order: 1 }, ]; + const groupedRoutes = [ + { path: '/foo', name: 'foo', group: fooGroup }, + { path: '/foo/y', name: 'y', parentName: 'foo' }, + { path: '/foo/bar', name: 'bar', group: barGroup }, + { path: '/foo/bar/baz', name: 'baz', group: barGroup }, + { path: '/foo/z', name: 'z' }, + ]; + beforeEach(() => { service = mockRoutesService(); }); @@ -33,9 +47,9 @@ describe('Routes Service', () => { it('should add given routes as flat$, tree$, and visible$', async () => { service.add(routes); - const flat = await service.flat$.pipe(take(1)).toPromise(); - const tree = await service.tree$.pipe(take(1)).toPromise(); - const visible = await service.visible$.pipe(take(1)).toPromise(); + const flat = await lastValueFrom(service.flat$.pipe(take(1))); + const tree = await lastValueFrom(service.tree$.pipe(take(1))); + const visible = await lastValueFrom(service.visible$.pipe(take(1))); expect(flat.length).toBe(5); expect(flat[0].name).toBe('baz'); @@ -59,6 +73,52 @@ describe('Routes Service', () => { }); }); + describe('#groupedVisible', () => { + it('should return undefined when there are no visible routes', async () => { + service.add(routes); + const result = await lastValueFrom(service.groupedVisible$.pipe(take(1))); + expect(result).toBeUndefined(); + }); + + it( + 'should group visible routes under "' + othersGroup + '" when no group is specified', + async () => { + service.add([ + { path: '/foo', name: 'foo' }, + { path: '/foo/bar', name: 'bar', group: '' }, + { path: '/foo/bar/baz', name: 'baz', group: undefined }, + { path: '/x', name: 'y', group: 'z' }, + ]); + + const result = await lastValueFrom(service.groupedVisible$.pipe(take(1))); + + expect(result[0].group).toBe(othersGroup); + expect(result[0].items[0].name).toBe('foo'); + expect(result[0].items[1].name).toBe('bar'); + expect(result[0].items[2].name).toBe('baz'); + }, + ); + + it('should return grouped route list', async () => { + service.add(groupedRoutes); + + const tree = await lastValueFrom(service.groupedVisible$.pipe(take(1))); + + expect(tree.length).toBe(3); + + expect(tree[0].group).toBe('FooGroup'); + expect(tree[0].items[0].name).toBe('foo'); + expect(tree[0].items[0].children[0].name).toBe('y'); + + expect(tree[1].group).toBe('BarGroup'); + expect(tree[1].items[0].name).toBe('bar'); + expect(tree[1].items[1].name).toBe('baz'); + + expect(tree[2].group).toBe(othersGroup); + expect(tree[2].items[0].name).toBe('z'); + }); + }); + describe('#find', () => { it('should return node found based on query', () => { service.add(routes); diff --git a/npm/ng-packs/packages/core/src/lib/tests/utils/common.utils.ts b/npm/ng-packs/packages/core/src/lib/tests/utils/common.utils.ts index e568b63a17..01612a987e 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/utils/common.utils.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/utils/common.utils.ts @@ -14,6 +14,6 @@ export class DummyInjector extends Injector { ): T; get(token: any, notFoundValue?: any): any; get(token, notFoundValue?, flags?: InjectFlags): any { - return this.payload[token.name || token]; + return this.payload[token.name || token._desc || token]; } } diff --git a/npm/ng-packs/packages/core/src/lib/tokens/index.ts b/npm/ng-packs/packages/core/src/lib/tokens/index.ts index f0e724259a..d01f652b98 100644 --- a/npm/ng-packs/packages/core/src/lib/tokens/index.ts +++ b/npm/ng-packs/packages/core/src/lib/tokens/index.ts @@ -12,3 +12,4 @@ export * from './pipe-to-login.token'; export * from './set-token-response-to-storage.token'; export * from './check-authentication-state'; export * from './http-context.token'; +export * from './others-group.token' \ No newline at end of file diff --git a/npm/ng-packs/packages/core/src/lib/tokens/others-group.token.ts b/npm/ng-packs/packages/core/src/lib/tokens/others-group.token.ts new file mode 100644 index 0000000000..23d7d65b92 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/tokens/others-group.token.ts @@ -0,0 +1,3 @@ +import { InjectionToken } from '@angular/core'; + +export const OTHERS_GROUP = new InjectionToken('OTHERS_GROUP'); diff --git a/npm/ng-packs/packages/core/src/lib/utils/tree-utils.ts b/npm/ng-packs/packages/core/src/lib/utils/tree-utils.ts index bfc938c158..8ea8cc504c 100644 --- a/npm/ng-packs/packages/core/src/lib/utils/tree-utils.ts +++ b/npm/ng-packs/packages/core/src/lib/utils/tree-utils.ts @@ -1,3 +1,5 @@ +import { isArray } from './common-utils'; + /* eslint-disable @typescript-eslint/ban-types */ export class BaseTreeNode { children: TreeNode[] = []; @@ -74,6 +76,28 @@ export function createTreeNodeFilterCreator( }; } +export function createGroupMap( + list: TreeNode[], + othersGroupKey: string, +) { + if (!isArray(list) || !list.some(node => Boolean(node.group))) return undefined; + + const mapGroup = new Map[]>(); + + for (const node of list) { + const group = node?.group || othersGroupKey; + if (typeof group !== 'string') { + throw new Error(`Invalid group: ${group}`); + } + + const items = mapGroup.get(group) || []; + items.push(node); + mapGroup.set(group, items); + } + + return mapGroup; +} + export type TreeNode = { [K in keyof T]: T[K]; } & { @@ -82,6 +106,11 @@ export type TreeNode = { parent?: TreeNode; }; +export type RouteGroup = { + readonly group: string; + readonly items: TreeNode[]; +}; + export type NodeKey = number | string | symbol | undefined | null; export type NodeValue any> = F extends undefined