Unverified Commit d2d3fdb4 authored by badboy-huaqiao's avatar badboy-huaqiao Committed by GitHub
Browse files

feat: Issue #275 deviceprofle list component refactor (#321)


* refactor: replace profile-list codes in device-add parent componet with profile list child component
Signed-off-by: default avatarHuaqiao Zhang <huaqiaoz@vmware.com>

* feat: Add new input property toolbars
Signed-off-by: default avatarHuaqiao Zhang <huaqiaoz@vmware.com>

* feat: replace hard code of device-profile-list with device profile list component
Signed-off-by: default avatarHuaqiao Zhang <huaqiaoz@vmware.com>
parent c5ee145f
main dependabot/go_modules/github.com/eclipse/paho.mqtt.golang-1.3.3 dependabot/go_modules/github.com/eclipse/paho.mqtt.golang-1.3.4 dependabot/go_modules/github.com/edgexfoundry/go-mod-configuration/v2-2.0.0 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.100 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.101 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.102 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.103 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.64 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.66 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.67 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.69 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.71 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.73 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.74 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.76 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.77 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.78 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.80 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.82 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.83 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.84 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.87 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.89 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.90 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.91 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.93 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.94 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.95 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.97 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.98 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.0.0-dev.99 dependabot/go_modules/github.com/edgexfoundry/go-mod-core-contracts/v2-2.1.0 dependabot/go_modules/github.com/edgexfoundry/go-mod-registry/v2-2.0.1-dev.5 dependabot/go_modules/github.com/edgexfoundry/go-mod-registry/v2-2.0.1-dev.6 dependabot/go_modules/github.com/edgexfoundry/go-mod-registry/v2-2.0.1-dev.7 dependabot/go_modules/github.com/edgexfoundry/go-mod-registry/v2-2.0.1-dev.8 dependabot/go_modules/github.com/edgexfoundry/go-mod-registry/v2-2.0.1-dev.9 dependabot/go_modules/github.com/edgexfoundry/go-mod-registry/v2-2.1.0 dependabot/go_modules/github.com/pelletier/go-toml-1.9.0 dependabot/go_modules/github.com/pelletier/go-toml-1.9.1 dependabot/go_modules/github.com/pelletier/go-toml-1.9.2 dependabot/go_modules/github.com/pelletier/go-toml-1.9.3 dependabot/go_modules/github.com/pelletier/go-toml-1.9.4 dependabot/npm_and_yarn/web/engine.io-4.1.2 dependabot/npm_and_yarn/web/follow-redirects-1.14.7 dependabot/npm_and_yarn/web/follow-redirects-1.14.8 dependabot/npm_and_yarn/web/karma-6.3.14 dependabot/npm_and_yarn/web/karma-6.3.16 dependabot/npm_and_yarn/web/nanoid-3.2.0 dependabot/npm_and_yarn/web/url-parse-1.5.10 master v2.1.1-dev.15 v2.1.1-dev.14 v2.1.1-dev.13 v2.1.1-dev.12 v2.1.1-dev.11 v2.1.1-dev.10 v2.1.1-dev.9 v2.1.1-dev.8 v2.1.1-dev.7 v2.1.1-dev.6 v2.1.1-dev.5 v2.1.1-dev.4 v2.1.1-dev.3 v2.1.1-dev.2 v2.1.1-dev.1 v2.1.0 v2.0.1-dev.33 v2.0.1-dev.32 v2.0.1-dev.31 v2.0.1-dev.30 v2.0.1-dev.29 v2.0.1-dev.28 v2.0.1-dev.27 v2.0.1-dev.26 v2.0.1-dev.25 v2.0.1-dev.24 v2.0.1-dev.23 v2.0.1-dev.22 v2.0.1-dev.21 v2.0.1-dev.20 v2.0.1-dev.19 v2.0.1-dev.18 v2.0.1-dev.17 v2.0.1-dev.16 v2.0.1-dev.15 v2.0.1-dev.14 v2.0.1-dev.13 v2.0.1-dev.12 v2.0.1-dev.11 v2.0.1-dev.10 v2.0.1-dev.9 v2.0.1-dev.8 v2.0.1-dev.7 v2.0.1-dev.6 v2.0.1-dev.5 v2.0.1-dev.4 v2.0.1-dev.3 v2.0.1-dev.2 v2.0.1-dev.1 v2.0.0 v2.0.0-dev.87 v2.0.0-dev.86 v2.0.0-dev.85 v2.0.0-dev.84 v2.0.0-dev.83 v2.0.0-dev.82 v2.0.0-dev.81 v2.0.0-dev.80 v2.0.0-dev.79 v2.0.0-dev.78 v2.0.0-dev.77 v2.0.0-dev.76 v2.0.0-dev.75 v2.0.0-dev.74 v2.0.0-dev.73 v2.0.0-dev.72 v2.0.0-dev.71 v2.0.0-dev.70 v2.0.0-dev.69 v2.0.0-dev.68 v2.0.0-dev.67 v2.0.0-dev.66 v2.0.0-dev.65 v2.0.0-dev.64 v2.0.0-dev.63 v2.0.0-dev.62 v2.0.0-dev.61 v2.0.0-dev.60 v2.0.0-dev.59 v2.0.0-dev.58 v2.0.0-dev.57 v2.0.0-dev.56 v2.0.0-dev.55 v2.0.0-dev.54 v2.0.0-dev.53 v2.0.0-dev.52 v2.0.0-dev.51 v2.0.0-dev.50 v2.0.0-dev.49 v2.0.0-dev.48 v2.0.0-dev.47 v2.0.0-dev.46 v2.0.0-dev.45 v2.0.0-dev.44 v2.0.0-dev.43 v2.0.0-dev.42 v2.0.0-dev.41 v2.0.0-dev.40 v2.0.0-dev.39 v2.0.0-dev.38 v2.0.0-dev.37 v2.0.0-dev.36 v2.0.0-dev.35 v2.0.0-dev.34 v2.0.0-dev.33 v2.0.0-dev.32 v2.0.0-dev.31 v2.0.0-dev.30 v2.0.0-dev.29 v2.0.0-dev.28 v2.0.0-dev.27
No related merge requests found
Showing with 147 additions and 95 deletions
+147 -95
......@@ -88,7 +88,10 @@
</ng-template>
<ng-template [ngSwitchCase]="1" #SelectDeviceProfile>
<div class="table-responsive">
<div class="p-2">
<app-device-profile-list (singleProfileSelectedEvent)="onSingleProfileSelected($event)" [enableSelectAll]="false" [toolbars]="false"></app-device-profile-list>
</div>
<!-- <div class="table-responsive">
<table class="table table-hover text-truncate">
<thead class="thead-light">
<tr>
......@@ -99,8 +102,8 @@
<th scope="col">Labels</th>
<th scope="col">Manufacturer</th>
<th scope="col">Model</th>
<!-- <th scope="col">Created</th>
<th scope="col">Modified</th> -->
<th scope="col">Created</th>
<th scope="col">Modified</th>
</tr>
</thead>
<tbody>
......@@ -112,12 +115,12 @@
<td>{{profile.labels}}</td>
<td>{{profile.manufacturer}}</td>
<td>{{profile.model}}</td>
<!-- <td>{{profile.created | date:'yyyy-MM-dd hh:mm:ss' }}</td>
<td>{{profile.modified | date:'yyyy-MM-dd hh:mm:ss' }}</td> -->
<td>{{profile.created | date:'yyyy-MM-dd hh:mm:ss' }}</td>
<td>{{profile.modified | date:'yyyy-MM-dd hh:mm:ss' }}</td>
</tr>
</tbody>
</table>
</div>
</div> -->
</ng-template>
<ng-template [ngSwitchCase]="2" #DevicePrimary>
......
......@@ -21,7 +21,7 @@ import { DeviceService } from '../../../contracts/v2/device-service';
import { MultiDeviceServiceResponse } from '../../../contracts/v2/responses/device-service-response';
import { Device } from '../../../contracts/v2/device';
import { DeviceProfile } from '../../../contracts/v2/device-profile';
import { MultiDeviceProfileResponse } from '../../../contracts/v2/responses/device-profile-response';
// import { MultiDeviceProfileResponse } from '../../../contracts/v2/responses/device-profile-response';
import { AutoEvent } from '../../../contracts/v2/auto-event';
import { MetadataService } from '../../../services/metadata.service';
......@@ -80,7 +80,7 @@ export class AddDeviceComponent implements OnInit {
noSelectedClass = "text-white rounded px-2 bg-secondary font-weight-bold";
deviceServiceList: DeviceService[] = [];
deviceProfileList: DeviceProfile[] = [];
// deviceProfileList: DeviceProfile[] = [];
selectedSvc?: DeviceService;
selectedProfile?: DeviceProfile;
......@@ -123,9 +123,13 @@ export class AddDeviceComponent implements OnInit {
this.metaSvc.allDeviceServices().subscribe((data: MultiDeviceServiceResponse) => {
this.deviceServiceList = data.services;
});
this.metaSvc.allDeviceProfoles().subscribe((data: MultiDeviceProfileResponse) => {
this.deviceProfileList = data.profiles;
});
// this.metaSvc.allDeviceProfoles().subscribe((data: MultiDeviceProfileResponse) => {
// this.deviceProfileList = data.profiles;
// });
}
onSingleProfileSelected(profile: DeviceProfile) {
this.selectedProfile = profile;
}
onAvailProtocolSelect() {
......@@ -224,22 +228,22 @@ export class AddDeviceComponent implements OnInit {
this.autoEventsInternal.splice(this.autoEventsInternal.indexOf(event), 1);
}
isProfileChecked(name: string): boolean {
return this.selectedProfile?.name === name
}
selectOneProfile(event: any, name: string) {
const checkbox = event.target;
if (checkbox.checked) {
this.deviceProfileList.forEach((profile) => {
if (profile.name === name) {
this.selectedProfile = profile;
}
});
} else {
this.selectedProfile = undefined;
}
}
// isProfileChecked(name: string): boolean {
// return this.selectedProfile?.name === name
// }
// selectOneProfile(event: any, name: string) {
// const checkbox = event.target;
// if (checkbox.checked) {
// this.deviceProfileList.forEach((profile) => {
// if (profile.name === name) {
// this.selectedProfile = profile;
// }
// });
// } else {
// this.selectedProfile = undefined;
// }
// }
isSvcChecked(name: string): boolean {
return this.selectedSvc?.name === name
......
......@@ -116,7 +116,11 @@
</div>
</div>
<div class="card mb-3">
<div class="mb-3">
<app-device-profile-list (singleProfileSelectedEvent)="onSingleProfileSelected($event)" [enableSelectAll]="false" [toolbars]="false"></app-device-profile-list>
</div>
<!-- <div class="card mb-3">
<div class="card-header font-weight-bold">
<i class="fa fa-tags fa-lg text-danger"></i> Device Profile
</div>
......@@ -132,8 +136,8 @@
<th scope="col">Labels</th>
<th scope="col">Manufacturer</th>
<th scope="col">Model</th>
<!-- <th scope="col">Created</th>
<th scope="col">Modified</th> -->
<th scope="col">Created</th>
<th scope="col">Modified</th>
</tr>
</thead>
<tbody>
......@@ -145,14 +149,14 @@
<td>{{profile.labels}}</td>
<td>{{profile.manufacturer}}</td>
<td>{{profile.model}}</td>
<!-- <td>{{profile.created | date:'yyyy-MM-dd hh:mm:ss' }}</td>
<td>{{profile.modified | date:'yyyy-MM-dd hh:mm:ss' }}</td> -->
<td>{{profile.created | date:'yyyy-MM-dd hh:mm:ss' }}</td>
<td>{{profile.modified | date:'yyyy-MM-dd hh:mm:ss' }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div> -->
<div class="card mb-3">
<div class="card-header font-weight-bold">
......
......@@ -52,7 +52,7 @@ export class EditDeviceComponent implements OnInit {
device?: Device;
deviceLabels?: string;
deviceServiceList!: DeviceService[];
deviceProfileList!: DeviceProfile[];
// deviceProfileList?: DeviceProfile[];
selectedSvc?: DeviceService;
selectedProfile?: DeviceProfile;
......@@ -95,19 +95,22 @@ export class EditDeviceComponent implements OnInit {
});
});
this.metaSvc.allDeviceProfoles().subscribe((data: MultiDeviceProfileResponse) => {
this.deviceProfileList = data.profiles;
this.deviceProfileList.forEach((profile) => {
if (profile.name === this.device?.profileName) {
this.selectedProfile = profile;
return
}
});
});
// this.metaSvc.allDeviceProfoles().subscribe((data: MultiDeviceProfileResponse) => {
// this.deviceProfileList = data.profiles;
// this.deviceProfileList.forEach((profile) => {
// if (profile.name === this.device?.profileName) {
// this.selectedProfile = profile;
// return
// }
// });
// });
});
});
}
onSingleProfileSelected(profile: DeviceProfile) {
this.selectedProfile = profile;
}
setAutoEventInternal(events?: AutoEvent[]) {
let unit: string;
......@@ -162,24 +165,24 @@ export class EditDeviceComponent implements OnInit {
this.autoEventsInternal.splice(this.autoEventsInternal.indexOf(event), 1);
}
isProfileChecked(name: string): boolean {
return this.selectedProfile?.name === name
}
// isProfileChecked(name: string): boolean {
// return this.selectedProfile?.name === name
// }
selectOneProfile(event: any, name: string) {
const checkbox = event.target;
// selectOneProfile(event: any, name: string) {
// const checkbox = event.target;
if (checkbox.checked) {
this.deviceProfileList.forEach((profile) => {
if (profile.name === name) {
this.selectedProfile = profile;
return
}
});
} else {
this.selectedProfile = undefined;
}
}
// if (checkbox.checked) {
// this.deviceProfileList.forEach((profile) => {
// if (profile.name === name) {
// this.selectedProfile = profile;
// return
// }
// });
// } else {
// this.selectedProfile = undefined;
// }
// }
isSvcChecked(name: string): boolean {
return this.selectedSvc?.name === name
......
......@@ -17,11 +17,11 @@
-->
<div class="card">
<div class="card-header">
<div class="card-header font-weight-bold">
<i class="fa fa-th-list text-danger"></i> Device Profile List
</div>
<div class="card-body p-0">
<div class="bg-light px-2 py-2">
<div *ngIf="toolbars" class="bg-light px-2 py-2">
<div class="btn-group btn-group-sm" role="group">
<button class="btn btn-primary" (click)="refresh()">
<span><i class="fa fa-refresh mr-1"></i>Refresh</span>
......@@ -29,10 +29,10 @@
<button type="button" class="btn btn-info" routerLink="../add-profile">
<span><i class="fa fa-plus mr-1"></i>Add</span>
</button>
<button type="button" class="btn btn-success" (click)="edit()" data-toggle="tooltip" data-placement="top" title="only one should be selected" [disabled]="selectedProfiles.length !== 1">
<button type="button" class="btn btn-success" (click)="edit()" data-toggle="tooltip" data-placement="top" title="only one should be selected" [disabled]="multiProfilesSelected.length !== 1">
<span><i class="fa fa-edit mr-1"></i>Edit</span>
</button>
<button type="button" class="btn btn-danger" (click)="deleteConfirm()" [disabled]="selectedProfiles.length === 0">
<button type="button" class="btn btn-danger" (click)="deleteConfirm()" [disabled]="multiProfilesSelected.length === 0">
<span><i class="fa fa-trash mr-1"></i>Delete</span>
</button>
</div>
......@@ -42,7 +42,9 @@
<table class="table table-hover text-truncate">
<thead class="thead-light">
<tr>
<th scope="col"><input type="checkbox" [checked]="isCheckedAll" (click)="selectAll($event)"></th>
<th scope="col">
<input *ngIf="enableSelectAll" type="checkbox" [checked]="isCheckedAll" (click)="selectAll($event)">
</th>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Description</th>
......
......@@ -14,7 +14,7 @@
* @author: Huaqiao Zhang, <huaqiaoz@vmware.com>
*******************************************************************************/
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { MetadataService } from '../../../services/metadata.service';
......@@ -28,9 +28,13 @@ import { DeviceProfile } from '../../../contracts/v2/device-profile';
styleUrls: ['./device-profile-list.component.css']
})
export class DeviceProfileListComponent implements OnInit {
@Input() toolbars: boolean = true;
@Input() enableSelectAll: boolean = true;
@Output() singleProfileSelectedEvent = new EventEmitter<DeviceProfile>();
profileList: DeviceProfile[] = [];
selectedProfiles: string[] = [];
multiProfilesSelected: string[] = [];
singleProfileSelected?: DeviceProfile;
isCheckedAll: boolean = false;
pagination: number = 1;
pageLimit: number = 5;
......@@ -56,11 +60,16 @@ export class DeviceProfileListComponent implements OnInit {
});
}
onSingleProfileSelectedEmitter() {
this.singleProfileSelectedEvent.emit(this.singleProfileSelected);
}
refresh() {
this.metaSvc.allDeviceProfolesPagination(0,this.pageLimit).subscribe((data: MultiDeviceProfileResponse) => {
this.profileList = data.profiles;
this.msgSvc.success('refresh');
this.pagination = 1;
this.resetCheckbox();
});
}
......@@ -79,11 +88,6 @@ export class DeviceProfileListComponent implements OnInit {
});
}
resetPagination() {
this.pageOffset = 0;
this.pageLimit = 5;
}
setPageLimit(n: number) {
this.pageLimit = n;
}
......@@ -91,20 +95,30 @@ export class DeviceProfileListComponent implements OnInit {
setPagination(n?: number) {
if (n === 1) {
this.pagination += 1;
} else {
this.pagination -= 1;
}
this.pageOffset = (this.pagination - 1) * this.pageLimit;
this.resetCheckbox();
}
resetPagination() {
this.pageOffset = 0;
this.pageLimit = 5;
this.resetCheckbox();
}
resetCheckbox() {
this.isCheckedAll = false; //reset checkbox all
this.multiProfilesSelected = [];
}
edit() {
this.router.navigate(['../edit-profile'], {
relativeTo: this.route,
queryParams: {
'profileName': this.selectedProfiles[0]
'profileName': this.multiProfilesSelected[0]
}
});
}
......@@ -114,9 +128,9 @@ export class DeviceProfileListComponent implements OnInit {
}
delete() {
this.selectedProfiles.forEach((profileName) => {
this.multiProfilesSelected.forEach((profileName) => {
this.metaSvc.deleteProfileByName(profileName).subscribe(() => {
this.selectedProfiles = [];
this.multiProfilesSelected = [];
this.profileList.forEach((profile, index) => {
if (profile.name == profileName) {
this.profileList.splice(index, 1);
......@@ -128,42 +142,65 @@ export class DeviceProfileListComponent implements OnInit {
$("#deleteConfirmDialog").modal('hide');
}
isSingleProfileChecked(name: string): boolean {
return this.singleProfileSelected?.name === name
}
selectSingleProfile(event: any, name: string) {
const checkbox = event.target;
if (checkbox.checked) {
this.profileList.forEach((profile) => {
if (profile.name === name) {
this.singleProfileSelected = profile;
}
});
} else {
this.singleProfileSelected = undefined;
}
this.onSingleProfileSelectedEmitter();
}
selectAll(event: any) {
const checkbox = event.target;
let self = this;
if (checkbox.checked) {
this.selectedProfiles = [];
this.profileList.forEach(function (item) {
self.selectedProfiles.push(item.id);
self.isChecked(item.id);
this.multiProfilesSelected = [];
this.profileList.forEach(profile => {
this.multiProfilesSelected.push(profile.name);
this.isChecked(profile.name);
});
this.isCheckedAll = true;
return
}
this.isCheckedAll = false;
this.selectedProfiles = [];
this.profileList.forEach(function (item) {
self.isChecked(item.id);
this.multiProfilesSelected = [];
this.profileList.forEach(profile => {
this.isChecked(profile.name);
});
}
isChecked(id: string): boolean {
return this.selectedProfiles.findIndex(v => v === id) >= 0;
isChecked(name: string): boolean {
if (!this.enableSelectAll) {
return this.isSingleProfileChecked(name)
}
return this.multiProfilesSelected.findIndex(v => v === name) >= 0;
}
selectOne(event: any, id: string) {
selectOne(event: any, name: string) {
if (!this.enableSelectAll) {
this.selectSingleProfile(event, name);
return
}
const checkbox = event.target;
if (checkbox.checked) {
this.selectedProfiles.push(id);
// console.log(this.selectedDevice)
if (this.selectedProfiles.length === this.profileList.length) {
this.multiProfilesSelected.push(name);
if (this.multiProfilesSelected.length === this.profileList.length) {
this.isCheckedAll = true;
}
return
}
this.isCheckedAll = false;
this.isChecked(id);
this.selectedProfiles.splice(this.selectedProfiles.indexOf(id), 1)
this.isChecked(name);
this.multiProfilesSelected.splice(this.multiProfilesSelected.indexOf(name), 1)
}
}
......@@ -234,7 +234,6 @@ export class MetadataService {
allDeviceProfolesPagination(offset: number, limit: number): Observable<MultiDeviceProfileResponse> {
let url = `${this.deviceProfilesListUrl}?offset=${offset}&limit=${limit}`;
console.log(url)
return this.http.get<MultiDeviceProfileResponse>(url).pipe(
catchError(error => this.errorSvc.handleError(error))
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment