express-sweet-generator 2.0.13 → 2.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/client/src/api/ProfileApi.js +11 -0
- package/templates/client/src/api/UserApi.js +36 -0
- package/templates/client/src/login.js +12 -0
- package/templates/client/src/modals/UserModal.js +3 -3
- package/templates/client/src/profile-edit.js +12 -0
- package/templates/client/src/users.js +12 -0
package/package.json
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import Api from '~/shared/Api';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* API client for user profile operations.
|
|
5
|
+
*/
|
|
3
6
|
export default class extends Api {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new instance of this API client.
|
|
9
|
+
*/
|
|
4
10
|
constructor() {
|
|
5
11
|
super('/api/profile');
|
|
6
12
|
}
|
|
7
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Updates the user's profile.
|
|
16
|
+
* @param {FormData} formData The form data containing the updated profile information.
|
|
17
|
+
* @return {Promise<object>} The API response.
|
|
18
|
+
*/
|
|
8
19
|
async updateProfile(formData) {
|
|
9
20
|
return this.client.put('/', formData);
|
|
10
21
|
}
|
|
@@ -1,30 +1,66 @@
|
|
|
1
1
|
import Api from '~/shared/Api';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* API client for user management operations.
|
|
5
|
+
*/
|
|
3
6
|
export default class extends Api {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new instance of this API client.
|
|
9
|
+
*/
|
|
4
10
|
constructor() {
|
|
5
11
|
super('/api/users');
|
|
6
12
|
}
|
|
7
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Logs in a user.
|
|
16
|
+
* @param {FormData} formData The form data containing the user's login credentials.
|
|
17
|
+
* @return {Promise<object>} The API response.
|
|
18
|
+
*/
|
|
8
19
|
async login(formData) {
|
|
9
20
|
return this.client.post('login', formData);
|
|
10
21
|
}
|
|
11
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Logs out the current user.
|
|
25
|
+
* @return {void}
|
|
26
|
+
*/
|
|
12
27
|
async logout() {
|
|
13
28
|
location.assign('/api/users/logout');
|
|
14
29
|
}
|
|
15
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new user.
|
|
33
|
+
* @param {FormData} formData The form data containing the new user's information.
|
|
34
|
+
* @return {Promise<object>} The API response.
|
|
35
|
+
*/
|
|
16
36
|
async createUser(formData) {
|
|
17
37
|
return this.client.post('/', formData);
|
|
18
38
|
}
|
|
19
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves a user by ID.
|
|
42
|
+
* @param {number} userId The ID of the user to retrieve.
|
|
43
|
+
* @return {Promise<object>} The API response.
|
|
44
|
+
*/
|
|
20
45
|
async getUser(userId) {
|
|
21
46
|
return this.client.get(`/${userId}`);
|
|
22
47
|
}
|
|
23
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Updates a user by ID.
|
|
51
|
+
* @param {number} userId The ID of the user to update.
|
|
52
|
+
* @param {FormData} formData - The form data containing the updated user information.
|
|
53
|
+
* @return {Promise<object>} The API response.
|
|
54
|
+
*/
|
|
24
55
|
async updateUser(userId, formData) {
|
|
25
56
|
return this.client.put(`/${userId}`, formData);
|
|
26
57
|
}
|
|
27
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Deletes a user by ID.
|
|
61
|
+
* @param {number} userId The ID of the user to delete.
|
|
62
|
+
* @return {Promise<object>} The API response.
|
|
63
|
+
*/
|
|
28
64
|
async deleteUser(userId) {
|
|
29
65
|
return this.client.delete(`/${userId}`);
|
|
30
66
|
}
|
|
@@ -2,6 +2,9 @@ import {components} from 'metronic-extension';
|
|
|
2
2
|
import UserApi from '~/api/UserApi';
|
|
3
3
|
import '~/login.css';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Initializes form validation.
|
|
7
|
+
*/
|
|
5
8
|
const initValidation = () => {
|
|
6
9
|
validation = new components.Validation(ref.loginForm.get(0), {
|
|
7
10
|
email: {
|
|
@@ -19,6 +22,9 @@ const initValidation = () => {
|
|
|
19
22
|
});
|
|
20
23
|
}
|
|
21
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Handles form events.
|
|
27
|
+
*/
|
|
22
28
|
const handleForm = () => {
|
|
23
29
|
validation.onValid(async () => {
|
|
24
30
|
try {
|
|
@@ -37,7 +43,13 @@ const handleForm = () => {
|
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
const userApi = new UserApi();
|
|
46
|
+
|
|
47
|
+
// Get references to elements with data-ref attributes.
|
|
40
48
|
const ref = components.selectRef();
|
|
49
|
+
|
|
50
|
+
// Initializes form validation.
|
|
41
51
|
let validation;
|
|
42
52
|
initValidation();
|
|
53
|
+
|
|
54
|
+
// Handles form events.
|
|
43
55
|
handleForm();
|
|
@@ -48,10 +48,10 @@ export default class extends components.Modal {
|
|
|
48
48
|
this.#mode = mode;
|
|
49
49
|
this.#userId = userId;
|
|
50
50
|
|
|
51
|
-
// Get elements.
|
|
51
|
+
// Get references to elements with data-ref attributes.
|
|
52
52
|
this.#ref = components.selectRef(super.element);
|
|
53
53
|
|
|
54
|
-
//
|
|
54
|
+
// Initializes form validation.
|
|
55
55
|
this.#initValidation();
|
|
56
56
|
|
|
57
57
|
// Image input component initialization.
|
|
@@ -284,7 +284,7 @@ export default class extends components.Modal {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
/**
|
|
287
|
-
*
|
|
287
|
+
* Initializes form validation.
|
|
288
288
|
*/
|
|
289
289
|
#initValidation() {
|
|
290
290
|
this.#validator = new components.Validation(this.#ref.form.get(0), {
|
|
@@ -3,6 +3,9 @@ import ProfileApi from '~/api/ProfileApi';
|
|
|
3
3
|
import UserApi from '~/api/UserApi';
|
|
4
4
|
import '~/profile-edit.css';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Initializes form validation.
|
|
8
|
+
*/
|
|
6
9
|
const initValidation = () => {
|
|
7
10
|
validation = new components.Validation(ref.profileEditForm.get(0), {
|
|
8
11
|
'user[email]': {
|
|
@@ -44,6 +47,9 @@ const initValidation = () => {
|
|
|
44
47
|
});
|
|
45
48
|
}
|
|
46
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Handles form events.
|
|
52
|
+
*/
|
|
47
53
|
const handleForm = () => {
|
|
48
54
|
validation.onValid(async () => {
|
|
49
55
|
try {
|
|
@@ -99,8 +105,14 @@ const handleForm = () => {
|
|
|
99
105
|
|
|
100
106
|
const profileApi = new ProfileApi();
|
|
101
107
|
const userApi = new UserApi();
|
|
108
|
+
|
|
109
|
+
// Get references to elements with data-ref attributes.
|
|
102
110
|
const ref = components.selectRef('#kt_app_content_container');
|
|
103
111
|
const originalEmail = utils.trim(ref.user.email.val(), true);
|
|
112
|
+
|
|
113
|
+
// Initializes form validation.
|
|
104
114
|
let validation;
|
|
105
115
|
initValidation();
|
|
116
|
+
|
|
117
|
+
// Handles form events.
|
|
106
118
|
handleForm();
|
|
@@ -6,6 +6,9 @@ import UserApi from '~/api/UserApi';
|
|
|
6
6
|
import UserModal from '~/modals/UserModal';
|
|
7
7
|
import '~/users.css';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Initializes the data table.
|
|
11
|
+
*/
|
|
9
12
|
const initDatatable = () => {
|
|
10
13
|
let targetIndex = 0;
|
|
11
14
|
userTable = new Datatable(ref.userTable, {
|
|
@@ -59,6 +62,9 @@ const initDatatable = () => {
|
|
|
59
62
|
});
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Handles form events.
|
|
67
|
+
*/
|
|
62
68
|
const handleForm = () => {
|
|
63
69
|
$('body')
|
|
64
70
|
.on('click', '[data-on-create-user]', async () => {
|
|
@@ -102,7 +108,13 @@ const handleForm = () => {
|
|
|
102
108
|
|
|
103
109
|
const userApi = new UserApi();
|
|
104
110
|
const userModal = new UserModal();
|
|
111
|
+
|
|
112
|
+
// Get references to elements with data-ref attributes.
|
|
105
113
|
const ref = components.selectRef('#kt_app_content_container');
|
|
106
114
|
let userTable;
|
|
115
|
+
|
|
116
|
+
// Initialize the data table.
|
|
107
117
|
initDatatable();
|
|
118
|
+
|
|
119
|
+
// Handles form events.
|
|
108
120
|
handleForm();
|