-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add suspicious instances detail (#22)
- Loading branch information
1 parent
a8e963a
commit c389642
Showing
11 changed files
with
188 additions
and
14 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
63 changes: 63 additions & 0 deletions
63
src/app/instances/pages/suspicious-instance-detail/suspicious-instance-detail.component.html
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,63 @@ | ||
<app-loader *ngIf="loading else content"></app-loader> | ||
|
||
<ng-template #content> | ||
<div class="col-md-12"> | ||
<div class="card" *ngIf="detail"> | ||
<div class="card-header"> | ||
<h3 class="card-title" id="instance-details">Instance details</h3> | ||
</div> | ||
<div class="card-body"> | ||
<table class="table table-bordered"> | ||
<tbody> | ||
<tr> | ||
<th>Field</th> | ||
<th>Value</th> | ||
</tr> | ||
<tr> | ||
<td>Domain</td> | ||
<td>{{detail.domain}}</td> | ||
</tr> | ||
<tr> | ||
<td>Uptime</td> | ||
<td>{{(detail.uptime_alltime / 100) | formatPercentage:2}}</td> | ||
</tr> | ||
<tr> | ||
<td>Local posts</td> | ||
<td>{{detail.local_posts | formatNumber}}</td> | ||
</tr> | ||
<tr> | ||
<td>Comments count</td> | ||
<td>{{detail.comment_counts | formatNumber}}</td> | ||
</tr> | ||
<tr> | ||
<td>Total users</td> | ||
<td>{{detail.total_users | formatNumber}}</td> | ||
</tr> | ||
<tr> | ||
<td>Monthly active users</td> | ||
<td>{{detail.active_users_monthly | formatNumber}}</td> | ||
</tr> | ||
<tr> | ||
<td>Registrations open</td> | ||
<td><app-yes-no [swapColors]="true" [yes]="detail.signup"></app-yes-no></td> | ||
</tr> | ||
<tr> | ||
<td>Local users per comments & posts</td> | ||
<td> | ||
{{detail.activity_suspicion | formatNumber:2}} | ||
<app-tooltip text="Higher is worse" /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Local users per monthly active users</td> | ||
<td> | ||
{{detail.active_users_suspicion | formatNumber:2}} | ||
<app-tooltip text="Higher is worse" /> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</ng-template> |
3 changes: 3 additions & 0 deletions
3
src/app/instances/pages/suspicious-instance-detail/suspicious-instance-detail.component.scss
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,3 @@ | ||
:host { | ||
min-width: 100%; | ||
} |
57 changes: 57 additions & 0 deletions
57
src/app/instances/pages/suspicious-instance-detail/suspicious-instance-detail.component.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,57 @@ | ||
import {Component, OnInit} from '@angular/core'; | ||
import {TitleService} from "../../../services/title.service"; | ||
import {FediseerApiService} from "../../../services/fediseer-api.service"; | ||
import {AuthenticationManagerService} from "../../../services/authentication-manager.service"; | ||
import {ActivatedRoute, Router} from "@angular/router"; | ||
import {ApiResponseHelperService} from "../../../services/api-response-helper.service"; | ||
import {toPromise} from "../../../types/resolvable"; | ||
import {MessageService} from "../../../services/message.service"; | ||
import {SuspiciousInstanceDetailResponse} from "../../../response/suspicious-instance-detail.response"; | ||
|
||
@Component({ | ||
selector: 'app-suspicious-instance-detail', | ||
templateUrl: './suspicious-instance-detail.component.html', | ||
styleUrls: ['./suspicious-instance-detail.component.scss'] | ||
}) | ||
export class SuspiciousInstanceDetailComponent implements OnInit { | ||
public loading: boolean = true; | ||
public detail: SuspiciousInstanceDetailResponse | null = null; | ||
|
||
constructor( | ||
private readonly titleService: TitleService, | ||
private readonly api: FediseerApiService, | ||
private readonly authManager: AuthenticationManagerService, | ||
private readonly activatedRoute: ActivatedRoute, | ||
private readonly router: Router, | ||
private readonly apiResponseHelper: ApiResponseHelperService, | ||
private readonly messageService: MessageService, | ||
) { | ||
} | ||
|
||
public async ngOnInit(): Promise<void> { | ||
this.activatedRoute.params.subscribe(async params => { | ||
this.loading = true; | ||
|
||
const instanceDomain = <string>params['instance']; | ||
this.titleService.title = `${instanceDomain} | Instance detail`; | ||
|
||
const instanceList = await toPromise(this.api.getSuspiciousInstances()); | ||
if (this.apiResponseHelper.handleErrors([instanceList])) { | ||
this.loading = false; | ||
return; | ||
} | ||
|
||
const instance = instanceList.successResponse!.instances.filter( | ||
instance => instance.domain === instanceDomain, | ||
)[0] ?? null; | ||
|
||
if (instance === null) { | ||
this.messageService.createError('This instance is not on the list of suspicious instances.'); | ||
this.loading = false; | ||
return; | ||
} | ||
this.detail = instance; | ||
this.loading = false; | ||
}); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
<span class="text-success" *ngIf="yes">Yes</span> | ||
<span class="text-danger" *ngIf="!yes">No</span> | ||
<span | ||
[class.text-success]="!swapColors" | ||
[class.text-danger]="swapColors" | ||
*ngIf="yes" | ||
>Yes</span> | ||
<span | ||
[class.text-success]="swapColors" | ||
[class.text-danger]="!swapColors" | ||
*ngIf="!yes" | ||
>No</span> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
@Pipe({ | ||
name: 'formatNumber' | ||
}) | ||
export class FormatNumberPipe implements PipeTransform { | ||
|
||
transform(value: string | number, digits: number | null = null): string { | ||
return new Intl.NumberFormat(undefined, { | ||
minimumFractionDigits: digits ?? undefined, | ||
maximumFractionDigits: digits ?? undefined, | ||
}).format(Number(value)); | ||
} | ||
|
||
} |
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,15 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
@Pipe({ | ||
name: 'formatPercentage' | ||
}) | ||
export class FormatPercentagePipe implements PipeTransform { | ||
|
||
transform(value: string | number, digits: number | null = null): string { | ||
return new Intl.NumberFormat(undefined, { | ||
minimumFractionDigits: digits ?? undefined, | ||
maximumFractionDigits: digits ?? undefined, | ||
style: 'percent', | ||
}).format(Number(value)); | ||
} | ||
} |
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