Skip to content

Commit

Permalink
Updated store, alarms and imports
Browse files Browse the repository at this point in the history
moved store and dependencies to core library, replaced alarm wrapper service with store, fixed imports
  • Loading branch information
GionaMartignani committed Jan 9, 2025
1 parent 3114051 commit 769a46a
Show file tree
Hide file tree
Showing 94 changed files with 1,553 additions and 1,745 deletions.
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import {
FormGroup
} from '@angular/forms';
import { ErrorStateMatcher } from '@angular/material/core';
import { Observable } from 'rxjs';
import { LoggerService, Logger } from 'core';
import '@angular/localize/init';

/**
* Custom provider for NG_VALUE_ACCESSOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
import { ErrorStateMatcher } from "@angular/material/core";

import { Logger, LoggerService } from "core";
import "@angular/localize/init";

/**
* Custom provider for NG_VALUE_ACCESSOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
FormGroupDirective,
NgForm,
} from "@angular/forms";
import "@angular/localize/init";

/**
* Class used to represent a select option.
Expand Down
39 changes: 39 additions & 0 deletions projects/core/src/lib/constants/http-errors-dictionary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
*
* * Copyright 2019-2023 HyperIoT
* *
* * Licensed under the Apache License, Version 2.0 (the "License")
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
*
*/

export const ErrorMessageDefault = {
title: $localize`:@@HYT_error:Error`,
body: $localize`:@@HYT_something_wrong:Something's wrong`
}

export const HttpErrorsDictionary: {
[index: number]: {
title: string,
body: string
}
} = {
401: {
title: $localize`:@@HYT_authorization_error:Athorization error`,
body: $localize`:@@HYT_you_do_not_have_sufficient_permissions_to_perform_this_operation:You do not have sufficient permissions to perform this operation`
},
403: {
title: $localize`:@@HYT_authentication_error:Authentication error`,
body: $localize`:@@HYT_you_do_not_have_sufficient_permissions_to_perform_this_operation:You do not have sufficient permissions to perform this operation`
}
};
5 changes: 5 additions & 0 deletions projects/core/src/lib/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './http-context-tokens';
export * from './http-errors-dictionary';

