forked from krayin/laravel-crm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkanban.blade.php
More file actions
772 lines (652 loc) · 33.6 KB
/
Copy pathkanban.blade.php
File metadata and controls
772 lines (652 loc) · 33.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
{!! view_render_event('admin.leads.index.kanban.before') !!}
<!-- Kanban Vue Component -->
<v-leads-kanban ref="leadsKanban">
<div class="flex flex-col gap-4">
<!-- Shimmer -->
<x-admin::shimmer.leads.index.kanban />
</div>
</v-leads-kanban>
{!! view_render_event('admin.leads.index.kanban.after') !!}
@pushOnce('scripts')
<script
type="text/x-template"
id="v-leads-kanban-template"
>
<template v-if="isLoading">
<div class="flex flex-col gap-4">
<x-admin::shimmer.leads.index.kanban />
</div>
</template>
<template v-else>
<div class="flex flex-col gap-4">
@include('admin::leads.index.kanban.toolbar')
{!! view_render_event('admin.leads.index.kanban.content.before') !!}
<div class="flex gap-2.5 overflow-x-auto">
<!-- Stage Cards -->
<div
class="flex min-w-[275px] max-w-[275px] flex-col gap-1 rounded-lg border border-gray-200 bg-white dark:border-gray-800 dark:bg-gray-900"
v-for="(stage, index) in stageLeads"
>
{!! view_render_event('admin.leads.index.kanban.content.stage.header.before') !!}
<!-- Stage Header -->
<div class="flex flex-col px-2 py-3">
<!-- Stage Title and Action -->
<div class="flex items-center justify-between">
<span class="text-xs font-medium dark:text-white">
@{{ stage.name }} (@{{ stage.leads.meta.total }})
</span>
@if (bouncer()->hasPermission('leads.create'))
<a
:href="'{{ route('admin.leads.create') }}' + '?stage_id=' + stage.id"
class="icon-add cursor-pointer rounded p-1 text-lg text-gray-600 transition-all hover:bg-gray-200 hover:text-gray-800 dark:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-white"
target="_blank"
>
</a>
@endif
</div>
<!-- Stage Total Leads and Amount -->
<div class="flex items-center justify-between gap-2">
<span class="text-xs font-medium dark:text-white">
@{{ $admin.formatPrice(stage.lead_value) }}
</span>
<!-- Progress Bar -->
<div class="h-1 w-36 overflow-hidden rounded-full bg-gray-200 dark:bg-gray-800">
<div
class="h-1 bg-green-500"
:style="{ width: (stage.lead_value / totalStagesAmount) * 100 + '%' }"
></div>
</div>
</div>
</div>
{!! view_render_event('admin.leads.index.kanban.content.stage.header.after') !!}
{!! view_render_event('admin.leads.index.kanban.content.stage.body.before') !!}
<!-- Draggable Stage Lead Cards -->
<draggable
class="flex h-[calc(100vh-317px)] flex-col gap-2 overflow-y-auto p-2"
:class="{ 'justify-center': stage.leads.data.length === 0 }"
ghost-class="draggable-ghost"
handle=".lead-item"
v-bind="{animation: 200}"
:list="stage.leads.data"
item-key="id"
group="leads"
@scroll="handleScroll(stage, $event)"
@change="handleUpdate(stage, $event)"
>
<template #header>
<div
class="flex flex-col items-center justify-center"
v-if="! stage.leads.data.length"
>
<img
class="dark:mix-blend-exclusion dark:invert"
src="{{ vite()->asset('images/empty-placeholders/pipedrive.svg') }}"
>
<div class="flex flex-col items-center gap-4">
<div class="flex flex-col items-center gap-2">
<p class="!text-base font-semibold dark:text-white">
@lang('admin::app.leads.index.kanban.empty-list')
</p>
<p class="!text-sm text-gray-400 dark:text-gray-400">
@lang('admin::app.leads.index.kanban.empty-list-description')
</p>
</div>
@if (bouncer()->hasPermission('leads.create'))
<a
:href="'{{ route('admin.leads.create') }}' + '?stage_id=' + stage.id"
class="secondary-button"
>
@lang('admin::app.leads.index.kanban.create-lead-btn')
</a>
@endif
</div>
</div>
</template>
<!-- Lead Card -->
<template #item="{ element, index }">
{!! view_render_event('admin.leads.index.kanban.content.stage.body.card.before') !!}
<a
class="lead-item flex cursor-pointer flex-col gap-5 rounded-md border border-gray-100 bg-gray-50 p-2 dark:border-gray-400 dark:bg-gray-400"
:href="'{{ route('admin.leads.view', 'replaceId') }}'.replace('replaceId', element.id)"
>
{!! view_render_event('admin.leads.index.kanban.content.stage.body.card.header.before') !!}
<!-- Header -->
<div class="flex items-start justify-between">
<div class="flex items-center gap-1">
<x-admin::avatar ::name="element.person.name" />
<div class="flex flex-col gap-0.5">
<span class="text-xs font-medium">
@{{ element.person.name }}
</span>
<span class="text-[10px] leading-normal">
@{{ element.person.organization?.name }}
</span>
</div>
</div>
<div
class="group relative"
v-if="element.rotten_days > 0"
>
<span class="icon-rotten cursor-default text-xl text-rose-600"></span>
<div class="absolute -top-1 right-7 hidden w-max flex-col items-center group-hover:flex">
<span class="whitespace-no-wrap relative rounded-md bg-black px-4 py-2 text-xs leading-none text-white shadow-lg">
@{{ "@lang('admin::app.leads.index.kanban.rotten-days', ['days' => 'replaceDays'])".replace('replaceDays', element.rotten_days) }}
</span>
<div class="absolute -right-1 top-2 h-3 w-3 rotate-45 bg-black"></div>
</div>
</div>
</div>
{!! view_render_event('admin.leads.index.kanban.content.stage.body.card.header.after') !!}
{!! view_render_event('admin.leads.index.kanban.content.stage.body.card.title.before') !!}
<!-- Lead Title -->
<p class="text-xs font-medium">
@{{ element.title }}
</p>
{!! view_render_event('admin.leads.index.kanban.content.stage.body.card.title.after') !!}
<div class="flex flex-wrap gap-1">
<div
class="flex items-center gap-1 rounded-xl bg-gray-200 px-2 py-1 text-xs font-medium dark:bg-gray-800 dark:text-white"
v-if="element.user"
>
<span class="icon-settings-user text-sm"></span>
@{{ element.user.name }}
</div>
<div class="rounded-xl bg-gray-200 px-2 py-1 text-xs font-medium dark:bg-gray-800 dark:text-white">
@{{ element.formatted_lead_value }}
</div>
<div class="rounded-xl bg-gray-200 px-2 py-1 text-xs font-medium dark:bg-gray-800 dark:text-white">
@{{ element.source.name }}
</div>
<div class="rounded-xl bg-gray-200 px-2 py-1 text-xs font-medium dark:bg-gray-800 dark:text-white">
@{{ element.type.name }}
</div>
<!-- Tags -->
<template v-for="tag in element.tags">
{!! view_render_event('admin.leads.index.kanban.content.stage.body.card.tag.before') !!}
<div
class="rounded-xl bg-gray-200 px-2 py-1 text-xs font-medium dark:bg-gray-800"
:style="{
backgroundColor: tag.color,
color: tagTextColor[tag.color]
}"
>
@{{ tag.name }}
</div>
{!! view_render_event('admin.leads.index.kanban.content.stage.body.card.tag.after') !!}
</template>
</div>
</a>
{!! view_render_event('admin.leads.index.kanban.content.stage.body.card.after') !!}
</template>
</draggable>
{!! view_render_event('admin.leads.index.kanban.content.stage.body.after') !!}
</div>
</div>
{!! view_render_event('admin.leads.index.kanban.content.after') !!}
</div>
<!-- Show modal for additional information while updating the leads into won or lost stage. -->
<x-admin::form
v-slot="{ meta, errors, handleSubmit }"
as="div"
ref="stageUpdateForm"
>
<form @submit="handleSubmit($event, handleFormSubmit)">
<!-- Modal -->
<x-admin::modal
ref="stageUpdateModal"
@toggle="handleCloseModal"
>
<!-- Header -->
<x-slot:header>
<h3 class="text-base font-semibold dark:text-white">
@lang('admin::app.leads.view.stages.need-more-info')
</h3>
</x-slot>
<!-- Content -->
<x-slot:content>
<x-admin::form.control-group.control
type="hidden"
name="lead_pipeline_stage_id"
::value="finalized.stage.id"
/>
<!-- Won Value -->
<template v-if="finalized.stage.code == 'won'">
<x-admin::form.control-group>
<x-admin::form.control-group.label>
@lang('admin::app.leads.view.stages.won-value')
</x-admin::form.control-group.label>
<x-admin::form.control-group.control
type="price"
name="lead_value"
::value="finalized.lead.lead_value"
/>
</x-admin::form.control-group>
</template>
<!-- Lost Reason -->
<template v-else>
<x-admin::form.control-group>
<x-admin::form.control-group.label>
@lang('admin::app.leads.view.stages.lost-reason')
</x-admin::form.control-group.label>
<x-admin::form.control-group.control
type="textarea"
name="lost_reason"
/>
</x-admin::form.control-group>
</template>
<!-- Closed At -->
<x-admin::form.control-group>
<x-admin::form.control-group.label>
@lang('admin::app.leads.view.stages.closed-at')
</x-admin::form.control-group.label>
<x-admin::form.control-group.control
type="datetime"
name="closed_at"
:label="trans('admin::app.leads.index.kanban.stages.closed-at')"
/>
<x-admin::form.control-group.error control-name="closed_at"/>
</x-admin::form.control-group>
</x-slot>
<!-- Footer -->
<x-slot:footer>
<x-admin::button
class="primary-button"
:title="trans('admin::app.leads.view.stages.save-btn')"
::loading="finalized.updating"
::disabled="finalized.updating"
/>
</x-slot>
</x-admin::modal>
</form>
</x-admin::form>
</template>
</script>
<script type="module">
app.component('v-leads-kanban', {
template: '#v-leads-kanban-template',
data() {
return {
available: {
columns: @json($columns),
},
applied: {
filters: {
columns: [],
}
},
finalized: {
lead: null,
stage: null,
updating: false,
},
stages: @json($pipeline->stages->toArray()),
stageLeads: {},
isLoading: true,
tagTextColor: {
'#FEE2E2': '#DC2626',
'#FFEDD5': '#EA580C',
'#FEF3C7': '#D97706',
'#FEF9C3': '#CA8A04',
'#ECFCCB': '#65A30D',
'#DCFCE7': '#16A34A',
},
};
},
computed: {
/**
* Computes the total amount of leads across all stages.
*
* @return {number} The total amount of leads.
*/
totalStagesAmount() {
let totalAmount = 0;
for (let [key, stage] of Object.entries(this.stageLeads)) {
totalAmount += parseFloat(stage.lead_value);
}
return totalAmount;
}
},
mounted () {
this.boot();
},
methods: {
/**
* Initialization: This function checks for any previously saved filters in local storage and applies them as needed.
*
* @returns {void}
*/
boot() {
let kanbans = this.getKanbans();
if (kanbans?.length) {
const currentKanban = kanbans.find(({ src }) => src === this.src);
if (currentKanban) {
this.applied.filters = currentKanban.applied.filters;
this.get()
.then(response => {
for (let [sortOrder, data] of Object.entries(response.data)) {
this.stageLeads[sortOrder] = data;
}
});
return;
}
}
this.get()
.then(response => {
for (let [sortOrder, data] of Object.entries(response.data)) {
this.stageLeads[sortOrder] = data;
}
});
},
/**
* Fetches the leads based on the applied filters.
*
* @param {object} requestedParams - The requested parameters.
* @returns {Promise} The promise object representing the request.
*/
get(requestedParams = {}) {
let params = {
search: '',
searchFields: '',
pipeline_id: "{{ request('pipeline_id') }}",
limit: 10,
};
this.applied.filters.columns.forEach((column) => {
if (column.index === 'all') {
if (! column.value.length) {
return;
}
params['search'] += `title:${column.value.join(',')};`;
params['searchFields'] += `title:like;`;
return;
}
/**
* If the column is a searchable dropdown, then we need to append the column value
* with the column label. Otherwise, we can directly append the column value.
*/
params['search'] += column.filterable_type === 'searchable_dropdown'
? `${column.index}:${column.value.map(option => option.value).join(',')};`
: `${column.index}:${column.value.join(',')};`;
params['searchFields'] += `${column.index}:${column.search_field};`;
});
return this.$axios
.get("{{ route('admin.leads.get') }}", {
params: {
...params,
...requestedParams,
}
})
.then(response => {
this.isLoading = false;
this.updateKanbans();
return response;
})
.catch(error => {
console.log(error)
});
},
/**
* Filters the leads based on the applied filters.
*
* @param {object} filters - The filters to be applied.
* @returns {void}
*/
filter(filters) {
this.applied.filters.columns = [
...(this.applied.filters.columns.filter((column) => column.index === 'all')),
...filters.columns,
];
this.get()
.then(response => {
for (let [sortOrder, data] of Object.entries(response.data)) {
this.stageLeads[sortOrder] = data;
}
});
},
/**
* Searches the leads based on the applied filters.
*
* @param {object} filters - The filters to be applied.
* @returns {void}
*/
search(filters) {
this.applied.filters.columns = [
...(this.applied.filters.columns.filter((column) => column.index !== 'all')),
...filters.columns,
];
this.get()
.then(response => {
for (let [sortOrder, data] of Object.entries(response.data)) {
this.stageLeads[sortOrder] = data;
}
});
},
/**
* Appends the leads to the stage.
*
* @param {object} params - The parameters to be appended.
* @returns {void}
*/
append(params) {
this.get(params)
.then(response => {
for (let [sortOrder, data] of Object.entries(response.data)) {
if (! this.stageLeads[sortOrder]) {
this.stageLeads[sortOrder] = data;
} else {
this.stageLeads[sortOrder].leads.data = this.stageLeads[sortOrder].leads.data.concat(data.leads.data);
this.stageLeads[sortOrder].leads.meta = data.leads.meta;
}
}
});
},
/**
* Updates the stage with the latest lead data.
*
* @param {object} stage - The stage object.
* @param {object} event - The event object.
* @returns {void}
*/
handleUpdate(stage, event) {
if (event.moved) {
return;
}
if (
(stage.code === "won" || stage.code === "lost")
&& event.added
&& event.added.element
) {
this.finalized.lead = event.added.element;
this.finalized.stage = stage;
this.toggleStageUpdateModal();
return;
}
if (event.removed) {
stage.lead_value = parseFloat(stage.lead_value) - parseFloat(event.removed.element.lead_value);
this.stageLeads[stage.sort_order].leads.meta.total = this.stageLeads[stage.sort_order].leads.meta.total - 1;
return;
}
stage.lead_value = parseFloat(stage.lead_value) + parseFloat(event.added.element.lead_value);
this.stageLeads[stage.sort_order].leads.meta.total = this.stageLeads[stage.sort_order].leads.meta.total + 1;
this.updateStage('{{ route('admin.leads.stage.update', '__LEAD_ID__') }}'.replace('__LEAD_ID__', event.added.element.id), {
'lead_pipeline_stage_id': stage.id
})
.then(response => {
this.$emitter.emit('add-flash', { type: 'success', message: response.data.message });
})
.catch(error => {
this.$emitter.emit('add-flash', { type: 'error', message: error.response.data.message });
});;
},
/**
* Updates the stage with the latest lead data.
*
* @param {string} url - The URL to update the stage.
* @param {object} params - The parameters to be updated.
*
* @returns {Promise} The promise object representing the request.
*/
updateStage(url, params) {
return this.$axios.put(url, params);
},
handleFormSubmit(params) {
this.finalized.updating = true;
this.updateStage("{{ route('admin.leads.stage.update', '__LEAD_ID__') }}".replace('__LEAD_ID__', this.finalized.lead.id), {
...params,
lead_pipeline_stage_id: this.finalized.stage.id,
})
.then(response => {
this.toggleStageUpdateModal();
this.resetFinalized();
this.get()
.then(response => {
for (let [sortOrder, data] of Object.entries(response.data)) {
this.stageLeads[sortOrder] = data;
}
});
this.$emitter.emit('add-flash', { type: 'success', message: response.data.message });
})
.catch(error => {
this.$emitter.emit('add-flash', { type: 'error', message: error.response.data.message });
}).finally(() => {
this.finalized.updating = false;
});
},
/**
* Resets the finalized lead and stage data.
*
* @returns {void}
*/
resetFinalized() {
this.finalized = {
lead: null,
stage: null,
updating: false,
};
},
/**
* Handles the close event of the modal.
*
* @returns {void}
*/
handleCloseModal(state) {
if (state.isActive) {
return;
}
this.resetFinalized();
this.get()
.then(response => {
for (let [sortOrder, data] of Object.entries(response.data)) {
this.stageLeads[sortOrder] = data;
}
});
},
/**
* Toggles the stage update modal.
*
* @returns {void}
*/
toggleStageUpdateModal() {
this.$refs.stageUpdateModal.toggle();
},
/**
* Handles the scroll event on the stage leads.
*
* @param {object} stage - The stage object.
* @param {object} event - The scroll event.
* @returns {void}
*/
handleScroll(stage, event) {
const bottom = event.target.scrollHeight - event.target.scrollTop === event.target.clientHeight;
if (! bottom) {
return;
}
if (this.stageLeads[stage.sort_order].leads.meta.current_page == this.stageLeads[stage.sort_order].leads.meta.last_page) {
return;
}
this.append({
pipeline_stage_id: stage.id,
pipeline_id: stage.lead_pipeline_id,
page: this.stageLeads[stage.sort_order].leads.meta.current_page + 1,
limit: 10,
});
},
//=======================================================================================
// Support for previous applied values in kanban's. All code is based on local storage.
//=======================================================================================
/**
* Updates the kanban's stored in local storage with the latest data.
*
* @returns {void}
*/
updateKanbans() {
let kanbans = this.getKanbans();
if (kanbans?.length) {
const currentKanban = kanbans.find(({ src }) => src === this.src);
if (currentKanban) {
kanbans = kanbans.map(kanban => {
if (kanban.src === this.src) {
return {
...kanban,
requestCount: ++kanban.requestCount,
available: this.available,
applied: this.applied,
};
}
return kanban;
});
} else {
kanbans.push(this.getKanbanInitialProperties());
}
} else {
kanbans = [this.getKanbanInitialProperties()];
}
this.setKanbans(kanbans);
},
/**
* Returns the initial properties for a kanban.
*
* @returns {object} Initial properties for a kanban.
*/
getKanbanInitialProperties() {
return {
src: this.src,
requestCount: 0,
available: this.available,
applied: this.applied,
};
},
/**
* Returns the storage key for kanban's in local storage.
*
* @returns {string} Storage key for kanban's.
*/
getKanbansStorageKey() {
return 'kanbans';
},
/**
* Retrieves the kanban's stored in local storage.
*
* @returns {Array} Kanban's stored in local storage.
*/
getKanbans() {
let kanbans = localStorage.getItem(
this.getKanbansStorageKey()
);
return JSON.parse(kanbans) ?? [];
},
/**
* Sets the kanban's in local storage.
*
* @param {Array} kanbans - Kanban's to be stored in local storage.
* @returns {void}
*/
setKanbans(kanbans) {
localStorage.setItem(
this.getKanbansStorageKey(),
JSON.stringify(kanbans)
);
},
}
});
</script>
@endPushOnce