Skip to content

Commit 775095e

Browse files
authored
Merge pull request #2 from manuio/conns
NOISSUE - Update ngx-admin, add delete all, imrpove pagination
2 parents 65ac3bd + ce267fd commit 775095e

35 files changed

+298
-205
lines changed

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Stage 0, based on Node.js, to build and compile Angular
2-
FROM node:16.9.1 as node
2+
FROM node:16.10-alpine as node
33
WORKDIR /app
44
COPY package.json /app/
55
COPY package-lock.json /app/

docker/nginx/nginx-key.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ http {
5757
}
5858

5959
# Proxy pass to things service
60-
location ~ ^/(things|channels|connect) {
60+
location ~ ^/(things|channels|connect|disconnect) {
6161
include snippets/proxy-headers.conf;
6262
add_header Access-Control-Expose-Headers Location;
6363
proxy_pass http://things:${MF_THINGS_HTTP_PORT};

docker/nginx/nginx-x509.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ http {
6363
}
6464

6565
# Proxy pass to things service
66-
location ~ ^/(things|channels|connect) {
66+
location ~ ^/(things|channels|connect|disconnect) {
6767
include snippets/proxy-headers.conf;
6868
add_header Access-Control-Expose-Headers Location;
6969
proxy_pass http://things:${MF_THINGS_HTTP_PORT};

proxy-config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
"target": "http://localhost:8182",
3232
"secure": false
3333
},
34+
"/disconnect": {
35+
"target": "http://localhost:8182",
36+
"secure": false
37+
},
3438
"/channels/*": {
3539
"target": "http://localhost:8182",
3640
"secure": false

src/app/common/common.module.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { NgModule } from '@angular/core';
22

33
import 'rxjs/add/operator/catch';
4-
import 'rxjs/add/observable/throw';
54
import 'rxjs/add/operator/switchMap';
65
import 'rxjs/add/operator/map';
76

src/app/common/services/channels/channels.service.ts

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { HttpClient, HttpParams } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
3-
import { Observable } from 'rxjs';
3+
import { throwError } from 'rxjs';
44

55
import { environment } from 'environments/environment';
66
import { Channel, PageFilters } from 'app/common/interfaces/mainflux.interface';
77
import { NotificationsService } from 'app/common/services/notifications/notifications.service';
88

99
const defLimit: number = 10;
10-
const defConnLimit: number = 5;
1110

1211
@Injectable()
1312
export class ChannelsService {
@@ -28,7 +27,7 @@ export class ChannelsService {
2827
err => {
2928
this.notificationsService.error('Failed to create Channel',
3029
`Error: ${err.status} - ${err.statusText}`);
31-
return Observable.throw(err);
30+
return throwError(err);
3231
},
3332
);
3433
}
@@ -44,7 +43,7 @@ export class ChannelsService {
4443
err => {
4544
this.notificationsService.error('Failed to create Channels',
4645
`Error: ${err.status} - ${err.statusText}`);
47-
return Observable.throw(err);
46+
return throwError(err);
4847
},
4948
);
5049
}
@@ -60,7 +59,7 @@ export class ChannelsService {
6059
err => {
6160
this.notificationsService.error('Failed to fetch Channel',
6261
`Error: ${err.status} - ${err.statusText}`);
63-
return Observable.throw(err);
62+
return throwError(err);
6463
},
6564
);
6665
}
@@ -97,7 +96,7 @@ export class ChannelsService {
9796
err => {
9897
this.notificationsService.error('Failed to fetch Channels',
9998
`Error: ${err.status} - ${err.statusText}`);
100-
return Observable.throw(err);
99+
return throwError(err);
101100
},
102101
);
103102
}
@@ -113,7 +112,7 @@ export class ChannelsService {
113112
err => {
114113
this.notificationsService.error('Failed to edit Channel',
115114
`Error: ${err.status} - ${err.statusText}`);
116-
return Observable.throw(err);
115+
return throwError(err);
117116
},
118117
);
119118
}
@@ -129,7 +128,7 @@ export class ChannelsService {
129128
err => {
130129
this.notificationsService.error('Failed to delete Channel',
131130
`Error: ${err.status} - ${err.statusText}`);
132-
return Observable.throw(err);
131+
return throwError(err);
133132
},
134133
);
135134
}
@@ -145,7 +144,7 @@ export class ChannelsService {
145144
err => {
146145
this.notificationsService.error('Failed to connect Thing to Channel',
147146
`Error: ${err.status} - ${err.statusText}`);
148-
return Observable.throw(err);
147+
return throwError(err);
149148
},
150149
);
151150
}
@@ -163,9 +162,9 @@ export class ChannelsService {
163162
)
164163
.catch(
165164
err => {
166-
this.notificationsService.error('Failed to connect Things to Channels',
165+
this.notificationsService.error('Failed to connect Thing(s) to Channel(s)',
167166
`Error: ${err.status} - ${err.statusText}`);
168-
return Observable.throw(err);
167+
return throwError(err);
169168
},
170169
);
171170
}
@@ -181,14 +180,34 @@ export class ChannelsService {
181180
err => {
182181
this.notificationsService.error('Failed to disconnect Thing from Channel',
183182
`Error: ${err.status} - ${err.statusText}`);
184-
return Observable.throw(err);
183+
return throwError(err);
184+
},
185+
);
186+
}
187+
188+
disconnectThings(channelIDs: string[], thingIDs: string[]) {
189+
const conReq = {
190+
channel_ids: channelIDs,
191+
thing_ids: thingIDs,
192+
};
193+
return this.http.put(`${environment.disconnectUrl}`, conReq)
194+
.map(
195+
resp => {
196+
return resp;
197+
},
198+
)
199+
.catch(
200+
err => {
201+
this.notificationsService.error('Failed to disconnect Thing(s) from Channel(s)',
202+
`Error: ${err.status} - ${err.statusText}`);
203+
return throwError(err);
185204
},
186205
);
187206
}
188207

