Skip to content

Commit

Permalink
Fixes for April 2024 (#146)
Browse files Browse the repository at this point in the history
* Disable schema browser and schema diagram in public mode

* Add initial value for time selector

* Add check for private mode

* Documentation
  • Loading branch information
edlu77 authored and bherr2 committed Jun 24, 2024
1 parent d83b10f commit e24ce41
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 29 deletions.
57 changes: 33 additions & 24 deletions apps/a2agc/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -47,22 +49,22 @@ 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
) {
router.navigationStart$.subscribe(() => {
this.menuOpen = false;
});

datasetsState.entitiesArray$.subscribe((datasets) => {
this.showData = datasets.length > 0;
dataState.isPrivate().subscribe((result) => {
this.showData = result;
});
}

Expand All @@ -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(() => {
Expand All @@ -88,27 +91,33 @@ export class AppComponent implements AfterViewInit {
* Opens contact form
*/
openContactUs(): void {
this.dialog.open<MarkdownModalComponent, MarkdownModalData>(MarkdownModalComponent, {
width: '800px',
height: '600px',
data: {
title: 'Contact us',
src: 'assets/footer/contact-us.md'
this.dialog.open<MarkdownModalComponent, MarkdownModalData>(
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, MarkdownModalData>(MarkdownModalComponent, {
width: '800px',
height: '600px',
data: {
title: 'Privacy Policy',
src: 'assets/footer/privacy-policy.md'
this.dialog.open<MarkdownModalComponent, MarkdownModalData>(
MarkdownModalComponent,
{
width: '800px',
height: '600px',
data: {
title: 'Privacy Policy',
src: 'assets/footer/privacy-policy.md',
},
}
});
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
</a>
<mat-divider></mat-divider>

<a class="link schema" routerLink="/data-schema-browser" routerLinkActive="active">
<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>

<a class="link er-diagram" routerLink="/data-er-diagram" routerLinkActive="active">
<a *ngIf="showData" class="link er-diagram" routerLink="/data-er-diagram" routerLinkActive="active">
<mat-icon>bar_chart_outline</mat-icon>
<span class="title">Data ER Diagram</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Dataset, DatasetVariable } from '../../models/dataset.model';

/* eslint-disable @typescript-eslint/naming-convention */

type RawData = Record<string, RawDataset>;
export type RawData = Record<string, RawDataset>;

/**
* Raw dataset info
Expand Down
29 changes: 27 additions & 2 deletions apps/a2agc/src/app/core/state/data/data.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, never>;
Expand All @@ -30,11 +32,13 @@ export class DataState extends NgxsImmutableDataRepository<DataStateModel> {
* @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();
}
Expand All @@ -50,4 +54,25 @@ export class DataState extends NgxsImmutableDataRepository<DataStateModel> {
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<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)
);
}

/**
* Handles error when no response
* @returns observable with false
*/
private handleError(): Observable<boolean> {
return of(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@
"params": [
{
"name": "period",
"value": {"x": [0, 0]},
"select": {
"type": "interval",
"mark": {
Expand Down

0 comments on commit e24ce41

Please sign in to comment.