diff --git a/src/field/FieldList.tsx b/src/field/FieldList.tsx index 7362fd8..8b03843 100644 --- a/src/field/FieldList.tsx +++ b/src/field/FieldList.tsx @@ -244,14 +244,12 @@ const columns: Column[] = [ return ( - {isMobile && - } [] = [ - {!isMobile && - - } {fieldTable(fields)} {/* ("") + const [user, setUser] = useState("") + const [sharedPermissions, setSharedPermissions] = useState([ + pond.Permission.PERMISSION_READ + ]) const share = () => { - //if sharing to team use shareAllByKey + if(teamShare){ + //if sharing to team use shareAllByKey + fieldAPI.shareAllByKey(team, sharedPermissions) + .then(resp => { + openSnack("Shared all fields to team") + }).catch(err => { + openSnack("There was a problem sharing the fields") + }) + }else{ + //if sharing to user use shareAll + fieldAPI.shareAll(user, sharedPermissions) + .then(resp => { + openSnack("Shared all fields to user") + }).catch(err => { + openSnack("There was a problem sharing the fields") + }) + } - //if sharing to user use shareAll } const target = () => { // toggle for whether sharing to user or team + return ( + + + User + + { + setTeamShare(checked) + }} + name="storage" + /> + + Team + + {teamShare ? + + {setTeam(teamKey)}}/> + : + + { + setUser(e.target.value) + }} + /> + } + + ) // if sharing to user have a text field - // if sharing to team have the team selector + } + + const changePermissions = (checked: boolean, permission: pond.Permission) => { + let currentPerms = cloneDeep(sharedPermissions) + if(checked){ + //if the permissions does not include the permission add it + if(!sharedPermissions.includes(permission)) currentPerms.push(permission) + }else{ + //if the permissions includes the permission remove it + if(sharedPermissions.includes(permission)) currentPerms.splice(currentPerms.indexOf(permission), 1) + } + setSharedPermissions(currentPerms) } const permissions = () => { // the checkboxes of permissions + return ( + + + Permissions + + {changePermissions(checked, pond.Permission.PERMISSION_READ)}} + value={pond.Permission.PERMISSION_READ as pond.Permission} + /> + } + label="View" + labelPlacement="end" + /> + {changePermissions(checked, pond.Permission.PERMISSION_WRITE)}} + value={pond.Permission.PERMISSION_WRITE as pond.Permission} + /> + } + label="Edit" + labelPlacement="end" + /> + {changePermissions(checked, pond.Permission.PERMISSION_SHARE)}} + value={pond.Permission.PERMISSION_SHARE as pond.Permission} + /> + } + label="Share" + labelPlacement="end" + /> + {changePermissions(checked, pond.Permission.PERMISSION_USERS)}} + value={pond.Permission.PERMISSION_USERS as pond.Permission} + /> + } + label="Users" + labelPlacement="end" + /> + {changePermissions(checked, pond.Permission.PERMISSION_FILE_MANAGEMENT)}} + value={pond.Permission.PERMISSION_FILE_MANAGEMENT as pond.Permission} + /> + } + label="Files" + labelPlacement="end" + /> + {/* billing */} + {changePermissions(checked, pond.Permission.PERMISSION_BILLING)}} + value={pond.Permission.PERMISSION_BILLING as pond.Permission} + /> + } + label="Billing" + labelPlacement="end" + /> + + + + ) } const actions = () => { //the buttons to shaare or cancel + return ( + + + + + ) } return ( Share All Fields - Content for selecting target and permissions + + {target()} + {permissions()} + - Buttons for cancel and confirm + {actions()} ) diff --git a/src/models/Field.ts b/src/models/Field.ts index d2061d1..d85b294 100644 --- a/src/models/Field.ts +++ b/src/models/Field.ts @@ -161,7 +161,7 @@ export class Field { * @param spacing - an optional paramater that will expand the bounding area by the given long lat amount * @returns LngLatBounds - an object containing the southwest and northeast coordinates of a bounding box */ - public fieldBounds(spacing?: number): LngLatBounds { + public fieldBounds(spacing?: number, squared?: boolean): LngLatBounds { let minLong = 0; let minLat = 0; let maxLong = 0; @@ -178,6 +178,12 @@ export class Field { } // let southWest = [minLong,minLat] // let northEast = [maxLong,maxLat] + if (squared){ + //make sure the bounds are squared so as to fit the entire field in the map + //get the diff between the longs and the lats + //find which is narrower + //take half of the difference between the differences + } if(spacing){ minLong = minLong - spacing minLat = minLat - spacing diff --git a/src/providers/pond/fieldAPI.tsx b/src/providers/pond/fieldAPI.tsx index 93309df..803be77 100644 --- a/src/providers/pond/fieldAPI.tsx +++ b/src/providers/pond/fieldAPI.tsx @@ -103,7 +103,7 @@ export default function FieldProvider(props: PropsWithChildren) { }; const shareAll = (email: string, permissions: pond.Permission[]) => { - let url = pondURL("/fields/shareAll") + let url = pondURL("/shareAllFields") if (as) url = url + "?as=" + as return new Promise((resolve, reject) => { post(url, { @@ -118,7 +118,7 @@ export default function FieldProvider(props: PropsWithChildren) { } const shareAllByKey = (key: string, permissions: pond.Permission[]) => { - let url = pondURL("/fields/shareAllByKey") + let url = pondURL("/shareAllFieldsByKey") if (as) url = url + "?as=" + as return new Promise((resolve, reject) => { post(url, {