Skip to content

Commit

Permalink
added automatic events from notification parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Dexagod committed Oct 5, 2020
1 parent 1b9f3f6 commit cf8d2ff
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 152 deletions.
2 changes: 0 additions & 2 deletions src/Components/CertificateViewComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const CertificateViewComponent = (props) => {
}
}, [])

console.log('STATE', state)

if (!state.proposal || !state.certificate) {
return (
<div id="marriageViewContainer" className='container' />
Expand Down
83 changes: 40 additions & 43 deletions src/Components/CertificatesViewerComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,50 @@ const CertificatesViewerComponent = (props) => {

// Retrieve notifications

const notifications = useNotifications(props.webId)
const contracts = useContracts(props.webId)
const [certifiedContacts, setCertifiedContracts] = useState([])
console.log('notifications', notifications)

useEffect(() => {
let mounted = true;

// This function updates the present submissions in case of a notification indicating that a certificate has been created
const updateProposals = async (submittedContracts) => {
const certificationNotices = notifications.filter(notification =>
notification.type === ns.as('Announce')
&& notification.object
&& notification.object.object
&& notification.metadata.types.object.object === ns.demo('Certificate'))
const userContracts = useContracts(props.webId) || []
const contracts = userContracts.filter(e => e.status && e.status === ns.demo('accepted') || e.status === ns.demo('rejected'))

// useEffect(() => {
// let mounted = true;

// // This function updates the present submissions in case of a notification indicating that a certificate has been created
// const updateProposals = async (submittedContracts) => {
// const certificationNotices = notifications.filter(notification =>
// notification.type === ns.as('Announce')
// && notification.object
// && notification.object.object
// && notification.metadata.types.object.object === ns.demo('Certificate'))

// TODO:: inblude if rejected, and move this more elaborate code to a separate controller.
for (let contract of submittedContracts){
const contractNotifications = certificationNotices.filter(n => n.object.target === contract.id)
if (contractNotifications.length > 0) {
const certificateId = contractNotifications[0].object.object
const contractId = contractNotifications[0].object.target
await setProposalValidatedBy(contractId, certificateId, "accepted")
contract.status = "accepted"
alreadyCertifiedContracts.push(contract)
}
}
setCertifiedContracts(alreadyCertifiedContracts)
}

const alreadyCertifiedContracts = contracts.filter(c => c.status === ns.demo('accepted')).concat(contracts.filter(c => c.status === ns.demo('rejected')))
const submittedContracts = contracts.filter(c => c.status === ns.demo('submitted'))
if (submittedContracts.length) { // check if submitted contract has been certified
updateProposals(submittedContracts)
} else {
setCertifiedContracts(alreadyCertifiedContracts)
}
return () => {
mounted = false;
}
}, [notifications, contracts])
// // TODO:: inblude if rejected, and move this more elaborate code to a separate controller.
// for (let contract of submittedContracts){
// const contractNotifications = certificationNotices.filter(n => n.object.target === contract.id)
// if (contractNotifications.length > 0) {
// const certificateId = contractNotifications[0].object.object
// const contractId = contractNotifications[0].object.target
// await setProposalValidatedBy(contractId, certificateId, "accepted")
// contract.status = "accepted"
// alreadyCertifiedContracts.push(contract)
// }
// }
// setCertifiedContracts(alreadyCertifiedContracts)
// }

// const alreadyCertifiedContracts = contracts.filter(c => c.status === ns.demo('accepted')).concat(contracts.filter(c => c.status === ns.demo('rejected')))
// const submittedContracts = contracts.filter(c => c.status === ns.demo('submitted'))
// if (submittedContracts.length) { // check if submitted contract has been certified
// updateProposals(submittedContracts)
// } else {
// setCertifiedContracts(alreadyCertifiedContracts)
// }
// return () => {
// mounted = false;
// }
// }, [contracts])


async function showCertificateViewer(contractId) {
const view = availableViews.certificateview
view.args = {proposalId: contractId}
console.log('setting view', view)
props.setview(view)
}

Expand All @@ -82,9 +79,9 @@ const CertificatesViewerComponent = (props) => {
<Col md={3}><label className="leftaligntext"><b>Residence</b></label></Col>
<Col md={5}><label className="leftaligntext">No certificate available</label></Col>
</Row>
{ certifiedContacts.length
{ contracts.length // certifiedContacts.length
?
certifiedContacts.map((contract, index) => {
contracts.map((contract, index) => { //certifiedContacts.map((contract, index) => {
return (
<Row className='propertyview' key={contract.id}>
{index === 0 ? <Col md={3}><label className="leftaligntext"><b>Marriage</b></label></Col> : <Col md={3} /> }
Expand Down
3 changes: 1 addition & 2 deletions src/Components/InProgressViewerComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { availableViews } from '../util/Util'

const InProgressViewerComponent = (props) => {

const userContracts = useContracts(props.webId)
console.log('userContracts', userContracts)
const userContracts = useContracts(props.webId) || []
const contracts = userContracts.filter(e => !e.status || e.status === ns.demo('proposal'))

const viewMarriage = function(contract){
Expand Down
20 changes: 6 additions & 14 deletions src/Components/MarriageRequestComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const MarriageRequestComponent = (props) => {
webId: "",
}
])

console.log('PROFILES', state)

const handleSubmit = async event => {
if (!await validateSubmission(state)) return;
const proposal = await createMarriageProposal(state, storageLocation, props.webId)
Expand All @@ -43,7 +42,6 @@ const MarriageRequestComponent = (props) => {
const setvalue = (index, value) => {
const stateCopy = state.slice()
stateCopy[index].webId = value
console.log('setting value', index, value)
setState(stateCopy)
}

Expand All @@ -58,13 +56,9 @@ const MarriageRequestComponent = (props) => {
}

const deleteWitness = (index) => {
console.log('deleting', index)
const stateCopy = state.slice()
const entry = stateCopy.splice(index, 1)[0]
console.log('deleting', index, entry, stateCopy)
console.log('deleting', entry.type === 'witness', entry.type)
if (entry.type === 'witness'){
console.log('setting state', stateCopy)
setState(stateCopy)
}

Expand All @@ -83,21 +77,19 @@ const MarriageRequestComponent = (props) => {
return false
}

console.log('GETTING PROFILE')
const profile = await getProfileData(person.webId)
console.log('PROFILE', profile)
if (!profile || !profile.name) {
window.alert(person.webId + ' is not a valid webId');
return false
} else if (!profile.bdate || !profile.location || !profile.cstatus) {
} else if (!profile.bdate || !profile.location /*|| !profile.cstatus*/) {
window.alert(person.webId + ' does not have a valid profile');
return false
}

if (person.type === 'spouse' && profile.cstatus === "Married"){
window.alert('spouse ' + person.webId + ' is already married.');
return false
}
// if (person.type === 'spouse' && profile.cstatus === "Married"){
// window.alert('spouse ' + person.webId + ' is already married.');
// return false
// }
}
return true
}
Expand Down
6 changes: 1 addition & 5 deletions src/Components/MarriageViewComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ const MarriageViewComponent = (props) => {
window.alert('Please fill in the webId of an official to submit the request to (this can be your own webId for demo purposes).');
return false
}
console.log('getting profile')
const profile = await getProfileData(official)
console.log('PROFILE', profile)
if (!profile || !profile.name)
window.alert('The webId of the official: ' + official + ', is not a valid webId');
return true
Expand All @@ -83,7 +81,7 @@ const MarriageViewComponent = (props) => {
// For demo purposes outside of the workshop also, we will have the user function as the official also
if (! await validateOfficial()) return;
const submission = await submitProposal(props.webId, props.contract.id, official)
props.setview(availableViews.official)
props.setview(availableViews.certificates)
}

async function deleteMarriageProposal() {
Expand All @@ -110,7 +108,6 @@ const MarriageViewComponent = (props) => {

async function accept(contactId, contractId) {
const response = await acceptProposal(props.webId, props.contract.id, props.contract.creator)
console.log('ACCEPTED', response)
setContactStatus(contactId, 'accepted')
}

Expand All @@ -124,7 +121,6 @@ const MarriageViewComponent = (props) => {
}

function getContactButton(contact){
console.log(contact, props.contract)
if(contact.status === 'pending') {
if (contact.id === props.webId) return (
<div>
Expand Down
34 changes: 29 additions & 5 deletions src/Components/OfficialComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Value } from '@solid/react';
import useNotifications from '../hooks/useNotifications'
import ns from '../util/NameSpaces'
import { Col, Row, Button } from 'react-bootstrap'
import { getContractData, availableViews } from '../util/Util'
import { getContractData, availableViews, getProfileCertified } from '../util/Util'

const { default: data } = require('@solid/query-ldflex');

Expand All @@ -12,10 +12,17 @@ const OfficialComponent = (props) => {
const notifications = useNotifications(props.webId)
const [submissions, setSubmissions] = useState([])

const [certifiedContracts, setCertified] = useState([])
const filteredSubmissions = submissions.filter(submission => submission.object && submission.object.object && certifiedContracts.indexOf(submission.object.object) === -1)

useEffect(() => {
const getCertifications = async() => setCertified(await getProfileCertified(props.webId))
getCertifications()
}, [])

useEffect(() => {
let mounted = true;
async function filterSubmissions() {
console.log("Notifications", notifications)
const submissions = notifications.filter(notification =>
notification.type === ns.as('Announce')
&& notification.object
Expand Down Expand Up @@ -60,8 +67,7 @@ const OfficialComponent = (props) => {
<Col md={3}><label className="leftaligntext">Submitted by</label></Col>
<Col md={2}><label className="centeraligntext">Action</label></Col>
</Row>
{submissions.map(submission => {
console.log(submission)
{filteredSubmissions.map(submission => {
return (
<Row className='propertyview ' key={submission.object}>
<Col md={3}><label className="leftaligntext"><b>marriage proposal</b></label></Col>
Expand All @@ -77,4 +83,22 @@ const OfficialComponent = (props) => {

}

export default OfficialComponent
export default OfficialComponent


/*
const userContracts = useContracts(props.webId) || []
const [certified, setCertified] = useState([])
const allContracts = userContracts.filter(e => e.status && e.status === ns.demo('submitted'))
const submissions = allContracts.filter(contract => certified.indexOf(contract.id) == -1)
console.log('officialContracts', allContracts.map(e => e.id), certified, submissions.map(e => e.id))
useEffect(() => {
async function getCertifications() {
setCertified(await getProfileCertified(props.webId) || [])
}
getCertifications()
}, [])
*/
2 changes: 1 addition & 1 deletion src/Components/ProfileCardComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const profileProps = {
name: "Name",
bdate: "BirthDate",
location: "Country",
cstatus: "Civil Status",
// cstatus: "Civil Status",
}

export default ProfileCardComponent
2 changes: 1 addition & 1 deletion src/Components/ProfileCardSelectorComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ProfileCardSelectorComponent = (props) => {
// if (profile && isProfile(profile)) props.setvalue(profile.webId);
// }, [profile])

const isComplete = (profile) => profile.name && profile.bdate && profile.location && profile.cstatus
const isComplete = (profile) => profile.name && profile.bdate && profile.location //&& profile.cstatus
const isProfile = (profile) => profile.name
const isOfAge = (profile) => profile.bdate && new Date(profile.bdate) && getAge(new Date(profile.bdate)) >= 18

Expand Down
32 changes: 16 additions & 16 deletions src/Components/ProfileEditorComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ const ProfileEditorComponent = (props) => {
label: 'Country',
name: 'location',
type: 'text',
}, {
label: 'Civil Status',
name: 'cstatus',
controller: <Controller as={
<Select>
<MenuItem value={"Single"}>Single</MenuItem>
<MenuItem value={"Cohabiting"}>Cohabiting</MenuItem>
<MenuItem value={"Married"}>Married</MenuItem>
<MenuItem value={"Divorced"}>Divorced</MenuItem>
<MenuItem value={"Widowed"}>Widowed</MenuItem>
</Select>
}
control={control}
name="cstatus"
defaultValue={"Single"}
/>
// }, {
// label: 'Civil Status',
// name: 'cstatus',
// controller: <Controller as={
// <Select>
// <MenuItem value={"Single"}>Single</MenuItem>
// <MenuItem value={"Cohabiting"}>Cohabiting</MenuItem>
// <MenuItem value={"Married"}>Married</MenuItem>
// <MenuItem value={"Divorced"}>Divorced</MenuItem>
// <MenuItem value={"Widowed"}>Widowed</MenuItem>
// </Select>
// }
// control={control}
// name="cstatus"
// defaultValue={"Single"}
// />
}]

return (
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ProfileViewerComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const profileProps = {
name: "Name",
bdate: "BirthDate",
location: "Country",
cstatus: "Civil Status",
// cstatus: "Civil Status",
}

export default ProfileViewerComponent
Loading

0 comments on commit cf8d2ff

Please sign in to comment.