From f81c0373048079dcfe22543e3908fdf030760cac Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Fri, 31 Oct 2025 13:40:15 +0200 Subject: [PATCH] UI: Move getGitHubStar function to new service --- ui-ngx/src/app/core/http/admin.service.ts | 13 ++----- ui-ngx/src/app/core/http/git-hub.service.ts | 38 +++++++++++++++++++ .../github-badge/github-badge.component.ts | 6 +-- 3 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 ui-ngx/src/app/core/http/git-hub.service.ts diff --git a/ui-ngx/src/app/core/http/admin.service.ts b/ui-ngx/src/app/core/http/admin.service.ts index 02b8153836..36bb931f93 100644 --- a/ui-ngx/src/app/core/http/admin.service.ts +++ b/ui-ngx/src/app/core/http/admin.service.ts @@ -16,14 +16,14 @@ import { Injectable } from '@angular/core'; import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; -import { Observable, of } from 'rxjs'; +import { Observable } from 'rxjs'; import { HttpClient } from '@angular/common/http'; import { AdminSettings, AutoCommitSettings, - MailConfigTemplate, FeaturesInfo, JwtSettings, + MailConfigTemplate, MailServerSettings, RepositorySettings, RepositorySettingsInfo, @@ -32,7 +32,7 @@ import { UpdateMessage } from '@shared/models/settings.models'; import { EntitiesVersionControlService } from '@core/http/entities-version-control.service'; -import { catchError, map, tap } from 'rxjs/operators'; +import { tap } from 'rxjs/operators'; import { LoginResponse } from '@shared/models/login.models'; @Injectable({ @@ -149,11 +149,4 @@ export class AdminService { public getMailConfigTemplate(config?: RequestConfig): Observable> { return this.http.get>('/api/mail/config/template', defaultHttpOptionsFromConfig(config)); } - - public getGitHubStar(config?: RequestConfig): Observable { - return this.http.get('https://api.github.com/repos/thingsboard/thingsboard', defaultHttpOptionsFromConfig(config)).pipe( - catchError(() => of({})), - map((res: any) => res?.stargazers_count ?? 0) - ) - } } diff --git a/ui-ngx/src/app/core/http/git-hub.service.ts b/ui-ngx/src/app/core/http/git-hub.service.ts new file mode 100644 index 0000000000..b6a927dab3 --- /dev/null +++ b/ui-ngx/src/app/core/http/git-hub.service.ts @@ -0,0 +1,38 @@ +/// +/// Copyright © 2016-2025 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import { Injectable } from '@angular/core'; +import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; +import { Observable, of } from 'rxjs'; +import { HttpClient } from '@angular/common/http'; +import { catchError, map } from 'rxjs/operators'; + +@Injectable({ + providedIn: 'root' +}) +export class GitHubService { + + constructor( + private http: HttpClient + ) { } + + public getGitHubStar(config?: RequestConfig): Observable { + return this.http.get('https://api.github.com/repos/thingsboard/thingsboard', defaultHttpOptionsFromConfig(config)).pipe( + catchError(() => of({})), + map((res: any) => res?.stargazers_count ?? 0) + ) + } +} diff --git a/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.ts b/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.ts index 8d1cedeb5a..da46d492c0 100644 --- a/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.ts +++ b/ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.ts @@ -15,7 +15,7 @@ /// import { Component } from '@angular/core'; -import { AdminService } from '@core/http/admin.service'; +import { GitHubService } from '@core/http/git-hub.service'; @Component({ selector: 'tb-github-badge', @@ -26,8 +26,8 @@ export class GithubBadgeComponent { githubStar = 0; - constructor(private adminService: AdminService) { - this.adminService.getGitHubStar().subscribe(star => { + constructor(private gitHubService: GitHubService) { + this.gitHubService.getGitHubStar().subscribe(star => { this.githubStar = star; }); }