diff --git a/src/app/reducers/volumes/redux/volumes.reducers.ts b/src/app/reducers/volumes/redux/volumes.reducers.ts index f76b42f023..e3170cf45f 100644 --- a/src/app/reducers/volumes/redux/volumes.reducers.ts +++ b/src/app/reducers/volumes/redux/volumes.reducers.ts @@ -1,7 +1,7 @@ import { createFeatureSelector, createSelector } from '@ngrx/store'; import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity'; import { Snapshot } from '../../../shared/models'; -import { Volume } from '../../../shared/models/volume.model'; +import { Volume, VolumeType } from '../../../shared/models/volume.model'; import { Utils } from '../../../shared/services/utils/utils.service'; import { getDescription } from '../../../shared/models'; @@ -44,6 +44,24 @@ export const volumeReducers = { form: formReducer }; +const sortByGroups = (a: Volume, b: Volume) => { + const aIsRoot = a.type === VolumeType.ROOT; + const bIsRoot = b.type === VolumeType.ROOT; + if (aIsRoot && bIsRoot) { + return a.name.localeCompare(b.name); + } + if (!aIsRoot && !bIsRoot) { + return a.name.localeCompare(b.name); + } + if (aIsRoot && !bIsRoot) { + return -1; + } + if (!aIsRoot && bIsRoot) { + return 1; + } + return 0; +}; + /** * createEntityAdapter creates many an object of helper * functions for single or multiple operations @@ -54,7 +72,7 @@ export const volumeReducers = { */ export const adapter: EntityAdapter = createEntityAdapter({ selectId: (item: Volume) => item.id, - sortComparer: Utils.sortByName + sortComparer: sortByGroups }); /** getInitialState returns the default initial state diff --git a/src/app/shared/components/grouped-list/grouped-list.component.ts b/src/app/shared/components/grouped-list/grouped-list.component.ts index 9c44673a30..ad92937b08 100644 --- a/src/app/shared/components/grouped-list/grouped-list.component.ts +++ b/src/app/shared/components/grouped-list/grouped-list.component.ts @@ -1,7 +1,6 @@ import { Component, Input, OnChanges, Type } from '@angular/core'; -import { Grouping } from '../../models/grouping.model'; import { BaseModelInterface } from '../../models/base.model'; - +import { Grouping } from '../../models/grouping.model'; import * as groupBy from 'lodash/groupBy'; @Component({ @@ -19,7 +18,7 @@ export class GroupedListComponent implements OnChanges { public tree: Array<{ items?, name? }>; - ngOnChanges(changes): void { + public ngOnChanges(changes): void { this.updateTree(); } diff --git a/src/app/volume/volume-list/volume-grouped-list.component.ts b/src/app/volume/volume-list/volume-grouped-list.component.ts new file mode 100644 index 0000000000..dbb7fd1bfe --- /dev/null +++ b/src/app/volume/volume-list/volume-grouped-list.component.ts @@ -0,0 +1,42 @@ +import { Component } from '@angular/core'; +import { GroupedListComponent } from '../../shared/components/grouped-list/grouped-list.component'; +import { volumeTypeNames } from '../../shared/models'; + +@Component({ + selector: 'cs-volume-grouped-list', + template: ` + +
+

{{ child.name | translate }}

+ +
+ + + + + +
+ `, + styleUrls: ['../../shared/components/grouped-list/grouped-list.component.scss'] +}) +export class VolumeGroupedListComponent extends GroupedListComponent { + protected sortGroups(group1, group2) { + return group1.name === volumeTypeNames['ROOT'] + ? -1 + : group1.name === volumeTypeNames['DATADISK'] + ? 1 + : group1.name.localeCompare(group2.name); + } +} diff --git a/src/app/volume/volume-list/volume-list.component.html b/src/app/volume/volume-list/volume-list.component.html index 7b074387de..4f520abcd2 100644 --- a/src/app/volume/volume-list/volume-list.component.html +++ b/src/app/volume/volume-list/volume-list.component.html @@ -1,4 +1,4 @@ - - + diff --git a/src/app/volume/volume.module.ts b/src/app/volume/volume.module.ts index 1b12abe634..008c4206cd 100644 --- a/src/app/volume/volume.module.ts +++ b/src/app/volume/volume.module.ts @@ -60,6 +60,7 @@ import { userAccountReducers } from '../reducers/auth/redux/auth.reducers'; import { UserAccountEffects } from '../reducers/auth/redux/auth.effects'; import { VolumeSnapshotDetailsContainerComponent } from './container/volume-snapshot-details.container'; import { virtualMachineReducers } from '../reducers/vm/redux/vm.reducers'; +import { VolumeGroupedListComponent } from './volume-list/volume-grouped-list.component'; @NgModule({ @@ -116,7 +117,8 @@ import { virtualMachineReducers } from '../reducers/vm/redux/vm.reducers'; VolumeCreationDialogComponent, VolumeCardItemComponent, VolumeRowItemComponent, - VolumeListComponent + VolumeListComponent, + VolumeGroupedListComponent ], exports: [ VolumePageComponent