Skip to content

Commit

Permalink
changing intialisation of JSONEditor2
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Nov 28, 2024
1 parent 5316431 commit 39142ee
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<label translate>Source Template - {{ sourceSystem }}</label>
</div>
<d11r-mapping-json-editor2 #editorSourceFilter [options]="editorOptionsSourceFilter" [class]="'jse-main-small'"
[data]="templateSource" (pathChanged)="onSelectedPathSourceChanged($event)"></d11r-mapping-json-editor2>
[data]="sourceTemplate" (pathChanged)="onSelectedPathSourceChanged($event)"></d11r-mapping-json-editor2>
</div>
<formly-form [form]="filterFormly" [fields]="filterFormlyFields" [model]="filterModel"></formly-form>
<div class="form-group ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class MappingFilterComponent implements OnInit, OnDestroy, AfterViewInit
readOnly: true,
name: 'message'
};
templateSource: any;
sourceTemplate: any;
filterModel: any = {};
filterFormly: FormGroup = new FormGroup({});
filterFormlyFields: FormlyFieldConfig[];
Expand All @@ -76,7 +76,7 @@ export class MappingFilterComponent implements OnInit, OnDestroy, AfterViewInit

async ngOnInit(): Promise<void> {
this.closeSubject = new Subject();
this.templateSource = JSON.parse(this.mapping.source);
this.sourceTemplate = JSON.parse(this.mapping.source);
this.filterFormlyFields = [
{
fieldGroup: [
Expand Down Expand Up @@ -140,7 +140,7 @@ export class MappingFilterComponent implements OnInit, OnDestroy, AfterViewInit
this.filterFormly.get('pathSource').setErrors(null);

const r: JSON = await this.mappingService.evaluateExpression(
this.templateSource,
this.sourceTemplate,
this.filterFormly.get('pathSource').value
);
this.filterModel.sourceExpression = {
Expand Down
2 changes: 2 additions & 0 deletions dynamic-mapping-ui/src/mapping/grid/mapping.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import { HttpStatusCode } from '@angular/common/http';
import { MappingIdCellRendererComponent } from '../renderer/mapping-id.renderer.component';
import { AdviceActionComponent } from './advisor/advice-action.component';
import { MappingFilterComponent } from '../filter/mapping-filter.component';
import { map } from 'cypress/types/bluebird';

@Component({
selector: 'd11r-mapping-mapping-grid',
Expand Down Expand Up @@ -559,6 +560,7 @@ export class MappingComponent implements OnInit, OnDestroy {
MAPPING_TYPE_DESCRIPTION[mapping.mappingType].properties[
mapping.direction
];
mapping.lastUpdate = Date.now();
if (
(mapping.snoopStatus == SnoopStatus.ENABLED ||
mapping.snoopStatus == SnoopStatus.STARTED) &&
Expand Down
4 changes: 2 additions & 2 deletions dynamic-mapping-ui/src/mapping/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,9 @@ export function expandC8YTemplate(template: object, mapping: Mapping): object {

export function reduceSourceTemplate(
template: object,
patched: boolean
returnPatched: boolean
): string {
if (!patched) {
if (!returnPatched) {
delete template[TOKEN_TOPIC_LEVEL];
delete template[TOKEN_CONTEXT_DATA];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
import { MappingService } from '../core/mapping.service';
import { C8YRequest } from '../processor/processor.model';
import { StepperConfiguration } from 'src/shared/model/shared.model';
import { isDisabled } from '../shared/util';
import { expandC8YTemplate, expandExternalTemplate, isDisabled } from '../shared/util';

@Component({
selector: 'd11r-mapping-testing',
Expand Down Expand Up @@ -73,7 +73,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
selectedResult$: BehaviorSubject<number> = new BehaviorSubject<number>(0);
sourceSystem: string;
targetSystem: string;
currentMapping: any;
currentContext: any;
editorOptionsTesting: any = {
mode: 'tree',
removeModes: ['text', 'table'],
Expand All @@ -89,6 +89,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
editorTestingRequest: JsonEditor2Component;
@ViewChild('editorTestingResponse', { static: false })
editorTestingResponse: JsonEditor2Component;
source: any;

constructor(
public mappingService: MappingService,
Expand All @@ -110,7 +111,10 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
// );

this.editorTestingPayloadTemplateEmitter.subscribe((current) => {
this.currentMapping = current;
this.currentContext = current;
this.source = JSON.parse(this.currentContext.mapping.source);
this.currentContext.mapping.source = JSON.stringify(current.sourceTemplate);
this.currentContext.mapping.target = JSON.stringify(current.targetTemplate);
const editorTestingRequestRef =
this.elementRef.nativeElement.querySelector('#editorTestingRequest');
if (editorTestingRequestRef != null) {
Expand All @@ -119,7 +123,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
getSchema(this.mapping.targetAPI, this.mapping.direction, true)
);
this.testingModel = {
payload: JSON.parse(this.currentMapping.source),
payload: this.source,
results: [],
selectedResult: -1,
request: {},
Expand All @@ -132,7 +136,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {

async onTestTransformation() {
const testProcessingContext = await this.mappingService.testResult(
this.currentMapping,
this.currentContext.mapping,
false
);
this.testingModel.results = testProcessingContext.requests;
Expand All @@ -155,7 +159,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {

async onSendTest() {
const testProcessingContext = await this.mappingService.testResult(
this.mapping,
this.currentContext.mapping,
true
);
this.testingModel.results = testProcessingContext.requests;
Expand Down Expand Up @@ -183,12 +187,14 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {

onResetTransformation() {
this.testingModel = {
payload: this.currentMapping,
payload: this.source,
results: [],
request: {},
response: {},
selectedResult: -1
};
this.editorTestingRequest.set(this.testingModel.request);
this.editorTestingResponse.set(this.testingModel.response);
this.mappingService.initializeCache(this.mapping.direction);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ <h4 class="text-medium">
</div>
<d11r-mapping-json-editor2 *ngIf="stepperConfiguration.showEditorSource"
[schemaUpdate]="schemaUpdateSource" [options]="editorOptionsSourceTemplate"
[class]="'jse-main-medium'" (initialized)="onEditorSourceInitialized()" [data]="templateSource"
[class]="'jse-main-medium'" (initialized)="onEditorSourceInitialized()" (contentChanged)="onsourceTemplateChanged($event)" [data]="sourceTemplate"
#editorSourceStepTemplate></d11r-mapping-json-editor2>
<ng-container *ngIf="!stepperConfiguration.showEditorSource">
<ng-container *ngTemplateOutlet="extensionTemplate; context: { form: templateForm }">
Expand All @@ -162,7 +162,7 @@ <h4 class="text-medium">
</div>
<d11r-mapping-json-editor2 [schemaUpdate]="schemaUpdateTarget"
[options]="editorOptionsTargetTemplate" [class]="'jse-main-medium'"
(initialized)="onEditorTargetInitialized()" [data]="templateTarget" #editorTargetStepTemplate>
(initialized)="onEditorTargetInitialized()" (contentChanged)="ontargetTemplateChanged($event)" [data]="targetTemplate" #editorTargetStepTemplate>
</d11r-mapping-json-editor2>
</div>
</div>
Expand Down Expand Up @@ -193,7 +193,7 @@ <h4 class="text-medium">
<d11r-mapping-json-editor2 [schemaUpdate]="schemaUpdateSource"
[options]="editorOptionsSourceSubstitution" [class]="'jse-main-small'"
(pathChanged)="onSelectedPathSourceChanged($event)"
(initialized)="onEditorSourceInitialized()" [data]="templateSource"
(initialized)="onEditorSourceInitialized()" [data]="sourceTemplate"
#editorSourceStepTemplate></d11r-mapping-json-editor2>
<span class="text-warning text-12 p-l-8" *ngIf="
substitutionModel.pathSource === ''
Expand All @@ -217,10 +217,10 @@ <h4 class="text-medium">
<div class="d-flex">
<label>Target Template - {{ targetSystem }}</label>
<span class="hidden-xs hidden-sm m-l-4">
<ng-template #popTemplateTarget>The template contains the dummy field
<ng-template #poptargetTemplate>The template contains the dummy field
"_TOPIC_LEVEL_"(outbound) to map device
identifiers.</ng-template>
<button class="btn-clean text-primary" [popover]="popTemplateTarget"
<button class="btn-clean text-primary" [popover]="poptargetTemplate"
popoverTitle='Use dummy field "_TOPIC_LEVEL_"' placement="right" triggers="focus"
type="button">
<i c8yIcon="question-circle-o"></i>
Expand All @@ -231,7 +231,7 @@ <h4 class="text-medium">
<d11r-mapping-json-editor2 [schemaUpdate]="schemaUpdateTarget"
[options]="editorOptionsTargetSubstitution" [class]="'jse-main-small'"
(pathChanged)="onSelectedPathTargetChanged($event)" (initialized)="onEditorTargetInitialized()"
[data]="templateTarget" #editorTargetStepTemplate>
[data]="targetTemplate" #editorTargetStepTemplate>
</d11r-mapping-json-editor2>
<span class="text-warning text-12 p-l-8" *ngIf="
substitutionModel.pathTarget === '' &&
Expand Down
Loading

0 comments on commit 39142ee

Please sign in to comment.