Skip to content

Commit

Permalink
fix(camera_preset): updated camera preset feature
Browse files Browse the repository at this point in the history
Signed-off-by: Abhiuday <[email protected]>
  • Loading branch information
aeswibon committed Apr 18, 2024
1 parent 78bdc55 commit 2b433e5
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 194 deletions.
39 changes: 19 additions & 20 deletions src/Components/Assets/AssetType/ONVIFCamera.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { useEffect, useState } from "react";
import { AssetData, ResolvedMiddleware } from "../AssetTypes";
import { SyntheticEvent, useEffect, useState } from "react";
import useAuthUser from "../../../Common/hooks/useAuthUser";
import { checkIfValidIP } from "../../../Common/validation";
import * as Notification from "../../../Utils/Notifications.js";
import { BedModel } from "../../Facility/models";
import { getCameraConfig } from "../../../Utils/transformUtils";
import CameraConfigure from "../configure/CameraConfigure";
import Loading from "../../Common/Loading";
import { checkIfValidIP } from "../../../Common/validation";
import TextFormField from "../../Form/FormFields/TextFormField";
import { Submit } from "../../Common/components/ButtonV2";
import { SyntheticEvent } from "react";
import useAuthUser from "../../../Common/hooks/useAuthUser";
import { BedModel } from "../../Facility/models";
import TextFormField from "../../Form/FormFields/TextFormField";
import { AssetData, ResolvedMiddleware } from "../AssetTypes";
import CameraConfigure from "../configure/CameraConfigure";

import request from "../../../Utils/request/request";
import routes from "../../../Redux/api";
import request from "../../../Utils/request/request";
import useQuery from "../../../Utils/request/useQuery";

import { useTranslation } from "react-i18next";
import CareIcon from "../../../CAREUI/icons/CareIcon";

interface Props {
Expand All @@ -25,6 +25,7 @@ interface Props {
}

const ONVIFCamera = ({ assetId, facilityId, asset, onUpdated }: Props) => {
const { t } = useTranslation();
const [isLoading, setIsLoading] = useState(true);
const [assetType, setAssetType] = useState("");
const [middlewareHostname, setMiddlewareHostname] = useState("");
Expand All @@ -40,7 +41,7 @@ const ONVIFCamera = ({ assetId, facilityId, asset, onUpdated }: Props) => {
const [loadingAddPreset, setLoadingAddPreset] = useState(false);
const [loadingSetConfiguration, setLoadingSetConfiguration] = useState(false);
const [refreshPresetsHash, setRefreshPresetsHash] = useState(
Number(new Date()),
Number(new Date())

Check failure on line 44 in src/Components/Assets/AssetType/ONVIFCamera.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
const { data: facility, loading } = useQuery(routes.getPermittedFacility, {
pathParams: { id: facilityId },
Expand Down Expand Up @@ -99,15 +100,13 @@ const ONVIFCamera = ({ assetId, facilityId, asset, onUpdated }: Props) => {
};
try {
setLoadingAddPreset(true);

const response = await fetch(
`https://${resolvedMiddleware?.hostname}/status?hostname=${config.hostname}&port=${config.port}&username=${config.username}&password=${config.password}`,
`https://${resolvedMiddleware?.hostname}/status?hostname=${config.hostname}&port=${config.port}&username=${config.username}&password=${config.password}`

Check failure on line 104 in src/Components/Assets/AssetType/ONVIFCamera.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
if (!response.ok) {
throw new Error("Network error");
}
const presetData = await response.json();

const { res } = await request(routes.createAssetBed, {
body: {
meta: { ...data, ...presetData },
Expand Down Expand Up @@ -145,15 +144,15 @@ const ONVIFCamera = ({ assetId, facilityId, asset, onUpdated }: Props) => {
name="middleware_hostname"
label={
<div className="flex flex-row gap-1">
<p>Middleware Hostname</p>
<p>{t("middleware_hostname")}</p>
{resolvedMiddleware?.source != "asset" && (
<div className="tooltip">
<CareIcon
icon="l-info-circle"
className="tooltip text-indigo-500 hover:text-indigo-600"
/>
<span className="tooltip-text w-56 whitespace-normal">
Middleware hostname sourced from asset{" "}
{t("middleware_hostname_sourced_from_asset")}{" "}
{resolvedMiddleware?.source}
</span>
</div>
Expand All @@ -166,30 +165,30 @@ const ONVIFCamera = ({ assetId, facilityId, asset, onUpdated }: Props) => {
/>
<TextFormField
name="camera_address"
label="Local IP Address"
label={t("local_ip_address")}
autoComplete="off"
value={cameraAddress}
onChange={({ value }) => setCameraAddress(value)}
error={ipadrdress_error}
/>
<TextFormField
name="username"
label="Username"
label={t("username")}
autoComplete="off"
value={username}
onChange={({ value }) => setUsername(value)}
/>
<TextFormField
name="password"
label="Password"
label={t("password")}
autoComplete="off"
type="password"
value={password}
onChange={({ value }) => setPassword(value)}
/>
<TextFormField
name="stream_uuid"
label="Stream UUID"
label={t("stream_uuid")}
autoComplete="off"
value={streamUuid}
type="password"
Expand All @@ -202,7 +201,7 @@ const ONVIFCamera = ({ assetId, facilityId, asset, onUpdated }: Props) => {
<Submit
disabled={loadingSetConfiguration}
className="w-full md:w-auto"
label="Set Configuration"
label={t("set_configuration")}
/>
</div>
</form>
Expand Down
Loading

0 comments on commit 2b433e5

Please sign in to comment.