Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Provide access to service directly from path helper

Oliver Güntherf0d6faa223c9
diff --git a/frontend/npm-shrinkwrap.json b/frontend/npm-shrinkwrap.json
index a46e3ddf4c3..02c38d8d85b 100644
--- a/frontend/npm-shrinkwrap.json
+++ b/frontend/npm-shrinkwrap.json
@@ -3587,9 +3587,9 @@
"integrity": "sha512-7TUK/k2/QGpEAv/BCwSHlYu3NXZhQ9ZwBYpzr9tjlPIL2C5BeGhH3DmVavRx3ZNyELX5TLC91JTz/cen6AAtIQ=="
},
"@types/jasmine": {
- "version": "3.4.0",
- "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-3.4.0.tgz",
- "integrity": "sha512-6pUnBg6DuSB55xnxJ5+gW9JOkFrPsXkYAuqqEE8oyrpgDiPQ+TZ+1Zt4S+CHcRJcxyNYXeIXG4vHSzdF6y9Uvw==",
+ "version": "3.5.8",
+ "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-3.5.8.tgz",
+ "integrity": "sha512-q/L59BjgE6VJtuIM4iDEEwT7xdSWVHMqC+td9sft5RfgHpDZ4Gdn0vLV59wKZ7PjGuVLCL7aNCdoiw5u6ZKSgA==",
"dev": true
},
"@types/jasminewd2": {
@@ -8275,9 +8275,9 @@
}
},
"jasmine-core": {
- "version": "3.4.0",
- "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.4.0.tgz",
- "integrity": "sha512-HU/YxV4i6GcmiH4duATwAbJQMlE0MsDIR5XmSVxURxKHn3aGAdbY1/ZJFmVRbKtnLwIxxMJD7gYaPsypcbYimg==",
+ "version": "3.5.0",
+ "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.5.0.tgz",
+ "integrity": "sha512-nCeAiw37MIMA9w9IXso7bRaLl+c/ef3wnxsoSAlYrzS+Ot0zTG6nU8G/cIfGkqpkjX2wNaIW9RFG0TwIFnG6bA==",
"dev": true
},
"jasmine-spec-reporter": {
diff --git a/frontend/package.json b/frontend/package.json
index 42550ddef26..66ef056c6ff 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -6,15 +6,15 @@
"private": true,
"devDependencies": {
"@angular/language-service": "8.2.9",
- "@types/jasmine": "~3.4.0",
+ "@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.6",
"@types/node": "~12.7.2",
"body-parser": "^1.19.0",
"circular-dependency-plugin": "^5.2.0",
"codelyzer": "^5.0.1",
"exec": "0.2.1",
- "jasmine-core": "^3.4.0",
- "jasmine-spec-reporter": "~4.2.1",
+ "jasmine-core": "3.5.0",
+ "jasmine-spec-reporter": "4.2.1",
"jquery-mockjax": "~2.5.0",
"json2htmlcov": "~0.1.1",
"karma": "^4.2.0",
diff --git a/frontend/src/app/modules/bim/bcf/api/bcf-api-request.service.ts b/frontend/src/app/modules/bim/bcf/api/bcf-api-request.service.ts
new file mode 100644
index 00000000000..a8b0b6f73d6
--- /dev/null
+++ b/frontend/src/app/modules/bim/bcf/api/bcf-api-request.service.ts
@@ -0,0 +1,109 @@
+import {HttpClient, HttpErrorResponse, HttpParams} from "@angular/common/http";
+import {Injector} from "@angular/core";
+import {TypedJSON} from "typedjson";
+import {Constructor} from "@angular/cdk/table";
+import {Observable} from "rxjs";
+import {
+ HTTPClientHeaders,
+ HTTPClientOptions,
+ HTTPClientParamMap,
+ HTTPSupportedMethods
+} from "core-app/modules/hal/http/http.interfaces";
+import {URLParamsEncoder} from "core-app/modules/hal/services/url-params-encoder";
+import {catchError, map} from "rxjs/operators";
+import {throwError} from "rxjs/internal/observable/throwError";
+import {InjectField} from "core-app/helpers/angular/inject-field.decorator";
+
+export class BcfApiRequestService<T> {
+ @InjectField() http:HttpClient;
+
+ /**
+ * Create a BCF api request service.
+ * Optionally pass a resource map to map the resulting data to with TypedJson.
+ *
+ * @param injector Injector
+ * @param resourceClass Optional mapped resource class with TypedJson annotations
+ */
+ constructor(readonly injector:Injector,
+ readonly resourceClass?:Constructor<T>) {
+ }
+
+ /**
+ * Request GET from the given BCF API 2.1 resource and map it to +resourceClass+.
+ *
+ * @param path API path to request
+ * @param params Request query params
+ * @param headers optional headers map
+ */
+ get(path:string, params:HTTPClientParamMap, headers:HTTPClientHeaders = {}):Observable<T> {
+ const config:HTTPClientOptions = {
+ headers: headers,
+ params: new HttpParams({ encoder: new URLParamsEncoder(), fromObject: params }),
+ withCredentials: true,
+ responseType: 'json'
+ };
+
+ return this._request('get', path, config);
+ }
+
+ /**
+ * Request the given BCF API 2.1 resource and map it to +resourceClass+.
+ *
+ * @param method request method
+ * @param path API path to request
+ * @param data Request payload (URL params for get, JSON payload otherwise)
+ * @param data Request payload (URL params for get, JSON payload otherwise)
+ */
+ public request(method:HTTPSupportedMethods, path:string, data:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}):Observable<T> {
+
+ // HttpClient requires us to create HttpParams instead of passing data for get
+ // so forward to that method instead.
+ if (method === 'get') {
+ return this.get(path, data, headers);
+ }
+
+ const config:HTTPClientOptions = {
+ body: data || {},
+ headers: headers,
+ withCredentials: true,
+ responseType: 'json'
+ };
+
+ return this._request(method, path, config);
+ }
+
+ /**
+ * Perform the request with httpClient and deserialize the result
+ *
+ * @param method Request method
+ * @param path Request path
+ * @param config HTTP client configuration
+ *
+ * @private
+ */
+ private _request(method:HTTPSupportedMethods, path:string, config:HTTPClientOptions):Observable<T> {
+ return this
+ .http
+ .request<T>(method, path, config)
+ .pipe(
+ map((response:any) => this.deserialize(response)),
+ catchError((error:HttpErrorResponse) => {
+ console.error(`Failed to ${method} ${path}: ${error.name}`);
+ return throwError(error);
+ })
+ );
+ }
+
+ /**
+ * Deserialize the JSON data into the mapped resource class, if given.
+ * @param data JSON API response.
+ */
+ protected deserialize(data:any):T {
+ if (this.resourceClass) {
+ const serializer = new TypedJSON(this.resourceClass);
+ return serializer.parse(data)!;
+ } else {
+ return data;
+ }
+ }
+}
\ No newline at end of file
diff --git a/frontend/src/app/modules/bim/bcf/api/bcf-api.service.spec.ts b/frontend/src/app/modules/bim/bcf/api/bcf-api.service.spec.ts
new file mode 100644
index 00000000000..eb6110c6588
--- /dev/null
+++ b/frontend/src/app/modules/bim/bcf/api/bcf-api.service.spec.ts
@@ -0,0 +1,134 @@
+//-- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2020 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See docs/COPYRIGHT.rdoc for more details.
+//++
+
+import {async, TestBed} from "@angular/core/testing";
+import {BcfApiService} from "core-app/modules/bim/bcf/api/bcf-api.service";
+import {BcfResourceCollectionPath, BcfResourcePath} from "core-app/modules/bim/bcf/api/bcf-path-resources";
+import {BcfTopicPaths} from "core-app/modules/bim/bcf/api/topics/bcf-topic.paths";
+
+fdescribe('BcfApiService', function () {
+ let service:BcfApiService;
+
+ beforeEach(async(() => {
+ // noinspection JSIgnoredPromiseFromCall
+ TestBed.configureTestingModule({
+ providers: [
+ BcfApiService,
+ ]
+ })
+ .compileComponents()
+ .then(() => {
+ service = TestBed.get(BcfApiService);
+ });
+ }));
+
+ describe('building the path', () => {
+ it('can build projects', () => {
+ let subject = service.projects;
+ expect(subject.toPath()).toEqual('/api/bcf/2.1/projects');
+ });
+
+ it('can build project', () => {
+ let subject = service.projects.id('foo');
+ expect(subject.toPath()).toEqual('/api/bcf/2.1/projects/foo');
+ });
+
+ it('can build topics', () => {
+ let subject = service.projects.id('foo').topics;
+ expect(subject.toPath()).toEqual('/api/bcf/2.1/projects/foo/topics');
+ });
+
+ it('can build topic', () => {
+ let subject = service.projects.id('foo').topics.id('bar');
+ expect(subject.toPath()).toEqual('/api/bcf/2.1/projects/foo/topics/bar');
+ });
+
+ it('can build viewpoints', () => {
+ let subject = service.projects.id('foo').topics.id('bar').viewpoints;
+ expect(subject.toPath()).toEqual('/api/bcf/2.1/projects/foo/topics/bar/viewpoints');
+ });
+
+ it('can build comments', () => {
+ let subject = service.projects.id('foo').topics.id('bar').comments;
+ expect(subject.toPath()).toEqual('/api/bcf/2.1/projects/foo/topics/bar/comments');
+ });
+ });
+
+ describe('#parse', () => {
+ it('can parse projects', () => {
+ let href = '/api/bcf/2.1/projects';
+ let subject:any = service.parse(href);
+ expect(subject).toBeInstanceOf(BcfResourceCollectionPath);
+ expect(subject.segment).toEqual('projects');
+ expect(subject.toPath()).toEqual(href);
+ });
+
+ it('can parse single project', () => {
+ let href = '/api/bcf/2.1/projects/foo';
+ let subject:any = service.parse(href);
+ expect(subject).toBeInstanceOf(BcfResourcePath);
+ expect(subject.id).toEqual('foo');
+ expect(subject.toPath()).toEqual(href);
+ });
+
+ it('can parse topics in projects', () => {
+ let href = '/api/bcf/2.1/projects/foo/topics';
+ let subject:any = service.parse(href);
+ expect(subject).toBeInstanceOf(BcfResourceCollectionPath);
+ expect(subject.segment).toEqual('topics');
+ expect(subject.toPath()).toEqual(href);
+ });
+
+ it('can parse single topic in projects', () => {
+ let href = '/api/bcf/2.1/projects/foo/topics/0efc0da-b4d5-4933-bcb6-e01513ee2bcc';
+ let subject:any = service.parse(href);
+ expect(subject).toBeInstanceOf(BcfTopicPaths);
+ expect(subject.comments).toBeDefined();
+ expect(subject.viewpoints).toBeDefined();
+ expect(subject.id).toEqual('0efc0da-b4d5-4933-bcb6-e01513ee2bcc');
+ expect(subject.toPath()).toEqual(href);
+ });
+
+ it('can parse viewpoints in topic', () => {
+ let href = '/api/bcf/2.1/projects/foo/topics/0efc0da-b4d5-4933-bcb6-e01513ee2bcc/viewpoints';
+ let subject:any = service.parse(href);
+ expect(subject).toBeInstanceOf(BcfResourceCollectionPath);
+ expect(subject.segment).toEqual('viewpoints');
+ expect(subject.toPath()).toEqual(href);
+ });
+
+ it('can parse single viewpoint in topic', () => {
+ let href = '/api/bcf/2.1/projects/demo-bcf-management-project/topics/00efc0da-b4d5-4933-bcb6-e01513ee2bcc/viewpoints/dfca6c25-832f-6a94-53ca-48d510b6bad9';
+ let subject:any = service.parse(href);
+ expect(subject).toBeInstanceOf(BcfResourcePath);
+ expect(subject.id).toEqual('dfca6c25-832f-6a94-53ca-48d510b6bad9');
+ expect(subject.toPath()).toEqual(href);
+ });
+
+ });
+});
diff --git a/frontend/src/app/modules/bim/bcf/api/bcf-api.service.ts b/frontend/src/app/modules/bim/bcf/api/bcf-api.service.ts
new file mode 100644
index 00000000000..bc3246af3c9
--- /dev/null
+++ b/frontend/src/app/modules/bim/bcf/api/bcf-api.service.ts
@@ -0,0 +1,81 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2020 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See docs/COPYRIGHT.rdoc for more details.
+// ++
+
+import {Injectable, Injector} from "@angular/core";
+import {BcfResourceCollectionPath, BcfResourcePath} from "core-app/modules/bim/bcf/api/bcf-path-resources";
+import {BcfProjectPaths} from "core-app/modules/bim/bcf/api/projects/bcf-project.paths";
+
+
+@Injectable()
+export class BcfApiService {
+
+ public readonly bcfApiVersion = '2.1';
+ public readonly appBasePath = window.appBasePath || '';
+ public readonly bcfApiBase = `${this.appBasePath}/api/bcf/${this.bcfApiVersion}`;
+
+ // /api/bcf/:version/projects
+ public readonly projects = new BcfResourceCollectionPath(this.injector, this.bcfApiBase, 'projects', BcfProjectPaths);
+
+ constructor(readonly injector:Injector) {
+ }
+
+ /**
+ * Parse the given string into a BCF resource path
+ *
+ * @param href
+ */
+ parse(href:string):BcfResourcePath|BcfResourceCollectionPath<any>|undefined {
+ if (!href.startsWith(this.bcfApiBase)) {
+ return;
+ }
+
+ const parts = href
+ .replace(this.bcfApiBase + '/', '')
+ .split('/');
+
+ // Try to find a target collection or resource
+ let current:any = this;
+
+ for (let i = 0; i < parts.length; i++) {
+ let pathOrId:string = parts[i];
+ if (pathOrId in current) {
+ // Current has a member named like this URL part
+ // descend into it
+ current = current[pathOrId];
+ } else if (current instanceof BcfResourceCollectionPath) {
+ // Otherwise, assume we're looking for an ID
+ current = current.id(pathOrId);
+ } else {
+ // Otherwise, return the current
+ break;
+ }
+ }
+
+ return current === this ? undefined : current;
+ }
+}
diff --git a/frontend/src/app/modules/bim/bcf/api/bcf-path-resources.ts b/frontend/src/app/modules/bim/bcf/api/bcf-path-resources.ts
new file mode 100644
index 00000000000..b3d155880f0
--- /dev/null
+++ b/frontend/src/app/modules/bim/bcf/api/bcf-path-resources.ts
@@ -0,0 +1,25 @@
+import {SimpleResource, SimpleResourceCollection} from "core-app/modules/common/path-helper/apiv3/path-resources";
+import {Injector} from "@angular/core";
+import {Constructor} from "@angular/cdk/table";
+
+export class BcfResourcePath extends SimpleResource {
+ constructor(readonly injector:Injector,
+ basePath:string,
+ id:string|number) {
+ super(basePath, id);
+ }
+}
+
+export class BcfResourceCollectionPath<T extends BcfResourcePath> extends SimpleResourceCollection<T> {
+ constructor(readonly injector:Injector,
+ protected basePath:string,
+ segment:string,
+ protected resource?:Constructor<T>) {
+ super(basePath, segment, resource);
+ }
+
+ public id(id:string|number):T {
+ return new (this.resource || BcfResourcePath)(this.injector, this.path, id) as T;
+ }
+
+}
\ No newline at end of file
diff --git a/frontend/src/app/modules/bim/bcf/api/endpoints/bcf-api-service.base.ts b/frontend/src/app/modules/bim/bcf/api/endpoints/bcf-api-service.base.ts
deleted file mode 100644
index 6e1767f00e9..00000000000
--- a/frontend/src/app/modules/bim/bcf/api/endpoints/bcf-api-service.base.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import {BcfApiPathsService} from "core-app/modules/bim/bcf/api/paths/bcf-api-paths.service";
-import {HttpClient} from "@angular/common/http";
-import {Injectable, Injector} from "@angular/core";
-import {OpenprojectBcfModule} from "core-app/modules/bim/bcf/openproject-bcf.module";
-import {BcfTopicResource} from "core-app/modules/bim/bcf/api/resources/bcf-topic.resource";
-import {Observable} from "rxjs";
-import {TypedJSON} from "typedjson";
-import {map} from "rxjs/operators";
-import {Constructor} from "@angular/cdk/table";
-
-export abstract class BcfApiServiceBase<T> {
-
- /** Mapped resource class to parse JSON response */
- protected abstract resourceClass:Constructor<T>;
-
- constructor(protected injector:Injector,
- protected paths:BcfApiPathsService,
- protected http:HttpClient) {
- }
-
- protected fromJson(data:any):T {
- const serializer = new TypedJSON(this.resourceClass);
- return serializer.parse(data)!;
- }
-}
\ No newline at end of file
diff --git a/frontend/src/app/modules/bim/bcf/api/endpoints/bcf-topic-api.service.ts b/frontend/src/app/modules/bim/bcf/api/endpoints/bcf-topic-api.service.ts
deleted file mode 100644
index 938da5d9d69..00000000000
--- a/frontend/src/app/modules/bim/bcf/api/endpoints/bcf-topic-api.service.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import {Injectable} from "@angular/core";
-import {OpenprojectBcfModule} from "core-app/modules/bim/bcf/openproject-bcf.module";
-import {BcfTopicResource} from "core-app/modules/bim/bcf/api/resources/bcf-topic.resource";
-import {Observable} from "rxjs";
-import {map} from "rxjs/operators";
-import {BcfApiServiceBase} from "core-app/modules/bim/bcf/api/endpoints/bcf-api-service.base";
-
-@Injectable({ providedIn: OpenprojectBcfModule })
-export class BcfTopicApiService extends BcfApiServiceBase<BcfTopicResource> {
-
- resourceClass = BcfTopicResource;
-
- get(projectIdentifier:string, uuid:string):Observable<BcfTopicResource> {
- return this
- .http
- .get(this.topicPath(projectIdentifier, uuid))
- .pipe(
- map(this.fromJson.bind(this))
- );
- }
-
- private topicPath(projectIdentifier:string, uuid:string) {
- return this.paths.projects.id(projectIdentifier).topics.id(uuid).toString();
- }
-}
\ No newline at end of file
diff --git a/frontend/src/app/modules/bim/bcf/api/paths/bcf-api-paths.service.ts b/frontend/src/app/modules/bim/bcf/api/paths/bcf-api-paths.service.ts
deleted file mode 100644
index bbff294708c..00000000000
--- a/frontend/src/app/modules/bim/bcf/api/paths/bcf-api-paths.service.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-// -- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) 2012-2020 the OpenProject GmbH
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License version 3.
-//
-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-// Copyright (C) 2006-2013 Jean-Philippe Lang
-// Copyright (C) 2010-2013 the ChiliProject Team
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// See docs/COPYRIGHT.rdoc for more details.
-// ++
-
-import {SimpleResource, SimpleResourceCollection} from 'core-app/modules/common/path-helper/apiv3/path-resources';
-import {Injectable} from "@angular/core";
-import {OpenprojectBcfModule} from "core-app/modules/bim/bcf/openproject-bcf.module";
-
-class BcfProjectPaths extends SimpleResource {
- public readonly topics = new SimpleResourceCollection<BcfTopicPaths>(this.path, 'topics', BcfTopicPaths);
-
-}
-
-class BcfTopicPaths extends SimpleResource {
- public readonly comments = new SimpleResourceCollection(this.path, 'comments');
- public readonly viewpoints = new SimpleResourceCollection(this.path, 'viewpoints');
-
-}
-
-@Injectable({ providedIn: OpenprojectBcfModule })
-export class BcfApiPathsService {
-
- public readonly bcfApiVersion = '2.1';
- public readonly bcfApiBase = `${window.appBasePath}/api/bcf/${this.bcfApiVersion}`;
-
- // /api/bcf/:version/projects
- public readonly projects = new SimpleResourceCollection<BcfProjectPaths>(this.bcfApiBase, 'projects', BcfProjectPaths);
-}
diff --git a/frontend/src/app/modules/bim/bcf/api/projects/bcf-project.paths.ts b/frontend/src/app/modules/bim/bcf/api/projects/bcf-project.paths.ts
new file mode 100644
index 00000000000..18efb6b78d0
--- /dev/null
+++ b/frontend/src/app/modules/bim/bcf/api/projects/bcf-project.paths.ts
@@ -0,0 +1,16 @@
+import {BcfResourceCollectionPath, BcfResourcePath} from "core-app/modules/bim/bcf/api/bcf-path-resources";
+import {BcfTopicPaths} from "core-app/modules/bim/bcf/api/topics/bcf-topic.paths";
+import {BcfApiRequestService} from "core-app/modules/bim/bcf/api/bcf-api-request.service";
+import {BcfProjectResource} from "core-app/modules/bim/bcf/api/projects/bcf-project.resource";
+import {HTTPClientHeaders, HTTPClientParamMap} from "core-app/modules/hal/http/http.interfaces";
+
+export class BcfProjectPaths extends BcfResourcePath {
+ readonly bcfProjectService = new BcfApiRequestService(this.injector, BcfProjectResource);
+
+ /** /topics */
+ public readonly topics = new BcfResourceCollectionPath(this.injector, this.path, 'topics', BcfTopicPaths);
+
+ get(params:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}) {
+ return this.bcfProjectService.get(this.toPath(), params, headers);
+ }
+}
\ No newline at end of file
diff --git a/frontend/src/app/modules/bim/bcf/api/projects/bcf-project.resource.ts b/frontend/src/app/modules/bim/bcf/api/projects/bcf-project.resource.ts
new file mode 100644
index 00000000000..84e63d294c4
--- /dev/null
+++ b/frontend/src/app/modules/bim/bcf/api/projects/bcf-project.resource.ts
@@ -0,0 +1,11 @@
+import {jsonMember, jsonObject} from "typedjson";
+
+@jsonObject
+export class BcfProjectResource {
+
+ @jsonMember
+ project_id:number;
+
+ @jsonMember
+ name:string;
+}
diff --git a/frontend/src/app/modules/bim/bcf/api/topics/bcf-topic.paths.ts b/frontend/src/app/modules/bim/bcf/api/topics/bcf-topic.paths.ts
new file mode 100644
index 00000000000..94b9f904df5
--- /dev/null
+++ b/frontend/src/app/modules/bim/bcf/api/topics/bcf-topic.paths.ts
@@ -0,0 +1,19 @@
+import {HTTPClientHeaders, HTTPClientParamMap} from "core-app/modules/hal/http/http.interfaces";
+import {BcfResourceCollectionPath, BcfResourcePath} from "core-app/modules/bim/bcf/api/bcf-path-resources";
+import {BcfTopicResource} from "core-app/modules/bim/bcf/api/topics/bcf-topic.resource";
+import {BcfApiRequestService} from "core-app/modules/bim/bcf/api/bcf-api-request.service";
+import {BcfViewpointPaths} from "core-app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.paths";
+
+export class BcfTopicPaths extends BcfResourcePath {
+ readonly bcfTopicService = new BcfApiRequestService(this.injector, BcfTopicResource);
+
+ /** /comments */
+ public readonly comments = new BcfResourceCollectionPath(this.injector, this.path, 'comments');
+
+ /** /viewpoints */
+ public readonly viewpoints = new BcfResourceCollectionPath(this.injector, this.path, 'viewpoints', BcfViewpointPaths);
+
+ get(params:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}) {
+ return this.bcfTopicService.get(this.toPath(), params, headers);
+ }
+}
\ No newline at end of file
diff --git a/frontend/src/app/modules/bim/bcf/api/resources/bcf-topic.resource.ts b/frontend/src/app/modules/bim/bcf/api/topics/bcf-topic.resource.ts
similarity index 94%
rename from frontend/src/app/modules/bim/bcf/api/resources/bcf-topic.resource.ts
rename to frontend/src/app/modules/bim/bcf/api/topics/bcf-topic.resource.ts
index 3b09a5935e2..f3fe02596f5 100644
--- a/frontend/src/app/modules/bim/bcf/api/resources/bcf-topic.resource.ts
+++ b/frontend/src/app/modules/bim/bcf/api/topics/bcf-topic.resource.ts
@@ -1,4 +1,4 @@
-import {jsonArrayMember, jsonMapMember, jsonMember, jsonObject} from "typedjson";
+import {jsonArrayMember, jsonMember, jsonObject} from "typedjson";
import {Moment} from "moment";
@jsonObject
diff --git a/frontend/src/app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface.ts b/frontend/src/app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface.ts
new file mode 100644
index 00000000000..48ee208ef90
--- /dev/null
+++ b/frontend/src/app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface.ts
@@ -0,0 +1,7 @@
+/** Viewpoints use an interface to avoid (de)serialization of data we don't need */
+export interface BcfViewpointInterface {
+ guid:string;
+ components:unknown;
+ orthogonal_camera?:unknown;
+ perspective_camera?:unknown;
+}
diff --git a/frontend/src/app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.paths.ts b/frontend/src/app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.paths.ts
new file mode 100644
index 00000000000..9fb9a5ae77d
--- /dev/null
+++ b/frontend/src/app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.paths.ts
@@ -0,0 +1,12 @@
+import {HTTPClientHeaders, HTTPClientParamMap} from "core-app/modules/hal/http/http.interfaces";
+import {BcfResourcePath} from "core-app/modules/bim/bcf/api/bcf-path-resources";
+import {BcfApiRequestService} from "core-app/modules/bim/bcf/api/bcf-api-request.service";
+import {BcfViewpointInterface} from "core-app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface";
+
+export class BcfViewpointPaths extends BcfResourcePath {
+ readonly bcfTopicService = new BcfApiRequestService<BcfViewpointInterface>(this.injector);
+
+ get(params:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}) {
+ return this.bcfTopicService.get(this.toPath(), params, headers);
+ }
+}
\ No newline at end of file
diff --git a/frontend/src/app/modules/bim/bcf/openproject-bcf.module.ts b/frontend/src/app/modules/bim/bcf/openproject-bcf.module.ts
index f481f3e3287..0e6b6277a94 100644
--- a/frontend/src/app/modules/bim/bcf/openproject-bcf.module.ts
+++ b/frontend/src/app/modules/bim/bcf/openproject-bcf.module.ts
@@ -36,7 +36,7 @@ import {BcfDetectorService} from "core-app/modules/bim/bcf/helper/bcf-detector.s
import {BcfPathHelperService} from "core-app/modules/bim/bcf/helper/bcf-path-helper.service";
import {BcfExportButtonComponent} from "core-app/modules/bim/bcf/bcf-buttons/bcf-export-button.component";
import {BcfThumbnailDisplayField} from "core-app/modules/bim/bcf/fields/display/bcf-thumbnail-field.module";
-import {BcfTopicApiService} from "core-app/modules/bim/bcf/api/endpoints/bcf-topic-api.service";
+import {BcfApiService} from "core-app/modules/bim/bcf/api/bcf-api.service";
@NgModule({
@@ -45,6 +45,7 @@ import {BcfTopicApiService} from "core-app/modules/bim/bcf/api/endpoints/bcf-top
NgxGalleryModule,
],
providers: [
+ BcfApiService,
BcfDetectorService,
BcfPathHelperService
],
diff --git a/frontend/src/app/modules/bim/ifc_models/pages/viewer/ifc-viewer-page.component.ts b/frontend/src/app/modules/bim/ifc_models/pages/viewer/ifc-viewer-page.component.ts
index 0c164d0d561..8d8327e86e1 100644
--- a/frontend/src/app/modules/bim/ifc_models/pages/viewer/ifc-viewer-page.component.ts
+++ b/frontend/src/app/modules/bim/ifc_models/pages/viewer/ifc-viewer-page.component.ts
@@ -21,8 +21,7 @@ import {QueryResource} from "core-app/modules/hal/resources/query-resource";
import {BimManageIfcModelsButtonComponent} from "core-app/modules/bim/ifc_models/toolbar/manage-ifc-models-button/bim-manage-ifc-models-button.component";
import {WorkPackageCreateButtonComponent} from "core-components/wp-buttons/wp-create-button/wp-create-button.component";
import {StateService, TransitionService} from "@uirouter/core";
-import {BehaviorSubject, Subject} from "rxjs";
-import {BcfTopicApiService} from "core-app/modules/bim/bcf/api/endpoints/bcf-topic-api.service";
+import {BehaviorSubject} from "rxjs";
@Component({
templateUrl: '/app/modules/work_packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.html',
@@ -51,7 +50,7 @@ export class IFCViewerPageComponent extends PartitionedQuerySpacePageComponent {
{
component: WorkPackageCreateButtonComponent,
inputs: {
- stateName$: this.newRoute$,
+ stateName$: this.newRoute$,
allowed: ['work_packages.createWorkPackage', 'work_package.copy']
}
},
@@ -93,11 +92,6 @@ export class IFCViewerPageComponent extends PartitionedQuerySpacePageComponent {
ngOnInit() {
super.ngOnInit();
- const bcfTopics = this.injector.get(BcfTopicApiService);
- bcfTopics
- .get('4', "00efc0da-b4d5-4933-bcb6-e01513ee2bcc")
- .subscribe((val) => console.warn(val));
-
this
.bimView
.observeUntil(componentDestroyed(this))
@@ -106,15 +100,13 @@ export class IFCViewerPageComponent extends PartitionedQuerySpacePageComponent {
});
// Keep the new route up to date depending on where we move to
- this.transitionUnsubscribeFn = this.transition.onSuccess({}, () => {
+ this.transitionUnsubscribeFn = this.transition.onSuccess({}, () => {
this.newRoute$.next(this.state.current.data.newRoute);
});
}
ngOnDestroy():void {
super.ngOnDestroy();
-
-
}
/**
@@ -123,7 +115,7 @@ export class IFCViewerPageComponent extends PartitionedQuerySpacePageComponent {
*
* To re-enable query titles, remove this function.
*
- * @param _query
+ * @param query
*/
updateTitle(query?:QueryResource) {
if (this.bimView.current === bimListViewIdentifier) {
diff --git a/frontend/src/app/modules/common/path-helper/apiv3/path-resources.ts b/frontend/src/app/modules/common/path-helper/apiv3/path-resources.ts
index 04c45134f12..43e9f159891 100644
--- a/frontend/src/app/modules/common/path-helper/apiv3/path-resources.ts
+++ b/frontend/src/app/modules/common/path-helper/apiv3/path-resources.ts
@@ -1,16 +1,16 @@
import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder";
-import {ComponentType} from "@angular/cdk/overlay";
+import {Constructor} from "@angular/cdk/table";
-export class SimpleResourceCollection<T extends SimpleResource = SimpleResource> {
+export class SimpleResourceCollection<T = SimpleResource> {
// Base path
public readonly path:string;
- constructor(protected basePath:string, segment:string, protected resource:ComponentType<SimpleResource> = SimpleResource) {
+ constructor(protected basePath:string, readonly segment:string, protected resource?:Constructor<T>) {
this.path = `${this.basePath}/${segment}`;
}
public id(id:string|number):T {
- return new this.resource(this.path, id) as T;
+ return new (this.resource || SimpleResource)(this.path, id) as T;
}
public optionalId(id?:string|number):this|T {
@@ -37,7 +37,7 @@ export class SimpleResourceCollection<T extends SimpleResource = SimpleResource>
export class SimpleResource {
public readonly path:string;
- constructor(protected basePath:string, id:string|number) {
+ constructor(protected basePath:string, readonly id:string|number) {
this.path = `${this.basePath}/${id}`;
}
diff --git a/frontend/src/app/modules/hal/hal-link/hal-link.ts b/frontend/src/app/modules/hal/hal-link/hal-link.ts
index b1daaaaada0..b0813071c73 100644
--- a/frontend/src/app/modules/hal/hal-link/hal-link.ts
+++ b/frontend/src/app/modules/hal/hal-link/hal-link.ts
@@ -27,10 +27,11 @@
//++
import {HalResource} from 'core-app/modules/hal/resources/hal-resource';
-import {HalResourceService, HTTPSupportedMethods} from 'core-app/modules/hal/services/hal-resource.service';
+import {HTTPSupportedMethods} from "core-app/modules/hal/http/http.interfaces";
+import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";
export interface HalLinkInterface {
- href:string | null;
+ href:string|null;
method:HTTPSupportedMethods;
title?:string;
templated?:boolean;
@@ -51,7 +52,7 @@ export interface CallableHalLink extends HalLinkInterface {
export class HalLink implements HalLinkInterface {
constructor(public requestMethod:(method:HTTPSupportedMethods, href:string, data:any, headers:any) => Promise<HalResource>,
- public href:string | null = null,
+ public href:string|null = null,
public title:string = '',
public method:HTTPSupportedMethods = 'get',
public templated:boolean = false,
@@ -65,7 +66,7 @@ export class HalLink implements HalLinkInterface {
*/
public static fromObject(halResourceService:HalResourceService, link:HalLinkInterface):HalLink {
return new HalLink(
- (method:HTTPSupportedMethods, href:string, data:any, headers:any) =>
+ (method:HTTPSupportedMethods, href:string, data:any, headers:any) =>
halResourceService.request(method, href, data, headers).toPromise(),
link.href,
link.title,
diff --git a/frontend/src/app/modules/hal/http/http.interfaces.ts b/frontend/src/app/modules/hal/http/http.interfaces.ts
new file mode 100644
index 00000000000..4c4bce1b5e9
--- /dev/null
+++ b/frontend/src/app/modules/hal/http/http.interfaces.ts
@@ -0,0 +1,17 @@
+import {HttpHeaders, HttpParams} from "@angular/common/http";
+
+export type HTTPSupportedMethods = 'get'|'post'|'put'|'patch'|'delete';
+
+export interface HTTPClientOptions {
+ body?:any;
+ headers?:HTTPClientHeaders;
+ observe?:any;
+ params?:HTTPClientParams;
+ reportProgress?:boolean;
+ withCredentials?:boolean;
+ responseType:any;
+}
+
+export type HTTPClientParamMap = { [key:string]:any };
+export type HTTPClientHeaders = HttpHeaders|HTTPClientParamMap;
+export type HTTPClientParams = HttpParams|HTTPClientParamMap;
\ No newline at end of file
diff --git a/frontend/src/app/modules/hal/services/hal-resource.service.ts b/frontend/src/app/modules/hal/services/hal-resource.service.ts
index 9fa117c8474..f018fb1feb4 100644
--- a/frontend/src/app/modules/hal/services/hal-resource.service.ts
+++ b/frontend/src/app/modules/hal/services/hal-resource.service.ts
@@ -27,7 +27,7 @@
//++
import {Injectable, Injector} from '@angular/core';
-import {HttpClient, HttpErrorResponse, HttpHeaders, HttpParams} from '@angular/common/http';
+import {HttpClient, HttpErrorResponse, HttpParams} from '@angular/common/http';
import {throwError} from 'rxjs/internal/observable/throwError';
import {catchError, map} from 'rxjs/operators';
import {Observable} from 'rxjs';
@@ -38,27 +38,18 @@ import {initializeHalProperties} from 'core-app/modules/hal/helpers/hal-resource
import {URLParamsEncoder} from 'core-app/modules/hal/services/url-params-encoder';
import {ErrorResource} from "core-app/modules/hal/resources/error-resource";
import * as Pako from 'pako';
+import {
+ HTTPClientHeaders,
+ HTTPClientOptions,
+ HTTPClientParamMap,
+ HTTPSupportedMethods
+} from "core-app/modules/hal/http/http.interfaces";
export interface HalResourceFactoryConfigInterface {
cls?:any;
attrTypes?:{ [attrName:string]:string };
}
-export type HTTPSupportedMethods = 'get'|'post'|'put'|'patch'|'delete';
-
-export interface HTTPClientOptions {
- body?:any;
- headers?:HttpHeaders|{
- [header:string]:string|string[];
- };
- observe?:any;
- params?:HttpParams|{
- [param:string]:string|string[];
- };
- reportProgress?:boolean;
- withCredentials?:boolean;
- responseType:any;
-}
@Injectable({ providedIn: 'root' })
export class HalResourceService {
@@ -75,7 +66,7 @@ export class HalResourceService {
/**
* Perform a HTTP request and return a HalResource promise.
*/
- public request<T extends HalResource>(method:HTTPSupportedMethods, href:string, data?:any, headers:any = {}):Observable<T> {
+ public request<T extends HalResource>(method:HTTPSupportedMethods, href:string, data?:any, headers:HTTPClientHeaders = {}):Observable<T> {
// HttpClient requires us to create HttpParams instead of passing data for get
// so forward to that method instead.
@@ -114,7 +105,7 @@ export class HalResourceService {
* @param headers
* @returns {Promise<HalResource>}
*/
- public get<T extends HalResource>(href:string, params?:any, headers?:any):Observable<T> {
+ public get<T extends HalResource>(href:string, params?:HTTPClientParamMap, headers?:HTTPClientHeaders):Observable<T> {
const config:HTTPClientOptions = {
headers: headers,
params: new HttpParams({ encoder: new URLParamsEncoder(), fromObject: params }),
@@ -135,7 +126,7 @@ export class HalResourceService {
* @param headers
* @return {Promise<CollectionResource[]>}
*/
- public async getAllPaginated<T extends HalResource[]>(href:string, expected:number, params:any = {}, headers:any = {}) {
+ public async getAllPaginated<T extends HalResource[]>(href:string, expected:number, params:any = {}, headers:HTTPClientHeaders = {}) {
// Total number retrieved
let retrieved = 0;
// Current offset page
@@ -171,7 +162,7 @@ export class HalResourceService {
* @param headers
* @returns {Promise<HalResource>}
*/
- public put<T extends HalResource>(href:string, data?:any, headers?:any):Observable<T> {
+ public put<T extends HalResource>(href:string, data?:any, headers?:HTTPClientHeaders):Observable<T> {
return this.request('put', href, data, headers);
}
@@ -183,7 +174,7 @@ export class HalResourceService {
* @param headers
* @returns {Promise<HalResource>}
*/
- public post<T extends HalResource>(href:string, data?:any, headers?:any):Observable<T> {
+ public post<T extends HalResource>(href:string, data?:any, headers?:HTTPClientHeaders):Observable<T> {
return this.request('post', href, data, headers);
}
@@ -195,7 +186,7 @@ export class HalResourceService {
* @param headers
* @returns {Promise<HalResource>}
*/
- public patch<T extends HalResource>(href:string, data?:any, headers?:any):Observable<T> {
+ public patch<T extends HalResource>(href:string, data?:any, headers?:HTTPClientHeaders):Observable<T> {
return this.request('patch', href, data, headers);
}
@@ -207,7 +198,7 @@ export class HalResourceService {
* @param headers
* @returns {Promise<HalResource>}
*/
- public delete<T extends HalResource>(href:string, data?:any, headers?:any):Observable<T> {
+ public delete<T extends HalResource>(href:string, data?:any, headers?:HTTPClientHeaders):Observable<T> {
return this.request('delete', href, data, headers);
}
@@ -286,7 +277,7 @@ export class HalResourceService {
* @param href Self link of the HAL resource
*/
public fromSelfLink(href:string|null) {
- const source = { _links: { self: { href: href }}};
+ const source = { _links: { self: { href: href } } };
return this.createHalResource(source);
}