Skip to content

Commit

Permalink
Some small fixes (#148)
Browse files Browse the repository at this point in the history
* Some small fixes

* Make public if aggregate-table-json is empty

* Fix for empty object check

* Another fix (it works this time)

* Put back responseType

* Update documentation
  • Loading branch information
edlu77 authored Apr 22, 2024
1 parent edc773e commit dbb87cb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
<mat-icon svgIcon="menu:data-distributions"></mat-icon>
<span class="title">Data Distributions</span>
</a>
<mat-divider></mat-divider>
<mat-divider *ngIf="showData" ></mat-divider>

<a class="link about" routerLink="/about" routerLinkActive="active">
<mat-icon>info_outlined</mat-icon>
<span class="title">About</span>
</a>
<mat-divider></mat-divider>
<mat-divider *ngIf="showData" ></mat-divider>

<a *ngIf="showData" class="link schema" routerLink="/data-schema-browser" routerLinkActive="active">
<mat-icon svgIcon="menu:data-storage"></mat-icon>
<span class="title">Data Schema Browser</span>
</a>
<mat-divider></mat-divider>
<mat-divider *ngIf="showData" ></mat-divider>

<a *ngIf="showData" class="link er-diagram" routerLink="/data-er-diagram" routerLinkActive="active">
<mat-icon>bar_chart_outline</mat-icon>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:host {
display: block;
width: 30rem;
padding-bottom: 2rem;
margin-bottom: 2rem;

.header,
.pages .link :not(mat-divider),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export class DatasetLoaderService {
* @returns parsed results
*/
private parseRawData(data: RawData): ParseResults {
if (!data) {
return { datasets: [], variables: [] };
}

const datasets: Dataset[] = [];
const variables: DatasetVariable[] = [];

Expand Down
34 changes: 19 additions & 15 deletions apps/a2agc/src/app/core/state/data/data.state.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import { Injectable } from '@angular/core';
import { StateRepository } from '@angular-ru/ngxs/decorators';
import { NgxsImmutableDataRepository } from '@angular-ru/ngxs/repositories';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { State } from '@ngxs/store';
import { catchError, map, Observable, of } from 'rxjs';

import { DATA_CONFIG } from '../../../../configs/config';
import { DatasetLoaderService, RawData } from '../../services/dataset-loader/dataset-loader.service';
import { DatasetVariablesState } from './dataset-variables.state';
import { DatasetsState } from './datasets.state';
import { Observable, catchError, map, of } from 'rxjs';
import { HttpClient } from '@angular/common/http';


export type DataStateModel = Record<string, never>;


/**
* Data state, contains datasets state and dataset variables state
*/
@StateRepository()
@State<DataStateModel>({
name: 'data',
children: [
DatasetsState,
DatasetVariablesState
]
children: [DatasetsState, DatasetVariablesState],
})
@Injectable()
export class DataState extends NgxsImmutableDataRepository<DataStateModel> {
Expand All @@ -49,22 +44,22 @@ export class DataState extends NgxsImmutableDataRepository<DataStateModel> {
ngxsOnInit(): void {
super.ngxsOnInit();

this.datasetLoader.load(DATA_CONFIG.datasetsPath).subscribe(result => {
this.datasetLoader.load(DATA_CONFIG.datasetsPath).subscribe((result) => {
this.datasetsState.addMany(result.datasets);
this.variablesState.addMany(result.variables);
});
}


/**
* Determines whether app is inprivate mode
* @returns true if the data config datasets path is valid, otherwise returns false
* Determines whether app is in private mode
* Searches for aggregate-table-data.json in assets/generated and checks if it's empty
* @returns true if the file contains data, false if empty
*/
isPrivate(): Observable<boolean> {
const response = this.http.get<RawData>(DATA_CONFIG.datasetsPath, { responseType: 'json' });
return response.pipe(
catchError((this.handleError)),
map(result => Object.keys(result).length > 0)
map((result) => this.isNotEmpty(result)),
catchError(this.handleError)
);
}

Expand All @@ -75,4 +70,13 @@ export class DataState extends NgxsImmutableDataRepository<DataStateModel> {
private handleError(): Observable<boolean> {
return of(false);
}

/**
* Checks if object is not empty
* @param input object
* @returns true if not empty
*/
private isNotEmpty(input: RawData): boolean {
return Object.keys(input).length !== 0;
}
}

0 comments on commit dbb87cb

Please sign in to comment.