Skip to content

Commit

Permalink
Add data and analytics authorizations (#302)
Browse files Browse the repository at this point in the history
* Add data and analytics authorizations

* Add some missing ending newlines

* Increment minor version to 1.5.0

* Upgrade stomp, update home component, and add data and analytics admin component
  • Loading branch information
wwelling committed Sep 29, 2023
1 parent 5ff73e4 commit 3b2b511
Show file tree
Hide file tree
Showing 46 changed files with 317 additions and 188 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .yarn/install-state.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ In addition to having [Docker](https://docs.docker.com/) installed, a running [S
-e HOST=localhost \
-e PORT=4200 \
-e BASE_HREF=/ \
-e SSR_SERVICE_URL="http://127.0.0.1:9000" \
-e BROKER_URL="ws://localhost:9000" \
-e SERVICE_URL="http://localhost:9000" \
-e SSR_SERVICE_URL="http://127.0.0.1:9000" \
-e EMBED_URL="http://localhost:4201" \
-e UI_URL="http://localhost:4200" \
-e VIVO_URL="http://localhost:8080/vivo" \
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scholars-angular",
"version": "1.4.3",
"version": "1.5.0",
"description": "Angular Universal client for Scholars Discovery",
"license": "MIT",
"contributors": [],
Expand Down Expand Up @@ -51,6 +51,7 @@
"@nguniversal/express-engine": "16.2.0",
"@ngx-translate/core": "15.0.0",
"@ngx-translate/http-loader": "8.0.0",
"@stomp/stompjs": "7.0.0",
"bootstrap": "~4.6.2",
"d3": "7.8.5",
"express": "4.18.2",
Expand Down
19 changes: 12 additions & 7 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { join } from 'path';
import { APP_BASE_HREF } from '@angular/common';

import { ngExpressEngine } from '@nguniversal/express-engine';
import { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens';

import * as express from 'express';
import * as expressStaticGzip from 'express-static-gzip';
Expand All @@ -22,10 +23,12 @@ const HOST = process.env.HOST || 'localhost';
const PORT = Number(process.env.PORT) || 4200;
const BASE_HREF = process.env.BASE_HREF || '/';

const SSR_SERVICE_URL = process.env.SSR_SERVICE_URL || 'http://127.0.0.1:9000';
const BROKER_URL = process.env.BROKER_URL || 'ws://localhost:9000';
const SERVICE_URL = process.env.SERVICE_URL || 'http://localhost:9000';
const EMBED_URL = process.env.EMBED_URL || 'http://localhost:4201';
const SSR_SERVICE_URL = process.env.SSR_SERVICE_URL || 'http://127.0.0.1:9000';

const UI_URL = process.env.UI_URL || 'http://localhost:4200';
const EMBED_URL = process.env.EMBED_URL || 'http://localhost:4201';
const VIVO_URL = process.env.VIVO_URL || 'http://localhost:8080/vivo';
const VIVO_EDITOR_URL = process.env.VIVO_EDITOR_URL || 'http://localhost:8080/vivo_editor';

Expand Down Expand Up @@ -81,10 +84,11 @@ export const app = (appConfig: AppConfig) => {
router.get('*', (req, res) => {
res.render(indexHtml, {
req,
providers: [{
provide: APP_BASE_HREF,
useValue: req.baseUrl
}]
providers: [
{ provide: APP_BASE_HREF, useValue: req.baseUrl },
{ provide: REQUEST, useValue: req },
{ provide: RESPONSE, useValue: res },
]
});
});

Expand All @@ -98,9 +102,10 @@ function run() {
host: HOST,
port: PORT,
baseHref: BASE_HREF,
brokerUrl: BROKER_URL,
serviceUrl: SERVICE_URL,
embedUrl: EMBED_URL,
uiUrl: UI_URL,
embedUrl: EMBED_URL,
vivoUrl: VIVO_URL,
vivoEditorUrl: VIVO_EDITOR_URL,
collectSearchStats: COLLECT_SEARCH_STATS
Expand Down
4 changes: 4 additions & 0 deletions src/app/+admin/admin.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class AdminComponent implements OnInit {
route: ['/admin/DisplayViews'],
translateKey: 'ADMIN.DISPLAY_VIEWS.TITLE',
},
{
route: ['/admin/DataAndAnalyticsViews'],
translateKey: 'ADMIN.DATA_AND_ANALYTICS_VIEWS.TITLE',
},
{
route: ['/admin/Themes'],
translateKey: 'ADMIN.THEMES.TITLE',
Expand Down
2 changes: 2 additions & 0 deletions src/app/+admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CustomMissingTranslationHandler } from '../core/handler/custom-missing-
import { SharedModule } from '../shared/shared.module';
import { AdminComponent } from './admin.component';
import { routes } from './admin.routes';
import { DataAndAnalyticsViewsComponent } from './data-and-analytics-views/data-and-analytics-views.component';
import { DirectoryViewsComponent } from './directory-views/directory-views.component';
import { DiscoveryViewsComponent } from './discovery-views/discovery-views.component';
import { DisplayViewsComponent } from './display-views/display-views.component';
Expand All @@ -16,6 +17,7 @@ import { UsersComponent } from './users/users.component';
@NgModule({
declarations: [
AdminComponent,
DataAndAnalyticsViewsComponent,
DirectoryViewsComponent,
DiscoveryViewsComponent,
DisplayViewsComponent,
Expand Down
14 changes: 14 additions & 0 deletions src/app/+admin/admin.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DiscoveryViewsComponent } from './discovery-views/discovery-views.compo
import { DisplayViewsComponent } from './display-views/display-views.component';
import { ThemesComponent } from './themes/themes.component';
import { UsersComponent } from './users/users.component';
import { DataAndAnalyticsViewsComponent } from './data-and-analytics-views/data-and-analytics-views.component';

export const routes: Routes = [
{
Expand Down Expand Up @@ -51,6 +52,19 @@ export const routes: Routes = [
],
},
},
{
path: 'DataAndAnalyticsViews',
component: DataAndAnalyticsViewsComponent,
data: {
collection: 'dataAndAnalyticsViews',
tags: [
{
name: 'view',
content: 'Scholars Administration - Data and Analytics Views',
},
],
},
},
{
path: 'Themes',
component: ThemesComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<scholars-pagination [page]="page">
<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">{{ 'ADMIN.DATA_AND_ANALYTICS_VIEWS.NAME' | translate }}</th>
<th scope="col">{{ 'ADMIN.DATA_AND_ANALYTICS_VIEWS.LAYOUT' | translate }}</th>
</tr>
</thead>
<tbody *ngIf="dataAndAnalyticsViews | async; let dataAndAnalyticsViews">
<tr *ngFor="let dataAndAnalyticsView of dataAndAnalyticsViews">
<td scope="row">{{dataAndAnalyticsView.name}}</td>
<td scope="row">{{dataAndAnalyticsView.layout}}</td>
</tr>
</tbody>
</table>
</scholars-pagination>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { APP_BASE_HREF } from '@angular/common';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { StoreModule } from '@ngrx/store';
import { TranslateModule } from '@ngx-translate/core';

import { testAppConfig } from '../../../test.config';
import { DialogService } from '../../core/service/dialog.service';
import { metaReducers, reducers } from '../../core/store';
import { SharedModule } from '../../shared/shared.module';
import { DataAndAnalyticsViewsComponent } from './data-and-analytics-views.component';

describe('DataAndAnalyticsViewsComponent', () => {
let component: DataAndAnalyticsViewsComponent;
let fixture: ComponentFixture<DataAndAnalyticsViewsComponent>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [DataAndAnalyticsViewsComponent],
providers: [
DialogService,
{
provide: APP_BASE_HREF,
useValue: '/',
},
],
imports: [
NoopAnimationsModule,
SharedModule,
StoreModule.forRoot(reducers(testAppConfig), {
metaReducers,
runtimeChecks: {
strictStateImmutability: false,
strictActionImmutability: false,
strictStateSerializability: false,
strictActionSerializability: false,
},
}),
TranslateModule.forRoot(),
RouterTestingModule.withRoutes([]),
],
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DataAndAnalyticsViewsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs';

import { SdrPage } from '../../core/model/sdr';
import { DataAndAnalyticsView } from '../../core/model/view';
import { AppState } from '../../core/store';
import { selectAllResources, selectResourcesPage } from '../../core/store/sdr';

@Component({
selector: 'scholars-data-and-analytics-views',
templateUrl: './data-and-analytics-views.component.html',
styleUrls: ['./data-and-analytics-views.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class DataAndAnalyticsViewsComponent implements OnInit {

public dataAndAnalyticsViews: Observable<DataAndAnalyticsView[]>;

public page: Observable<SdrPage>;

constructor(private store: Store<AppState>) { }

ngOnInit() {
this.dataAndAnalyticsViews = this.store.pipe(select(selectAllResources<DataAndAnalyticsView>('dataAndAnalyticsViews')));
this.page = this.store.pipe(select(selectResourcesPage<DataAndAnalyticsView>('dataAndAnalyticsViews')));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
</tr>
</tbody>
</table>
</scholars-pagination>
</scholars-pagination>
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
</tr>
</tbody>
</table>
</scholars-pagination>
</scholars-pagination>
2 changes: 1 addition & 1 deletion src/app/+admin/display-views/display-views.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
</tr>
</tbody>
</table>
</scholars-pagination>
</scholars-pagination>
2 changes: 1 addition & 1 deletion src/app/+admin/themes/themes.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
</tr>
</tbody>
</table>
</scholars-pagination>
</scholars-pagination>
2 changes: 1 addition & 1 deletion src/app/+admin/users/users.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
</tr>
</tbody>
</table>
</scholars-pagination>
</scholars-pagination>
52 changes: 25 additions & 27 deletions src/app/+dashboard/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { Component, Inject, OnInit, PLATFORM_ID, ViewEncapsulation } from '@angular/core';
import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
import { ActivatedRoute, Params } from '@angular/router';
import { NgbCarouselConfig } from '@ng-bootstrap/ng-bootstrap';
import { Store, select } from '@ngrx/store';
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
import { filter } from 'rxjs/operators';
import { Observable, Subject } from 'rxjs';
import { filter, take } from 'rxjs/operators';

import { Hero, Home } from '../../core/model/theme';
import { DiscoveryView } from '../../core/model/view';
Expand All @@ -21,49 +22,46 @@ import * as fromAuth from '../../core/store/auth/auth.actions';
styleUrls: ['home.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class HomeComponent implements OnInit, OnDestroy {
export class HomeComponent implements OnInit {

public discoveryView: Observable<DiscoveryView>;

public home: Observable<Home>;

public organization: Observable<string>;

public searchStyles: BehaviorSubject<SearchBoxStyles>;
public searchStyles: Subject<SearchBoxStyles>;

private subscriptions: Subscription[];

constructor(public config: NgbCarouselConfig, private sanitizer: DomSanitizer, private route: ActivatedRoute, private store: Store<AppState>) {
this.subscriptions = [];
}
constructor(
public config: NgbCarouselConfig,
@Inject(PLATFORM_ID) private platformId: string,
private sanitizer: DomSanitizer,
private route: ActivatedRoute,
private store: Store<AppState>
) { }

ngOnInit() {
this.discoveryView = this.store.pipe(
select(selectDiscoveryViewByClass('People')),
filter((view: DiscoveryView) => view !== undefined)
filter((view: DiscoveryView) => !!view)
);
this.home = this.store.pipe(
select(selectActiveThemeHome),
filter((home: Home) => home !== undefined)
filter((home: Home) => !!home)
);
this.organization = this.store.pipe(
select(selectActiveThemeOrganization),
filter((organization: string) => organization !== undefined)
);
this.subscriptions.push(
this.route.queryParams.subscribe((params: Params) => {
if (params.key !== undefined) {
this.store.dispatch(new fromAuth.ConfirmRegistrationAction({ key: params.key }));
}
})
filter((organization: string) => !!organization)
);
this.searchStyles = new BehaviorSubject<SearchBoxStyles>(undefined);
}

ngOnDestroy() {
this.subscriptions.forEach((subscription: Subscription) => {
subscription.unsubscribe();
});
if (isPlatformBrowser(this.platformId)) {
this.route.queryParams.pipe(take(1))
.subscribe((params: Params) => {
if (!!params.key) {
this.store.dispatch(new fromAuth.ConfirmRegistrationAction({ key: params.key }));
}
});
}
this.searchStyles = new Subject<SearchBoxStyles>();
}

public showCarousel(home: Home): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="container mb-1" *ngIf="getSelectedExportView() | async; let selected">
<a class="btn btn-primary pull-right" [href]="getDownloadLink(organization, selected)">{{ 'DATA_AND_ANALYTICS.DOWNLOAD' | translate }}</a>
<button class="btn btn-primary pull-right" (click)="download(organization, selected)">{{ 'DATA_AND_ANALYTICS.DOWNLOAD' | translate }}</button>
</div>
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { StoreModule } from '@ngrx/store';
import { REQUEST } from '@nguniversal/express-engine/tokens';
import { TranslateModule } from '@ngx-translate/core';

import { testAppConfig } from '../../../test.config';
import { getRequest } from '../../app.browser.module';
import { Layout } from '../../core/model/view';
import { ContainerType } from '../../core/model/view/data-and-analytics-view';
import { Side } from '../../core/model/view/display-view';
import { RestService } from '../../core/service/rest.service';
import { metaReducers, reducers } from '../../core/store';
import { SharedModule } from '../../shared/shared.module';
import { ProfileSummariesExportComponent } from './profile-summaries-export.component';
Expand All @@ -20,6 +24,7 @@ describe('ProfileSummariesExportComponent', () => {
declarations: [ProfileSummariesExportComponent],
imports: [
SharedModule,
HttpClientTestingModule,
StoreModule.forRoot(reducers(testAppConfig), {
metaReducers,
runtimeChecks: {
Expand All @@ -31,6 +36,10 @@ describe('ProfileSummariesExportComponent', () => {
}),
RouterTestingModule.withRoutes([]),
TranslateModule.forRoot(),
],
providers: [
{ provide: REQUEST, useFactory: getRequest },
RestService
]
}).compileComponents();
}));
Expand Down

0 comments on commit 3b2b511

Please sign in to comment.