-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHIBUI-812 Integrated attribute release into backend
- Loading branch information
Showing
6 changed files
with
84 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
ui/src/app/metadata/domain/model/properties/release-attribute.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface ReleaseAttribute { | ||
key: string; | ||
label: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable, throwError } from 'rxjs'; | ||
import { catchError, shareReplay, map } from 'rxjs/operators'; | ||
import { ReleaseAttribute } from '../model/properties/release-attribute'; | ||
|
||
const CACHE_SIZE = 1; | ||
|
||
@Injectable() | ||
export class AttributesService { | ||
|
||
readonly endpoint = '/customAttributes'; | ||
readonly base = '/api'; | ||
|
||
private cache$: Observable<ReleaseAttribute[]>; | ||
|
||
constructor( | ||
private http: HttpClient | ||
) { } | ||
|
||
query(path: string = this.endpoint): Observable<ReleaseAttribute[]> { | ||
if (!this.cache$) { | ||
this.cache$ = this.requestAttributes(path).pipe( | ||
shareReplay(CACHE_SIZE) | ||
); | ||
} | ||
|
||
return this.cache$; | ||
} | ||
|
||
requestAttributes(path: string): Observable<ReleaseAttribute[]> { | ||
return this.http.get<ReleaseAttribute[]>(`${this.base}${path}`, {}) | ||
.pipe( | ||
map(attrs => attrs.map((attr: any) => ({ key: attr.name, label: attr.displayName }))), | ||
catchError(err => throwError([])) | ||
); | ||
} | ||
} |