Skip to content

Commit

Permalink
NOISSUE - Remove and-jsoneditor and use custom one (absmach#16)
Browse files Browse the repository at this point in the history
* NOISSUE - Remove and-jsoneditor and use custom one

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* NOISSUE - Remove error message if message reader is not running

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
  • Loading branch information
manuio committed Dec 13, 2019
1 parent 2c63288 commit a90ca60
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 65 deletions.
8 changes: 0 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@nebular/eva-icons": "4.1.0",
"@nebular/security": "4.1.0",
"@nebular/theme": "^4.5.0",
"ang-jsoneditor": "^1.8.4",
"angular-tree-component": "7.2.0",
"angular2-chartjs": "0.4.1",
"angular2-toaster": "^7.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/app/auth/auth.token.interceptor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class TokenInterceptor implements HttpInterceptor {
if (err instanceof HttpErrorResponse &&
!request.url.startsWith(environment.writerChannelsUrl) &&
!request.url.startsWith(environment.readerChannelsUrl) &&
!request.url.startsWith(environment.readerVersionUrl) &&
!request.url.startsWith(environment.bootstrapUrl) &&
(err.status === 403 || err.status === 504)) {
localStorage.removeItem('auth_app_token');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@
</nb-card-body>
</nb-card>

<nb-card status="primary" size="small">
<nb-card-header>
Metadata
<button (click)="onEdit()" nbButton status="success" size="tiny">
Edit
</button>
</nb-card-header>
<nb-card-body style="padding: 0px;">
<textarea class="form-control"
[ngModel]="channel.metadata | json"
(ngModelChange)="editorMetadata=$event">
</textarea>
</nb-card-body>
</nb-card>
</div>

<div class="col-md-6">
<nb-card size="small" status="info">
<nb-card-header>
Connection
Expand All @@ -32,7 +49,6 @@
</div>
</div>
</nb-card-body>

<nb-card-body>
<div class="row">
<div class="col-3">Connect to: </div>
Expand All @@ -56,20 +72,4 @@
</nb-card-body>
</nb-card>
</div>

<div class="col-md-6">
<nb-card status="primary" size="large">
<nb-card-header>
Metadata
<button (click)="onEdit()" nbButton status="success" size="tiny">
Edit
</button>
</nb-card-header>
<nb-card-body style="padding: 0;">
<json-editor [options]="editorOptions"
[data]="channel.metadata">
</json-editor>
</nb-card-body>
</nb-card>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ button {
margin-left: 10px;
}

json-editor {
padding: 0;
textarea {
width: 100%;
height: 100%;
}
28 changes: 14 additions & 14 deletions src/app/pages/things/channels/details/channels.details.component.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { ThingsService } from 'app/common/services/things/things.service';
import { ChannelsService } from 'app/common/services/channels/channels.service';
import { NotificationsService } from 'app/common/services/notifications/notifications.service';
import { Channel } from 'app/common/interfaces/mainflux.interface';

import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor';

@Component({
selector: 'ngx-channels-details-component',
templateUrl: './channels.details.component.html',
styleUrls: ['./channels.details.component.scss'],
})
export class ChannelsDetailsComponent implements OnInit {
channel: Channel = {
name: '',
metadata: {},
};
offset = 0;
limit = 20;

channel: Channel = {};

connections: Array<{name: string, id: string}> = [];

things = [];
selectedThings = [];

offset = 0;
limit = 20;
editorMetadata = '';

editorOptions: JsonEditorOptions;
@ViewChild(JsonEditorComponent, { static: true }) editor: JsonEditorComponent;
constructor(
private route: ActivatedRoute,
private thingsService: ThingsService,
private channelsService: ChannelsService,
private notificationsService: NotificationsService,
) {
this.editorOptions = new JsonEditorOptions();
}
) {}

ngOnInit() {
const id = this.route.snapshot.paramMap.get('id');
Expand Down Expand Up @@ -67,7 +61,13 @@ export class ChannelsDetailsComponent implements OnInit {
}

onEdit() {
this.channel.metadata = this.editor.get();
try {
this.channel.metadata = JSON.parse(this.editorMetadata);
} catch (e) {
this.notificationsService.error('Wrong metadata format', '');
return;
}

this.channelsService.editChannel(this.channel).subscribe(
resp => {
this.notificationsService.success('Channel metadata successfully edited', '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
Edit
</button>
</nb-card-header>
<nb-card-body style="padding: 0;">
<json-editor [options]="editorOptions"
[data]="thing.metadata">
</json-editor>
<nb-card-body style="padding: 0px;">
<textarea class="form-control"
[ngModel]="thing.metadata | json"
(ngModelChange)="editorMetadata=$event">
</textarea>
</nb-card-body>
</nb-card>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ button {
margin-left: 10px;
}

json-editor {
padding: 0;
textarea {
width: 100%;
height: 100%;
}
20 changes: 12 additions & 8 deletions src/app/pages/things/devices/details/devices.details.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { ThingsService } from 'app/common/services/things/things.service';
Expand All @@ -7,7 +7,6 @@ import { MessagesService } from 'app/common/services/messages/messages.service';
import { NotificationsService } from 'app/common/services/notifications/notifications.service';
import { Thing } from 'app/common/interfaces/mainflux.interface';

import { JsonEditorComponent, JsonEditorOptions } from 'ang-jsoneditor';

@Component({
selector: 'ngx-devices-details-component',
Expand All @@ -26,17 +25,16 @@ export class DevicesDetailsComponent implements OnInit {
messages = [];
selectedChannels = [];

editorOptions: JsonEditorOptions;
@ViewChild(JsonEditorComponent, { static: true }) editor: JsonEditorComponent;
editorMetadata = '';


constructor(
private route: ActivatedRoute,
private thingsService: ThingsService,
private channelsService: ChannelsService,
private messagesService: MessagesService,
private notificationsService: NotificationsService,
) {
this.editorOptions = new JsonEditorOptions();
}
) {}

ngOnInit() {
const id = this.route.snapshot.paramMap.get('id');
Expand Down Expand Up @@ -75,7 +73,13 @@ export class DevicesDetailsComponent implements OnInit {
}

onEdit() {
this.thing.metadata = this.editor.get();
try {
this.thing.metadata = JSON.parse(this.editorMetadata);
} catch (e) {
this.notificationsService.error('Wrong metadata format', '');
return;
}

this.thingsService.editThing(this.thing).subscribe(
resp => {
this.notificationsService.success('Device metadata successfully edited', '');
Expand Down
2 changes: 0 additions & 2 deletions src/app/pages/things/opcua/opcua.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ export class OpcuaComponent implements OnInit {
},
},
serverURI: {
width: '20%',
title: 'Server URI',
editable: true,
addable: true,
filter: true,
},
nodeID: {
width: '20%',
title: 'Node ID',
editable: true,
addable: true,
Expand Down
2 changes: 0 additions & 2 deletions src/app/pages/things/things.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ import { GatewaysInfoComponent } from 'app/pages/things/gateways/details/info/ga
import { GatewaysConfigComponent } from 'app/pages/things/gateways/details/config/gateways.config.component';
import { GatewaysXtermComponent } from 'app/pages/things/gateways/details/xterm/gateways.xterm.component';

import { NgJsonEditorModule } from 'ang-jsoneditor';

@NgModule({
imports: [
ThingsRoutingModule,
PagesModule,
NbCardModule,
NbButtonModule,
NgJsonEditorModule,
NbSelectModule,
FormsModule,
],
Expand Down
10 changes: 5 additions & 5 deletions src/app/shared/map/leaflet/map.leaflet.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ export class MapComponent implements OnChanges {
private mqttService: MqttService,
) {
this.versionService.getReaderVersion().subscribe(
() => {
resp => {
this.msgServiceON = true;
}, err => {
},
err => {
this.msgServiceON = false;
this.notificationsService.error('Gateways configuration not available',
`Error: ${err.status} - ${err.statusTexts}`);
});
},
);
}

addMarker(lon, lat, gw: Gateway) {
Expand Down

0 comments on commit a90ca60

Please sign in to comment.