33 q-card( flat )
44 q-card-section( horizontal )
55 q-card-section.full-width ( :style ="{maxWidth: '50vw', overflow: 'hidden'}" )
6- q-table.my -sticky-last-column-table (
6+ q-table.tk -sticky-last-column-table (
77 v-model:selected ="selected"
88 v-model:pagination ="pagination"
99 title ="Mails"
10- :rows ="tickets .data"
10+ :rows ="mails? .data"
1111 row-key ="uid"
1212 @request ="onRequest"
1313 :rows-per-page-options ="[5, 10, 15]"
1919 no-results-label ="Aucun résultat"
2020 selection ="multiple"
2121 :pagination-label ="(firstRowIndex, endRowIndex, totalRowsNumber) => `${firstRowIndex}-${endRowIndex} sur ${totalRowsNumber} lignes`"
22- :selected-rows-label ="(numberOfRows) => `${numberOfRows} tickets sélectionnées`"
22+ :selected-rows-label ="(numberOfRows) => `${numberOfRows} Mails sélectionnées`"
2323 flat
2424 )
2525 template( #body-cell-actions ="props" )
2626 q-td( :props ="props" )
2727 q-btn-group( flat rounded )
2828 q-btn( icon ="mdi-eye" color ="primary" @click ="goToMail(props.row)" size ="sm" flat )
2929 q-tooltip.text-body2 ( transition-show ="scale" transition-hide ="scale" ) Afficher le ticket
30- q-btn( icon ="mdi-delete" color ="primary" @click ="" size ="sm" flat )
30+ q-btn( icon ="mdi-delete" color ="primary" @click ="deleteMail(props.row) " size ="sm" flat )
3131 q-tooltip.text-body2 ( transition-show ="scale" transition-hide ="scale" ) Supprimer le ticket
3232 q-separator( vertical )
3333 q-card-section.full-width ( :style ="{maxWidth: '50vw', overflow: 'hidden'}" )
34- q-card
34+ div.flex.items-center.full-height.justify-center ( v-if ='!target' )
35+ p Selectionnez un email pour afficher son contenu...
36+ q-card( v-else )
3537 q-card-actions
3638 q-toolbar-title( v-text ='target?.subject' style ='flex: 100 1 0%' )
3739 q-space
38- q-btn( color ="negative" icon ='mdi-delete' @click ="" )
39- q-btn( color ="info" icon ='mdi-email-arrow-right-outline' @click ="" )
40- q-btn( color ="primary" icon ='mdi-content-save' @click ="" )
40+ q-btn( color ="negative" icon ='mdi-delete' @click ="deleteMail(target)" )
41+ q-btn( color ="primary" icon ='mdi-content-save' @click ="importMail(target)" )
4142 q-card-section.q-pa-xs
4243 q-tabs( v-model ="tab" dense )
43- q-tab( name ="mails" icon ="mdi-mail" label ="Mails" )
44- q-tab( name ="raw" icon ="mdi-square" label ="raw" )
44+ q-tab( name ="email" icon ="mdi-mail" label ="Email" )
45+ q-tab( name ="headers" icon ="mdi-format-list-text" label ="headers" )
46+ q-tab( name ="raw" icon ="mdi-email-newsletter" label ="Contenu" )
4547 q-tab-panels( v-model ="tab" )
46- q-tab-panel.no-padding ( name ="mails" )
47- object( :data ='"http://localhost:7100/tickets/mails/" + target?.uid + "/source"' style ='width: 100%; height: 75vh;' )
48- q-tab-panel.no-padding ( name ="raw" )
48+ q-tab-panel.no-padding ( name ="email" )
49+ object.bg-white ( :data ='"http://localhost:7100/tickets/mails/" + target?.accountId + "/" + target?.seq + "/render?signature=" + target?.signature' style ='width: 100%; height: 75vh;' )
50+ p Impossible de charger le contenu du mail
51+ a( :href ='"http://localhost:7100/tickets/mails/" + target?.accountId + "/" + target?.seq + "/render?signature=" + target?.signature' target ='_blank' ) Lien direct
52+ q-tab-panel.no-padding ( name ="headers" )
4953 q-table(
5054 :rows ="target.headers"
5155 :pagination ='{rowsPerPage: 12}'
5660 no-results-label ="Aucun résultat"
5761 flat
5862 )
63+ q-tab-panel.no-padding ( name ="raw" )
64+ object.bg-white ( :data ='"http://localhost:7100/tickets/mails/" + target?.accountId + "/" + target?.seq + "/source?signature=" + target?.signature' style ='width: 100%; height: 75vh;' )
65+ p Impossible de charger le contenu du mail
66+ a( :href ='"http://localhost:7100/tickets/mails/" + target?.accountId + "/" + target?.seq + "/source?signature=" + target?.signature' target ='_blank' ) Lien direct
5967</template >
6068
6169<script lang="ts">
@@ -64,14 +72,14 @@ import { useRoute, useRouter } from 'nuxt/app'
6472import { ref } from ' vue'
6573import type { QTableProps } from ' quasar'
6674import type { components } from ' #build/types/service-api'
75+ import { omit } from ' radash'
6776
6877type Ticket = components [" schemas" ][' TicketDto' ]
78+ const route = useRoute ()
6979
7080export default defineNuxtComponent ({
7181 data : () => ({
72- tab: ref (' ' ),
7382 selected: ref <Ticket []>([]),
74- target: ref <Ticket | null >(null ),
7583 pagination: ref <QTableProps [' pagination' ]>({
7684 page: 1 ,
7785 rowsPerPage: 10 ,
@@ -80,14 +88,30 @@ export default defineNuxtComponent({
8088 }),
8189 async setup() {
8290 const route = useRoute ()
83- const { data : tickets, pending, refresh, error } = await useHttpApi (' /tickets/mails' , {
91+ let tab = ref (' ' )
92+ let target = ref <Ticket | null >(null )
93+ const { data : mails, pending, refresh, error } = await useHttpApi (' /tickets/mails' , {
8494 method: ' get' ,
8595 query: computed (() => {
8696 return {
87- ... route .query ,
97+ ... omit ( route .query , [ ' accountId ' , ' seq ' ]) ,
8898 }
8999 })
90100 })
101+ if (error .value ) {
102+ console .error (error .value )
103+ }
104+ if (route .query .accountId && route .query .seq ) {
105+ const { data } = await useHttpApi (` /tickets/mails/${route .query .accountId }/${route .query .seq } ` , {
106+ method: ' get' ,
107+ })
108+ const mail = mails .value .data .filter ((mail : any ) => mail .accountId === route .query .accountId && mail .seq === parseInt (` ${route .query .seq } ` , 10 ))[0 ]
109+ target .value = {
110+ ... data .value ?.data ,
111+ ... mail ,
112+ }
113+ tab .value = ' email'
114+ }
91115 const daysjs = useDayjs ()
92116 const columns = ref <QTableProps [' columns' ]>([
93117 {
@@ -96,6 +120,12 @@ export default defineNuxtComponent({
96120 field: ' uid' ,
97121 align: ' left' ,
98122 },
123+ {
124+ name: ' accountName' ,
125+ label: ' Compte' ,
126+ field: ' accountName' ,
127+ align: ' left' ,
128+ },
99129 {
100130 name: ' envelope.subject' ,
101131 label: ' Sujet' ,
@@ -128,37 +158,88 @@ export default defineNuxtComponent({
128158 },
129159 ])
130160 return {
161+ tab ,
162+ target ,
131163 columns ,
132- tickets ,
164+ mails ,
133165 pending ,
134166 refresh ,
135167 error ,
136168 }
137169 },
138170 methods: {
139- async goToMail(ticket : Ticket ) {
140- const route = useRoute ()
171+ async deleteMail(mail : any ) {
172+ this .$q .dialog ({
173+ title: ' Suppression' ,
174+ message: ' Vous êtes sur le point de supprimer un email, êtes-vous sûr ?' ,
175+ cancel: true ,
176+ persistent: true ,
177+ color: ' negative' ,
178+ }).onOk (async () => {
179+ const { error } = await useHttpApi (` /tickets/mails/${mail .accountId }/${mail .seq } ` , {
180+ method: ' delete' ,
181+ })
182+ if (error .value ) {
183+ this .$q .notify ({
184+ color: ' negative' ,
185+ message: ` Impossible de supprimer l'email: ${mail .uid } ` ,
186+ })
187+ return
188+ }
189+ this .$q .notify ({
190+ color: ' positive' ,
191+ message: ' Email supprimé avec succès' ,
192+ })
193+ this .target = null
194+ await this .refresh ()
195+ }).onCancel (() => this .target = null )
196+ },
197+ async importMail(mail : any ) {
198+ const { data, error } = await useHttpApi (` /tickets/mails/import ` , {
199+ method: ' post' ,
200+ body: {
201+ account: mail .accountId ,
202+ seq: mail .seq ,
203+ uid: mail .uid ,
204+ id: mail .id ,
205+ },
206+ })
207+ console .log (data .value )
208+ if (error .value ) {
209+ console .log ()
210+ this .$q .notify ({
211+ color: ' negative' ,
212+ message: ` Impossible d\' importer l'email <${mail .uid }> ${error .value ?.data ?.message || error .value ?.message } ` ,
213+ })
214+ return
215+ }
216+ this .$q .notify ({
217+ color: ' positive' ,
218+ message: ' Email importé avec succès' ,
219+ })
220+ await this .refresh ()
221+ },
222+ async goToMail(mail : any ) {
141223 const router = useRouter ()
142224 router .replace ({
143225 query: {
144226 ... route .query ,
145- uid: ticket .uid ,
227+ accountId: mail .accountId ,
228+ seq: mail .seq ,
146229 }
147230 })
148- const { data : mail, pending, refresh, error } = await useHttpApi (` /tickets/mails/${ticket . uid } ` , {
231+ const { data } = await useHttpApi (` /tickets/mails/${mail . accountId }/${ mail . seq } ` , {
149232 method: ' get' ,
150- query: computed (() => {
151- return {
152- ... route .query ,
153- }
154- })
155233 })
156- this .target = mail .value ?.data
157- this .tab = ' mails'
234+ this .target = {
235+ ... mail ,
236+ ... data .value ?.data ,
237+ }
238+ this .tab = ' email'
158239 },
159240 async onRequest(props : QTableProps ) {
160241 const { page, rowsPerPage, sortBy, descending } = props .pagination
161- this .pagination ! .rowsNumber = this .tickets ?.total
242+ this .pagination ! .rowsNumber = this .mails ?.total
162243 this .pagination ! .page = page
163244 this .pagination ! .rowsPerPage = rowsPerPage
164245 this .pagination ! .sortBy = sortBy
@@ -189,7 +270,7 @@ export default defineNuxtComponent({
189270 },
190271 async mounted() {
191272 const route = useRoute ()
192- this .pagination ! .rowsNumber = this .tickets ?.total
273+ this .pagination ! .rowsNumber = this .mails ?.total
193274 const query = { ... route .query }
194275 const limit = query .limit ?? 10
195276 const skip = query .skip ?? 0
@@ -210,16 +291,3 @@ export default defineNuxtComponent({
210291 },
211292})
212293 </script >
213- <style lang="sass">
214- @import " quasar/src/css/variables.sass"
215- .my-sticky-last-column-table
216- thead tr :last-child th :last-child
217- background-color : $menu-background
218- td :last-child
219- background-color : $menu-background
220- th :last-child ,
221- td :last-child
222- position : sticky
223- right : -1px
224- z-index : 1
225- </style >
0 commit comments