Skip to content

Commit

Permalink
Merge pull request #19 from arkedge/implement-ui-pages
Browse files Browse the repository at this point in the history
Implement UI pages
  • Loading branch information
sankichi92 authored Nov 8, 2024
2 parents 90a5748 + 301cf74 commit 8e151da
Show file tree
Hide file tree
Showing 14 changed files with 1,825 additions and 1,135 deletions.
111 changes: 108 additions & 3 deletions client-ui/app/.server/CloverClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { Client, createClient } from "@connectrpc/connect";
import { CloverService } from "~/gen/aegs/clover/v1/clover_service_connect";
import { toJson } from "@bufbuild/protobuf";
import { timestampFromDate } from "@bufbuild/protobuf/wkt";
import { Client, Code, ConnectError, createClient } from "@connectrpc/connect";
import { CloverService } from "~/gen/aegs/clover/v1/clover_service_pb";
import {
ContactSchema,
GroundStationSchema,
PassSchema,
SatelliteSchema,
TLERecordSchema,
} from "~/gen/aegs/clover/v1/models_pb";
import { cloverTransport } from "./grpc";

export class CloverClient {
Expand All @@ -11,6 +20,102 @@ export class CloverClient {

async listSatellites() {
const response = await this.client.listSatellites({});
return response.satellites;
return response.satellites.map((satellite) =>
toJson(SatelliteSchema, satellite),
);
}

async getSatellite(satelliteId: bigint) {
try {
const response = await this.client.getSatellite({ satelliteId });
return toJson(SatelliteSchema, response.satellite!);
} catch (err) {
if (err instanceof ConnectError && err.code === Code.NotFound) {
return null;
} else {
throw err;
}
}
}

async getLatestTLE(satelliteId: bigint) {
try {
const response = await this.client.getLatestTLE({ satelliteId });
return toJson(TLERecordSchema, response.tleRecord!);
} catch (err) {
if (err instanceof ConnectError && err.code === Code.NotFound) {
return null;
} else {
throw err;
}
}
}

async registerTLE(satelliteId: bigint, line1: string, line2: string) {
const response = await this.client.registerTLE({
satelliteId,
tle: { line1, line2 },
});
return toJson(TLERecordSchema, response.tleRecord!);
}

async listAvailableGroundStations(satelliteId: bigint) {
const response = await this.client.listAvailableGroundStations({
satelliteId,
});
return response.groundStations.map((groundStation) =>
toJson(GroundStationSchema, groundStation),
);
}

async getGroundStation(groundStationId: bigint) {
const response = await this.client.getGroundStation({ groundStationId });
return toJson(GroundStationSchema, response.groundStation!);
}

async listUpcomingContacts(satelliteId: bigint) {
const response = await this.client.listUpcomingContacts({ satelliteId });
return response.contacts.map((contact) => toJson(ContactSchema, contact));
}

async getContact(contactId: bigint) {
try {
const response = await this.client.getContact({ contactId });
return toJson(ContactSchema, response.contact!);
} catch (err) {
if (err instanceof ConnectError && err.code === Code.NotFound) {
return null;
} else {
throw err;
}
}
}

async createContact(
satelliteId: bigint,
groundStationId: bigint,
aos: Date,
los: Date,
) {
const response = await this.client.createContact({
satelliteId,
groundStationId,
aos: timestampFromDate(aos),
los: timestampFromDate(los),
});
return toJson(ContactSchema, response.contact!);
}

async cancelContact(contactId: bigint) {
const response = await this.client.cancelContact({ contactId });
return toJson(ContactSchema, response.contact!);
}

async listPasses(satelliteId: bigint, groundStationIds: bigint[]) {
const response = await this.client.listPasses({
satelliteId,
groundStationIds,
});
return response.passes.map((pass) => toJson(PassSchema, pass));
}
}
1 change: 0 additions & 1 deletion client-ui/app/.server/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function createCloverTransport() {

return createGrpcTransport({
baseUrl: CLOVER_BASE_URL,
httpVersion: "2",
nodeOptions: {
cert: CLOVER_CLIENT_CERT,
key: CLOVER_CLIENT_KEY,
Expand Down
33 changes: 33 additions & 0 deletions client-ui/app/components/ContactStatusTag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Intent, Tag, TagProps } from "@blueprintjs/core";
import { Contact_StatusJson } from "~/gen/aegs/clover/v1/models_pb";

interface Props extends TagProps {
status: Contact_StatusJson;
}

export const ContactStatusTag = ({ status, ...rest }: Props) => {
const intent = getIntent(status);
const label = status.replace("STATUS_", "");
return (
<Tag intent={intent} {...rest}>
{label}
</Tag>
);
};

function getIntent(status: Contact_StatusJson) {
switch (status) {
case "STATUS_SCHEDULED":
return Intent.SUCCESS;
case "STATUS_REJECTED":
return Intent.DANGER;
case "STATUS_RUNNING":
return Intent.WARNING;
case "STATUS_COMPLETED":
return Intent.PRIMARY;
case "STATUS_FAILED":
return Intent.DANGER;
default:
return Intent.NONE;
}
}
144 changes: 0 additions & 144 deletions client-ui/app/gen/aegs/clover/v1/clover_service_connect.ts

This file was deleted.

Loading

0 comments on commit 8e151da

Please sign in to comment.