diff --git a/apps/a2agc/src/app/app.component.ts b/apps/a2agc/src/app/app.component.ts index 31f08d60..a7351e0c 100644 --- a/apps/a2agc/src/app/app.component.ts +++ b/apps/a2agc/src/app/app.component.ts @@ -4,19 +4,19 @@ import { MatSidenavContainer } from '@angular/material/sidenav'; import { buildInfo } from './build-info'; import { PageLink } from './core/models/pages.model'; -import { DatasetsState } from './core/state/data/datasets.state'; +import { DataState } from './core/state/data/data.state'; import { RouterState } from './core/state/router/router.state'; import { visualizations } from './core/state/visualizations/visualizations'; import { MarkdownModalComponent, MarkdownModalData } from './shared/components/markdown-modal/markdown-modal.component'; /** * A2AGC app component -*/ + */ // eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection @Component({ selector: 'agc-root', templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'] + styleUrls: ['./app.component.scss'], }) export class AppComponent implements AfterViewInit { /** HTML class name */ @@ -33,8 +33,10 @@ export class AppComponent implements AfterViewInit { /** Sidenav menu header */ readonly menuHeader = 'Marion County Opioid Addiction Report'; /** Page options to include in the sidenav menu */ - readonly pages: PageLink[] = visualizations.map(v => ({ - path: v.id, title: v.title, description: v.description + readonly pages: PageLink[] = visualizations.map((v) => ({ + path: v.id, + title: v.title, + description: v.description, })); /** Whether or not to show the subbar under the page header */ @@ -47,13 +49,13 @@ export class AppComponent implements AfterViewInit { /** * Creates an instance of app component. * @param router Router state - * @param datasetsState Datasets state + * @param dataState Data state * @param dialog Mat dialog service * @param zone NgZone */ constructor( router: RouterState, - datasetsState: DatasetsState, + dataState: DataState, private readonly dialog: MatDialog, private readonly zone: NgZone ) { @@ -61,8 +63,8 @@ export class AppComponent implements AfterViewInit { this.menuOpen = false; }); - datasetsState.entitiesArray$.subscribe((datasets) => { - this.showData = datasets.length > 0; + dataState.isPrivate().subscribe((result) => { + this.showData = result; }); } @@ -74,7 +76,8 @@ export class AppComponent implements AfterViewInit { this.sidenavContainer.scrollable.elementScrolled().subscribe(() => { // NOTE: This runs outside angular's zone // ALL modifications must be wrapped in calls to `this.zone.run` or related methods - const offset = this.sidenavContainer.scrollable.measureScrollOffset('top'); + const offset = + this.sidenavContainer.scrollable.measureScrollOffset('top'); const visible = offset === 0; if (this.subBarVisible !== visible) { this.zone.run(() => { @@ -88,27 +91,33 @@ export class AppComponent implements AfterViewInit { * Opens contact form */ openContactUs(): void { - this.dialog.open(MarkdownModalComponent, { - width: '800px', - height: '600px', - data: { - title: 'Contact us', - src: 'assets/footer/contact-us.md' + this.dialog.open( + MarkdownModalComponent, + { + width: '800px', + height: '600px', + data: { + title: 'Contact us', + src: 'assets/footer/contact-us.md', + }, } - }); + ); } /** * Opens privacy policy dialog */ openPrivacyPolicy(): void { - this.dialog.open(MarkdownModalComponent, { - width: '800px', - height: '600px', - data: { - title: 'Privacy Policy', - src: 'assets/footer/privacy-policy.md' + this.dialog.open( + MarkdownModalComponent, + { + width: '800px', + height: '600px', + data: { + title: 'Privacy Policy', + src: 'assets/footer/privacy-policy.md', + }, } - }); + ); } } diff --git a/apps/a2agc/src/app/core/components/page-menu/page-menu.component.html b/apps/a2agc/src/app/core/components/page-menu/page-menu.component.html index 7a32f24a..81908248 100644 --- a/apps/a2agc/src/app/core/components/page-menu/page-menu.component.html +++ b/apps/a2agc/src/app/core/components/page-menu/page-menu.component.html @@ -24,13 +24,13 @@ - + Data Schema Browser - + bar_chart_outline Data ER Diagram diff --git a/apps/a2agc/src/app/core/services/dataset-loader/dataset-loader.service.ts b/apps/a2agc/src/app/core/services/dataset-loader/dataset-loader.service.ts index c926314b..32a7d0a4 100644 --- a/apps/a2agc/src/app/core/services/dataset-loader/dataset-loader.service.ts +++ b/apps/a2agc/src/app/core/services/dataset-loader/dataset-loader.service.ts @@ -8,7 +8,7 @@ import { Dataset, DatasetVariable } from '../../models/dataset.model'; /* eslint-disable @typescript-eslint/naming-convention */ -type RawData = Record; +export type RawData = Record; /** * Raw dataset info diff --git a/apps/a2agc/src/app/core/state/data/data.state.ts b/apps/a2agc/src/app/core/state/data/data.state.ts index 066f3e09..a3c721e1 100644 --- a/apps/a2agc/src/app/core/state/data/data.state.ts +++ b/apps/a2agc/src/app/core/state/data/data.state.ts @@ -4,9 +4,11 @@ import { NgxsImmutableDataRepository } from '@angular-ru/ngxs/repositories'; import { State } from '@ngxs/store'; import { DATA_CONFIG } from '../../../../configs/config'; -import { DatasetLoaderService } from '../../services/dataset-loader/dataset-loader.service'; +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; @@ -30,11 +32,13 @@ export class DataState extends NgxsImmutableDataRepository { * @param datasetLoader dataset loader service * @param datasetsState datasets state * @param variablesState variables state + * @param variablesState http service */ constructor( private readonly datasetLoader: DatasetLoaderService, private readonly datasetsState: DatasetsState, - private readonly variablesState: DatasetVariablesState + private readonly variablesState: DatasetVariablesState, + private readonly http: HttpClient ) { super(); } @@ -50,4 +54,25 @@ export class DataState extends NgxsImmutableDataRepository { this.variablesState.addMany(result.variables); }); } + + + /** + * Determines whether app is inprivate mode + * @returns true if the data config datasets path is valid, otherwise returns false + */ + isPrivate(): Observable { + const response = this.http.get(DATA_CONFIG.datasetsPath, { responseType: 'json' }); + return response.pipe( + catchError((this.handleError)), + map(result => Object.keys(result).length > 0) + ); + } + + /** + * Handles error when no response + * @returns observable with false + */ + private handleError(): Observable { + return of(false); + } } diff --git a/apps/a2agc/src/assets/pages/vis1-geomap-of-opioid-deaths/vis.vl.json b/apps/a2agc/src/assets/pages/vis1-geomap-of-opioid-deaths/vis.vl.json index 3679fd76..3b04fc94 100644 --- a/apps/a2agc/src/assets/pages/vis1-geomap-of-opioid-deaths/vis.vl.json +++ b/apps/a2agc/src/assets/pages/vis1-geomap-of-opioid-deaths/vis.vl.json @@ -528,6 +528,7 @@ "params": [ { "name": "period", + "value": {"x": [0, 0]}, "select": { "type": "interval", "mark": {