Browse Source

UI: Move getGitHubStar function to new service

pull/14254/head
Vladyslav_Prykhodko 11 months ago
parent
commit
f81c037304
  1. 13
      ui-ngx/src/app/core/http/admin.service.ts
  2. 38
      ui-ngx/src/app/core/http/git-hub.service.ts
  3. 6
      ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.ts

13
ui-ngx/src/app/core/http/admin.service.ts

@ -16,14 +16,14 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils';
import { Observable, of } from 'rxjs'; import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { import {
AdminSettings, AdminSettings,
AutoCommitSettings, AutoCommitSettings,
MailConfigTemplate,
FeaturesInfo, FeaturesInfo,
JwtSettings, JwtSettings,
MailConfigTemplate,
MailServerSettings, MailServerSettings,
RepositorySettings, RepositorySettings,
RepositorySettingsInfo, RepositorySettingsInfo,
@ -32,7 +32,7 @@ import {
UpdateMessage UpdateMessage
} from '@shared/models/settings.models'; } from '@shared/models/settings.models';
import { EntitiesVersionControlService } from '@core/http/entities-version-control.service'; 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'; import { LoginResponse } from '@shared/models/login.models';
@Injectable({ @Injectable({
@ -149,11 +149,4 @@ export class AdminService {
public getMailConfigTemplate(config?: RequestConfig): Observable<Array<MailConfigTemplate>> { public getMailConfigTemplate(config?: RequestConfig): Observable<Array<MailConfigTemplate>> {
return this.http.get<Array<MailConfigTemplate>>('/api/mail/config/template', defaultHttpOptionsFromConfig(config)); return this.http.get<Array<MailConfigTemplate>>('/api/mail/config/template', defaultHttpOptionsFromConfig(config));
} }
public getGitHubStar(config?: RequestConfig): Observable<number> {
return this.http.get<any>('https://api.github.com/repos/thingsboard/thingsboard', defaultHttpOptionsFromConfig(config)).pipe(
catchError(() => of({})),
map((res: any) => res?.stargazers_count ?? 0)
)
}
} }

38
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<number> {
return this.http.get<any>('https://api.github.com/repos/thingsboard/thingsboard', defaultHttpOptionsFromConfig(config)).pipe(
catchError(() => of({})),
map((res: any) => res?.stargazers_count ?? 0)
)
}
}

6
ui-ngx/src/app/modules/home/components/github-badge/github-badge.component.ts

@ -15,7 +15,7 @@
/// ///
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { AdminService } from '@core/http/admin.service'; import { GitHubService } from '@core/http/git-hub.service';
@Component({ @Component({
selector: 'tb-github-badge', selector: 'tb-github-badge',
@ -26,8 +26,8 @@ export class GithubBadgeComponent {
githubStar = 0; githubStar = 0;
constructor(private adminService: AdminService) { constructor(private gitHubService: GitHubService) {
this.adminService.getGitHubStar().subscribe(star => { this.gitHubService.getGitHubStar().subscribe(star => {
this.githubStar = star; this.githubStar = star;
}); });
} }

Loading…
Cancel
Save