Skip to content

Commit

Permalink
Parse feature service after validation
Browse files Browse the repository at this point in the history
  • Loading branch information
newmanw committed Oct 8, 2024
1 parent adf867a commit ef150cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion plugins/arcgis/service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const arcgisPluginHooks: InitPluginHook<typeof InjectedServices> = {
<html>
<head>
<script>
window.opener.postMessage('authenticated', '${req.protocol}://${req.headers.host}');
window.opener.postMessage(${JSON.stringify(service)}, '${req.protocol}://${req.headers.host}');
</script>
</head>
</html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,31 @@ export class ArcLayerDialogComponent {
case AuthType.Token: {
const { token } = this.layerForm.controls.token.value
this.featureService = { url, auth: { type: AuthType.Token, token }, layers: [] }
this.arcService.validateFeatureService(this.featureService).subscribe(() => this.validated(url))
this.arcService.validateFeatureService(this.featureService).subscribe((service) => this.validated(service))

break;
}
case AuthType.OAuth: {
const { clientId } = this.layerForm.controls.oauth.value
this.featureService = { url, auth: { type: AuthType.OAuth, clientId }, layers: [] }
this.arcService.oauth(url, clientId).subscribe(() => this.validated(url))
this.arcService.oauth(url, clientId).subscribe((service) => this.validated(service))

break;
}
case AuthType.UsernamePassword: {
const { username, password } = this.layerForm.controls.local.value
this.featureService = { url, auth: { type: AuthType.UsernamePassword, username, password }, layers: [] }
this.arcService.validateFeatureService(this.featureService).subscribe(() => this.validated(url))
this.arcService.validateFeatureService(this.featureService).subscribe((service) => this.validated(service))

break;
}
}
}

validated(url: string): void {
this.fetchLayers(url)
validated(service: FeatureServiceConfig): void {
this.state = State.Layers
this.featureService = service
this.fetchLayers(service.url)
}

onSave(): void {
Expand Down
10 changes: 4 additions & 6 deletions plugins/arcgis/web-app/projects/main/src/lib/arc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ export class ArcService implements ArcServiceInterface {
return this.http.get<FeatureLayer[]>(`${baseUrl}/featureService/layers?featureServiceUrl=${encodeURIComponent(featureServiceUrl)}`)
}

oauth(featureServiceUrl: string, clientId: string): Observable<any> {
let subject = new Subject<any>();
oauth(featureServiceUrl: string, clientId: string): Observable<FeatureServiceConfig> {
let subject = new Subject<FeatureServiceConfig>();

const url = `${baseUrl}/oauth/signin?featureServiceUrl=${encodeURIComponent(featureServiceUrl)}&clientId=${encodeURIComponent(clientId)}`;
const oauthWindow = window.open(url, "_blank");

const listener = (event: any) => {
console.log('got window message', event)

window.removeEventListener('message', listener, false);

if (event.origin !== window.location.origin) {
Expand All @@ -79,8 +77,8 @@ export class ArcService implements ArcServiceInterface {
return subject.asObservable()
}

validateFeatureService(service: FeatureServiceConfig): Observable<any> {
return this.http.post(`${baseUrl}/featureService/validate`, service)
validateFeatureService(service: FeatureServiceConfig): Observable<FeatureServiceConfig> {
return this.http.post<FeatureServiceConfig>(`${baseUrl}/featureService/validate`, service)
}

fetchEvents(): Observable<MageEvent[]> {
Expand Down

0 comments on commit ef150cd

Please sign in to comment.