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

Add frontend for job status

Oliver Güntherc9ef067c5eac
diff --git a/frontend/src/app/components/op-modals/op-modal.component.ts b/frontend/src/app/components/op-modals/op-modal.component.ts
index 9e7375c29a0..d6b69d8cf6f 100644
--- a/frontend/src/app/components/op-modals/op-modal.component.ts
+++ b/frontend/src/app/components/op-modals/op-modal.component.ts
@@ -1,8 +1,9 @@
import {ChangeDetectorRef, ElementRef, EventEmitter, OnDestroy, OnInit} from '@angular/core';
import {OpModalLocalsMap} from 'core-components/op-modals/op-modal.types';
import {OpModalService} from 'core-components/op-modals/op-modal.service';
+import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";
-export abstract class OpModalComponent implements OnInit, OnDestroy {
+export abstract class OpModalComponent extends UntilDestroyedMixin implements OnInit, OnDestroy {
/* Close on escape? */
public closeOnEscape:boolean = true;
@@ -21,9 +22,10 @@ export abstract class OpModalComponent implements OnInit, OnDestroy {
public openingEvent = new EventEmitter<this>();
- constructor(public locals:OpModalLocalsMap,
+ protected constructor(public locals:OpModalLocalsMap,
readonly cdRef:ChangeDetectorRef,
readonly elementRef:ElementRef) {
+ super();
}
ngOnInit() {
diff --git a/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts b/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts
index eff9af71761..84ba50d6dde 100644
--- a/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts
+++ b/frontend/src/app/modules/common/path-helper/apiv3/apiv3-paths.ts
@@ -102,6 +102,8 @@ export class ApiV3Paths {
// /api/v3/groups
public readonly groups = new Apiv3GroupsPaths(this.apiV3Base);
+ // /api/v3/job_statuses
+ public readonly job_statuses = new SimpleResourceCollection(this.apiV3Base, 'job_statuses');
constructor(readonly appBasePath:string) {
}
diff --git a/frontend/src/app/modules/job-status/display-job-page/display-job-page.component.html b/frontend/src/app/modules/job-status/display-job-page/display-job-page.component.html
deleted file mode 100644
index 9ebdca9828f..00000000000
--- a/frontend/src/app/modules/job-status/display-job-page/display-job-page.component.html
+++ /dev/null
@@ -1 +0,0 @@
-Hello {{jobId}}
\ No newline at end of file
diff --git a/frontend/src/app/modules/job-status/display-job-page/display-job-page.component.ts b/frontend/src/app/modules/job-status/display-job-page/display-job-page.component.ts
index eb0ae635413..88d79f44ecf 100644
--- a/frontend/src/app/modules/job-status/display-job-page/display-job-page.component.ts
+++ b/frontend/src/app/modules/job-status/display-job-page/display-job-page.component.ts
@@ -1,12 +1,25 @@
-import {Component} from "@angular/core";
+import {AfterViewInit, Component, Injector, OnDestroy} from "@angular/core";
import {StateService} from "@uirouter/core";
+import {OpModalService} from "core-components/op-modals/op-modal.service";
+import {OpModalComponent} from "core-components/op-modals/op-modal.component";
+import {JobStatusModal} from "core-app/modules/job-status/job-status-modal/job-status.modal";
@Component({
- templateUrl: './display-job-page.component.html'
+ template: ''
})
-export class DisplayJobPageComponent {
- jobId:string = this.$state.params.jobId;
+export class DisplayJobPageComponent implements AfterViewInit, OnDestroy {
+ private modal?:OpModalComponent;
- constructor(private $state:StateService) {
+ constructor(private injector:Injector,
+ private $state:StateService,
+ private modalService:OpModalService) {
+ }
+
+ ngAfterViewInit() {
+ this.modal = this.modalService.show(JobStatusModal, this.injector, { jobId: this.$state.params.jobId });
+ }
+
+ ngOnDestroy() {
+ this.modal?.closeMe();
}
}
\ No newline at end of file
diff --git a/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.html b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.html
new file mode 100644
index 00000000000..b30f71d1e4f
--- /dev/null
+++ b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.html
@@ -0,0 +1,37 @@
+<div class="op-modal--portal">
+ <div class="op-modal--modal-container wp-table--configuration-modal"
+ tabindex="0">
+ <div class="op-modal--modal-header">
+ <a class="op-modal--modal-close-button">
+ <i
+ class="icon-close"
+ (click)="closeMe($event)"
+ [attr.title]="text.closePopup">
+ </i>
+ </a>
+ </div>
+
+ <h3 [textContent]="text.title"></h3>
+
+ <div>
+ <div class="loading-indicator--location"
+ data-indicator-name="modal">
+ <div class="status-icon-wrapper" *ngIf="!isLoading">
+ <ng-container [ngSwitch]="status">
+ <span *ngSwitchCase="'error'" class="icon-big icon-error"></span>
+ <span *ngSwitchCase="'success'" class="icon-big icon-checkmark"></span>
+ </ng-container>
+ </div>
+ </div>
+ <div [textContent]="message"></div>
+ </div>
+
+ <a #downloadLink
+ id="download-link"
+ [title]="'Export'"
+ class="button"
+ download
+ [attr.href]="downloadHref">
+ </a>
+ </div>
+</div>
diff --git a/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.sass b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.sass
new file mode 100644
index 00000000000..b4e1412e099
--- /dev/null
+++ b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.sass
@@ -0,0 +1,12 @@
+#download-link
+ display: none
+
+.loading-indicator--location
+ height: 220px
+
+.status-icon-wrapper
+ display: flex
+ height: 100%
+ align-items: center
+ justify-content: center
+
diff --git a/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts
new file mode 100644
index 00000000000..4f388af4473
--- /dev/null
+++ b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts
@@ -0,0 +1,117 @@
+import {ChangeDetectorRef, Component, ElementRef, Inject, OnInit} from '@angular/core';
+import {OpModalLocalsMap} from 'core-components/op-modals/op-modal.types';
+import {OpModalComponent} from 'core-components/op-modals/op-modal.component';
+import {I18nService} from "core-app/modules/common/i18n/i18n.service";
+import {OpModalLocalsToken} from "core-components/op-modals/op-modal.service";
+import {HttpClient} from '@angular/common/http';
+import {interval, Observable, timer} from "rxjs";
+import {map, switchMap, takeUntil, takeWhile} from "rxjs/operators";
+import {
+ LoadingIndicatorService,
+ withDelayedLoadingIndicator
+} from "core-app/modules/common/loading-indicator/loading-indicator.service";
+import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";
+import {JobStatusEnum, JobStatusInterface} from "core-app/modules/job-status/job-status.interface";
+import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";
+
+
+@Component({
+ templateUrl: './job-status.modal.html',
+ styleUrls: ['./job-status.modal.sass']
+})
+export class JobStatusModal extends OpModalComponent implements OnInit {
+
+ /* Close on escape? */
+ public closeOnEscape = false;
+
+ /* Close on outside click */
+ public closeOnOutsideClick = false;
+
+ public text = {
+ title: this.I18n.t('js.job_status.title'),
+ closePopup: this.I18n.t('js.close_popup_title'),
+ exportPreparing: this.I18n.t('js.label_export_preparing')
+ };
+
+ /** The job ID reference */
+ public jobId:string;
+
+ /** Whether to show the loading indicator */
+ public isLoading = false;
+
+ /** The current status */
+ public status:JobStatusEnum;
+
+ /** Public message to show */
+ public message:string;
+
+ /** A link in case the job results in a download */
+ public downloadHref:string|null = null;
+
+ constructor(@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
+ readonly cdRef:ChangeDetectorRef,
+ readonly I18n:I18nService,
+ readonly elementRef:ElementRef,
+ readonly pathHelper:PathHelperService,
+ readonly loadingIndicator:LoadingIndicatorService,
+ readonly notifications:NotificationsService,
+ readonly httpClient:HttpClient) {
+ super(locals, cdRef, elementRef);
+
+ this.jobId = locals.jobId;
+ }
+
+ ngOnInit() {
+ super.ngOnInit();
+ this.listenOnJobStatus();
+ }
+
+ private listenOnJobStatus() {
+ this.isLoading = true;
+
+ timer(0, 2000)
+ .pipe(
+ switchMap(() => this.performRequest()),
+ takeWhile(response => this.continuedStatus(response), true),
+ this.untilDestroyed(),
+ withDelayedLoadingIndicator(this.loadingIndicator.getter('modal')),
+ ).subscribe(
+ object => this.onResponse(object),
+ error => this.handleError(error.message),
+ () => this.isLoading = false
+ );
+ }
+
+ /**
+ * Determine whether the given status continues the timer
+ * @param response
+ */
+ private continuedStatus(response:JobStatusInterface) {
+ return ['in_queue', 'in_process'].includes(response.status);
+ }
+
+ private onResponse(response:JobStatusInterface) {
+ let status = this.status = response.status;
+ this.message = response.message ||
+ this.I18n.t(`js.job_status.generic_messages.${status}`, { defaultValue: status });
+
+ this.cdRef.detectChanges();
+ }
+
+ private performRequest():Observable<JobStatusInterface> {
+ return this
+ .httpClient
+ .get<JobStatusInterface>(
+ this.jobUrl,
+ { observe: 'body', responseType: 'json' }
+ );
+ }
+
+ private handleError(error:string|null|undefined) {
+ this.notifications.addError(error || this.I18n.t('js.error.internal'));
+ }
+
+ private get jobUrl():string {
+ return this.pathHelper.api.v3.job_statuses.id(this.jobId).toString();
+ }
+}
diff --git a/frontend/src/app/modules/job-status/job-status.interface.ts b/frontend/src/app/modules/job-status/job-status.interface.ts
new file mode 100644
index 00000000000..81b27afe1fe
--- /dev/null
+++ b/frontend/src/app/modules/job-status/job-status.interface.ts
@@ -0,0 +1,26 @@
+export type JobStatusEnum = 'in_queue'|'error'|'in_process'|'success'|'failure'|'cancelled' ;
+
+export interface JobStatusInterface {
+ /**
+ * Status
+ */
+ status:JobStatusEnum;
+
+ /**
+ * The job id
+ */
+ jobId:string;
+
+ /**
+ * Message for the current status, if any
+ */
+ message?:string;
+
+ /**
+ * Additional payload object
+ */
+ payload?:{
+ download?:string;
+ redirectTo?:string;
+ };
+}
\ No newline at end of file
diff --git a/frontend/src/app/modules/job-status/openproject-job-status.module.ts b/frontend/src/app/modules/job-status/openproject-job-status.module.ts
index e2e90c3d264..78810515d2c 100644
--- a/frontend/src/app/modules/job-status/openproject-job-status.module.ts
+++ b/frontend/src/app/modules/job-status/openproject-job-status.module.ts
@@ -28,16 +28,9 @@
import {OpenprojectCommonModule} from 'core-app/modules/common/openproject-common.module';
import {NgModule} from '@angular/core';
-import {FullCalendarModule} from '@fullcalendar/angular';
-import {WorkPackagesCalendarEntryComponent} from "core-app/modules/calendar/wp-calendar-entry/wp-calendar-entry.component";
-import {WorkPackagesCalendarController} from "core-app/modules/calendar/wp-calendar/wp-calendar.component";
-import {OpenprojectWorkPackagesModule} from "core-app/modules/work_packages/openproject-work-packages.module";
import {Ng2StateDeclaration, UIRouterModule} from "@uirouter/angular";
-import {TimeEntryCalendarComponent} from "core-app/modules/calendar/te-calendar/te-calendar.component";
-import {OpenprojectFieldsModule} from "core-app/modules/fields/openproject-fields.module";
-import {OpenprojectTimeEntriesModule} from "core-app/modules/time_entries/openproject-time-entries.module";
import {DisplayJobPageComponent} from "core-app/modules/job-status/display-job-page/display-job-page.component";
-import {ApplicationBaseComponent} from "core-app/modules/router/base/application-base.component";
+import {JobStatusModal} from "core-app/modules/job-status/job-status-modal/job-status.modal";
export const JOB_STATUS_ROUTE:Ng2StateDeclaration[] = [
{
@@ -61,7 +54,8 @@ export const JOB_STATUS_ROUTE:Ng2StateDeclaration[] = [
],
declarations: [
- DisplayJobPageComponent
+ DisplayJobPageComponent,
+ JobStatusModal
]
})
export class OpenProjectJobStatusModule {
diff --git a/modules/job_status/config/locales/js-en.yml b/modules/job_status/config/locales/js-en.yml
new file mode 100644
index 00000000000..8d0d555a633
--- /dev/null
+++ b/modules/job_status/config/locales/js-en.yml
@@ -0,0 +1,10 @@
+en:
+ js:
+ job_status:
+ title: 'Background job status'
+ generic_messages:
+ in_queue: 'The job has been queued and will be processed shortly.'
+ in_process: 'The job is currently being processed.'
+ error: 'The job has failed to complete.'
+ cancelled: 'The job has been cancelled due to an error.'
+ success: 'The job completed successfully.'
diff --git a/modules/job_status/lib/api/v3/job_status/job_status_api.rb b/modules/job_status/lib/api/v3/job_status/job_status_api.rb
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/modules/job_status/lib/api/v3/job_status/job_status_representer.rb b/modules/job_status/lib/api/v3/job_status/job_status_representer.rb
new file mode 100644
index 00000000000..6bc21e5b892
--- /dev/null
+++ b/modules/job_status/lib/api/v3/job_status/job_status_representer.rb
@@ -0,0 +1,49 @@
+#-- 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-2017 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.
+#++
+
+module API
+ module V3
+ module CostTypes
+ class CostTypeRepresenter < ::API::Decorators::Single
+ self_link
+ property :id, render_nil: true
+ property :name, render_nil: true
+ property :unit,
+ render_nil: true
+ property :unit_plural,
+ render_nil: true
+ property :is_default,
+ getter: ->(*) { default }
+
+ def _type
+ 'CostType'
+ end
+ end
+ end
+ end
+end