Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resource)!: new resource route (DEV-196) #581

Merged
merged 13 commits into from Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/app/app-init.service.spec.ts
Expand Up @@ -19,6 +19,7 @@ describe('TestService', () => {
jsonWebToken: 'mytoken',
logErrors: true,
geonameToken: 'geoname_token',
iriBase: 'http://rdfh.ch',
instrumentation: {
environment: 'dev',
dataDog: {
Expand Down Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion src/app/app-init.service.ts
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/app/app-routing.module.ts
Expand Up @@ -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'
},
{
Expand Down
5 changes: 2 additions & 3 deletions src/app/app.component.spec.ts
@@ -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';
Expand All @@ -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';
Expand Down
1 change: 1 addition & 0 deletions src/app/main/declarations/app-config.ts
Expand Up @@ -7,6 +7,7 @@ export interface IConfig {
iiifHost: string;
iiifPort: number;
iiifPath: string;
iriBase: string;
jsonWebToken: string;
geonameToken: string;
logErrors: boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/app/main/declarations/dsp-app-config.ts
@@ -1,5 +1,6 @@
export class DspAppConfig {
constructor(
public geonameToken: string
public geonameToken: string,
public iriBase: string
) { }
}
Expand Up @@ -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"
Expand Down
22 changes: 17 additions & 5 deletions src/app/workspace/resource/properties/properties.component.spec.ts
@@ -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';
Expand All @@ -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.
Expand Down Expand Up @@ -147,6 +149,12 @@ describe('PropertiesComponent', () => {

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

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

TestBed.configureTestingModule({
imports: [
ClipboardModule,
Expand Down Expand Up @@ -178,6 +186,10 @@ describe('PropertiesComponent', () => {
provide: IncomingService,
useValue: incomingServiceSpy
},
{
provide: AppInitService,
useValue: appInitSpy
}
]
})
.compileComponents();
Expand Down
11 changes: 7 additions & 4 deletions src/app/workspace/resource/properties/properties.component.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Expand Up @@ -24,9 +24,7 @@ import {
MockResource,
MockUsers,
OntologiesEndpointV2,
OntologiesMetadata,
ReadOntology,
ReadResource,
OntologiesMetadata, ReadResource,
ResourceClassAndPropertyDefinitions,
ResourceClassDefinition,
ResourcePropertyDefinition,
Expand All @@ -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';
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -348,6 +351,10 @@ describe('ResourceInstanceFormComponent', () => {
provide: CacheService,
useValue: cacheServiceSpy
},
{
provide: AppInitService,
useValue: appInitSpy
},
// {
// provide: Router,
// useValue: routerSpy
Expand Down
@@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -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
) { }

Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -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';
Expand Down Expand Up @@ -122,6 +123,12 @@ describe('ResourceLinkFormComponent', () => {

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

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

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