6161 .row
6262 q-btn( label ="Envoyer en note interne" color ="primary" icon ="mdi-note" @click ="sendMessage(ThreadType.INTERNAL)" : disable= "isDisabledTicket" ) .col-6
6363 q-btn( label ="Envoyer par mail" color ="primary" icon ="mdi-email" @click ="sendMessage(ThreadType.OUTGOING)" : disable= "isDisabledTicket" ) .col-6
64- //- .col-1(ref="dropZoneRef").bg-grey-3.items-center.justify-center.q-pa-md
65- //- q-icon(name="mdi-paperclip" size="md" :class="isOverDropZone ? 'text-primary' : 'text-grey-5'")
66- //- span.q-ml-md(:class="isOverDropZone ? 'text-primary' : 'text-grey-5'") Déposer un fichier
67-
6864</template >
6965
7066<script lang="ts" setup>
@@ -80,11 +76,8 @@ import { FsType } from '~/utils'
8076import { useQuasar } from ' quasar' ;
8177import ObjectID from ' bson-objectid' ;
8278
83- type ThreadCreateDto = components [' schemas' ][' ThreadCreateDto' ]
84- type FsPart = components [" schemas" ][" IdfsPartDto" ]
85- type MailinfoPartDto = components [" schemas" ][" MailinfoPartDto" ]
86-
8779const emit = defineEmits ([' refreshThreadsList' ])
80+ const isDisabledTicket = inject <boolean >(' isDisabledTicket' )
8881
8982const dayjs = useDayjs ()
9083const store = usePinia ()
@@ -96,21 +89,7 @@ onMounted(() => {
9689 currentThreadId .value = generateMongoId ()
9790})
9891
99- const threadType = ref (threadTypes [0 ])
100- const isFullscreen = ref (false )
101- const message = ref (' ' )
102- const dropZoneRef = ref <HTMLDivElement >()
103- const dropZoneDialogRef = ref <HTMLDivElement >()
104- const editorDialog = ref ()
105- const currentThreadId = ref <ObjectID | null >(null )
106- const attachements = ref <FsPart []>([])
107- const mailInfo = ref ({
108- from: ' ' ,
109- to: ' ' ,
110- cc: ' ' ,
111- subject: ' '
112- })
113-
92+ // Manage dropzone
11493const onDrop = (files : File [] | null ) => {
11594 if (isDisabledTicket ) {
11695 $q .notify ({
@@ -130,19 +109,25 @@ const onDrop = (files: File[] | null) => {
130109 uploadFile (file )
131110 }
132111}
133-
112+ const dropZoneRef = ref <HTMLDivElement >()
113+ const dropZoneDialogRef = ref <HTMLDivElement >()
134114const { isOverDropZone } = useDropZone (dropZoneRef , onDrop )
135115const { isOverDropZone : isOverDropZoneDialog } = useDropZone (dropZoneDialogRef , onDrop )
136116
117+ // Manage attachements
118+ type FsPart = components [" schemas" ][" IdfsPartDto" ]
119+ type FilestorageCreateDto = components [" schemas" ][" FilestorageCreateDto" ]
120+ const attachements = ref <FsPart []>([])
121+ const currentThreadId = ref <ObjectID | null >(null )
137122const uploadFile = async (file : File ) => {
138123 const formData = new FormData ()
139124 formData .append (' file' , file )
140125 formData .append (' namespace' , ' s3' )
141- formData .append (' path' , ` /ticket/${route .params .id }/attachement/${currentThreadId }/${file .name } ` )
126+ formData .append (' path' , ` /ticket/${route .params .id }/attachement/${currentThreadId . value }/${file .name } ` )
142127 formData .append (' type' , FsType .FILE )
143- const { data, error } = await useHttpApi (` core/filestorage ` , {
128+ const { data, error } = await useHttpApi (` / core/filestorage` , {
144129 method: ' post' ,
145- body: formData
130+ body: formData as unknown as FilestorageCreateDto
146131 })
147132 if (error .value ) {
148133 $q .notify ({
@@ -151,27 +136,24 @@ const uploadFile = async (file: File) => {
151136 })
152137 return
153138 }
139+ const id = generateMongoId (data .value ?.data ?._id ).toHexString ()
154140 const fsPart: FsPart = {
155- id: data . value ?. data . _id ,
141+ id ,
156142 name: file .name ,
157- namespace: data .value ?.data .namespace ,
158- path: data .value ?.data .path ,
159- mime: data .value ?.data .mime
143+ namespace: data .value ?.data ? .namespace || ' ' ,
144+ path: data .value ?.data ? .path || ' ' ,
145+ mime: data .value ?.data ? .mime || ' ' ,
160146 }
161147 attachements .value .push (fsPart )
162148 $q .notify (' Fichier envoyé' )
163149}
164150
165- const emailReponse = (data : MailinfoPartDto ) => {
166- mailInfo .value .to = data .from .address
167- mailInfo .value .from = data .to [0 ].address
168- mailInfo .value .subject = data .subject .startsWith (' Re:' ) ? data .subject : ` Re:${data .subject } `
169- isFullscreen .value = true
170- }
171-
172151const removeAttachment = (id : string ) => {
173- const { data, error } = useHttpApi (` core/filestorage/${id } ` , {
174- method: ' delete'
152+ const { data, error } = useHttpApi (` /core/filestorage/{_id} ` , {
153+ method: ' delete' ,
154+ pathParams: {
155+ _id: id
156+ }
175157 })
176158 if (error .value ) {
177159 $q .notify ({
@@ -180,19 +162,38 @@ const removeAttachment = (id: string) => {
180162 })
181163 return
182164 }
183- attachements .value = attachements .value .filter (attachement => attachement .id !== id )
165+ attachements .value = attachements .value .filter (attachement => ` ${ attachement .id } ` !== id )
184166 $q .notify (' Fichier supprimé' )
185167}
186168
187- const sendMessage = (type : ThreadType = ThreadType .OUTGOING ) => {
188- const { data : thread, error } = useHttpApi (` tickets/thread ` , {
169+ const editorDialog = ref ()
170+ const isFullscreen = ref (false )
171+ const mailInfo = ref ({
172+ from: ' ' ,
173+ to: ' ' ,
174+ cc: ' ' ,
175+ subject: ' '
176+ })
177+ type MailinfoPartDto = components [" schemas" ][" MailinfoPartDto" ]
178+ const emailReponse = (data : MailinfoPartDto ) => {
179+ mailInfo .value .to = data .from .address
180+ mailInfo .value .from = data .to [0 ].address
181+ mailInfo .value .subject = data .subject .startsWith (' Re:' ) ? data .subject : ` Re:${data .subject } `
182+ isFullscreen .value = true
183+ }
184+
185+ // Manage editor
186+ const threadType = ref (threadTypes [0 ])
187+ const message = ref (' ' )
188+ async function sendMessage(type : ThreadType = ThreadType .OUTGOING ) {
189+ const { data : thread, error } = await useHttpApi (` /tickets/thread ` , {
189190 method: ' post' ,
190191 body: {
191- _id: currentThreadId .value ,
192+ _id: currentThreadId .value ?. toHexString () ,
192193 attachments: attachements .value ,
193- ticketId: generateMongoId (route .params .id .toString ()),
194+ ticketId: generateStringMongoId (route .params .id .toString ()),
194195 fragments: [{
195- id: generateMongoId (),
196+ id: generateStringMongoId (),
196197 disposition: ' raw' ,
197198 message: message .value
198199 }],
@@ -206,7 +207,10 @@ const sendMessage = (type: ThreadType = ThreadType.OUTGOING) => {
206207 }
207208 })
208209
209- if (error && error .value ) {
210+ console .log (' thread' , thread .value )
211+ console .log (' error' , error .value )
212+
213+ if (error .value ) {
210214 $q .notify ({
211215 message: ' Impossible d\' envoyer le message' ,
212216 type: ' negative'
@@ -224,7 +228,6 @@ const sendMessage = (type: ThreadType = ThreadType.OUTGOING) => {
224228 })
225229 emit (' refreshThreadsList' )
226230}
227-
228231const editorDefinitions = computed (() => (
229232 {
230233 fullscreen : {
@@ -236,13 +239,10 @@ const editorDefinitions = computed(() => (
236239 }
237240 }
238241 }))
239-
240242const editorToolbar = computed (() => {
241243 return [[' left' , ' center' , ' right' , ' justify' ], [' bold' , ' italic' , ' underline' , ' strike' ], [' undo' , ' redo' ], [' fullscreen' ]]
242244})
243245
244- const isDisabledTicket = inject (' isDisabledTicket' )
245-
246246defineExpose ({
247247 emailReponse
248248})
0 commit comments