diff --git a/frontend/src/components/StudentCourseEnrollment/StudentCourseEnrollment.vue b/frontend/src/components/StudentCourseEnrollment/StudentCourseEnrollment.vue index c5f16bbc8bde2c0f4d113de578d1e26ce13ea926..3a06a35e66b4a71dd10e51a3e405613b8e79599e 100644 --- a/frontend/src/components/StudentCourseEnrollment/StudentCourseEnrollment.vue +++ b/frontend/src/components/StudentCourseEnrollment/StudentCourseEnrollment.vue @@ -83,6 +83,7 @@ : 'btn-secondary-six' " @click="updateStatus" + :disabled="isZeroCredits" > {{ studyPlanStatus === "DRAFT" @@ -210,7 +211,8 @@ export default { studyPlanId: null, studyPlanStatus: null, notesModal: null, - reasonApproval: null + reasonApproval: null, + isZeroCredits: false }; }, async mounted() { @@ -305,6 +307,9 @@ export default { this.studyPlanId = childResponse.data.id; this.studyPlanStatus = childResponse.data.status; this.studentCourseData = childResponse.data.studyPlanCourses; + if (childResponse.data.studyPlanCourses.length === 0) { + this.isZeroCredits = true; + } this.getCourseClass(); } }) @@ -352,9 +357,12 @@ export default { }, updateStatus() { let status = "DRAFT"; + let studyPlanStatusChild = true; if (this.studyPlanStatus == "DRAFT") { + studyPlanStatusChild = false; status = "SUBMITTED"; } + this.$emit("studyPlanStatusUpdate", studyPlanStatusChild); const requestBody = { status: status }; diff --git a/frontend/src/views/CourseEnrollment/CourseEnrollment.vue b/frontend/src/views/CourseEnrollment/CourseEnrollment.vue index f1679ff916299105af60930cb20ae3c8c9ebdfd3..29b9859c28c30b0fc3ddabeed8a303073c980866 100644 --- a/frontend/src/views/CourseEnrollment/CourseEnrollment.vue +++ b/frontend/src/views/CourseEnrollment/CourseEnrollment.vue @@ -11,7 +11,7 @@ Rencana Studi </h1> </div> - <div class="col-md-3"> + <div v-if="showSelectCourseButton" class="col-md-3"> <div v-if="GetIsStudent()"> <button type="button" @@ -24,7 +24,7 @@ </button> </div> </div> - <div class="col-md-3"> + <div v-if="showSelectCourseButton" class="col-md-3"> <div v-if="GetIsStudent()"> <button type="button" @@ -44,6 +44,7 @@ ></LecturerCourseEnrollment> <StudentCourseEnrollment v-if="role === 'student'" + @studyPlanStatusUpdate="showSelectCourseButton = $event" ></StudentCourseEnrollment> </div> </div> @@ -53,20 +54,24 @@ import Sidebar from "@/components/Sidebar/Sidebar"; import LecturerCourseEnrollment from "../../components/LecturerCourseEnrollment/LecturerCourseEnrollment"; import StudentCourseEnrollment from "../../components/StudentCourseEnrollment/StudentCourseEnrollment"; +import axios from "axios"; export default { components: { Sidebar, LecturerCourseEnrollment, StudentCourseEnrollment }, name: "CourseEnrollment", data() { return { - role: null + semester: "1", + year: 2021, + role: null, + showSelectCourseButton: true }; }, - mounted() { - if (localStorage.uemail.includes("lecturer")) { - this.role = "lecturer"; - } else if (localStorage.uemail.includes("mahasiswa")) { + async mounted() { + if (localStorage.uemail.includes("mahasiswa")) { this.role = "student"; + } else { + this.role = "lecturer"; } }, methods: { @@ -76,10 +81,49 @@ export default { } }, ChangeStatusButton() { - this.$router.push("/course-enrollment"); + this.$router.push("/enrollment-type"); }, SelectCourseButton() { this.$router.push("/select-course"); + }, + async getStudyPlan() { + await axios + .get( + process.env.VUE_APP_API_ENDPOINT + + "/student/" + + localStorage.getItem("uid") + ) + .then((response) => { + if (response.status == 200) { + let params = + "studentId=" + + response.data.id + + "&semester=" + + this.semester + + "&startYear=" + + this.year; + + axios + .get(process.env.VUE_APP_API_ENDPOINT + "/study-plan/?" + params) + .then((childResponse) => { + if (childResponse.status == 200) { + if (childResponse.data.status !== "DRAFT") { + this.showSelectCourseButton = false; + if (childResponse.data.studyPlanCourses.length === 0) { + this.$router.push("/enrollment-type"); + } + } + this.role = "student"; + } + }) + .catch(() => { + this.$router.push("/enrollment-type"); + }); + } + }) + .catch((error) => { + console.error(error); + }); } } }; diff --git a/frontend/src/views/CourseEnrollment/EnrollmentType.vue b/frontend/src/views/CourseEnrollment/EnrollmentType.vue index b65ab4c211144f0a3eb082a492e1ab519f1fe748..7a69a6b84d1b0c5940d1a721b0e1fee5b61ee6cc 100644 --- a/frontend/src/views/CourseEnrollment/EnrollmentType.vue +++ b/frontend/src/views/CourseEnrollment/EnrollmentType.vue @@ -37,10 +37,16 @@ <div class="card-footer bg-transparent "> <button type="button" - class="btn btn-primary-six col-12" + class="btn col-12" + :class=" + studyPlanChoosen === 1 + ? 'btn-disabled-six' + : 'btn-primary-six' + " @click="submitTakeCredits" + :disabled="studyPlanChoosen === 1" > - Pilih + {{ studyPlanChoosen === 1 ? "Sudah Dipilih" : "Pilih" }} </button> </div> </div> @@ -59,10 +65,17 @@ <div class="card-footer bg-transparent "> <button type="button" - class="btn btn-primary-six col-12" + class="btn col-12" + :class=" + studyPlanChoosen === 2 + ? 'btn-secondary-six' + : 'btn-primary-six' + " @click="openZeroCreditsModal" > - Pilih + {{ + studyPlanChoosen === 2 ? "Sudah Diajukan" : "Pilih" + }} </button> </div> </div> @@ -115,10 +128,18 @@ <div class="form-group col-6"> <button type="button" - class="btn btn-primary-six col-12" + class="btn col-12" + :class=" + studyPlanChoosen === 2 + ? 'btn-disabled-six' + : 'btn-primary-six' + " @click="submitZeroCredits" + :disabled="studyPlanChoosen === 2" > - Ajukan + {{ + studyPlanChoosen === 2 ? "Sudah Diajukan" : "Ajukan" + }} </button> </div> </div> @@ -136,16 +157,25 @@ <script> import Sidebar from "@/components/Sidebar/Sidebar"; import { Modal } from "bootstrap"; +import axios from "axios"; export default { components: { Sidebar }, name: "EnrollmentType", data() { return { + semester: "1", + year: 2021, reasonZeroCredits: null, - zeroCreditsModal: null + zeroCreditsModal: null, + studyPlanChoosen: 0, + studyPlanId: null, + studentId: null }; }, + async mounted() { + await this.getStudyPlan(); + }, methods: { openZeroCreditsModal() { this.zeroCreditsModal = new Modal( @@ -157,10 +187,117 @@ export default { this.zeroCreditsModal.hide(); }, submitZeroCredits() { - console.log(this.reasonZeroCredits); + if (this.studyPlanChoosen === 0) { + this.createStudyPlan(2); + } else { + this.updateStudyPlan(2); + } + this.zeroCreditsModal.hide(); }, submitTakeCredits() { - console.log("Saya mengambil mata kuliah"); + if (this.studyPlanChoosen === 0) { + this.createStudyPlan(1); + } else { + this.updateStudyPlan(1); + } + }, + createStudyPlan(type) { + let status = "DRAFT"; + if (type === 2) { + status = "SUBMITTED"; + } + const params = { + studentId: this.studentId, + startYear: this.year, + semester: this.semester, + status: status + }; + + axios + .post(process.env.VUE_APP_API_ENDPOINT + "/study-plan", params) + .then((childResponse) => { + if (childResponse.status == 200) { + if (type === 2) { + this.studyPlanId = childResponse.data.id; + this.studyPlanChoosen = 2; + } else { + this.$router.push("/course-enrollment"); + } + } + }) + .catch((error) => { + console.error(error); + }); + }, + updateStudyPlan(type) { + let status = "SUBMITTED"; + if (type === 1) { + status = "DRAFT"; + } + const params = { + status: status, + studyPlanCourses: [] + }; + + axios + .put( + process.env.VUE_APP_API_ENDPOINT + "/study-plan/" + this.studyPlanId, + params + ) + .then((childResponse) => { + if (childResponse.status == 200) { + if (type === 1) { + this.$router.push("/course-enrollment"); + } else { + this.studyPlanChoosen = 2; + } + } + }) + .catch((error) => { + console.error(error); + }); + }, + async getStudyPlan() { + await axios + .get( + process.env.VUE_APP_API_ENDPOINT + + "/student/" + + localStorage.getItem("uid") + ) + .then((response) => { + if (response.status == 200) { + this.studentId = response.data.id; + let params = + "studentId=" + + response.data.id + + "&semester=" + + this.semester + + "&startYear=" + + this.year; + + axios + .get(process.env.VUE_APP_API_ENDPOINT + "/study-plan/?" + params) + .then((childResponse) => { + if (childResponse.status == 200) { + this.studyPlanId = childResponse.data.id; + if ( + childResponse.data.status === "SUBMITTED" && + childResponse.data.studyPlanCourses.length === 0 + ) { + this.studyPlanChoosen = 2; + } else { + this.studyPlanChoosen = 1; + } + } + }) + .catch(() => { + this.studyPlanChoosen = 0; + }); + } + }) + .catch((error) => { + console.error(error); + }); } } };