diff --git a/web/projects/ui/src/app/routes/portal/components/interfaces/gateways.component.ts b/web/projects/ui/src/app/routes/portal/components/interfaces/gateways.component.ts index 00b4631c1..033c0991f 100644 --- a/web/projects/ui/src/app/routes/portal/components/interfaces/gateways.component.ts +++ b/web/projects/ui/src/app/routes/portal/components/interfaces/gateways.component.ts @@ -1,11 +1,18 @@ import { CommonModule } from '@angular/common' -import { ChangeDetectionStrategy, Component, input } from '@angular/core' +import { + ChangeDetectionStrategy, + Component, + input, + inject, +} from '@angular/core' import { TuiTitle } from '@taiga-ui/core' import { TuiSkeleton, TuiSwitch } from '@taiga-ui/kit' import { FormsModule } from '@angular/forms' -import { i18nPipe } from '@start9labs/shared' +import { i18nPipe, LoadingService, ErrorService } from '@start9labs/shared' import { TuiCell } from '@taiga-ui/layout' import { InterfaceGateway } from './interface.service' +import { ApiService } from 'src/app/services/api/embassy-api.service' +import { InterfaceComponent } from './interface.component' @Component({ selector: 'section[gateways]', @@ -21,7 +28,7 @@ import { InterfaceGateway } from './interface.service' [showIcons]="false" [ngModel]="gateway.enabled" (ngModelChange)="onToggle(gateway)" - [disabled]="isOs() && !gateway.public" + [disabled]="!interface.packageId() && !gateway.public" /> } @empty { @@ -54,8 +61,39 @@ import { InterfaceGateway } from './interface.service' ], }) export class InterfaceGatewaysComponent { - readonly gateways = input.required() - readonly isOs = input.required() + private readonly loader = inject(LoadingService) + private readonly errorService = inject(ErrorService) + private readonly api = inject(ApiService) + readonly interface = inject(InterfaceComponent) - async onToggle(gateway: InterfaceGateway) {} + readonly gateways = input.required() + + async onToggle(gateway: InterfaceGateway) { + const addressInfo = this.interface.value()!.addressInfo + const pkgId = this.interface.packageId() + + const loader = this.loader.open().subscribe() + + try { + if (pkgId) { + await this.api.pkgBindingToggleGateway({ + gateway: gateway.id, + enabled: !gateway.enabled, + internalPort: addressInfo.internalPort, + host: addressInfo.hostId, + package: pkgId, + }) + } else { + await this.api.serverBindingToggleGateway({ + gateway: gateway.id, + enabled: !gateway.enabled, + internalPort: 80, + }) + } + } catch (e: any) { + this.errorService.handleError(e) + } finally { + loader.unsubscribe() + } + } } diff --git a/web/projects/ui/src/app/routes/portal/components/interfaces/interface.component.ts b/web/projects/ui/src/app/routes/portal/components/interfaces/interface.component.ts index afabe51c4..15ddc9452 100644 --- a/web/projects/ui/src/app/routes/portal/components/interfaces/interface.component.ts +++ b/web/projects/ui/src/app/routes/portal/components/interfaces/interface.component.ts @@ -11,10 +11,7 @@ import { InterfaceAddressesComponent } from './addresses/addresses.component' selector: 'service-interface', template: `
-
+
diff --git a/web/projects/ui/src/app/routes/portal/components/interfaces/interface.service.ts b/web/projects/ui/src/app/routes/portal/components/interfaces/interface.service.ts index 507b15dd9..d544b9f4d 100644 --- a/web/projects/ui/src/app/routes/portal/components/interfaces/interface.service.ts +++ b/web/projects/ui/src/app/routes/portal/components/interfaces/interface.service.ts @@ -488,7 +488,6 @@ export type MappedServiceInterface = T.ServiceInterface & { common: DisplayAddress[] uncommon: DisplayAddress[] } - isOs: boolean } export type InterfaceGateway = GatewayPlus & { diff --git a/web/projects/ui/src/app/routes/portal/routes/services/routes/interface.component.ts b/web/projects/ui/src/app/routes/portal/routes/services/routes/interface.component.ts index d61885e73..d2c28b7ec 100644 --- a/web/projects/ui/src/app/routes/portal/routes/services/routes/interface.component.ts +++ b/web/projects/ui/src/app/routes/portal/routes/services/routes/interface.component.ts @@ -135,7 +135,6 @@ export default class ServiceInterfaceRoute { torDomains: host.onions.map(o => `${o}.onion`), publicDomains: getPublicDomains(host.publicDomains, gateways), privateDomains: host.privateDomains, - isOs: false, } }) diff --git a/web/projects/ui/src/app/routes/portal/routes/system/routes/gateways/gateways.component.ts b/web/projects/ui/src/app/routes/portal/routes/system/routes/gateways/gateways.component.ts index 3d94acee4..01d69284e 100644 --- a/web/projects/ui/src/app/routes/portal/routes/system/routes/gateways/gateways.component.ts +++ b/web/projects/ui/src/app/routes/portal/routes/system/routes/gateways/gateways.component.ts @@ -131,6 +131,13 @@ export default class GatewaysComponent { handler: async (input: typeof spec._TYPE) => { const loader = this.loader.open('Saving').subscribe() + console.log('FILE', input.config.value.file) + + console.log( + 'FILE STRINGIFIED', + JSON.stringify(input.config.value.file), + ) + try { await this.api.addTunnel({ name: input.name, diff --git a/web/projects/ui/src/app/routes/portal/routes/system/routes/startos-ui/startos-ui.component.ts b/web/projects/ui/src/app/routes/portal/routes/system/routes/startos-ui/startos-ui.component.ts index cc7a6ac4e..63956c813 100644 --- a/web/projects/ui/src/app/routes/portal/routes/system/routes/startos-ui/startos-ui.component.ts +++ b/web/projects/ui/src/app/routes/portal/routes/system/routes/startos-ui/startos-ui.component.ts @@ -98,7 +98,6 @@ export default class StartOsUiComponent { torDomains: network.host.onions.map(o => `${o}.onion`), publicDomains: getPublicDomains(network.host.publicDomains, gateways), privateDomains: network.host.privateDomains, - isOs: true, } }) } diff --git a/web/projects/ui/src/app/services/api/api.types.ts b/web/projects/ui/src/app/services/api/api.types.ts index 34dc6082b..7a670ebf7 100644 --- a/web/projects/ui/src/app/services/api/api.types.ts +++ b/web/projects/ui/src/app/services/api/api.types.ts @@ -325,7 +325,10 @@ export namespace RR { } export type OsUiRemovePrivateDomainRes = null - export type PkgBindingToggleGatewayReq = ServerBindingToggleGatewayReq & { + export type PkgBindingToggleGatewayReq = Omit< + ServerBindingToggleGatewayReq, + 'internalPort' + > & { // package.host.binding.set-gateway-enabled internalPort: number package: T.PackageId // string