|
|
|
@ -12,8 +12,9 @@ import { |
|
|
|
AppClientDto, |
|
|
|
AppClientsDto, |
|
|
|
AppClientsService, |
|
|
|
AppContext, |
|
|
|
AppsState, |
|
|
|
CreateAppClientDto, |
|
|
|
DialogService, |
|
|
|
UpdateAppClientDto, |
|
|
|
ValidatorsEx |
|
|
|
} from '@app/shared'; |
|
|
|
@ -21,10 +22,7 @@ import { |
|
|
|
@Component({ |
|
|
|
selector: 'sqx-clients-page', |
|
|
|
styleUrls: ['./clients-page.component.scss'], |
|
|
|
templateUrl: './clients-page.component.html', |
|
|
|
providers: [ |
|
|
|
AppContext |
|
|
|
] |
|
|
|
templateUrl: './clients-page.component.html' |
|
|
|
}) |
|
|
|
export class ClientsPageComponent implements OnInit { |
|
|
|
public appClients: AppClientsDto; |
|
|
|
@ -36,15 +34,18 @@ export class ClientsPageComponent implements OnInit { |
|
|
|
[ |
|
|
|
Validators.maxLength(40), |
|
|
|
ValidatorsEx.pattern('[a-z0-9]+(\-[a-z0-9]+)*', 'Name can contain lower case letters (a-z), numbers and dashes (not at the end).') |
|
|
|
]] |
|
|
|
] |
|
|
|
] |
|
|
|
}); |
|
|
|
|
|
|
|
public get hasName() { |
|
|
|
return this.addClientForm.controls['name'].value && this.addClientForm.controls['name'].value.length > 0; |
|
|
|
} |
|
|
|
|
|
|
|
constructor(public readonly ctx: AppContext, |
|
|
|
constructor( |
|
|
|
public readonly appsState: AppsState, |
|
|
|
private readonly appClientsService: AppClientsService, |
|
|
|
private readonly dialogs: DialogService, |
|
|
|
private readonly formBuilder: FormBuilder |
|
|
|
) { |
|
|
|
} |
|
|
|
@ -54,42 +55,42 @@ export class ClientsPageComponent implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
public load() { |
|
|
|
this.appClientsService.getClients(this.ctx.appName) |
|
|
|
this.appClientsService.getClients(this.appsState.appName) |
|
|
|
.subscribe(dtos => { |
|
|
|
this.updateClients(dtos); |
|
|
|
}, error => { |
|
|
|
this.ctx.notifyError(error); |
|
|
|
this.dialogs.notifyError(error); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public revokeClient(client: AppClientDto) { |
|
|
|
this.appClientsService.deleteClient(this.ctx.appName, client.id, this.appClients.version) |
|
|
|
this.appClientsService.deleteClient(this.appsState.appName, client.id, this.appClients.version) |
|
|
|
.subscribe(dto => { |
|
|
|
this.updateClients(this.appClients.removeClient(client, dto.version)); |
|
|
|
}, error => { |
|
|
|
this.ctx.notifyError(error); |
|
|
|
this.dialogs.notifyError(error); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public renameClient(client: AppClientDto, name: string) { |
|
|
|
const requestDto = new UpdateAppClientDto(name); |
|
|
|
|
|
|
|
this.appClientsService.updateClient(this.ctx.appName, client.id, requestDto, this.appClients.version) |
|
|
|
this.appClientsService.updateClient(this.appsState.appName, client.id, requestDto, this.appClients.version) |
|
|
|
.subscribe(dto => { |
|
|
|
this.updateClients(this.appClients.updateClient(client.rename(name), dto.version)); |
|
|
|
}, error => { |
|
|
|
this.ctx.notifyError(error); |
|
|
|
this.dialogs.notifyError(error); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public updateClient(client: AppClientDto, permission: string) { |
|
|
|
const requestDto = new UpdateAppClientDto(undefined, permission); |
|
|
|
|
|
|
|
this.appClientsService.updateClient(this.ctx.appName, client.id, requestDto, this.appClients.version) |
|
|
|
this.appClientsService.updateClient(this.appsState.appName, client.id, requestDto, this.appClients.version) |
|
|
|
.subscribe(dto => { |
|
|
|
this.updateClients(this.appClients.updateClient(client.update(permission), dto.version)); |
|
|
|
}, error => { |
|
|
|
this.ctx.notifyError(error); |
|
|
|
this.dialogs.notifyError(error); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@ -101,12 +102,12 @@ export class ClientsPageComponent implements OnInit { |
|
|
|
|
|
|
|
const requestDto = new CreateAppClientDto(this.addClientForm.controls['name'].value); |
|
|
|
|
|
|
|
this.appClientsService.postClient(this.ctx.appName, requestDto, this.appClients.version) |
|
|
|
this.appClientsService.postClient(this.appsState.appName, requestDto, this.appClients.version) |
|
|
|
.subscribe(dto => { |
|
|
|
this.updateClients(this.appClients.addClient(dto.payload, dto.version)); |
|
|
|
this.resetClientForm(); |
|
|
|
}, error => { |
|
|
|
this.ctx.notifyError(error); |
|
|
|
this.dialogs.notifyError(error); |
|
|
|
|
|
|
|
this.resetClientForm(); |
|
|
|
}); |
|
|
|
|