Skip to content
Snippets Groups Projects
Commit ee9d093f authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

update state

parent 9b9ff78c
No related branches found
No related tags found
2 merge requests!353Production Release,!329Dynamic compare - control panel
......@@ -13,34 +13,36 @@ import {NshmpPlot} from 'projects/plot-lib/src/lib/models/nshmp-plot.model';
/**
* Application NGRX actions
*/
export const actions = createActionGroup({
export const appActions = createActionGroup({
events: {
/** Action for available NSHMs */
availableModels: props<{models: Parameter[]}>(),
'Available Models': props<{models: Parameter[]}>(),
/** Action for calling services */
callServices: emptyProps(),
'Call Services': emptyProps(),
/** Application init action */
init: emptyProps(),
/** Action for NSHM metadata */
nshmServices: props<{nshmServices: NshmMetadata[]}>(),
'nshm Services': props<{nshmServices: NshmMetadata[]}>(),
/** Redraw plots action */
plotRedraw: emptyProps(),
'Plot Redraw': emptyProps(),
/** Action to set the plots */
plots: props<{plots: Map<string, NshmpPlot>}>(),
/** Reset the control panel action */
resetControlPanel: emptyProps(),
'Reset Control Panel': emptyProps(),
/** Reset the application settings action */
resetSettings: emptyProps(),
'Reset Settings': emptyProps(),
/** Set the response spectra data action */
responseSpectra: props<{responseSpectra: ResponseSpectra[]}>(),
'Response Spectra': props<{responseSpectra: ResponseSpectra[]}>(),
/** Set the service call info action */
serviceCallInfo: props<{serviceCallInfo: ServiceCallInfo}>(),
'Service Call Info': props<{serviceCallInfo: ServiceCallInfo}>(),
/** Set the service response action */
serviceResponses: props<{serviceResponses: HazardCalcResponse[]}>(),
'Service Responses': props<{serviceResponses: HazardCalcResponse[]}>(),
/** Set the site location action */
setLocation: props<{location: Location}>(),
'Set Location': props<{location: Location}>(),
/** Set the usage responses action */
usageResponses: props<{usageResponses: Map<string, HazardUsageResponse>}>(),
'Usage Responses': props<{
usageResponses: Map<string, HazardUsageResponse>;
}>(),
},
source: 'Development Dynamic Hazard',
});
import {Injectable} from '@angular/core';
import {Store, select} from '@ngrx/store';
import {FormGroupState} from 'ngrx-forms';
import {Observable} from 'rxjs';
import {Location} from '@ghsc/nshmp-web-utils/libs/nshmp-lib/geo';
import {ControlForm} from './app.state';
import {appFeature} from './app.reducer';
import {appActions} from './app.actions';
import {HazardUsageResponse} from '@ghsc/nshmp-web-utils/libs/nshmp-haz/www/hazard-service';
@Injectable({
providedIn: 'root',
})
export class AppFacade {
constructor() {}
constructor(private store: Store) {}
/**
* Returns the control panel form state.
*/
get controlPanelForm$(): Observable<FormGroupState<ControlForm>> {
return this.store.pipe(select(appFeature.selectControlPanelForm));
}
/**
* Return the usage for the selected model.
*/
// get usage$(): Observable<HazardUsageResponse> {
// return this.store.pipe(select(appFeature.selectUsageResponses));
// }
/**
* Call the hazard service.
*/
callServices(): void {
this.store.dispatch(appActions.callServices());
}
/**
* Initialize applicaiton.
*/
init(): void {
this.store.dispatch(appActions.init());
}
/**
* Redraw the plots.
*/
plotRedraw(): void {
this.store.dispatch(appActions.plotRedraw());
}
/**
* Reset the control panel.
*/
resetControlPanel(): void {
this.store.dispatch(appActions.resetControlPanel());
}
/**
* Reset the plot settings.
*/
resetSettings(): void {
this.store.dispatch(appActions.resetSettings());
}
/**
* Set the location form fields.
*
* @param location The location
*/
setLocation(location: Location): void {
this.store.dispatch(appActions.setLocation({location}));
}
}
import {createFeature, createReducer} from '@ngrx/store';
import {onNgrxForms} from 'ngrx-forms';
import {INITIAL_STATE} from './app.state';
import {initialState} from './app.state';
export const appFeature = createFeature({
name: 'dynamicCompareApp',
reducer: createReducer(
// Initial state
INITIAL_STATE,
initialState(),
// On NGRX forms
onNgrxForms()
),
......
......@@ -9,7 +9,7 @@ import {
} from '@ghsc/nshmp-web-utils/libs/nshmp-lib/model';
import {NshmId} from '@ghsc/nshmp-web-utils/libs/nshmp-lib/nshm';
import {Parameter} from '@ghsc/nshmp-web-utils/libs/nshmp-ws-utils/metadata';
import {createFormGroupState} from 'ngrx-forms';
import {FormGroupState, FormState, createFormGroupState} from 'ngrx-forms';
import {DynamicHazardControlForm} from 'projects/hazard-lib/src/lib/models';
import {hazardDefaultFormValues} from 'projects/hazard-lib/src/lib/utils';
import {ServiceCallInfo} from 'projects/nshmp-lib/src/lib/models/service-call-info.model';
......@@ -21,28 +21,33 @@ export const FORM_ID = 'ngrx-forms [Dynamic Hazard Compare Form]';
/**
* Dynamic hazard compare initial state.
*/
export const INITIAL_STATE: AppState = {
availableModels: [],
nshmServices: [],
plots: null,
serviceCallInfo: {
serviceCalls: [],
serviceName: 'Dynamic Hazard Curves',
usage: null,
},
serviceResponses: [],
usageResponses: null,
};
export function initialState(): AppState {
return {
availableModels: [],
controlPanelForm: controlPanelFormInitialState(),
nshmServices: [],
plots: null,
serviceCallInfo: {
serviceCalls: [],
serviceName: 'Dynamic Hazard Curves',
usage: null,
},
serviceResponses: [],
usageResponses: null,
};
}
/**
* Initial state for the control panel,
*/
export const FORM_INITIAL_STATE = createFormGroupState<ControlForm>(FORM_ID, {
...hazardDefaultFormValues(),
modelCompare: null,
sourceType: sourceTypeToString(SourceType.TOTAL),
vs30: 760,
});
export function controlPanelFormInitialState(): FormGroupState<ControlForm> {
return createFormGroupState<ControlForm>(FORM_ID, {
...hazardDefaultFormValues(),
modelCompare: null,
sourceType: sourceTypeToString(SourceType.TOTAL),
vs30: 760,
});
}
/**
* Control panel form.
......@@ -58,6 +63,8 @@ export interface ControlForm extends DynamicHazardControlForm {
export interface AppState extends SharedAppState {
/** Available NSHMs */
availableModels: Parameter[];
/** Control panel form field state */
controlPanelForm: FormState<ControlForm>;
/** NSHM service metadata */
nshmServices: NshmMetadata[];
/** Service call info */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment