mdkcontroller 1.2.2 → 1.3.0

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.
@@ -1,3 +1,14 @@
1
+ .dk-table textarea {
2
+ resize: none;
3
+ overflow: auto;
4
+ scrollbar-width: none;
5
+ }
6
+
7
+ .dk-table textarea::-webkit-scrollbar {
8
+ display: none;
9
+ /* Chrome & Safari */
10
+ }
11
+
1
12
  .dk-table {
2
13
  font-family: Arial, Helvetica, sans-serif;
3
14
  border-collapse: collapse;
@@ -7,6 +18,7 @@
7
18
 
8
19
  .dk-table td {
9
20
  border: 1px solid #ddd;
21
+ overflow: hidden;
10
22
  }
11
23
 
12
24
  .dk-table th {
@@ -55,7 +67,7 @@
55
67
  .dk-table .RowNavigator td {
56
68
  background: white;
57
69
  border-bottom: 1px solid #ff2828d6;
58
- border-radius: 7px;
70
+ /* border-radius: 7px; */
59
71
  }
60
72
 
61
73
  .dk-table .edit {
@@ -67,6 +79,7 @@
67
79
  }
68
80
 
69
81
  .dk-table .RowNavigator td>input,
82
+ .dk-table .RowNavigator td>textarea,
70
83
  .dk-table .RowNavigator td>select {
71
84
  height: 23px;
72
85
  font-size: 18px;
@@ -80,51 +93,28 @@
80
93
  background-color: #f1f1f1;
81
94
  }
82
95
 
83
- .dk-table .edit input[type="checkbox"] {
96
+ /* .dk-table .edit input[type="checkbox"] {
84
97
  min-height: 22px;
85
98
  width: 30px;
86
99
  margin: auto;
87
100
  display: block;
88
- }
101
+ } */
89
102
 
90
- .dk-table .edit input[type="checkbox"]:disabled {
103
+ /* .dk-table .edit input[type="checkbox"]:disabled {
91
104
  cursor: not-allowed;
92
105
  }
93
106
 
94
107
  .dk-table .edit input:not([type="checkbox"]) :focus {
95
108
  outline: 1px solid rgba(65, 185, 65, 0.705);
96
- }
109
+ } */
97
110
 
98
- .dk-table .edit input:not(:disabled),
99
- .dk-table .edit select {
111
+ .dk-table .edit td * {
100
112
  display: block;
101
- color: #495057;
102
- background-color: #fff;
103
- background-image: none;
104
- background-clip: padding-box;
105
- border: 1px solid rgba(0, 0, 0, 0.15);
106
- border-radius: 0.25rem;
107
- transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
108
113
  width: -webkit-fill-available;
109
114
  padding: 0;
115
+ border: 0px;
110
116
  outline: none;
111
- }
112
-
113
- .dk-actionsBar {
114
- padding: 5px 10px;
115
- width: max-content;
116
- }
117
-
118
- .dk-actionsBar button {
119
- border: 2px solid #0e9966b6;
120
- border-radius: 5px;
121
- cursor: pointer;
122
- transition: all 1s;
123
- }
124
-
125
- .dk-actionsBar button:active,
126
- .dk-actionsBar button:hover {
127
- border-color: #0fbd7db6;
117
+ font-family: sans-serif;
128
118
  }
129
119
 
130
120
  .active {
@@ -65,12 +65,13 @@ class DKGrid {
65
65
  let totalWidth = 0;
66
66
  const colWidths = this.config.column.map(f => {
67
67
  let width = f.width || (f.dataType === "string" ? 200 : f.dataType === "date" ? 140 : f.dataType === "number" ? 100 : 80);
68
+ f.width = width;
68
69
  totalWidth += width;
69
70
  return `<col style="width: ${width}px;">`;
70
71
  }).join("");
71
72
  this.editorDefault = '<tr>' + this.config.column.map(f => {
72
73
  switch (f.dataType) {
73
- case "string": return `<td><input type='text'name='${f.fieldName}'/></td>`;
74
+ case "string": return `<td><textarea name='${f.fieldName}'></textarea></td>`;
74
75
  case "bool": return `<td><input type="checkbox" name='${f.fieldName}'></td>`;
75
76
  case "date": return `<td><input type="date" name='${f.fieldName}'></td>`;
76
77
  case "number": return `<td><input type="number" name='${f.fieldName}'></td>`;
@@ -142,8 +143,9 @@ class DKGrid {
142
143
  const dkgrid = this;
143
144
  this.tableEditor.addEventListener('keydown', function (event) {
144
145
  const keyCode = event.keyCode || event.which;
145
-
146
- dkgrid.#keyDownOnTable(keyCode);
146
+ if (!event.shiftKey) {
147
+ dkgrid.#keyDownOnTable(keyCode);
148
+ }
147
149
  });
148
150
 
149
151
  this.tableRaw.addEventListener('click', function (event) {
@@ -245,8 +247,9 @@ class DKGrid {
245
247
  tbEditor.querySelector('tbody').querySelectorAll('td').forEachExt(
246
248
  child => {
247
249
  const input = child.firstChild;
250
+ input.style.height = (trTag.clientHeight) + 'px';
248
251
  try {
249
- if (input.tagName == "INPUT" || input.tagName == "SELECT") {
252
+ if (input.tagName == "INPUT" || input.tagName == "SELECT" || input.tagName == "TEXTAREA") {
250
253
  if (input.tagName == "SELECT") {
251
254
  let itemSelector = tableConfig.column.find(f => f.fieldName == input.name).items;
252
255
  this.fireEvent('onSelectorSelecting', (rs) => {
@@ -289,7 +292,7 @@ class DKGrid {
289
292
  tbEditor.querySelector('tbody').querySelectorAll('td').forEachExt(
290
293
  child => {
291
294
  const input = child.firstChild;
292
- if (input.tagName == "INPUT" || input.tagName == "SELECT") {
295
+ if (input.tagName == "INPUT" || input.tagName == "SELECT" || input.tagName == "TEXTAREA") {
293
296
  objectEditing[input.name] = input.value;
294
297
  if (input.type == 'checkbox') {
295
298
  objectEditing[input.name] = input.checked;
@@ -476,7 +479,7 @@ class DKGrid {
476
479
  this.fireEvent('onAddNewRow', null, newOb);
477
480
  }
478
481
  if (!newOb[primaryKey]) {
479
- newOb[primaryKey] = DKGrid.generateRandomString(32);
482
+ newOb[primaryKey] = Date.now() + '_' + DKGrid.generateRandomString(12);
480
483
  }
481
484
  newTR.dataset.primaryValue = newOb[primaryKey];
482
485
  const cache = this.#cache;
@@ -12,11 +12,16 @@ function isCalledFromNodeModules() {
12
12
  return false;
13
13
  }
14
14
 
15
- export default function (db) {
16
- const tbLoginToken = db.data.loginTokens;
17
- const tbUser = db.data.users;
15
+ export default function () {
16
+
18
17
  const isModule = isCalledFromNodeModules();
19
18
  const validateBase = function name(req, res) {
19
+ const db = global.db;
20
+ db.data.loginTokens = db.data.loginTokens || [];
21
+ const tbLoginToken = db.data.loginTokens;
22
+ db.data.users = db.data.users || [];
23
+ const tbUser = db.data.users;
24
+
20
25
  const accessToken = req.cookies?.access_token;
21
26
  if (accessToken) {
22
27
  const datenow = new Date();
@@ -38,20 +43,20 @@ export default function (db) {
38
43
  }
39
44
  }
40
45
  console.log(
41
- "Module dk_modules/authorization.js: (db)=>{ validate:fn, validateBool:fn }"
46
+ "Module dk_modules/authorization.js: ()=>{ validate:fn, validateBool:fn }"
42
47
  );
43
48
  return {
44
49
  validate: (req, res, next) => {
45
50
  const resultValidate = validateBase(req, res);
46
51
  switch (resultValidate) {
47
52
  case 0:
48
- return res.status(401).json({message: 'Token không được cung cấp'});
53
+ return res.status(401).json({ message: 'Token không được cung cấp' });
49
54
  case 1:
50
55
 
51
56
  next();
52
57
  break;
53
58
  case -1:
54
- return res.status(401).json({message: 'Token không hợp lệ'});
59
+ return res.status(401).json({ message: 'Token không hợp lệ' });
55
60
  }
56
61
  },
57
62
  validateBool: (req, res) => {
@@ -1,23 +1,23 @@
1
- export default (db) => {
1
+
2
+
3
+ export const getNumber = (name) => {
4
+ const db = global.db;
5
+ db.data.autoSequenceNumber = db.data.autoSequenceNumber || [];
2
6
  const tbSequence = db.data.autoSequenceNumber;
7
+ let continueNumber = tbSequence.find(f => f.name == name);
8
+ if (!continueNumber) {
9
+ tbSequence
10
+ .push({
11
+ name: name,
12
+ currentNumber: 0
13
+ });
14
+ continueNumber = tbSequence.find(f => f.name == name);
15
+ }
16
+ continueNumber.currentNumber += 1
17
+ db.write();
18
+ return continueNumber.currentNumber;
19
+ };
3
20
 
4
- console.log(
5
- "Module dk_modules/autoSequence.js: (db)=>{ getNumber:fn }"
6
- );
7
- return {
8
- getNumber: (name) => {
9
- let continueNumber = tbSequence.find(f => f.name == name);
10
- if (!continueNumber) {
11
- tbSequence
12
- .push({
13
- name: name,
14
- currentNumber: 0
15
- });
16
- continueNumber = tbSequence.find(f => f.name == name);
17
- }
18
- continueNumber.currentNumber += 1
19
- db.write();
20
- return continueNumber.currentNumber;
21
- }
22
- };
23
- }
21
+ console.log(
22
+ "Module dk_modules/autoSequence.js: ()=> getNumber:fn"
23
+ );
@@ -1,23 +1,24 @@
1
1
  import authInstant from "./authorization.js";
2
- import autoSequenceInstant from "./autoSequence.js";
3
- import {generateRandomToken, privateKey} from "./dkvar.js";
2
+ import { getNumber } from "./autoSequence.js";
4
3
 
5
4
  export default (router, db) => {
6
5
 
7
- const auth = authInstant(db);
8
- const autoNumber = autoSequenceInstant(db);
6
+ const auth = authInstant();
7
+
8
+ db.data.users = db.data.users || [];
9
9
  const tbUser = db.data.users;
10
+ db.data.loginTokens = db.data.loginTokens || [];
10
11
  const tbLoginToken = db.data.loginTokens;
11
12
 
12
13
 
13
14
  router.get("/users/gets", auth.validate, (req, res) => {
14
- res.json({message: "Get all users"});
15
+ res.json({ message: "Get all users" });
15
16
  });
16
17
 
17
18
  router.get("/users/get", auth.validate, (req, res) => {
18
19
  const userId = req.params.id;
19
- const userO = tbUser.find({id: parseInt(userId)});
20
- res.json({message: `Get user with ID ${userId}`, user: userO});
20
+ const userO = tbUser.find({ id: parseInt(userId) });
21
+ res.json({ message: `Get user with ID ${userId}`, user: userO });
21
22
  });
22
23
  router.get('/users/logout', async (req, res) => {
23
24
  const accessToken = req.cookies?.access_token;
@@ -26,7 +27,7 @@ export default (router, db) => {
26
27
  tbLoginToken.slice(indexToken, 1);
27
28
  await db.write();
28
29
  }
29
- res.clearCookie('access_token', {httpOnly: true});
30
+ res.clearCookie('access_token', { httpOnly: true });
30
31
  res.clearCookie('sessionUExt', {});
31
32
  res.redirect('/login');
32
33
  });
@@ -37,26 +38,26 @@ export default (router, db) => {
37
38
  let userLoging = tbUser.find(f => f.userName == bodyParser.userName.toLowerCase() && f.password == bodyParser.password);
38
39
  if (userLoging) {
39
40
  const userIdCode = await auth.encrypt(userLoging.userName);
40
- const accessToken = userIdCode + generateRandomToken(100);
41
+ const accessToken = userIdCode + global.generateRandomToken(100);
41
42
 
42
43
  const expiredValue = new Date();
43
44
  expiredValue.setMonth(expiredValue.getMonth() + 1);
44
45
 
45
46
  tbLoginToken.push({
46
- id: autoNumber.getNumber('loginTokens'),
47
+ id: getNumber('loginTokens'),
47
48
  userId: userLoging.id,
48
49
  tokenString: accessToken,
49
50
  expired: expiredValue
50
51
  });
51
52
  await db.write();
52
- res.cookie('access_token', accessToken, {httpOnly: true, expires: expiredValue});
53
- res.cookie('sessionUExt', userIdCode, {expires: expiredValue});
54
- res.json({message: `Đăng nhập thành công.`, success: true});
53
+ res.cookie('access_token', accessToken, { httpOnly: true, expires: expiredValue });
54
+ res.cookie('sessionUExt', userIdCode, { expires: expiredValue });
55
+ res.json({ message: `Đăng nhập thành công.`, success: true });
55
56
  } else {
56
- res.json({message: `Tài khoản hoặc mật khẩu không chính xác.`, success: false});
57
+ res.json({ message: `Tài khoản hoặc mật khẩu không chính xác.`, success: false });
57
58
  }
58
59
  } else {
59
- res.json({message: `Không đủ thông tin để đăng nhập.`, success: false});
60
+ res.json({ message: `Không đủ thông tin để đăng nhập.`, success: false });
60
61
  }
61
62
  });
62
63
  router.get("/users/tryGetAccess", (req, res) => {
@@ -65,13 +66,13 @@ export default (router, db) => {
65
66
  const accessToken = req.cookies?.access_token;
66
67
  const expiredValue = new Date();
67
68
  expiredValue.setMonth(expiredValue.getMonth() + 1);
68
- res.cookie('access_token', accessToken, {httpOnly: true, expires: expiredValue});
69
+ res.cookie('access_token', accessToken, { httpOnly: true, expires: expiredValue });
69
70
  }
70
- res.json({success: true, isLogin: isLogin});
71
+ res.json({ success: true, isLogin: isLogin });
71
72
  });
72
73
  router.post("/users/create", async (req, res) => {
73
74
  if (!global.allowRegister) {
74
- res.json({message: `Chức năng đăng ký tài khoản mới không được cung cấp.`, success: false});
75
+ res.json({ message: `Chức năng đăng ký tài khoản mới không được cung cấp.`, success: false });
75
76
  return;
76
77
  }
77
78
  const bodyParser = req.body;
@@ -80,12 +81,12 @@ export default (router, db) => {
80
81
  if (!newUser) {
81
82
  let validateUserName = tbUser.find(f => f.userName == bodyParser.userName.toLowerCase());
82
83
  if (validateUserName) {
83
- res.json({message: `Tên tài khoản đã có người đăng ký.`, success: false});
84
+ res.json({ message: `Tên tài khoản đã có người đăng ký.`, success: false });
84
85
  return;
85
86
  }
86
87
  tbUser
87
88
  .push({
88
- id: autoNumber.getNumber('users'),
89
+ id: getNumber('users'),
89
90
  userName: bodyParser.userName.toLowerCase(),
90
91
  email: bodyParser.email.toLowerCase(),
91
92
  password: bodyParser.password,
@@ -107,14 +108,14 @@ export default (router, db) => {
107
108
  });
108
109
  }
109
110
  } else {
110
- res.json({message: `Không đủ thông tin để tạo User mới.`, success: false});
111
+ res.json({ message: `Không đủ thông tin để tạo User mới.`, success: false });
111
112
  }
112
113
  });
113
114
 
114
115
  console.log(
115
116
  "Module dk_modules/users.js: (db)=>{ router: router, table: tbUser }"
116
117
  );
117
- return {router: router, table: tbUser};
118
+ return { router: router, table: tbUser };
118
119
  };
119
120
 
120
121
  // // Thêm một người dùng mới
package/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import main from "./main.js"
2
2
  import authen from "./dk_modules/authorization.js"
3
- import ause from "./dk_modules/autoSequence.js"
3
+ import { getNumber } from "./dk_modules/autoSequence.js"
4
4
 
5
5
  export const Root = async (a, b) => await main(a, b);
6
- export const Authen = (db) => authen(db);
7
- export const Sequense = (db) => ause(db);
6
+ export const Authen = () => authen();
7
+ export const Sequense = (key) => {
8
+ return getNumber(key);
9
+ }
package/main.js CHANGED
@@ -12,7 +12,6 @@ import authInstant from "./dk_modules/authorization.js";
12
12
 
13
13
  import {fileURLToPath} from "url";
14
14
  import path from 'path';
15
- // import {privateKey, encodeMini} from "./dk_modules/dkvar.js";
16
15
 
17
16
  export default async function (appname, cfgHandler = {}) {
18
17
 
@@ -22,7 +21,7 @@ export default async function (appname, cfgHandler = {}) {
22
21
  const app = express();
23
22
  const server = createServer(app);
24
23
  const db = await dbInstant(appname + "-Database.json");
25
- const auth = authInstant(db);
24
+ const auth = authInstant();
26
25
  const userRoutes = userInstant(Router(), db);
27
26
 
28
27
  app.use(json());
package/package.json CHANGED
@@ -9,15 +9,14 @@
9
9
  "socket.io": "^4.7.2"
10
10
  },
11
11
  "name": "mdkcontroller",
12
- "version": "1.2.2",
12
+ "version": "1.3.0",
13
13
  "keywords": [],
14
14
  "author": "KHANHNBD <khanh272421@gmail.com>",
15
15
  "license": "ISC",
16
16
  "description": "Quick setup authentication and express",
17
17
  "type": "module",
18
18
  "exports": {
19
- ".": "./index.js",
20
- "./autosequence": "./dk_modules/autoSequence.js"
19
+ ".": "./index.js"
21
20
  },
22
21
  "types": "./index.js",
23
22
  "files": [
@@ -27,4 +26,4 @@
27
26
  "Cores/",
28
27
  "dk_modules/"
29
28
  ]
30
- }
29
+ }
@@ -1,13 +0,0 @@
1
- import {Buffer} from 'node:buffer';
2
-
3
- export const privateKey = 'eyJzdWIiOiI5Nzc4IiwibmFtZSI6IkRraGFuaE1NTSIsImlhdCI6ODkxMDB9';
4
-
5
- export function generateRandomToken(length = 100) {
6
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
7
- let token = '';
8
- for (let i = 0; i < length; i++) {
9
- const randomIndex = Math.floor(Math.random() * characters.length);
10
- token += characters.charAt(randomIndex);
11
- }
12
- return token;
13
- }