AdvancedTable.vue 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537
  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. let data = "";
  1569. if (this.addFilterValue.defaultFilterType.startsWith("datetime")) {
  1570. const now = new Date();
  1571. now.setMinutes(now.getMinutes() - now.getTimezoneOffset());
  1572. data = now.toISOString().slice(0, 16);
  1573. }
  1574. this.editingFilters.push({
  1575. data,
  1576. filter: this.addFilterValue,
  1577. filterType:
  1578. this.allFilterTypes[this.addFilterValue.defaultFilterType]
  1579. });
  1580. },
  1581. removeFilterItem(index) {
  1582. this.editingFilters.splice(index, 1);
  1583. },
  1584. columnResizingStart(column, event) {
  1585. const eventIsTouch = event.type === "touchstart";
  1586. if (eventIsTouch) {
  1587. // Handle double click from touch (if this method is called for the same column twice in a row within one second)
  1588. if (
  1589. this.lastColumnResizerTapped === column &&
  1590. Date.now() - this.lastColumnResizerTappedDate <= 1000
  1591. ) {
  1592. this.columnResetWidth(column);
  1593. this.lastColumnResizerTapped = null;
  1594. this.lastColumnResizerTappedDate = 0;
  1595. return;
  1596. }
  1597. this.lastColumnResizerTapped = column;
  1598. this.lastColumnResizerTappedDate = Date.now();
  1599. }
  1600. this.resizing.resizing = true;
  1601. this.resizing.resizingColumn = column;
  1602. this.resizing.width = event.target.parentElement.offsetWidth;
  1603. this.resizing.lastX = eventIsTouch
  1604. ? event.targetTouches[0].clientX
  1605. : event.x;
  1606. },
  1607. columnResizing(event) {
  1608. if (this.resizing.resizing) {
  1609. const eventIsTouch = event.type === "touchmove";
  1610. if (!eventIsTouch && event.buttons !== 1) {
  1611. this.resizing.resizing = false;
  1612. this.storeTableSettings();
  1613. }
  1614. const x = eventIsTouch
  1615. ? event.changedTouches[0].clientX
  1616. : event.x;
  1617. this.resizing.width -= this.resizing.lastX - x;
  1618. this.resizing.lastX = x;
  1619. if (
  1620. this.resizing.resizingColumn.minWidth &&
  1621. this.resizing.resizingColumn.maxWidth
  1622. ) {
  1623. this.resizing.resizingColumn.width = Math.max(
  1624. Math.min(
  1625. this.resizing.resizingColumn.maxWidth,
  1626. this.resizing.width
  1627. ),
  1628. this.resizing.resizingColumn.minWidth
  1629. );
  1630. } else if (this.resizing.resizingColumn.minWidth) {
  1631. this.resizing.resizingColumn.width = Math.max(
  1632. this.resizing.width,
  1633. this.resizing.resizingColumn.minWidth
  1634. );
  1635. } else if (this.resizing.resizingColumn.maxWidth) {
  1636. this.resizing.resizingColumn.width = Math.min(
  1637. this.resizing.resizingColumn.maxWidth,
  1638. this.resizing.width
  1639. );
  1640. } else {
  1641. this.resizing.resizingColumn.width = this.resizing.width;
  1642. }
  1643. this.resizing.width = this.resizing.resizingColumn.width;
  1644. console.log(`New width: ${this.resizing.width}px`);
  1645. this.storeTableSettings();
  1646. }
  1647. },
  1648. columnResizingStop() {
  1649. this.resizing.resizing = false;
  1650. this.storeTableSettings();
  1651. },
  1652. columnResetWidth(column) {
  1653. const index = this.orderedColumns.indexOf(column);
  1654. if (column.defaultWidth && !Number.isNaN(column.defaultWidth))
  1655. this.orderedColumns[index].width = column.defaultWidth;
  1656. else if (
  1657. column.calculatedWidth &&
  1658. !Number.isNaN(column.calculatedWidth)
  1659. )
  1660. this.orderedColumns[index].width = column.calculatedWidth;
  1661. this.storeTableSettings();
  1662. },
  1663. filterTypes(filter) {
  1664. if (!filter || !filter.filterTypes) return [];
  1665. return filter.filterTypes.map(
  1666. filterType => this.allFilterTypes[filterType]
  1667. );
  1668. },
  1669. changeFilterType(index) {
  1670. this.editingFilters[index].filterType =
  1671. this.allFilterTypes[
  1672. this.editingFilters[index].filter.defaultFilterType
  1673. ];
  1674. },
  1675. onDragBox(e) {
  1676. const e1 = e || window.event;
  1677. const e1IsTouch = e1.type === "touchstart";
  1678. e1.preventDefault();
  1679. if (e1IsTouch) {
  1680. // Handle double click from touch (if this method is twice in a row within one second)
  1681. if (Date.now() - this.lastBulkActionsTappedDate <= 1000) {
  1682. this.resetBulkActionsPosition();
  1683. this.lastBulkActionsTappedDate = 0;
  1684. return;
  1685. }
  1686. this.lastBulkActionsTappedDate = Date.now();
  1687. }
  1688. this.bulkPopup.pos3 = e1IsTouch
  1689. ? e1.changedTouches[0].clientX
  1690. : e1.clientX;
  1691. this.bulkPopup.pos4 = e1IsTouch
  1692. ? e1.changedTouches[0].clientY
  1693. : e1.clientY;
  1694. document.onmousemove = document.ontouchmove = e => {
  1695. const e2 = e || window.event;
  1696. const e2IsTouch = e2.type === "touchmove";
  1697. if (!e2IsTouch) e2.preventDefault();
  1698. // Get the clientX and clientY
  1699. const e2ClientX = e2IsTouch
  1700. ? e2.changedTouches[0].clientX
  1701. : e2.clientX;
  1702. const e2ClientY = e2IsTouch
  1703. ? e2.changedTouches[0].clientY
  1704. : e2.clientY;
  1705. // calculate the new cursor position:
  1706. this.bulkPopup.pos1 = this.bulkPopup.pos3 - e2ClientX;
  1707. this.bulkPopup.pos2 = this.bulkPopup.pos4 - e2ClientY;
  1708. this.bulkPopup.pos3 = e2ClientX;
  1709. this.bulkPopup.pos4 = e2ClientY;
  1710. // set the element's new position:
  1711. this.bulkPopup.top -= this.bulkPopup.pos2;
  1712. this.bulkPopup.left -= this.bulkPopup.pos1;
  1713. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1714. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1715. this.bulkPopup.top = document.body.clientHeight - 50;
  1716. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1717. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1718. this.bulkPopup.left = document.body.clientWidth - 400;
  1719. };
  1720. document.onmouseup = document.ontouchend = () => {
  1721. document.onmouseup = null;
  1722. document.ontouchend = null;
  1723. document.onmousemove = null;
  1724. document.ontouchmove = null;
  1725. };
  1726. },
  1727. resetBulkActionsPosition() {
  1728. this.bulkPopup.top = document.body.clientHeight - 56;
  1729. this.bulkPopup.left = document.body.clientWidth / 2 - 200;
  1730. },
  1731. applyFilterAndGetData() {
  1732. this.appliedFilters = JSON.parse(
  1733. JSON.stringify(this.editingFilters)
  1734. );
  1735. this.appliedFilterOperator = this.filterOperator;
  1736. this.page = 1;
  1737. this.getData();
  1738. this.storeTableSettings();
  1739. },
  1740. recalculateWidths() {
  1741. let noWidthCount = 0;
  1742. let calculatedWidth = 0;
  1743. this.orderedColumns.forEach(column => {
  1744. if (this.shownColumns.indexOf(column.name) !== -1)
  1745. if (
  1746. Number.isFinite(column.width) &&
  1747. !Number.isFinite(column.calculatedWidth)
  1748. ) {
  1749. calculatedWidth += column.width;
  1750. } else if (Number.isFinite(column.defaultWidth)) {
  1751. calculatedWidth += column.defaultWidth;
  1752. } else {
  1753. noWidthCount += 1;
  1754. }
  1755. });
  1756. calculatedWidth = Math.floor(
  1757. (Math.min(this.maxWidth, document.body.clientWidth) -
  1758. calculatedWidth) /
  1759. (noWidthCount - 1)
  1760. );
  1761. this.orderedColumns = this.orderedColumns.map(column => {
  1762. const orderedColumn = column;
  1763. if (this.shownColumns.indexOf(orderedColumn.name) !== -1) {
  1764. let newWidth;
  1765. if (Number.isFinite(orderedColumn.defaultWidth)) {
  1766. newWidth = orderedColumn.defaultWidth;
  1767. } else {
  1768. // eslint-disable-next-line no-param-reassign
  1769. newWidth = orderedColumn.calculatedWidth = Math.min(
  1770. Math.max(
  1771. orderedColumn.minWidth || 100, // fallback 100px min width
  1772. calculatedWidth
  1773. ),
  1774. orderedColumn.maxWidth || 1000 // fallback 1000px max width
  1775. );
  1776. }
  1777. if (newWidth && !Number.isFinite(orderedColumn.width))
  1778. orderedColumn.width = newWidth;
  1779. }
  1780. return orderedColumn;
  1781. });
  1782. },
  1783. columnOrderChanged() {
  1784. this.storeTableSettings();
  1785. },
  1786. getTableSettings() {
  1787. const urlTableSettings = {};
  1788. if (this.query) {
  1789. if (this.$route.query.page)
  1790. urlTableSettings.page = Number.parseInt(
  1791. this.$route.query.page
  1792. );
  1793. if (this.$route.query.pageSize)
  1794. urlTableSettings.pageSize = Number.parseInt(
  1795. this.$route.query.pageSize
  1796. );
  1797. if (this.$route.query.shownColumns)
  1798. urlTableSettings.shownColumns = JSON.parse(
  1799. this.$route.query.shownColumns
  1800. );
  1801. if (this.$route.query.columnOrder)
  1802. urlTableSettings.columnOrder = JSON.parse(
  1803. this.$route.query.columnOrder
  1804. );
  1805. if (this.$route.query.columnWidths)
  1806. urlTableSettings.columnWidths = JSON.parse(
  1807. this.$route.query.columnWidths
  1808. );
  1809. if (this.$route.query.columnSort)
  1810. urlTableSettings.columnSort = JSON.parse(
  1811. this.$route.query.columnSort
  1812. );
  1813. if (this.$route.query.filter)
  1814. urlTableSettings.filter = JSON.parse(
  1815. this.$route.query.filter
  1816. );
  1817. }
  1818. const localStorageTableSettings = JSON.parse(
  1819. localStorage.getItem(`advancedTableSettings:${this.name}`)
  1820. );
  1821. return {
  1822. ...localStorageTableSettings,
  1823. ...urlTableSettings
  1824. };
  1825. },
  1826. storeTableSettings() {
  1827. // Clear debounce timeout
  1828. if (this.storeTableSettingsDebounceTimeout)
  1829. clearTimeout(this.storeTableSettingsDebounceTimeout);
  1830. // Resizing calls this function a lot, so rather than saving dozens of times a second, use debouncing
  1831. this.storeTableSettingsDebounceTimeout = setTimeout(() => {
  1832. if (this.query) this.setQuery();
  1833. this.setLocalStorage();
  1834. }, 250);
  1835. },
  1836. setQuery() {
  1837. const queryObject = {
  1838. ...this.$route.query,
  1839. page: this.page,
  1840. pageSize: this.pageSize,
  1841. filter: JSON.stringify({
  1842. appliedFilters: this.appliedFilters,
  1843. appliedFilterOperator: this.appliedFilterOperator
  1844. }),
  1845. columnSort: JSON.stringify(this.sort),
  1846. columnOrder: JSON.stringify(
  1847. this.orderedColumns.map(column => column.name)
  1848. ),
  1849. columnWidths: JSON.stringify(
  1850. this.orderedColumns.map(column => ({
  1851. name: column.name,
  1852. width: column.width
  1853. }))
  1854. ),
  1855. shownColumns: JSON.stringify(this.shownColumns)
  1856. };
  1857. const queryString = `?${Object.keys(queryObject)
  1858. .map(key => `${key}=${queryObject[key]}`)
  1859. .join("&")}`;
  1860. window.history.replaceState(null, null, queryString);
  1861. },
  1862. setLocalStorage() {
  1863. localStorage.setItem(
  1864. `advancedTableSettings:${this.name}`,
  1865. JSON.stringify({
  1866. pageSize: this.pageSize,
  1867. filter: {
  1868. appliedFilters: this.appliedFilters,
  1869. appliedFilterOperator: this.appliedFilterOperator
  1870. },
  1871. columnSort: this.sort,
  1872. columnOrder: this.orderedColumns.map(column => column.name),
  1873. columnWidths: this.orderedColumns.map(column => ({
  1874. name: column.name,
  1875. width: column.width
  1876. })),
  1877. shownColumns: this.shownColumns
  1878. })
  1879. );
  1880. },
  1881. onWindowResize() {
  1882. // Only change the position if the popup is actually visible
  1883. if (this.selectedRows.length === 0) return;
  1884. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1885. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1886. this.bulkPopup.top = document.body.clientHeight - 50;
  1887. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1888. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1889. this.bulkPopup.left = document.body.clientWidth - 400;
  1890. },
  1891. updateData(index, data) {
  1892. this.rows[index] = { ...this.rows[index], ...data, updated: true };
  1893. },
  1894. removeData(index) {
  1895. this.rows[index] = {
  1896. ...this.rows[index],
  1897. selected: false,
  1898. removed: true
  1899. };
  1900. },
  1901. blurFilterInput(filter, event) {
  1902. if (
  1903. event.relatedTarget &&
  1904. event.relatedTarget.classList.contains("autosuggest-item")
  1905. )
  1906. this.autosuggest.itemFocussed[filter.filter.name] = true;
  1907. this.autosuggest.inputFocussed[filter.filter.name] = false;
  1908. },
  1909. focusFilterInput(filter) {
  1910. this.autosuggest.inputFocussed[filter.filter.name] = true;
  1911. },
  1912. keydownFilterInput(filter) {
  1913. const { name } = filter.filter;
  1914. clearTimeout(this.autosuggest.keydownInputTimeout[name]);
  1915. this.autosuggest.keydownInputTimeout[name] = setTimeout(() => {
  1916. if (filter.data.length > 1) {
  1917. this.autosuggest.items[name] = this.autosuggest.allItems[
  1918. name
  1919. ]?.filter(item =>
  1920. item.toLowerCase().startsWith(filter.data.toLowerCase())
  1921. );
  1922. } else this.autosuggest.items[name] = [];
  1923. }, 1000);
  1924. },
  1925. focusFilterAutosuggestContainer(filter) {
  1926. this.autosuggest.containerFocussed[filter.filter.name] = true;
  1927. },
  1928. blurFilterAutosuggestContainer(filter) {
  1929. this.autosuggest.containerFocussed[filter.filter.name] = false;
  1930. },
  1931. selectAutosuggestItem(index, filter, item) {
  1932. this.editingFilters[index].data = item;
  1933. this.autosuggest.items[filter.filter.name] = [];
  1934. },
  1935. focusAutosuggestItem(filter) {
  1936. this.autosuggest.itemFocussed[filter.filter.name] = true;
  1937. },
  1938. blurAutosuggestItem(filter, event) {
  1939. if (
  1940. !event.relatedTarget ||
  1941. !event.relatedTarget.classList.contains("autosuggest-item")
  1942. )
  1943. this.autosuggest.itemFocussed[filter.filter.name] = false;
  1944. }
  1945. }
  1946. };
  1947. </script>
  1948. <style lang="scss" scoped>
  1949. .night-mode {
  1950. .table-outer-container {
  1951. .table-container .table {
  1952. &,
  1953. thead th {
  1954. background-color: var(--dark-grey-3) !important;
  1955. color: var(--light-grey-2);
  1956. }
  1957. tr {
  1958. th,
  1959. td {
  1960. border-color: var(--dark-grey) !important;
  1961. background-color: var(--dark-grey-3) !important;
  1962. }
  1963. &:nth-child(even) td {
  1964. background-color: var(--dark-grey-2) !important;
  1965. }
  1966. &:hover,
  1967. &:focus,
  1968. &.highlighted {
  1969. th,
  1970. td {
  1971. background-color: var(--dark-grey-4) !important;
  1972. }
  1973. }
  1974. &.updated td:first-child {
  1975. background-color: var(--primary-color) !important;
  1976. }
  1977. }
  1978. &.has-checkboxes tbody tr {
  1979. td:nth-child(2) {
  1980. background-color: var(--dark-grey-3) !important;
  1981. }
  1982. &:nth-child(even) td:nth-child(2) {
  1983. background-color: var(--dark-grey-2) !important;
  1984. }
  1985. &.updated td:first-child {
  1986. background-color: var(--primary-color) !important;
  1987. }
  1988. &:hover,
  1989. &:focus,
  1990. &.highlighted {
  1991. th,
  1992. td {
  1993. &:nth-child(2) {
  1994. background-color: var(--dark-grey-4) !important;
  1995. }
  1996. }
  1997. }
  1998. }
  1999. }
  2000. .table-header,
  2001. .table-footer {
  2002. background-color: var(--dark-grey-3);
  2003. color: var(--light-grey-2);
  2004. }
  2005. .table-no-results {
  2006. background-color: var(--dark-grey-3);
  2007. color: var(--light-grey-2);
  2008. border-color: var(--dark-grey) !important;
  2009. }
  2010. .label.control {
  2011. background-color: var(--dark-grey) !important;
  2012. border-color: var(--grey-3) !important;
  2013. color: var(--white) !important;
  2014. }
  2015. }
  2016. .bulk-popup {
  2017. border: 0;
  2018. background-color: var(--dark-grey-2);
  2019. color: var(--white);
  2020. .material-icons {
  2021. color: var(--white);
  2022. }
  2023. }
  2024. .autosuggest-container {
  2025. background-color: var(--dark-grey) !important;
  2026. .autosuggest-item {
  2027. background-color: var(--dark-grey) !important;
  2028. color: var(--white) !important;
  2029. border-color: var(--dark-grey) !important;
  2030. }
  2031. .autosuggest-item:hover,
  2032. .autosuggest-item:focus {
  2033. background-color: var(--dark-grey-2) !important;
  2034. }
  2035. }
  2036. }
  2037. .table-outer-container {
  2038. border-radius: 5px;
  2039. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  2040. margin: 10px 0;
  2041. overflow: hidden;
  2042. .table-container {
  2043. overflow-x: auto;
  2044. table {
  2045. border-collapse: separate;
  2046. table-layout: fixed;
  2047. thead {
  2048. tr {
  2049. th {
  2050. height: 40px;
  2051. line-height: 40px;
  2052. border: 1px solid var(--light-grey-2);
  2053. border-width: 1px 1px 1px 0;
  2054. padding: 0;
  2055. &:last-child {
  2056. border-width: 1px 0 1px;
  2057. }
  2058. &.sortable {
  2059. cursor: pointer;
  2060. }
  2061. & > div {
  2062. display: flex;
  2063. white-space: nowrap;
  2064. padding: 8px 10px;
  2065. & > span {
  2066. margin-left: 5px;
  2067. &:first-child {
  2068. margin-left: 0;
  2069. margin-right: auto;
  2070. }
  2071. & > .material-icons {
  2072. font-size: 22px;
  2073. position: relative;
  2074. top: 6px;
  2075. cursor: pointer;
  2076. &.active {
  2077. color: var(--primary-color);
  2078. }
  2079. &:hover,
  2080. &:focus {
  2081. filter: brightness(90%);
  2082. }
  2083. }
  2084. }
  2085. }
  2086. }
  2087. }
  2088. }
  2089. tbody {
  2090. tr {
  2091. &.highlighted td {
  2092. background-color: var(--light-grey);
  2093. }
  2094. &.updated {
  2095. td:first-child {
  2096. background-color: var(--primary-color) !important;
  2097. }
  2098. }
  2099. &:nth-child(even) td {
  2100. background-color: #fafafa;
  2101. }
  2102. td {
  2103. border: 1px solid var(--light-grey-2);
  2104. border-width: 0 1px 1px 0;
  2105. &:last-child {
  2106. border-width: 0 0 1px;
  2107. }
  2108. /deep/ .row-options {
  2109. display: flex;
  2110. justify-content: space-evenly;
  2111. .icon-with-button {
  2112. height: 30px;
  2113. width: 30px;
  2114. }
  2115. }
  2116. }
  2117. &.removed {
  2118. filter: grayscale(100%);
  2119. cursor: not-allowed;
  2120. user-select: none;
  2121. td .removed-overlay {
  2122. position: absolute;
  2123. top: 0;
  2124. left: 0;
  2125. bottom: 0;
  2126. right: 5px;
  2127. z-index: 5;
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. table {
  2134. thead tr,
  2135. tbody tr {
  2136. th,
  2137. td {
  2138. position: relative;
  2139. white-space: nowrap;
  2140. text-overflow: ellipsis;
  2141. overflow: hidden;
  2142. background-color: var(--white);
  2143. &:first-child {
  2144. display: table-cell;
  2145. position: sticky;
  2146. left: 0;
  2147. z-index: 2;
  2148. & > .updated-tooltip {
  2149. position: absolute;
  2150. top: 0;
  2151. left: 0;
  2152. bottom: 0;
  2153. right: 0;
  2154. }
  2155. }
  2156. .resizer {
  2157. height: 100%;
  2158. width: 5px;
  2159. background-color: transparent;
  2160. cursor: col-resize;
  2161. position: absolute;
  2162. right: 0;
  2163. top: 0;
  2164. }
  2165. }
  2166. &:hover,
  2167. &:focus,
  2168. &.highlighted {
  2169. th,
  2170. td {
  2171. background-color: var(--light-grey);
  2172. }
  2173. }
  2174. }
  2175. &.has-checkboxes {
  2176. thead,
  2177. tbody {
  2178. tr {
  2179. th,
  2180. td {
  2181. &:nth-child(2) {
  2182. display: table-cell;
  2183. position: sticky;
  2184. left: 5px;
  2185. z-index: 2;
  2186. }
  2187. }
  2188. &.updated td:first-child {
  2189. background-color: var(--primary-color);
  2190. }
  2191. }
  2192. }
  2193. }
  2194. }
  2195. }
  2196. .table-header,
  2197. .table-footer {
  2198. display: flex;
  2199. flex-direction: row;
  2200. flex-wrap: wrap;
  2201. justify-content: space-between;
  2202. line-height: 36px;
  2203. background-color: var(--white);
  2204. }
  2205. .table-header > div {
  2206. display: flex;
  2207. flex-direction: row;
  2208. > span > .control {
  2209. margin: 5px;
  2210. }
  2211. .filters-indicator {
  2212. line-height: 46px;
  2213. display: flex;
  2214. align-items: center;
  2215. column-gap: 4px;
  2216. }
  2217. }
  2218. .table-footer {
  2219. .page-controls,
  2220. .page-size > .control {
  2221. display: flex;
  2222. flex-direction: row;
  2223. margin-bottom: 0 !important;
  2224. button {
  2225. margin: 5px;
  2226. font-size: 20px;
  2227. }
  2228. p,
  2229. label {
  2230. margin: 5px;
  2231. font-size: 14px;
  2232. font-weight: 600;
  2233. }
  2234. &.select::after {
  2235. top: 18px;
  2236. }
  2237. }
  2238. }
  2239. .table-no-results {
  2240. display: flex;
  2241. flex-direction: row;
  2242. justify-content: center;
  2243. border-bottom: 1px solid var(--light-grey-2);
  2244. font-size: 18px;
  2245. line-height: 50px;
  2246. background-color: var(--white);
  2247. }
  2248. }
  2249. .control.is-grouped {
  2250. display: flex;
  2251. & > .control {
  2252. &.label {
  2253. height: 36px;
  2254. background-color: var(--white);
  2255. border: 1px solid var(--light-grey-2);
  2256. color: var(--dark-grey-2);
  2257. appearance: none;
  2258. border-radius: 3px;
  2259. font-size: 14px;
  2260. line-height: 34px;
  2261. padding-left: 8px;
  2262. padding-right: 8px;
  2263. }
  2264. &.select.is-expanded > select {
  2265. width: 100%;
  2266. }
  2267. & > input,
  2268. & > select,
  2269. & > .button,
  2270. &.label {
  2271. border-radius: 0;
  2272. }
  2273. &:first-child {
  2274. & > input,
  2275. & > select,
  2276. & > .button,
  2277. &.label {
  2278. border-radius: 5px 0 0 5px;
  2279. }
  2280. }
  2281. &:last-child {
  2282. & > input,
  2283. & > select,
  2284. & > .button,
  2285. &.label {
  2286. border-radius: 0 5px 5px 0;
  2287. }
  2288. }
  2289. & > .button {
  2290. font-size: 22px;
  2291. }
  2292. }
  2293. @media screen and (max-width: 600px) {
  2294. &.advanced-filter {
  2295. flex-wrap: wrap;
  2296. .control.select {
  2297. width: 50%;
  2298. select {
  2299. width: 100%;
  2300. }
  2301. }
  2302. .control {
  2303. margin-bottom: 0 !important;
  2304. &:nth-child(1) select {
  2305. border-radius: 5px 0 0 0;
  2306. }
  2307. &:nth-child(2) select {
  2308. border-radius: 0 5px 0 0;
  2309. }
  2310. &:nth-child(3) input {
  2311. border-radius: 0 0 0 5px;
  2312. }
  2313. &:nth-child(4) button {
  2314. border-radius: 0 0 5px 0;
  2315. }
  2316. }
  2317. }
  2318. }
  2319. }
  2320. .autosuggest-container {
  2321. position: absolute;
  2322. background: var(--white);
  2323. width: calc(100% + 1px);
  2324. top: 35px;
  2325. z-index: 200;
  2326. overflow: auto;
  2327. max-height: 98px;
  2328. clear: both;
  2329. .autosuggest-item {
  2330. padding: 8px;
  2331. display: block;
  2332. border: 1px solid var(--light-grey-2);
  2333. margin-top: -1px;
  2334. line-height: 16px;
  2335. cursor: pointer;
  2336. -webkit-user-select: none;
  2337. -ms-user-select: none;
  2338. -moz-user-select: none;
  2339. user-select: none;
  2340. }
  2341. .autosuggest-item:hover,
  2342. .autosuggest-item:focus {
  2343. background-color: var(--light-grey);
  2344. }
  2345. .autosuggest-item:first-child {
  2346. border-top: none;
  2347. }
  2348. .autosuggest-item:last-child {
  2349. border-radius: 0 0 3px 3px;
  2350. }
  2351. }
  2352. .advanced-filter {
  2353. .control {
  2354. position: relative;
  2355. }
  2356. }
  2357. .advanced-filter-bottom {
  2358. display: flex;
  2359. .button {
  2360. font-size: 16px !important;
  2361. width: 100%;
  2362. }
  2363. .control {
  2364. margin: 0 !important;
  2365. }
  2366. }
  2367. /deep/ .bulk-popup {
  2368. display: flex;
  2369. position: fixed;
  2370. flex-direction: row;
  2371. width: 100%;
  2372. max-width: 400px;
  2373. line-height: 36px;
  2374. z-index: 5;
  2375. border: 1px solid var(--light-grey-3);
  2376. border-radius: 5px;
  2377. box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  2378. background-color: var(--white);
  2379. color: var(--dark-grey);
  2380. padding: 5px;
  2381. .right {
  2382. display: flex;
  2383. flex-direction: row;
  2384. margin-left: auto;
  2385. }
  2386. .drag-icon {
  2387. position: relative;
  2388. top: 6px;
  2389. color: var(--dark-grey);
  2390. cursor: move;
  2391. }
  2392. .bulk-actions {
  2393. display: flex;
  2394. flex-direction: row;
  2395. width: 100%;
  2396. justify-content: space-evenly;
  2397. .material-icons {
  2398. position: relative;
  2399. top: 6px;
  2400. margin-left: 5px;
  2401. cursor: pointer;
  2402. color: var(--primary-color);
  2403. &:hover,
  2404. &:focus {
  2405. filter: brightness(90%);
  2406. }
  2407. }
  2408. .delete-icon {
  2409. color: var(--dark-red);
  2410. }
  2411. }
  2412. }
  2413. </style>