Skip to content

Commit

Permalink
adding template explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Oct 11, 2024
1 parent fcad9b1 commit a38056f
Show file tree
Hide file tree
Showing 16 changed files with 611 additions and 259 deletions.
314 changes: 145 additions & 169 deletions dynamic-mapping-ui/package-lock.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dynamic-mapping-ui/src/mapping/core/mapping.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class MappingService {
}
private eventRealtimeService: EventRealtimeService;
private subscription: Subscription;
private updateMappingEnriched$: Subject<MappingEnriched> = new Subject();
queriesUtil: QueriesUtil;
private _agentId: string;
protected JSONATA = require('jsonata');
Expand All @@ -115,6 +116,13 @@ export class MappingService {
);
}

listenToUpdateMapping(): Observable<MappingEnriched> {
return this.updateMappingEnriched$;
}
initiateUpdateMapping(m: MappingEnriched): void {
this.updateMappingEnriched$.next(m);
}

async changeDebuggingMapping(parameter: any) {
await this.sharedService.runOperation(Operation.DEBUG_MAPPING, parameter);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!--
~ Copyright (c) 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA,
~ and/or its subsidiaries and/or its affiliates and/or their licensors.
~
~ SPDX-License-Identifier: Apache-2.0
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ @authors Christof Strack
-->

<div class="modal-header dialog-header animated fadeIn">
<h1 c8yIcon="plus-circle"></h1>
<h4>Select next step</h4>
</div>

<c8y-modal
(onClose)="onClose()"
(onDismiss)="onDismiss()"
[labels]="labels"
[disabled]="!valid"
>
<div>
<p class="text-center text-medium text-16 sticky-top bg-white">
{{ 'Select next step ... ' | translate }}
</p>
<div class="p-24 modal-inner-scroll animated fadeIn">
<c8y-list-group class="separator-top">
<c8y-li>
<c8y-li-radio
name="mapping_type_group"
title="{{ 'Continue snooping' }}"
(click)="onSelection('CONTINUE_SNOOPING')"
></c8y-li-radio>
<span>{{ 'Continue snooping and wait for more templates ...' }}</span>
</c8y-li>
<c8y-li>
<c8y-li-radio
name="mapping_type_group"
title="{{ 'Stop snooping' }}"
(click)="onSelection('STOP_SNOOPING_AND_EDIT')"
></c8y-li-radio>
<span>{{ 'Stop snooping and edit mapping ...' }}</span>
</c8y-li>
</c8y-list-group>
</div>
</div>
</c8y-modal>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA,
* and/or its subsidiaries and/or its affiliates and/or their licensors.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @authors Christof Strack
*/
import {
Component,
Input,
OnDestroy,
OnInit,
ViewEncapsulation
} from '@angular/core';
import { ModalLabels } from '@c8y/ngx-components';
import { Subject } from 'rxjs';
import { Mapping, MappingEnriched } from '../../../shared';

@Component({
selector: 'd11r-advice-action',
templateUrl: './advice-action.component.html',
encapsulation: ViewEncapsulation.None
})
export class AdviceActionComponent implements OnInit, OnDestroy {
@Input() enrichedMapping: MappingEnriched;
mapping: Mapping;
closeSubject: Subject<string> = new Subject();
labels: ModalLabels = { ok: 'Select', cancel: 'Cancel' };

selection: string = '';
valid: boolean = false;

constructor() {}

ngOnInit(): void {
this.closeSubject = new Subject();
}

onDismiss() {
this.closeSubject.next('CANCEL');
this.closeSubject.complete();
}

onClose() {
this.closeSubject.next(this.selection);
this.closeSubject.complete();
}

onSelection(t) {
this.selection = t;
this.valid = true;
}

ngOnDestroy() {
this.closeSubject.complete();
}
}
141 changes: 91 additions & 50 deletions dynamic-mapping-ui/src/mapping/grid/mapping.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ import {
} from '../shared/mapping.model';
import { EditorMode } from '../shared/stepper-model';
import { HttpStatusCode } from '@angular/common/http';
import { MappingIdCellRendererComponent } from '../renderer/mapping-id.cell-renderer.component';
import { AdviceActionComponent } from './advisor/advice-action.component';

@Component({
selector: 'd11r-mapping-mapping-grid',
Expand Down Expand Up @@ -194,20 +196,20 @@ export class MappingComponent implements OnInit, OnDestroy {
callback: this.deleteMappingWithConfirmation.bind(this),
showIf: (item) => !item['mapping']['active']
},
{
type: 'ACTIVATE_MAPPING',
text: 'Activate',
icon: 'toggle-on',
callback: this.activateMapping.bind(this),
showIf: (item) => !item['mapping']['active']
},
{
type: 'DEACTIVATE_MAPPING',
text: 'Deactivate',
icon: 'toggle-off',
callback: this.activateMapping.bind(this),
showIf: (item) => item['mapping']['active']
},
// {
// type: 'ACTIVATE_MAPPING',
// text: 'Activate',
// icon: 'toggle-on',
// callback: this.activateMapping.bind(this),
// showIf: (item) => !item['mapping']['active']
// },
// {
// type: 'DEACTIVATE_MAPPING',
// text: 'Deactivate',
// icon: 'toggle-off',
// callback: this.activateMapping.bind(this),
// showIf: (item) => item['mapping']['active']
// },
{
type: 'ENABLE_DEBUG',
text: 'Enable debugging',
Expand Down Expand Up @@ -303,6 +305,12 @@ export class MappingComponent implements OnInit, OnDestroy {
this.mappingsCount = maps.length;
});
await this.mappingService.startChangedMappingEvents();
this.mappingService
.listenToUpdateMapping()
.subscribe((m: MappingEnriched) => {
console.log('Triggered updating mapping', m);
this.updateMapping(m);
});
}

getColumnsMappings(): Column[] {
Expand All @@ -313,7 +321,7 @@ export class MappingComponent implements OnInit, OnDestroy {
path: 'mapping.name',
filterable: false,
dataType: ColumnDataType.TextShort,
cellRendererComponent: NameRendererComponent,
cellRendererComponent: MappingIdCellRendererComponent,
sortOrder: 'asc',
visible: true,
gridTrackSize: '10%'
Expand Down Expand Up @@ -529,44 +537,77 @@ export class MappingComponent implements OnInit, OnDestroy {
}

async updateMapping(m: MappingEnriched) {
let action = 'CONTINUE';
const { mapping } = m;

if (mapping.active) {
this.setStepperConfiguration(
mapping.mappingType,
this.stepperConfiguration.direction,
EditorMode.READ_ONLY
);
} else {
this.setStepperConfiguration(
mapping.mappingType,
this.stepperConfiguration.direction,
EditorMode.UPDATE
const { snoopSupported } =
MAPPING_TYPE_DESCRIPTION[mapping.mappingType].properties[
mapping.direction
];
if (
(mapping.snoopStatus == SnoopStatus.ENABLED ||
mapping.snoopStatus == SnoopStatus.STARTED) &&
snoopSupported
) {
const initialState = {
mapping,
labels: {
ok: 'Ok',
cancel: 'Cancel'
}
};
const confirmAdviceActionModalRef: BsModalRef = this.bsModalService.show(
AdviceActionComponent,
{ initialState }
);

action =
await confirmAdviceActionModalRef.content.closeSubject.toPromise();
console.log('Result from next step:', mapping, action);
}
// create deep copy of existing mapping, in case user cancels changes
this.mappingToUpdate = JSON.parse(JSON.stringify(mapping));

// for backward compatibility set direction of mapping to inbound
if (
!this.mappingToUpdate.direction ||
this.mappingToUpdate.direction == null
)
this.mappingToUpdate.direction = Direction.INBOUND;
const deploymentMapEntry =
await this.mappingService.getDefinedDeploymentMapEntry(mapping.ident);
this.deploymentMapEntry = {
ident: this.mappingToUpdate.ident,
connectors: deploymentMapEntry.connectors
};
// console.log('Editing mapping', this.mappingToUpdate);
if (
mapping.snoopStatus === SnoopStatus.NONE ||
mapping.snoopStatus === SnoopStatus.STOPPED
) {
this.showConfigMapping = true;
} else {
this.showSnoopingMapping = true;
if (action != 'CANCEL') {
// stop snooping
if (action == 'STOP_SNOOPING_AND_EDIT') {
mapping.snoopStatus = SnoopStatus.STOPPED;
if (mapping.active) await this.activateMapping(m);
}
if (mapping.active) {
this.setStepperConfiguration(
mapping.mappingType,
this.stepperConfiguration.direction,
EditorMode.READ_ONLY
);
} else {
this.setStepperConfiguration(
mapping.mappingType,
this.stepperConfiguration.direction,
EditorMode.UPDATE
);
}
// create deep copy of existing mapping, in case user cancels changes
this.mappingToUpdate = JSON.parse(JSON.stringify(mapping));

// for backward compatibility set direction of mapping to inbound
if (
!this.mappingToUpdate.direction ||
this.mappingToUpdate.direction == null
)
this.mappingToUpdate.direction = Direction.INBOUND;
const deploymentMapEntry =
await this.mappingService.getDefinedDeploymentMapEntry(mapping.ident);
this.deploymentMapEntry = {
ident: this.mappingToUpdate.ident,
connectors: deploymentMapEntry.connectors
};
// console.log('Editing mapping', this.mappingToUpdate);
if (
// mapping.snoopStatus === SnoopStatus.NONE ||
mapping.snoopStatus === SnoopStatus.STOPPED
) {
this.showConfigMapping = true;
} else {
this.showSnoopingMapping = true;
}
}
}

Expand Down Expand Up @@ -609,7 +650,7 @@ export class MappingComponent implements OnInit, OnDestroy {
const parameter = { id: mapping.id, active: newActive };
const response =
await this.mappingService.changeActivationMapping(parameter);
if (response.status != HttpStatusCode.Ok) {
if (response.status != HttpStatusCode.Created) {
const failedMap = await response.json();
const failedList = Object.values(failedMap).join(',');
this.alertService.warning(
Expand Down
10 changes: 8 additions & 2 deletions dynamic-mapping-ui/src/mapping/mapping.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { AssetSelectorModule } from '@c8y/ngx-components/assets-navigator';
import { PopoverModule } from 'ngx-bootstrap/popover';
import { BrokerConfigurationModule } from '../configuration';
import { SharedModule } from '../shared';
import { EditSubstitutionComponent } from './edit/edit-substitution-modal.component';
import { EditSubstitutionComponent } from './substitution/edit/edit-substitution-modal.component';
import { MappingComponent } from './grid/mapping.component';
import { ImportMappingsComponent } from './import/import-modal.component';
import { MappingTypeComponent } from './mapping-type/mapping-type.component';
Expand Down Expand Up @@ -61,6 +61,9 @@ import {
} from './shared/util';
import { NODE1 } from '../shared/model/util';
import { MappingSubscriptionComponent } from './subscription-grid/subscription.component';
import { MappingIdCellRendererComponent } from './renderer/mapping-id.cell-renderer.component';
import { SnoopExplorerComponent } from './snoop-explorer/snoop-explorer-modal.component';
import { AdviceActionComponent } from './grid/advisor/advice-action.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -88,7 +91,10 @@ import { MappingSubscriptionComponent } from './subscription-grid/subscription.c
FieldInputCustom,
MappingConnectorComponent,
MappingSubscriptionComponent,
DeviceSelectorSubscriptionComponent
DeviceSelectorSubscriptionComponent,
MappingIdCellRendererComponent,
SnoopExplorerComponent,
AdviceActionComponent
],
imports: [
CoreModule,
Expand Down
Loading

0 comments on commit a38056f

Please sign in to comment.