build_app

This commit is contained in:
string 2024-11-04 11:35:20 +00:00
parent 7db5105aa6
commit 771479615d
6 changed files with 701 additions and 92 deletions

@ -43,6 +43,11 @@ const DocumentSequence = require("./routes/DocumentSequence/DocumentSeq.routes")
app.use(`${basePath}`, DocumentSequence)
// buildercomponents
const FormaRouter = require("./routes/basic1/Forma.routes")
app.use(`${basePath}/Forma/Forma`, FormaRouter)
const port = process.env.PORT || 9292

@ -0,0 +1,213 @@
const { pool, db } = require("../../config/database")
const getUsersPaged = async (req, res) => {
try {
const page = parseInt(req.query.page) || 2
const pageSize = parseInt(req.query.size) || 10
const offset = (page - 1) * pageSize
const results = await executeQuery(
`SELECT * FROM forma LIMIT ${pageSize} OFFSET ${offset}`
)
return res.json({ content: results})
} catch (error) {
console.error(error)
return res.status(500).json({
success: 0,
message: "Error fetching content from the contentbase",
error: error.message,
})
}
}
const getUsers = (req, res) => {
pool.query(`SELECT * FROM forma`, [], (error, results) => {
if (error) {
console.error(error);
return res.status(500).json({
success: 0,
message: "Error fetching content from the database",
});
}
const formattedResults = results.map((row) => ({
...row,
// Use Buffer conversion to boolean
}));
return res.json(formattedResults);
});
};
const getUsersByUserId = async (req, res) => {
const id = req.params.id
try {
const results = await executeQuery(
"SELECT * FROM forma WHERE id = ?",
[id]
)
if (!results || results.length === 0) {
return res.json({
success: 0,
message: "Record not found",
})
}
return res.json({
success: 1,
content: results,
})
} catch (error) {
console.error(error)
return res.status(500).json({
success: 0,
message: "Error fetching content from the contentbase",
error: error.message,
})
}
}
const createUser = async (req, res) => {
const body = req.body
try {
const params = [ body.audiob,
body.imageuploadb,
]
// Replace undefined with null in parameters
const sanitizedParams = params.map((param) =>
param !== undefined ? param : null
)
await executeQuery(
`
INSERT INTO forma
SET audiob = ?,
imageuploadb = ?
`,
sanitizedParams
)
return res.json({
success: 1,
content: "user created successfully",
})
} catch (error) {
console.error(error)
return res.status(500).json({
success: 0,
message: "Error creating user",
error: error.message,
})
}
}
const updateUsers = async (req, res) => {
const body = req.body;
const id = req.params.id;
try {
// Ensure that required parameters exist and replace undefined with null
const params = [body.audiob,
body.imageuploadb,
id,
];
const sanitizedParams = params.map((param) => (param !== undefined ? param : null));
const results = await executeQuery(
`
UPDATE forma
SET audiob = ?,
imageuploadb = ?
WHERE id = ?
`,
sanitizedParams
);
if (!results) {
return res.json({
success: 0,
message: "Failed to update user",
});
}
return res.json({
success: 1,
content: "Updated successfully",
});
} catch (error) {
console.error(error);
return res.status(500).json({
success: 0,
message: "Error updating user",
error: error.message,
});
}
};
const deleteUsers = async (req, res) => {
const id = req.params.id
try {
await executeQuery("DELETE FROM forma WHERE id = ?", [id])
return res.json({
success: 1,
content: "user deleted successfully",
})
} catch (error) {
console.error(error)
return res.status(500).json({
success: 0,
message: "Error deleting user",
error: error.message,
})
}
}
module.exports = {
getUsers,
getUsersPaged,
getUsersByUserId,
createUser,
updateUsers,
deleteUsers,
}
async function executeQuery(sql, values) {
const connection = await db.getConnection()
try {
const [rows] = await connection.execute(sql, values)
return rows
} finally {
connection.release()
}
}

