You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
7.4 KiB

6 months ago
import { ref, computed } from 'vue';
import { axios, Environment, $t, Tools, EnumTools, Options } from 'platform-core';
import { Processor } from '../Processor';
import { PlaceHolder } from '@/utils/PlaceHolder';
class HttpRequest extends Processor {
#HttpMethodTypeEnum: any;
#httpMethodTypeOptionsRef = ref(<any>[]);
6 months ago
#HttpAuthorizationTypeEnum: any;
#httpAuthorizationTypeOptionsRef = ref(<any>[]);
6 months ago
constructor(targetType: string, context?: any) {
super(targetType, context);
6 months ago
this.PROCESSOR_TYPE = 'HTTP_REQUEST';
this.EDITOR_DIALOG_WIDTH = 1024;
EnumTools.fetch(['io.sc.engine.rule.core.enums.HttpMethodType', 'io.sc.engine.rule.core.enums.HttpAuthorizationType']).then((value) => {
6 months ago
this.#HttpMethodTypeEnum = value.HttpMethodType;
this.#httpMethodTypeOptionsRef = Options.enum(this.#HttpMethodTypeEnum);
6 months ago
this.#HttpAuthorizationTypeEnum = value.HttpAuthorizationType;
this.#httpAuthorizationTypeOptionsRef = Options.enum(this.#HttpAuthorizationTypeEnum);
6 months ago
});
}
public getToolbarAction(): any {
return {
extend: 'add',
name: 'http',
6 months ago
label: $t('io.sc.engine.rule.core.enums.ProcessorType.' + this.PROCESSOR_TYPE),
6 months ago
icon: 'sync_alt',
enableIf: (args: any) => {
const type = this.context.target.type;
return type !== 'RULE_RESULT' && type !== 'SINGLE_RULE_RESULT';
},
afterClick: (args: any) => {
6 months ago
args.grid.getEditorForm().setFieldValue('type', this.PROCESSOR_TYPE);
6 months ago
},
};
}
public format(row: any): any {
6 months ago
return row.httpMethod + ', ' + PlaceHolder.replace(row.httpUrl);
6 months ago
}
public getEditorFields(): any {
return [
{
6 months ago
colSpan: 3,
6 months ago
name: 'httpMethod',
label: $t('re.resources.designer.processor.grid.entity.httpMethod'),
type: 'w-select',
options: this.#httpMethodTypeOptionsRef,
rows: 1,
showIf: (args: any) => {
6 months ago
return args.form.getFieldValue('type') === this.PROCESSOR_TYPE;
6 months ago
},
},
{
6 months ago
colSpan: 9,
name: 'httpUrl',
6 months ago
label: $t('re.resources.designer.processor.grid.entity.httpUrl'),
type: 'w-text',
showIf: (args: any) => {
6 months ago
return args.form.getFieldValue('type') === this.PROCESSOR_TYPE;
6 months ago
},
},
{
colSpan: 3,
6 months ago
name: 'httpAuthType',
label: $t('re.resources.designer.processor.grid.entity.httpAuthType'),
type: 'w-select',
options: this.#httpAuthorizationTypeOptionsRef,
6 months ago
showIf: (args: any) => {
6 months ago
return args.form.getFieldValue('type') === this.PROCESSOR_TYPE;
6 months ago
},
6 months ago
},
{
colSpan: 3,
name: 'httpAuthApikey',
label: $t('re.resources.designer.processor.grid.entity.httpAuthApikey'),
type: 'w-text',
showIf: (args: any) => {
return args.form.getFieldValue('type') === this.PROCESSOR_TYPE && args.form.getFieldValue('httpAuthType') === 'API_KEY';
6 months ago
},
},
{
6 months ago
colSpan: 6,
name: 'httpAuthApiValue',
label: $t('re.resources.designer.processor.grid.entity.httpAuthApiValue'),
type: 'w-text',
6 months ago
showIf: (args: any) => {
6 months ago
return args.form.getFieldValue('type') === this.PROCESSOR_TYPE && args.form.getFieldValue('httpAuthType') === 'API_KEY';
6 months ago
},
},
{
colSpan: 3,
6 months ago
name: 'httpAuthBasicUsername',
label: $t('re.resources.designer.processor.grid.entity.httpAuthBasicUsername'),
type: 'w-text',
6 months ago
showIf: (args: any) => {
6 months ago
return args.form.getFieldValue('type') === this.PROCESSOR_TYPE && args.form.getFieldValue('httpAuthType') === 'BASIC_AUTH';
6 months ago
},
6 months ago
},
{
colSpan: 6,
name: 'httpAuthBasicPassword',
label: $t('re.resources.designer.processor.grid.entity.httpAuthBasicPassword'),
type: 'w-text',
showIf: (args: any) => {
return args.form.getFieldValue('type') === this.PROCESSOR_TYPE && args.form.getFieldValue('httpAuthType') === 'BASIC_AUTH';
6 months ago
},
6 months ago
},
{
colSpan: 9,
name: 'httpAuthBearerToken',
label: $t('re.resources.designer.processor.grid.entity.httpAuthBearerToken'),
type: 'w-text',
showIf: (args: any) => {
return args.form.getFieldValue('type') === this.PROCESSOR_TYPE && args.form.getFieldValue('httpAuthType') === 'BEARER';
6 months ago
},
},
6 months ago
{
colSpan: 12,
name: 'httpRequestBody',
label: $t('re.resources.designer.processor.grid.entity.httpRequestBody'),
showIf: (args: any) => {
return args.form.getFieldValue('type') === this.PROCESSOR_TYPE;
},
type: 'w-code-mirror',
rows: 4,
toolbar: false,
lineNumber: false,
lang: 'json',
lineWrap: false,
lineBreak: true,
placeholder: true,
autoCompletion: this.autoCompletionManager.autoCompletion(),
userDefinedFunctions: this.userDefinedFunctionsManager.userDefinedFunctions(),
},
{
colSpan: 12,
name: 'httpResponseBody',
label: $t('re.resources.designer.processor.grid.entity.httpResponseBody'),
showIf: (args: any) => {
return args.form.getFieldValue('type') === this.PROCESSOR_TYPE;
},
type: 'w-code-mirror',
lang: 'json',
rows: 5,
toolbar: false,
lineNumber: false,
lineWrap: false,
lineBreak: true,
},
{
colSpan: 12,
name: 'httpResponseMapping',
label: $t('re.resources.designer.processor.grid.entity.httpResponseMapping'),
showIf: (args: any) => {
return args.form.getFieldValue('type') === this.PROCESSOR_TYPE;
},
type: 'w-code-mirror',
rows: 8,
toolbar: false,
lineNumber: false,
lang: 'json',
lineWrap: false,
lineBreak: true,
placeholder: true,
autoCompletion: this.autoCompletionManager.autoCompletion(),
userDefinedFunctions: this.userDefinedFunctionsManager.userDefinedFunctions(),
},
6 months ago
];
}
public getViewerFields(): any {
return [
6 months ago
{ name: 'httpMethod', label: $t('re.resources.designer.processor.grid.entity.httpMethod') },
{ name: 'httpUrl', label: $t('re.resources.designer.processor.grid.entity.httpUrl') },
{ name: 'httpAuthType', label: $t('re.resources.designer.processor.grid.entity.httpAuthType') },
{ name: 'httpAuthApikey', label: $t('re.resources.designer.processor.grid.entity.httpAuthApikey') },
{ name: 'httpAuthApiValue', label: $t('re.resources.designer.processor.grid.entity.httpAuthApiValue') },
{ name: 'httpAuthBasicUsername', label: $t('re.resources.designer.processor.grid.entity.httpAuthBasicUsername') },
{ name: 'httpAuthBasicPassword', label: $t('re.resources.designer.processor.grid.entity.httpAuthBasicPassword') },
{ name: 'httpAuthBearerToken', label: $t('re.resources.designer.processor.grid.entity.httpAuthBearerToken') },
{ name: 'httpRequestBody', label: $t('re.resources.designer.processor.grid.entity.httpRequestBody') },
{ name: 'httpResponseMapping', label: $t('re.resources.designer.processor.grid.entity.httpResponseMapping') },
6 months ago
];
}
6 months ago
public beforeEditorDataSubmit(args: any): void {}
6 months ago
public afterEditorOpen(args: any): void {
6 months ago
args.grid.getEditorDialog().setWidth(this.EDITOR_DIALOG_WIDTH);
6 months ago
this.initAutoCompletionManager();
this.initUserDefinedFunctionsManager();
}
}
export { HttpRequest };