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

geolocation and position packages #37

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ff7e759
init work on geolocation package
suenot Dec 26, 2022
545ed7b
fix init pakages, add save position (need to continue)
suenot Dec 30, 2022
e62ce09
fix naming, fix adding coordintas to history
suenot Dec 30, 2022
b0ee622
fix types for geolocation/position
suenot Dec 30, 2022
0a0724c
add ios
suenot Dec 30, 2022
d71dd5c
save links with coordinates only if them are existing
suenot Dec 30, 2022
2e26760
getPositionsFromDeep
suenot Dec 30, 2022
99bfa75
button: get positions from deep
suenot Jan 3, 2023
71fdce4
geolocation: add ios, try to unsubscribe to watch geolocations
suenot Jan 17, 2023
7f98941
geolocation: watchPositionAndUnwatch
suenot Jan 17, 2023
01f4396
wrong way: setState fn as args, but need used callback fn
suenot Jan 20, 2023
2518d9c
refactoring
suenot Jan 20, 2023
ab1182a
merge main to geolocation-suenot
suenot Jan 22, 2023
e63f769
merge
suenot Jan 28, 2023
b3d583a
fixes: earth to Earth, permissionStatus to permissionState, callback …
suenot Jan 28, 2023
1fa9b7f
remove init device in geolocation package
suenot Feb 7, 2023
17f925a
Merge branch 'main' into geolocation-suenot
suenot Feb 7, 2023
bc09a61
add tree, save multiple positions with one transaction
suenot Mar 23, 2023
e3e4754
change buttons order to init first geolocation package, the second p…
suenot Apr 5, 2023
a10599d
change package name
suenot Apr 11, 2023
16db108
comment trees, revert numbers to string values
suenot Apr 11, 2023
22967bc
add console logs
suenot Apr 13, 2023
ed211ba
merge
suenot Apr 13, 2023
61d46aa
new packages names
suenot Apr 14, 2023
f4cf8fe
merge
suenot Apr 14, 2023
4253bf6
reinstall packages
suenot Apr 14, 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
4 changes: 4 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deepfoundation.deep">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
59 changes: 59 additions & 0 deletions imports/geolocation/initialize-package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { DeepClient } from "@deep-foundation/deeplinks/imports/client";
import { PACKAGE_NAME } from "./package-name";

export async function initializePackage(deep: DeepClient) {
console.log(`initializePackage ${PACKAGE_NAME}`)

const typeTypeLinkId = await deep.id("@deep-foundation/core", "Type");
const anyTypeLinkId = await deep.id("@deep-foundation/core", "Any");
const containTypeLinkId = await deep.id("@deep-foundation/core", "Contain");
const packageTypeLinkId = await deep.id("@deep-foundation/core", "Package");
const joinTypeLinkId = await deep.id("@deep-foundation/core", "Join");
const valueTypeLinkId = await deep.id("@deep-foundation/core", "Value");
const stringTypeLinkId = await deep.id("@deep-foundation/core", "String");
const numberTypeLinkId = await deep.id("@deep-foundation/core", "Number");

const { data: [{ id: packageLinkId }] } = await deep.insert({
type_id: packageTypeLinkId,
string: { data: { value: PACKAGE_NAME } },
in: { data: [
{
type_id: containTypeLinkId,
from_id: deep.linkId
},
] },
out: { data: [
{
type_id: joinTypeLinkId,
to_id: await deep.id('deep', 'users', 'packages'),
},
{
type_id: joinTypeLinkId,
to_id: await deep.id('deep', 'admin'),
},
] },
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { data: [{ id: spaceTypeLinkId }] } = await deep.insert({
type_id: typeTypeLinkId,
from_id: anyTypeLinkId,
to_id: anyTypeLinkId,
in: { data: {
type_id: containTypeLinkId,
from_id: packageLinkId,
string: { data: { value: 'Space' } },
} },
});

const { data: [{ id: earthLinkId }] } = await deep.insert({
type_id: spaceTypeLinkId,
from_id: anyTypeLinkId,
to_id: anyTypeLinkId,
in: { data: {
type_id: containTypeLinkId,
from_id: packageLinkId,
string: { data: { value: 'Earth' } },
} },
});

}
1 change: 1 addition & 0 deletions imports/geolocation/package-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PACKAGE_NAME=`@deep-foundation/capacitor-geolocation`
14 changes: 14 additions & 0 deletions imports/position/check-permissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Geolocation, PermissionStatus } from '@capacitor/geolocation';
import { PermissionState } from '@capacitor/core';

export const checkPermissions = async ({callback}: {callback?: ({newPermissionState}: {newPermissionState: PermissionState}) => any}) => {
try {
const permissionStatus: PermissionStatus = await Geolocation.checkPermissions();
console.log({permissionStatus});
callback?.({newPermissionState: permissionStatus?.location});
return permissionStatus?.location;
} catch {
callback?.({newPermissionState: null});
return null;
}
};
13 changes: 13 additions & 0 deletions imports/position/clear-watch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import { Geolocation } from '@capacitor/geolocation';
// import { Dispatch } from 'react';

export const clearWatch = async ({watchId, callback}: { watchId: string, callback?: ({ result, error }: { result?: string, error?: any }) => void} ) => {
try {
await Geolocation.clearWatch({id: watchId});
callback?.({result: 'success'});
} catch (error) {
console.error(error);
callback?.({error})
}
};
13 changes: 13 additions & 0 deletions imports/position/get-current-position.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Geolocation, Position } from '@capacitor/geolocation';

export const getCurrentPosition = async ({callback}: {callback?: ({coordinates}: {coordinates: Position}) => void}) => {
try {
const coordinates = await Geolocation.getCurrentPosition();
callback?.({coordinates});
return coordinates;
} catch (error) {
console.log(error);
callback?.({coordinates: null});
return null;
}
};
48 changes: 48 additions & 0 deletions imports/position/get-positions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { DeepClient, DeepClientResult } from "@deep-foundation/deeplinks/imports/client";
import { PACKAGE_NAME } from "./package-name";
import { PACKAGE_NAME as PACKAGE_NAME_GEOLOCATION } from "../geolocation/package-name";

export async function getPositions({deep, deviceLinkId, space, callback}: {deep: DeepClient, deviceLinkId: number, space?: string, callback?: (positions: DeepClientResult<any>) => any}) {
try {
const geolocationSpaceTypeLinkId = await deep.id(PACKAGE_NAME_GEOLOCATION, space || "Earth");

if(!deviceLinkId) {
throw new Error("deviceLinkId must not be 0");
}

const xTypeLinkId = await deep.id(PACKAGE_NAME, 'X');
const yTypeLinkId = await deep.id(PACKAGE_NAME, 'Y');
const zTypeLinkId = await deep.id(PACKAGE_NAME, 'Z');
// const positionTreeLinkId = await deep.id(PACKAGE_NAME, 'PositionTree');

const positions = await deep.select({
type_id: {
_in: [xTypeLinkId, yTypeLinkId, zTypeLinkId]
},
from_id: deviceLinkId,
to_id: geolocationSpaceTypeLinkId,
});

// const linksDownToEarthMp = await deep.select({
// up: {
// parent_id: { _eq: geolocationSpaceTypeLinkId },
// tree_id: { _eq: positionTreeLinkId }
// }
// },
// {
// returning: `type_id id from_id to_id
// to {
// value
// }
// `
// });
// console.log({linksDownToEarthMp});

callback?.(positions);
return positions;
} catch (error) {
console.error(error);
callback?.(null);
return null;
}
}
225 changes: 225 additions & 0 deletions imports/position/initialize-package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
import { DeepClient } from "@deep-foundation/deeplinks/imports/client";
import { PACKAGE_NAME } from "./package-name";
import { PACKAGE_NAME as PACKAGE_NAME_GEOLOCATION } from "../geolocation/package-name";

