diff --git a/frontend/src/app/modules/policy-engine/policy-configuration/blocks/documents/upload-config/upload-config.component.css b/frontend/src/app/modules/policy-engine/policy-configuration/blocks/documents/upload-config/upload-config.component.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/frontend/src/app/modules/policy-engine/policy-configuration/blocks/documents/upload-config/upload-config.component.html b/frontend/src/app/modules/policy-engine/policy-configuration/blocks/documents/upload-config/upload-config.component.html deleted file mode 100644 index a425fde7ac..0000000000 --- a/frontend/src/app/modules/policy-engine/policy-configuration/blocks/documents/upload-config/upload-config.component.html +++ /dev/null @@ -1,195 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Schema - - - {{schema.name}} - ({{schema.version}}) - ({{schema.status}}) - - -
Id Type - - - DID (New DID) - UUID (New UUID) - Owner (Owner DID) - -
Preset - -
- arrow_drop_down - UI
Type - - PAGE - DIALOG - -
Title - -
Description - -
Title - -
Button Content - -
Button Class - -
Dialog Title - -
Dialog Description - -
Dialog Class - -
- arrow_drop_down - Preset
Preset Schema - - - {{schema.name}} - ({{schema.version}}) - ({{schema.status}}) - - -
- arrow_drop_down - Field {{i}} - {{field.name}} = {{field.value}} -
- Title - - {{field.title}} -
- Preset Field - - - - {{f.title}} - - -
- Readonly - - -
\ No newline at end of file diff --git a/frontend/src/app/modules/policy-engine/policy-configuration/blocks/documents/upload-config/upload-config.component.ts b/frontend/src/app/modules/policy-engine/policy-configuration/blocks/documents/upload-config/upload-config.component.ts deleted file mode 100644 index a065260084..0000000000 --- a/frontend/src/app/modules/policy-engine/policy-configuration/blocks/documents/upload-config/upload-config.component.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { Component, EventEmitter, Input, OnInit, Output, SimpleChanges, ViewEncapsulation } from '@angular/core'; -import { IModuleVariables, PolicyBlockModel, SchemaVariables } from '../../../../structures'; - -/** - * Settings for block of 'requestVcDocument' type. - */ -@Component({ - selector: 'upload-config', - templateUrl: './upload-config.component.html', - styleUrls: ['./upload-config.component.css'], - encapsulation: ViewEncapsulation.Emulated -}) -export class UploadConfigComponent implements OnInit { - @Input('block') currentBlock!: PolicyBlockModel; - @Input('readonly') readonly!: boolean; - @Output() onInit = new EventEmitter(); - - private moduleVariables!: IModuleVariables | null; - private item!: PolicyBlockModel; - - propHidden: any = { - main: false, - privateFieldsGroup: false, - preset: false, - presetFields: {} - }; - - properties!: any; - schemas!: SchemaVariables[]; - - presetMap: any; - - constructor() { - this.presetMap = []; - } - - ngOnInit(): void { - this.schemas = []; - this.onInit.emit(this); - this.load(this.currentBlock); - } - - ngOnChanges(changes: SimpleChanges) { - this.load(this.currentBlock); - } - - load(block: PolicyBlockModel) { - this.moduleVariables = block.moduleVariables; - this.item = block; - this.properties = block.properties; - this.properties.uiMetaData = this.properties.uiMetaData || {}; - this.properties.uiMetaData.type = this.properties.uiMetaData.type || 'page'; - this.properties.presetFields = this.properties.presetFields || []; - - this.schemas = this.moduleVariables?.schemas || []; - - const schema = this.schemas.find(e => e.value == this.properties.schema); - const presetSchema = this.schemas.find(e => e.value == this.properties.presetSchema); - if (!schema || !presetSchema) { - this.properties.presetFields = []; - } - this.presetMap = []; - if (presetSchema?.data?.fields) { - for (const field of presetSchema.data.fields) { - this.presetMap.push({ - name: field.name, - title: field.description - }) - } - } - } - - onHide(item: any, prop: any) { - item[prop] = !item[prop]; - } - - onSelectInput() { - this.properties.presetFields = []; - this.presetMap = []; - - const schema = this.schemas.find(e => e.value == this.properties.schema); - const presetSchema = this.schemas.find(e => e.value == this.properties.presetSchema); - - if (schema && presetSchema) { - if (schema.data?.fields) { - for (const field of schema.data.fields) { - this.properties.presetFields.push({ - name: field.name, - title: field.description, - value: null, - readonly: false - }) - } - } - if (presetSchema.data?.fields) { - this.presetMap.push({ - name: null, - title: '' - }); - for (const field of presetSchema.data.fields) { - this.presetMap.push({ - name: field.name, - title: field.description - }); - } - } - } - - const dMap: any = {}; - for (let i = 0; i < this.presetMap.length; i++) { - const f = this.presetMap[i]; - dMap[f.title] = f.name; - } - for (let i = 0; i < this.properties.presetFields.length; i++) { - const f = this.properties.presetFields[i]; - f.value = dMap[f.title]; - } - } - - onSave() { - this.item.changed = true; - } -} diff --git a/frontend/src/app/modules/policy-engine/policy-engine.module.ts b/frontend/src/app/modules/policy-engine/policy-engine.module.ts index 28c901d95d..5cb121fbde 100644 --- a/frontend/src/app/modules/policy-engine/policy-engine.module.ts +++ b/frontend/src/app/modules/policy-engine/policy-engine.module.ts @@ -95,7 +95,6 @@ import { NewPolicyDialog } from './helpers/new-policy-dialog/new-policy-dialog.c import { PolicySettingsComponent } from './policy-configuration/policy-settings/policy-settings.component'; import { ImportFileDialog } from './helpers/import-file-dialog/import-file-dialog.component'; import { NewThemeDialog } from './helpers/new-theme-dialog/new-theme-dialog.component'; -import { UploadConfigComponent } from './policy-configuration/blocks/documents/upload-config/upload-config.component'; import { UploadDocumentBlockComponent } from './policy-viewer/blocks/upload-document-block/upload-document-block.component'; @NgModule({ @@ -107,7 +106,6 @@ import { UploadDocumentBlockComponent } from './policy-viewer/blocks/upload-docu ActionConfigComponent, ContainerConfigComponent, RequestConfigComponent, - UploadConfigComponent, PolicyPropertiesComponent, MintConfigComponent, SendConfigComponent, diff --git a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.css b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.css index f8a67e8d69..c6e9129a9e 100644 --- a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.css +++ b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.css @@ -241,3 +241,10 @@ margin: auto; width: 600px; } + +.page-header { + display: flex; + justify-content: center; + flex-direction: column; + align-items: center; +} diff --git a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.html b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.html index 8758ec3dd8..770e62a50b 100644 --- a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.html +++ b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.html @@ -4,21 +4,25 @@
+
+ (click)="onDialog()">{{buttonText}}
-

