Update various configuration files, components, and assets; enhance notification system and API endpoints; improve documentation and styles across the application.
This commit is contained in:
51
server/api/devtool/menu/add.js
Normal file
51
server/api/devtool/menu/add.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
|
||||
try {
|
||||
// Check if last character is not slash
|
||||
if (body.formData.path.slice(-1) != "/") {
|
||||
body.formData.path = body.formData.path + "/";
|
||||
}
|
||||
|
||||
// Check if the path already exists
|
||||
if (fs.existsSync(path.join(process.cwd(), "pages", body.formData.path))) {
|
||||
return {
|
||||
statusCode: 500,
|
||||
message: "Path already exists. Please choose another path.",
|
||||
};
|
||||
}
|
||||
|
||||
// Create new file path with index.vue
|
||||
const newFilePath = path.join(
|
||||
process.cwd(),
|
||||
"pages",
|
||||
body.formData.path,
|
||||
"index.vue"
|
||||
);
|
||||
|
||||
// Create the folder if doesn't exist
|
||||
fs.mkdirSync(path.dirname(newFilePath), { recursive: true });
|
||||
|
||||
// Create template content
|
||||
const templateContent = buildNuxtTemplate({
|
||||
title: body.formData.title || body.formData.name,
|
||||
name: body.formData.name,
|
||||
});
|
||||
|
||||
// Write file with template
|
||||
fs.writeFileSync(newFilePath, templateContent);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
message: "Menu successfully added!",
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
statusCode: 500,
|
||||
message: error.message,
|
||||
};
|
||||
}
|
||||
});
|
||||
61
server/api/devtool/menu/delete.js
Normal file
61
server/api/devtool/menu/delete.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import navigationData from "~/navigation";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
|
||||
try {
|
||||
// Get file path
|
||||
const filePath = path.join(process.cwd() + "/pages/", body.filePath);
|
||||
|
||||
// Delete path
|
||||
fs.rmSync(filePath, { recursive: true, force: true });
|
||||
|
||||
// Remove menu from navigation
|
||||
removeMenuFromNavigation(body.filePath);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
message: "Menu successfully deleted and removed from navigation!",
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return {
|
||||
statusCode: 500,
|
||||
message: error.message,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
function removeMenuFromNavigation(menuPath) {
|
||||
const removeMenuItem = (items) => {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
if (items[i].path === menuPath) {
|
||||
items.splice(i, 1);
|
||||
return true;
|
||||
}
|
||||
if (items[i].child && items[i].child.length > 0) {
|
||||
if (removeMenuItem(items[i].child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
navigationData.forEach((section) => {
|
||||
if (section.child) {
|
||||
removeMenuItem(section.child);
|
||||
}
|
||||
});
|
||||
|
||||
// Save updated navigation data
|
||||
const navigationFilePath = path.join(process.cwd(), "navigation", "index.js");
|
||||
const navigationContent = `export default ${JSON.stringify(
|
||||
navigationData,
|
||||
null,
|
||||
2
|
||||
)};`;
|
||||
fs.writeFileSync(navigationFilePath, navigationContent, "utf8");
|
||||
}
|
||||
65
server/api/devtool/menu/edit.js
Normal file
65
server/api/devtool/menu/edit.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
|
||||
// Normalize paths
|
||||
const oldPath = body.filePath.endsWith("/")
|
||||
? body.filePath
|
||||
: body.filePath + "/";
|
||||
const newPath = body.formData.path.endsWith("/")
|
||||
? body.formData.path
|
||||
: body.formData.path + "/";
|
||||
|
||||
// Get file paths
|
||||
const oldFilePath = path.join(process.cwd(), "pages", oldPath, "index.vue");
|
||||
const newFilePath = path.join(process.cwd(), "pages", newPath, "index.vue");
|
||||
|
||||
try {
|
||||
// Create template content
|
||||
const templateContent = buildNuxtTemplate({
|
||||
title: body.formData.title || body.formData.name,
|
||||
name: body.formData.name,
|
||||
});
|
||||
|
||||
if (oldPath !== newPath) {
|
||||
// Create the new folder if it doesn't exist
|
||||
fs.mkdirSync(path.dirname(newFilePath), { recursive: true });
|
||||
|
||||
// Write the new file
|
||||
fs.writeFileSync(newFilePath, templateContent);
|
||||
|
||||
// Delete the old file
|
||||
fs.unlinkSync(oldFilePath);
|
||||
|
||||
// Remove empty directories
|
||||
let dirToCheck = path.dirname(oldFilePath);
|
||||
while (dirToCheck !== path.join(process.cwd(), "pages")) {
|
||||
if (fs.readdirSync(dirToCheck).length === 0) {
|
||||
fs.rmdirSync(dirToCheck);
|
||||
dirToCheck = path.dirname(dirToCheck);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Update existing file
|
||||
fs.writeFileSync(oldFilePath, templateContent);
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
message:
|
||||
oldPath !== newPath
|
||||
? "Menu successfully moved and updated"
|
||||
: "Menu successfully updated",
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return {
|
||||
statusCode: 500,
|
||||
message: error.message,
|
||||
};
|
||||
}
|
||||
});
|
||||
5
server/api/devtool/menu/new-add.js
Normal file
5
server/api/devtool/menu/new-add.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
|
||||
// try {
|
||||
});
|
||||
25
server/api/devtool/menu/overwrite-navigation.js
Normal file
25
server/api/devtool/menu/overwrite-navigation.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
|
||||
try {
|
||||
// get menu path
|
||||
const menuPath = path.join(process.cwd() + "/navigation/", "index.js");
|
||||
fs.writeFileSync(
|
||||
menuPath,
|
||||
`export default ${JSON.stringify(body.menuData, null, 2)}`
|
||||
);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
message: "Menu successfully saved",
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
statusCode: 500,
|
||||
message: error.message,
|
||||
};
|
||||
}
|
||||
});
|
||||
33
server/api/devtool/menu/role-list.js
Normal file
33
server/api/devtool/menu/role-list.js
Normal file
@@ -0,0 +1,33 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const roles = await prisma.role.findMany({
|
||||
select: {
|
||||
roleID: true,
|
||||
roleName: true,
|
||||
},
|
||||
where: {
|
||||
roleStatus: {
|
||||
not: "DELETED",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (roles) {
|
||||
return {
|
||||
statusCode: 200,
|
||||
message: "Roles successfully fetched",
|
||||
data: roles,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
statusCode: 404,
|
||||
message: "No Roles found",
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
statusCode: 500,
|
||||
message: error.message,
|
||||
};
|
||||
}
|
||||
});
|
||||
33
server/api/devtool/menu/user-list.js
Normal file
33
server/api/devtool/menu/user-list.js
Normal file
@@ -0,0 +1,33 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const users = await prisma.user.findMany({
|
||||
select: {
|
||||
userID: true,
|
||||
userUsername: true,
|
||||
},
|
||||
where: {
|
||||
userStatus: {
|
||||
not: "DELETED",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (users) {
|
||||
return {
|
||||
statusCode: 200,
|
||||
message: "Users successfully fetched",
|
||||
data: users,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
statusCode: 404,
|
||||
message: "No Users found",
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
statusCode: 500,
|
||||
message: error.message,
|
||||
};
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user