export async function initializePackage(deep: DeepClient) {

const typeTypeLinkId = await deep.id("@deep-foundation/core", "Type");
const containTypeLinkId = await deep.id("@deep-foundation/core", "Contain");
const packageTypeLinkId = await deep.id("@deep-foundation/core", "Package");
const joinTypeLinkId = await deep.id("@deep-foundation/core", "Join");
const valueTypeLinkId = await deep.id("@deep-foundation/core", "Value");
const numberTypeLinkId = await deep.id("@deep-foundation/core", "Number");
const stringTypeLinkId = await deep.id("@deep-foundation/core", "String");
const objectTypeLinkId = await deep.id("@deep-foundation/core", "Object");
const deviceTypeLinkId = await deep.id("@deep-foundation/device", "Device");
const treeTypeLinkId = await deep.id('@deep-foundation/core', 'Tree');
const userTypeLinkId = await deep.id('@deep-foundation/core', 'User');
const geolocationSpaceTypeLinkId = await deep.id(PACKAGE_NAME_GEOLOCATION, "Space");
// const treeIncludeNodeTypeLinkId = await deep.id("@deep-foundation/core", "TreeIncludeNode");
// const treeIncludeDownTypeLinkId = await deep.id("@deep-foundation/core", "TreeIncludeDown");

const { data: [{ id: packageLinkId }] } = await deep.insert({
type_id: packageTypeLinkId,
string: { data: { value: PACKAGE_NAME } },
in: { data: [
{
type_id: containTypeLinkId,
from_id: deep.linkId,
string: { data: { value: 'Package' } },
},
] },
out: { data: [
{
type_id: joinTypeLinkId,
to_id: await deep.id('deep', 'users', 'packages'),
},
{
type_id: joinTypeLinkId,
to_id: await deep.id('deep', 'admin'),
},
] },
});

// const { data: [{ id: positionTreeLinkId }] } = await deep.insert({
// type_id: treeTypeLinkId,
// in: {
// data: {
// type_id: containTypeLinkId,
// from_id: packageLinkId,
// string: { data: { value: 'PositionTree' } },
// },
// },
// out: { data: [
// {
// type_id: treeIncludeNodeTypeLinkId,
// to_id: geolocationSpaceTypeLinkId,
// },
// {
// type_id: treeIncludeNodeTypeLinkId,
// to_id: deviceTypeLinkId,
// },
// ]}
// })

const { data: [{ id: xTypeLinkId }] } = await deep.insert({
type_id: typeTypeLinkId,
from_id: deviceTypeLinkId,
to_id: geolocationSpaceTypeLinkId,
in: { data: [
{
type_id: containTypeLinkId,
from_id: packageLinkId,
string: { data: { value: 'X' } },
},
// {
// type_id: treeIncludeDownTypeLinkId,
// from_id: positionTreeLinkId,
// in: {
// data: [
// {
// type_id: containTypeLinkId,
// from_id: packageLinkId,
// string: { data: { value: 'TreeIncludeDownToX' } },
// },
// ],
// },
// }
]},
out: {
data: {
type_id: valueTypeLinkId,
to_id: stringTypeLinkId
},
},
});

const { data: [{ id: yTypeLinkId }] } = await deep.insert({
type_id: typeTypeLinkId,
from_id: deviceTypeLinkId,
to_id: geolocationSpaceTypeLinkId,
in: { data: [
{
type_id: containTypeLinkId,
from_id: packageLinkId,
string: { data: { value: 'Y' } },
},
// {
// type_id: treeIncludeDownTypeLinkId,
// from_id: positionTreeLinkId,
// in: {
// data: [
// {
// type_id: containTypeLinkId,
// from_id: packageLinkId,
// string: { data: { value: 'TreeIncludeDownToY' } },
// },
// ],
// },
// }
]},
out: {
data: {
type_id: valueTypeLinkId,
to_id: stringTypeLinkId
},
},
});

const { data: [{ id: zTypeLinkId }] } = await deep.insert({
type_id: typeTypeLinkId,
from_id: deviceTypeLinkId,
to_id: geolocationSpaceTypeLinkId,
in: { data: [
{
type_id: containTypeLinkId,
from_id: packageLinkId,
string: { data: { value: 'Z' } },
},
// {
// type_id: treeIncludeDownTypeLinkId,
// from_id: positionTreeLinkId,
// in: {
// data: [
// {
// type_id: containTypeLinkId,
// from_id: packageLinkId,
// string: { data: { value: 'TreeIncludeDownToZ' } },
// },
// ],
// },
// }
]},
out: {
data: {
type_id: valueTypeLinkId,
to_id: stringTypeLinkId
},
},
});

const { data: [{ id: timestampTypeLinkId }] } = await deep.insert({
type_id: typeTypeLinkId,
from_id: deviceTypeLinkId,
to_id: geolocationSpaceTypeLinkId,
in: { data: [
{
type_id: containTypeLinkId,
from_id: packageLinkId,
string: { data: { value: 'Timestamp' } },
},
// {
// type_id: treeIncludeDownTypeLinkId,
// from_id: positionTreeLinkId,
// in: {
// data: [
// {
// type_id: containTypeLinkId,
// from_id: packageLinkId,
// string: { data: { value: 'TreeIncludeDownToTimestamp' } },
// },
// ],
// },
// }
]},
out: {
data: {
type_id: valueTypeLinkId,
to_id: stringTypeLinkId
},
},
});

const { data: [{ id: optionsTypeLinkId }] } = await deep.insert({
type_id: typeTypeLinkId,
from_id: userTypeLinkId,
to_id: deviceTypeLinkId,
in: { data: [
{
type_id: containTypeLinkId,
from_id: packageLinkId,
string: { data: { value: 'Options' } },
},
// {
// type_id: treeIncludeDownTypeLinkId,
// from_id: positionTreeLinkId,
// in: {
// data: [
// {
// type_id: containTypeLinkId,
// from_id: packageLinkId,
// string: { data: { value: 'TreeIncludeDownToOptions' } },
// },
// ],
// },
// }
]},
out: {
data: {
type_id: valueTypeLinkId,
to_id: objectTypeLinkId
},
},
});

}
1 change: 1 addition & 0 deletions imports/position/package-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PACKAGE_NAME=`@deep-foundation/capacitor-position`
Loading