| @@ -599,254 +599,8 @@ | ||
| 599 | 599 | /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (getStepsUpgradeStatus); |
| 600 | 600 | |
| 601 | 601 | /***/ }, |
| 602 | 602 | |
| 603 | -/***/ "./assets/src/apps/js/admin/pages/tools/reset-data/course.js" | |
| 604 | -/*!*******************************************************************!*\ | |
| 605 | - !*** ./assets/src/apps/js/admin/pages/tools/reset-data/course.js ***! | |
| 606 | - \*******************************************************************/ | |
| 607 | -(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 608 | - | |
| 609 | -__webpack_require__.r(__webpack_exports__); | |
| 610 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 611 | -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) | |
| 612 | -/* harmony export */ }); | |
| 613 | -/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); | |
| 614 | -/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | |
| 615 | - | |
| 616 | -/** | |
| 617 | - * Reset course progress. | |
| 618 | - * | |
| 619 | - * @since 4.0.5. | |
| 620 | - * @author Nhamdv - Code choi choi in Physcode. | |
| 621 | - */ | |
| 622 | -const { | |
| 623 | - __ | |
| 624 | -} = wp.i18n; | |
| 625 | -const { | |
| 626 | - TextControl, | |
| 627 | - Button, | |
| 628 | - Spinner, | |
| 629 | - CheckboxControl, | |
| 630 | - Notice | |
| 631 | -} = wp.components; | |
| 632 | -const { | |
| 633 | - useState, | |
| 634 | - useEffect | |
| 635 | -} = wp.element; | |
| 636 | -const { | |
| 637 | - addQueryArgs | |
| 638 | -} = wp.url; | |
| 639 | -const ResetCourse = () => { | |
| 640 | - const [loading, setLoading] = useState(false); | |
| 641 | - const [search, setSearch] = useState(''); | |
| 642 | - const [data, setData] = useState([]); | |
| 643 | - const [checkData, setCheckData] = useState([]); | |
| 644 | - const [message, setMessage] = useState([]); | |
| 645 | - const [loadingReset, setLoadingReset] = useState(false); | |
| 646 | - useEffect(() => { | |
| 647 | - responsiveData(search); | |
| 648 | - }, [search]); | |
| 649 | - const responsiveData = async s => { | |
| 650 | - try { | |
| 651 | - if (!s || loading) { | |
| 652 | - setMessage([]); | |
| 653 | - setData([]); | |
| 654 | - return; | |
| 655 | - } | |
| 656 | - if (s.length < 3) { | |
| 657 | - setMessage([{ | |
| 658 | - status: 'error', | |
| 659 | - message: 'Please enter at least 3 characters to searching course.' | |
| 660 | - }]); | |
| 661 | - setData([]); | |
| 662 | - return; | |
| 663 | - } | |
| 664 | - setLoading(true); | |
| 665 | - const response = await wp.apiFetch({ | |
| 666 | - path: addQueryArgs('lp/v1/admin/tools/reset-data/search-courses', { | |
| 667 | - s | |
| 668 | - }), | |
| 669 | - method: 'GET' | |
| 670 | - }); | |
| 671 | - const { | |
| 672 | - status, | |
| 673 | - data | |
| 674 | - } = response; | |
| 675 | - setLoading(false); | |
| 676 | - if (status === 'success') { | |
| 677 | - setData(data); | |
| 678 | - setMessage([]); | |
| 679 | - } else { | |
| 680 | - setMessage([{ | |
| 681 | - status: 'error', | |
| 682 | - message: response.message || 'LearnPress: Search Course Fail!' | |
| 683 | - }]); | |
| 684 | - setData([]); | |
| 685 | - } | |
| 686 | - } catch (error) { | |
| 687 | - console.log(error.message); | |
| 688 | - } | |
| 689 | - }; | |
| 690 | - function checkItems(id) { | |
| 691 | - const datas = [...checkData]; | |
| 692 | - if (datas.includes(id)) { | |
| 693 | - const index = datas.indexOf(id); | |
| 694 | - if (index > -1) { | |
| 695 | - datas.splice(index, 1); | |
| 696 | - } | |
| 697 | - } else { | |
| 698 | - datas.push(id); | |
| 699 | - } | |
| 700 | - setCheckData(datas); | |
| 701 | - } | |
| 702 | - const resetCourse = async () => { | |
| 703 | - if (checkData.length === 0) { | |
| 704 | - setMessage([{ | |
| 705 | - status: 'error', | |
| 706 | - message: 'Please chooce Course for reset data!' | |
| 707 | - }]); | |
| 708 | - return; | |
| 709 | - } | |
| 710 | - | |
| 711 | - // eslint-disable-next-line no-alert | |
| 712 | - if (!confirm('Are you sure to reset course progress of all users enrolled this course?')) { | |
| 713 | - return; | |
| 714 | - } | |
| 715 | - const notice = []; | |
| 716 | - try { | |
| 717 | - setLoadingReset(true); | |
| 718 | - for (const courseId of checkData) { | |
| 719 | - const response = await wp.apiFetch({ | |
| 720 | - path: addQueryArgs('lp/v1/admin/tools/reset-data/reset-courses', { | |
| 721 | - courseId | |
| 722 | - }), | |
| 723 | - method: 'GET' | |
| 724 | - }); | |
| 725 | - const { | |
| 726 | - status, | |
| 727 | - data, | |
| 728 | - message | |
| 729 | - } = response; | |
| 730 | - notice.push({ | |
| 731 | - status, | |
| 732 | - message: message || `Course #${courseId} reset successfully!` | |
| 733 | - }); | |
| 734 | - } | |
| 735 | - setLoadingReset(false); | |
| 736 | - } catch (error) { | |
| 737 | - notice.push({ | |
| 738 | - status: 'error', | |
| 739 | - message: error.message || `LearnPress Error: Reset Course Data.` | |
| 740 | - }); | |
| 741 | - } | |
| 742 | - setMessage(notice); | |
| 743 | - }; | |
| 744 | - return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("h2", null, __('Reset Course Progress', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { | |
| 745 | - className: "description" | |
| 746 | - }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, __('This action will reset course progress of all users who have enrolled.', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, __('Search results only show if courses have user data.', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(TextControl, { | |
| 747 | - placeholder: __('Search course by name', 'learnpress'), | |
| 748 | - value: search, | |
| 749 | - onChange: value => setSearch(value), | |
| 750 | - style: { | |
| 751 | - width: 300 | |
| 752 | - } | |
| 753 | - }))), loading && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(Spinner, null), data.length > 0 && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { | |
| 754 | - className: "lp-reset-course_progress", | |
| 755 | - style: { | |
| 756 | - border: '1px solid #eee' | |
| 757 | - } | |
| 758 | - }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { | |
| 759 | - style: { | |
| 760 | - background: '#eee' | |
| 761 | - } | |
| 762 | - }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(CheckboxControl, { | |
| 763 | - checked: checkData.length === data.length, | |
| 764 | - onChange: () => { | |
| 765 | - if (checkData.length === data.length) { | |
| 766 | - setCheckData([]); | |
| 767 | - } else { | |
| 768 | - setCheckData(data.map(dt => dt.id)); | |
| 769 | - } | |
| 770 | - }, | |
| 771 | - style: { | |
| 772 | - margin: 0 | |
| 773 | - } | |
| 774 | - })), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, __('ID', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, __('Name', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, __('Students', 'learnpress')))), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { | |
| 775 | - style: { | |
| 776 | - height: '100%', | |
| 777 | - maxHeight: 200, | |
| 778 | - overflow: 'auto' | |
| 779 | - } | |
| 780 | - }, data.map(dt => { | |
| 781 | - return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { | |
| 782 | - style: { | |
| 783 | - borderTop: '1px solid #eee' | |
| 784 | - }, | |
| 785 | - key: dt.id | |
| 786 | - }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(CheckboxControl, { | |
| 787 | - checked: checkData.includes(dt.id), | |
| 788 | - onChange: () => checkItems(dt.id) | |
| 789 | - })), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, "#", dt.id), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, dt.title), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, dt.students)); | |
| 790 | - }))), loadingReset ? (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(Spinner, null) : (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(Button, { | |
| 791 | - isPrimary: true, | |
| 792 | - onClick: () => resetCourse(), | |
| 793 | - style: { | |
| 794 | - marginTop: 10, | |
| 795 | - height: 30 | |
| 796 | - } | |
| 797 | - }, __('Reset now', 'learnpress'))), message.length > 0 && message.map((mess, index) => { | |
| 798 | - return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(Notice, { | |
| 799 | - status: mess.status, | |
| 800 | - key: index, | |
| 801 | - isDismissible: false | |
| 802 | - }, mess.message); | |
| 803 | - }), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("style", null, '\ | |
| 804 | - .lp-reset-course_progress .components-base-control__field {\ | |
| 805 | - margin: 0;\ | |
| 806 | - }\ | |
| 807 | - .components-notice{\ | |
| 808 | - margin-left: 0;\ | |
| 809 | - }\ | |
| 810 | - .lp-reset-course_progress > div > div{\ | |
| 811 | - display: grid;\ | |
| 812 | - grid-template-columns: 80px 50px 1fr 80px;\ | |
| 813 | - align-items: center;\ | |
| 814 | - }\ | |
| 815 | - .lp-reset-course_progress > div > div > div{\ | |
| 816 | - maegin: 0;\ | |
| 817 | - padding: 8px 10px;\ | |
| 818 | - }\ | |
| 819 | - ')); | |
| 820 | -}; | |
| 821 | -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ResetCourse); | |
| 822 | - | |
| 823 | -/***/ }, | |
| 824 | - | |
| 825 | -/***/ "./assets/src/apps/js/admin/pages/tools/reset-data/index.js" | |
| 826 | -/*!******************************************************************!*\ | |
| 827 | - !*** ./assets/src/apps/js/admin/pages/tools/reset-data/index.js ***! | |
| 828 | - \******************************************************************/ | |
| 829 | -(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 830 | - | |
| 831 | -__webpack_require__.r(__webpack_exports__); | |
| 832 | -/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 833 | -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) | |
| 834 | -/* harmony export */ }); | |
| 835 | -/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); | |
| 836 | -/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | |
| 837 | -/* harmony import */ var _course__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./course */ "./assets/src/apps/js/admin/pages/tools/reset-data/course.js"); | |
| 838 | - | |
| 839 | - | |
| 840 | -const resetData = () => { | |
| 841 | - if (document.querySelectorAll('#learn-press-reset-course-users').length > 0) { | |
| 842 | - wp.element.render((0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_course__WEBPACK_IMPORTED_MODULE_1__["default"], null), [...document.querySelectorAll('#learn-press-reset-course-users')][0]); | |
| 843 | - } | |
| 844 | -}; | |
| 845 | -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (resetData); | |
| 846 | - | |
| 847 | -/***/ }, | |
| 848 | - | |
| 849 | 603 | /***/ "./assets/src/apps/js/utils/handle-ajax-api.js" |
| 850 | 604 | /*!*****************************************************!*\ |
| 851 | 605 | !*** ./assets/src/apps/js/utils/handle-ajax-api.js ***! |
| 852 | 606 | \*****************************************************/ |
| @@ -942,18 +696,8 @@ | ||
| 942 | 696 | } |
| 943 | 697 | }; |
| 944 | 698 | /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (lpModalOverlay); |
| 945 | 699 | |
| 946 | -/***/ }, | |
| 947 | - | |
| 948 | -/***/ "react" | |
| 949 | -/*!************************!*\ | |
| 950 | - !*** external "React" ***! | |
| 951 | - \************************/ | |
| 952 | -(module) { | |
| 953 | - | |
| 954 | -module.exports = window["React"]; | |
| 955 | - | |
| 956 | 700 | /***/ } |
| 957 | 701 | |
| 958 | 702 | /******/ }); |
| 959 | 703 | /************************************************************************/ |
| @@ -987,20 +731,8 @@ | ||
| 987 | 731 | /******/ return module.exports; |
| 988 | 732 | /******/ } |
| 989 | 733 | /******/ |
| 990 | 734 | /************************************************************************/ |
| 991 | -/******/ /* webpack/runtime/compat get default export */ | |
| 992 | -/******/ (() => { | |
| 993 | -/******/ // getDefaultExport function for compatibility with non-harmony modules | |
| 994 | -/******/ __webpack_require__.n = (module) => { | |
| 995 | -/******/ var getter = module && module.__esModule ? | |
| 996 | -/******/ () => (module['default']) : | |
| 997 | -/******/ () => (module); | |
| 998 | -/******/ __webpack_require__.d(getter, { a: getter }); | |
| 999 | -/******/ return getter; | |
| 1000 | -/******/ }; | |
| 1001 | -/******/ })(); | |
| 1002 | -/******/ | |
| 1003 | 735 | /******/ /* webpack/runtime/define property getters */ |
| 1004 | 736 | /******/ (() => { |
| 1005 | 737 | /******/ // define getter functions for harmony exports |
| 1006 | 738 | /******/ __webpack_require__.d = (exports, definition) => { |
| @@ -1039,70 +771,14 @@ | ||
| 1039 | 771 | /* harmony import */ var _tools_database_upgrade__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./tools/database/upgrade */ "./assets/src/apps/js/admin/pages/tools/database/upgrade.js"); |
| 1040 | 772 | /* harmony import */ var _tools_database_create_indexs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./tools/database/create_indexs */ "./assets/src/apps/js/admin/pages/tools/database/create_indexs.js"); |
| 1041 | 773 | /* harmony import */ var _tools_database_re_upgrade_db__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./tools/database/re-upgrade-db */ "./assets/src/apps/js/admin/pages/tools/database/re-upgrade-db.js"); |
| 1042 | 774 | /* harmony import */ var _tools_database_clean_database__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./tools/database/clean_database */ "./assets/src/apps/js/admin/pages/tools/database/clean_database.js"); |
| 1043 | -/* harmony import */ var _tools_reset_data__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./tools/reset-data */ "./assets/src/apps/js/admin/pages/tools/reset-data/index.js"); | |
| 1044 | 775 | |
| 1045 | 776 | |
| 1046 | 777 | |
| 1047 | 778 | |
| 1048 | - | |
| 1049 | 779 | (function ($) { |
| 1050 | 780 | const $doc = $(document); |
| 1051 | - let isRunning = false; | |
| 1052 | - const installSampleCourse = function installSampleCourse(e) { | |
| 1053 | - e.preventDefault(); | |
| 1054 | - const $button = $(this); | |
| 1055 | - if (isRunning) { | |
| 1056 | - return; | |
| 1057 | - } | |
| 1058 | - if (!confirm(lpGlobalSettings.i18n.confirm_install_sample_data)) { | |
| 1059 | - return; | |
| 1060 | - } | |
| 1061 | - $button.addClass('disabled').html($button.data('installing-text')); | |
| 1062 | - $('.lp-install-sample__response').remove(); | |
| 1063 | - isRunning = true; | |
| 1064 | - $.ajax({ | |
| 1065 | - method: 'POST', | |
| 1066 | - url: $button.attr('href'), | |
| 1067 | - data: $('.lp-install-sample__options').serializeJSON(), | |
| 1068 | - success(response) { | |
| 1069 | - $button.removeClass('disabled').html($button.data('text')); | |
| 1070 | - isRunning = false; | |
| 1071 | - $(response).insertBefore($button.parent()); | |
| 1072 | - }, | |
| 1073 | - error() { | |
| 1074 | - $button.removeClass('disabled').html($button.data('text')); | |
| 1075 | - isRunning = false; | |
| 1076 | - $(response).insertBefore($button.parent()); | |
| 1077 | - } | |
| 1078 | - }); | |
| 1079 | - }; | |
| 1080 | - const uninstallSampleCourse = function uninstallSampleCourse(e) { | |
| 1081 | - e.preventDefault(); | |
| 1082 | - const $button = $(this); | |
| 1083 | - if (isRunning) { | |
| 1084 | - return; | |
| 1085 | - } | |
| 1086 | - if (!confirm(lpGlobalSettings.i18n.confirm_uninstall_sample_data)) { | |
| 1087 | - return; | |
| 1088 | - } | |
| 1089 | - $button.addClass('disabled').html($button.data('uninstalling-text')); | |
| 1090 | - isRunning = true; | |
| 1091 | - $.ajax({ | |
| 1092 | - url: $button.attr('href'), | |
| 1093 | - success(response) { | |
| 1094 | - $button.removeClass('disabled').html($button.data('text')); | |
| 1095 | - isRunning = false; | |
| 1096 | - $(response).insertBefore($button.parent()); | |
| 1097 | - }, | |
| 1098 | - error() { | |
| 1099 | - $button.removeClass('disabled').html($button.data('text')); | |
| 1100 | - isRunning = false; | |
| 1101 | - $(response).insertBefore($button.parent()); | |
| 1102 | - } | |
| 1103 | - }); | |
| 1104 | - }; | |
| 1105 | 781 | const clearHardCache = function clearHardCache(e) { |
| 1106 | 782 | e.preventDefault(); |
| 1107 | 783 | const $button = $(this); |
| 1108 | 784 | if ($button.hasClass('disabled')) { |
| @@ -1129,31 +805,14 @@ | ||
| 1129 | 805 | success(response) {}, |
| 1130 | 806 | error() {} |
| 1131 | 807 | }); |
| 1132 | 808 | }; |
| 1133 | - const toggleOptions = function toggleOptions(e) { | |
| 1134 | - e.preventDefault(); | |
| 1135 | - $('.lp-install-sample__options').toggleClass('hide-if-js'); | |
| 1136 | - }; | |
| 1137 | - const formatValueInput = e => { | |
| 1138 | - const input = $(e.target); | |
| 1139 | - let value = input.val(); | |
| 1140 | - value = value.replace(/[^0-9]/g, ''); | |
| 1141 | - input.val(value); | |
| 1142 | - if (parseInt(value, 10) < input.attr('min')) { | |
| 1143 | - input.val(input.attr('min')); | |
| 1144 | - } | |
| 1145 | - if (parseInt(value, 10) > input.attr('max')) { | |
| 1146 | - input.val(input.attr('max')); | |
| 1147 | - } | |
| 1148 | - }; | |
| 1149 | 809 | $(function () { |
| 1150 | 810 | (0,_tools_database_upgrade__WEBPACK_IMPORTED_MODULE_0__["default"])(); |
| 1151 | 811 | (0,_tools_database_create_indexs__WEBPACK_IMPORTED_MODULE_1__["default"])(); |
| 1152 | 812 | (0,_tools_database_re_upgrade_db__WEBPACK_IMPORTED_MODULE_2__["default"])(); |
| 1153 | - (0,_tools_reset_data__WEBPACK_IMPORTED_MODULE_4__["default"])(); | |
| 1154 | 813 | (0,_tools_database_clean_database__WEBPACK_IMPORTED_MODULE_3__["default"])(); |
| 1155 | - $doc.on('click', '.lp-install-sample__install', installSampleCourse).on('click', '.lp-install-sample__uninstall', uninstallSampleCourse).on('click', '#learn-press-clear-cache', clearHardCache).on('click', 'input[name="enable_hard_cache"]', toggleHardCache).on('click', '.lp-install-sample__toggle-options', toggleOptions).on('change', 'input[name="section-range[]"]', formatValueInput).on('change', 'input[name="item-range[]"]', formatValueInput).on('change', 'input[name="question-range[]"]', formatValueInput).on('change', 'input[name="answer-range[]"]', formatValueInput).on('change', 'input[name="course-price"]', formatValueInput); | |
| 814 | + $doc.on('click', '#learn-press-clear-cache', clearHardCache).on('click', 'input[name="enable_hard_cache"]', toggleHardCache); | |
| 1156 | 815 | }); |
| 1157 | 816 | })(jQuery); |
| 1158 | 817 | })(); |
| 1159 | 818 | |