{{data.dialogContent}}

+

{{data.dialogTitle}}

- {{description}} + {{dialogDescription}}
diff --git a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.ts b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.ts index cc37989344..5d11c7f41c 100644 --- a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.ts +++ b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/upload-document-block/upload-document-block.component.ts @@ -5,7 +5,6 @@ import { IUser } from '@guardian/interfaces'; import { PolicyEngineService } from 'src/app/services/policy-engine.service'; import { PolicyHelper } from 'src/app/services/policy-helper.service'; import { ProfileService } from 'src/app/services/profile.service'; -import { global } from '@angular/compiler/src/util'; import { WebSocketService } from 'src/app/services/web-socket.service'; /** @@ -27,28 +26,15 @@ export class UploadDocumentBlockComponent implements OnInit { loading: boolean = true; socket: any; dialogLoading: boolean = false; - dataForm: FormGroup; - schema: any; - hideFields: any; type!: string; - content: any; - dialogContent: any; - dialogClass: any; + buttonText: string = ''; + dialogTitle: string = ''; + dialogClass: string = ''; dialogRef: any; - ref: any; - title: any; - description: any; - presetDocument: any; - rowDocument: any; - needPreset: any; - presetFields: any; - presetReadonlyFields: any; - buttonClass: any; - user!: IUser; - restoreData: any; - - public innerWidth: any; - public innerHeight: any; + pageTitle: string = ''; + pageDescription: string = ''; + dialogDescription: string = ''; + buttonClass: string = ''; public items: unknown[] = [] @@ -57,27 +43,15 @@ export class UploadDocumentBlockComponent implements OnInit { private wsService: WebSocketService, private profile: ProfileService, private policyHelper: PolicyHelper, - private fb: FormBuilder, private dialog: MatDialog, - private changeDetectorRef: ChangeDetectorRef ) { - this.dataForm = fb.group({}); } ngOnInit(): void { - this.innerWidth = window.innerWidth; - this.innerHeight = window.innerHeight; if (!this.static) { this.socket = this.wsService.blockSubscribe(this.onUpdate.bind(this)); } - this.profile.getProfile() - .subscribe((user: IUser) => { - this.user = user; - this.loadData(); - }); - (window as any).__requestLast = this; - (window as any).__request = (window as any).__request || {}; - (window as any).__request[this.id] = this; + this.loadData(); } ngOnDestroy(): void { @@ -112,80 +86,23 @@ export class UploadDocumentBlockComponent implements OnInit { } } - getJson(data: any, presetFields: any[]) { - try { - if (data) { - const json: any = {}; - let cs: any = {}; - if (Array.isArray(data.document.credentialSubject)) { - cs = data.document.credentialSubject[0]; - } else { - cs = data.document.credentialSubject; - } - for (let i = 0; i < presetFields.length; i++) { - const f = presetFields[i]; - if (f.value === 'username') { - json[f.name] = this.user.username; - continue; - } - if (f.value === 'hederaAccountId') { - json[f.name] = this.user.hederaAccountId; - continue; - } - - json[f.name] = cs[f.value]; - } - return json; - } - } catch (error) { - return null; - } - return null; - } - setData(data: any) { if (data) { - const uiMetaData = data.uiMetaData; - const row = data.data; - const schema = data.schema; - const active = data.active; - this.ref = row; - this.type = uiMetaData.type; - this.schema = schema; - this.hideFields = {}; - if (uiMetaData.privateFields) { - for (let index = 0; index < uiMetaData.privateFields.length; index++) { - const field = uiMetaData.privateFields[index]; - this.hideFields[field] = true; - } - } + this.type = data.uiMetaData.type; if (this.type == 'dialog') { - this.content = uiMetaData.content; - this.buttonClass = uiMetaData.buttonClass; - this.dialogContent = uiMetaData.dialogContent; - this.dialogClass = uiMetaData.dialogClass; - this.description = uiMetaData.description; + this.buttonText = data.uiMetaData.buttonText; + this.buttonClass = data.uiMetaData.buttonClass; + this.dialogTitle = data.uiMetaData.dialogTitle; + this.dialogClass = data.uiMetaData.dialogClass; + this.dialogDescription = data.uiMetaData.dialogDescription; } if (this.type == 'page') { - this.title = uiMetaData.title; - this.description = uiMetaData.description; + this.pageTitle = data.uiMetaData.pageTitle; + this.pageDescription = data.uiMetaData.pageDescription; } - this.disabled = active === false; + this.disabled = false; this.isExist = true; - this.needPreset = !!data.presetSchema; - this.presetFields = data.presetFields || []; - this.restoreData = data.restoreData; - this.presetReadonlyFields = this.presetFields.filter( - (item: any) => item.readonly && item.value - ); - if (this.needPreset && row) { - this.rowDocument = this.getJson(row, this.presetFields); - this.preset(this.rowDocument); - } } else { - this.ref = null; - this.schema = null; - this.hideFields = null; this.disabled = false; this.isExist = false; } @@ -211,41 +128,6 @@ export class UploadDocumentBlockComponent implements OnInit { }); } - prepareDataFrom(data: any) { - if (Array.isArray(data)) { - for (let j = 0; j < data.length; j++) { - let dataArrayElem = data[j]; - if (dataArrayElem === "" || dataArrayElem === null) { - data.splice(j, 1); - j--; - } - if (Object.getPrototypeOf(dataArrayElem) === Object.prototype - || Array.isArray(dataArrayElem)) { - this.prepareDataFrom(dataArrayElem); - } - } - } - - if (Object.getPrototypeOf(data) === Object.prototype) { - let dataKeys = Object.keys(data); - for (let i = 0; i < dataKeys.length; i++) { - const dataElem = data[dataKeys[i]]; - if (dataElem === "" || dataElem === null) { - delete data[dataKeys[i]]; - } - if (Object.getPrototypeOf(dataElem) === Object.prototype - || Array.isArray(dataElem)) { - this.prepareDataFrom(dataElem); - } - } - } - } - - preset(document: any) { - this.presetDocument = document; - this.changeDetectorRef.detectChanges(); - } - onCancel(): void { if (this.dialogRef) { this.dialogRef.close(); @@ -254,20 +136,13 @@ export class UploadDocumentBlockComponent implements OnInit { } onDialog() { - this.dataForm.reset(); - if (this.needPreset && this.rowDocument) { - this.preset(this.rowDocument); - } else { - this.presetDocument = null; - } - - if (this.innerWidth <= 810) { + if (window.innerWidth <= 810) { const bodyStyles = window.getComputedStyle(document.body); const headerHeight: number = parseInt(bodyStyles.getPropertyValue('--header-height')); this.dialogRef = this.dialog.open(this.dialogTemplate, { width: `100vw`, maxWidth: '100vw', - height: `${this.innerHeight - headerHeight}px`, + height: `${window.innerHeight - headerHeight}px`, position: { 'bottom': '0' }, @@ -286,17 +161,6 @@ export class UploadDocumentBlockComponent implements OnInit { } } - - handleCancelBtnEvent(value: boolean, data: any) { - data.onCancel() - } - - handleSubmitBtnEvent(value: boolean, data: any) { - if (data.dataForm.valid || !this.loading || !this.dialogLoading) { - data.onSubmit(); - } - } - onDrop(files: any): void { for (const file of files) { const reader = new FileReader(); diff --git a/frontend/src/app/modules/policy-engine/services/blocks-information.ts b/frontend/src/app/modules/policy-engine/services/blocks-information.ts index 0f0d608d77..c185f0878c 100644 --- a/frontend/src/app/modules/policy-engine/services/blocks-information.ts +++ b/frontend/src/app/modules/policy-engine/services/blocks-information.ts @@ -48,7 +48,6 @@ import { IBlockSetting } from "../structures"; import { TagsManagerBlockComponent } from '../policy-viewer/blocks/tags-manager-block/tags-manager-block.component'; -import { UploadConfigComponent } from '../policy-configuration/blocks/documents/upload-config/upload-config.component'; import { UploadDocumentBlockComponent } from '../policy-viewer/blocks/upload-document-block/upload-document-block.component'; const Container: IBlockSetting = { @@ -294,7 +293,7 @@ const Upload: IBlockSetting = { group: BlockGroup.Documents, header: BlockHeaders.UIComponents, factory: UploadDocumentBlockComponent, - property: UploadConfigComponent, + property: null, allowedChildren: [{ type: BlockType.DocumentsSourceAddon, group: BlockGroup.UnGrouped diff --git a/guardian-service/src/policy-engine/block-about.ts b/guardian-service/src/policy-engine/block-about.ts index d5f4ee355f..33736f3fbe 100644 --- a/guardian-service/src/policy-engine/block-about.ts +++ b/guardian-service/src/policy-engine/block-about.ts @@ -19,7 +19,75 @@ export const BlockAbout = { 'RunEvent', 'RefreshEvent' ], - 'defaultEvent': true + 'defaultEvent': true, + properties: [ + { + name: 'uiMetaData', + label: 'UI', + title: 'UI Properties', + type: 'Group', + properties: [ + { + name: 'type', + label: 'Type', + title: 'Type', + type: 'Select', + items: [ + { + label: 'Page', + value: 'page' + }, + { + label: 'dialog', + value: 'dialog' + } + ] + }, + { + name: 'buttonClass', + label: 'Dialog button class', + title: 'Dialog button class', + type: 'Input' + }, + { + name: 'buttonText', + label: 'Dialog button text', + title: 'Dialog button text', + type: 'Input' + }, + { + name: 'dialogTitle', + label: 'Dialog title', + title: 'Dialog title', + type: 'Input' + }, + { + name: 'dialogClass', + label: 'Dialog class', + title: 'Dialog class', + type: 'Input' + }, + { + name: 'dialogDescription', + label: 'Dialog description', + title: 'Dialog description', + type: 'Input' + }, + { + name: 'pageTitle', + label: 'Page title', + title: 'Page title', + type: 'Input' + }, + { + name: 'pageDescription', + label: 'Page description', + title: 'Page description', + type: 'Input' + } + ] + } + ] }, 'aggregateDocumentBlock': { 'label': 'Aggregate Data', diff --git a/policy-service/src/policy-engine/blocks/upload-vc-document-block.ts b/policy-service/src/policy-engine/blocks/upload-vc-document-block.ts index 751ebe3bc6..6b2d4af9b7 100644 --- a/policy-service/src/policy-engine/blocks/upload-vc-document-block.ts +++ b/policy-service/src/policy-engine/blocks/upload-vc-document-block.ts @@ -4,11 +4,9 @@ import { BlockActionError } from '@policy-engine/errors'; import { ActionCallback } from '@policy-engine/helpers/decorators'; import { IPolicyDocument, IPolicyRequestBlock } from '@policy-engine/policy-engine.interface'; import { PolicyInputEventType, PolicyOutputEventType } from '@policy-engine/interfaces'; -import { ChildrenType, ControlType } from '@policy-engine/interfaces/block-about'; +import { ChildrenType, ControlType, PropertyType } from '@policy-engine/interfaces/block-about'; import { EventBlock } from '@policy-engine/helpers/decorators/event-block'; -import { - VcHelper, -} from '@guardian/common'; +import { VcHelper, } from '@guardian/common'; import { PolicyComponentsUtils } from '@policy-engine/policy-components-utils'; import { IPolicyUser } from '@policy-engine/policy-user'; import { ExternalDocuments, ExternalEvent, ExternalEventType } from '@policy-engine/interfaces/external-event'; @@ -27,6 +25,75 @@ import { VcDocumentDefinition as VcDocument } from '@guardian/common/dist/hedera get: true, children: ChildrenType.Special, control: ControlType.UI, + + properties: [ + { + name: 'uiMetaData', + label: 'UI', + title: 'UI Properties', + type: PropertyType.Group, + properties: [ + { + name: 'type', + label: 'Type', + title: 'Type', + type: PropertyType.Select, + items: [ + { + label: 'Page', + value: 'page' + }, + { + label: 'Dialog', + value: 'dialog' + } + ] + }, + { + name: 'buttonClass', + label: 'Dialog button class', + title: 'Dialog button class', + type: PropertyType.Input + }, + { + name: 'buttonText', + label: 'Dialog button text', + title: 'Dialog button text', + type: PropertyType.Input + }, + { + name: 'dialogTitle', + label: 'Dialog title', + title: 'Dialog title', + type: PropertyType.Input + }, + { + name: 'dialogClass', + label: 'Dialog class', + title: 'Dialog class', + type: PropertyType.Input + }, + { + name: 'dialogDescription', + label: 'Dialog description', + title: 'Dialog description', + type: PropertyType.Input + }, + { + name: 'pageTitle', + label: 'Page title', + title: 'Page title', + type: PropertyType.Input + }, + { + name: 'pageDescription', + label: 'Page description', + title: 'Page description', + type: PropertyType.Input + } + ] + } + ], input: [ PolicyInputEventType.RunEvent, PolicyInputEventType.RefreshEvent,