 75608dce5c
			
		
	
	75608dce5c
	
	
	
		
			
			Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> # Conflicts: # web/src/interfaces/locale.ts
		
			
				
	
	
		
			66 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { ChartData } from "chart.js";
 | |
| 
 | |
| import { t } from "@lingui/macro";
 | |
| 
 | |
| import { customElement, property } from "lit/decorators";
 | |
| 
 | |
| import { CoreApi, UserMetrics } from "@goauthentik/api";
 | |
| 
 | |
| import { DEFAULT_CONFIG } from "../../api/Config";
 | |
| import { AKChart } from "./Chart";
 | |
| 
 | |
| @customElement("ak-charts-user")
 | |
| export class UserChart extends AKChart<UserMetrics> {
 | |
|     @property({ type: Number })
 | |
|     userId?: number;
 | |
| 
 | |
|     apiRequest(): Promise<UserMetrics> {
 | |
|         return new CoreApi(DEFAULT_CONFIG).coreUsersMetricsRetrieve({
 | |
|             id: this.userId || 0,
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     getChartData(data: UserMetrics): ChartData {
 | |
|         return {
 | |
|             datasets: [
 | |
|                 {
 | |
|                     label: t`Failed Logins`,
 | |
|                     backgroundColor: "rgba(201, 25, 11, .5)",
 | |
|                     spanGaps: true,
 | |
|                     data:
 | |
|                         data.loginsFailedPer1h?.map((cord) => {
 | |
|                             return {
 | |
|                                 x: cord.xCord || 0,
 | |
|                                 y: cord.yCord || 0,
 | |
|                             };
 | |
|                         }) || [],
 | |
|                 },
 | |
|                 {
 | |
|                     label: t`Successful Logins`,
 | |
|                     backgroundColor: "rgba(189, 229, 184, .5)",
 | |
|                     spanGaps: true,
 | |
|                     data:
 | |
|                         data.loginsPer1h?.map((cord) => {
 | |
|                             return {
 | |
|                                 x: cord.xCord || 0,
 | |
|                                 y: cord.yCord || 0,
 | |
|                             };
 | |
|                         }) || [],
 | |
|                 },
 | |
|                 {
 | |
|                     label: t`Application authorizations`,
 | |
|                     backgroundColor: "rgba(43, 154, 243, .5)",
 | |
|                     spanGaps: true,
 | |
|                     data:
 | |
|                         data.authorizationsPer1h?.map((cord) => {
 | |
|                             return {
 | |
|                                 x: cord.xCord || 0,
 | |
|                                 y: cord.yCord || 0,
 | |
|                             };
 | |
|                         }) || [],
 | |
|                 },
 | |
|             ],
 | |
|         };
 | |
|     }
 | |
| }
 |