Skip to content

Commit

Permalink
added lunchtopic score
Browse files Browse the repository at this point in the history
  • Loading branch information
jzakotnik committed Aug 22, 2021
1 parent 65ddd0f commit 5788bca
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 41 deletions.
10 changes: 9 additions & 1 deletion nextjs/mwe/pages/api/insertData.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ async function insertUser(req) {
public_id: authid.reader,
private_id: authid.admin,
name: "tbd",

lunchprofile: {
create: { mon: true, tue: true, wed: true, thu: true, fri: true },
create: {
mon: true,
tue: true,
wed: true,
thu: true,
fri: true,
lunchtopic: 50,
},
},
},
});
Expand Down
7 changes: 4 additions & 3 deletions nextjs/mwe/pages/api/updateData.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ async function updateUser(req) {
const authid = req.body.authid.admin;
console.log("Updating user");
console.log(req.body);
const lunchprofile = req.body.dayselection;
//console.log(lunchprofile);
//console.log(authid);
const lunchprofile = req.body.lunchProfile;

console.log(lunchprofile);
console.log(authid);

const updateLunch = await prisma.lunchProfile.update({
where: {
Expand Down
122 changes: 100 additions & 22 deletions nextjs/mwe/pages/lunchprofileadmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,71 @@ import LockOutlinedIcon from "@material-ui/icons/LockOutlined";
import FastfoodIcon from "@material-ui/icons/Fastfood";
import Typography from "@material-ui/core/Typography";
import FormGroup from "@material-ui/core/FormGroup";
import Slider from "@material-ui/core/Slider";

import Switch from "@material-ui/core/Switch";
import Divider from "@material-ui/core/Divider";
import Impressum from "./impressum";

const marks = [
{
value: 0,
label: "Lieber Privates",
},
{
value: 50,
label: "Ist mir egal",
},
{
value: 100,
label: "Lieber Arbeit",
},
];

function valuetext(value) {
return `${value}%`;
}

const lunchtime = [
{
value: 0,
label: "11:00",
},
{
value: 50,
label: "13:00",
},
{
value: 100,
label: "14:00",
},
];

export default function LunchProfileAdmin(props) {
const [dayselection, setDayselection] = useState({
const [lunchProfile, setLunchProfile] = useState({
mon: true,
tue: true,
wed: true,
thu: true,
fri: true,
lunchtopic: 50,
});

const [saving, setSaving] = useState(false);

const authid = props.authid;
const readerid = props.reader;

useEffect(() => {
setDayselection(props.lunchdata);
setLunchProfile(props.lunchdata);
}, [props]);

const handleSubmit = (event) => {
event.preventDefault();
//setSaving(true);
console.log(event);

const data = { dayselection, authid: { admin: authid } };
const data = { lunchProfile, authid: { admin: authid } };
console.log("Saving..");
console.log(JSON.stringify(data));

Expand All @@ -61,13 +99,18 @@ export default function LunchProfileAdmin(props) {

const handleInput = (evt) => {
//console.log(evt.target.name + ": " + evt.target.checked);
setDayselection({ ...dayselection, [evt.target.name]: evt.target.checked });
setLunchProfile({ ...lunchProfile, [evt.target.name]: evt.target.checked });
};

const handleLunchTopic = (e) => {
setLunchProfile({ ...lunchProfile, lunchtopic: e.target.value });
};

function SaveButton(props) {
return (
<Button
type="submit"
onClick={handleSubmit}
disabled={saving}
fullWidth
variant="contained"
Expand Down Expand Up @@ -100,34 +143,42 @@ export default function LunchProfileAdmin(props) {
<Grid item xs={12} sm={8} md={5} component={Paper} elevation={6} square>
<Box
sx={{
my: 8,
mx: 4,
mt: 6,
my: 4,
mx: 2,
display: "flex",
flexDirection: "column",
alignItems: "center",
}}
>
<Avatar sx={{ m: 1, bgcolor: "secondary.main" }}>
<FastfoodIcon />
</Avatar>
{" "}
<Typography component="h1" variant="h5">
Mein Lunch Profil
</Typography>
<Typography component="subtitle1" variant="subtitle1">
An diesen Tagen habe ich typischerweise Zeit für einen Lunch
</Typography>
<Avatar sx={{ m: 1, bgcolor: "secondary.main" }}>
<FastfoodIcon />
</Avatar>
<Box
component="form"
noValidate
onSubmit={handleSubmit}
sx={{ mt: 1 }}
sx={{
mt: 1,
my: 5,
mx: 1,
display: "flex",
flexDirection: "column",
alignItems: "left",
}}
>
<Typography component="subtitle1" variant="subtitle1">
Typischerweise Zeit am
</Typography>
<FormGroup>
<FormControlLabel
control={
<Switch
name="mon"
checked={dayselection.mon}
checked={lunchProfile.mon}
onChange={handleInput}
inputProps={{ "aria-label": "controlled" }}
/>
Expand All @@ -138,7 +189,7 @@ export default function LunchProfileAdmin(props) {
control={
<Switch
name="tue"
checked={dayselection.tue}
checked={lunchProfile.tue}
onChange={handleInput}
inputProps={{ "aria-label": "controlled" }}
/>
Expand All @@ -149,7 +200,7 @@ export default function LunchProfileAdmin(props) {
control={
<Switch
name="wed"
checked={dayselection.wed}
checked={lunchProfile.wed}
onChange={handleInput}
inputProps={{ "aria-label": "controlled" }}
/>
Expand All @@ -160,7 +211,7 @@ export default function LunchProfileAdmin(props) {
control={
<Switch
name="thu"
checked={dayselection.thu}
checked={lunchProfile.thu}
onChange={handleInput}
inputProps={{ "aria-label": "controlled" }}
/>
Expand All @@ -171,18 +222,45 @@ export default function LunchProfileAdmin(props) {
control={
<Switch
name="fri"
checked={dayselection.fri}
checked={lunchProfile.fri}
onChange={handleInput}
inputProps={{ "aria-label": "controlled" }}
/>
}
label="Freitag"
/>
</FormGroup>
<SaveButton />

<Impressum sx={{ mt: 5 }} />
</Box>
<Box
component="form"
noValidate
sx={{
mt: 1,
my: 5,
mx: 1,
display: "flex",
flexDirection: "column",
alignItems: "left",
}}
>
<Typography component="subtitle1" variant="subtitle1">
Lieblingsthema beim Essen
</Typography>
<Slider
aria-label="Essensthema"
value={lunchProfile.lunchtopic}
getAriaValueText={valuetext}
step={10}
onChange={handleLunchTopic}
valueLabelDisplay="auto"
marks={marks}
sx={{
width: "95%",
}}
/>
</Box>
<SaveButton />
<Impressum sx={{ mt: 5 }} />
</Box>
</Grid>
</Grid>
Expand Down
23 changes: 14 additions & 9 deletions nextjs/mwe/pages/lunchprofileread.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import ListItemText from "@material-ui/core/ListItemText";
import Impressum from "./impressum";

export default function LunchProfileRead(props) {
const [dayselection, setDayselection] = useState({
const [lunchProfile, setLunchProfile] = useState({
mon: true,
tue: true,
wed: true,
thu: true,
fri: true,
lunchtopic: 50,
});

const daymapping = {
Expand All @@ -44,7 +45,7 @@ export default function LunchProfileRead(props) {
useEffect(() => {
console.log("Use Effect with props:");
console.log(props);
setDayselection(props.lunchdata);
setLunchProfile(props.lunchdata);
}, [props]);

function Emoji(props) {
Expand All @@ -63,39 +64,39 @@ export default function LunchProfileRead(props) {
<ListItem>
<ListItemAvatar>
<Avatar>
<Emoji mood={dayselection.mon} />
<Emoji mood={lunchProfile.mon} />
</Avatar>
</ListItemAvatar>
<ListItemText primary="Montag" />
</ListItem>
<ListItem>
<ListItemAvatar>
<Avatar>
<Emoji mood={dayselection.tue} />
<Emoji mood={lunchProfile.tue} />
</Avatar>
</ListItemAvatar>
<ListItemText primary="Dienstag" />
</ListItem>
<ListItem>
<ListItemAvatar>
<Avatar>
<Emoji mood={dayselection.wed} />
<Emoji mood={lunchProfile.wed} />
</Avatar>
</ListItemAvatar>
<ListItemText primary="Mittwoch" />
</ListItem>
<ListItem>
<ListItemAvatar>
<Avatar>
<Emoji mood={dayselection.thu} />
<Emoji mood={lunchProfile.thu} />
</Avatar>
</ListItemAvatar>
<ListItemText primary="Donnerstag" />
</ListItem>
<ListItem>
<ListItemAvatar>
<Avatar>
<Emoji mood={dayselection.fri} />
<Emoji mood={lunchProfile.fri} />
</Avatar>
</ListItemAvatar>
<ListItemText primary="Freitag" />
Expand Down Expand Up @@ -146,9 +147,13 @@ export default function LunchProfileRead(props) {
</Typography>
<Box component="form" noValidate sx={{ mt: 1 }}>
<DaysTable />
<Impressum sx={{ mt: 5 }} />
<Typography component="subtitle1" variant="subtitle1">
Auf einer Skala von 0-10, wobei 0 nur Privates und 10 nur Arbeit
ist, wäre mein Lieblingsthema eine {lunchProfile.lunchtopic / 10}
</Typography>
</Box>
</Box>
</Box>{" "}
<Impressum sx={{ mt: 5 }} />
</Grid>
</Grid>
);
Expand Down
13 changes: 7 additions & 6 deletions nextjs/mwe/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ model User {
}

model LunchProfile {
id String @id @unique
mon Boolean @default(true)
tue Boolean @default(true)
wed Boolean @default(true)
thu Boolean @default(true)
fri Boolean @default(true)
id String @id @unique
mon Boolean @default(true)
tue Boolean @default(true)
wed Boolean @default(true)
thu Boolean @default(true)
fri Boolean @default(true)
lunchtopic Int @default(50)
user User @relation(fields: [id], references: [private_id])
Expand Down

0 comments on commit 5788bca

Please sign in to comment.