Browse Source

Refactor all IoT Hub dialogs: inject IotHubApiService instead of passing via data

- Remove iotHubApiService from IotHubItemDetailDialogData, inject in constructor
- Remove iotHubApiService from IotHubInstallDialogData, inject in constructor
- Remove iotHubApiService from IotHubUpdateDialogData, inject in constructor
- Remove iotHubApiService from DeviceInstallDialogData, inject in constructor
- Update all callers (home, browse, search, installed items, widget select,
  item detail dialog) to remove iotHubApiService from dialog data
- Fix device install dialog data (item + zipData) after bulk removal
pull/15508/head
Igor Kulikov 6 months ago
parent
commit
2750e37147
  1. 1
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts
  2. 5
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts
  3. 19
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts
  4. 6
      ui-ngx/src/app/modules/home/pages/iot-hub/device-install-dialog/device-install-dialog.component.ts
  5. 5
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts
  6. 6
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-install-dialog.component.ts
  7. 3
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.ts
  8. 6
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search.component.ts
  9. 6
      ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-update-dialog.component.ts

1
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-widget-select.component.ts

@ -354,7 +354,6 @@ export class DashboardWidgetSelectComponent implements OnInit {
autoFocus: false,
data: {
item,
iotHubApiService: this.iotHubApiService,
mode: 'add'
} as IotHubItemDetailDialogData
});

5
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-browse.component.ts