@ -0,0 +1,28 @@
const {
createUser,
getUsers,
getUsersPaged,
getUsersByUserId,
updateUsers,
deleteUsers,
} = require("../../entity/basic1/Forma.controller")
const router = require("express").Router()
router.get("/", getUsers).post("/", createUser).get("/getall/page",getUsersPaged)
router
.get("/:id", getUsersByUserId)
.put("/:id", updateUsers)
.delete("/:id", deleteUsers)
module.exports = router

@ -0,0 +1,2 @@
CREATE TABLE db.Forma(id BIGINT NOT NULL AUTO_INCREMENT, audiob VARCHAR(400), imageuploadb VARCHAR(400), PRIMARY KEY (id));

@ -0,0 +1,356 @@
<template>
<div class="container mt-4">
<button class="btn btn-success mb-3" @click="openAddDialog">
Add New Item
</button>
<table class="table table-striped">
<thead class="table-light">
<tr>
<th scope="col">audiobname</th>
<th scope="col">audiobpath</th>
<th scope="col">imageuploadbname</th>
<th scope="col">imageuploadbpath</th>
</tr>
</thead>
<tbody>
<tr v-for="item in paginatedData" :key="item.id">
<td>{{ item.audiobname }}</td>
<td>{{ item.audiobpath }}</td>
<td>{{ item.imageuploadbname }}</td>
<td>{{ item.imageuploadbpath }}</td>
<td>
<button class="btn btn-primary btn-sm" @click="openDialog(item)">
Update
</button>
<button
class="btn btn-danger btn-sm ms-2"
@click="deleteItem(item.id)"
>
Delete
</button>
</td>
</tr>
</tbody>
</table>
<!-- Pagination Controls -->
<nav aria-label="Page navigation">
<ul class="pagination">
<li class="page-item" :class="{ disabled: currentPage === 1 }">
<a
class="page-link"
href="#"
@click.prevent="changePage(currentPage - 1)"
>Previous</a
>
</li>
<li
class="page-item"
v-for="page in totalPages"
:key="page"
:class="{ active: page === currentPage }"
>
<a class="page-link" href="#" @click.prevent="changePage(page)">{{
page
}}</a>
</li>
<li class="page-item" :class="{ disabled: currentPage === totalPages }">
<a
class="page-link"
href="#"
@click.prevent="changePage(currentPage + 1)"
>Next</a
>
</li>
</ul>
</nav>
<!-- Form Dialog -->
<div
v-if="dialogVisible"
class="modal fade show"
tabindex="-1"
style="display: block"
>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
{{ isEditMode ? "Edit Item" : "Add Item" }}
</h5>
<button
type="button"
class="btn-close"
@click="closeDialog"
></button>
</div>
<div class="modal-body">
<form @submit.prevent="submitForm">
<div class="mb-3">
<label>audiob Upload:</label>
<input type="file"
@change="handleFileUploadaudiob('audiob')"
accept="audio/mpeg, audio/wav, audio/ogg, audio/mp3, audio/aac"/>
</div>
<div class="mb-3">
<label>imageuploadb Upload:</label>
<input type="file"
@change="handleFileUploadimageuploadb('imageuploadb')"
accept="image/png, image/jpeg, image/jpg, image/gif, image/webp"/>
</div>
<button type="submit" class="btn btn-primary">
{{ isEditMode ? "Save changes" : "Add Item" }}
</button>
</form>
</div>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted, computed } from "vue";
import { TokenService } from '../../../../services/TokenService';
import QRCode from "qrcode";
import JsBarcode from "jsbarcode";
const FILE_API_URL = `${import.meta.env.VITE_APP_API_URL}/FileUpload/Uploadeddocs`;
const API_URL = `${
import.meta.env.VITE_APP_API_URL
}/Forma/Forma`;
const token = localStorage.getItem("token");
console.log("hii", token);
const data = ref([]);
const currentItem = ref({
audiobname: "",
audiobpath: "",
imageuploadbname: "",
imageuploadbpath: "",
});
const dialogVisible = ref(false);
const isEditMode = ref(false);
const currentPage = ref(1);
const itemsPerPage = 10;
const fetchData = async () => {
try {
const token = TokenService.getToken();
const response = await fetch(API_URL, {
headers: {
Authorization: `Bearer ${token}`,
},
});
const result = await response.json();
// Ensure data is an array
if (Array.isArray(result)) {
data.value = result;
} else {
console.error("Error: Fetched data is not an array");
} } catch (error) {
console.error("Error fetching data:", error);
}
};
const paginatedData = computed(() => {
const start = (currentPage.value - 1) * itemsPerPage;
const end = start + itemsPerPage;
return Array.isArray(data.value) ? data.value.slice(start, end) : [];});
const totalPages = computed(() => {
return Array.isArray(data.value)
? Math.ceil(data.value.length / itemsPerPage)
: 0;});
const changePage = (page) => {
if (page > 0 && page <= totalPages.value) {
currentPage.value = page;
}
};
const openDialog = (item) => {
currentItem.value = { ...item };
isEditMode.value = true;
dialogVisible.value = true;
};
const openAddDialog = () => {
currentItem.value = {
audiobname: "",
audiobpath: "",
imageuploadbname: "",
imageuploadbpath: "",
};
isEditMode.value = false;
dialogVisible.value = true;
};
const closeDialog = () => {
dialogVisible.value = false;
};
const submitForm = async () => {
if (Object.values(currentItem.value).some(path => !path)) {
alert('Please ensure all files are uploaded.');
return;
}
if (Object.values(currentItem.value).some(path => !path)) {
alert('Please ensure all files are uploaded.');
return;
}
if (isEditMode.value) {
// Update item
try {
const token = TokenService.getToken();
await fetch(`${API_URL}/${currentItem.value.id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(currentItem.value),
});
closeDialog();
await fetchData();
} catch (error) {
console.error("Error updating item:", error);
}
} else {
// Add new item
try {
const token = TokenService.getToken();
await fetch(API_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(currentItem.value),
});
closeDialog();
await fetchData();
} catch (error) {
console.error("Error adding item:", error);
}
}
};
const deleteItem = async (id) => {
if (confirm("Are you sure you want to delete this item?")) {
try {
const token = TokenService.getToken();
await fetch(`${API_URL}/${id}`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${token}`,
},
});
await fetchData();
} catch (error) {
console.error("Error deleting item:", error);
}
}
};
const file = ref(null);
const uploadProgress = ref(0);
const fileUploaded = ref(false);
const handleFileUpload = (event) => {
file.value = event.target.files[0];
};
const handleFileUploadaudiob = async (type) => {
const fileInput = event.target.files[0];
if (!fileInput) return;
const formData = new FormData();
formData.append("file", fileInput);
try {
const response = await fetch(`${FILE_API_URL}/ref/Forma`, {
method: "POST",
headers: { Authorization: `Bearer ${token}` },
body: formData,
});
if (response.ok) {
const responseData = await response.json();
// Update the corresponding file details in currentItem
currentItem.value[`${type}name`] = responseData.uploadedfile_name;
currentItem.value[`${type}path`] = responseData.uploadedfile_path;
} else {
alert("File upload failed.");
}
} catch (error) {
console.error("File upload error:", error);
}
};
const handleFileUploadimageuploadb = async (type) => {
const fileInput = event.target.files[0];
if (!fileInput) return;
const formData = new FormData();
formData.append("file", fileInput);
try {
const response = await fetch(`${FILE_API_URL}/ref/Forma`, {
method: "POST",
headers: { Authorization: `Bearer ${token}` },
body: formData,
});
if (response.ok) {
const responseData = await response.json();
// Update the corresponding file details in currentItem
currentItem.value[`${type}name`] = responseData.uploadedfile_name;
currentItem.value[`${type}path`] = responseData.uploadedfile_path;
} else {
alert("File upload failed.");
}
} catch (error) {
console.error("File upload error:", error);
}
};
onMounted(fetchData);
</script>
<style scoped>
/* No custom styles, relying on Bootstrap */
</style>