export const HyperiotLogoPath = 'assets/images/logo/Hyperiot-Ex_S.png';
export const HyperiotLogoMobilePath = 'assets/images/hyperiot_logo_single_char_animated.svg';

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ export namespace HytAlarm{
alarmId: number;
alarmName: string;
event: {
alarmEventId: number;
alarmEventId?: number;
alarmEventName: string;
severity: number;
alarmState: string;
lastFiredTimestamp: number;
ruleDefinition?: string;
ruleDefinition: string;
ruleId: number;
};
projectId?: number;
projectId: number;
deviceIds: number[];
packetIds?: number[];
color: {
Expand Down
2 changes: 2 additions & 0 deletions projects/core/src/lib/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './branding';
export * from './hyperiot-alarm.model';
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { UiBrandingService } from 'core';
import { lastValueFrom, Observable, tap } from 'rxjs';
import { BrandingTheme } from './models/branding';
import { Store } from '@ngrx/store';
import { BrandingActions } from 'src/app/state/branding/branding.actions';
import { BrandingSelectors } from 'src/app/state/branding/branding.selectors';
import { BrandingSelectors } from '../../store/branding/branding.selectors';
import { BrandingActions } from '../../store/branding/branding.actions';
import { BrandingTheme } from '../../models/branding';

@Injectable({
providedIn: 'root'
Expand All @@ -25,7 +24,6 @@ export class BrandingService {
}> = this.store.select(BrandingSelectors.selectThemeLogoPath);

constructor(
private uiBrandingService: UiBrandingService,
private _sanitizer: DomSanitizer,
private httpClient: HttpClient,
private store: Store
Expand Down
29 changes: 29 additions & 0 deletions projects/core/src/lib/store/branding/branding.actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createAction, props } from "@ngrx/store";
import { BrandingTheme } from "../../models/branding";
import { BrandingStore } from "./branding.reducer";

export namespace BrandingActions {
export const load = createAction('[Branding] Load');
export const updateAll = createAction(
'[Branding] Update',
props<{ brandingTheme: BrandingTheme }>()
);
export const updateLogo = createAction(
'[Branding] Update Logo',
props<{ brandingTheme: BrandingTheme }>()
);
export const updateColorSchema = createAction(
'[Branding] Update ColorScheme',
props<{ brandingTheme: BrandingTheme }>()
);
export const reset = createAction('[Branding] Reset');
export const unset = createAction('[Branding] Unset after logout');

export const loadSuccess = createAction('[Branding API] Branding Load Success', props<{ payload: BrandingStore.State }>());
export const loadFailure = createAction('[Branding API] Branding Load Error', props<{ payload: any }>());
export const updateSuccess = createAction('[Branding API] Branding Update Success', props<{ payload: BrandingStore.State }>());
export const updateFailure = createAction('[Branding API] Branding Update Error', props<{ payload: any }>());
export const resetSuccess = createAction('[Branding API] Branding Reset Success', props<{ payload: any }>());
export const resetFailure = createAction('[Branding API] Branding Reset Error', props<{ payload: any }>());

}
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Logger, LoggerService, UiBrandingService } from 'core';
import { UiBrandingService } from '../../hyperiot-client/uibranding-client/api-module';
import { of } from 'rxjs';
import { map, mergeMap, catchError, exhaustMap } from 'rxjs/operators';
import { BrandingService } from 'src/app/services/branding/branding.service';
import { BrandingActions, BrandingApiActions } from './branding.actions';
import { BrandingState } from './branding.model';
import { BrandingStore } from './branding.reducer';
import { BrandingActions } from './branding.actions';
import { BrandingService } from '../../services/branding/branding.service';

@Injectable()
export class BrandingEffects {

private logger: Logger;

load$ = createEffect(() => this.actions$.pipe(
ofType(BrandingActions.load),
mergeMap(() => this.uiBrandingService.getUIBranding()
.pipe(
map(branding => {
this.logger.debug('laod$ getUIBranding() response', branding);
const colorSchema = JSON.parse(branding.colorScheme);
const newBranding: BrandingState = {
const newBranding: BrandingStore.State = {
colorSchema,
logo: {
standard: this.brandingService.getSanitizedLogo(branding.logoBase64),
mobile: this.brandingService.getSanitizedLogo(branding.logoBase64),
},
isBrandedTheme: true
};
this.logger.debug('laod$ return payload', newBranding);
return BrandingApiActions.loadSuccess({ payload: newBranding });
return BrandingActions.loadSuccess({ payload: newBranding });
}),
catchError((err) => {
this.logger.debug('laod$ getUIBranding() catchError', err);
return of(BrandingApiActions.loadFailure({ payload: err }));
return of(BrandingActions.loadFailure({ payload: err }));
})
))
)
Expand All @@ -44,22 +39,19 @@ export class BrandingEffects {
exhaustMap(action =>
this.brandingService.updateBranding(action.brandingTheme).pipe(
map(res => {
this.logger.debug('updateAll$ updateBranding() response', res);
const colorSchema = JSON.parse(res.colorScheme)
const newBranding: BrandingState = {
const newBranding: BrandingStore.State = {
colorSchema,
logo: {
standard: res.logoBase64 ? this.brandingService.getSanitizedLogo(res.logoBase64) : action.brandingTheme.fileBase64,
mobile: res.logoBase64 ? this.brandingService.getSanitizedLogo(res.logoBase64) : action.brandingTheme.fileBase64,
},
isBrandedTheme: true
};
this.logger.debug('updateAll$ return payload', newBranding);
return BrandingApiActions.updateSuccess({ payload: newBranding });
return BrandingActions.updateSuccess({ payload: newBranding });
}),
catchError(error => {
this.logger.error('updateAll$ updateBranding() catchError', error);
return of(BrandingApiActions.updateFailure({ payload: error }));
return of(BrandingActions.updateFailure({ payload: error }));
})
)
)
Expand All @@ -72,12 +64,10 @@ export class BrandingEffects {
exhaustMap(action =>
this.brandingService.resetBranding().pipe(
map(res => {
this.logger.debug('reset$ resetBranding() response', res);
return BrandingApiActions.resetSuccess({ payload: res });
return BrandingActions.resetSuccess({ payload: res });
}),
catchError(error => {
this.logger.error('reset$ resetBranding() catchError', error);
return of(BrandingApiActions.resetFailure({ payload: error }));
return of(BrandingActions.resetFailure({ payload: error }));
})
)
)
Expand All @@ -87,10 +77,6 @@ export class BrandingEffects {
constructor(
private actions$: Actions,
private brandingService: BrandingService,
private uiBrandingService: UiBrandingService,
loggerService: LoggerService
) {
this.logger = new Logger(loggerService);
this.logger.registerClass("BrandingEffects");
}
private uiBrandingService: UiBrandingService
) { }
}
Loading

0 comments on commit 769a46a

Please sign in to comment.