Skip to content

Commit f89acdf

Browse files
committed
add table for acts
1 parent 6b9dbc0 commit f89acdf

File tree

11 files changed

+114
-32
lines changed

11 files changed

+114
-32
lines changed

backend/backend/db/postgres/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __str__(self):
3636

3737
class Act(Model):
3838
id = fields.UUIDField(pk=True)
39+
name = fields.TextField(null=True, description='Комментарий')
3940
customer = fields.TextField()
4041
file_name = fields.TextField()
4142

@@ -55,4 +56,4 @@ class Meta:
5556
table = 'netclients'
5657

5758
def __str__(self):
58-
return self.systemname
59+
return self.system
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from tortoise import BaseDBAsyncClient
2+
3+
4+
async def upgrade(db: BaseDBAsyncClient) -> str:
5+
return """
6+
ALTER TABLE "acts" ADD "name" TEXT;"""
7+
8+
9+
async def downgrade(db: BaseDBAsyncClient) -> str:
10+
return """
11+
ALTER TABLE "acts" DROP COLUMN "name";"""

backend/backend/models/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Config:
4747
class ActSchema(BaseModel):
4848
"""Модель загружаемого файла(акта) пользователя."""
4949
id: UUID4 = Field()
50-
customer: str = Field()
50+
customer: str = Field(description='Имя пользователя')
5151
file: str = Field(alias='file_name')
5252

5353

