Skip to content

Commit

Permalink
fixed connection state widget and added filter for unknown connection…
Browse files Browse the repository at this point in the history
…; fix #SNRGY-3030
  • Loading branch information
hahahannes committed Dec 18, 2023
1 parent 7f7b358 commit adb0da3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import { SearchbarService } from 'src/app/core/components/searchbar/shared/searc
import { DeviceInstancesFilterDialogComponent } from './dialogs/device-instances-filter-dialog/device-instances-filter-dialog.component';
import { MatDialog } from '@angular/material/dialog';
import { ExportDataService } from 'src/app/widgets/shared/export-data.service';

export interface DeviceInstancesRouterState {
type: DeviceInstancesRouterStateTypesEnum | undefined | null;
tab: DeviceInstancesRouterStateTabEnum | undefined | null;
value: any;
}

Expand All @@ -50,7 +50,8 @@ export enum DeviceInstancesRouterStateTypesEnum {
NETWORK,
DEVICE_TYPE,
LOCATION,
DEVICE_GROUP
DEVICE_GROUP,
CONNECTION_STATE
}

// eslint-disable-next-line no-shadow
Expand Down Expand Up @@ -102,7 +103,7 @@ export class DeviceInstancesComponent implements OnInit, AfterViewInit {
routerDeviceType: string[] | undefined = undefined;
routerLocation: string | undefined = undefined;
routerDeviceIds: string[] | undefined = undefined;
routerConnectionState: boolean | undefined = undefined;
routerConnectionState: DeviceInstancesRouterStateTabEnum | undefined = undefined;

private searchSub: Subscription = new Subscription();
sortBy: string = "display_name"
Expand Down Expand Up @@ -304,6 +305,8 @@ export class DeviceInstancesComponent implements OnInit, AfterViewInit {
case DeviceInstancesRouterStateTypesEnum.DEVICE_GROUP:
this.routerDeviceIds = state.value as string[];
break;
case DeviceInstancesRouterStateTypesEnum.CONNECTION_STATE:
this.routerConnectionState = state.value
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LocationModel } from '../../../locations/shared/locations.model';
import { LocationsService } from '../../../locations/shared/locations.service';
import { NetworksModel } from '../../../networks/shared/networks.model';
import { NetworksService } from '../../../networks/shared/networks.service';
import { DeviceInstancesRouterStateTabEnum } from '../../device-instances.component';
import { DeviceConnectionState, FilterSelection } from '../../shared/device-instances.model';
import { DeviceInstancesService } from '../../shared/device-instances.service';

Expand All @@ -22,13 +23,17 @@ export class DeviceInstancesFilterDialogComponent implements OnInit {
locationOptions: LocationModel[] = [];
networkOptions: NetworksModel[] = [];
deviceTypeOptions: DeviceTypeBaseModel[] = [];
connectionOptions: DeviceConnectionState[] = [{"name": "connected", "value": true}, {"name": "unconnected", "value": false}]
connectionOptions: DeviceConnectionState[] = [
{"name": "connected", "value": DeviceInstancesRouterStateTabEnum.ONLINE},
{"name": "unconnected", "value": DeviceInstancesRouterStateTabEnum.OFFLINE},
{"name": "unknown", "value": DeviceInstancesRouterStateTabEnum.UNKNOWN}
]

form = new FormGroup({
location: new FormControl<string|undefined>(undefined),
network: new FormControl<string|undefined>(undefined),
deviceTypes: new FormControl<string[]>([]),
connectionState: new FormControl<boolean|undefined>(undefined),
connectionState: new FormControl<DeviceInstancesRouterStateTabEnum|undefined>(DeviceInstancesRouterStateTabEnum.ALL),
});

savedFilterSelection!: FilterSelection | undefined
Expand Down Expand Up @@ -107,7 +112,7 @@ export class DeviceInstancesFilterDialogComponent implements OnInit {
}

resetConnectionFilter() {
this.form.controls.connectionState.patchValue(undefined)
this.form.controls.connectionState.patchValue(DeviceInstancesRouterStateTabEnum.ALL)
}

resetLocationFilter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { DeviceTypePermSearchModel, PermissionsModel } from '../../../metadata/d
import { DeviceTypeServiceModel } from '../../../metadata/device-types-overview/shared/device-type.model';
import { ImportInstancesModel } from '../../../imports/import-instances/shared/import-instances.model';
import { ImportTypeModel } from '../../../imports/import-types/shared/import-types.model';
import { DeviceInstancesRouterStateTabEnum } from '../device-instances.component';

export interface Attribute {
key: string;
Expand Down Expand Up @@ -85,7 +86,7 @@ export interface DeviceSelectablesFullModel {
}

export interface DeviceConnectionState {
value: boolean;
value: DeviceInstancesRouterStateTabEnum;
name: string;
}

Expand All @@ -96,8 +97,8 @@ export interface SelectedTag {
}

export interface FilterSelection {
connectionState: boolean | undefined;
deviceTypes: string[] | undefined;
location: string | undefined;
network: string | undefined;
connectionState?: DeviceInstancesRouterStateTabEnum;
deviceTypes?: string[];
location?: string;
network?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { DeviceTypePermSearchModel } from 'src/app/modules/metadata/device-types
import { PermissionQueryRequest, Selection } from 'src/app/core/model/permissions/permissions';
import { LocationsService } from '../../locations/shared/locations.service';
import { NetworksService } from '../../networks/shared/networks.service';
import { DeviceInstancesRouterStateTabEnum } from '../device-instances.component';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -186,7 +187,7 @@ export class DeviceInstancesService {
sortDesc: boolean = false,
searchText?: string,
deviceTypeIds?: string[],
connectionState?: boolean,
connectionState?: DeviceInstancesRouterStateTabEnum,
deviceIds?: string[],
): Observable<DeviceInstancesTotalModel> {
var queryRequest: PermissionQueryRequest = {
Expand All @@ -199,23 +200,42 @@ export class DeviceInstancesService {
sort_by: sortBy,
}
}

var optionalFilters: Selection[] = []
var optionalNotFilter: Selection = {"not": {}}

if(searchText != null) {
if(searchText != null && searchText != "") {
if(queryRequest.find) {
queryRequest.find.search = searchText
}
}

if(connectionState != null) {
optionalFilters.push(
{
condition: {
feature: 'annotations.connected', operation: '==', value: connectionState
if(connectionState == DeviceInstancesRouterStateTabEnum.ONLINE) {
optionalFilters.push(
{
condition: {
feature: 'annotations.connected', operation: '==', value: true
}
}
)
} else if(connectionState == DeviceInstancesRouterStateTabEnum.OFFLINE) {
optionalFilters.push(
{
condition: {
feature: 'annotations.connected', operation: '==', value: false
}
}
)
} else if(connectionState == DeviceInstancesRouterStateTabEnum.UNKNOWN) {
// filter for unknown connection state
optionalNotFilter.not!.condition = {
feature: 'annotations.connected', operation: "any_value_in_feature", value: [true, false]
}
)
}
optionalFilters.push(optionalNotFilter)
}

}

if(deviceTypeIds != null && deviceTypeIds.length > 0) {
optionalFilters.push(
Expand All @@ -240,6 +260,7 @@ export class DeviceInstancesService {
if(optionalFilters.length > 0 && queryRequest.find) {
queryRequest.find.filter = {"and": optionalFilters}
}

return this.queryPermissionSearch(queryRequest).pipe(
map((resp) => <DeviceInstancesPermSearchTotalModel>resp || []),
concatMap(result => {
Expand All @@ -265,7 +286,7 @@ export class DeviceInstancesService {
locationId?: string,
hubId?: string,
deviceTypeIds?: string[],
connectionState?: boolean,
connectionState?: DeviceInstancesRouterStateTabEnum,
): Observable<DeviceInstancesTotalModel> {
if(hubId != null || locationId != null) {
return this.getDeviceIds(hubId, locationId).pipe(
Expand Down Expand Up @@ -296,7 +317,7 @@ export class DeviceInstancesService {
locationId?: string,
hubId?: string,
deviceTypeIds?: string[],
connectionState?: boolean,
connectionState?: DeviceInstancesRouterStateTabEnum,
): Observable<DeviceInstancesTotalModel> {
return this.loadDeviceInstances(limit, offset, sortBy, sortDesc, searchText, locationId, hubId, deviceTypeIds, connectionState)
}
Expand All @@ -310,7 +331,7 @@ export class DeviceInstancesService {
locationId?: string,
hubId?: string,
deviceTypeIds?: string[],
connectionState?: boolean,
connectionState?: DeviceInstancesRouterStateTabEnum,
): Observable<DeviceInstancesModel[]> {
return this.loadDeviceInstances(limit, offset, sortBy, sortDesc, searchText, locationId, hubId, deviceTypeIds, connectionState).pipe(
map((result) => result.result)
Expand Down
8 changes: 4 additions & 4 deletions src/app/widgets/devices-state/devices-state.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DevicesStateModel } from './shared/devices-state.model';
import { DashboardService } from '../../modules/dashboard/shared/dashboard.service';
import { Subscription } from 'rxjs';
import { Router } from '@angular/router';
import { DeviceInstancesRouterState, DeviceInstancesRouterStateTabEnum } from 'src/app/modules/devices/device-instances/device-instances.component';
import { DeviceInstancesRouterState, DeviceInstancesRouterStateTabEnum, DeviceInstancesRouterStateTypesEnum } from 'src/app/modules/devices/device-instances/device-instances.component';

@Component({
selector: 'senergy-devices-state',
Expand Down Expand Up @@ -73,21 +73,21 @@ export class DevicesStateComponent implements OnInit, OnDestroy {

showOnlineDevices() {
this.router.navigate(['devices/deviceinstances'], {
state: { tab: DeviceInstancesRouterStateTabEnum.ONLINE } as DeviceInstancesRouterState,
state: { type: DeviceInstancesRouterStateTypesEnum.CONNECTION_STATE, value: DeviceInstancesRouterStateTabEnum.ONLINE } as DeviceInstancesRouterState,
});
return false;
}

showOfflineDevices() {
this.router.navigate(['devices/deviceinstances'], {
state: { tab: DeviceInstancesRouterStateTabEnum.OFFLINE } as DeviceInstancesRouterState,
state: { type: DeviceInstancesRouterStateTypesEnum.CONNECTION_STATE, value: DeviceInstancesRouterStateTabEnum.OFFLINE } as DeviceInstancesRouterState,
});
return false;
}

showUnknownDevices() {
this.router.navigate(['devices/deviceinstances'], {
state: { tab: DeviceInstancesRouterStateTabEnum.UNKNOWN } as DeviceInstancesRouterState,
state: { type: DeviceInstancesRouterStateTypesEnum.CONNECTION_STATE, value: DeviceInstancesRouterStateTabEnum.UNKNOWN } as DeviceInstancesRouterState,
});
return false;
}
Expand Down

0 comments on commit adb0da3

Please sign in to comment.