-
Notifications
You must be signed in to change notification settings - Fork 19
Groups now contain a list of doors they give access to, and this is synced automatically to accessy. #670
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
Merged
Merged
Groups now contain a list of doors they give access to, and this is synced automatically to accessy. #670
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
41ff0f0
Groups now contain a list of doors they give access to, and this is s…
HalfVoxel 4171261
Minor cleanup.
HalfVoxel 5af8984
Clarifications
HalfVoxel 2e94164
Fix test.
HalfVoxel b98742d
Address review comments.
HalfVoxel cefd4d2
Fix crash when accessy is not configured.
HalfVoxel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
import GroupDoorAccess from "Models/GroupDoorAccess"; | ||
import React, { useEffect, useMemo, useState } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
import Select from "react-select"; | ||
import CollectionTable from "../Components/CollectionTable"; | ||
import Icon from "../Components/icons"; | ||
import Collection from "../Models/Collection"; | ||
import { get, post } from "../gateway"; | ||
|
||
interface AccessyAsset { | ||
id: string; | ||
createdAt: string; | ||
updatedAt: string; | ||
name: string; | ||
description: string; | ||
address: object; | ||
images: { | ||
id: string; | ||
imageId: string; | ||
thumbnailId: string; | ||
size: number; | ||
width: number; | ||
height: number; | ||
}[]; | ||
roomType: string; | ||
category: string; | ||
status: string; | ||
} | ||
|
||
interface AccessyAssetPublication { | ||
id: string; | ||
} | ||
|
||
interface AccessyAssetWithPublication { | ||
asset: AccessyAsset; | ||
publication: AccessyAssetPublication; | ||
} | ||
|
||
const GroupBoxDoorAccess = () => { | ||
const { group_id } = useParams<{ group_id: string }>(); | ||
const group_id_num = Number(group_id); | ||
const [selectedOption, setSelectedOption] = | ||
useState<AccessyAssetWithPublication | null>(null); | ||
const [options, setOptions] = useState<AccessyAssetWithPublication[]>([]); | ||
const [items, setItems] = useState<GroupDoorAccess[]>([]); | ||
const [loading, setLoading] = useState(true); | ||
const filteredOptions = useMemo(() => { | ||
return options.filter((option) => { | ||
return !items.some( | ||
(item) => | ||
item.accessy_asset_publication_guid === | ||
option.publication.id, | ||
); | ||
}); | ||
}, [options, items]); | ||
|
||
const collection = useMemo( | ||
() => | ||
new Collection({ | ||
type: GroupDoorAccess, | ||
url: `/membership/group/${group_id}/door_access_permissions`, | ||
idListName: "door_access_permissions", | ||
pageSize: 0, | ||
}), | ||
[group_id], | ||
); | ||
|
||
useEffect(() => { | ||
get({ url: "/accessy/assets" }).then(({ data }) => { | ||
setOptions(data); | ||
setLoading(false); | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
// Purely for the rendering side-effect | ||
const unsubscribe = collection.subscribe(({ items: newItems }) => { | ||
setItems(newItems); | ||
}); | ||
|
||
return () => { | ||
unsubscribe(); | ||
}; | ||
}, [collection]); | ||
|
||
const selectOption = async (item: AccessyAssetWithPublication | null) => { | ||
setSelectedOption(item); | ||
|
||
if (item !== null) { | ||
let access = new GroupDoorAccess({ | ||
group_id: group_id_num, | ||
accessy_asset_publication_guid: item.publication.id, | ||
}); | ||
await access.save(); | ||
setSelectedOption(null); | ||
await collection.fetch(); | ||
await post({ | ||
url: `/accessy/sync`, | ||
expectedDataStatus: "ok", | ||
}); | ||
} | ||
}; | ||
|
||
const columns = [{ title: "Tillgångar" }]; | ||
|
||
const Row = ({ item }: { item: GroupDoorAccess }) => { | ||
const asset = options.find( | ||
(o) => o.publication.id === item.accessy_asset_publication_guid, | ||
); | ||
return ( | ||
<tr> | ||
<td> | ||
{asset?.asset.images.map((img) => ( | ||
<img | ||
className="accessy-asset-img-thumbnail" | ||
src={ | ||
config.apiBasePath + | ||
`/accessy/image/${img.thumbnailId}` | ||
} | ||
/> | ||
))} | ||
</td> | ||
<td> | ||
{asset !== undefined | ||
? asset.asset.name | ||
: `Unknown Asset - ${item.accessy_asset_publication_guid}`} | ||
</td> | ||
<td> | ||
<a | ||
onClick={async () => { | ||
await item.del(); | ||
await collection.fetch(); | ||
await post({ | ||
url: `/accessy/sync`, | ||
expectedDataStatus: "ok", | ||
}); | ||
}} | ||
className="removebutton" | ||
> | ||
<Icon icon="trash" /> | ||
</a> | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className="uk-margin-top uk-form-stacked"> | ||
<p> | ||
All members of this group will get access to the following | ||
Accessy assets if they have active labaccess. | ||
</p> | ||
<label className="uk-form-label" htmlFor="asset"> | ||
Lägg till tillgång | ||
</label> | ||
<div className="uk-form-controls"> | ||
<Select<AccessyAssetWithPublication, false> | ||
name="asset" | ||
className="uk-width-1-1" | ||
tabIndex={1} | ||
options={filteredOptions} | ||
value={selectedOption} | ||
getOptionValue={(p) => p.publication.id} | ||
getOptionLabel={(p) => p.asset.name} | ||
formatOptionLabel={(p) => ( | ||
<div> | ||
{p.asset.images.length > 0 ? ( | ||
<img | ||
className="accessy-asset-img-thumbnail" | ||
src={ | ||
config.apiBasePath + | ||
`/accessy/image/${ | ||
p.asset.images[0]!.thumbnailId | ||
}` | ||
} | ||
/> | ||
) : null} | ||
<span className="uk-margin-left"> | ||
{p.asset.name} | ||
</span> | ||
</div> | ||
)} | ||
onChange={(p) => selectOption(p)} | ||
isDisabled={!filteredOptions.length} | ||
placeholder={ | ||
!loading && options.length == 0 | ||
? "Inga Accessy-tillgångar hittades" | ||
: "Välj tillgång" | ||
} | ||
/> | ||
</div> | ||
</div> | ||
<div className="uk-margin-top"> | ||
<CollectionTable | ||
emptyMessage="Gruppen ger inga extra rättigheter att öppna dörrar" | ||
rowComponent={Row} | ||
loading={loading} | ||
collection={collection} | ||
columns={columns} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GroupBoxDoorAccess; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Base from "./Base"; | ||
|
||
export default class GroupDoorAccess extends Base<GroupDoorAccess> { | ||
group_id!: number; | ||
accessy_asset_publication_guid!: string; | ||
created_at!: Date | null; | ||
updated_at!: Date | null; | ||
deleted_at!: Date | null; | ||
|
||
static model = { | ||
root: "/membership/group_door_access_permissions", | ||
id: "id", | ||
attributes: { | ||
accessy_asset_publication_guid: null, | ||
deleted_at: null, | ||
}, | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.