Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions frontend/src/app/core/apiv3/cache/cachable-apiv3-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
} from 'rxjs/operators';
import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { CallableHalLink } from 'core-app/features/hal/hal-link/hal-link';

export abstract class ApiV3Resource<T extends HasId = HalResource>
extends ApiV3GettableResource<T> {
Expand Down Expand Up @@ -137,15 +138,15 @@ export abstract class ApiV3Resource<T extends HasId = HalResource>
switchMap((resource) => {
if (resource.$links.schema) {
return this.schemaCache
.requireAndStream(resource.$links.schema.href)
.requireAndStream((resource.$links.schema as CallableHalLink).href!)
.pipe(
take(1),
mapTo(resource),
);
}
return of(resource);
}),
) as any; // T does not extend HalResource for virtual endpoints such as board, thus we need to cast here
) as unknown as Observable<T>; // T does not extend HalResource for virtual endpoints such as board, thus we need to cast here
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ export class ApiV3QueriesPaths extends ApiV3ResourceCollection<QueryResource, Ap
*/
public toggleStarred(query:QueryResource):Promise<unknown> {
if (query.starred) {
return query.unstar();
return query.unstar!();
}
return query.star();
return query.star!();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/core/apiv3/virtual/apiv3-boards-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class ApiV3BoardsPaths extends ApiV3Collection<Board, ApiV3BoardPath> {
switchMap((form) => this
.apiRoot
.grids
.post(form.payload.$source)),
.post(form.payload.$source as unknown as GridResource)),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
//++

import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { HalSource } from 'core-app/features/hal/interfaces';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { GlobalSearchInputComponent } from './global-search-input.component';

Expand Down Expand Up @@ -62,7 +63,7 @@ describe('GlobalSearchInputComponent#followItem', () => {
// so followItem exercises the production displayId getter rather than a stub.
function buildWorkPackage(source:{ id:number, displayId?:string }):WorkPackageResource {
const item = Object.create(WorkPackageResource.prototype) as WorkPackageResource;
item.$source = source;
item.$source = source as unknown as HalSource;
return item;
}

Expand Down
3 changes: 1 addition & 2 deletions frontend/src/app/core/path-helper/apiv3-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';

export class ApiV3Paths {
readonly apiV3Base:string;
Expand Down Expand Up @@ -96,7 +95,7 @@ export class ApiV3Paths {

if (!workPackage.id || workPackage.id === 'new') {
// that are members of that project:
filters.add('member', '=', [(workPackage.project as HalResource).id!]);
filters.add('member', '=', [workPackage.project.id!]);
} else {
// that are mentionable on the work package
filters.add(
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/core/schemas/schema-cache.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { HalResourceService } from 'core-app/features/hal/services/hal-resource.
import { WorkPackageSchemaProxy } from 'core-app/features/hal/schemas/work-package-schema-proxy';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { SchemaResource } from 'core-app/features/hal/resources/schema-resource';
import { CallableHalLink } from 'core-app/features/hal/hal-link/hal-link';

export const fallbackSchemaId = '__fallback';

Expand Down Expand Up @@ -82,8 +83,7 @@ export class SchemaCacheService extends StateCacheService<SchemaResource> {
}

public getSchemaHref(resource:HalResource):string|undefined {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return resource.$links.schema?.href as string|undefined;
return (resource.$links.schema as CallableHalLink|undefined)?.href as string|undefined;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
} from 'rxjs/operators';

import { I18nService } from 'core-app/core/i18n/i18n.service';
import { HalLink } from 'core-app/features/hal/hal-link/hal-link';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { ConfigurationService } from 'core-app/core/config/configuration.service';
import { AttachmentsStore } from 'core-app/core/state/attachments/attachments.store';
Expand All @@ -58,6 +57,7 @@ import {
import { LazyInject } from 'core-app/shared/helpers/angular/lazy-inject.decorator';
import isNewResource, { HAL_NEW_RESOURCE_ID } from 'core-app/features/hal/helpers/is-new-resource';
import waitForUploadsFinished from 'core-app/core/upload/wait-for-uploads-finished';
import { CallableHalLink } from 'core-app/features/hal/hal-link/hal-link';

@Injectable()
export class AttachmentsResourceService extends ResourceStoreService<IAttachment> {
Expand Down Expand Up @@ -202,10 +202,10 @@ export class AttachmentsResourceService extends ResourceStoreService<IAttachment
}

private getDirectUploadLink(resource:HalResource):string|null {
const links = resource.$links as { prepareAttachment:HalLink };
const links = resource.$links;

if (links.prepareAttachment) {
return links.prepareAttachment.href!;
return (links.prepareAttachment as CallableHalLink).href!;
}

if (isNewResource(resource)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,21 @@ export class BcfWpAttributeGroupComponent extends UntilDestroyedMixin implements
.id(this.workPackage)
.requireAndStream()
.pipe(this.untilDestroyed())
.subscribe(async (wp) => {
this.workPackage = wp;
.subscribe((wp) => {
void this.onWorkPackageChange(wp);
});
}

if (!this.projectId) {
await this.initialize(this.workPackage);
}
private async onWorkPackageChange(wp:WorkPackageResource) {
this.workPackage = wp;

if (wp.bcfViewpoints) {
this.refreshViewpoints(wp.bcfViewpoints);
}
});
if (!this.projectId) {
await this.initialize(this.workPackage);
}

if (wp.bcfViewpoints) {
this.refreshViewpoints(wp.bcfViewpoints as unknown as HalLink[]);
}
}

async initialize(workPackage:WorkPackageResource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ViewpointsService {
@LazyInject() apiV3Service:ApiV3Service;

public getViewPointResource(workPackage:WorkPackageResource, index:number):BcfViewpointPaths {
const viewpointHref = (workPackage.bcfViewpoints as HalResource[])[index].href!;
const viewpointHref = workPackage.bcfViewpoints![index].href!;

return this.bcfApi.parse<BcfViewpointPaths>(viewpointHref)!;
}
Expand Down Expand Up @@ -91,7 +91,7 @@ export class ViewpointsService {
}

public saveViewpoint$(workPackage:WorkPackageResource, viewpoint?:CreateBcfViewpointData):Observable<CreateBcfViewpointData> {
const projectLink = (workPackage.project as HalResource).href;
const projectLink = workPackage.project.href;
const wpProjectId = idFromLink(projectLink);
const topicUUID$ = this.setBcfTopic$(workPackage);
// Default to the current viewer's viewpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
IfcProjectDefinition,
} from 'core-app/features/bim/ifc_models/pages/viewer/ifc-models-data.service';
import { BcfViewpointData, CreateBcfViewpointData } from 'core-app/features/bim/bcf/api/bcf-api.model';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import idFromLink from 'core-app/features/hal/helpers/id-from-link';
import { getMetaContent } from 'core-app/core/setup/globals/global-helpers';

Expand Down Expand Up @@ -256,7 +255,7 @@ export class IFCViewerService extends ViewerBridgeService {
// no means of setting it from here. Hence we must make a hard transition to bcf details route of the
// current work package.
window.location.href = this.pathHelper.bimDetailsPath(
idFromLink((workPackage.project as HalResource).href),
idFromLink(workPackage.project.href),
workPackage.id || '',
index,
);
Expand Down
28 changes: 14 additions & 14 deletions frontend/src/app/features/hal/hal-link/hal-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface HalLinkInterface {
method:HTTPSupportedMethods;
title?:string;
templated?:boolean;
payload?:any;
payload?:unknown;
type?:string;
identifier?:string;
displayId?:string;
Expand All @@ -50,18 +50,21 @@ export interface HalLinkSource {
title:string;
}

export interface CallableHalLink extends HalLinkInterface {
$link:this;
export interface CallableHalLink<T = HalResource> extends HalLinkInterface {
(data?:unknown, headers?:HTTPClientHeaders):Promise<T>;
$link:HalLink;
data?:Promise<HalResource>;
}

export type HalLinkRequestMethod = (method:HTTPSupportedMethods, href:string, data?:unknown, headers?:HTTPClientHeaders) => Promise<HalResource>;

export class HalLink implements HalLinkInterface {
constructor(public requestMethod:(method:HTTPSupportedMethods, href:string, data:any, headers:any) => Promise<HalResource>,
constructor(public requestMethod:HalLinkRequestMethod,
public href:string|null = null,
public title = '',
public method:HTTPSupportedMethods = 'get',
public templated = false,
public payload?:any,
public payload?:unknown,
public type = 'application/json',
public identifier?:string,
public displayId?:string) {
Expand All @@ -72,7 +75,7 @@ export class HalLink implements HalLinkInterface {
*/
public static fromObject(halResourceService:HalResourceService, link:HalLinkInterface):HalLink {
return new HalLink(
(method:HTTPSupportedMethods, href:string, data:object, headers:HTTPClientHeaders) => firstValueFrom(halResourceService.request(method, href, data, headers)),
(method, href, data, headers) => firstValueFrom(halResourceService.request(method, href, data, headers)),
link.href,
link.title,
link.method,
Expand All @@ -87,9 +90,8 @@ export class HalLink implements HalLinkInterface {
/**
* Fetch the resource.
*/
public $fetch(...params:any[]):Promise<HalResource> {
const [data, headers] = params;
return this.requestMethod(this.method, this.href!, data, headers);
public $fetch<T = HalResource>(data?:unknown, headers?:HTTPClientHeaders):Promise<T> {
return this.requestMethod(this.method, this.href!, data, headers) as Promise<T>;
}

/**
Expand Down Expand Up @@ -126,10 +128,10 @@ export class HalLink implements HalLinkInterface {
*
* @returns {CallableHalLink}
*/
public $callable():CallableHalLink {
const linkFunc:any = (...params:any[]) => this.$fetch(...params);
public $callable<T = HalResource>():CallableHalLink<T> {
const linkFunc = (data?:unknown, headers?:HTTPClientHeaders) => this.$fetch<T>(data, headers);

Object.assign(linkFunc, {
return Object.assign(linkFunc, {
$link: this,
href: this.href,
title: this.title,
Expand All @@ -140,7 +142,5 @@ export class HalLink implements HalLinkInterface {
identifier: this.identifier,
displayId: this.displayId,
});

return linkFunc;
}
}
Loading
Loading