AdvancedTable.vue 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555
  1. <template>
  2. <div>
  3. <div
  4. class="table-outer-container"
  5. @mousemove="columnResizing($event)"
  6. @touchmove="columnResizing($event)"
  7. >
  8. <div class="table-header">
  9. <div>
  10. <tippy
  11. v-if="filters.length > 0"
  12. :touch="true"
  13. :interactive="true"
  14. placement="bottom-start"
  15. theme="search"
  16. ref="search"
  17. trigger="click"
  18. @show="
  19. () => {
  20. showFiltersDropdown = true;
  21. }
  22. "
  23. @hide="
  24. () => {
  25. showFiltersDropdown = false;
  26. }
  27. "
  28. >
  29. <div class="control has-addons" ref="trigger">
  30. <button class="button is-primary">
  31. <i class="material-icons icon-with-button"
  32. >filter_list</i
  33. >
  34. Filters
  35. </button>
  36. <button class="button">
  37. <i class="material-icons">
  38. {{
  39. showFiltersDropdown
  40. ? "expand_more"
  41. : "expand_less"
  42. }}
  43. </i>
  44. </button>
  45. </div>
  46. <template #content>
  47. <div class="control is-grouped input-with-button">
  48. <p class="control select is-expanded">
  49. <select v-model="addFilterValue">
  50. <option
  51. v-for="type in filters"
  52. :key="type.name"
  53. :value="type"
  54. >
  55. {{ type.displayName }}
  56. </option>
  57. </select>
  58. </p>
  59. <p class="control">
  60. <button
  61. :disabled="!addFilterValue"
  62. class="button material-icons is-success"
  63. @click="addFilterItem()"
  64. >
  65. control_point
  66. </button>
  67. </p>
  68. </div>
  69. <div
  70. v-for="(filter, index) in editingFilters"
  71. :key="`filter-${index}`"
  72. class="
  73. advanced-filter
  74. control
  75. is-grouped is-expanded
  76. "
  77. >
  78. <div class="control select">
  79. <select
  80. v-model="filter.filter"
  81. @change="changeFilterType(index)"
  82. >
  83. <option
  84. v-for="type in filters"
  85. :key="type.name"
  86. :value="type"
  87. >
  88. {{ type.displayName }}
  89. </option>
  90. </select>
  91. </div>
  92. <div class="control select">
  93. <select
  94. v-model="filter.filterType"
  95. :disabled="!filter.filterType"
  96. >
  97. <option
  98. v-for="filterType in filterTypes(
  99. filter.filter
  100. )"
  101. :key="filterType.name"
  102. :value="filterType"
  103. :selected="
  104. filter.filter
  105. .defaultFilterType ===
  106. filterType.name
  107. "
  108. >
  109. {{ filterType.displayName }}
  110. </option>
  111. </select>
  112. </div>
  113. <div
  114. v-if="
  115. filter.filterType.name &&
  116. (filter.filterType.name === 'exact' ||
  117. filter.filterType.name ===
  118. 'boolean') &&
  119. filter.filter.dropdown
  120. "
  121. class="control is-expanded select"
  122. >
  123. <select
  124. v-model="filter.data"
  125. :disabled="!filter.filterType"
  126. >
  127. <option
  128. v-for="[
  129. dropdownValue,
  130. dropdownDisplay
  131. ] in filter.filter.dropdown"
  132. :key="dropdownValue"
  133. :value="dropdownValue"
  134. >
  135. {{ dropdownDisplay }}
  136. </option>
  137. </select>
  138. </div>
  139. <div
  140. v-else-if="
  141. filter.filterType.name &&
  142. filter.filterType.name === 'boolean'
  143. "
  144. class="control is-expanded select"
  145. >
  146. <select
  147. v-model="filter.data"
  148. :disabled="!filter.filterType"
  149. >
  150. <option :value="true">true</option>
  151. <option :value="false">false</option>
  152. </select>
  153. </div>
  154. <div v-else class="control is-expanded">
  155. <input
  156. v-if="
  157. filter.filterType.name &&
  158. filter.filterType.name.startsWith(
  159. 'datetime'
  160. )
  161. "
  162. v-model="filter.data"
  163. class="input"
  164. type="datetime-local"
  165. />
  166. <input
  167. v-else-if="
  168. filter.filterType.name &&
  169. filter.filterType.name.startsWith(
  170. 'number'
  171. )
  172. "
  173. v-model="filter.data"
  174. class="input"
  175. type="number"
  176. :disabled="!filter.filterType"
  177. @keydown.enter="applyFilterAndGetData()"
  178. />
  179. <input
  180. v-else
  181. v-model="filter.data"
  182. class="input"
  183. type="text"
  184. placeholder="Search value"
  185. :disabled="!filter.filterType"
  186. @keydown.enter="applyFilterAndGetData()"
  187. @blur="blurFilterInput(filter, $event)"
  188. @focus="focusFilterInput(filter)"
  189. @keydown="keydownFilterInput(filter)"
  190. />
  191. <div
  192. class="autosuggest-container"
  193. v-if="
  194. filter.filter.autosuggest &&
  195. (autosuggest.inputFocussed[
  196. filter.filter.name
  197. ] ||
  198. autosuggest.containerFocussed[
  199. filter.filter.name
  200. ] ||
  201. autosuggest.itemFocussed[
  202. filter.filter.name
  203. ]) &&
  204. autosuggest.items[
  205. filter.filter.name
  206. ]?.length > 0
  207. "
  208. @mouseover="
  209. focusFilterAutosuggestContainer(
  210. filter
  211. )
  212. "
  213. @mouseleave="
  214. blurFilterAutosuggestContainer(
  215. filter
  216. )
  217. "
  218. >
  219. <span
  220. class="autosuggest-item"
  221. tabindex="0"
  222. @click="
  223. selectAutosuggestItem(
  224. index,
  225. filter,
  226. item
  227. )
  228. "
  229. @keyup.enter="
  230. selectAutosuggestItem(
  231. index,
  232. filter,
  233. item
  234. )
  235. "
  236. @focus="
  237. focusAutosuggestItem(filter)
  238. "
  239. @blur="
  240. blurAutosuggestItem(
  241. filter,
  242. $event
  243. )
  244. "
  245. v-for="item in autosuggest.items[
  246. filter.filter.name
  247. ]"
  248. :key="item"
  249. >{{ item }}
  250. </span>
  251. </div>
  252. </div>
  253. <div class="control">
  254. <button
  255. class="button material-icons is-danger"
  256. @click="removeFilterItem(index)"
  257. >
  258. remove_circle_outline
  259. </button>
  260. </div>
  261. </div>
  262. <div
  263. v-if="editingFilters.length > 0"
  264. class="control is-expanded is-grouped"
  265. >
  266. <label class="control label"
  267. >Filter operator</label
  268. >
  269. <div class="control select is-expanded">
  270. <select v-model="filterOperator">
  271. <option
  272. v-for="operator in filterOperators"
  273. :key="operator.name"
  274. :value="operator.name"
  275. >
  276. {{ operator.displayName }}
  277. </option>
  278. </select>
  279. </div>
  280. </div>
  281. <div
  282. class="advanced-filter-bottom"
  283. v-if="editingFilters.length > 0"
  284. >
  285. <div class="control is-expanded">
  286. <button
  287. class="button is-info"
  288. @click="applyFilterAndGetData()"
  289. >
  290. <i
  291. class="
  292. material-icons
  293. icon-with-button
  294. "
  295. >filter_list</i
  296. >
  297. Apply filters
  298. </button>
  299. </div>
  300. </div>
  301. <div
  302. class="advanced-filter-bottom"
  303. v-else-if="editingFilters.length === 0"
  304. >
  305. <div class="control is-expanded">
  306. <button
  307. class="button is-info"
  308. @click="applyFilterAndGetData()"
  309. >
  310. <i
  311. class="
  312. material-icons
  313. icon-with-button
  314. "
  315. >filter_list</i
  316. >
  317. Apply filters
  318. </button>
  319. </div>
  320. </div>
  321. </template>
  322. </tippy>
  323. <tippy
  324. v-if="appliedFilters.length > 0"
  325. :touch="true"
  326. :interactive="true"
  327. theme="info"
  328. ref="activeFilters"
  329. >
  330. <div class="filters-indicator">
  331. {{ appliedFilters.length }}
  332. <i class="material-icons" @click.prevent="true"
  333. >filter_list</i
  334. >
  335. </div>
  336. <template #content>
  337. <p
  338. v-for="(filter, index) in appliedFilters"
  339. :key="`filter-${index}`"
  340. >
  341. {{ filter.filter.displayName }}
  342. {{
  343. appliedFilters.length === 1 &&
  344. appliedFilterOperator === "nor"
  345. ? "not"
  346. : ""
  347. }}
  348. {{
  349. filter.filterType.displayName.toLowerCase()
  350. }}
  351. "{{ filter.data }}"
  352. {{
  353. appliedFilters.length === index + 1
  354. ? ""
  355. : appliedFilterOperator
  356. }}
  357. </p>
  358. </template>
  359. </tippy>
  360. <i
  361. v-else
  362. class="filters-indicator material-icons"
  363. content="No active filters"
  364. v-tippy="{ theme: 'info' }"
  365. >
  366. filter_list_off
  367. </i>
  368. </div>
  369. <div>
  370. <tippy
  371. v-if="hidableSortedColumns.length > 0"
  372. :touch="true"
  373. :interactive="true"
  374. placement="bottom-end"
  375. theme="dropdown"
  376. ref="editColumns"
  377. trigger="click"
  378. @show="
  379. () => {
  380. showColumnsDropdown = true;
  381. }
  382. "
  383. @hide="
  384. () => {
  385. showColumnsDropdown = false;
  386. }
  387. "
  388. >
  389. <div class="control has-addons" ref="trigger">
  390. <button class="button is-primary">
  391. <i class="material-icons icon-with-button"
  392. >tune</i
  393. >
  394. Columns
  395. </button>
  396. <button class="button">
  397. <i class="material-icons">
  398. {{
  399. showColumnsDropdown
  400. ? "expand_more"
  401. : "expand_less"
  402. }}
  403. </i>
  404. </button>
  405. </div>
  406. <template #content>
  407. <draggable
  408. item-key="name"
  409. v-model="orderedColumns"
  410. v-bind="columnDragOptions"
  411. tag="div"
  412. draggable=".item-draggable"
  413. class="nav-dropdown-items"
  414. @change="columnOrderChanged"
  415. >
  416. <template #item="{ element: column }">
  417. <button
  418. v-if="
  419. column.name !== 'select' &&
  420. column.name !== 'placeholder' &&
  421. column.name !== 'updatedPlaceholder'
  422. "
  423. :class="{
  424. sortable: column.sortable,
  425. 'item-draggable': column.draggable,
  426. 'nav-item': true
  427. }"
  428. @click.prevent="
  429. toggleColumnVisibility(column)
  430. "
  431. >
  432. <p
  433. class="
  434. control
  435. is-expanded
  436. checkbox-control
  437. "
  438. >
  439. <label class="switch">
  440. <input
  441. type="checkbox"
  442. :id="index"
  443. :checked="
  444. shownColumns.indexOf(
  445. column.name
  446. ) !== -1
  447. "
  448. @click="
  449. toggleColumnVisibility(
  450. column
  451. )
  452. "
  453. />
  454. <span
  455. :class="{
  456. slider: true,
  457. round: true,
  458. disabled:
  459. !column.hidable
  460. }"
  461. ></span>
  462. </label>
  463. <label :for="index">
  464. <span></span>
  465. <p>{{ column.displayName }}</p>
  466. </label>
  467. </p>
  468. </button>
  469. </template>
  470. </draggable>
  471. </template>
  472. </tippy>
  473. </div>
  474. </div>
  475. <div class="table-container">
  476. <table
  477. :class="{
  478. table: true,
  479. 'has-checkboxes': hasCheckboxes
  480. }"
  481. >
  482. <thead>
  483. <draggable
  484. item-key="name"
  485. v-model="orderedColumns"
  486. v-bind="columnDragOptions"
  487. tag="tr"
  488. handle=".handle"
  489. draggable=".item-draggable"
  490. @change="columnOrderChanged"
  491. >
  492. <template #item="{ element: column }">
  493. <th
  494. v-if="
  495. shownColumns.indexOf(column.name) !==
  496. -1 &&
  497. (column.name !== 'updatedPlaceholder' ||
  498. rows.length > 0)
  499. "
  500. :class="{
  501. sortable: column.sortable,
  502. 'item-draggable': column.draggable
  503. }"
  504. :style="{
  505. minWidth: Number.isNaN(column.minWidth)
  506. ? column.minWidth
  507. : `${column.minWidth}px`,
  508. width: Number.isNaN(column.width)
  509. ? column.width
  510. : `${column.width}px`,
  511. maxWidth: Number.isNaN(column.maxWidth)
  512. ? column.maxWidth
  513. : `${column.maxWidth}px`
  514. }"
  515. >
  516. <div v-if="column.name === 'select'">
  517. <p class="checkbox">
  518. <input
  519. v-if="rows.length === 0"
  520. type="checkbox"
  521. disabled
  522. />
  523. <input
  524. v-else
  525. type="checkbox"
  526. :checked="
  527. rows.filter(
  528. row => !row.removed
  529. ).length ===
  530. selectedRows.length
  531. "
  532. @click="toggleAllRows()"
  533. />
  534. </p>
  535. </div>
  536. <div v-else class="handle">
  537. <span>
  538. {{ column.displayName }}
  539. </span>
  540. <span
  541. v-if="column.sortable"
  542. :content="`Sort by ${column.displayName}`"
  543. v-tippy
  544. >
  545. <span
  546. v-if="
  547. !sort[column.sortProperty]
  548. "
  549. class="material-icons"
  550. @click="changeSort(column)"
  551. >
  552. unfold_more
  553. </span>
  554. <span
  555. v-if="
  556. sort[
  557. column.sortProperty
  558. ] === 'ascending'
  559. "
  560. class="material-icons active"
  561. @click="changeSort(column)"
  562. >
  563. expand_more
  564. </span>
  565. <span
  566. v-if="
  567. sort[
  568. column.sortProperty
  569. ] === 'descending'
  570. "
  571. class="material-icons active"
  572. @click="changeSort(column)"
  573. >
  574. expand_less
  575. </span>
  576. </span>
  577. </div>
  578. <div
  579. class="resizer"
  580. v-if="column.resizable"
  581. @mousedown.prevent.stop="
  582. columnResizingStart(column, $event)
  583. "
  584. @touchstart.prevent.stop="
  585. columnResizingStart(column, $event)
  586. "
  587. @mouseup="columnResizingStop()"
  588. @touchend="columnResizingStop()"
  589. @dblclick="columnResetWidth(column)"
  590. ></div>
  591. </th>
  592. </template>
  593. </draggable>
  594. </thead>
  595. <tbody>
  596. <tr
  597. v-for="(item, itemIndex) in rows"
  598. :key="item._id"
  599. :class="{
  600. selected: item.selected,
  601. highlighted: item.highlighted,
  602. updated: item.updated,
  603. removed: item.removed
  604. }"
  605. :ref="`row-${itemIndex}`"
  606. tabindex="0"
  607. @keydown.up.prevent
  608. @keydown.down.prevent
  609. @keydown.space.prevent
  610. @click="highlightRow(itemIndex)"
  611. @keyup.up.exact="highlightUp(itemIndex)"
  612. @keyup.down.exact="highlightDown(itemIndex)"
  613. @keyup.shift.up.exact="selectUp(itemIndex)"
  614. @keyup.shift.down.exact="selectDown(itemIndex)"
  615. @keyup.ctrl.up.exact="unselectUp(itemIndex)"
  616. @keyup.ctrl.down.exact="unselectDown(itemIndex)"
  617. @keyup.space.exact="
  618. toggleSelectedRow(itemIndex, {})
  619. "
  620. >
  621. <td
  622. v-for="column in sortedFilteredColumns"
  623. :key="`${item._id}-${column.name}`"
  624. >
  625. <slot
  626. :name="`column-${column.name}`"
  627. :item="item"
  628. v-if="
  629. column.properties.length === 0 ||
  630. column.properties.every(
  631. property =>
  632. property
  633. .split('.')
  634. .reduce(
  635. (previous, current) =>
  636. previous &&
  637. previous[
  638. current
  639. ] !== null &&
  640. previous[
  641. current
  642. ] !== undefined
  643. ? previous[
  644. current
  645. ]
  646. : null,
  647. item
  648. ) !== null
  649. )
  650. "
  651. ></slot>
  652. <div
  653. v-if="
  654. column.name === 'updatedPlaceholder' &&
  655. item.updated
  656. "
  657. class="updated-tooltip"
  658. content="Row updated"
  659. v-tippy="{
  660. theme: 'info',
  661. placement: 'right'
  662. }"
  663. ></div>
  664. <p
  665. class="checkbox"
  666. v-if="column.name === 'select'"
  667. >
  668. <input
  669. type="checkbox"
  670. :checked="item.selected"
  671. @click="
  672. toggleSelectedRow(itemIndex, $event)
  673. "
  674. :disabled="item.removed"
  675. />
  676. </p>
  677. <span
  678. v-if="item.removed"
  679. class="removed-overlay"
  680. content="Item removed"
  681. v-tippy="{ theme: 'info' }"
  682. ></span>
  683. <div
  684. class="resizer"
  685. v-if="column.resizable"
  686. @mousedown.prevent.stop="
  687. columnResizingStart(column, $event)
  688. "
  689. @touchstart.prevent.stop="
  690. columnResizingStart(column, $event)
  691. "
  692. @mouseup="columnResizingStop()"
  693. @touchend="columnResizingStop()"
  694. @dblclick="columnResetWidth(column)"
  695. ></div>
  696. </td>
  697. </tr>
  698. </tbody>
  699. </table>
  700. </div>
  701. <div v-if="rows.length === 0" class="table-no-results">
  702. No results found
  703. </div>
  704. <div class="table-footer">
  705. <div class="page-controls">
  706. <button
  707. :class="{ disabled: page === 1 }"
  708. class="button is-primary material-icons"
  709. :disabled="page === 1"
  710. @click="changePage(1)"
  711. content="First Page"
  712. v-tippy
  713. >
  714. skip_previous
  715. </button>
  716. <button
  717. :class="{ disabled: page === 1 }"
  718. class="button is-primary material-icons"
  719. :disabled="page === 1"
  720. @click="changePage(page - 1)"
  721. content="Previous Page"
  722. v-tippy
  723. >
  724. fast_rewind
  725. </button>
  726. <p>Page {{ page }} / {{ lastPage > 0 ? lastPage : 1 }}</p>
  727. <button
  728. :class="{
  729. disabled: page === lastPage || lastPage === 0
  730. }"
  731. class="button is-primary material-icons"
  732. :disabled="page === lastPage"
  733. @click="changePage(page + 1)"
  734. content="Next Page"
  735. v-tippy
  736. >
  737. fast_forward
  738. </button>
  739. <button
  740. :class="{
  741. disabled: page === lastPage || lastPage === 0
  742. }"
  743. class="button is-primary material-icons"
  744. :disabled="page === lastPage"
  745. @click="changePage(lastPage)"
  746. content="Last Page"
  747. v-tippy
  748. >
  749. skip_next
  750. </button>
  751. </div>
  752. <div class="page-size">
  753. <div class="control">
  754. <label class="label">Items per page</label>
  755. <p class="control select">
  756. <select
  757. v-model.number="pageSize"
  758. @change="changePageSize()"
  759. >
  760. <option value="10">10</option>
  761. <option value="25">25</option>
  762. <option value="50">50</option>
  763. <option value="100">100</option>
  764. <option value="250">250</option>
  765. <option value="500">500</option>
  766. <option value="1000">1000</option>
  767. </select>
  768. </p>
  769. </div>
  770. </div>
  771. </div>
  772. </div>
  773. <div
  774. v-if="hasCheckboxes && selectedRows.length > 0"
  775. class="bulk-popup"
  776. :style="{
  777. top: bulkPopup.top + 'px',
  778. left: bulkPopup.left + 'px'
  779. }"
  780. ref="bulk-popup"
  781. >
  782. <button
  783. class="button is-primary"
  784. :content="
  785. selectedRows.length === 1
  786. ? `${selectedRows.length} row selected`
  787. : `${selectedRows.length} rows selected`
  788. "
  789. v-tippy="{ theme: 'info' }"
  790. >
  791. {{ selectedRows.length }}
  792. </button>
  793. <slot name="bulk-actions" :item="selectedRows" />
  794. <div class="right">
  795. <span
  796. class="material-icons drag-icon"
  797. @mousedown.left="onDragBox"
  798. @touchstart="onDragBox"
  799. @dblclick="resetBulkActionsPosition()"
  800. >
  801. drag_indicator
  802. </span>
  803. </div>
  804. </div>
  805. </div>
  806. </template>
  807. <script>
  808. import { mapGetters } from "vuex";
  809. import draggable from "vuedraggable";
  810. import Toast from "toasters";
  811. import keyboardShortcuts from "@/keyboardShortcuts";
  812. import ws from "@/ws";
  813. export default {
  814. components: {
  815. draggable
  816. },
  817. props: {
  818. /*
  819. Column properties:
  820. name: Unique lowercase name
  821. displayName: Nice name for the column header
  822. properties: The properties this column needs to show data
  823. sortable: Boolean for whether the order of a particular column can be changed
  824. sortProperty: The property the backend will sort on if this column gets sorted, e.g. title
  825. hidable: Boolean for whether a column can be hidden
  826. defaultVisibility: Default visibility for a column, either "shown" or "hidden"
  827. draggable: Boolean for whether a column can be dragged/reordered,
  828. resizable: Boolean for whether a column can be resized
  829. minWidth: Minimum width of column, e.g. 50px
  830. width: Width of column, e.g. 100px
  831. maxWidth: Maximum width of column, e.g. 150px
  832. */
  833. columnDefault: { type: Object, default: () => {} },
  834. columns: { type: Array, default: null },
  835. filters: { type: Array, default: null },
  836. dataAction: { type: String, default: null },
  837. name: { type: String, default: null },
  838. maxWidth: { type: Number, default: 1880 },
  839. query: { type: Boolean, default: true },
  840. keyboardShortcuts: { type: Boolean, default: true },
  841. events: { type: Object, default: () => {} }
  842. },
  843. data() {
  844. return {
  845. page: 1,
  846. pageSize: 10,
  847. rows: [],
  848. count: 0, // TODO Rename
  849. sort: {},
  850. orderedColumns: [],
  851. shownColumns: [],
  852. columnDragOptions() {
  853. return {
  854. animation: 200,
  855. group: "columns",
  856. disabled: false,
  857. ghostClass: "draggable-list-ghost",
  858. filter: ".ignore-elements",
  859. fallbackTolerance: 50
  860. };
  861. },
  862. editingFilters: [],
  863. appliedFilters: [],
  864. filterOperator: "or",
  865. appliedFilterOperator: "or",
  866. filterOperators: [
  867. {
  868. name: "or",
  869. displayName: "OR"
  870. },
  871. {
  872. name: "and",
  873. displayName: "AND"
  874. },
  875. {
  876. name: "nor",
  877. displayName: "NOR"
  878. }
  879. ],
  880. resizing: {},
  881. allFilterTypes: {
  882. contains: {
  883. name: "contains",
  884. displayName: "Contains"
  885. },
  886. exact: {
  887. name: "exact",
  888. displayName: "Exact"
  889. },
  890. regex: {
  891. name: "regex",
  892. displayName: "Regex"
  893. },
  894. datetimeBefore: {
  895. name: "datetimeBefore",
  896. displayName: "Before"
  897. },
  898. datetimeAfter: {
  899. name: "datetimeAfter",
  900. displayName: "After"
  901. },
  902. numberLesserEqual: {
  903. name: "numberLesserEqual",
  904. displayName: "Less than or equal to"
  905. },
  906. numberLesser: {
  907. name: "numberLesser",
  908. displayName: "Less than"
  909. },
  910. numberGreater: {
  911. name: "numberGreater",
  912. displayName: "Greater than"
  913. },
  914. numberGreaterEqual: {
  915. name: "numberGreaterEqual",
  916. displayName: "Greater than or equal to"
  917. },
  918. numberEquals: {
  919. name: "numberEquals",
  920. displayName: "Equals"
  921. },
  922. boolean: {
  923. name: "boolean",
  924. displayName: "Boolean"
  925. }
  926. },
  927. bulkPopup: {
  928. top: 0,
  929. left: 0,
  930. pos1: 0,
  931. pos2: 0,
  932. pos3: 0,
  933. pos4: 0
  934. },
  935. addFilterValue: null,
  936. showFiltersDropdown: false,
  937. showColumnsDropdown: false,
  938. lastColumnResizerTapped: null,
  939. lastColumnResizerTappedDate: 0,
  940. lastBulkActionsTappedDate: 0,
  941. autosuggest: {
  942. inputFocussed: {},
  943. containerFocussed: {},
  944. itemFocussed: {},
  945. keydownInputTimeout: {},
  946. items: {},
  947. allItems: {
  948. genres: ["edm", "pop", "test"]
  949. }
  950. }
  951. };
  952. },
  953. computed: {
  954. properties() {
  955. return Array.from(
  956. new Set(
  957. this.sortedFilteredColumns.flatMap(
  958. column => column.properties
  959. )
  960. )
  961. );
  962. },
  963. lastPage() {
  964. return Math.ceil(this.count / this.pageSize);
  965. },
  966. sortedFilteredColumns() {
  967. return this.orderedColumns.filter(
  968. column => this.shownColumns.indexOf(column.name) !== -1
  969. );
  970. },
  971. hidableSortedColumns() {
  972. return this.orderedColumns.filter(column => column.hidable);
  973. },
  974. lastSelectedItemIndex() {
  975. return this.rows.findIndex(item => item.highlighted);
  976. },
  977. selectedRows() {
  978. return this.rows.filter(row => row.selected);
  979. },
  980. hasCheckboxes() {
  981. return (
  982. this.$slots["bulk-actions"] != null ||
  983. this.$slots["bulk-actions-right"] != null
  984. );
  985. },
  986. ...mapGetters({
  987. socket: "websockets/getSocket"
  988. })
  989. },
  990. watch: {
  991. selectedRows(newSelectedRows, oldSelectedRows) {
  992. // If selected rows goes from zero to one or more selected, trigger onWindowResize, as otherwise the popup could be out of bounds
  993. if (oldSelectedRows.length === 0 && newSelectedRows.length > 0)
  994. this.onWindowResize();
  995. }
  996. },
  997. mounted() {
  998. const tableSettings = this.getTableSettings();
  999. const columns = [
  1000. ...this.columns.map(column => ({
  1001. ...this.columnDefault,
  1002. ...column
  1003. })),
  1004. {
  1005. name: "placeholder",
  1006. displayName: "",
  1007. properties: [],
  1008. sortable: false,
  1009. hidable: false,
  1010. draggable: false,
  1011. resizable: false,
  1012. minWidth: "auto",
  1013. width: "auto",
  1014. maxWidth: "auto"
  1015. }
  1016. ];
  1017. if (this.hasCheckboxes)
  1018. columns.unshift({
  1019. name: "select",
  1020. displayName: "",
  1021. properties: [],
  1022. sortable: false,
  1023. hidable: false,
  1024. draggable: false,
  1025. resizable: false,
  1026. minWidth: 47,
  1027. defaultWidth: 47,
  1028. maxWidth: 47
  1029. });
  1030. if (this.events && this.events.updated)
  1031. columns.unshift({
  1032. name: "updatedPlaceholder",
  1033. displayName: "",
  1034. properties: [],
  1035. sortable: false,
  1036. hidable: false,
  1037. draggable: false,
  1038. resizable: false,
  1039. minWidth: 5,
  1040. width: 5,
  1041. maxWidth: 5
  1042. });
  1043. this.orderedColumns = columns.sort((columnA, columnB) => {
  1044. // Always places updatedPlaceholder column in the first position
  1045. if (columnA.name === "updatedPlaceholder") return -1;
  1046. if (columnB.name === "updatedPlaceholder") return 1;
  1047. // Always places select column in the second position
  1048. if (columnA.name === "select") return -1;
  1049. if (columnB.name === "select") return 1;
  1050. // Always places placeholder column in the last position
  1051. if (columnA.name === "placeholder") return 1;
  1052. if (columnB.name === "placeholder") return -1;
  1053. // If there are no table settings stored, use default ordering
  1054. if (!tableSettings || !tableSettings.columnOrder) return 0;
  1055. const indexA = tableSettings.columnOrder.indexOf(columnA.name);
  1056. const indexB = tableSettings.columnOrder.indexOf(columnB.name);
  1057. // If either of the columns is not stored in the table settings, use default ordering
  1058. if (indexA === -1 || indexB === -1) return 0;
  1059. return indexA - indexB;
  1060. });
  1061. this.shownColumns = this.orderedColumns
  1062. .filter(column => {
  1063. // If table settings exist, use shownColumns from settings to determine which columns to show
  1064. if (tableSettings && tableSettings.shownColumns)
  1065. return (
  1066. tableSettings.shownColumns.indexOf(column.name) !== -1
  1067. );
  1068. // Table settings don't exist, only show if the default visibility isn't hidden
  1069. return column.defaultVisibility !== "hidden";
  1070. })
  1071. .map(column => column.name);
  1072. this.recalculateWidths();
  1073. if (tableSettings) {
  1074. // If table settings' page is an integer, use it for the page
  1075. if (Number.isInteger(tableSettings?.page))
  1076. this.page = tableSettings.page;
  1077. // If table settings' pageSize is an integer, use it for the pageSize
  1078. if (Number.isInteger(tableSettings?.pageSize))
  1079. this.pageSize = tableSettings.pageSize;
  1080. // If table settings' columnSort exists, sort all still existing columns based on table settings' columnSort object
  1081. if (tableSettings.columnSort) {
  1082. Object.entries(tableSettings.columnSort).forEach(
  1083. ([columnName, sortDirection]) => {
  1084. if (
  1085. this.columns.find(
  1086. column => column.name === columnName
  1087. )
  1088. )
  1089. this.sort[columnName] = sortDirection;
  1090. }
  1091. );
  1092. }
  1093. // If table settings' columnWidths exists, load the stored widths into the columns
  1094. if (tableSettings.columnWidths) {
  1095. this.orderedColumns = this.orderedColumns.map(orderedColumn => {
  1096. const columnWidth = tableSettings.columnWidths.find(
  1097. column => column.name === orderedColumn.name
  1098. )?.width;
  1099. if (orderedColumn.resizable && columnWidth)
  1100. return { ...orderedColumn, width: columnWidth };
  1101. return orderedColumn;
  1102. });
  1103. }
  1104. if (
  1105. tableSettings.filter &&
  1106. tableSettings.filter.appliedFilters &&
  1107. tableSettings.filter.appliedFilterOperator
  1108. ) {
  1109. const { appliedFilters, appliedFilterOperator } =
  1110. tableSettings.filter;
  1111. // Set the applied filter operator and filter operator to the value stored in table settings
  1112. this.appliedFilterOperator = this.filterOperator =
  1113. appliedFilterOperator;
  1114. // Set the applied filters and editing filters to the value stored in table settings, for all filters that are allowed
  1115. this.appliedFilters = appliedFilters.filter(appliedFilter =>
  1116. this.filters.find(
  1117. filter => appliedFilter.filter.name === filter.name
  1118. )
  1119. );
  1120. this.editingFilters = appliedFilters.filter(appliedFilter =>
  1121. this.filters.find(
  1122. filter => appliedFilter.filter.name === filter.name
  1123. )
  1124. );
  1125. }
  1126. }
  1127. this.resetBulkActionsPosition();
  1128. this.$nextTick(() => {
  1129. this.onWindowResize();
  1130. window.addEventListener("resize", this.onWindowResize);
  1131. });
  1132. ws.onConnect(this.init);
  1133. if (this.events && this.events.updated)
  1134. this.socket.on(`event:${this.events.updated.event}`, res => {
  1135. const index = this.rows
  1136. .map(row => row._id)
  1137. .indexOf(
  1138. this.events.updated.id
  1139. .split(".")
  1140. .reduce(
  1141. (previous, current) =>
  1142. previous &&
  1143. previous[current] !== null &&
  1144. previous[current] !== undefined
  1145. ? previous[current]
  1146. : null,
  1147. res.data
  1148. )
  1149. );
  1150. const row = this.events.updated.item
  1151. .split(".")
  1152. .reduce(
  1153. (previous, current) =>
  1154. previous &&
  1155. previous[current] !== null &&
  1156. previous[current] !== undefined
  1157. ? previous[current]
  1158. : null,
  1159. res.data
  1160. );
  1161. this.updateData(index, row);
  1162. });
  1163. if (this.events && this.events.removed)
  1164. this.socket.on(`event:${this.events.removed.event}`, res => {
  1165. const index = this.rows
  1166. .map(row => row._id)
  1167. .indexOf(
  1168. this.events.removed.id
  1169. .split(".")
  1170. .reduce(
  1171. (previous, current) =>
  1172. previous &&
  1173. previous[current] !== null &&
  1174. previous[current] !== undefined
  1175. ? previous[current]
  1176. : null,
  1177. res.data
  1178. )
  1179. );
  1180. this.removeData(index);
  1181. });
  1182. if (this.keyboardShortcuts) {
  1183. // Navigation section
  1184. // Page navigation section
  1185. keyboardShortcuts.registerShortcut("advancedTable.previousPage", {
  1186. keyCode: 37, // 'Left arrow' key
  1187. ctrl: true,
  1188. preventDefault: true,
  1189. handler: () => {
  1190. // Previous page
  1191. this.changePage(this.page - 1);
  1192. }
  1193. });
  1194. keyboardShortcuts.registerShortcut("advancedTable.nextPage", {
  1195. keyCode: 39, // 'Right arrow' key
  1196. ctrl: true,
  1197. preventDefault: true,
  1198. handler: () => {
  1199. // Next page
  1200. this.changePage(this.page + 1);
  1201. }
  1202. });
  1203. keyboardShortcuts.registerShortcut("advancedTable.firstPage", {
  1204. keyCode: 37, // 'Left arrow' key
  1205. ctrl: true,
  1206. shift: true,
  1207. preventDefault: true,
  1208. handler: () => {
  1209. // First page
  1210. this.changePage(1);
  1211. }
  1212. });
  1213. keyboardShortcuts.registerShortcut("advancedTable.lastPage", {
  1214. keyCode: 39, // 'Right arrow' key
  1215. ctrl: true,
  1216. shift: true,
  1217. preventDefault: true,
  1218. handler: () => {
  1219. // Last page
  1220. this.changePage(this.lastPage);
  1221. }
  1222. });
  1223. // Reset localStorage section
  1224. keyboardShortcuts.registerShortcut(
  1225. "advancedTable.resetLocalStorage",
  1226. {
  1227. keyCode: 116, // 'F5' key
  1228. ctrl: true,
  1229. preventDefault: false,
  1230. handler: () => {
  1231. // Reset local storage
  1232. console.log("Reset local storage");
  1233. localStorage.removeItem(
  1234. `advancedTableSettings:${this.name}`
  1235. );
  1236. this.$router.push({ query: "" });
  1237. }
  1238. }
  1239. );
  1240. // Selecting section
  1241. keyboardShortcuts.registerShortcut("advancedTable.selectAll", {
  1242. keyCode: 65, // 'A' key
  1243. ctrl: true,
  1244. preventDefault: true,
  1245. handler: () => {
  1246. this.toggleAllRows();
  1247. }
  1248. });
  1249. // Popup actions section
  1250. for (let i = 1; i <= 9; i += 1) {
  1251. keyboardShortcuts.registerShortcut(
  1252. `advancedTable.executePopupAction${i}`,
  1253. {
  1254. keyCode: 48 + i, // '1-9' keys, where 49 is 1 and 57 is 9
  1255. ctrl: true,
  1256. preventDefault: true,
  1257. handler: () => {
  1258. // Execute popup action 1-9
  1259. if (this.selectedRows.length === 0) return;
  1260. const bulkActionsElement =
  1261. this.$refs["bulk-popup"].querySelector(
  1262. ".bulk-actions"
  1263. );
  1264. bulkActionsElement.children[i - 1].click();
  1265. }
  1266. }
  1267. );
  1268. }
  1269. keyboardShortcuts.registerShortcut(
  1270. `advancedTable.selectPopupAction1`,
  1271. {
  1272. keyCode: 48, // '0' key
  1273. ctrl: true,
  1274. preventDefault: true,
  1275. handler: () => {
  1276. // Select popup action 0
  1277. if (this.selectedRows.length === 0) return;
  1278. const bulkActionsElement =
  1279. this.$refs["bulk-popup"].querySelector(
  1280. ".bulk-actions"
  1281. );
  1282. bulkActionsElement.children[
  1283. bulkActionsElement.children.length - 1
  1284. ].focus();
  1285. }
  1286. }
  1287. );
  1288. }
  1289. },
  1290. unmounted() {
  1291. window.removeEventListener("resize", this.onWindowResize);
  1292. if (this.storeTableSettingsDebounceTimeout)
  1293. clearTimeout(this.storeTableSettingsDebounceTimeout);
  1294. if (this.keyboardShortcuts) {
  1295. const shortcutNames = [
  1296. // Navigation
  1297. "advancedTable.previousPage",
  1298. "advancedTable.nextPage",
  1299. "advancedTable.firstPage",
  1300. "advancedTable.lastPage",
  1301. // Reset localStorage
  1302. "advancedTable.resetLocalStorage",
  1303. // Selecting
  1304. "advancedTable.selectAll",
  1305. // Popup actions
  1306. "advancedTable.executePopupAction1",
  1307. "advancedTable.executePopupAction2",
  1308. "advancedTable.executePopupAction3",
  1309. "advancedTable.executePopupAction4",
  1310. "advancedTable.executePopupAction5",
  1311. "advancedTable.executePopupAction6",
  1312. "advancedTable.executePopupAction7",
  1313. "advancedTable.executePopupAction8",
  1314. "advancedTable.executePopupAction9",
  1315. "advancedTable.selectPopupAction1"
  1316. ];
  1317. shortcutNames.forEach(shortcutName => {
  1318. keyboardShortcuts.unregisterShortcut(shortcutName);
  1319. });
  1320. }
  1321. },
  1322. methods: {
  1323. init() {
  1324. this.getData();
  1325. if (this.query) this.setQuery();
  1326. if (this.events) {
  1327. if (this.events.room)
  1328. this.socket.dispatch(
  1329. "apis.joinRoom",
  1330. this.events.room,
  1331. () => {}
  1332. );
  1333. if (this.events.adminRoom)
  1334. this.socket.dispatch(
  1335. "apis.joinAdminRoom",
  1336. this.events.adminRoom,
  1337. () => {}
  1338. );
  1339. }
  1340. this.filters.forEach(filter => {
  1341. if (filter.autosuggest && filter.autosuggestDataAction) {
  1342. this.socket.dispatch(filter.autosuggestDataAction, res => {
  1343. if (res.status === "success") {
  1344. const { items } = res.data;
  1345. this.autosuggest.allItems[filter.name] = items;
  1346. } else {
  1347. new Toast(res.message);
  1348. }
  1349. });
  1350. }
  1351. });
  1352. },
  1353. getData() {
  1354. this.socket.dispatch(
  1355. this.dataAction,
  1356. this.page,
  1357. this.pageSize,
  1358. this.properties,
  1359. this.sort,
  1360. this.appliedFilters.map(filter => ({
  1361. ...filter,
  1362. filterType: filter.filterType.name
  1363. })),
  1364. this.appliedFilterOperator,
  1365. res => {
  1366. console.log(111, res);
  1367. if (res.status === "success") {
  1368. const { data, count } = res.data;
  1369. this.rows = data.map(row => ({
  1370. ...row,
  1371. selected: false
  1372. }));
  1373. this.count = count;
  1374. } else {
  1375. new Toast(res.message);
  1376. }
  1377. }
  1378. );
  1379. },
  1380. changePageSize() {
  1381. this.page = 1;
  1382. this.getData();
  1383. this.storeTableSettings();
  1384. },
  1385. changePage(page) {
  1386. if (page < 1) return;
  1387. if (page > this.lastPage) return;
  1388. if (page === this.page) return;
  1389. this.page = page;
  1390. this.getData();
  1391. if (this.query) this.setQuery();
  1392. },
  1393. changeSort(column) {
  1394. if (column.sortable) {
  1395. const { sortProperty } = column;
  1396. if (this.sort[sortProperty] === undefined)
  1397. this.sort[sortProperty] = "ascending";
  1398. else if (this.sort[sortProperty] === "ascending")
  1399. this.sort[sortProperty] = "descending";
  1400. else if (this.sort[sortProperty] === "descending")
  1401. delete this.sort[sortProperty];
  1402. this.getData();
  1403. this.storeTableSettings();
  1404. }
  1405. },
  1406. toggleColumnVisibility(column) {
  1407. if (!column.hidable) return false;
  1408. if (this.shownColumns.indexOf(column.name) !== -1) {
  1409. if (this.shownColumns.length <= 3)
  1410. return new Toast(
  1411. `Unable to hide column ${column.displayName}, there must be at least 1 visibile column`
  1412. );
  1413. this.shownColumns.splice(
  1414. this.shownColumns.indexOf(column.name),
  1415. 1
  1416. );
  1417. } else {
  1418. this.shownColumns.push(column.name);
  1419. }
  1420. this.recalculateWidths();
  1421. this.getData();
  1422. return this.storeTableSettings();
  1423. },
  1424. toggleSelectedRow(itemIndex, event) {
  1425. const { shiftKey, ctrlKey } = event;
  1426. // Shift was pressed, so attempt to select all items between the clicked item and last clicked item
  1427. if (shiftKey) {
  1428. // If the clicked item is already selected, prevent default, otherwise the checkbox will be unchecked
  1429. if (this.rows[itemIndex].selected) event.preventDefault();
  1430. // If there is a last clicked item
  1431. if (this.lastSelectedItemIndex >= 0) {
  1432. // Clicked item is lower than last item, so select upwards until it reaches the last selected item
  1433. if (itemIndex > this.lastSelectedItemIndex) {
  1434. for (
  1435. let itemIndexUp = itemIndex;
  1436. itemIndexUp > this.lastSelectedItemIndex;
  1437. itemIndexUp -= 1
  1438. ) {
  1439. if (!this.rows[itemIndexUp].removed)
  1440. this.rows[itemIndexUp].selected = true;
  1441. }
  1442. }
  1443. // Clicked item is higher than last item, so select downwards until it reaches the last selected item
  1444. else if (itemIndex < this.lastSelectedItemIndex) {
  1445. for (
  1446. let itemIndexDown = itemIndex;
  1447. itemIndexDown < this.lastSelectedItemIndex;
  1448. itemIndexDown += 1
  1449. ) {
  1450. if (!this.rows[itemIndexDown].removed)
  1451. this.rows[itemIndexDown].selected = true;
  1452. }
  1453. }
  1454. }
  1455. }
  1456. // Ctrl was pressed, so attempt to unselect all items between the clicked item and last clicked item
  1457. else if (ctrlKey) {
  1458. // If the clicked item is already unselected, prevent default, otherwise the checkbox will be checked
  1459. if (!this.rows[itemIndex].selected) event.preventDefault();
  1460. // If there is a last clicked item
  1461. if (this.lastSelectedItemIndex >= 0) {
  1462. // Clicked item is lower than last item, so unselect upwards until it reaches the last selected item
  1463. if (itemIndex > this.lastSelectedItemIndex) {
  1464. for (
  1465. let itemIndexUp = itemIndex;
  1466. itemIndexUp >= this.lastSelectedItemIndex;
  1467. itemIndexUp -= 1
  1468. ) {
  1469. if (!this.rows[itemIndexUp].removed)
  1470. this.rows[itemIndexUp].selected = false;
  1471. }
  1472. }
  1473. // Clicked item is higher than last item, so unselect downwards until it reaches the last selected item
  1474. else if (itemIndex < this.lastSelectedItemIndex) {
  1475. for (
  1476. let itemIndexDown = itemIndex;
  1477. itemIndexDown <= this.lastSelectedItemIndex;
  1478. itemIndexDown += 1
  1479. ) {
  1480. if (!this.rows[itemIndexDown].removed)
  1481. this.rows[itemIndexDown].selected = false;
  1482. }
  1483. }
  1484. }
  1485. }
  1486. // Neither ctrl nor shift were pressed, so toggle clicked item
  1487. else {
  1488. this.rows[itemIndex].selected = !this.rows[itemIndex].selected;
  1489. }
  1490. // Set the last clicked item to no longer be highlighted, if it exists
  1491. if (this.lastSelectedItemIndex >= 0)
  1492. this.rows[this.lastSelectedItemIndex].highlighted = false;
  1493. // Set the clicked item to be highlighted
  1494. this.rows[itemIndex].highlighted = true;
  1495. },
  1496. toggleAllRows() {
  1497. if (
  1498. this.rows.filter(row => !row.removed).length >
  1499. this.selectedRows.length
  1500. ) {
  1501. this.rows = this.rows.map(row => {
  1502. if (row.removed) return row;
  1503. return { ...row, selected: true };
  1504. });
  1505. } else {
  1506. this.rows = this.rows.map(row => {
  1507. if (row.removed) return row;
  1508. return { ...row, selected: false };
  1509. });
  1510. }
  1511. },
  1512. highlightUp(itemIndex) {
  1513. if (itemIndex === 0) return;
  1514. const newItemIndex = itemIndex - 1;
  1515. this.highlightRow(newItemIndex);
  1516. },
  1517. highlightDown(itemIndex) {
  1518. if (itemIndex === this.rows.length - 1) return;
  1519. const newItemIndex = itemIndex + 1;
  1520. this.highlightRow(newItemIndex);
  1521. },
  1522. highlightRow(itemIndex) {
  1523. const rowElement = this.$refs[`row-${itemIndex}`];
  1524. // Set the last clicked item to no longer be highlighted, if it exists
  1525. if (this.lastSelectedItemIndex >= 0)
  1526. this.rows[this.lastSelectedItemIndex].highlighted = false;
  1527. if (rowElement) rowElement.focus();
  1528. // Set the item to be highlighted
  1529. this.rows[itemIndex].highlighted = true;
  1530. },
  1531. selectUp(itemIndex) {
  1532. if (itemIndex === 0) return;
  1533. const newItemIndex = itemIndex - 1;
  1534. if (!this.rows[itemIndex].removed)
  1535. this.rows[itemIndex].selected = true;
  1536. if (!this.rows[newItemIndex].removed)
  1537. this.rows[newItemIndex].selected = true;
  1538. this.highlightRow(newItemIndex);
  1539. },
  1540. selectDown(itemIndex) {
  1541. if (itemIndex === this.rows.length - 1) return;
  1542. const newItemIndex = itemIndex + 1;
  1543. if (!this.rows[itemIndex].removed)
  1544. this.rows[itemIndex].selected = true;
  1545. if (!this.rows[newItemIndex].removed)
  1546. this.rows[newItemIndex].selected = true;
  1547. this.highlightRow(newItemIndex);
  1548. },
  1549. unselectUp(itemIndex) {
  1550. if (itemIndex === 0) return;
  1551. const newItemIndex = itemIndex - 1;
  1552. if (!this.rows[itemIndex].removed)
  1553. this.rows[itemIndex].selected = false;
  1554. if (!this.rows[newItemIndex].removed)
  1555. this.rows[newItemIndex].selected = false;
  1556. this.highlightRow(newItemIndex);
  1557. },
  1558. unselectDown(itemIndex) {
  1559. if (itemIndex === this.rows.length - 1) return;
  1560. const newItemIndex = itemIndex + 1;
  1561. if (!this.rows[itemIndex].removed)
  1562. this.rows[itemIndex].selected = false;
  1563. if (!this.rows[newItemIndex].removed)
  1564. this.rows[newItemIndex].selected = false;
  1565. this.highlightRow(newItemIndex);
  1566. },
  1567. addFilterItem() {
  1568. this.editingFilters.push({
  1569. data: "",
  1570. filter: this.addFilterValue,
  1571. filterType:
  1572. this.allFilterTypes[this.addFilterValue.defaultFilterType]
  1573. });
  1574. },
  1575. removeFilterItem(index) {
  1576. this.editingFilters.splice(index, 1);
  1577. },
  1578. columnResizingStart(column, event) {
  1579. const eventIsTouch = event.type === "touchstart";
  1580. if (eventIsTouch) {
  1581. // Handle double click from touch (if this method is called for the same column twice in a row within one second)
  1582. if (
  1583. this.lastColumnResizerTapped === column &&
  1584. Date.now() - this.lastColumnResizerTappedDate <= 1000
  1585. ) {
  1586. this.columnResetWidth(column);
  1587. this.lastColumnResizerTapped = null;
  1588. this.lastColumnResizerTappedDate = 0;
  1589. return;
  1590. }
  1591. this.lastColumnResizerTapped = column;
  1592. this.lastColumnResizerTappedDate = Date.now();
  1593. }
  1594. this.resizing.resizing = true;
  1595. this.resizing.resizingColumn = column;
  1596. this.resizing.width = event.target.parentElement.offsetWidth;
  1597. this.resizing.lastX = eventIsTouch
  1598. ? event.targetTouches[0].clientX
  1599. : event.x;
  1600. },
  1601. columnResizing(event) {
  1602. if (this.resizing.resizing) {
  1603. const eventIsTouch = event.type === "touchmove";
  1604. if (!eventIsTouch && event.buttons !== 1) {
  1605. this.resizing.resizing = false;
  1606. this.storeTableSettings();
  1607. }
  1608. const x = eventIsTouch
  1609. ? event.changedTouches[0].clientX
  1610. : event.x;
  1611. this.resizing.width -= this.resizing.lastX - x;
  1612. this.resizing.lastX = x;
  1613. if (
  1614. this.resizing.resizingColumn.minWidth &&
  1615. this.resizing.resizingColumn.maxWidth
  1616. ) {
  1617. this.resizing.resizingColumn.width = Math.max(
  1618. Math.min(
  1619. this.resizing.resizingColumn.maxWidth,
  1620. this.resizing.width
  1621. ),
  1622. this.resizing.resizingColumn.minWidth
  1623. );
  1624. } else if (this.resizing.resizingColumn.minWidth) {
  1625. this.resizing.resizingColumn.width = Math.max(
  1626. this.resizing.width,
  1627. this.resizing.resizingColumn.minWidth
  1628. );
  1629. } else if (this.resizing.resizingColumn.maxWidth) {
  1630. this.resizing.resizingColumn.width = Math.min(
  1631. this.resizing.resizingColumn.maxWidth,
  1632. this.resizing.width
  1633. );
  1634. } else {
  1635. this.resizing.resizingColumn.width = this.resizing.width;
  1636. }
  1637. this.resizing.width = this.resizing.resizingColumn.width;
  1638. console.log(`New width: ${this.resizing.width}px`);
  1639. this.storeTableSettings();
  1640. }
  1641. },
  1642. columnResizingStop() {
  1643. this.resizing.resizing = false;
  1644. this.storeTableSettings();
  1645. },
  1646. columnResetWidth(column) {
  1647. const index = this.orderedColumns.indexOf(column);
  1648. if (column.defaultWidth && !Number.isNaN(column.defaultWidth))
  1649. this.orderedColumns[index].width = column.defaultWidth;
  1650. else if (
  1651. column.calculatedWidth &&
  1652. !Number.isNaN(column.calculatedWidth)
  1653. )
  1654. this.orderedColumns[index].width = column.calculatedWidth;
  1655. this.storeTableSettings();
  1656. },
  1657. filterTypes(filter) {
  1658. if (!filter || !filter.filterTypes) return [];
  1659. return filter.filterTypes.map(
  1660. filterType => this.allFilterTypes[filterType]
  1661. );
  1662. },
  1663. changeFilterType(index) {
  1664. this.editingFilters[index].filterType =
  1665. this.allFilterTypes[
  1666. this.editingFilters[index].filter.defaultFilterType
  1667. ];
  1668. },
  1669. onDragBox(e) {
  1670. const e1 = e || window.event;
  1671. const e1IsTouch = e1.type === "touchstart";
  1672. e1.preventDefault();
  1673. if (e1IsTouch) {
  1674. // Handle double click from touch (if this method is twice in a row within one second)
  1675. if (Date.now() - this.lastBulkActionsTappedDate <= 1000) {
  1676. this.resetBulkActionsPosition();
  1677. this.lastBulkActionsTappedDate = 0;
  1678. return;
  1679. }
  1680. this.lastBulkActionsTappedDate = Date.now();
  1681. }
  1682. this.bulkPopup.pos3 = e1IsTouch
  1683. ? e1.changedTouches[0].clientX
  1684. : e1.clientX;
  1685. this.bulkPopup.pos4 = e1IsTouch
  1686. ? e1.changedTouches[0].clientY
  1687. : e1.clientY;
  1688. document.onmousemove = document.ontouchmove = e => {
  1689. const e2 = e || window.event;
  1690. const e2IsTouch = e2.type === "touchmove";
  1691. if (!e2IsTouch) e2.preventDefault();
  1692. // Get the clientX and clientY
  1693. const e2ClientX = e2IsTouch
  1694. ? e2.changedTouches[0].clientX
  1695. : e2.clientX;
  1696. const e2ClientY = e2IsTouch
  1697. ? e2.changedTouches[0].clientY
  1698. : e2.clientY;
  1699. // calculate the new cursor position:
  1700. this.bulkPopup.pos1 = this.bulkPopup.pos3 - e2ClientX;
  1701. this.bulkPopup.pos2 = this.bulkPopup.pos4 - e2ClientY;
  1702. this.bulkPopup.pos3 = e2ClientX;
  1703. this.bulkPopup.pos4 = e2ClientY;
  1704. // set the element's new position:
  1705. this.bulkPopup.top -= this.bulkPopup.pos2;
  1706. this.bulkPopup.left -= this.bulkPopup.pos1;
  1707. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1708. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1709. this.bulkPopup.top = document.body.clientHeight - 50;
  1710. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1711. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1712. this.bulkPopup.left = document.body.clientWidth - 400;
  1713. };
  1714. document.onmouseup = document.ontouchend = () => {
  1715. document.onmouseup = null;
  1716. document.ontouchend = null;
  1717. document.onmousemove = null;
  1718. document.ontouchmove = null;
  1719. };
  1720. },
  1721. resetBulkActionsPosition() {
  1722. this.bulkPopup.top = document.body.clientHeight - 56;
  1723. this.bulkPopup.left = document.body.clientWidth / 2 - 200;
  1724. },
  1725. applyFilterAndGetData() {
  1726. this.appliedFilters = JSON.parse(
  1727. JSON.stringify(this.editingFilters)
  1728. );
  1729. this.appliedFilterOperator = this.filterOperator;
  1730. this.page = 1;
  1731. this.getData();
  1732. this.storeTableSettings();
  1733. },
  1734. recalculateWidths() {
  1735. let noWidthCount = 0;
  1736. let calculatedWidth = 0;
  1737. this.orderedColumns.forEach(column => {
  1738. if (this.shownColumns.indexOf(column.name) !== -1)
  1739. if (
  1740. Number.isFinite(column.width) &&
  1741. !Number.isFinite(column.calculatedWidth)
  1742. ) {
  1743. calculatedWidth += column.width;
  1744. } else if (Number.isFinite(column.defaultWidth)) {
  1745. calculatedWidth += column.defaultWidth;
  1746. } else {
  1747. noWidthCount += 1;
  1748. }
  1749. });
  1750. calculatedWidth = Math.floor(
  1751. (Math.min(this.maxWidth, document.body.clientWidth) -
  1752. calculatedWidth) /
  1753. (noWidthCount - 1)
  1754. );
  1755. this.orderedColumns = this.orderedColumns.map(column => {
  1756. const orderedColumn = column;
  1757. if (this.shownColumns.indexOf(orderedColumn.name) !== -1) {
  1758. let newWidth;
  1759. if (Number.isFinite(orderedColumn.defaultWidth)) {
  1760. newWidth = orderedColumn.defaultWidth;
  1761. } else {
  1762. // eslint-disable-next-line no-param-reassign
  1763. newWidth = orderedColumn.calculatedWidth = Math.min(
  1764. Math.max(
  1765. orderedColumn.minWidth || 100, // fallback 100px min width
  1766. calculatedWidth
  1767. ),
  1768. orderedColumn.maxWidth || 1000 // fallback 1000px max width
  1769. );
  1770. }
  1771. if (newWidth && !Number.isFinite(orderedColumn.width))
  1772. orderedColumn.width = newWidth;
  1773. }
  1774. return orderedColumn;
  1775. });
  1776. },
  1777. columnOrderChanged() {
  1778. this.storeTableSettings();
  1779. },
  1780. getTableSettings() {
  1781. const urlTableSettings = {};
  1782. if (this.query) {
  1783. if (this.$route.query.page)
  1784. urlTableSettings.page = Number.parseInt(
  1785. this.$route.query.page
  1786. );
  1787. if (this.$route.query.pageSize)
  1788. urlTableSettings.pageSize = Number.parseInt(
  1789. this.$route.query.pageSize
  1790. );
  1791. if (this.$route.query.shownColumns)
  1792. urlTableSettings.shownColumns = JSON.parse(
  1793. this.$route.query.shownColumns
  1794. );
  1795. if (this.$route.query.columnOrder)
  1796. urlTableSettings.columnOrder = JSON.parse(
  1797. this.$route.query.columnOrder
  1798. );
  1799. if (this.$route.query.columnWidths)
  1800. urlTableSettings.columnWidths = JSON.parse(
  1801. this.$route.query.columnWidths
  1802. );
  1803. if (this.$route.query.columnSort)
  1804. urlTableSettings.columnSort = JSON.parse(
  1805. this.$route.query.columnSort
  1806. );
  1807. if (this.$route.query.filter)
  1808. urlTableSettings.filter = JSON.parse(
  1809. this.$route.query.filter
  1810. );
  1811. }
  1812. const localStorageTableSettings = JSON.parse(
  1813. localStorage.getItem(`advancedTableSettings:${this.name}`)
  1814. );
  1815. return {
  1816. ...localStorageTableSettings,
  1817. ...urlTableSettings
  1818. };
  1819. },
  1820. storeTableSettings() {
  1821. // Clear debounce timeout
  1822. if (this.storeTableSettingsDebounceTimeout)
  1823. clearTimeout(this.storeTableSettingsDebounceTimeout);
  1824. // Resizing calls this function a lot, so rather than saving dozens of times a second, use debouncing
  1825. this.storeTableSettingsDebounceTimeout = setTimeout(() => {
  1826. if (this.query) this.setQuery();
  1827. this.setLocalStorage();
  1828. }, 250);
  1829. },
  1830. setQuery() {
  1831. const queryObject = {
  1832. ...this.$route.query,
  1833. page: this.page,
  1834. pageSize: this.pageSize,
  1835. filter: JSON.stringify({
  1836. appliedFilters: this.appliedFilters,
  1837. appliedFilterOperator: this.appliedFilterOperator
  1838. }),
  1839. columnSort: JSON.stringify(this.sort),
  1840. columnOrder: JSON.stringify(
  1841. this.orderedColumns.map(column => column.name)
  1842. ),
  1843. columnWidths: JSON.stringify(
  1844. this.orderedColumns.map(column => ({
  1845. name: column.name,
  1846. width: column.width
  1847. }))
  1848. ),
  1849. shownColumns: JSON.stringify(this.shownColumns)
  1850. };
  1851. const queryString = `?${Object.keys(queryObject)
  1852. .map(key => `${key}=${queryObject[key]}`)
  1853. .join("&")}`;
  1854. window.history.replaceState(null, null, queryString);
  1855. },
  1856. setLocalStorage() {
  1857. localStorage.setItem(
  1858. `advancedTableSettings:${this.name}`,
  1859. JSON.stringify({
  1860. pageSize: this.pageSize,
  1861. filter: {
  1862. appliedFilters: this.appliedFilters,
  1863. appliedFilterOperator: this.appliedFilterOperator
  1864. },
  1865. columnSort: this.sort,
  1866. columnOrder: this.orderedColumns.map(column => column.name),
  1867. columnWidths: this.orderedColumns.map(column => ({
  1868. name: column.name,
  1869. width: column.width
  1870. })),
  1871. shownColumns: this.shownColumns
  1872. })
  1873. );
  1874. },
  1875. onWindowResize() {
  1876. // Only change the position if the popup is actually visible
  1877. if (this.selectedRows.length === 0) return;
  1878. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1879. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1880. this.bulkPopup.top = document.body.clientHeight - 50;
  1881. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1882. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1883. this.bulkPopup.left = document.body.clientWidth - 400;
  1884. },
  1885. updateData(index, data) {
  1886. this.rows[index] = { ...this.rows[index], ...data, updated: true };
  1887. },
  1888. removeData(index) {
  1889. this.rows[index] = {
  1890. ...this.rows[index],
  1891. selected: false,
  1892. removed: true
  1893. };
  1894. },
  1895. blurFilterInput(filter, event) {
  1896. if (
  1897. event.relatedTarget &&
  1898. event.relatedTarget.classList.contains("autosuggest-item")
  1899. )
  1900. this.autosuggest.itemFocussed[filter.filter.name] = true;
  1901. this.autosuggest.inputFocussed[filter.filter.name] = false;
  1902. },
  1903. focusFilterInput(filter) {
  1904. this.autosuggest.inputFocussed[filter.filter.name] = true;
  1905. },
  1906. keydownFilterInput(filter) {
  1907. const { name } = filter.filter;
  1908. clearTimeout(this.autosuggest.keydownInputTimeout[name]);
  1909. this.autosuggest.keydownInputTimeout[name] = setTimeout(() => {
  1910. if (filter.data.length > 1) {
  1911. this.autosuggest.items[name] = this.autosuggest.allItems[
  1912. name
  1913. ]?.filter(item =>
  1914. item.toLowerCase().startsWith(filter.data.toLowerCase())
  1915. );
  1916. } else this.autosuggest.items[name] = [];
  1917. }, 1000);
  1918. },
  1919. focusFilterAutosuggestContainer(filter) {
  1920. this.autosuggest.containerFocussed[filter.filter.name] = true;
  1921. },
  1922. blurFilterAutosuggestContainer(filter) {
  1923. this.autosuggest.containerFocussed[filter.filter.name] = false;
  1924. },
  1925. selectAutosuggestItem(index, filter, item) {
  1926. this.editingFilters[index].data = item;
  1927. this.autosuggest.items[filter.filter.name] = [];
  1928. },
  1929. focusAutosuggestItem(filter) {
  1930. this.autosuggest.itemFocussed[filter.filter.name] = true;
  1931. },
  1932. blurAutosuggestItem(filter, event) {
  1933. if (
  1934. !event.relatedTarget ||
  1935. !event.relatedTarget.classList.contains("autosuggest-item")
  1936. )
  1937. this.autosuggest.itemFocussed[filter.filter.name] = false;
  1938. }
  1939. }
  1940. };
  1941. </script>
  1942. <style lang="scss" scoped>
  1943. .night-mode {
  1944. .table-outer-container {
  1945. .table-container .table {
  1946. &,
  1947. thead th {
  1948. background-color: var(--dark-grey-3) !important;
  1949. color: var(--light-grey-2);
  1950. }
  1951. tr {
  1952. th,
  1953. td {
  1954. border-color: var(--dark-grey) !important;
  1955. &:first-child {
  1956. background-color: var(--dark-grey-3) !important;
  1957. }
  1958. }
  1959. &:nth-child(even) {
  1960. &,
  1961. td:first-child {
  1962. background-color: var(--dark-grey-2) !important;
  1963. }
  1964. }
  1965. &:hover,
  1966. &:focus,
  1967. &.highlighted {
  1968. th,
  1969. td {
  1970. &,
  1971. &:first-child {
  1972. background-color: var(--dark-grey-4) !important;
  1973. }
  1974. }
  1975. }
  1976. &.updated td:first-child {
  1977. background-color: var(--primary-color) !important;
  1978. }
  1979. }
  1980. &.has-checkboxes tbody tr {
  1981. td:nth-child(2) {
  1982. background-color: var(--dark-grey-3) !important;
  1983. }
  1984. &:nth-child(even) td:nth-child(2) {
  1985. background-color: var(--dark-grey-2) !important;
  1986. }
  1987. &.updated td:first-child {
  1988. background-color: var(--primary-color) !important;
  1989. }
  1990. &:hover,
  1991. &:focus,
  1992. &.highlighted {
  1993. th,
  1994. td {
  1995. &:nth-child(2) {
  1996. background-color: var(--dark-grey-4) !important;
  1997. }
  1998. }
  1999. }
  2000. }
  2001. }
  2002. .table-header,
  2003. .table-footer {
  2004. background-color: var(--dark-grey-3);
  2005. color: var(--light-grey-2);
  2006. }
  2007. .table-no-results {
  2008. background-color: var(--dark-grey-3);
  2009. color: var(--light-grey-2);
  2010. border-color: var(--dark-grey) !important;
  2011. }
  2012. .label.control {
  2013. background-color: var(--dark-grey) !important;
  2014. border-color: var(--grey-3) !important;
  2015. color: var(--white) !important;
  2016. }
  2017. }
  2018. .bulk-popup {
  2019. border: 0;
  2020. background-color: var(--dark-grey-2);
  2021. color: var(--white);
  2022. .material-icons {
  2023. color: var(--white);
  2024. }
  2025. }
  2026. .autosuggest-container {
  2027. background-color: var(--dark-grey) !important;
  2028. .autosuggest-item {
  2029. background-color: var(--dark-grey) !important;
  2030. color: var(--white) !important;
  2031. border-color: var(--dark-grey) !important;
  2032. }
  2033. .autosuggest-item:hover,
  2034. .autosuggest-item:focus {
  2035. background-color: var(--dark-grey-2) !important;
  2036. }
  2037. }
  2038. }
  2039. .table-outer-container {
  2040. border-radius: 5px;
  2041. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  2042. margin: 10px 0;
  2043. overflow: hidden;
  2044. .table-container {
  2045. overflow-x: auto;
  2046. table {
  2047. border-collapse: separate;
  2048. table-layout: fixed;
  2049. thead {
  2050. tr {
  2051. th {
  2052. height: 40px;
  2053. line-height: 40px;
  2054. border: 1px solid var(--light-grey-2);
  2055. border-width: 1px 1px 1px 0;
  2056. padding: 0;
  2057. &:last-child {
  2058. border-width: 1px 0 1px;
  2059. }
  2060. &.sortable {
  2061. cursor: pointer;
  2062. }
  2063. & > div {
  2064. display: flex;
  2065. white-space: nowrap;
  2066. padding: 8px 10px;
  2067. & > span {
  2068. margin-left: 5px;
  2069. &:first-child {
  2070. margin-left: 0;
  2071. margin-right: auto;
  2072. }
  2073. & > .material-icons {
  2074. font-size: 22px;
  2075. position: relative;
  2076. top: 6px;
  2077. cursor: pointer;
  2078. &.active {
  2079. color: var(--primary-color);
  2080. }
  2081. &:hover,
  2082. &:focus {
  2083. filter: brightness(90%);
  2084. }
  2085. }
  2086. }
  2087. }
  2088. }
  2089. }
  2090. }
  2091. tbody {
  2092. tr {
  2093. &.highlighted {
  2094. background-color: var(--light-grey);
  2095. }
  2096. &.updated {
  2097. td:first-child {
  2098. background-color: var(--primary-color) !important;
  2099. }
  2100. }
  2101. td {
  2102. border: 1px solid var(--light-grey-2);
  2103. border-width: 0 1px 1px 0;
  2104. &:last-child {
  2105. border-width: 0 0 1px;
  2106. }
  2107. /deep/ .row-options {
  2108. display: flex;
  2109. justify-content: space-evenly;
  2110. .icon-with-button {
  2111. height: 30px;
  2112. width: 30px;
  2113. }
  2114. }
  2115. }
  2116. &.removed {
  2117. filter: grayscale(100%);
  2118. cursor: not-allowed;
  2119. user-select: none;
  2120. td .removed-overlay {
  2121. position: absolute;
  2122. top: 0;
  2123. left: 0;
  2124. bottom: 0;
  2125. right: 5px;
  2126. z-index: 5;
  2127. }
  2128. }
  2129. }
  2130. }
  2131. }
  2132. table {
  2133. thead tr,
  2134. tbody tr {
  2135. th,
  2136. td {
  2137. position: relative;
  2138. white-space: nowrap;
  2139. text-overflow: ellipsis;
  2140. overflow: hidden;
  2141. &:first-child {
  2142. display: table-cell;
  2143. position: sticky;
  2144. left: 0;
  2145. background-color: var(--white);
  2146. z-index: 2;
  2147. & > .updated-tooltip {
  2148. position: absolute;
  2149. top: 0;
  2150. left: 0;
  2151. bottom: 0;
  2152. right: 0;
  2153. }
  2154. }
  2155. .resizer {
  2156. height: 100%;
  2157. width: 5px;
  2158. background-color: transparent;
  2159. cursor: col-resize;
  2160. position: absolute;
  2161. right: 0;
  2162. top: 0;
  2163. }
  2164. }
  2165. &:nth-child(even) td:first-child {
  2166. background-color: #fafafa;
  2167. }
  2168. &:hover,
  2169. &:focus,
  2170. &.highlighted {
  2171. th,
  2172. td {
  2173. &,
  2174. &:first-child {
  2175. background-color: var(--light-grey);
  2176. }
  2177. }
  2178. }
  2179. }
  2180. &.has-checkboxes {
  2181. thead,
  2182. tbody {
  2183. tr {
  2184. th,
  2185. td {
  2186. &:nth-child(2) {
  2187. display: table-cell;
  2188. position: sticky;
  2189. left: 5px;
  2190. background-color: var(--white);
  2191. z-index: 2;
  2192. }
  2193. }
  2194. &:hover,
  2195. &:focus,
  2196. &.highlighted {
  2197. th,
  2198. td {
  2199. &:nth-child(2) {
  2200. background-color: var(--light-grey);
  2201. }
  2202. }
  2203. }
  2204. &.updated td:first-child {
  2205. background-color: var(--primary-color);
  2206. }
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. .table-header,
  2213. .table-footer {
  2214. display: flex;
  2215. flex-direction: row;
  2216. flex-wrap: wrap;
  2217. justify-content: space-between;
  2218. line-height: 36px;
  2219. background-color: var(--white);
  2220. }
  2221. .table-header > div {
  2222. display: flex;
  2223. flex-direction: row;
  2224. > span > .control {
  2225. margin: 5px;
  2226. }
  2227. .filters-indicator {
  2228. line-height: 46px;
  2229. display: flex;
  2230. align-items: center;
  2231. column-gap: 4px;
  2232. }
  2233. }
  2234. .table-footer {
  2235. .page-controls,
  2236. .page-size > .control {
  2237. display: flex;
  2238. flex-direction: row;
  2239. margin-bottom: 0 !important;
  2240. button {
  2241. margin: 5px;
  2242. font-size: 20px;
  2243. }
  2244. p,
  2245. label {
  2246. margin: 5px;
  2247. font-size: 14px;
  2248. font-weight: 600;
  2249. }
  2250. &.select::after {
  2251. top: 18px;
  2252. }
  2253. }
  2254. }
  2255. .table-no-results {
  2256. display: flex;
  2257. flex-direction: row;
  2258. justify-content: center;
  2259. border-bottom: 1px solid var(--light-grey-2);
  2260. font-size: 18px;
  2261. line-height: 50px;
  2262. background-color: var(--white);
  2263. }
  2264. }
  2265. .control.is-grouped {
  2266. display: flex;
  2267. & > .control {
  2268. &.label {
  2269. height: 36px;
  2270. background-color: var(--white);
  2271. border: 1px solid var(--light-grey-2);
  2272. color: var(--dark-grey-2);
  2273. appearance: none;
  2274. border-radius: 3px;
  2275. font-size: 14px;
  2276. line-height: 34px;
  2277. padding-left: 8px;
  2278. padding-right: 8px;
  2279. }
  2280. &.select.is-expanded > select {
  2281. width: 100%;
  2282. }
  2283. & > input,
  2284. & > select,
  2285. & > .button,
  2286. &.label {
  2287. border-radius: 0;
  2288. }
  2289. &:first-child {
  2290. & > input,
  2291. & > select,
  2292. & > .button,
  2293. &.label {
  2294. border-radius: 5px 0 0 5px;
  2295. }
  2296. }
  2297. &:last-child {
  2298. & > input,
  2299. & > select,
  2300. & > .button,
  2301. &.label {
  2302. border-radius: 0 5px 5px 0;
  2303. }
  2304. }
  2305. & > .button {
  2306. font-size: 22px;
  2307. }
  2308. }
  2309. @media screen and (max-width: 600px) {
  2310. &.advanced-filter {
  2311. flex-wrap: wrap;
  2312. .control.select {
  2313. width: 50%;
  2314. select {
  2315. width: 100%;
  2316. }
  2317. }
  2318. .control {
  2319. margin-bottom: 0 !important;
  2320. &:nth-child(1) select {
  2321. border-radius: 5px 0 0 0;
  2322. }
  2323. &:nth-child(2) select {
  2324. border-radius: 0 5px 0 0;
  2325. }
  2326. &:nth-child(3) input {
  2327. border-radius: 0 0 0 5px;
  2328. }
  2329. &:nth-child(4) button {
  2330. border-radius: 0 0 5px 0;
  2331. }
  2332. }
  2333. }
  2334. }
  2335. }
  2336. .autosuggest-container {
  2337. position: absolute;
  2338. background: var(--white);
  2339. width: calc(100% + 1px);
  2340. top: 35px;
  2341. z-index: 200;
  2342. overflow: auto;
  2343. max-height: 98px;
  2344. clear: both;
  2345. .autosuggest-item {
  2346. padding: 8px;
  2347. display: block;
  2348. border: 1px solid var(--light-grey-2);
  2349. margin-top: -1px;
  2350. line-height: 16px;
  2351. cursor: pointer;
  2352. -webkit-user-select: none;
  2353. -ms-user-select: none;
  2354. -moz-user-select: none;
  2355. user-select: none;
  2356. }
  2357. .autosuggest-item:hover,
  2358. .autosuggest-item:focus {
  2359. background-color: var(--light-grey);
  2360. }
  2361. .autosuggest-item:first-child {
  2362. border-top: none;
  2363. }
  2364. .autosuggest-item:last-child {
  2365. border-radius: 0 0 3px 3px;
  2366. }
  2367. }
  2368. .advanced-filter {
  2369. .control {
  2370. position: relative;
  2371. }
  2372. }
  2373. .advanced-filter-bottom {
  2374. display: flex;
  2375. .button {
  2376. font-size: 16px !important;
  2377. width: 100%;
  2378. }
  2379. .control {
  2380. margin: 0 !important;
  2381. }
  2382. }
  2383. /deep/ .bulk-popup {
  2384. display: flex;
  2385. position: fixed;
  2386. flex-direction: row;
  2387. width: 100%;
  2388. max-width: 400px;
  2389. line-height: 36px;
  2390. z-index: 5;
  2391. border: 1px solid var(--light-grey-3);
  2392. border-radius: 5px;
  2393. box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  2394. background-color: var(--white);
  2395. color: var(--dark-grey);
  2396. padding: 5px;
  2397. .right {
  2398. display: flex;
  2399. flex-direction: row;
  2400. margin-left: auto;
  2401. }
  2402. .drag-icon {
  2403. position: relative;
  2404. top: 6px;
  2405. color: var(--dark-grey);
  2406. cursor: move;
  2407. }
  2408. .bulk-actions {
  2409. display: flex;
  2410. flex-direction: row;
  2411. width: 100%;
  2412. justify-content: space-evenly;
  2413. .material-icons {
  2414. position: relative;
  2415. top: 6px;
  2416. margin-left: 5px;
  2417. cursor: pointer;
  2418. color: var(--primary-color);
  2419. &:hover,
  2420. &:focus {
  2421. filter: brightness(90%);
  2422. }
  2423. }
  2424. .delete-icon {
  2425. color: var(--dark-red);
  2426. }
  2427. }
  2428. }
  2429. </style>