Skip to content
Permalink
Browse files
feat(resource)!: new resource route (DEV-196) (#581)
* feat(resource): new resource route

* feat(resource)!: new resource route (DEV-196)

* test(resource): resolve tests with new config

* refactor(resource): make tslint happy

* chore(deps): update package-lock

* feat(resource)!: new resource route (DEV-196)

* refactor(resource): url check to keep consistent result

* refactor(test): clean up code

* test(resource): add missing test

* refactor(resouce): better test file
  • Loading branch information
kilchenmann committed Nov 10, 2021
1 parent 7680353 commit 3fbd94cdfd62e78ee7b6e7a718663e12d222f897
Show file tree
Hide file tree
Showing 28 changed files with 237 additions and 50 deletions.

Some generated files are not rendered by default. Learn more.

@@ -19,6 +19,7 @@ describe('TestService', () => {
jsonWebToken: 'mytoken',
logErrors: true,
geonameToken: 'geoname_token',
iriBase: 'http://rdfh.ch',
instrumentation: {
environment: 'dev',
dataDog: {
@@ -84,6 +85,7 @@ describe('TestService', () => {
expect(service.dspApiConfig.jsonWebToken).toEqual('mytoken');
expect(service.dspApiConfig.logErrors).toEqual(true);
expect(service.dspAppConfig.geonameToken).toEqual('geoname_token');
expect(service.dspAppConfig.iriBase).toEqual('http://rdfh.ch');
expect(service.dspInstrumentationConfig.environment).toEqual('dev');
expect(service.dspInstrumentationConfig.dataDog.enabled).toEqual(true);
expect(service.dspInstrumentationConfig.dataDog.applicationId).toEqual('app_id');
@@ -71,7 +71,8 @@ export class AppInitService {

// init dsp app extended configuration
this._dspAppConfig = new DspAppConfig(
this._config.geonameToken
this._config.geonameToken,
this._config.iriBase
);

// init instrumentation configuration
@@ -162,13 +162,17 @@ const routes: Routes = [
]
},
{
path: 'resource/:id',
component: ResourceComponent,
runGuardsAndResolvers: 'always'
},
{
path: 'resource/:id/:val',
component: ResourceComponent,
path: 'resource',
children: [
{
path: ':project/:resource/:value',
component: ResourceComponent
},
{
path: ':project/:resource',
component: ResourceComponent,
}
],
runGuardsAndResolvers: 'always'
},
{
@@ -1,5 +1,5 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { waitForAsync, TestBed } from '@angular/core/testing';
import { TestBed, waitForAsync } from '@angular/core/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatListModule } from '@angular/material/list';
@@ -12,8 +12,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { TestConfig } from 'test.config';
import { AppInitService } from './app-init.service';
import { AppComponent } from './app.component';
import { DspApiConfigToken, DspApiConnectionToken, DspInstrumentationToken } from './main/declarations/dsp-api-tokens';
import { DspDataDogConfig, DspInstrumentationConfig } from './main/declarations/dsp-instrumentation-config';
import { DspApiConfigToken, DspApiConnectionToken } from './main/declarations/dsp-api-tokens';
import { HeaderComponent } from './main/header/header.component';
import { SelectLanguageComponent } from './main/select-language/select-language.component';
import { UserMenuComponent } from './user/user-menu/user-menu.component';
@@ -7,6 +7,7 @@ export interface IConfig {
iiifHost: string;
iiifPort: number;
iiifPath: string;
iriBase: string;
jsonWebToken: string;
geonameToken: string;
logErrors: boolean;
@@ -1,5 +1,6 @@
export class DspAppConfig {
constructor(
public geonameToken: string
public geonameToken: string,
public iriBase: string
) { }
}
@@ -150,7 +150,7 @@ <h3 class="label mat-title">
<app-progress-indicator *ngIf="loading"></app-progress-indicator>
<div *ngIf="!loading">
<!-- the value(s) of the incoming links -->
<a class="link link-value" *ngFor="let inRes of incomingLinkResources" [routerLink]="['/resource', inRes.id]" target="_blank">{{inRes.label}}</a>
<a class="link link-value" *ngFor="let inRes of incomingLinkResources" (click)="openResource(inRes.id)">{{inRes.label}}</a>
<mat-paginator *ngIf="numberOffAllIncomingLinkRes > 25"
[length]=numberOffAllIncomingLinkRes
[pageSize]="25"
@@ -1,6 +1,7 @@
import { ClipboardModule } from '@angular/cdk/clipboard';
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatMenuModule } from '@angular/material/menu';
import { MatSnackBarModule } from '@angular/material/snack-bar';
@@ -23,14 +24,15 @@ import {
SystemPropertyDefinition
} from '@dasch-swiss/dsp-js';
import { of, Subscription } from 'rxjs';
import { AppInitService } from 'src/app/app-init.service';
import { DspApiConnectionToken, DspAppConfigToken } from 'src/app/main/declarations/dsp-api-tokens';
import { DspAppConfig } from 'src/app/main/declarations/dsp-app-config';
import { TestConfig } from 'test.config';
import { DspResource } from '../dsp-resource';
import { PropertiesComponent, PropertyInfoValues } from './properties.component';
import { IncomingService } from '../incoming.service';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { IncomingService } from '../services/incoming.service';
import { UserService } from '../services/user.service';
import { MatDialogModule } from '@angular/material/dialog';
import { AppInitService } from 'src/app/app-init.service';
import { EmitEvent, Events, ValueOperationEventService } from '../services/value-operation-event.service';
import { PropertiesComponent, PropertyInfoValues } from './properties.component';

/**
* test host component to simulate parent component.
@@ -147,6 +149,12 @@ describe('PropertiesComponent', () => {

const incomingServiceSpy = jasmine.createSpyObj('IncomingService', ['getIncomingLinks']);

const appInitSpy = {
dspAppConfig: {
iriBase: 'http://rdfh.ch'
}
};

TestBed.configureTestingModule({
imports: [
ClipboardModule,
@@ -178,6 +186,10 @@ describe('PropertiesComponent', () => {
provide: IncomingService,
useValue: incomingServiceSpy
},
{
provide: AppInitService,
useValue: appInitSpy
}
]
})
.compileComponents();
@@ -32,8 +32,9 @@ import { ConfirmationWithComment, DialogComponent } from 'src/app/main/dialog/di
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
import { NotificationService } from 'src/app/main/services/notification.service';
import { DspResource } from '../dsp-resource';
import { IncomingService } from '../incoming.service';
import { RepresentationConstants } from '../representation/file-representation';
import { IncomingService } from '../services/incoming.service';
import { ResourceService } from '../services/resource.service';
import { UserService } from '../services/user.service';
import {
AddedEventValue,
@@ -142,11 +143,12 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _dialog: MatDialog,
private _errorHandler: ErrorHandlerService,
private _incomingService: IncomingService,
private _notification: NotificationService,
private _resourceService: ResourceService,
private _userService: UserService,
private _valueOperationEventService: ValueOperationEventService,
private _valueService: ValueService,
private _incomingService: IncomingService
) { }

ngOnInit(): void {
@@ -262,8 +264,9 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
* @param linkValue
*/
openResource(linkValue: ReadLinkValue | string) {
const id = ((typeof linkValue == 'string') ? linkValue : linkValue.linkedResourceIri);
window.open('/resource/' + encodeURIComponent(id), '_blank');
const iri = ((typeof linkValue == 'string') ? linkValue : linkValue.linkedResourceIri);
const path = this._resourceService.getResourcePath(iri);
window.open('/resource' + path, '_blank');
}

previewResource(linkValue: ReadLinkValue) {
@@ -24,9 +24,7 @@ import {
MockResource,
MockUsers,
OntologiesEndpointV2,
OntologiesMetadata,
ReadOntology,
ReadResource,
OntologiesMetadata, ReadResource,
ResourceClassAndPropertyDefinitions,
ResourceClassDefinition,
ResourcePropertyDefinition,
@@ -35,10 +33,10 @@ import {
UserResponse,
UsersEndpointAdmin
} from '@dasch-swiss/dsp-js';
import { OntologyCache } from '@dasch-swiss/dsp-js/src/cache/ontology-cache/OntologyCache';
import { TranslateModule } from '@ngx-translate/core';
import { of } from 'rxjs';
import { AjaxResponse } from 'rxjs/ajax';
import { AppInitService } from 'src/app/app-init.service';
import { CacheService } from 'src/app/main/cache/cache.service';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { BaseValueDirective } from 'src/app/main/directive/base-value.directive';
@@ -309,6 +307,11 @@ describe('ResourceInstanceFormComponent', () => {

const cacheServiceSpy = jasmine.createSpyObj('CacheService', ['get']);

const appInitSpy = {
dspAppConfig: {
iriBase: 'http://rdfh.ch'
}
};
// const routerSpy = jasmine.createSpyObj('Router', ['navigate', 'navigateByUrl']);

TestBed.configureTestingModule({
@@ -348,6 +351,10 @@ describe('ResourceInstanceFormComponent', () => {
provide: CacheService,
useValue: cacheServiceSpy
},
{
provide: AppInitService,
useValue: appInitSpy
},
// {
// provide: Router,
// useValue: routerSpy
@@ -1,5 +1,5 @@
import { Component, EventEmitter, Inject, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Router } from '@angular/router';
import {
ApiResponseError,
@@ -20,7 +20,8 @@ import { Subscription } from 'rxjs';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
import { DefaultClass, DefaultResourceClasses } from 'src/app/project/ontology/default-data/default-resource-classes';
import { ProjectService } from '../project.service';
import { ProjectService } from '../services/project.service';
import { ResourceService } from '../services/resource.service';
import { SelectOntologyComponent } from './select-ontology/select-ontology.component';
import { SelectPropertiesComponent } from './select-properties/select-properties.component';
import { SelectResourceClassComponent } from './select-resource-class/select-resource-class.component';
@@ -87,6 +88,7 @@ export class ResourceInstanceFormComponent implements OnInit, OnDestroy {
private _errorHandler: ErrorHandlerService,
private _fb: FormBuilder,
private _project: ProjectService,
private _resourceService: ResourceService,
private _router: Router
) { }

@@ -200,7 +202,9 @@ export class ResourceInstanceFormComponent implements OnInit, OnDestroy {
(res: ReadResource) => {
this.resource = res;

const goto = '/resource/' + encodeURIComponent(this.resource.id);
const path = this._resourceService.getResourcePath(this.resource.id);

const goto = '/resource' + path;
this._router.navigate([]).then(result => window.open(goto, '_blank'));

this.closeDialog.emit();
@@ -28,6 +28,7 @@ import {
import { TranslateModule } from '@ngx-translate/core';
import { of } from 'rxjs';
import { AjaxResponse } from 'rxjs/ajax';
import { AppInitService } from 'src/app/app-init.service';
import { CacheService } from 'src/app/main/cache/cache.service';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { Session, SessionService } from 'src/app/main/services/session.service';
@@ -122,6 +123,12 @@ describe('ResourceLinkFormComponent', () => {

const cacheServiceSpy = jasmine.createSpyObj('CacheService', ['get']);

const appInitSpy = {
dspAppConfig: {
iriBase: 'http://rdfh.ch'
}
};

TestBed.configureTestingModule({
declarations: [
ResourceLinkFormComponent,
@@ -143,6 +150,7 @@ describe('ResourceLinkFormComponent', () => {
TranslateModule.forRoot()
],
providers: [
AppInitService,
{
provide: DspApiConnectionToken,
useValue: dspConnSpy
@@ -154,6 +162,10 @@ describe('ResourceLinkFormComponent', () => {
{
provide: CacheService,
useValue: cacheServiceSpy
},
{
provide: AppInitService,
useValue: appInitSpy
}
]
})

0 comments on commit 3fbd94c

Please sign in to comment.