Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock asset feature #5967

Closed
wants to merge 117 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
96fcc41
Merge pull request #1 from coronasafe/develop
JahnabDutta May 26, 2023
c348b50
Change MUI components to CARE components in ResultList.tsx
JahnabDutta May 26, 2023
b1fea78
Merge pull request #2 from coronasafe/develop
JahnabDutta May 26, 2023
393e374
Merge pull request #3 from coronasafe/develop
JahnabDutta May 26, 2023
0657d09
Merge branch 'develop' into develop
khavinshankar May 30, 2023
5296973
Merge branch 'coronasafe:develop' into develop
JahnabDutta May 31, 2023
a8eec96
replace MUI components in src/Components/Shifting/ListFilter.tsx
JahnabDutta May 31, 2023
a4c0702
change LegacySelectField to SelectFormField
JahnabDutta May 31, 2023
8ab013c
fix handChange issue
JahnabDutta May 31, 2023
b7c14e0
Merge branch 'develop' into develop
khavinshankar Jun 1, 2023
2cd2d15
Merge branch 'coronasafe:develop' into develop
JahnabDutta Jun 2, 2023
2be8dc5
fix shiftFilter issues
JahnabDutta Jun 2, 2023
ecf8294
add cypress tests
JahnabDutta Jun 2, 2023
f4016fd
Merge branch 'develop' into develop
nihal467 Jun 5, 2023
7b53f44
change DateRangePicker to DateRangeFormField and add cpyress tests
JahnabDutta Jun 5, 2023
ffff958
Merge original repository to develop repository
JahnabDutta Jun 5, 2023
2e4a9c0
CareUI: Adds `UserAutocompleteFormField` and used it in Assigned To f…
rithviknishad Jun 8, 2023
142f5ca
delete unused `UserSelect2`
rithviknishad Jun 8, 2023
eb3baaf
Merge branch 'develop' into tailwind/userautocompleteformfield
nihal467 Jun 9, 2023
b405d68
Merge branch 'develop' into tailwind/userautocompleteformfield
nihal467 Jun 10, 2023
aa9b9df
Merge branch 'coronasafe:develop' into develop
JahnabDutta Jun 11, 2023
2161dbf
change UserSelect to UserAutoCompleteFormField in ListFilter.tsx and …
JahnabDutta Jun 11, 2023
dc602d3
remove unnecessary grid around DateRangeFormField
JahnabDutta Jun 13, 2023
cc5342f
replace FieldLabel with SelectFormField label
JahnabDutta Jun 13, 2023
65761b2
resolve merge confilcts with ListFilter and cypress test
JahnabDutta Jun 13, 2023
07e9b3c
savepoint
JahnabDutta Jun 28, 2023
2082245
Merge branch 'develop' of https://github.com/JahnabDutta/care_fe into…
JahnabDutta Jun 30, 2023
194680e
Merge branch 'develop' of https://github.com/JahnabDutta/care_fe into…
JahnabDutta Jul 6, 2023
3a81d93
add boundary preset functionality
JahnabDutta Jul 8, 2023
eacf431
add initial UI to boundaryPreset
JahnabDutta Jul 11, 2023
155a55d
Merge branch 'develop' of https://github.com/JahnabDutta/care_fe into…
JahnabDutta Jul 11, 2023
75d9f26
Merge branch 'develop' into add-boundary-preset
JahnabDutta Jul 11, 2023
f00804d
fix updateBoundaryPreset
JahnabDutta Jul 11, 2023
afb0ec0
boundary preset ui
JahnabDutta Jul 12, 2023
36a2718
add boundary calculation algorithm
JahnabDutta Jul 12, 2023
8bb0486
Merge branch 'develop' of https://github.com/JahnabDutta/care_fe into…
JahnabDutta Jul 14, 2023
1e8ffd7
add details
JahnabDutta Jul 14, 2023
62dd642
merge develop branch
JahnabDutta Jul 14, 2023
886bdf4
add UpdateCameraBoundary skeleton
JahnabDutta Jul 14, 2023
d0dd9a4
add directional movement, expand/shrink functionality
JahnabDutta Jul 15, 2023
67bf478
Merge branch 'coronasafe:develop' into add-boundary-preset
JahnabDutta Jul 15, 2023
ca79cd7
fix conditional render bugs with updateBoundaryPreset
JahnabDutta Jul 15, 2023
5b48432
implement scroll
JahnabDutta Jul 15, 2023
c9496bf
add previewBoundary and ConfirmDialog to deleteBoundary
JahnabDutta Jul 16, 2023
7cf39f7
refactor boundarypreset screen
JahnabDutta Jul 16, 2023
b320f53
add loading to preview
JahnabDutta Jul 16, 2023
a06c086
modify UI for updateboundaryPreset
JahnabDutta Jul 16, 2023
472a235
conditional render of feedbuttons in liveFeed
JahnabDutta Jul 17, 2023
f9df5d5
refactor calcBoundary
JahnabDutta Jul 17, 2023
45b2506
refactor directional boundary update
JahnabDutta Jul 17, 2023
f1176a0
add null checks in onvifcamera file
JahnabDutta Jul 17, 2023
aef2c60
refactor and fix bugs
JahnabDutta Jul 18, 2023
0c29460
Merge branch 'coronasafe:develop' into add-boundary-preset
JahnabDutta Jul 18, 2023
398bd4d
shift camera configuration into LiveFeed, changes to UI remain
JahnabDutta Jul 20, 2023
2e7d6d9
remove loading prop
JahnabDutta Jul 21, 2023
4b4296f
Merge branch 'develop' into add-boundary-preset
JahnabDutta Jul 21, 2023
461e079
Merge branch 'add-boundary-preset' of https://github.com/JahnabDutta/…
JahnabDutta Jul 21, 2023
8b4be8a
Merge branch 'develop' of https://github.com/JahnabDutta/care_fe into…
JahnabDutta Jul 22, 2023
01af16b
solve package-lock.json conflicts
JahnabDutta Jul 22, 2023
d3657cf
initialize locking in frontend
JahnabDutta Jul 22, 2023
d10864f
display asset occupied user name
JahnabDutta Jul 24, 2023
ca776c2
Merge branch 'develop' of https://github.com/JahnabDutta/care_fe into…
JahnabDutta Jul 24, 2023
e2bf89b
merge conflicts in package-lock solved
JahnabDutta Jul 24, 2023
bba9658
change UI for adding point preset
JahnabDutta Jul 24, 2023
f6eca76
Merge branch 'develop' of https://github.com/JahnabDutta/care_fe into…
JahnabDutta Jul 26, 2023
c6ac0ce
merge upstream develop with local add-boundary-preset
JahnabDutta Jul 26, 2023
9936777
change UI for add/delete boundary
JahnabDutta Jul 26, 2023
c05b304
change UI for add/delete boundary-2
JahnabDutta Jul 26, 2023
0fdd074
make updateboundary UI skeleton
JahnabDutta Jul 26, 2023
238cfdc
add alternate functions for boundary move
JahnabDutta Jul 27, 2023
82714bb
disable buttons depending on boundary
JahnabDutta Jul 27, 2023
a29e70e
added updation info
JahnabDutta Jul 27, 2023
cfe8d60
Merge branch 'coronasafe:develop' into add-boundary-preset
JahnabDutta Jul 29, 2023
2e5cbf0
Merge branch 'add-boundary-preset' of https://github.com/JahnabDutta/…
JahnabDutta Jul 29, 2023
34c47c5
add red flash around border
JahnabDutta Jul 30, 2023
c009835
add disabled feature on bed
JahnabDutta Aug 1, 2023
a207a5b
Merge branch 'develop' of https://github.com/JahnabDutta/care_fe into…
JahnabDutta Aug 1, 2023
6269385
solve merge conflicts
JahnabDutta Aug 1, 2023
e864cc7
UI changes
JahnabDutta Aug 2, 2023
a39b731
UI changes-2
JahnabDutta Aug 2, 2023
508fea5
Merge branch 'coronasafe:develop' into add-boundary-preset
JahnabDutta Aug 6, 2023
a4d9c93
Merge branch 'add-boundary-preset' of https://github.com/JahnabDutta/…
JahnabDutta Aug 6, 2023
e89b795
Merge branch 'develop' into add-boundary-preset
JahnabDutta Aug 7, 2023
6f3c57a
Merge branch 'coronasafe:develop' into add-boundary-preset
JahnabDutta Aug 9, 2023
271927a
Merge branch 'coronasafe:develop' into lock-asset-feature
JahnabDutta Aug 9, 2023
dfce418
Merge branch 'develop' of https://github.com/JahnabDutta/care_fe into…
JahnabDutta Aug 9, 2023
5a20a91
Merge branch 'develop' of https://github.com/JahnabDutta/care_fe into…
JahnabDutta Aug 12, 2023
4a99291
Revert "fix no data issue in notice borad on hard reload (#6025)"
JahnabDutta Aug 12, 2023
3cfada4
Revert "fixes #6062; align tooltip of `RecordMeta` relative time (#60…
JahnabDutta Aug 12, 2023
dc293a8
register service workers
JahnabDutta Aug 12, 2023
c94b33c
fix feed.tsx conflicts
JahnabDutta Aug 12, 2023
188a2c8
merge add boundary to lock asset branch
JahnabDutta Aug 12, 2023
10b7f70
Merge branch 'lock-asset-feature' of https://github.com/JahnabDutta/c…
JahnabDutta Aug 12, 2023
e990612
add useMessageListner hook
JahnabDutta Aug 15, 2023
bfa1fbc
add subscribe for info button
JahnabDutta Aug 18, 2023
a33dca4
implement real time unlock-asset in frontend
JahnabDutta Aug 19, 2023
2c9268c
add support for locking/unlocking without subscription
JahnabDutta Aug 19, 2023
3c654c5
Merge branch 'develop' of https://github.com/JahnabDutta/care_fe into…
JahnabDutta Aug 21, 2023
2585b02
conflicts fixed
JahnabDutta Aug 21, 2023
0e12642
merge conflicts fixed
JahnabDutta Aug 21, 2023
f12126d
add timeout in camera access
JahnabDutta Aug 22, 2023
4485d56
Merge branch 'develop' into add-boundary-preset
JahnabDutta Aug 23, 2023
09e65e0
Merge branch 'develop' into lock-asset-feature
JahnabDutta Aug 23, 2023
e88a0bb
crash/window close support & request access
JahnabDutta Aug 25, 2023
bf1c754
fix merge conflicts
JahnabDutta Aug 25, 2023
9cc3411
solve merge conflicts
JahnabDutta Aug 25, 2023
ab58415
solve conflicts
JahnabDutta Aug 25, 2023
e62efbe
add cypress test
JahnabDutta Aug 27, 2023
1a212c9
add comments to functions for readability
JahnabDutta Aug 28, 2023
76c0ce5
Merge branch 'add-boundary-preset' of https://github.com/JahnabDutta/…
JahnabDutta Aug 28, 2023
5057647
add comments
JahnabDutta Aug 28, 2023
febfa20
merge upstream develop
JahnabDutta Aug 29, 2023
140ee41
merge upstream develop
JahnabDutta Aug 30, 2023
a503745
merge upstream develop
JahnabDutta Aug 30, 2023
31f3ecf
merge upstream develop
JahnabDutta Aug 30, 2023
e7f36b5
revert extra files
JahnabDutta Aug 30, 2023
6d71f33
Merge branch 'add-boundary-preset' into lock-asset-feature
JahnabDutta Aug 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions cypress/e2e/camera_spec/camera_boundary.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { cy, describe, before, beforeEach, it } from "local-cypress";
const user = { username: "devdistrictadmin", password: "Coronasafe@123" };
describe("Camera Boundary", () => {
before(() => {
cy.loginByApi(user.username, user.password);
cy.saveLocalStorage();
});
beforeEach(() => {
cy.restoreLocalStorage();
cy.awaitUrl("/assets");
cy.get("input[id='search']").type("Dev Camera");
cy.contains("a", "Dev Camera").contains("a", "ICU").click();
cy.get("button[id='configure-asset']").click();
});

it("Add new boundary", () => {
cy.get("input[name='bed']").type("bed 01");
cy.get("li[role='option']").contains("Bed 01").click();
cy.wait(2000);
cy.intercept("**/api/v1/assetbed/**").as("addBoundary");
cy.get("button[id='add-boundary-preset']").click();
cy.wait("@addBoundary");
});

it("Update boundary", () => {
cy.get("input[name='bed']").type("bed 01");
cy.get("li[role='option']").contains("Bed 01").click();
cy.wait(2000);
cy.get("button[id='update-boundary-preset']").click();
cy.intercept("**/api/v1/assetbed/**").as("updateBoundary");
cy.get("button")
.find("svg.care-svg-icon__baseline.care-l-angle-right")
.should("be.visible")
.first()
.click();
cy.wait("@updateBoundary");
cy.get("button").contains("Next").click();
cy.get("button")
.find("svg.care-svg-icon__baseline.care-l-angle-right")
.should("be.visible")
.first()
.click();
cy.wait("@updateBoundary");
cy.get("button").contains("Next").click();
cy.get("button")
.find("svg.care-svg-icon__baseline.care-l-angle-up")
.should("be.visible")
.first()
.click();
cy.wait("@updateBoundary");
cy.get("button").contains("Next").click();
cy.get("button")
.find("svg.care-svg-icon__baseline.care-l-angle-down")
.should("be.visible")
.first()
.click();
cy.wait("@updateBoundary");
cy.get("button").contains("Done").click();
});

it("Delete boundary", () => {
cy.get("input[name='bed']").type("bed 01");
cy.get("li[role='option']").contains("Bed 01").click();
cy.wait(1000);
cy.intercept("**/api/v1/assetbed/**").as("deleteBoundary");
cy.get("button[id='delete-boundary-preset']").click();
cy.get("button").contains("Delete").click();
cy.wait("@deleteBoundary");
});
});
8 changes: 8 additions & 0 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1000,3 +1000,11 @@ export const XLSXAssetImportSchema = {
},
},
};

