quar 1.4.0 → 1.4.2
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/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.github/workflows/publish.yaml +50 -0
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -21
- package/README.md +96 -95
- package/dummy_models/posts.model.js +52 -52
- package/dummy_models/user.model.js +44 -44
- package/package.json +10 -3
- package/public/scripts/insertTab.js +155 -155
- package/public/scripts/keyboardCommands.js +15 -15
- package/public/scripts/main.js +364 -364
- package/public/scripts/popup.js +25 -25
- package/public/styles/insertTab.css +73 -73
- package/public/styles/popup.css +70 -70
- package/public/styles/sidebar.css +33 -33
- package/public/styles/style.css +306 -306
- package/public/styles/variables.css +8 -8
- package/server.js +241 -241
- package/utils/loadModels.js +26 -26
- package/views/base.zare +16 -16
- package/views/components/insertTab.zare +7 -7
- package/views/components/popup.zare +11 -11
- package/views/components/sidebar.zare +11 -11
- package/views/pages/index.zare +48 -48
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
async function toggleInsertTab() {
|
|
2
|
-
const modelName = content.dataset?.modelName;
|
|
3
|
-
if (!modelName) {
|
|
4
|
-
showModal('error', 'Error Occurred!', 'No model selected.');
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const insertTab = document.querySelector('.insert-tab');
|
|
9
|
-
insertTab.classList.toggle('active');
|
|
10
|
-
|
|
11
|
-
if (insertTab.innerHTML.trim() !== '') return;
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const res = await fetch(`/schema/${modelName}`);
|
|
15
|
-
if (!res.ok) throw new Error();
|
|
16
|
-
|
|
17
|
-
const schema = await res.json();
|
|
18
|
-
|
|
19
|
-
const form = document.createElement('form');
|
|
20
|
-
form.id = 'insert-form';
|
|
21
|
-
|
|
22
|
-
form.addEventListener('submit', async (e) => {
|
|
23
|
-
e.preventDefault();
|
|
24
|
-
|
|
25
|
-
const formData = new FormData(e.target);
|
|
26
|
-
const data = Object.fromEntries(formData.entries());
|
|
27
|
-
|
|
28
|
-
const checkboxes = e.target.querySelectorAll('input[type="checkbox"]');
|
|
29
|
-
checkboxes.forEach(cb => {
|
|
30
|
-
data[cb.name] = cb.checked;
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const textareas = e.target.querySelectorAll('textarea');
|
|
34
|
-
textareas.forEach(async tarea => {
|
|
35
|
-
|
|
36
|
-
data[tarea.name] = JSON.parse(tarea.value)
|
|
37
|
-
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
const res = await fetch(`/insert/${modelName}`, {
|
|
41
|
-
method: 'POST',
|
|
42
|
-
headers: { 'Content-Type': 'application/json' },
|
|
43
|
-
body: JSON.stringify(data)
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
if (!res.ok) {
|
|
47
|
-
const error = await res.json();
|
|
48
|
-
showModal('error', 'Error Occurred!', error.error || 'Something went wrong, please try again.');
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
loadDocuments();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
for (const key in schema) {
|
|
57
|
-
|
|
58
|
-
if (/\.\$\*$/.test(key)) continue;
|
|
59
|
-
const field = schema[key];
|
|
60
|
-
let inputType = null;
|
|
61
|
-
|
|
62
|
-
const label = document.createElement('label');
|
|
63
|
-
label.innerHTML = `${key}:`;
|
|
64
|
-
label.className = 'label';
|
|
65
|
-
label.htmlFor = key;
|
|
66
|
-
|
|
67
|
-
if (field.type === 'ObjectId') {
|
|
68
|
-
const idRes = await fetch(`/id/${field.ref}`);
|
|
69
|
-
if (!idRes.ok) {
|
|
70
|
-
const error = await idRes.json();
|
|
71
|
-
showModal('error', 'Error Occurred!', error.error || 'Something went wrong, please try again.');
|
|
72
|
-
return;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const ids = await idRes.json();
|
|
76
|
-
const select = document.createElement('select');
|
|
77
|
-
select.id = key;
|
|
78
|
-
select.name = key;
|
|
79
|
-
select.className = 'input';
|
|
80
|
-
|
|
81
|
-
ids.forEach(id => {
|
|
82
|
-
const option = document.createElement('option');
|
|
83
|
-
option.value = id;
|
|
84
|
-
option.innerText = id;
|
|
85
|
-
select.appendChild(option);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
form.append(label, select);
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (field.type === 'String') inputType = 'text';
|
|
93
|
-
else if (field.type === 'Number') inputType = 'number';
|
|
94
|
-
else if (field.type === 'Boolean') inputType = 'checkbox';
|
|
95
|
-
else if (field.type === 'Date') inputType = 'date';
|
|
96
|
-
else if (field.type === 'Array' || field.type === "Map" || field.type === "Object" || field.type == "Mixed" || field.type === "Buffer") {
|
|
97
|
-
const input = document.createElement('textarea');
|
|
98
|
-
|
|
99
|
-
input.placeholder = field.type;
|
|
100
|
-
input.id = key;
|
|
101
|
-
input.name = key;
|
|
102
|
-
input.className = 'input';
|
|
103
|
-
field.type === "Array" ? input.textContent = "[ ]" : input.textContent = "{ }";
|
|
104
|
-
input.required = isRequired(field.require);
|
|
105
|
-
if (field.default !== undefined) input.value = field.default;
|
|
106
|
-
|
|
107
|
-
form.append(label, input);
|
|
108
|
-
continue;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
if (field.enum) {
|
|
112
|
-
const select = document.createElement('select');
|
|
113
|
-
select.id = key;
|
|
114
|
-
select.name = key;
|
|
115
|
-
select.className = 'input';
|
|
116
|
-
|
|
117
|
-
field.enum.forEach(id => {
|
|
118
|
-
const option = document.createElement('option');
|
|
119
|
-
option.value = id;
|
|
120
|
-
option.innerText = id;
|
|
121
|
-
select.appendChild(option);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
form.append(label, select);
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const input = document.createElement('input');
|
|
129
|
-
input.type = inputType || 'text';
|
|
130
|
-
input.placeholder = field.type;
|
|
131
|
-
input.id = key;
|
|
132
|
-
input.name = key;
|
|
133
|
-
input.className = 'input';
|
|
134
|
-
input.required = isRequired(field.require);
|
|
135
|
-
if (field.default !== undefined) input.value = field.default;
|
|
136
|
-
|
|
137
|
-
form.append(label, input);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const submitBtn = document.createElement('button');
|
|
141
|
-
submitBtn.type = 'submit';
|
|
142
|
-
submitBtn.innerHTML = 'Submit';
|
|
143
|
-
submitBtn.className = 'btn';
|
|
144
|
-
form.appendChild(submitBtn);
|
|
145
|
-
|
|
146
|
-
insertTab.appendChild(form);
|
|
147
|
-
|
|
148
|
-
} catch (error) {
|
|
149
|
-
showModal('error', 'Error Occurred!', error.message || 'Something went wrong, please try again.');
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function isRequired(require) {
|
|
154
|
-
return Array.isArray(require) ? require[0] : require;
|
|
155
|
-
}
|
|
1
|
+
async function toggleInsertTab() {
|
|
2
|
+
const modelName = content.dataset?.modelName;
|
|
3
|
+
if (!modelName) {
|
|
4
|
+
showModal('error', 'Error Occurred!', 'No model selected.');
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const insertTab = document.querySelector('.insert-tab');
|
|
9
|
+
insertTab.classList.toggle('active');
|
|
10
|
+
|
|
11
|
+
if (insertTab.innerHTML.trim() !== '') return;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const res = await fetch(`/schema/${modelName}`);
|
|
15
|
+
if (!res.ok) throw new Error();
|
|
16
|
+
|
|
17
|
+
const schema = await res.json();
|
|
18
|
+
|
|
19
|
+
const form = document.createElement('form');
|
|
20
|
+
form.id = 'insert-form';
|
|
21
|
+
|
|
22
|
+
form.addEventListener('submit', async (e) => {
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
|
|
25
|
+
const formData = new FormData(e.target);
|
|
26
|
+
const data = Object.fromEntries(formData.entries());
|
|
27
|
+
|
|
28
|
+
const checkboxes = e.target.querySelectorAll('input[type="checkbox"]');
|
|
29
|
+
checkboxes.forEach(cb => {
|
|
30
|
+
data[cb.name] = cb.checked;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const textareas = e.target.querySelectorAll('textarea');
|
|
34
|
+
textareas.forEach(async tarea => {
|
|
35
|
+
|
|
36
|
+
data[tarea.name] = JSON.parse(tarea.value)
|
|
37
|
+
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const res = await fetch(`/insert/${modelName}`, {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
headers: { 'Content-Type': 'application/json' },
|
|
43
|
+
body: JSON.stringify(data)
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (!res.ok) {
|
|
47
|
+
const error = await res.json();
|
|
48
|
+
showModal('error', 'Error Occurred!', error.error || 'Something went wrong, please try again.');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
loadDocuments();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
for (const key in schema) {
|
|
57
|
+
|
|
58
|
+
if (/\.\$\*$/.test(key)) continue;
|
|
59
|
+
const field = schema[key];
|
|
60
|
+
let inputType = null;
|
|
61
|
+
|
|
62
|
+
const label = document.createElement('label');
|
|
63
|
+
label.innerHTML = `${key}:`;
|
|
64
|
+
label.className = 'label';
|
|
65
|
+
label.htmlFor = key;
|
|
66
|
+
|
|
67
|
+
if (field.type === 'ObjectId') {
|
|
68
|
+
const idRes = await fetch(`/id/${field.ref}`);
|
|
69
|
+
if (!idRes.ok) {
|
|
70
|
+
const error = await idRes.json();
|
|
71
|
+
showModal('error', 'Error Occurred!', error.error || 'Something went wrong, please try again.');
|
|
72
|
+
return;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const ids = await idRes.json();
|
|
76
|
+
const select = document.createElement('select');
|
|
77
|
+
select.id = key;
|
|
78
|
+
select.name = key;
|
|
79
|
+
select.className = 'input';
|
|
80
|
+
|
|
81
|
+
ids.forEach(id => {
|
|
82
|
+
const option = document.createElement('option');
|
|
83
|
+
option.value = id;
|
|
84
|
+
option.innerText = id;
|
|
85
|
+
select.appendChild(option);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
form.append(label, select);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (field.type === 'String') inputType = 'text';
|
|
93
|
+
else if (field.type === 'Number') inputType = 'number';
|
|
94
|
+
else if (field.type === 'Boolean') inputType = 'checkbox';
|
|
95
|
+
else if (field.type === 'Date') inputType = 'date';
|
|
96
|
+
else if (field.type === 'Array' || field.type === "Map" || field.type === "Object" || field.type == "Mixed" || field.type === "Buffer") {
|
|
97
|
+
const input = document.createElement('textarea');
|
|
98
|
+
|
|
99
|
+
input.placeholder = field.type;
|
|
100
|
+
input.id = key;
|
|
101
|
+
input.name = key;
|
|
102
|
+
input.className = 'input';
|
|
103
|
+
field.type === "Array" ? input.textContent = "[ ]" : input.textContent = "{ }";
|
|
104
|
+
input.required = isRequired(field.require);
|
|
105
|
+
if (field.default !== undefined) input.value = field.default;
|
|
106
|
+
|
|
107
|
+
form.append(label, input);
|
|
108
|
+
continue;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
if (field.enum) {
|
|
112
|
+
const select = document.createElement('select');
|
|
113
|
+
select.id = key;
|
|
114
|
+
select.name = key;
|
|
115
|
+
select.className = 'input';
|
|
116
|
+
|
|
117
|
+
field.enum.forEach(id => {
|
|
118
|
+
const option = document.createElement('option');
|
|
119
|
+
option.value = id;
|
|
120
|
+
option.innerText = id;
|
|
121
|
+
select.appendChild(option);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
form.append(label, select);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const input = document.createElement('input');
|
|
129
|
+
input.type = inputType || 'text';
|
|
130
|
+
input.placeholder = field.type;
|
|
131
|
+
input.id = key;
|
|
132
|
+
input.name = key;
|
|
133
|
+
input.className = 'input';
|
|
134
|
+
input.required = isRequired(field.require);
|
|
135
|
+
if (field.default !== undefined) input.value = field.default;
|
|
136
|
+
|
|
137
|
+
form.append(label, input);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const submitBtn = document.createElement('button');
|
|
141
|
+
submitBtn.type = 'submit';
|
|
142
|
+
submitBtn.innerHTML = 'Submit';
|
|
143
|
+
submitBtn.className = 'btn';
|
|
144
|
+
form.appendChild(submitBtn);
|
|
145
|
+
|
|
146
|
+
insertTab.appendChild(form);
|
|
147
|
+
|
|
148
|
+
} catch (error) {
|
|
149
|
+
showModal('error', 'Error Occurred!', error.message || 'Something went wrong, please try again.');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function isRequired(require) {
|
|
154
|
+
return Array.isArray(require) ? require[0] : require;
|
|
155
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
document.addEventListener("keydown", (e) => {
|
|
2
|
-
|
|
3
|
-
if (e.ctrlKey && e.key === 'o') {
|
|
4
|
-
e.preventDefault();
|
|
5
|
-
toggleInsertTab();
|
|
6
|
-
} else if (e.ctrlKey && e.key == "r") {
|
|
7
|
-
e.preventDefault()
|
|
8
|
-
loadDocuments();
|
|
9
|
-
} else if (e.ctrlKey && e.key == ".") {
|
|
10
|
-
e.preventDefault()
|
|
11
|
-
gotoNextPage();
|
|
12
|
-
} else if (e.ctrlKey && e.key == ",") {
|
|
13
|
-
e.preventDefault()
|
|
14
|
-
gotoPreviousPage();
|
|
15
|
-
}
|
|
1
|
+
document.addEventListener("keydown", (e) => {
|
|
2
|
+
|
|
3
|
+
if (e.ctrlKey && e.key === 'o') {
|
|
4
|
+
e.preventDefault();
|
|
5
|
+
toggleInsertTab();
|
|
6
|
+
} else if (e.ctrlKey && e.key == "r") {
|
|
7
|
+
e.preventDefault()
|
|
8
|
+
loadDocuments();
|
|
9
|
+
} else if (e.ctrlKey && e.key == ".") {
|
|
10
|
+
e.preventDefault()
|
|
11
|
+
gotoNextPage();
|
|
12
|
+
} else if (e.ctrlKey && e.key == ",") {
|
|
13
|
+
e.preventDefault()
|
|
14
|
+
gotoPreviousPage();
|
|
15
|
+
}
|
|
16
16
|
})
|