Skip to content

Commit

Permalink
Add Status service and component to dashboard; adjust database connec…
Browse files Browse the repository at this point in the history
…tion pool settings
  • Loading branch information
austenstone committed Dec 3, 2024
1 parent 15d4f60 commit 2726233
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 14 deletions.
11 changes: 11 additions & 0 deletions backend/src/controllers/setup.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Request, Response } from 'express';
import app from '../index.js';
import StatusService from '../services/status.service.js';

class SetupController {
async registrationComplete(req: Request, res: Response) {
Expand Down Expand Up @@ -77,6 +78,16 @@ class SetupController {
}
}

async getStatus(req: Request, res: Response) {
try {
const statusService = new StatusService();
const status = await statusService.getStatus();
return res.json(status);
} catch (error) {
res.status(500).json(error);
}
}

async getInstall(req: Request, res: Response) {
try {
const { installation } = await app.github.getInstallation(req.body.id || req.body.owner)
Expand Down
7 changes: 6 additions & 1 deletion backend/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ class Database {
sequelize = typeof this.input === 'string' ?
new Sequelize(this.input, {
pool: {
max: 10,
max: 5,
acquire: 30000,
idle: 10000
},
...this.options
}) :
new Sequelize({
pool: {
max: 10,
acquire: 30000,
idle: 10000
},
...this.input,
...this.options
});
Expand Down
12 changes: 11 additions & 1 deletion backend/src/services/copilot.seats.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Endpoints } from '@octokit/types';
import { Seat } from "../models/copilot.seats.model.js";
import { Sequelize } from 'sequelize';
import { QueryTypes, Sequelize } from 'sequelize';
import { components } from "@octokit/openapi-types";
import { Member, Team } from '../models/teams.model.js';
import app from '../index.js';
Expand Down Expand Up @@ -231,6 +231,16 @@ class SeatsService {
}

async getMembersActivityTotals(org?: string) {
const assignees2 = await app.database.sequelize?.query(`
SELECT \`Member\`.\`login\`, \`Member\`.\`id\`, \`activity\`.\`id\` AS \`activity.id\`, \`activity\`.\`last_activity_at\` AS \`activity.last_activity_at\`
FROM \`Members\` AS \`Member\`
INNER JOIN \`Seats\` AS \`activity\` ON \`Member\`.\`id\` = \`activity\`.\`assignee_id\`
`, {
replacements: { org },
type: QueryTypes.SELECT
});
console.log(assignees2);

const assignees = await Member.findAll({
attributes: ['login', 'id'],
include: [{
Expand Down
65 changes: 65 additions & 0 deletions backend/src/services/status.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Seat } from "../models/copilot.seats.model.js";
import { Survey } from "../models/survey.model.js";
import { Member } from "../models/teams.model.js";

export interface StatusType {
github?: {
isGood: boolean
};
pollingHistory?: {
isGood: boolean;
message: string;
value?: any;
progress?: string;
};
repos?: {
value: number;
};
surveys?: StatusType;
}

class StatusService {
constructor() {

}

async getStatus(): Promise<StatusType> {
const status = {} as StatusType;

const assignee = await Member.findOne();
if (assignee) {
const seats = await Seat.findAll({
include: [{
model: Member,
as: 'assignee'
}],
where: {
assignee_id: assignee.id
},
order: [['createdAt', 'DESC']],
});
const oldestSeat = seats.find(seat => seat.createdAt);
const daysSince = oldestSeat ? Math.floor((new Date().getTime() - oldestSeat.createdAt.getTime()) / (1000 * 3600 * 24)) : undefined;
status.pollingHistory = {
isGood: true,
message: `${oldestSeat?.createdAt}`,
value: daysSince
}
}

const surveys = await Survey.findAll({
order: [['updatedAt', 'DESC']]
});

if (surveys) {
// status.surveys = {
// message: `${surveys.length} surveys created`,
// value: surveys.length
// }
}

return status;
}
}

export default StatusService;
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ <h1>Dashboard</h1>
</div> -->
<div class="cards-grid">

<!-- <app-dashboard-card-value routerLink="/copilot/seats" title="Seats" [value]="totalSeats" [change]="seatPercentage"
<app-dashboard-card-value routerLink="/copilot/seats" title="Seats" [value]="totalSeats" [change]="seatPercentage"
changeSuffix="" icon="" changeDescription="% have Copilot"
subtitle="Total Copilot Seats"></app-dashboard-card-value>
<app-dashboard-card-value title="Active Users" [value]="activeCurrentWeekAverage"
[change]="activeWeeklyChangePercent" changeSuffix="" changeDescription="% since last"
subtitle="Average activity for last 7 days"></app-dashboard-card-value>
<app-dashboard-card-value routerLink="/copilot/surveys" title="Surveys Complete" icon="" [value]="totalSurveys"
[change]="totalSurveysThisWeek" changeSuffix="" changeDescription=" this week"></app-dashboard-card-value> -->
[change]="totalSurveysThisWeek" changeSuffix="" changeDescription=" this week"></app-dashboard-card-value>

<mat-card id="adoption" appearance="outlined" routerLink="/copilot/value" fragment="adoption">
<mat-card-header>
Expand All @@ -39,11 +39,11 @@ <h1>Dashboard</h1>
</ng-container>
</mat-card>

<mat-card>
<app-status></app-status>
</mat-card>
<!-- <mat-card id="status" appearance="outlined">
<app-status [status]="statusChecks"></app-status>
</mat-card> -->

<!-- <mat-card appearance="outlined" id="card-bars">
<mat-card appearance="outlined" id="card-bars">
<mat-card-header>
<mat-card-title>Engagement</mat-card-title>
</mat-card-header>
Expand All @@ -69,7 +69,7 @@ <h1>Dashboard</h1>
<ng-container *ngIf="activityTotals; else loading">
<app-active-users-chart [data]="activityTotals" [chartOptions]="chartOptions"></app-active-users-chart>
</ng-container>
</mat-card> -->
</mat-card>
</div>
</div>
<ng-template #loading>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
width: 100%;
overflow: hidden;
}

#status {
grid-column: span 3;
}
}

/* Add media query for smaller screens */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,25 @@ export class CopilotDashboardComponent implements OnInit {
}

activityTotals?: Record<string, number>;

statusChecks = [
// First column: Telemetry
{ title: 'API Connectivity', statusMessage: 'Unknown' },
{ title: 'Form Hits', statusMessage: 'Unknown' },
{ title: 'Settings Configured', statusMessage: 'Unknown' },
// Second column: Developer Estimates
{ title: 'Polling History', statusMessage: 'Unknown' },
{ title: 'Repositories Configured', statusMessage: 'Unknown' },
{ title: 'Targets Selected', statusMessage: 'Unknown' },
// Third column: Predictive Modeling
{ title: 'Average Usage Level', statusMessage: 'Unknown' },
{ title: 'Estimates Collected', statusMessage: 'Unknown' },
{ title: 'Targets Last Updated', statusMessage: 'Unknown' },
// Additional Checks
{ title: 'Usage Level Trend', statusMessage: 'Unknown' },
{ title: 'Estimates/Daily-User Ratio', statusMessage: 'Unknown' },
{ title: 'Target Levels Acquired', statusMessage: '0 Levels Acquired' }
];

constructor(
private metricsService: MetricsService,
private membersService: MembersService,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@for (s of status; track $index) {
<div class="status">
<div class="status-header">
<mat-card-title>{{s.title}}</mat-card-title>
<mat-card-subtitle>{{s.statusMessage}}</mat-card-subtitle>
</div>
<span class="spacer"></span>
<div class="status-icon">
<button mat-mini-fab [class]="1 ? 'success' : 'error'">
<mat-icon>checked</mat-icon>
</button>
</div>
</div>
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
:host {
display: block;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}

.status {
display: flex;
padding: 17.6px 20px 16px 20px;
border: var(--mdc-outlined-card-outline-width) solid var(--mdc-outlined-card-outline-color, var(--mat-app-outline-variant));
.status-icon {
display: flex;
justify-content: center;
align-items: center;
}
}

.error {
background-color: var(--error) !important;
}

.success {
background-color: var(--success) !important;
}

.warning {
background-color: var(--warning) !important;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatIconModule } from '@angular/material/icon';

@Component({
selector: 'app-status',
standalone: true,
imports: [],
imports: [
MatCardModule,
MatIconModule,
MatButtonModule
],
templateUrl: './status.component.html',
styleUrl: './status.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class StatusComponent { }
export class StatusComponent {
@Input() status?: any[];

constructor() {
}

ngOnInit() {
console.log(this.status);
}
}
6 changes: 6 additions & 0 deletions frontend/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,10 @@ highcharts-chart {
display: block;
width: 100% !important;
height: 100% !important;
}

:root {
--error: #93000a; /* Error */
--success: #28a745; /* Green */
--warning: #FFAB00; /* Orange/Yellow */
}

0 comments on commit 2726233

Please sign in to comment.