@ -437,7 +437,6 @@ export class TbIotHubBrowseComponent implements OnInit, OnDestroy {
autoFocus: false,
data: {
item,
iotHubApiService: this.iotHubApiService,
installedItem: this.getInstalledItem(item),
mode: this.mode
} as IotHubItemDetailDialogData
@ -465,7 +464,6 @@ export class TbIotHubBrowseComponent implements OnInit, OnDestroy {
autoFocus: false,
data: {
item,
iotHubApiService: this.iotHubApiService
} as IotHubInstallDialogData
});
dialogRef.afterClosed().subscribe(result => {
@ -483,7 +481,7 @@ export class TbIotHubBrowseComponent implements OnInit, OnDestroy {
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
disableClose: true,
autoFocus: false,
data: { item, zipData, iotHubApiService: this.iotHubApiService } as DeviceInstallDialogData
data: { item, zipData } as DeviceInstallDialogData
});
dialogRef.afterClosed().subscribe(result => {
if (result === 'installed') {
@ -508,7 +506,6 @@ export class TbIotHubBrowseComponent implements OnInit, OnDestroy {
itemType: item.type,
version: item.version,
versionId: item.id,
iotHubApiService: this.iotHubApiService
} as IotHubUpdateDialogData
});
dialogRef.afterClosed().subscribe(result => {

19
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-item-detail-dialog.component.ts

@ -35,7 +35,6 @@ export type IotHubItemDetailDialogMode = 'default' | 'add';
export interface IotHubItemDetailDialogData {
item: MpItemVersionView;
iotHubApiService: IotHubApiService;
installedItem?: IotHubInstalledItem;
mode?: IotHubItemDetailDialogMode;
}
@ -65,7 +64,8 @@ export class TbIotHubItemDetailDialogComponent {
private dialogRef: MatDialogRef<TbIotHubItemDetailDialogComponent>,
private dialog: MatDialog,
private router: Router,
private translate: TranslateService
private translate: TranslateService,
private iotHubApiService: IotHubApiService
) {
this.item = data.item;
this.mode = data.mode || 'default';
@ -86,7 +86,7 @@ export class TbIotHubItemDetailDialogComponent {
}
getPreviewUrl(): string | null {
return this.item.image ? this.data.iotHubApiService.resolveResourceUrl(this.item.image) : null;
return this.item.image ? this.iotHubApiService.resolveResourceUrl(this.item.image) : null;
}
getTypeChipClass(): string {
@ -253,7 +253,6 @@ export class TbIotHubItemDetailDialogComponent {
panelClass: ['tb-dialog'],
data: {
item: this.item,
iotHubApiService: this.data.iotHubApiService
} as IotHubInstallDialogData
});
dialogRef.afterClosed().subscribe(result => {
@ -265,7 +264,7 @@ export class TbIotHubItemDetailDialogComponent {
private installDevice(): void {
const versionId = this.item.id as string;
this.data.iotHubApiService.getVersionFileData(versionId, { ignoreLoading: true }).subscribe({
this.iotHubApiService.getVersionFileData(versionId, { ignoreLoading: true }).subscribe({
next: async (blob: Blob) => {
const zipData = await blob.arrayBuffer();
const dialogRef = this.dialog.open(TbDeviceInstallDialogComponent, {
@ -275,7 +274,6 @@ export class TbIotHubItemDetailDialogComponent {
data: {
item: this.item,
zipData,
iotHubApiService: this.data.iotHubApiService
} as DeviceInstallDialogData
});
dialogRef.afterClosed().subscribe(result => {
@ -296,7 +294,6 @@ export class TbIotHubItemDetailDialogComponent {
itemType: this.item.type,
version: this.item.version,
versionId: this.item.id,
iotHubApiService: this.data.iotHubApiService
} as IotHubUpdateDialogData
});
dialogRef.afterClosed().subscribe(result => {
@ -366,7 +363,7 @@ export class TbIotHubItemDetailDialogComponent {
});
deleteDialogRef.afterClosed().subscribe(confirmed => {
if (confirmed) {
this.data.iotHubApiService.deleteInstalledItem(this.installedItem.id.id).subscribe(() => {
this.iotHubApiService.deleteInstalledItem(this.installedItem.id.id).subscribe(() => {
this.dialogRef.close('deleted');
});
}
@ -390,19 +387,19 @@ export class TbIotHubItemDetailDialogComponent {
? screenshotResources
: this.item.resources.filter(r => r.type === 'ICON');
this.carouselImages = allResources.map(r =>
this.data.iotHubApiService.resolveResourceUrl(`/api/resources/${r.id}`)
this.iotHubApiService.resolveResourceUrl(`/api/resources/${r.id}`)
);
}
private loadReadme(): void {
const versionId = this.item.id as string;
this.data.iotHubApiService.getVersionReadme(versionId, { ignoreLoading: true }).subscribe(
this.iotHubApiService.getVersionReadme(versionId, { ignoreLoading: true }).subscribe(
content => this.readmeContent = this.prefixResourceUrls(content || '')
);
}
private prefixResourceUrls(markdown: string): string {
const baseUrl = this.data.iotHubApiService.baseUrl;
const baseUrl = this.iotHubApiService.baseUrl;
return markdown.replace(/(\(|")(\/api\/resources\/[^)"]*)/g, `$1${baseUrl}$2`);
}
}

6
ui-ngx/src/app/modules/home/pages/iot-hub/device-install-dialog/device-install-dialog.component.ts

@ -42,7 +42,6 @@ import {
export interface DeviceInstallDialogData {
item: MpItemVersionView;
zipData: ArrayBuffer;
iotHubApiService: IotHubApiService;
}
export type WizardStepType = 'instruction' | 'form' | 'progress';
@ -102,7 +101,8 @@ export class TbDeviceInstallDialogComponent implements OnInit {
private deviceProfileService: DeviceProfileService,
private deviceService: DeviceService,
private dashboardService: DashboardService,
private ruleChainService: RuleChainService
private ruleChainService: RuleChainService,
private iotHubApiService: IotHubApiService
) {}
async ngOnInit(): Promise<void> {
@ -404,7 +404,7 @@ export class TbDeviceInstallDialogComponent implements OnInit {
const createdEntityIds = this.collectCreatedEntityIds();
const dashboardId = this.findCreatedDashboardId();
await firstValueFrom(
this.data.iotHubApiService.registerDeviceInstall(
this.iotHubApiService.registerDeviceInstall(
this.data.item.id as string,
{ createdEntityIds, dashboardId },
{ ignoreLoading: true }

5
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-home.component.ts

@ -319,7 +319,6 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
autoFocus: false,
data: {
item,
iotHubApiService: this.iotHubApiService,
installedItem
} as IotHubItemDetailDialogData
});
@ -368,7 +367,6 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
autoFocus: false,
data: {
item,
iotHubApiService: this.iotHubApiService
} as IotHubInstallDialogData
});
dialogRef.afterClosed().subscribe(result => {
@ -386,7 +384,7 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
disableClose: true,
autoFocus: false,
data: { item, zipData, iotHubApiService: this.iotHubApiService } as DeviceInstallDialogData
data: { item, zipData } as DeviceInstallDialogData
});
dialogRef.afterClosed().subscribe(result => {
if (result === 'installed') {
@ -411,7 +409,6 @@ export class TbIotHubHomeComponent implements OnInit, OnDestroy {
itemType: item.type,
version: item.version,
versionId: item.id,
iotHubApiService: this.iotHubApiService
} as IotHubUpdateDialogData
});
dialogRef.afterClosed().subscribe(result => {

6
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-install-dialog.component.ts

@ -32,7 +32,6 @@ import { SolutionInstallDialogComponent } from '@home/components/solution/soluti
export interface IotHubInstallDialogData {
item: MpItemVersionView;
iotHubApiService: IotHubApiService;
}
export type InstallState = 'select-entity' | 'confirm' | 'installing' | 'success' | 'error';
@ -68,7 +67,8 @@ export class TbIotHubInstallDialogComponent {
private dialogRef: MatDialogRef<TbIotHubInstallDialogComponent>,
private dialog: MatDialog,
private router: Router,
private translate: TranslateService
private translate: TranslateService,
private iotHubApiService: IotHubApiService
) {
this.item = data.item;
}
@ -90,7 +90,7 @@ export class TbIotHubInstallDialogComponent {
this.state = 'installing';
const versionId = this.item.id as string;
const data = this.selectedEntityId ? { entityId: this.selectedEntityId } : undefined;
this.data.iotHubApiService.installItemVersion(versionId, { ignoreLoading: true }, data).subscribe({
this.iotHubApiService.installItemVersion(versionId, { ignoreLoading: true }, data).subscribe({
next: (result) => {
if (result.success) {
if (result.descriptor?.type === 'SOLUTION_TEMPLATE') {

3
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-installed-items.component.ts

@ -214,7 +214,6 @@ export class TbIotHubInstalledItemsComponent implements OnInit, AfterViewInit {
autoFocus: false,
data: {
item: versionView,
iotHubApiService: this.iotHubApiService,
installedItem: item
} as IotHubItemDetailDialogData
});
@ -287,7 +286,6 @@ export class TbIotHubInstalledItemsComponent implements OnInit, AfterViewInit {
autoFocus: false,
data: {
item: versionView,
iotHubApiService: this.iotHubApiService,
installedItem
} as IotHubItemDetailDialogData
});
@ -308,7 +306,6 @@ export class TbIotHubInstalledItemsComponent implements OnInit, AfterViewInit {
itemType: item.itemType as ItemType,
version: publishedInfo.publishedVersion,
versionId: publishedInfo.publishedVersionId,
iotHubApiService: this.iotHubApiService
} as IotHubUpdateDialogData
});
dialogRef.afterClosed().subscribe(result => {

6
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-search.component.ts

@ -217,7 +217,6 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
autoFocus: false,
data: {
item,
iotHubApiService: this.iotHubApiService,
installedItem: this.getInstalledItem(item)
} as IotHubItemDetailDialogData
});
@ -236,7 +235,7 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
const dialogRef = this.dialog.open(TbIotHubInstallDialogComponent, {
panelClass: ['tb-dialog'],
autoFocus: false,
data: { item, iotHubApiService: this.iotHubApiService } as IotHubInstallDialogData
data: { item } as IotHubInstallDialogData
});
dialogRef.afterClosed().subscribe(result => {
if (result === 'installed') {
@ -253,7 +252,7 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
disableClose: true,
autoFocus: false,
data: { item, zipData, iotHubApiService: this.iotHubApiService } as DeviceInstallDialogData
data: { item, zipData } as DeviceInstallDialogData
});
dialogRef.afterClosed().subscribe(result => {
if (result === 'installed') {
@ -276,7 +275,6 @@ export class TbIotHubSearchComponent implements OnInit, OnDestroy {
itemType: item.type,
version: item.version,
versionId: item.id,
iotHubApiService: this.iotHubApiService
} as IotHubUpdateDialogData
});
dialogRef.afterClosed().subscribe(result => {

6
ui-ngx/src/app/modules/home/pages/iot-hub/iot-hub-update-dialog.component.ts

@ -35,7 +35,6 @@ export interface IotHubUpdateDialogData {
itemType: ItemType;
version: string;
versionId: string;
iotHubApiService: IotHubApiService;
}
export type UpdateState = 'confirm' | 'updating' | 'success' | 'error';
@ -67,7 +66,8 @@ export class TbIotHubUpdateDialogComponent {
private dialog: MatDialog,
private dialogService: DialogService,
private router: Router,
private translate: TranslateService
private translate: TranslateService,
private iotHubApiService: IotHubApiService
) {}
getTypeLabel(): string {
@ -77,7 +77,7 @@ export class TbIotHubUpdateDialogComponent {
update(force = false): void {
this.state = 'updating';
this.data.iotHubApiService.updateItemVersion(this.data.installedItemId, this.data.versionId, { ignoreLoading: true }, force).subscribe({
this.iotHubApiService.updateItemVersion(this.data.installedItemId, this.data.versionId, { ignoreLoading: true }, force).subscribe({
next: (result) => {
if (result.success) {
if (result.descriptor?.type === 'SOLUTION_TEMPLATE') {

Loading…
Cancel
Save