1212 </div >
1313
1414 <ListView
15- v-if =" links.list.data"
16- rowKey =" name"
17- :columns =" [{
18- label: 'Short Link',
19- key: 'name',
20- width: 0.3
21- },
22- {
23- label: 'Destination',
24- key: 'destination_url'
25- },
26- {
27- label: 'Description',
28- key: 'description'
29- }]"
15+ v-if =" links.list.data"
16+ rowKey =" name"
17+ :columns =" [{
18+ label: 'Short Link',
19+ key: 'name',
20+ width: 0.3
21+ },
22+ {
23+ label: 'Destination',
24+ key: 'destination_url'
25+ },
26+ {
27+ key: 'copy_to_clipboard'
28+ },
29+ {
30+ key: 'more_actions'
31+ },]"
3032
3133 :rows =" links.list.data"
3234
3335 :options =" {
3436 showTooltip: false,
3537 selectable: false,
36- onRowClick: (row) => {
37- editDialogShown = true
38- Object.assign(newLink, row)
39- },
38+ // onRowClick: (row) => {
39+ // editDialogShown = true
40+ // Object.assign(newLink, row)
41+ // },
4042 emptyState: {
4143 title: 'No links found',
4244 description: 'Create a new short link to get started',
4951 },
5052 }
5153 }"
52- />
54+ >
55+ <template #cell =" { item , row , column } " >
56+ <Button v-if =" column.key === 'copy_to_clipboard'" class =" cursor-pointer" icon =" copy" @click.stop =" copyShortLinkToClipboard(row.name)" variant =" outline" theme =" blue" ></Button >
57+
58+ <Dropdown
59+ v-else-if =" column.key === 'more_actions'"
60+ :options =" [
61+ {'label': 'Show QR Code', onClick: () => {
62+ if (!row.qr_code) {
63+ toast.warning('No QR Code found!')
64+ return;
65+ }
66+ qrCodeLink = row.qr_code;
67+ qrCodeShown = true;
68+ }}
69+ ]"
70+ >
71+ <Button icon =" more-horizontal" />
72+ </Dropdown >
73+
74+ <span v-else class =" font-medium text-ink-gray-7" >
75+ {{ item }}
76+ </span >
77+ </template >
78+ </ListView >
5379
5480
5581 <Dialog :options =" {
147173 <ErrorMessage class =" mt-2" :message =" links.insert.error" />
148174 </template >
149175 </Dialog >
176+
177+
178+ <Dialog
179+ v-model =" qrCodeShown"
180+ :options =" {
181+ title: 'QR Code'
182+ }"
183+ >
184+ <template #body-content >
185+ <div class =" flex justify-center items-center" >
186+ <img v-if =" qrCodeLink" :src =" qrCodeLink" alt =" QR Code for short link" >
187+ </div >
188+ </template >
189+ </Dialog >
150190 </div >
151191</template >
152192
153193<script setup>
154194import { ref } from " vue" ;
155195import { onKeyStroke } from " @vueuse/core" ;
156- import { ListView , Dialog , FormControl , ErrorMessage } from " frappe-ui" ;
196+ import { ListView , Dialog , FormControl , ErrorMessage , Dropdown } from " frappe-ui" ;
157197import { createListResource } from " frappe-ui" ;
158198import { reactive } from " vue" ;
159199import { toast } from ' vue-sonner'
160200
161201const createDialogShown = ref (false );
162202const editDialogShown = ref (false );
203+ const qrCodeShown = ref (false );
204+ const qrCodeLink = ref (null );
205+
163206const newLink = reactive ({
164207 short_link: " " ,
165208 destination_url: " " ,
@@ -172,7 +215,7 @@ onKeyStroke(["c", "C"], () => {
172215
173216const links = createListResource ({
174217 doctype: " Short Link" ,
175- fields: [" name" , " destination_url" , " description" ],
218+ fields: [" name" , " destination_url" , " description" , " qr_code " ],
176219 orderBy: " creation desc" ,
177220});
178221
@@ -188,11 +231,15 @@ function createShortLink(close) {
188231 newLink .short_link = " " ;
189232 newLink .description = " " ;
190233 newLink .destination_url = " " ;
191- navigator .clipboard .writeText (` ${ window .location .origin } /${ newLink .short_link } ` );
192- toast .success (" Link copied to clipboard!" )
234+ copyShortLinkToClipboard (newLink .short_link )
193235 close ();
194236 },
195237 },
196238 );
197239}
240+
241+ function copyShortLinkToClipboard (text ) {
242+ navigator .clipboard .writeText (` ${ window .location .origin } /${ text} ` );
243+ toast .success (" Link copied to clipboard!" )
244+ }
198245 </script >
0 commit comments