diff --git a/app/Http/Controllers/SiswaController.php b/app/Http/Controllers/SiswaController.php index 78589d2..a2cd017 100644 --- a/app/Http/Controllers/SiswaController.php +++ b/app/Http/Controllers/SiswaController.php @@ -47,8 +47,11 @@ class SiswaController extends Controller $siswa = Siswa::where('nisn', $request->nisn) ->where('tanggal_lahir', $tanggalLahir) - ->with($request->with) ->first(); + if ($request->with !== null) + $siswa = $siswa->with($request->with); + + $siswa = $siswa->first(); /* * Redirect with error if not found diff --git a/public/js/app.js b/public/js/app.js index e88896a..1e27c32 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -4744,6 +4744,10 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var mithril__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! mithril */ "./node_modules/mithril/mithril.mjs"); /* harmony import */ var _components_SuratKelulusan__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./components/SuratKelulusan */ "./resources/js/components/SuratKelulusan.js"); /* harmony import */ var _components_SKHasilBelajar__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./components/SKHasilBelajar */ "./resources/js/components/SKHasilBelajar.js"); +/* harmony import */ var _models_Siswa__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./models/Siswa */ "./resources/js/models/Siswa.js"); +/* harmony import */ var _models_AccessLog__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./models/AccessLog */ "./resources/js/models/AccessLog.js"); + + @@ -4751,6 +4755,52 @@ mithril__WEBPACK_IMPORTED_MODULE_0__["default"].route.prefix('#'); mithril__WEBPACK_IMPORTED_MODULE_0__["default"].route(document.body.querySelector('.container'), '/', { '/': _components_SuratKelulusan__WEBPACK_IMPORTED_MODULE_1__["default"], '/hasil-belajar': _components_SKHasilBelajar__WEBPACK_IMPORTED_MODULE_2__["default"] +}); // Below is to handle Ctrl+P or MouseR->Print + +window.addEventListener("beforeprint", function () { + if (mithril__WEBPACK_IMPORTED_MODULE_0__["default"].route.get() === '/hasil-belajar') { + // If the print button did not exists, show nothing when printing + if (document.body.querySelector('button.print-button') === null) document.body.style.display = 'none';else { + if (!component.confirmPrint) { + alert('Surat Keterangan ini hanya dapat dicetak satu kali. Lanjutkan?'); + component.confirmPrint = 1; + _models_AccessLog__WEBPACK_IMPORTED_MODULE_4__["default"].create({ + siswaId: _models_Siswa__WEBPACK_IMPORTED_MODULE_3__["default"].current.id, + src: 'sk-hasil-belajar' + }).then(function () { + _models_AccessLog__WEBPACK_IMPORTED_MODULE_4__["default"].fetch('sk-hasil-belajar'); + })["catch"](function (e) { + if (e.code === 0) { + _models_AccessLog__WEBPACK_IMPORTED_MODULE_4__["default"].error = { + message: e.message, + errors: { + create: ['Terjadi kesalahan saat menghubungkan ke server.'] + } + }; + } else { + _models_AccessLog__WEBPACK_IMPORTED_MODULE_4__["default"].error = JSON.parse(e.message); + } + }); + } + } + } +}); +window.addEventListener("afterprint", function () { + if (mithril__WEBPACK_IMPORTED_MODULE_0__["default"].route.get() === '/hasil-belajar') { + // Give back the whole document.body + if (document.body.querySelector('button.print-button') === null) document.body.style.display = 'block'; // Hide the print button + + if (document.body.querySelector('button.print-button') !== null) document.body.querySelector('button.print-button').style.display = 'none'; // To redraw the content to prevent printing + + var nisn = document.body.querySelector('input[name=nisn]').value, + tanggalLahir = document.body.querySelector('input[name=tanggalLahir]').value; + _models_Siswa__WEBPACK_IMPORTED_MODULE_3__["default"].cariData({ + nisn: nisn, + tanggalLahir: tanggalLahir, + src: 'sk-hasil-belajar', + "with": ['hasilBelajar', 'accessLog'] + }); + } }); /***/ }), @@ -4778,7 +4828,7 @@ __webpack_require__.r(__webpack_exports__); var component = { oninit: function oninit() { - _models_AccessLog__WEBPACK_IMPORTED_MODULE_4__["default"].fetch('sk-hasil-belajar'); + _models_Siswa__WEBPACK_IMPORTED_MODULE_3__["default"].current = {}, _models_AccessLog__WEBPACK_IMPORTED_MODULE_4__["default"].fetch('sk-hasil-belajar'); }, namaMapel: { 'agama': 'Pendidikan Agama', @@ -4905,49 +4955,7 @@ var component = { } }))), Object(mithril__WEBPACK_IMPORTED_MODULE_0__["default"])('tr', Object(mithril__WEBPACK_IMPORTED_MODULE_0__["default"])('td', 'Drs. Engkos Kosasih, M.M.'))])])])]; } -}; // Below is to handle Ctrl+P or MouseR->Print - -window.addEventListener("beforeprint", function () { - // If the print button did not exists, show nothing when printing - if (document.body.querySelector('button.print-button') === null) document.body.style.display = 'none';else { - if (!component.confirmPrint) { - alert('Surat Keterangan ini hanya dapat dicetak satu kali. Lanjutkan?'); - component.confirmPrint = 1; - _models_AccessLog__WEBPACK_IMPORTED_MODULE_4__["default"].create({ - siswaId: _models_Siswa__WEBPACK_IMPORTED_MODULE_3__["default"].current.id, - src: 'sk-hasil-belajar' - }).then(function () { - _models_AccessLog__WEBPACK_IMPORTED_MODULE_4__["default"].fetch('sk-hasil-belajar'); - })["catch"](function (e) { - if (e.code === 0) { - _models_AccessLog__WEBPACK_IMPORTED_MODULE_4__["default"].error = { - message: e.message, - errors: { - create: ['Terjadi kesalahan saat menghubungkan ke server.'] - } - }; - } else { - _models_AccessLog__WEBPACK_IMPORTED_MODULE_4__["default"].error = JSON.parse(e.message); - } - }); - } - } -}); -window.addEventListener("afterprint", function () { - // Give back the whole document.body - if (document.body.querySelector('button.print-button') === null) document.body.style.display = 'block'; // Hide the print button - - if (document.body.querySelector('button.print-button') !== null) document.body.querySelector('button.print-button').style.display = 'none'; // To redraw the content to prevent printing - - var nisn = document.body.querySelector('input[name=nisn]').value, - tanggalLahir = document.body.querySelector('input[name=tanggalLahir]').value; - _models_Siswa__WEBPACK_IMPORTED_MODULE_3__["default"].cariData({ - nisn: nisn, - tanggalLahir: tanggalLahir, - src: 'sk-hasil-belajar', - "with": ['hasilBelajar', 'accessLog'] - }); -}); +}; /* harmony default export */ __webpack_exports__["default"] = (component); /***/ }), @@ -4972,6 +4980,7 @@ __webpack_require__.r(__webpack_exports__); var component = { oninit: function oninit() { + _models_Siswa__WEBPACK_IMPORTED_MODULE_2__["default"].current = {}; _models_AccessLog__WEBPACK_IMPORTED_MODULE_3__["default"].fetch('surat-kelulusan'); }, view: function view() { diff --git a/resources/js/app.js b/resources/js/app.js index 39784c4..41dd183 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1,9 +1,65 @@ import m from "mithril" import SuratKelulusan from "./components/SuratKelulusan" import SKHasilBelajar from "./components/SKHasilBelajar" +import Siswa from "./models/Siswa" +import AccessLog from "./models/AccessLog" m.route.prefix('#'); m.route(document.body.querySelector('.container'), '/', { '/': SuratKelulusan, '/hasil-belajar': SKHasilBelajar, }); + +// Below is to handle Ctrl+P or MouseR->Print +window.addEventListener("beforeprint", function () { + if (m.route.get() === '/hasil-belajar') { + // If the print button did not exists, show nothing when printing + if (document.body.querySelector('button.print-button') === null) + document.body.style.display = 'none'; + else { + if (!component.confirmPrint) { + alert('Surat Keterangan ini hanya dapat dicetak satu kali. Lanjutkan?'); + component.confirmPrint = 1; + AccessLog.create({siswaId: Siswa.current.id, src: 'sk-hasil-belajar'}).then(() => { + AccessLog.fetch('sk-hasil-belajar'); + }) + .catch(e => { + if (e.code === 0) { + AccessLog.error = { + message: e.message, + errors: { + create: ['Terjadi kesalahan saat menghubungkan ke server.'], + }, + }; + } + else { + AccessLog.error = JSON.parse(e.message); + } + }); + } + } + } +}); + +window.addEventListener("afterprint", function () { + if (m.route.get() === '/hasil-belajar') { + // Give back the whole document.body + if (document.body.querySelector('button.print-button') === null) + document.body.style.display = 'block'; + + // Hide the print button + if (document.body.querySelector('button.print-button') !== null) + document.body.querySelector('button.print-button').style.display = 'none'; + + // To redraw the content to prevent printing + let nisn = document.body.querySelector('input[name=nisn]').value, + tanggalLahir = document.body.querySelector('input[name=tanggalLahir]').value; + Siswa.cariData({ + nisn, + tanggalLahir, + src: 'sk-hasil-belajar', + with: ['hasilBelajar', 'accessLog'], + }); + } +}); + diff --git a/resources/js/components/SKHasilBelajar.js b/resources/js/components/SKHasilBelajar.js index 4764524..c10891a 100644 --- a/resources/js/components/SKHasilBelajar.js +++ b/resources/js/components/SKHasilBelajar.js @@ -6,6 +6,7 @@ import AccessLog from "../models/AccessLog" var component = { oninit: () => { + Siswa.current = {}, AccessLog.fetch('sk-hasil-belajar'); }, namaMapel: { @@ -350,53 +351,4 @@ var component = { }, }; -// Below is to handle Ctrl+P or MouseR->Print -window.addEventListener("beforeprint", function () { - // If the print button did not exists, show nothing when printing - if (document.body.querySelector('button.print-button') === null) - document.body.style.display = 'none'; - else { - if (!component.confirmPrint) { - alert('Surat Keterangan ini hanya dapat dicetak satu kali. Lanjutkan?'); - component.confirmPrint = 1; - AccessLog.create({siswaId: Siswa.current.id, src: 'sk-hasil-belajar'}).then(() => { - AccessLog.fetch('sk-hasil-belajar'); - }) - .catch(e => { - if (e.code === 0) { - AccessLog.error = { - message: e.message, - errors: { - create: ['Terjadi kesalahan saat menghubungkan ke server.'], - }, - }; - } - else { - AccessLog.error = JSON.parse(e.message); - } - }); - } - } -}); - -window.addEventListener("afterprint", function () { - // Give back the whole document.body - if (document.body.querySelector('button.print-button') === null) - document.body.style.display = 'block'; - - // Hide the print button - if (document.body.querySelector('button.print-button') !== null) - document.body.querySelector('button.print-button').style.display = 'none'; - - // To redraw the content to prevent printing - let nisn = document.body.querySelector('input[name=nisn]').value, - tanggalLahir = document.body.querySelector('input[name=tanggalLahir]').value; - Siswa.cariData({ - nisn, - tanggalLahir, - src: 'sk-hasil-belajar', - with: ['hasilBelajar', 'accessLog'], - }); -}); - export default component; diff --git a/resources/js/components/SuratKelulusan.js b/resources/js/components/SuratKelulusan.js index 2d852ed..54a67ce 100644 --- a/resources/js/components/SuratKelulusan.js +++ b/resources/js/components/SuratKelulusan.js @@ -5,6 +5,7 @@ import AccessLog from "../models/AccessLog" var component = { oninit: () => { + Siswa.current = {}; AccessLog.fetch('surat-kelulusan'); }, view: () => {