189208
connectedThings(chanID: string, offset?: number, limit?: number) {
190209
offset = offset || 0;
191-
limit = limit || defConnLimit;
210+
limit = limit || defLimit;
192211

193212
const params = new HttpParams()
194213
.set('offset', offset.toString())
@@ -204,14 +223,14 @@ export class ChannelsService {
204223
err => {
205224
this.notificationsService.error('Failed to fetch connected Things to the Channel',
206225
`Error: ${err.status} - ${err.statusText}`);
207-
return Observable.throw(err);
226+
return throwError(err);
208227
},
209228
);
210229
}
211230

212231
disconnectedThings(chanID: string, offset?: number, limit?: number) {
213232
offset = offset || 0;
214-
limit = limit || defConnLimit;
233+
limit = limit || defLimit;
215234

216235
const params = new HttpParams()
217236
.set('offset', offset.toString())
@@ -228,7 +247,7 @@ export class ChannelsService {
228247
err => {
229248
this.notificationsService.error('Failed to fetch not connected Things to the Channel',
230249
`Error: ${err.status} - ${err.statusText}`);
231-
return Observable.throw(err);
250+
return throwError(err);
232251
},
233252
);
234253
}

src/app/common/services/messages/messages.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HttpClient, HttpHeaders } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
3-
import { Observable } from 'rxjs';
3+
import { throwError } from 'rxjs';
44

55
import { environment } from 'environments/environment';
66
import { ThingsService } from 'app/common/services/things/things.service';
@@ -47,7 +47,7 @@ export class MessagesService {
4747
err => {
4848
this.notificationsService.error('Failed to read Messages',
4949
`Error: ${err.status} - ${err.statusText}`);
50-
return Observable.throw(err);
50+
return throwError(err);
5151
},
5252
);
5353
}
@@ -70,7 +70,7 @@ export class MessagesService {
7070
err => {
7171
this.notificationsService.error('Failed to send Message',
7272
`Error: ${err.status} - ${err.statusText}`);
73-
return Observable.throw(err);
73+
return throwError(err);
7474
},
7575
);
7676
}

src/app/common/services/opcua/opcua.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@angular/core';
22
import { HttpClient, HttpParams } from '@angular/common/http';
3-
import { Observable } from 'rxjs';
3+
import { throwError } from 'rxjs';
44

55
import { environment } from 'environments/environment';
66
import { OpcuaNode, OpcuaTableRow } from 'app/common/interfaces/opcua.interface';
@@ -170,7 +170,7 @@ export class OpcuaService {
170170
err => {
171171
this.notificationsService.error('Failed to Browse',
172172
`Error: ${err.status} - ${err.statusText}`);
173-
return Observable.throw(err);
173+
return throwError(err);
174174
},
175175
);
176176
}

src/app/common/services/things/things.service.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { HttpClient, HttpParams } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
3-
import { Observable } from 'rxjs';
3+
import { throwError } from 'rxjs';
44

55
import { environment } from 'environments/environment';
66
import { Thing, PageFilters } from 'app/common/interfaces/mainflux.interface';
77
import { NotificationsService } from 'app/common/services/notifications/notifications.service';
88

99
const defLimit: number = 10;
10-
const defConnLimit: number = 5;
1110

1211
@Injectable()
1312
export class ThingsService {
@@ -28,7 +27,7 @@ export class ThingsService {
2827
err => {
2928
this.notificationsService.error('Failed to create Thing',
3029
`Error: ${err.status} - ${err.statusText}`);
31-
return Observable.throw(err);
30+
return throwError(err);
3231
},
3332
);
3433
}
@@ -44,7 +43,7 @@ export class ThingsService {
4443
err => {
4544
this.notificationsService.error('Failed to create Things',
4645
`Error: ${err.status} - ${err.statusText}`);
47-
return Observable.throw(err);
46+
return throwError(err);
4847
},
4948
);
5049
}
@@ -60,7 +59,7 @@ export class ThingsService {
6059
err => {
6160
this.notificationsService.error('Failed to fetch Thing',
6261
`Error: ${err.status} - ${err.statusText}`);
63-
return Observable.throw(err);
62+
return throwError(err);
6463
},
6564
);
6665
}
@@ -97,7 +96,7 @@ export class ThingsService {
9796
err => {
9897
this.notificationsService.error('Failed to get Things',
9998
`Error: ${err.status} - ${err.statusText}`);
100-
return Observable.throw(err);
99+
return throwError(err);
101100
},
102101
);
103102
}
@@ -113,7 +112,7 @@ export class ThingsService {
113112
err => {
114113
this.notificationsService.error('Failed to delete Thing',
115114
`Error: ${err.status} - ${err.statusText}`);
116-
return Observable.throw(err);
115+
return throwError(err);
117116
},
118117
);
119118
}
@@ -129,14 +128,14 @@ export class ThingsService {
129128
err => {
130129
this.notificationsService.error('Failed to edit Thing',
131130
`Error: ${err.status} - ${err.statusText}`);
132-
return Observable.throw(err);
131+
return throwError(err);
133132
},
134133
);
135134
}
136135

137136
connectedChannels(thingID: string, offset?: number, limit?: number) {
138137
offset = offset || 0;
139-
limit = limit || defConnLimit;
138+
limit = limit || defLimit;
140139

141140
const params = new HttpParams()
142141
.set('offset', offset.toString())
@@ -152,16 +151,16 @@ export class ThingsService {
152151
)
153152
.catch(
154153
err => {
155-
this.notificationsService.error('Failed to fetch connected Chanels to the Thing',
154+
this.notificationsService.error('Failed to fetch connected Channels to the Thing',
156155
`Error: ${err.status} - ${err.statusText}`);
157-
return Observable.throw(err);
156+
return throwError(err);
158157
},
159158
);
160159
}
161160

162161
disconnectedChannels(thingID: string, offset?: number, limit?: number) {
163162
offset = offset || 0;
164-
limit = limit || defConnLimit;
163+
limit = limit || defLimit;
165164

166165
const params = new HttpParams()
167166
.set('offset', offset.toString())
@@ -180,7 +179,7 @@ export class ThingsService {
180179
err => {
181180
this.notificationsService.error('Failed to fetch not connected Channels to the Thing',
182181
`Error: ${err.status} - ${err.statusText}`);
183-
return Observable.throw(err);
182+
return throwError(err);
184183
},
185184
);
186185
}

0 commit comments

Comments
 (0)