add statment manager forms

This commit is contained in:
Hesabix 2025-04-13 15:33:45 +00:00
parent fcedb985ef
commit baae7232e2
6 changed files with 1205 additions and 859 deletions

View file

@ -39,12 +39,6 @@ class GeneralController extends AbstractController
]);
}
#[Route('/api/general/statements', name: 'general_statement')]
public function general_statement(EntityManagerInterface $entityManager): JsonResponse
{
return $this->json($entityManager->getRepository(Statment::class)->findBy([], ['id' => 'DESC']));
}
#[Route('/api/general/get/time', name: 'general_get_time')]
public function general_get_time(Jdate $jdate, Request $request): JsonResponse
{

View file

@ -0,0 +1,80 @@
<?php
namespace App\Controller\System;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Statment;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
final class StatementController extends AbstractController
{
#[Route('/api/general/statements', name: 'general_statement')]
public function general_statement(EntityManagerInterface $entityManager): JsonResponse
{
return $this->json($entityManager->getRepository(Statment::class)->findBy([], ['id' => 'DESC']));
}
#[Route('/api/admin/statement/list', name: 'system_statement_admin_list')]
public function admin_statement_list(EntityManagerInterface $entityManager): JsonResponse
{
return $this->json($entityManager->getRepository(Statment::class)->findBy([], ['id' => 'DESC']));
}
#[Route('/api/admin/statement/mod', name: 'system_statement_admin_create', methods: ['POST'])]
public function admin_statement_create(EntityManagerInterface $entityManager, Request $request): JsonResponse
{
$data = json_decode($request->getContent(), true);
$statement = new Statment();
$statement->setTitle($data['title'] ?? '');
$statement->setBody($data['body'] ?? '');
$statement->setDateSubmit($data['dateSubmit'] ?? date('Y-m-d'));
$entityManager->persist($statement);
$entityManager->flush();
return $this->json(['success' => true, 'id' => $statement->getId()]);
}
#[Route('/api/admin/statement/mod/{id}', name: 'system_statement_admin_mod', methods: ['GET', 'PUT', 'DELETE'])]
public function admin_statement_mod(
EntityManagerInterface $entityManager,
Request $request,
?string $id = null
): JsonResponse {
if (!$id) {
return $this->json(['error' => 'ID is required'], 400);
}
$statement = $entityManager->getRepository(Statment::class)->find($id);
if (!$statement) {
return $this->json(['error' => 'Statement not found'], 404);
}
if ($request->isMethod('GET')) {
return $this->json($statement);
}
if ($request->isMethod('DELETE')) {
$entityManager->remove($statement);
$entityManager->flush();
return $this->json(['success' => true]);
}
if ($request->isMethod('PUT')) {
$data = json_decode($request->getContent(), true);
$statement->setTitle($data['title'] ?? '');
$statement->setBody($data['body'] ?? '');
$statement->setDateSubmit($data['dateSubmit'] ?? date('Y-m-d'));
$entityManager->flush();
return $this->json(['success' => true]);
}
return $this->json(['error' => 'Method not allowed'], 405);
}
}

View file

@ -106,6 +106,22 @@ const router = createRouter({
'login': true
}
},
{
path: 'manager/statments/list',
component: () => import('../views/user/manager/statements/list.vue'),
meta: {
'title': 'اطلاعیه‌ها',
'login': true
}
},
{
path: 'manager/statments/mod/:id?',
component: () => import('../views/user/manager/statements/mod.vue'),
meta: {
'title': 'ویرایش اطلاعیه',
'login': true
}
},
{
path: 'manager/business/list',
component: () => import('../views/user/manager/business/list.vue'),
@ -211,7 +227,7 @@ const router = createRouter({
}
},
],
}, {
}, {
path: '/acc/',
component: () => import('../views/acc/App.vue'),
children: [
@ -911,7 +927,7 @@ const router = createRouter({
import('../views/acc/shareholder/list.vue'),
},
],
},
},
{
path: '/user/',
component: () => import('../views/user/single.vue'),

View file

@ -0,0 +1,116 @@
<template>
<v-toolbar color="toolbar">
<v-toolbar-title>لیست اطلاعیهها</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn
color="primary"
prepend-icon="mdi-plus"
to="/profile/manager/statments/mod"
>
افزودن اطلاعیه جدید
</v-btn>
</v-toolbar>
<v-container class="pa-0 ma-0">
<v-card>
<v-card-text>
<v-data-table
:headers="headers"
:items="statements"
:loading="loading"
class="elevation-1"
density="comfortable"
>
<template v-slot:item.actions="{ item }">
<v-btn
icon
color="primary"
variant="text"
@click="editStatement(item)"
density="comfortable"
>
<v-icon>mdi-pencil</v-icon>
<v-tooltip activator="parent" location="top">ویرایش</v-tooltip>
</v-btn>
<v-btn
icon
color="error"
variant="text"
@click="deleteStatement(item)"
density="comfortable"
>
<v-icon>mdi-delete</v-icon>
<v-tooltip activator="parent" location="top">حذف</v-tooltip>
</v-btn>
</template>
</v-data-table>
</v-card-text>
</v-card>
</v-container>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import axios from 'axios'
export default defineComponent({
name: 'list',
data() {
return {
loading: false,
statements: [],
headers: [
{ title: 'عنوان', key: 'title', sortable: true },
{ title: 'تاریخ ارسال', key: 'dateSubmit', sortable: true },
{ title: 'عملیات', key: 'actions', sortable: false, align: 'center' as const }
]
}
},
methods: {
async fetchStatements() {
this.loading = true
try {
const response = await axios.get('/api/admin/statement/list')
this.statements = response.data
} catch (error) {
console.error('Error fetching statements:', error)
} finally {
this.loading = false
}
},
editStatement(item: any) {
if (!item.id) {
console.error('Invalid statement ID')
return
}
this.$router.push(`/profile/manager/statments/mod/${item.id}`)
},
async deleteStatement(item: any) {
if (!item.id) {
console.error('Invalid statement ID')
return
}
if (confirm('آیا از حذف این اطلاعیه اطمینان دارید؟')) {
this.loading = true
try {
await axios.delete(`/api/admin/statement/mod/${item.id}`)
await this.fetchStatements()
} catch (error) {
console.error('Error deleting statement:', error)
} finally {
this.loading = false
}
}
}
},
mounted() {
this.fetchStatements()
}
})
</script>
<style scoped>
.v-card {
margin-top: 20px;
}
</style>

View file

@ -0,0 +1,139 @@
<template>
<v-toolbar color="toolbar">
<v-toolbar-title>{{ isEdit ? 'ویرایش اطلاعیه' : 'افزودن اطلاعیه جدید' }}</v-toolbar-title>
<v-spacer></v-spacer>
</v-toolbar>
<v-container class="pa-0 ma-0">
<v-card>
<v-card-text>
<v-form ref="form" @submit.prevent="submitForm">
<v-text-field
v-model="form.title"
label="عنوان"
:rules="[v => !!v || 'عنوان الزامی است']"
required
variant="outlined"
density="comfortable"
class="mb-3"
></v-text-field>
<v-textarea
v-model="form.body"
label="متن اطلاعیه"
:rules="[v => !!v || 'متن اطلاعیه الزامی است']"
required
variant="outlined"
density="comfortable"
class="mb-3"
auto-grow
rows="4"
></v-textarea>
<Hdatepicker
v-model="form.dateSubmit"
label="تاریخ ارسال"
:rules="[(v: string) => !!v || 'تاریخ ارسال الزامی است']"
required
variant="outlined"
density="comfortable"
class="mb-3"
/>
<v-btn
type="submit"
color="primary"
:loading="loading"
class="mt-4"
block
size="large"
>
{{ isEdit ? 'ویرایش' : 'افزودن' }}
</v-btn>
</v-form>
</v-card-text>
</v-card>
</v-container>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import axios from 'axios'
import { useRoute, useRouter } from 'vue-router'
import Hdatepicker from '@/components/forms/Hdatepicker.vue'
export default defineComponent({
name: 'mod',
components: {
Hdatepicker
},
data() {
return {
loading: false,
form: {
title: '',
body: '',
dateSubmit: ''
}
}
},
computed: {
isEdit() {
return !!this.$route.params.id
}
},
methods: {
async submitForm() {
const { valid } = await (this.$refs.form as any).validate()
if (!valid) {
return
}
this.loading = true
try {
if (this.isEdit) {
if (!this.$route.params.id) {
console.error('Invalid statement ID')
return
}
await axios.put(`/api/admin/statement/mod/${this.$route.params.id}`, this.form)
} else {
await axios.post('/api/admin/statement/mod', this.form)
}
this.$router.push('/profile/manager/statments/list')
} catch (error) {
console.error('Error submitting form:', error)
} finally {
this.loading = false
}
},
async fetchStatement() {
if (this.isEdit) {
if (!this.$route.params.id) {
console.error('Invalid statement ID')
return
}
this.loading = true
try {
const response = await axios.get(`/api/admin/statement/mod/${this.$route.params.id}`)
this.form = response.data
} catch (error) {
console.error('Error fetching statement:', error)
} finally {
this.loading = false
}
}
}
},
mounted() {
this.fetchStatement()
}
})
</script>
<style scoped>
.v-card {
margin-top: 20px;
}
</style>

View file

@ -106,6 +106,7 @@ export default defineComponent({
{ text: 'تغییرات', url: '/profile/manager/changes/list', icon: 'mdi-cellphone-arrow-down', visible: true },
{ text: 'تاریخچه سیستم', url: '/profile/manager/logs/list', icon: 'mdi-history', visible: true },
{ text: 'کیف پول', url: '/profile/manager/wallet/list', icon: 'mdi-wallet', visible: true },
{ text: 'اطلاعیه‌ها', url: '/profile/manager/statments/list', icon: 'mdi-bell', visible: true },
],
adminSettings: [