Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 125x 129x 129x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 6x 6x 6x 125x 5x 5x 5x 5x 5x 5x 125x 125x 125x 125x 125x 125x 125x 125x 4x 4x 4x 4x 4x 4x 3x 3x 3x 1x 1x 1x 1x 2x 2x 125x 125x 127x 125x 125x 125x 125x 125x 127x 127x 126x 125x 125x 125x 125x 125x 126x 125x 125x 125x 125x 125x 125x 125x 125x | import { css, html, TemplateResult } from 'lit';
import { ContentList, ContentListColumn } from './ContentList';
import { Icon } from '../Icons';
import { Campaign, CustomEventType, ObjectReference } from '../interfaces';
/**
* Campaign CRUDL list — drop-in replacement for the rapidpro
* `campaigns/campaign_list.html` table. Every row leads with the
* campaign clock icon (from the styleguide's campaign list), then
* name, the group pill the campaign schedules against, contact /
* event counts, and the last-updated date.
*/
export class CampaignList extends ContentList<Campaign> {
static get styles() {
return css`
${ContentList.styles}
.campaign-name {
color: inherit;
font-weight: var(--w-medium);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.num {
font-variant-numeric: tabular-nums;
color: inherit;
}
`;
}
constructor() {
super();
this.valueKey = 'uuid';
this.emptyMessage = 'No campaigns';
this.searchPlaceholder = 'Search campaigns';
this.columns = [
{
key: 'name',
label: 'Name',
sortable: true,
minWidth: '160px',
maxWidth: '280px',
pinned: true
},
{
key: 'group',
label: 'Group',
minWidth: '120px',
maxWidth: '220px'
},
{
key: 'contacts',
label: 'Contacts',
sortable: true,
minWidth: '72px',
align: 'right'
},
{
key: 'events',
label: 'Events',
sortable: true,
minWidth: '64px',
align: 'right'
},
{
key: 'modified_on',
label: 'Updated',
sortable: true,
minWidth: '96px',
maxWidth: '150px',
align: 'right'
}
];
this.bulkActions = [
{ key: 'archive', label: 'Archive', icon: Icon.archive }
];
}
protected getRowIcon(_item: Campaign): string | null {
return Icon.campaign;
}
protected getRowHref(item: Campaign): string | null {
return item?.uuid ? `/campaign/read/${item.uuid}/` : null;
}
/** Clicking the group pill opens that group's contact list rather
* than falling through to the row click (which opens the campaign). */
private handleGroupClick(group: ObjectReference, event: MouseEvent): void {
// Stop the click from bubbling to the row's navigation handler.
event.stopPropagation();
if (!group?.uuid) return;
const href = `/contact/group/${group.uuid}/`;
// Guard the JSON-driven href against open-redirect, same as the
// row-click path in ContentList.handleRowClick.
if (!this.isSafeHref(href)) return;
// Meta/ctrl-click opens a new tab, matching ordinary links and the
// row-click behavior.
if (event.metaKey || event.ctrlKey) {
window.open(href, '_blank');
return;
}
this.fireCustomEvent(CustomEventType.Redirected, { url: href });
}
protected renderCell(
item: Campaign,
column: ContentListColumn
): TemplateResult | string {
switch (column.key) {
case 'name':
return html`<span class="campaign-name" title=${item.name || ''}
>${item.name || ''}</span
>`;
case 'group':
return item.group
? html`<temba-label
type="group"
icon=${Icon.group}
clickable
@click=${(e: MouseEvent) => this.handleGroupClick(item.group, e)}
>${item.group.name}</temba-label
>`
: '';
case 'events':
return html`<span class="num"
>${(item.events ?? 0).toLocaleString()}</span
>`;
case 'contacts':
return html`<span class="num"
>${(item.contacts ?? 0).toLocaleString()}</span
>`;
case 'modified_on':
return item.modified_on
? html`<temba-date
value=${item.modified_on}
display="timedate"
></temba-date>`
: '';
default:
return super.renderCell(item, column);
}
}
}
|