@ -1,92 +1,97 @@
import { createRouter, createWebHistory } from "vue-router";
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: "/home",
component: () => import("../views/Home.vue"),
},
{
path: "/dashboard",
component: () => import("../views/Dashboard.vue"),
},
{
path: "/report",
component: () => import("../views/Report.vue"),
},
{
path: "/setup",
component: () => import("../views/Setup.vue"),
},
{
path: "/login",
component: () => import("../components/Login/LoginComponent.vue"),
},
{
path: "/",
component: () => import("../components/Login/LoginComponent.vue"),
},
{
path: "/createacc",
component: () => import("../components/Login/CreateAccount.vue"),
},
{
path: "/forgetPassword",
component: () => import("../components/Login/ResetPassword.vue"),
},
{
path: "/usermaintenance",
component: () => import("../views/setupTools/UserMaintenance.vue"),
},
{
path: "/userGroupmaintenance",
component: () => import("../views/setupTools/UserGroupMaintenance.vue"),
},
{
path: "/menumaintenance",
component: () => import("../views/setupTools/MenuMaintance.vue"),
},
{
path: "/menuaccesscontrol",
component: () => import("../views/setupTools/MenuAccessControl.vue"),
},
// {
// path: "/systemparameter",
// component: () => import("../views/setupTools/SystemParameter.vue"),
// },
{
path: "/accesstype",
component: () => import("../views/setupTools/AccessType.vue"),
},
{
path: "/documentsequence",
component: () => import("../views/setupTools/DocumentSequence.vue"),
},
// {
// path: "/reports",
// component: () => import("../views/setupTools/Reports.vue"),
// },
{
path: "/dashboardescription",
component: () => import("../views/setupTools/DashboardDescription.vue"),
},
// {
// path: "/reportbuildersql",
// component: () => import("../views/reportbuilder/ReportBuilderSQL.vue"),
// },
// {
// path: "/reportbuilderurl",
// component: () => import("../views/reportbuilder/ReportBuilderURL.vue"),
// },
// buildercomponents
{
path: "/datfolder",
component: () => import("../components/BuilderComponents/Test/DataTable.vue"),
},
],
});
export default router;
import { createRouter, createWebHistory } from "vue-router";
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: "/home",
component: () => import("../views/Home.vue"),
},
{
path: "/dashboard",
component: () => import("../views/Dashboard.vue"),
},
{
path: "/report",
component: () => import("../views/Report.vue"),
},
{
path: "/setup",
component: () => import("../views/Setup.vue"),
},
{
path: "/login",
component: () => import("../components/Login/LoginComponent.vue"),
},
{
path: "/",
component: () => import("../components/Login/LoginComponent.vue"),
},
{
path: "/createacc",
component: () => import("../components/Login/CreateAccount.vue"),
},
{
path: "/forgetPassword",
component: () => import("../components/Login/ResetPassword.vue"),
},
{
path: "/usermaintenance",
component: () => import("../views/setupTools/UserMaintenance.vue"),
},
{
path: "/userGroupmaintenance",
component: () => import("../views/setupTools/UserGroupMaintenance.vue"),
},
{
path: "/menumaintenance",
component: () => import("../views/setupTools/MenuMaintance.vue"),
},
{
path: "/menuaccesscontrol",
component: () => import("../views/setupTools/MenuAccessControl.vue"),
},
// {
// path: "/systemparameter",
// component: () => import("../views/setupTools/SystemParameter.vue"),
// },
{
path: "/accesstype",
component: () => import("../views/setupTools/AccessType.vue"),
},
{
path: "/documentsequence",
component: () => import("../views/setupTools/DocumentSequence.vue"),
},
// {
// path: "/reports",
// component: () => import("../views/setupTools/Reports.vue"),
// },
{
path: "/dashboardescription",
component: () => import("../views/setupTools/DashboardDescription.vue"),
},
// {
// path: "/reportbuildersql",
// component: () => import("../views/reportbuilder/ReportBuilderSQL.vue"),
// },
// {
// path: "/reportbuilderurl",
// component: () => import("../views/reportbuilder/ReportBuilderURL.vue"),
// },
// buildercomponents
{
path: "/Forma",
component: () => import("../components/BuilderComponents/basic1/Forma/Forma.vue"),
},
{
path: "/datfolder",
component: () => import("../components/BuilderComponents/Test/DataTable.vue"),
},
],
});
export default router;