@uiowa/universal-workflow
Version:
universal-workflow, uiowa-universal-workflow, universal workflow
189 lines (181 loc) • 8.75 kB
JavaScript
import * as i0 from '@angular/core';
import { Injectable, Inject, Component, Input, NgModule } from '@angular/core';
import { shareReplay, forkJoin, ReplaySubject, finalize } from 'rxjs';
import { DOCUMENT, CommonModule } from '@angular/common';
import * as i1 from '@angular/common/http';
import * as i2 from '@uiowa/spinner';
import { SpinnerModule } from '@uiowa/spinner';
class WorkflowService {
constructor(httpClient, document) {
this.httpClient = httpClient;
this.document = document;
this.api = 'api/workflow';
this._loadedLibraries = {};
this.today = new Date();
}
getWorkflowWidgetConfig() {
if (!this._widgetConfig$) {
this._widgetConfig$ = this.httpClient
.get(`${this.api}/widget-config`)
.pipe(shareReplay(1));
}
return this._widgetConfig$;
}
getPackageRoutingHistory(packageId) {
return this.httpClient.get(`${this.api}/packages/${packageId}/routing-history`);
}
lazyLoadWorkflowWidget() {
return this.loadScript('https://workflow.uiowa.edu/workflow-widget/workflow.js?ver=' +
new Date().getTime());
}
lazyLoadHistoryWidget() {
return forkJoin([
this.loadScript('https://workflow.uiowa.edu/workflow-widget/historyFormat.js?ver=' +
this.today.getTime()),
this.loadScript('https://workflow.uiowa.edu/workflow-widget/assets/js/workflow-widget-route-table.js?ver=' +
this.today.getTime()),
this.loadScript('https://code.jquery.com/jquery-3.6.0.min.js'),
this.loadScript('https://workflow.uiowa.edu/workflow-widget/assets/js/moment/moment.2.7.0.js'),
]);
}
loadScript(url) {
if (this._loadedLibraries[url]) {
return this._loadedLibraries[url].asObservable();
}
this._loadedLibraries[url] = new ReplaySubject();
const script = this.document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = url;
script.onload = () => {
this._loadedLibraries[url].next(1);
this._loadedLibraries[url].complete();
};
this.document.body.appendChild(script);
return this._loadedLibraries[url].asObservable();
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.5", ngImport: i0, type: WorkflowService, deps: [{ token: i1.HttpClient }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.5", ngImport: i0, type: WorkflowService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.5", ngImport: i0, type: WorkflowService, decorators: [{
type: Injectable,
args: [{ providedIn: 'root' }]
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: Document, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }] });
class WorkflowWidgetComponent {
constructor(svc) {
this.svc = svc;
this.packageId = 0;
this.signatureId = '';
this.loading = false;
}
ngOnInit() {
this.loading = true;
this.svc.getWorkflowWidgetConfig().subscribe((c) => {
window.WorkflowWidget = {
form_id: c.formId,
package_id: this.packageId,
scope: c.scope,
client_id: c.clientId,
environment: c.workflowEnvironment,
signature_id: this.signatureId,
post_sign_void: '',
post_version_mismatch: '',
};
this.svc
.lazyLoadWorkflowWidget()
.pipe(finalize(() => (this.loading = false)))
.subscribe();
});
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.5", ngImport: i0, type: WorkflowWidgetComponent, deps: [{ token: WorkflowService }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.0.5", type: WorkflowWidgetComponent, selector: "workflow-widget", inputs: { packageId: "packageId", signatureId: "signatureId" }, ngImport: i0, template: `
{
<div style="height: 20rem">
<loading-placeholder></loading-placeholder>
</div>
}
<div id="workflowWidgetContainer"></div>
`, isInline: true, dependencies: [{ kind: "component", type: i2.LoadingPlaceholderComponent, selector: "loading-placeholder" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.5", ngImport: i0, type: WorkflowWidgetComponent, decorators: [{
type: Component,
args: [{ selector: 'workflow-widget', template: `
{
<div style="height: 20rem">
<loading-placeholder></loading-placeholder>
</div>
}
<div id="workflowWidgetContainer"></div>
` }]
}], ctorParameters: () => [{ type: WorkflowService }], propDecorators: { packageId: [{
type: Input
}], signatureId: [{
type: Input
}] } });
class UwRoutingHistoryComponent {
constructor(svc) {
this.svc = svc;
this.packageId = 0;
this.loading = false;
this.routingHistoryString = '';
}
ngOnInit() {
this.loading = true;
this.svc.lazyLoadHistoryWidget().subscribe((_) => {
this.svc
.getPackageRoutingHistory(this.packageId || 0)
.pipe(finalize(() => (this.loading = false)))
.subscribe((x) => {
this.routingHistoryString = formatWorkflowHistory(x, this.packageId || 0);
});
});
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.5", ngImport: i0, type: UwRoutingHistoryComponent, deps: [{ token: WorkflowService }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.0.5", type: UwRoutingHistoryComponent, selector: "uw-routing-history", inputs: { packageId: "packageId" }, ngImport: i0, template: `
{
<div style="height: 20rem">
<loading-placeholder></loading-placeholder>
</div>
} {
<div id="routingHistory" [innerHtml]="routingHistoryString"></div>
}
`, isInline: true, dependencies: [{ kind: "component", type: i2.LoadingPlaceholderComponent, selector: "loading-placeholder" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.5", ngImport: i0, type: UwRoutingHistoryComponent, decorators: [{
type: Component,
args: [{ selector: 'uw-routing-history', template: `
{
<div style="height: 20rem">
<loading-placeholder></loading-placeholder>
</div>
} {
<div id="routingHistory" [innerHtml]="routingHistoryString"></div>
}
` }]
}], ctorParameters: () => [{ type: WorkflowService }], propDecorators: { packageId: [{
type: Input
}] } });
class UniversalWorkflowModule {
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.5", ngImport: i0, type: UniversalWorkflowModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.5", ngImport: i0, type: UniversalWorkflowModule, declarations: [WorkflowWidgetComponent, UwRoutingHistoryComponent], imports: [CommonModule, SpinnerModule], exports: [WorkflowWidgetComponent, UwRoutingHistoryComponent] }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.5", ngImport: i0, type: UniversalWorkflowModule, imports: [CommonModule, SpinnerModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.5", ngImport: i0, type: UniversalWorkflowModule, decorators: [{
type: NgModule,
args: [{
declarations: [WorkflowWidgetComponent, UwRoutingHistoryComponent],
imports: [CommonModule, SpinnerModule],
exports: [WorkflowWidgetComponent, UwRoutingHistoryComponent],
}]
}] });
/*
* Public API Surface of universal-workflow
*/
/**
* Generated bundle index. Do not edit.
*/
export { UniversalWorkflowModule, UwRoutingHistoryComponent, WorkflowService, WorkflowWidgetComponent };
//# sourceMappingURL=uiowa-universal-workflow.mjs.map