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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[40656] Use APIv3 service to access backups API
Oliver Günther5391a9a37ec0
diff --git a/frontend/src/app/core/apiv3/api-v3.service.ts b/frontend/src/app/core/apiv3/api-v3.service.tsindex be455f65fe9..fb3c4abd1b5 100644--- a/frontend/src/app/core/apiv3/api-v3.service.ts+++ b/frontend/src/app/core/apiv3/api-v3.service.ts@@ -26,8 +26,14 @@// See COPYRIGHT and LICENSE files for more details.//++-import { Injectable, Injector } from '@angular/core';-import { APIv3GettableResource, APIv3ResourceCollection } from 'core-app/core/apiv3/paths/apiv3-resource';+import {+ Injectable,+ Injector,+} from '@angular/core';+import {+ APIv3GettableResource,+ APIv3ResourceCollection,+} from 'core-app/core/apiv3/paths/apiv3-resource';import { Constructor } from '@angular/cdk/table';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { Apiv3GridsPaths } from 'core-app/core/apiv3/endpoints/grids/apiv3-grids-paths';@@ -53,12 +59,16 @@ import { Apiv3PlaceholderUsersPaths } from 'core-app/core/apiv3/endpoints/placehimport { Apiv3GroupsPaths } from 'core-app/core/apiv3/endpoints/groups/apiv3-groups-paths';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { Apiv3NotificationsPaths } from 'core-app/core/apiv3/endpoints/notifications/apiv3-notifications-paths';+import { Apiv3BackupsPath } from 'core-app/core/apiv3/endpoints/backups/apiv3-backups-path';@Injectable({ providedIn: 'root' })export class APIV3Service {// /api/v3/attachmentspublic readonly attachments = this.apiV3CollectionEndpoint('attachments');+ // /api/v3/backups+ public readonly backups = this.apiV3CustomEndpoint(Apiv3BackupsPath);+// /api/v3/configurationpublic readonly configuration = this.apiV3CustomEndpoint(Apiv3ConfigurationPath);diff --git a/frontend/src/app/core/apiv3/endpoints/backups/apiv3-backups-path.ts b/frontend/src/app/core/apiv3/endpoints/backups/apiv3-backups-path.tsnew file mode 100644index 00000000000..dcb6de1caf3--- /dev/null+++ b/frontend/src/app/core/apiv3/endpoints/backups/apiv3-backups-path.ts@@ -0,0 +1,49 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2021 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 COPYRIGHT and LICENSE files for more details.+//++++import { APIv3GettableResource } from 'core-app/core/apiv3/paths/apiv3-resource';+import { ConfigurationResource } from 'core-app/features/hal/resources/configuration-resource';+import { Observable } from 'rxjs';+import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';+import { HalResource } from 'core-app/features/hal/resources/hal-resource';++export class Apiv3BackupsPath extends APIv3GettableResource<ConfigurationResource> {+ constructor(protected apiRoot:APIV3Service,+ readonly basePath:string) {+ super(apiRoot, basePath, 'backups');+ }++ public post(backupToken:string, includeAttachments:boolean):Observable<HalResource> {+ return this+ .halResourceService+ .post(+ this.path,+ { backupToken, attachments: includeAttachments },+ );+ }+}diff --git a/frontend/src/app/core/backup/op-backup.service.ts b/frontend/src/app/core/backup/op-backup.service.tsindex 3ce1c3ccd06..32010a73962 100644--- a/frontend/src/app/core/backup/op-backup.service.ts+++ b/frontend/src/app/core/backup/op-backup.service.ts@@ -27,28 +27,21 @@//++import { Injectable } from '@angular/core';-import { HttpClient } from '@angular/common/http';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { Observable } from 'rxjs';-import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';+import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';@Injectable({ providedIn: 'root' })export class OpenProjectBackupService {- constructor(protected http:HttpClient,- protected halResource:HalResourceService) {+ constructor(+ protected apiV3Service:APIV3Service,+ ) {}public triggerBackup(backupToken:string, includeAttachments = true):Observable<HalResource> {return this- .http- .request<HalResource>(- 'post',- '/api/v3/backups',- {- body: { backupToken, attachments: includeAttachments },- withCredentials: true,- responseType: 'json' as any,- },- );+ .apiV3Service+ .backups+ .post(backupToken, includeAttachments);}}diff --git a/frontend/src/app/core/setup/globals/components/admin/backup.component.ts b/frontend/src/app/core/setup/globals/components/admin/backup.component.tsindex 2cc5e0c63ae..8ae87c1bce6 100644--- a/frontend/src/app/core/setup/globals/components/admin/backup.component.ts+++ b/frontend/src/app/core/setup/globals/components/admin/backup.component.ts@@ -28,7 +28,11 @@import { HttpErrorResponse } from '@angular/common/http';import {- AfterViewInit, Component, ElementRef, Injector, ViewChild,+ AfterViewInit,+ Component,+ ElementRef,+ Injector,+ ViewChild,} from '@angular/core';import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';import { I18nService } from 'core-app/core/i18n/i18n.service';@@ -37,6 +41,8 @@ import { JobStatusModalComponent } from 'core-app/features/job-status/job-statusimport { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { OpModalService } from 'core-app/shared/components/modal/modal.service';import { OpenProjectBackupService } from 'core-app/core/backup/op-backup.service';+import { HalResource } from 'core-app/features/hal/resources/hal-resource';+import { HalError } from 'core-app/features/hal/services/hal-error';export const backupSelector = 'backup';@@ -120,13 +126,14 @@ export class BackupComponent implements AfterViewInit {this.opBackup.triggerBackup(backupToken, this.includeAttachments)- .toPromise()- .then((resp:any) => {- this.jobStatusId = resp.jobStatusId;- this.opModalService.show(JobStatusModalComponent, 'global', { jobId: resp.jobStatusId });- })- .catch((error:HttpErrorResponse) => {- this.toastService.addError(error.error);- });+ .subscribe(+ (resp:HalResource) => {+ this.jobStatusId = resp.jobStatusId;+ this.opModalService.show(JobStatusModalComponent, 'global', { jobId: resp.jobStatusId });+ },+ (error:HalError) => {+ this.toastService.addError(error.message);+ },+ );}}