backend/backend/routers/files.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
async def upload_act(
2323
file: UploadFile,
2424
customer: str,
25+
name: str = None,
2526
token: HTTPAuthorizationCredentials = Security(token_auth_scheme)
2627
) -> str:
2728
"""Загрузка акта пользователя AD.
@@ -33,7 +34,7 @@ async def upload_act(
3334
Returns:
3435
str: статус.
3536
"""
36-
await Act.create(customer=customer, file_name=f'{ACT_DIR}/{customer}.pdf')
37+
await Act.create(customer=customer, name=name, file_name=f'{ACT_DIR}/{customer}.pdf')
3738
async with aiofiles.open(f'{ACT_DIR}/{customer}.pdf', 'wb') as resp_file:
3839
content = await file.read()
3940
await resp_file.write(content)
@@ -63,8 +64,9 @@ async def download_act(
6364

6465
@router.put('/act/{customer}/change')
6566
async def change_act(
66-
file: UploadFile,
6767
customer: str,
68+
file: UploadFile = None,
69+
name: str = None,
6870
token: HTTPAuthorizationCredentials = Security(token_auth_scheme)
6971
) -> str:
7072
"""Замена файла для выбранного пользователя.
@@ -76,12 +78,16 @@ async def change_act(
7678
Returns:
7779
str: статус.
7880
"""
79-
await aiofiles.os.remove(f'{ACT_DIR}/{customer}.pdf')
80-
async with aiofiles.open(f'{ACT_DIR}/{customer}.pdf', 'wb') as resp_file:
81-
content = await file.read()
82-
await resp_file.write(content)
83-
await Act.filter(customer=customer).update(file_name=f'{ACT_DIR}/{customer}')
84-
logger.info(f'Загружен новый акт {file.filename} для {customer}')
81+
if file:
82+
await aiofiles.os.remove(f'{ACT_DIR}/{customer}.pdf')
83+
async with aiofiles.open(f'{ACT_DIR}/{customer}.pdf', 'wb') as resp_file:
84+
content = await file.read()
85+
await resp_file.write(content)
86+
await Act.filter(customer=customer).update(file_name=f'{ACT_DIR}/{customer}')
87+
logger.info(f'Загружен новый акт {file.filename} для {customer}')
88+
if name:
89+
await Act.filter(customer=customer).update(name=name)
90+
logger.info(f'Изменено описание для {customer}')
8591
return 'ok'
8692

8793
@router.delete('/act/{customer}/delete')
@@ -101,3 +107,16 @@ async def delete_act(
101107
await aiofiles.os.remove(f'{ACT_DIR}/{customer}.pdf')
102108
logger.info(f'Удален акт для {customer}')
103109
return 'ok'
110+
111+
@router.get('/acts')
112+
async def get_acts(token: HTTPAuthorizationCredentials = Security(token_auth_scheme)) -> list:
113+
"""_summary_
114+
115+
Args:
116+
token (HTTPAuthorizationCredentials, optional): _description_. Defaults to Security(token_auth_scheme).
117+
118+
Returns:
119+
dict: _description_
120+
"""
121+
acts = await Act.all().values()
122+
return acts

backend/backend/routers/users.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,7 @@ async def get_customers(
7777
token (HTTPAuthorizationCredentials, optional): Токен аутентификации.
7878
"""
7979
count = cache.get_value('customers_count')
80-
return int(count)
80+
if count is not None:
81+
return int(count)
82+
else:
83+
return 0

web/src/components/ActRender.vue

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ export default {
1616
},
1717
data() {
1818
return {
19-
id: 'acts/template.pdf', // по-умолчанию грузится шаблон
19+
id: 'acts/template.pdf', // по-умолчанию грузится шаблон,
20+
actsTable: [],
2021
}
2122
},
2223
watch: {
2324
$route(to, from) {
2425
this.render(to)
26+
this.renderActs()
2527
},
2628
},
2729
methods: {
@@ -30,16 +32,24 @@ export default {
3032
},
3133
render(data) {
3234
this.id = data.path + '.pdf'
35+
},
36+
async renderActs() {
37+
let acts = await this.store.getActsTable()
38+
console.log(acts)
39+
this.actsTable = acts
3340
}
3441
},
42+
created () {
43+
this.renderActs()
44+
}
3545
}
3646
</script>
3747

3848
<template>
3949
<div class="row">
4050
<div class="col-4 p-4 d-flex justify-content-center">
4151
<div class="mx-auto">
42-
<div class="card shadow rounded" style="width: 30rem;">
52+
<div class="card shadow rounded mb-3" style="width: 30rem;">
4353
<div class="card-body">
4454
<h6 class="card-subtitle text-body-secondary d-flex justify-content-center">
4555
{{ this.route.params.id == 'template'? 'Шаблон акта': id.slice(6,-4) }}
@@ -51,6 +61,22 @@ export default {
5161
</div>
5262
</div>
5363
</div>
64+
<table class="table table-striped shadow-lg p-3 mb-5 bg-body-tertiary rounded" style="width: 30rem;">
65+
<thead class="table-light">
66+
<tr>
67+
<th scope="col">#</th>
68+
<th scope="col">Акт</th>
69+
<th scope="col">Описание</th>
70+
</tr>
71+
</thead>
72+
<tbody class="table-group-divider">
73+
<tr v-for="(item, index) in this.actsTable" :key="(index)">
74+
<th scope="row">{{ (index + 1)}}</th>
75+
<td>{{ item.customer }}</td>
76+
<td>{{ item.name }}</td>
77+
</tr>
78+
</tbody>
79+
</table>
5480
</div>
5581
</div>
5682
<div class="col-8 p-4 act-area">

web/src/components/AddAct.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ export default {
1212
data() {
1313
return {
1414
file: '',
15-
customer: 'customer'
15+
customer: '',
16+
name: ''
1617
}
1718
},
1819
methods: {
1920
handleFileUpload() {
2021
this.file = this.$refs.file.files[0]
2122
},
2223
async uploadFile() {
23-
await this.store.UploadAct(this.file, this.customer)
24+
await this.store.UploadAct(this.file, this.customer, this.name)
2425
this.$notify({
2526
type: 'success',
2627
title: 'Уведомление',
@@ -30,7 +31,8 @@ export default {
3031
},
3132
clearData() {
3233
this.file = ''
33-
this.customer = 'customer'
34+
this.customer = ''
35+
this.name = ''
3436
}
3537
},
3638
}
@@ -49,12 +51,16 @@ export default {
4951
<label for="new-act" class="col-form-label">Customer:</label>
5052
<input type="text" class="form-control" id="new-act" v-model="customer">
5153
</div>
54+
<div class="mb-3">
55+
<label for="new-act" class="col-form-label">Описание:</label>
56+
<input type="text" class="form-control" id="new-act" placeholder="Необязательно" v-model="name">
57+
</div>
5258
<div class="input-group">
5359
<input type="file" class="form-control" ref="file" id="inputGroupFile04" aria-describedby="inputGroupFileAddon04" aria-label="Upload" v-on:change="handleFileUpload()">
54-
<button class="btn btn-outline-secondary" type="button" id="inputGroupFileAddon04" data-bs-dismiss="modal" @click="uploadFile()">Отправить</button>
5560
</div>
5661
</div>
5762
<div class="modal-footer">
63+
<button class="btn btn-outline-secondary" type="button" data-bs-dismiss="modal" @click="uploadFile()">Отправить</button>
5864
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" @click="clearData()">Закрыть</button>
5965
</div>
6066
</div>

web/src/components/ChangeAct.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ export default {
1212
data() {
1313
return {
1414
file: '',
15-
customer: 'customer'
15+
customer: '',
16+
name: ''
1617
}
1718
},
1819
methods: {
1920
handleFileUpload() {
2021
this.file = this.$refs.file.files[0]
2122
},
2223
async uploadFile() {
23-
await this.store.ChangeAct(this.file, this.customer)
24+
await this.store.ChangeAct(this.file, this.customer, this.name)
2425
this.$notify({
2526
type: 'success',
2627
title: 'Уведомление',
@@ -30,7 +31,8 @@ export default {
3031
},
3132
clearData() {
3233
this.file = ''
33-
this.customer = 'customer'
34+
this.customer = ''
35+
this.name = ''
3436
}
3537
},
3638
}
@@ -50,14 +52,17 @@ export default {
5052
<label for="customer" class="col-form-label">Customer:</label>
5153
<input type="text" class="form-control" id="customer" v-model="customer">
5254
</div>
55+
<div class="mb-3">
56+
<label for="new-act" class="col-form-label">Описание:</label>
57+
<input type="text" class="form-control" id="new-act" placeholder="Необязательно" v-model="name">
58+
</div>
5359
<div class="input-group">
5460
<input type="file" class="form-control" ref="file" id="inputGroupFile04"
5561
aria-describedby="inputGroupFileAddon04" aria-label="Upload" v-on:change="handleFileUpload()">
56-
<button class="btn btn-outline-secondary" type="button" id="inputGroupFileAddon04" data-bs-dismiss="modal"
57-
@click="uploadFile()">Отправить</button>
5862
</div>
5963
</div>
6064
<div class="modal-footer">
65+
<button class="btn btn-outline-secondary" type="button" data-bs-dismiss="modal" @click="uploadFile()">Отправить</button>
6166
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"
6267
@click="clearData()">Закрыть</button>
6368
</div>

web/src/router/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ router.afterEach((to, from) => {
8484

8585
// до перехода
8686
router.beforeEach((to, from) => {
87+
const store = defaultStore()
8788
if (to.name == 'customer-tables') { // рендер таблицы при переходе на вкладку /customers/tables
88-
const store = defaultStore()
8989
store.getComputersandCustomers(to.params.skip, to.params.limit, to.params.name)
9090
}
9191
})

web/src/stores/counter.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const defaultStore = defineStore('default', {
3232
}),
3333
getters: {
3434
getUser: (state) => state.user,
35+
getActs: (state) => state.acts,
3536
getNetworkTable: (state) => state.network,
3637
getPaginationInfo: (state) => state.pagination,
3738
getCustomersTable: (state) => state.customers,
@@ -170,20 +171,16 @@ export const defaultStore = defineStore('default', {
170171
},
171172
async getCustomersList() {
172173
let cache
173-
// let responseHeader
174174
const headers = { 'Authorization': `Bearer ${this.user.token}` }
175175
await axios.get(`http://${this.BACKEND}/api/v1/ldap3/users/count`, { headers }).then(
176176
function (response) {
177177
cache = response.data
178-
console.log(cache)
179-
// responseHeader = response.headers['x-customers-count']
180178
}
181179
).catch(function (error) {
182180
console.log(error)
183181
localStorage.removeItem("isActive")
184182
localStorage.removeItem("token")
185183
})
186-
// this.customers.customersAll = cache
187184
localStorage.customersCount = cache
188185
return cache
189186
},
@@ -243,23 +240,25 @@ export const defaultStore = defineStore('default', {
243240
console.log(error)
244241
})
245242
},
246-
async UploadAct(data, customer) {
243+
async UploadAct(data, customer, description) {
247244
const headers = { 'Authorization': `Bearer ${this.user.token}`, 'Content-Type': 'multipart/form-data' }
248245
let formData = new FormData()
246+
let params = {'name': description}
249247
formData.append('file', data)
250-
await axios.post(`http://${this.BACKEND}/api/v1/files/act/${customer}/upload`, formData, { headers }).then(
248+
await axios.post(`http://${this.BACKEND}/api/v1/files/act/${customer}/upload`, formData, { headers, params }).then(
251249
function (response) {
252250
console.log(response)
253251
}
254252
).catch(function (error) {
255253
console.log(error)
256254
})
257255
},
258-
async ChangeAct(data, customer) {
256+
async ChangeAct(data, customer, description) {
259257
const headers = { 'Authorization': `Bearer ${this.user.token}`, 'Content-Type': 'multipart/form-data' }
260258
let formData = new FormData()
259+
let params = { 'name': description }
261260
formData.append('file', data)
262-
await axios.put(`http://${this.BACKEND}/api/v1/files/act/${customer}/change`, formData, { headers }).then(
261+
await axios.put(`http://${this.BACKEND}/api/v1/files/act/${customer}/change`, formData, { headers, params }).then(
263262
function (response) {
264263
console.log(response)
265264
}
@@ -291,5 +290,17 @@ export const defaultStore = defineStore('default', {
291290
console.log(error)
292291
})
293292
},
293+
async getActsTable() {
294+
let responseData = []
295+
const headers = { 'Authorization': `Bearer ${this.user.token}` }
296+
await axios.get(`http://${this.BACKEND}/api/v1/files/acts`, { headers }).then(
297+
function (response) {
298+
responseData = response.data
299+
}
300+
).catch(function (error) {
301+
console.log(error)
302+
})
303+
return responseData
304+
}
294305
},
295306
})

0 commit comments

Comments
 (0)