|
10 | 10 |
|
11 | 11 | const svelteDispatch = createEventDispatcher(); |
12 | 12 |
|
13 | | - const allActions = [ |
14 | | - UserAction.Edit, |
15 | | - UserAction.Chat |
16 | | - ]; |
17 | | -
|
18 | | - const colStyle = `flex: 0 0 ${allActions.length > 2 ? Math.floor(1 / (allActions.length + 1) * 100) - 1 : 32}%;`; |
19 | 13 |
|
20 | 14 | /** @type {import('$userTypes').UserModel} */ |
21 | 15 | export let item; |
|
36 | 30 | /** @type {import('$userTypes').UserAgentInnerAction[]} */ |
37 | 31 | let innerActions = []; |
38 | 32 |
|
| 33 | + let allActions = [ |
| 34 | + { |
| 35 | + name: UserAction.Edit, |
| 36 | + value: UserAction.Edit, |
| 37 | + checked: false |
| 38 | + }, |
| 39 | + { |
| 40 | + name: UserAction.Chat, |
| 41 | + value: UserAction.Chat, |
| 42 | + checked:false |
| 43 | + } |
| 44 | + ]; |
| 45 | +
|
| 46 | + const colStyle = `flex: 0 0 ${allActions.length > 2 ? Math.floor(1 / (allActions.length + 1) * 100) - 1 : 32}%;`; |
| 47 | +
|
| 48 | + $: { |
| 49 | + allActions = allActions.map(x => { |
| 50 | + const list = innerActions.flatMap(a => a.actions.filter(y => y.value === x.value)); |
| 51 | + x.checked = list.every(a => !!a.checked); |
| 52 | + return { ...x }; |
| 53 | + }); |
| 54 | + } |
| 55 | +
|
39 | 56 | onMount(() => { |
40 | 57 | initInnerItem(); |
41 | 58 | initAgentActions(); |
|
57 | 74 | actions: allActions.map(a => { |
58 | 75 | return { |
59 | 76 | key: uuidv4(), |
60 | | - value: a, |
| 77 | + value: a.value, |
61 | 78 | checked: false |
62 | 79 | }; |
63 | 80 | }) |
64 | 81 | } |
65 | 82 | } |
66 | 83 |
|
67 | 84 | const actions = allActions.map(a => { |
68 | | - const checked = !!found.actions.find(y => y === a) || false; |
| 85 | + const checked = !!found.actions.find(y => y === a.value) || false; |
69 | 86 | return { |
70 | 87 | key: uuidv4(), |
71 | | - value: a, |
| 88 | + value: a.value, |
72 | 89 | checked: checked |
73 | 90 | }; |
74 | 91 | }); |
|
93 | 110 |
|
94 | 111 | /** |
95 | 112 | * @param {any} e |
96 | | - * @param {any} agentActionItem |
| 113 | + * @param {import('$userTypes').UserAgentInnerAction} agentActionItem |
97 | 114 | * @param {any} actionItem |
98 | 115 | */ |
99 | 116 | function checkAction(e, agentActionItem, actionItem) { |
|
104 | 121 | if (action) { |
105 | 122 | action.checked = checked; |
106 | 123 | } |
| 124 | +
|
| 125 | + innerActions = [ ...innerActions ]; |
| 126 | + } |
| 127 | +
|
| 128 | + /** |
| 129 | + * @param {any} e |
| 130 | + * @param {any} title |
| 131 | + */ |
| 132 | + function checkAll(e, title) { |
| 133 | + const checked = e.target.checked; |
| 134 | + allActions = allActions.map(x => { |
| 135 | + if (x.value === title.value) { |
| 136 | + x.checked = checked; |
| 137 | + } |
| 138 | + return { ...x }; |
| 139 | + }); |
| 140 | +
|
| 141 | + innerActions = innerActions.map(x => { |
| 142 | + const actions = x.actions.map(a => { |
| 143 | + if (a.value === title.value) { |
| 144 | + a.checked = checked; |
| 145 | + } |
| 146 | + return { ...a }; |
| 147 | + }); |
| 148 | +
|
| 149 | + return { |
| 150 | + ...x, |
| 151 | + actions: actions |
| 152 | + }; |
| 153 | + }); |
107 | 154 | } |
108 | 155 |
|
109 | 156 | /** @param {string} id */ |
|
123 | 170 | svelteDispatch("save", { |
124 | 171 | updatedData: data |
125 | 172 | }); |
126 | | - open = false; |
127 | 173 | } |
128 | 174 | }); |
129 | 175 | } |
|
185 | 231 | <tr in:fly={{ y: -5, duration: 800 }} out:fly={{ y: -5, duration: 300 }}> |
186 | 232 | <td colspan="12"> |
187 | 233 | <div class="user-detail"> |
| 234 | + <div class="edit-btn"> |
| 235 | + <!-- svelte-ignore a11y-click-events-have-key-events --> |
| 236 | + <!-- svelte-ignore a11y-no-static-element-interactions --> |
| 237 | + <div |
| 238 | + class="text-primary clickable" |
| 239 | + data-bs-toggle="tooltip" |
| 240 | + data-bs-placement="top" |
| 241 | + title="Save" |
| 242 | + on:click={() => save(item.id)} |
| 243 | + > |
| 244 | + <i class="mdi mdi-content-save-all" /> |
| 245 | + </div> |
| 246 | + </div> |
188 | 247 | <ul class="basic-info"> |
189 | 248 | <li> |
190 | 249 | <div class="wrappable"> |
|
234 | 293 | {/if} |
235 | 294 | </ul> |
236 | 295 | {#if innerActions.length > 0} |
237 | | - <div class="user-agent-container"> |
238 | | - <div class="action-row action-title"> |
239 | | - <div class="action-col action-title-text fw-bold" style={colStyle}> |
240 | | - {'Agent'} |
241 | | - </div> |
242 | | - {#each allActions as title} |
243 | | - <div class="action-col action-title-text fw-bold" style={colStyle}> |
244 | | - {title} |
| 296 | + <div class="user-agent-container"> |
| 297 | + <div class="action-row action-title"> |
| 298 | + <div class="action-col action-title-wrapper fw-bold" style={colStyle}> |
| 299 | + {'Agent'} |
245 | 300 | </div> |
246 | | - {/each} |
247 | | - </div> |
248 | | - <div class="action-row-wrapper"> |
249 | | - {#each innerActions as agentActionItem} |
250 | | - <div class="action-row"> |
251 | | - <div class="action-col fw-bold" style={colStyle}> |
252 | | - {agentActionItem.agent_name} |
253 | | - </div> |
254 | | - {#each agentActionItem.actions as actionItem} |
255 | | - <div class="action-col action-center" style={colStyle}> |
| 301 | + {#each allActions as title} |
| 302 | + <div class="action-col action-title-wrapper fw-bold" style={colStyle}> |
| 303 | + <div>{title.name}</div> |
| 304 | + <div> |
256 | 305 | <Input |
257 | 306 | type="checkbox" |
258 | 307 | class="action-center" |
259 | | - checked={actionItem.checked} |
260 | | - on:change={e => checkAction(e, agentActionItem, actionItem)} |
| 308 | + checked={title.checked} |
| 309 | + on:change={e => checkAll(e, title)} |
261 | 310 | /> |
262 | 311 | </div> |
263 | | - {/each} |
264 | | - </div> |
265 | | - {/each} |
| 312 | + </div> |
| 313 | + {/each} |
| 314 | + </div> |
| 315 | + <div class="action-row-wrapper"> |
| 316 | + {#each innerActions as agentActionItem} |
| 317 | + <div class="action-row"> |
| 318 | + <div class="action-col fw-bold" style={colStyle}> |
| 319 | + {agentActionItem.agent_name} |
| 320 | + </div> |
| 321 | + {#each agentActionItem.actions as actionItem} |
| 322 | + <div class="action-col action-center" style={colStyle}> |
| 323 | + <Input |
| 324 | + type="checkbox" |
| 325 | + class="action-center" |
| 326 | + checked={actionItem.checked} |
| 327 | + on:change={e => checkAction(e, agentActionItem, actionItem)} |
| 328 | + /> |
| 329 | + </div> |
| 330 | + {/each} |
| 331 | + </div> |
| 332 | + {/each} |
| 333 | + </div> |
266 | 334 | </div> |
267 | | - </div> |
268 | 335 | {/if} |
269 | | - <div class="edit-btn"> |
270 | | - <!-- svelte-ignore a11y-click-events-have-key-events --> |
271 | | - <!-- svelte-ignore a11y-no-static-element-interactions --> |
272 | | - <div |
273 | | - class="text-primary clickable" |
274 | | - data-bs-toggle="tooltip" |
275 | | - data-bs-placement="top" |
276 | | - title="Save" |
277 | | - on:click={() => save(item.id)} |
278 | | - > |
279 | | - <i class="mdi mdi-content-save-all" /> |
280 | | - </div> |
281 | | - </div> |
282 | 336 | </div> |
283 | 337 | </td> |
284 | 338 | </tr> |
|
0 commit comments