Skip to content
Snippets Groups Projects
Commit 1d13e9f6 authored by Julian's avatar Julian
Browse files

Create grades

parent c727ca51
No related branches found
No related tags found
2 merge requests!3Draft: Resolve "Implement shared secret mechanism",!2Frontend
......@@ -67,6 +67,7 @@ export default {
:effort="effort"
:person-id="item.id"
:value="effort.grades.find(grade => grade.person.id === item.id)"
:affected-query="$apollo.queries.efforts"
/>
<grade-chip v-else :grade="effort.grades.find(grade => grade.person.id === item.id)" />
</template>
......
<script>
import ChipSelectField from "aleksis.core/components/generic/forms/ChipSelectField.vue";
import { createGrades } from "./grades.graphql";
import mutateMixin from "aleksis.core/mixins/mutateMixin.js";
export default {
name: "UpdateOrCreateGrade",
components: { ChipSelectField },
mixins: [mutateMixin],
props: {
personId: {
type: [String, Number],
......@@ -24,6 +26,14 @@ export default {
type: Boolean,
default: true,
},
/**
* Override prop default value from mutateMixin
*/
gqlDataKey: {
type: String,
required: false,
default: "efforts",
},
},
computed: {
items() {
......@@ -32,6 +42,43 @@ export default {
name: this.effort.gradeSet.name,
}].concat(this.effort.gradeSet.gradeChoices.sort((a, b) => a.order - b.order));
}
},
selectedGrade: {
get() {
return this.value?.grade;
},
set(newValue) {
// TODO
if (this.value) {
// → Preexisting grade, edit mutation
} else {
// Create and return a grade object
this.mutate(
createGrades,
{
input: [{
person: this.personId,
effort: this.effort.id,
grade: newValue,
}],
},
(storedEfforts, incomingGrades) => {
console.log("foo");
console.log(storedEfforts, incomingGrades);
const effort = storedEfforts.find(
(effort) => effort.id === this.effort.id,
);
incomingGrades.forEach((newGrade) => {
effort.grades.push(newGrade)
});
return storedEfforts;
},
);
}
}
},
},
}
</script>
......@@ -49,4 +96,5 @@ export default {
hide-details
dense
/>
v-model="selectedGrade"
</template>
query grades($orderBy: [String], $filters: JSONString) {
items: grades(orderBy: $orderBy, filters: $filters) {
id
person {
id
}
grade {
id
name
value
}
effort {
id
}
canEdit
canDelete
}
}
mutation createGrades($input: [BatchCreateGradeInput]!) {
createGrades(input: $input) {
items: grades {
id
person {
id
}
grade {
id
name
value
}
effort {
id
}
canEdit
canDelete
}
}
}
mutation deleteGrades($ids: [ID]!) {
deleteGrades(ids: $ids) {
deletionCount
}
}
mutation updateGrades($input: [BatchPatchGradeInput]!) {
updateGrades(input: $input) {
items: grades {
id
person {
id
}
grade {
id
name
value
}
effort {
id
}
canEdit
canDelete
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment