Extend plugin context for use in actual plugins

pull/6376/head
Oliver Günther 6 years ago
parent c60eb93acb
commit 4ce28cf898
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 2
      frontend/legacy/app/components/help-texts/attribute-help-text.directive.ts
  2. 2
      frontend/legacy/app/components/modals/confirm-form-submit/confirm-form-submit.directive.ts
  3. 2
      frontend/legacy/app/components/modals/modal-wrapper/modal-wrapper.directive.ts
  4. 2
      frontend/legacy/app/components/modals/request-for-confirmation/request-for-confirmation.directive.ts
  5. 2
      frontend/legacy/app/components/type-configuration/type-configuration.controller.ts
  6. 17
      frontend/legacy/app/services/plugin-context.service.ts
  7. 8
      frontend/legacy/typings/open-project-legacy.typings.d.ts
  8. 75
      frontend/src/app/components/api/op-file-upload/op-file-upload.service.ts
  9. 18
      frontend/src/app/modules/plugins/plugin-context.ts

@ -49,7 +49,7 @@ export class AttributeHelpTextController {
constructor(protected $element:IAugmentedJQuery,
protected $scope:angular.IScope) {
window.OpenProject.pluginContext.valuesPromise().then((context) => {
window.OpenProject.getPluginContext().then((context) => {
this.i18n = context.services.i18n;
this.helpTextDm = context.services.helpTextDm;
this.opModal = context.services.opModalService;

@ -41,7 +41,7 @@ export class ConfirmFormSubmitController {
private I18n:any;
constructor(protected $element:IAugmentedJQuery) {
window.OpenProject.pluginContext.valuesPromise().then((context) => {
window.OpenProject.getPluginContext().then((context) => {
this.confirmDialog = context.services.confirmDialog;
this.I18n = context.services.i18n;

@ -41,7 +41,7 @@ export class ModalWrapperController {
constructor(protected $element:ng.IAugmentedJQuery,
protected $attrs:ng.IAttributes) {
window.OpenProject.pluginContext.valuesPromise().then((context) => {
window.OpenProject.getPluginContext().then((context) => {
this.opModalService = context.services.opModalService;
this.dynamicContentModal = context.classes.modals.dynamicContent;

@ -40,7 +40,7 @@ export class RequestForConfirmationController {
readonly $timeout:ng.ITimeoutService,
readonly $scope:ng.IScope) {
window.OpenProject.pluginContext.valuesPromise().then((context) => {
window.OpenProject.getPluginContext().then((context) => {
this.opModalService = context.services.opModalService;
this.passwordConfirmationModal = context.classes.modals.passwordConfirmation;
});

@ -42,7 +42,7 @@ function typesFormConfigurationCtrl(
let externalQueryConfiguration:any;
let I18n:any;
window.OpenProject.pluginContext.valuesPromise().then((context) => {
window.OpenProject.getPluginContext().then((context) => {
confirmDialog = context.services.confirmDialog;
NotificationsService = context.services.notifications;
externalQueryConfiguration = context.services.externalQueryConfiguration;

@ -0,0 +1,17 @@
// Need to re-use this from typings of the actual context if at all possible
import {openprojectLegacyModule} from "core-app/openproject-legacy-app";
import {IPluginContext} from "../../typings/open-project-legacy.typings";
export class PluginContextService {
public context?:IPluginContext;
constructor() {
window.OpenProject.getPluginContext().then((context:IPluginContext) => this.context = context!);
}
public getContext():Promise<IPluginContext> {
return (window as any).OpenProject.getPluginContext();
}
}
openprojectLegacyModule.service('pluginContext', PluginContextService);

@ -35,13 +35,19 @@ import * as TAngular from 'angular';
import * as TLodash from 'lodash';
import {State} from "reactivestates";
export interface IPluginContext {
classes:any;
services:any;
}
declare global {
interface Window {
appBasePath:string;
OpenProject:{
guardedLocalStorage(key:string, newValue?:string):string|void,
environment:string,
pluginContext:State<any>
getPluginContext():Promise<IPluginContext>,
pluginContext:State<IPluginContext>
};
}
const angular:typeof TAngular;

@ -56,45 +56,54 @@ export class OpenProjectFileUploadService {
* Upload multiple files using `ngFileUpload` and return a single promise.
* Ignore directories.
*/
public upload(url:string, files:UploadFile[]):UploadResult {
public upload(url:string, files:UploadFile[], method:string = 'post'):UploadResult {
files = _.filter(files, (file:UploadFile) => file.type !== 'directory');
const uploads:UploadInProgress[] = _.map(files, (file:UploadFile) => {
const formData = new FormData();
const metadata = {
description: file.description,
fileName: file.customName || file.name
};
const uploads:UploadInProgress[] = _.map(files, (file:UploadFile) => this.uploadSingle(url, file, method));
// add the metadata object
formData.append(
'metadata',
JSON.stringify(metadata),
);
const finished = this.whenFinished(uploads);
return {uploads, finished} as any;
}
// Add the file
formData.append('file', file);
/**
* Upload a single file, get an UploadResult observable
* @param {string} url
* @param {UploadFile} file
* @param {string} method
*/
public uploadSingle(url:string, file:UploadFile, method:string = 'post') {
const formData = new FormData();
const metadata = {
description: file.description,
fileName: file.customName || file.name
};
const observable = this
.http
.post<HalResource>(
url,
formData,
{
// Observe the response, not the body
observe: 'response',
// Subscribe to progress events. subscribe() will fire multiple times!
reportProgress: true
}
)
.pipe(
share()
)
// add the metadata object
formData.append(
'metadata',
JSON.stringify(metadata),
);
return [file, observable] as UploadInProgress;
});
// Add the file
formData.append('file', file);
const finished = this.whenFinished(uploads);
return {uploads, finished} as any;
const observable = this
.http
.request<HalResource>(
method,
url,
{
body: formData,
// Observe the response, not the body
observe: 'response',
// Subscribe to progress events. subscribe() will fire multiple times!
reportProgress: true
}
)
.pipe(
share()
)
return [file, observable] as UploadInProgress;
}
/**

@ -11,6 +11,13 @@ import {HelpTextDmService} from "../hal/dm-services/help-text-dm.service";
import {AttributeHelpTextsService} from "../common/help-texts/attribute-help-text.service";
import {AttributeHelpTextModal} from "../common/help-texts/attribute-help-text.modal";
import {DynamicContentModal} from "../../components/modals/modal-wrapper/dynamic-content.modal";
import {DisplayField} from "core-app/modules/fields/display/display-field.module";
import {HalResource} from "core-app/modules/hal/resources/hal-resource";
import {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";
import {DisplayFieldService} from "core-app/modules/fields/display/display-field.service";
import {EditFieldService} from "core-app/modules/fields/edit/edit-field.service";
import {WorkPackageNotificationService} from "core-components/wp-edit/wp-notification.service";
import {OpenProjectFileUploadService} from "core-components/api/op-file-upload/op-file-upload.service";
/**
* Plugin context bridge for plugins outside the CLI compiler context
@ -31,9 +38,14 @@ export class OpenProjectPluginContext {
hooks: this.injector.get<HookService>(HookService),
i18n: this.injector.get<I18nService>(I18nService),
notifications: this.injector.get<NotificationsService>(NotificationsService),
wpNotifications: this.injector.get<WorkPackageNotificationService>(WorkPackageNotificationService),
opModalService: this.injector.get<OpModalService>(OpModalService),
opFileUpload: this.injector.get<OpenProjectFileUploadService>(OpenProjectFileUploadService),
helpTextDm: this.injector.get<HelpTextDmService>(HelpTextDmService),
attributeHelpTexts: this.injector.get<AttributeHelpTextsService>(AttributeHelpTextsService)
attributeHelpTexts: this.injector.get<AttributeHelpTextsService>(AttributeHelpTextsService),
displayField: this.injector.get<DisplayFieldService>(DisplayFieldService),
editField: this.injector.get<EditFieldService>(EditFieldService),
wpCache: this.injector.get<WorkPackageCacheService>(WorkPackageCacheService),
};
// Random collection of classes needed outside of angular
@ -41,7 +53,9 @@ export class OpenProjectPluginContext {
modals: {
passwordConfirmation: PasswordConfirmationModal,
attributeHelpTexts: AttributeHelpTextModal,
dynamicContent: DynamicContentModal
dynamicContent: DynamicContentModal,
DisplayField: DisplayField,
HalResource: HalResource
}
};

Loading…
Cancel
Save