Skip to content

Commit f31a6f3

Browse files
authored
FIWARE datatarget (#67)
* Datatarget multi-types administration and new FIWARE Datatarget type * PR fixes * DatatargetTypesService pr fixes
1 parent 1bed9dd commit f31a6f3

File tree

51 files changed

+2086
-670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2086
-670
lines changed

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { MonacoEditorModule } from 'ngx-monaco-editor';
2323
import { MatInputModule } from '@angular/material/input';
2424
import { MatPaginatorIntl } from '@angular/material/paginator';
2525
import { MatPaginatorIntlDa } from '@shared/helpers/mat-paginator-intl-da';
26+
import { MatTooltipModule } from '@angular/material/tooltip';
2627

2728
export function HttpLoaderFactory(http: HttpClient) {
2829
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
@@ -62,6 +63,7 @@ export function tokenGetter() {
6263
SearchModule,
6364
HttpClientModule,
6465
MatInputModule,
66+
MatTooltipModule,
6567
JwtModule.forRoot({
6668
config: {
6769
tokenGetter

src/app/applications/application-detail/application-detail.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h3>Detaljer</h3>
6666
<div class="jumbotron">
6767
<div *ngIf="canEdit else readOnly">
6868
<app-top-bar-table [component]="true" [title]="'APPLICATION.DATATARGET-SHOW' | translate"
69-
[ctaLabelPrimary]="'FORM.CREATE-NEW-DATATARGET' | translate" [ctaRouterLinkPrimary]="'datatarget-edit'">
69+
[ctaLabelPrimary]="'FORM.CREATE-NEW-DATATARGET' | translate" [ctaRouterLinkPrimary]="'datatarget-new'">
7070
</app-top-bar-table>
7171
</div>
7272
<ng-template #readOnly>

src/app/applications/application-detail/application-detail.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy {
5252
label: '',
5353
editRouterLink: '../../edit-application/' + this.id,
5454
isErasable: true,
55-
};
56-
57-
console.log(this.id);
55+
};
5856
}
5957

6058
this.translate

src/app/applications/applications-routing.module.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { DatatargetDetailComponent } from './datatarget/datatarget-detail/datata
1111
import { BulkImportComponent } from './bulk-import/bulk-import.component';
1212
import { MulticastEditComponent } from './multicast/multicast-edit/multicast-edit.component';
1313
import { MulticastDetailComponent } from './multicast/multicast-detail/multicast-detail.component';
14-
14+
import { DatatargetNewComponent } from './datatarget/datatarget-new/datatarget-new.component';
1515

1616
const applicationRoutes: Routes = [
1717
{
@@ -27,12 +27,11 @@ const applicationRoutes: Routes = [
2727
{ path: '', component: ApplicationDetailComponent },
2828
{ path: 'new-iot-device', component: IotDeviceEditComponent, },
2929
{ path: 'iot-device-edit/:deviceId', component: IotDeviceEditComponent, },
30-
{ path: 'iot-device/:deviceId', component: IoTDeviceDetailComponent, },
31-
30+
{ path: 'iot-device/:deviceId', component: IoTDeviceDetailComponent, },
31+
{ path: 'datatarget-new', component: DatatargetNewComponent },
3232
{ path: 'datatarget-edit', component: DatatargetEditComponent },
3333
{ path: 'datatarget-edit/:datatargetId', component: DatatargetEditComponent },
34-
{ path: 'datatarget/:datatargetId', component: DatatargetDetailComponent },
35-
34+
{ path: 'datatarget/:datatargetId', component: DatatargetDetailComponent },
3635
{ path: 'multicast-edit', component: MulticastEditComponent},
3736
{ path: 'multicast-edit/:multicastId', component: MulticastEditComponent },
3837
{ path: 'multicast/:multicastId', component: MulticastDetailComponent },
@@ -41,7 +40,7 @@ const applicationRoutes: Routes = [
4140
],
4241
},
4342

44-
],
43+
],
4544
},
4645
];
4746

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* tslint:disable:no-unused-variable */
2+
3+
import { ViewContainerRef } from '@angular/core';
4+
import { DatatargetDetailTypeSelectorDirective } from './datatarget-detail-type-selector.directive';
5+
let viewContainerRef: ViewContainerRef;
6+
describe('Directive: DatatargetDetailTypeSelector', () => {
7+
it('should create an instance', () => {
8+
const directive = new DatatargetDetailTypeSelectorDirective(viewContainerRef);
9+
expect(directive).toBeTruthy();
10+
});
11+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Directive, ViewContainerRef } from '@angular/core';
2+
3+
@Directive({
4+
selector: '[detail-component]'
5+
})
6+
export class DatatargetDetailTypeSelectorDirective {
7+
8+
constructor(public viewContainerRef: ViewContainerRef) { }
9+
}
Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,3 @@
1-
<div *ngIf="datatarget">
2-
<app-top-bar [data]="datatarget" [backButton]="backButton" [subPage]="true" [addDetailDowndown]="true"
3-
[dropDownButton]="dropdownButton" (deleteSelectedInDropdown)="onDeleteDatatarget()"></app-top-bar>
4-
<div class="container-fluid">
5-
<div class="row">
6-
<div class="col-md-6 d-flex align-items-stretch">
7-
<div class="jumbotron jumbotron--m-right jumbotron--full-width">
8-
<h3>{{ 'DATATARGET.DETAILS' | translate }}</h3>
9-
<app-general-details [data]="datatarget"></app-general-details>
10-
<mat-divider></mat-divider>
11-
<p><strong>{{ 'DATATARGET.URL' | translate }}</strong>{{datatarget.url}}</p>
12-
<p><strong>{{ 'DATATARGET.TIMEOUT' | translate }}</strong>{{datatarget.timeout}}</p>
13-
<p><strong>{{ 'DATATARGET.TYPE' | translate }}</strong>{{datatarget.type | translate}}</p>
14-
<mat-divider></mat-divider>
15-
<p><strong>{{ 'DATATARGET.AUTHORIZATIONHEADER' | translate }}</strong></p>
16-
<code><pre *ngIf="datatarget.authorizationHeader; else showNoAuthText">{{datatarget.authorizationHeader}}</pre></code>
17-
<ng-template #showNoAuthText>
18-
<p>{{ 'DATATARGET.NO-AUTHORIZATIONHEADER' | translate }}</p>
19-
</ng-template>
20-
21-
</div>
22-
</div>
23-
<div class="col-md-6 d-flex align-items-stretch">
24-
<div class="jumbotron jumbotron--m-left jumbotron--full-width">
25-
<h3>{{ 'DATATARGET.OPENDATA-DK' | translate }}</h3>
26-
<div *ngIf="datatarget.setToOpendataDk else noOpendataDk">
27-
<app-opendatadk-detail [openDataDkDataset]="datatarget.openDataDkDataset"></app-opendatadk-detail>
28-
</div>
29-
<ng-template #noOpendataDk>
30-
<p>{{ 'DATATARGET.NO-OPENDATA-DK' | translate }}</p>
31-
</ng-template>
32-
</div>
33-
</div>
34-
</div>
35-
36-
<div class="row">
37-
<div class="col-12">
38-
<div class=" jumbotron">
39-
<div class="form-group">
40-
<h3>{{ 'DATATARGET.RELATIONS' | translate }}</h3>
41-
<div *ngIf="dataTargetRelations?.length === 0">
42-
<p>{{'DATATARGET.NO-RELATIONS' | translate}}</p>
43-
</div>
44-
<div *ngIf="dataTargetRelations">
45-
<div *ngFor="let relation of dataTargetRelations">
46-
<div class="row">
47-
<div class="col-md-4 d-flex align-items-center">
48-
<p><strong>{{'DATATARGET.PAYLOADEDECODER' | translate}}</strong><span
49-
*ngIf="relation.payloadDecoder; else noDecoder">
50-
<a [routerLink]="['/payload-decoder/payload-decoder-detail/', relation.payloadDecoder.id]">{{relation.payloadDecoder.name}}</a>
51-
</span>
52-
<ng-template #noDecoder>{{ 'DATATARGET.NO-PAYLOADDECODER' | translate}}</ng-template>
53-
</p>
54-
</div>
55-
<div class="col-md-1 d-flex align-items-center justify-content-center">
56-
<fa-icon [icon]="arrowsAltH" class="icon--primary icon--medium icon--disabled"></fa-icon>
57-
</div>
58-
<div class="col-md-7 d-flex align-items-center">
59-
<p><strong>{{'DATATARGET.IOTDEVICE' | translate}}</strong>
60-
<span *ngFor="let device of relation.iotDevices; let first = first">
61-
<ng-container *ngIf="!first">, </ng-container> <a [routerLink]="['/applications', device.application.id, 'iot-device', device.id]">{{device.name}}</a>
62-
</span>
63-
</p>
64-
</div>
65-
<mat-divider></mat-divider>
66-
</div>
67-
</div>
68-
</div>
69-
</div>
70-
</div>
71-
</div>
72-
</div>
73-
</div>
1+
<div>
2+
<ng-template detail-component></ng-template>
743
</div>
Lines changed: 38 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import { Component, OnDestroy, OnInit } from '@angular/core';
2-
import { Subscription } from 'rxjs';
1+
import { Component, ComponentFactoryResolver, OnDestroy, OnInit, Type, ViewChild } from '@angular/core';
32
import { ActivatedRoute } from '@angular/router';
4-
import { TranslateService } from '@ngx-translate/core';
5-
import { PayloadDeviceDatatargetGetByDataTarget } from '@app/payload-decoder/payload-device-data.model';
6-
import { PayloadDeviceDatatargetService } from '@app/payload-decoder/payload-device-datatarget.service';
7-
import { BackButton } from '@shared/models/back-button.model';
8-
import { DatatargetService } from '../datatarget.service';
9-
import { Location } from '@angular/common';
10-
import { DeleteDialogService } from '@shared/components/delete-dialog/delete-dialog.service';
3+
import { DataTargetType } from '@shared/enums/datatarget-type';
4+
import { DatatargetTypesService } from '../datatarget-types.service';
115
import { Datatarget } from '../datatarget.model';
12-
import { DropdownButton } from '@shared/models/dropdown-button.model';
13-
import { faArrowsAltH } from '@fortawesome/free-solid-svg-icons';
6+
import { DatatargetService } from '../datatarget.service';
7+
import { DatatargetDetail } from './datatarget-detail';
8+
import { DatatargetDetailTypeSelectorDirective } from './datatarget-detail-type-selector.directive';
149

1510
@Component({
1611
selector: 'app-datatarget-detail',
@@ -19,79 +14,46 @@ import { faArrowsAltH } from '@fortawesome/free-solid-svg-icons';
1914
})
2015
export class DatatargetDetailComponent implements OnInit, OnDestroy {
2116

22-
public datatargetSubscription: Subscription;
17+
@ViewChild(DatatargetDetailTypeSelectorDirective, {static: true}) adHost!: DatatargetDetailTypeSelectorDirective;
18+
2319
public datatarget: Datatarget;
24-
public backButton: BackButton = { label: '', routerLink: '/datatarget-list' };
25-
public dataTargetRelations: PayloadDeviceDatatargetGetByDataTarget[];
26-
private deleteDialogSubscription: Subscription;
27-
public dropdownButton: DropdownButton;
28-
arrowsAltH = faArrowsAltH;
29-
private applicationName: string;
30-
31-
constructor(
32-
private route: ActivatedRoute,
33-
private deleteDialogService: DeleteDialogService,
34-
private location: Location,
35-
private datatargetRelationServicer: PayloadDeviceDatatargetService,
36-
private datatargetService: DatatargetService,
37-
public translate: TranslateService) { }
20+
private datatargetType: DataTargetType;
3821

39-
ngOnInit(): void {
40-
const id: number = +this.route.snapshot.paramMap.get('datatargetId');
41-
this.applicationName = this.route.snapshot.paramMap.get('name');
42-
if (id) {
43-
this.getDatatarget(id);
44-
this.getDatatargetRelations(id);
45-
this.dropdownButton = {
46-
label: '',
47-
editRouterLink: '../../datatarget-edit/' + id,
48-
isErasable: true,
49-
}
50-
}
51-
this.translate.get(['NAV.MY-DATATARGET', 'DATATARGET.SHOW-OPTIONS'])
52-
.subscribe(translations => {
53-
this.backButton.label = translations['NAV.MY-DATATARGET'];
54-
this.dropdownButton.label = translations['DATATARGET.SHOW-OPTIONS']
55-
});
56-
}
22+
constructor(private componentFactoryResolver: ComponentFactoryResolver,
23+
private datatargetService: DatatargetService,
24+
private route: ActivatedRoute,
25+
private datatargetTypesService: DatatargetTypesService
26+
) { }
5727

58-
getDatatarget(id: number) {
59-
this.datatargetService.get(id)
60-
.subscribe((dataTarget: Datatarget) => {
61-
this.datatarget = dataTarget;
62-
this.setBackButton(this.datatarget.applicationId);
63-
});
64-
}
6528

66-
private setBackButton(applicationId: number) {
67-
this.backButton.routerLink = ['applications', applicationId.toString()]
68-
}
29+
loadComponent(componentType: Type<any>) {
6930

70-
onDeleteDatatarget() {
71-
this.deleteDialogSubscription = this.deleteDialogService.showSimpleDialog().subscribe(
72-
(response) => {
73-
if (response) {
74-
this.datatargetService.delete(this.datatarget.id).subscribe((response) => {
75-
});
76-
this.location.back();
77-
} else {
78-
console.log(response);
79-
}
80-
}
81-
);
82-
}
31+
const viewContainerRef = this.adHost.viewContainerRef;
8332

84-
getDatatargetRelations(id: number) {
85-
this.datatargetRelationServicer.getByDataTarget(id)
86-
.subscribe((response) => {
87-
this.dataTargetRelations = response.data;
88-
});
33+
viewContainerRef.clear();
34+
const factory = this.componentFactoryResolver.resolveComponentFactory(componentType);
35+
viewContainerRef.createComponent<DatatargetDetail>(factory);
8936
}
9037

91-
ngOnDestroy(): void {
92-
if (this.deleteDialogSubscription) {
93-
this.deleteDialogSubscription.unsubscribe();
94-
}
38+
ngOnInit(): void {
39+
40+
const id: number = +this.route.snapshot.paramMap.get('datatargetId');
41+
42+
this.datatargetService.get(id)
43+
.subscribe((dataTarget: Datatarget) => {
44+
this.datatarget = dataTarget;
45+
this.datatargetType = dataTarget.type;
46+
47+
const component = this.datatargetTypesService.getDetailComponent(this.datatargetType);
48+
49+
this.loadComponent(component);
50+
51+
});
52+
53+
9554
}
9655

56+
ngOnDestroy() {
57+
58+
}
9759
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export interface DatatargetDetail {
2+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* tslint:disable:no-unused-variable */
2+
3+
import { ViewContainerRef } from '@angular/core';
4+
import { DatatargetEditTypeSelectorDirective } from './datatarget-edit-type-selector.directive';
5+
let viewContainerRef: ViewContainerRef;
6+
describe('Directive: DatatargetEditTypeSelector', () => {
7+
it('should create an instance', () => {
8+
const directive = new DatatargetEditTypeSelectorDirective(viewContainerRef);
9+
expect(directive).toBeTruthy();
10+
});
11+
});

0 commit comments

Comments
 (0)