Skip to content

Commit 296922b

Browse files
committed
RocketChat#821 [EDIT] Форма подачи документов | Правки
1 parent 96b1965 commit 296922b

20 files changed

+527
-308
lines changed

app/api/server/v1/protocols.js

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ API.v1.addRoute('protocols.list.requestAnswer', { authRequired: false }, {
3333
fields: {
3434
sections: 1,
3535
num: 1,
36+
place: 1,
37+
d: 1,
3638
},
3739
pagination: {
3840
offset,

app/api/server/v1/working-groups-requests.js

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ API.v1.addRoute('working-groups-requests.upload/:id/:mailId/:answerId', { authRe
9595
const uploadedFile = fileStore.insertSync(details, file.fileBuffer);
9696

9797
uploadedFile.description = fields.description;
98+
99+
Meteor.call('sendFileWorkingGroupRequestAnswer', this.urlParams.id, this.urlParams.mailId, this.urlParams.answerId, uploadedFile);
100+
98101
return uploadedFile;
99102
});
100103
return API.v1.success({ _id: fileData._id });

app/file-upload/server/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import './lib/requests';
55
import './config/_configUploadStorage';
66
import './methods/sendFileMessage';
77
import './methods/getS3FileUrl';
8+
import './methods/sendFileWorkingGroupRequestAnswer';
89
import './startup/settings';
910

1011
export {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Meteor } from 'meteor/meteor';
2+
import _ from 'underscore';
3+
4+
import { Uploads, WorkingGroupsRequests } from '../../../models';
5+
import { FileUpload } from '../lib/FileUpload';
6+
7+
Meteor.methods({
8+
async sendFileWorkingGroupRequestAnswer(workingGroupRequestId, workingGroupRequestMailId, workingGroupRequestAnswerId, file) {
9+
if (!Meteor.userId()) {
10+
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'sendFileMessage' });
11+
}
12+
13+
Uploads.updateFileComplete(file._id, Meteor.userId(), _.omit(file, '_id'));
14+
15+
const fileUrl = FileUpload.getPath(`${ file._id }/${ encodeURI(file.name) }`);
16+
17+
const attachment = {
18+
_id: file._id,
19+
title: file.name,
20+
type: 'file',
21+
description: file.description ?? '',
22+
title_link: fileUrl,
23+
title_link_download: true,
24+
};
25+
26+
if (/^image\/.+/.test(file.type)) {
27+
attachment.image_url = fileUrl;
28+
attachment.image_type = file.type;
29+
attachment.image_size = file.size;
30+
if (file.identify && file.identify.size) {
31+
attachment.image_dimensions = file.identify.size;
32+
}
33+
try {
34+
attachment.image_preview = await FileUpload.resizeImagePreview(file);
35+
} catch (e) {
36+
delete attachment.image_url;
37+
delete attachment.image_type;
38+
delete attachment.image_size;
39+
delete attachment.image_dimensions;
40+
}
41+
} else if (/^audio\/.+/.test(file.type)) {
42+
attachment.audio_url = fileUrl;
43+
attachment.audio_type = file.type;
44+
attachment.audio_size = file.size;
45+
} else if (/^video\/.+/.test(file.type)) {
46+
attachment.video_url = fileUrl;
47+
attachment.video_type = file.type;
48+
attachment.video_size = file.size;
49+
}
50+
51+
WorkingGroupsRequests.addWorkingGroupRequestAnswerFile(workingGroupRequestId, workingGroupRequestMailId, workingGroupRequestAnswerId, attachment);
52+
return attachment;
53+
},
54+
});

app/models/server/models/WorkingGroupsRequests.js

+55-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Base } from './_Base';
21
import { ObjectID } from 'bson';
32

3+
import { Base } from './_Base';
4+
45
class WorkingGroupsRequests extends Base {
56
constructor() {
67
super('working-groups-requests');
@@ -16,8 +17,6 @@ class WorkingGroupsRequests extends Base {
1617
mailData._id = _id;
1718

1819
const data = this.findOne({ _id: workingGroupRequestId });
19-
console.log(workingGroupRequestId);
20-
console.log(data);
2120

2221
if (data.mails) {
2322
let internalNum = 0;
@@ -40,27 +39,29 @@ class WorkingGroupsRequests extends Base {
4039
return _id;
4140
}
4241

43-
// addAnswerToRequest(_id, mailIndex, answer) {
44-
// const data = this.findOne({ _id });
45-
// if (mailIndex < 0 && mailIndex >= data.mails.length) {
46-
// return;
47-
// }
48-
// data._updatedAt = new Date();
49-
// data.mails[mailIndex].answers = data.mails[mailIndex].answers ? [...data.mails[mailIndex].answers, answer] : [answer];
50-
// return this.update({ _id }, { $set: { ...data } });
51-
// }
52-
53-
addAnswerToRequest(workingGroupRequestId, mailId, answerData) {
42+
addAnswerToRequest(workingGroupRequestId, _mailId, answerData) {
43+
const mailId = _mailId === null ? 'noAnswer' : _mailId;
44+
const newMailId = mailId === 'noAnswer' ? mailId : '';
5445
const _id = new ObjectID().toHexString();
5546
answerData._id = _id;
5647

5748
const data = this.findOne({ _id: workingGroupRequestId });
49+
data._updatedAt = new Date();
5850

59-
if (data.mails) {
60-
data._updatedAt = new Date();
51+
const newMailData = {
52+
_id: mailId,
53+
description: '',
54+
number: null,
55+
ts: new Date(),
56+
inum: 1,
57+
answers: [answerData],
58+
};
6159

60+
if (data.mails) {
61+
let isAdded = false;
6262
data.mails.forEach((mail) => {
6363
if (mail._id === mailId) {
64+
isAdded = true;
6465
if (mail.answers) {
6566
let internalNum = 0;
6667
mail.answers.forEach((answer) => {
@@ -77,11 +78,36 @@ class WorkingGroupsRequests extends Base {
7778
}
7879
}
7980
});
81+
if (!isAdded) {
82+
data.mails = [...data.mails, newMailData];
83+
}
84+
} else {
85+
data.mails = [newMailData];
86+
}
87+
88+
this.update({ _id: workingGroupRequestId }, { $set: { ...data } });
89+
return { answerId: _id, mailId: newMailId };
90+
}
91+
92+
addWorkingGroupRequestAnswerFile(workingGroupRequestId, mailId, answerId, fileData) {
93+
const data = this.findOne({ _id: workingGroupRequestId });
94+
const indexMail = data.mails ? data.mails.findIndex((mail) => mail._id === mailId) : -1;
95+
if (indexMail < 0) {
96+
return;
97+
}
8098

81-
this.update({ _id: workingGroupRequestId }, { $set: { ...data } });
99+
const indexAnswer = data.mails[indexMail].answers ? data.mails[indexMail].answers.findIndex((answer) => answer._id === answerId) : -1;
100+
if (indexAnswer < 0) {
101+
return;
82102
}
83103

84-
return _id;
104+
data._updatedAt = new Date();
105+
if (data.mails[indexMail].answers[indexAnswer].documents) {
106+
data.mails[indexMail].answers[indexAnswer].documents.push(fileData);
107+
} else {
108+
data.mails[indexMail].answers[indexAnswer].documents = [fileData];
109+
}
110+
return this.update({ _id: workingGroupRequestId }, { $set: { ...data } });
85111
}
86112

87113
// UPDATE
@@ -90,8 +116,17 @@ class WorkingGroupsRequests extends Base {
90116
return this.update({ _id }, { $set: { ...data } });
91117
}
92118

93-
updateWorkingGroupRequestMail(_id, data) {
94-
119+
updateWorkingGroupRequestMail(workingGroupRequestId, updateMailData) {
120+
const data = this.findOne({ _id: workingGroupRequestId });
121+
if (data.mails) {
122+
const index = data.mails.findIndex((mail) => mail._id === updateMailData._id);
123+
if (index < 0) {
124+
return;
125+
}
126+
data.mails[index] = updateMailData;
127+
data._updatedAt = new Date();
128+
return this.update({ _id: workingGroupRequestId }, { $set: { ...data } });
129+
}
95130
}
96131

97132
readAnswer(_id, mailId, answerId) {

app/ui/client/lib/fileUpload.js

+9-31
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ export const uploadFileWithWorkingGroupRequestAnswer = async (workingGroupReques
274274
await promise;
275275
const uploads = Session.get('uploading') || [];
276276
Session.set('uploading', uploads.filter((u) => u.id !== upload.id));
277-
const _id = promise.responseJSON._id;
278-
return { id: _id, description };
277+
return { id: promise.responseJSON._id, description };
279278
} catch (error) {
280279
const uploads = Session.get('uploading') || [];
281280
uploads.filter((u) => u.id === upload.id).forEach((u) => {
@@ -415,7 +414,6 @@ const getFileNameWithoutExtension = (fileName) => fileName.replace(/\..+$/, '');
415414

416415
export const fileUploadToWorkingGroupRequestAnswer = async (files, { _id, mailId, answerId }) => {
417416
files = [].concat(files);
418-
let fullFileName = {};
419417

420418
const uploadNextFile = () => {
421419
const file = files.pop();
@@ -443,38 +441,18 @@ export const fileUploadToWorkingGroupRequestAnswer = async (files, { _id, mailId
443441
return;
444442
}
445443

446-
const fileExtension = getFileExtension(file.name);
447-
file.name = getFileNameWithoutExtension(file.name);
448-
449-
showUploadPreview(file, async (file, preview) => modal.open({
450-
title: t('Upload_file_question'),
451-
text: await getUploadPreview(file, preview),
452-
showCancelButton: true,
453-
closeOnConfirm: false,
454-
closeOnCancel: false,
455-
confirmButtonText: t('Send'),
456-
cancelButtonText: t('Cancel'),
457-
html: true,
458-
onRendered: () => $('#file-name').focus(),
459-
}, async (isConfirm) => {
460-
if (!isConfirm) {
461-
return;
462-
}
463-
464-
const fileName = (document.getElementById('file-name').value || file.name || file.file.name) + '.' + fileExtension;
465-
const description = document.getElementById('file-description').value || undefined;
466-
fullFileName = { fileName, description };
467-
// filesId = await uploadFileWithWorkingGroupRequestAnswer(_id, mailId, answerId, {
468-
// description,
469-
// fileName,
470-
// file,
471-
// });
444+
const upload = async () => {
445+
await uploadFileWithWorkingGroupRequestAnswer(_id, mailId, answerId, {
446+
description: '',
447+
fileName: file.name,
448+
file: file.file,
449+
});
472450
uploadNextFile();
473-
}));
451+
};
452+
upload();
474453
};
475454

476455
uploadNextFile();
477-
return fullFileName;
478456
};
479457

480458
export const fileUploadToWorkingGroup = async (files, isWorkingGroupMeeting, { _id }) => {

app/working-group/client/views/lib.js

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export function createWorkingGroupRequestMessageData(description, number, previo
9494

9595
if (previousData) {
9696
workingGroupRequestData._id = previousData._id;
97+
workingGroupRequestData.ts = previousData.ts;
98+
workingGroupRequestData.inum = previousData.inum;
99+
workingGroupRequestData.answers = previousData.answers;
97100
}
98101

99102
workingGroupRequestData.description = description;

app/working-group/client/views/requests/AddMail.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import { useToastMessageDispatch } from '../../../../../client/contexts/ToastMes
77
import { createWorkingGroupRequestMessageData, validateWorkingGroupRequestMessageData } from '../lib';
88
import VerticalBar from '../../../../../client/components/basic/VerticalBar';
99

10-
export function AddMail({ goToNew, close, onChange, requestId, ...props }) {
10+
export function AddMail({ goToNew, close, onChange, requestId, data, ...props }) {
1111
const t = useTranslation();
1212
const dispatchToastMessage = useToastMessageDispatch();
1313

14-
const [description, setDescription] = useState('');
15-
const [number, setNumber] = useState('');
14+
const [description, setDescription] = useState(data?.description ?? '');
15+
const [number, setNumber] = useState(data?.number ?? '');
1616

1717
const insertOrUpdateWorkingGroupRequestMail = useMethod('insertOrUpdateWorkingGroupRequestMail');
1818

1919
const saveAction = useCallback(async (description, number) => {
20-
const messageData = createWorkingGroupRequestMessageData(description, number);
20+
const messageData = createWorkingGroupRequestMessageData(description, number, data);
2121
const validation = validateWorkingGroupRequestMessageData(messageData);
2222
if (validation.length === 0) {
2323
const result = await insertOrUpdateWorkingGroupRequestMail(requestId, messageData);
@@ -29,7 +29,7 @@ export function AddMail({ goToNew, close, onChange, requestId, ...props }) {
2929
const handleSave = useCallback(async () => {
3030
try {
3131
const result = await saveAction(description, number);
32-
dispatchToastMessage({ type: 'success', message: t('Protocol_Added_Successfully') });
32+
dispatchToastMessage({ type: 'success', message: !data ? t('Working_group_request_mail_added_successfully') : t('Working_group_request_mail_edited_successfully') });
3333
goToNew(result)();
3434
onChange();
3535
} catch (error) {

0 commit comments

Comments
 (0)