Skip to content

Commit

Permalink
made it possible to change appointment leader
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonf committed Oct 29, 2024
1 parent 2a8089d commit 38ea20e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 18 deletions.
3 changes: 2 additions & 1 deletion babex-vue/src/components/agenda/AgendaCalendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@
title: event.participant.name,
location: event.location,
// extra field will be displayed in a separate line
extra: `${icon} ${event.location} (${event.leader})`,
extra: `${icon} ${event.location} (${event.leader.name})`,
display: 'block',
category: 'appointment',
comment: event.comment,
outcome: event.outcome,
experiment: event.experiment,
participant: event.participant,
leader: event.leader,
color: eventColor(event),
};
}
Expand Down
39 changes: 28 additions & 11 deletions babex-vue/src/components/agenda/AppointmentForm.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script lang="ts" setup>
import {defineEmits, defineProps, ref} from 'vue';
import {babexApi} from '../../api';
import {Location} from '../../types';
import { _ } from '@/util';
import DateTimePicker from '../DateTimePicker.vue';
const props = defineProps<{
locations: {id: number, name: string}[],
locations: Location[],
// eslint-disable-next-line
event: any,
comment?: string,
Expand All @@ -20,6 +21,7 @@
end: props.event.end,
comment: props.event ? props.event.extendedProps.comment : null,
location: props.event.extendedProps.location,
leader: props.event.extendedProps.leader,
outcome: props.event.extendedProps.outcome ?? undefined,
});
Expand All @@ -37,7 +39,7 @@
if (isPast()) {
// when the appointment is in the past, we only allow adding a comment and
// setting the outcome value
let update = {comment:form.value.comment, outcome: form.value.outcome};
let update = {comment:form.value.comment, outcome: form.value.outcome, leader: form.value.leader};
promise = babexApi.agenda.appointment.updatePartial(props.event.id, update);
}
else {
Expand All @@ -63,17 +65,32 @@
<template>
<div class="mt-4 mb-4">
<div>
<strong>{{ _('Participant:') }}</strong>&nbsp;
<a :href="'/participants/' + event.extendedProps.participant.id">
{{event.extendedProps.participant.name}}
</a>
<strong>{{ _('Participant:') }}</strong>
<div>
<a :href="'/participants/' + event.extendedProps.participant.id">
{{event.extendedProps.participant.name}}
</a>
</div>
</div>
<div>
<strong>{{ _('Experiment:') }}</strong>&nbsp;
<div>
<a :href="'/experiments/' + event.extendedProps.experiment.id">
{{event.extendedProps.experiment.name}}
</a>
</div>
</div>
<div><strong>{{ _('Experiment:') }}</strong>&nbsp;
<a :href="'/experiments/' + event.extendedProps.experiment.id">
{{event.extendedProps.experiment.name}}
</a>
<div>
<strong>{{ _('Location:') }}</strong>
<div>{{form.location}}</div>
</div>
<div>
<strong>{{ _('Leader:') }}</strong>
<select class="form-select" v-model="form.leader">
<option v-for="leader in event.extendedProps.experiment.leaders"
:key="leader.id" :value="leader">{{ leader.name }}</option>
</select>
</div>
<div><strong>{{ _('Location:') }}</strong> {{form.location}}</div>
</div>
<form @submit="onSubmit">
<div>{{ _('From:') }}</div>
Expand Down
10 changes: 9 additions & 1 deletion babex-vue/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Appointment {
comment: string
experiment?: string,
leader?: string,
leader_id?: number,
outcome?: string,
}

Expand All @@ -28,6 +29,11 @@ interface Location {
name: string
}

interface Leader {
id: number,
name: string
}

interface Call {
id?: number,
experiment?: number,
Expand All @@ -41,6 +47,8 @@ interface ActionContext {
type?: string,
event?: Dictionary,
locations?: Location[],
leaders?: Leader[],
leader?: Leader,

start?: Date,
end?: Date
Expand All @@ -65,4 +73,4 @@ interface Response {
value?: any;
}

export {Appointment, Closing, Location, Call, ActionContext, User, Question, Response};
export {Appointment, Closing, Location, Call, ActionContext, User, Question, Response, Leader};
6 changes: 3 additions & 3 deletions lab/agenda/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class AppointmentFeed(RandomLeaderMixin, generics.ListAPIView):
def get_queryset(self):
from_date = dateutil.parser.parse(self.request.GET["start"])
to_date = dateutil.parser.parse(self.request.GET["end"])

# the experiment parameter is used to retrieve a feed that's relevant for a given experiment
# practically, that means appointments of any experiement taking place at the relevant location
experiment_id = self.request.GET.get("experiment")
appointments = Appointment.objects.filter(timeslot__start__gte=from_date, timeslot__end__lt=to_date)
if experiment_id:
experiment = Experiment.objects.get(pk=experiment_id)
appointments = appointments.filter(experiment__location=experiment.location)
return appointments
return appointments


class AgendaHome(RandomLeaderMixin, generic.TemplateView):
Expand Down Expand Up @@ -56,7 +56,7 @@ def get_queryset(self):
if self.request.method == "GET":
from_date = dateutil.parser.parse(self.request.GET["start"])
to_date = dateutil.parser.parse(self.request.GET["end"])

# the experiment parameter is used to retrieve a feed that's relevant for a given experiment
# practically, that means closings of the relevant location, or the entire building
experiment_id = self.request.GET.get("experiment")
Expand Down
24 changes: 22 additions & 2 deletions lab/experiments/serializers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
from rest_framework import serializers

from participants.models import Participant
from main.models import User
from .models import Appointment, Experiment


class ExperimentLeadersSerializer(serializers.ModelSerializer):
id = serializers.IntegerField()

class Meta:
model = User
fields = ["id", "name"]


class AppointmentSerializer(serializers.ModelSerializer):
class AppointmentExperimentSerializer(serializers.ModelSerializer):
class Meta:
model = Experiment
fields = ["id", "name"]
fields = ["id", "name", "leaders"]

leaders = ExperimentLeadersSerializer(read_only=True, many=True)

class AppointmentParticipantSerializer(serializers.ModelSerializer):
class Meta:
Expand All @@ -21,6 +32,7 @@ class Meta:
"id",
"experiment",
"leader",
"leader_id",
"participant",
"location",
"start",
Expand All @@ -35,7 +47,7 @@ class Meta:
participant = AppointmentParticipantSerializer(read_only=True)

location = serializers.ReadOnlyField()
leader = serializers.ReadOnlyField(source="leader.name")
leader = ExperimentLeadersSerializer()

contact_phone = serializers.ReadOnlyField(source="leader.phonenumber")

Expand All @@ -44,6 +56,14 @@ class Meta:

session_duration = serializers.ReadOnlyField(source="experiment.session_duration")

def update(self, instance, validated_data):
if "leader" in validated_data:
leader = User.objects.get(pk=validated_data["leader"]["id"])
if leader in instance.experiment.leaders.all():
instance.leader = leader
instance.save()
return instance


class ExperimentSerializer(serializers.ModelSerializer):
class Meta:
Expand Down

0 comments on commit 38ea20e

Please sign in to comment.