export type direction = "left" | "right" | "up" | "down" | null;
export interface BoundaryRange {
max_x: number;
min_x: number;
max_y: number;
min_y: number;
}
59 changes: 59 additions & 0 deletions src/Common/hooks/useFeedPTZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface PTZPayload {
x: number;
y: number;
zoom: number;
id?: string | null;
camera_state?: PTZState | null;
}

export interface PTZState {
Expand Down Expand Up @@ -48,6 +50,9 @@ interface UseMSEMediaPlayerReturnType {
getCameraStatus: (options: IOptions) => void;
getPresets: (options: IOptions) => void;
gotoPreset: (payload: IGotoPresetPayload, options: IOptions) => void;
lockAsset: (options: IOptions) => void;
unlockAsset: (options: IOptions) => void;
requestAccess: (options: IOptions) => void;
}

interface IOptions {
Expand Down Expand Up @@ -189,6 +194,57 @@ export const getPTZPayload = (
return { x, y, zoom };
};

const lockAsset =
(config: IAsset, dispatch: any) =>
async (options: IOptions = {}) => {
if (!config.id) return;
const resp = await dispatch(
operateAsset(config.id, {
action: {
type: "lock_asset",
},
})
);
resp &&
(resp.status === 200
? options?.onSuccess && options.onSuccess(resp.data.result)
: options?.onError && options.onError(resp));
};

const requestAccess =
(config: IAsset, dispatch: any) =>
async (options: IOptions = {}) => {
if (!config.id) return;
const resp = await dispatch(
operateAsset(config.id, {
action: {
type: "request_access",
},
})
);
resp &&
(resp.status === 200
? options?.onSuccess && options.onSuccess(resp.data.result)
: options?.onError && options.onError(resp));
};

const unlockAsset =
(config: IAsset, dispatch: any) =>
async (options: IOptions = {}) => {
if (!config.id) return;
const resp = await dispatch(
operateAsset(config.id, {
action: {
type: "unlock_asset",
},
})
);
resp &&
(resp.status === 200
? options?.onSuccess && options.onSuccess(resp.data.result)
: options?.onError && options.onError(resp));
};

export const useFeedPTZ = ({
config,
dispatch,
Expand All @@ -200,5 +256,8 @@ export const useFeedPTZ = ({
getCameraStatus: getCameraStatus(config, dispatch),
getPresets: getPresets(config, dispatch),
gotoPreset: gotoPreset(config, dispatch),
lockAsset: lockAsset(config, dispatch),
unlockAsset: unlockAsset(config, dispatch),
requestAccess: requestAccess(config, dispatch),
};
};
131 changes: 131 additions & 0 deletions src/Common/hooks/useNotificationSubscribe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { useDispatch } from "react-redux";
import {
getUserPnconfig,
updateUserPnconfig,
getPublicKey,
} from "../../Redux/actions";
import { useState } from "react";
import * as Sentry from "@sentry/browser";
import { useTranslation } from "react-i18next";
import { Error } from "../../Utils/Notifications.js";
import useAuthUser from "../../Common/hooks/useAuthUser";

export default function useNotificationSubscribe() {
const { username } = useAuthUser();
const dispatch: any = useDispatch();
const [isSubscribed, setIsSubscribed] = useState("");
const [isSubscribing, setIsSubscribing] = useState(false);
const { t } = useTranslation();

const intialSubscriptionState = async () => {
try {
const res = await dispatch(getUserPnconfig({ username: username }));
const reg = await navigator.serviceWorker.ready;
const subscription = await reg.pushManager.getSubscription();
if (!subscription && !res?.data?.pf_endpoint) {
setIsSubscribed("NotSubscribed");
} else if (subscription?.endpoint === res?.data?.pf_endpoint) {
setIsSubscribed("SubscribedOnThisDevice");
} else {
setIsSubscribed("SubscribedOnAnotherDevice");
}
} catch (error) {
Sentry.captureException(error);
}
};

const handleSubscribeClick = () => {
const status = isSubscribed;
if (status === "NotSubscribed" || status === "SubscribedOnAnotherDevice") {
subscribe();
} else {
unsubscribe();
}
};

const unsubscribe = () => {
navigator.serviceWorker.ready
.then(function (reg) {
setIsSubscribing(true);
reg.pushManager
.getSubscription()
.then(function (subscription) {
subscription
?.unsubscribe()
.then(async function (_successful) {
const data = {
pf_endpoint: "",
pf_p256dh: "",
pf_auth: "",
};
await dispatch(
updateUserPnconfig(data, { username: username })
);

setIsSubscribed("NotSubscribed");
setIsSubscribing(false);
})
.catch(function (_e) {
Error({
msg: t("unsubscribe_failed"),
});
});
})
.catch(function (_e) {
Error({ msg: t("subscription_error") });
});
})
.catch(function (_e) {
Sentry.captureException(_e);
});
};

async function subscribe() {
setIsSubscribing(true);
const response = await dispatch(getPublicKey());
const public_key = response.data.public_key;
const sw = await navigator.serviceWorker.ready;
const push = await sw.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: public_key,
});
const p256dh = btoa(
String.fromCharCode.apply(
null,
new Uint8Array(push.getKey("p256dh") as any) as any
)
);
const auth = btoa(
String.fromCharCode.apply(
null,
new Uint8Array(push.getKey("auth") as any) as any
)
);

const data = {
pf_endpoint: push.endpoint,
pf_p256dh: p256dh,
pf_auth: auth,
};

const res = await dispatch(
updateUserPnconfig(data, { username: username })
);

if (res.status >= 200 && res.status <= 300) {
setIsSubscribed("SubscribedOnThisDevice");
}
setIsSubscribing(false);
}

return {
isSubscribed,
isSubscribing,
setIsSubscribed,
setIsSubscribing,
handleSubscribeClick,
intialSubscriptionState,
subscribe,
unsubscribe,
};
}
Loading