AdvancedTable.vue 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535
  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(property =>
  631. property
  632. .split('.')
  633. .reduce(
  634. (previous, current) =>
  635. (previous !== null &&
  636. previous[
  637. current
  638. ]) !== null || null,
  639. item
  640. )
  641. )
  642. "
  643. ></slot>
  644. <div
  645. v-if="
  646. column.name === 'updatedPlaceholder' &&
  647. item.updated
  648. "
  649. class="updated-tooltip"
  650. content="Row updated"
  651. v-tippy="{
  652. theme: 'info',
  653. placement: 'right'
  654. }"
  655. ></div>
  656. <p
  657. class="checkbox"
  658. v-if="column.name === 'select'"
  659. >
  660. <input
  661. type="checkbox"
  662. :checked="item.selected"
  663. @click="
  664. toggleSelectedRow(itemIndex, $event)
  665. "
  666. :disabled="item.removed"
  667. />
  668. </p>
  669. <span
  670. v-if="item.removed"
  671. class="removed-overlay"
  672. content="Item removed"
  673. v-tippy="{ theme: 'info' }"
  674. ></span>
  675. <div
  676. class="resizer"
  677. v-if="column.resizable"
  678. @mousedown.prevent.stop="
  679. columnResizingStart(column, $event)
  680. "
  681. @touchstart.prevent.stop="
  682. columnResizingStart(column, $event)
  683. "
  684. @mouseup="columnResizingStop()"
  685. @touchend="columnResizingStop()"
  686. @dblclick="columnResetWidth(column)"
  687. ></div>
  688. </td>
  689. </tr>
  690. </tbody>
  691. </table>
  692. </div>
  693. <div v-if="rows.length === 0" class="table-no-results">
  694. No results found
  695. </div>
  696. <div class="table-footer">
  697. <div class="page-controls">
  698. <button
  699. :class="{ disabled: page === 1 }"
  700. class="button is-primary material-icons"
  701. :disabled="page === 1"
  702. @click="changePage(1)"
  703. content="First Page"
  704. v-tippy
  705. >
  706. skip_previous
  707. </button>
  708. <button
  709. :class="{ disabled: page === 1 }"
  710. class="button is-primary material-icons"
  711. :disabled="page === 1"
  712. @click="changePage(page - 1)"
  713. content="Previous Page"
  714. v-tippy
  715. >
  716. fast_rewind
  717. </button>
  718. <p>Page {{ page }} / {{ lastPage > 0 ? lastPage : 1 }}</p>
  719. <button
  720. :class="{
  721. disabled: page === lastPage || lastPage === 0
  722. }"
  723. class="button is-primary material-icons"
  724. :disabled="page === lastPage"
  725. @click="changePage(page + 1)"
  726. content="Next Page"
  727. v-tippy
  728. >
  729. fast_forward
  730. </button>
  731. <button
  732. :class="{
  733. disabled: page === lastPage || lastPage === 0
  734. }"
  735. class="button is-primary material-icons"
  736. :disabled="page === lastPage"
  737. @click="changePage(lastPage)"
  738. content="Last Page"
  739. v-tippy
  740. >
  741. skip_next
  742. </button>
  743. </div>
  744. <div class="page-size">
  745. <div class="control">
  746. <label class="label">Items per page</label>
  747. <p class="control select">
  748. <select
  749. v-model.number="pageSize"
  750. @change="changePageSize()"
  751. >
  752. <option value="10">10</option>
  753. <option value="25">25</option>
  754. <option value="50">50</option>
  755. <option value="100">100</option>
  756. <option value="250">250</option>
  757. <option value="500">500</option>
  758. <option value="1000">1000</option>
  759. </select>
  760. </p>
  761. </div>
  762. </div>
  763. </div>
  764. </div>
  765. <div
  766. v-if="hasCheckboxes && selectedRows.length > 0"
  767. class="bulk-popup"
  768. :style="{
  769. top: bulkPopup.top + 'px',
  770. left: bulkPopup.left + 'px'
  771. }"
  772. ref="bulk-popup"
  773. >
  774. <button
  775. class="button is-primary"
  776. :content="
  777. selectedRows.length === 1
  778. ? `${selectedRows.length} row selected`
  779. : `${selectedRows.length} rows selected`
  780. "
  781. v-tippy="{ theme: 'info' }"
  782. >
  783. {{ selectedRows.length }}
  784. </button>
  785. <slot name="bulk-actions" :item="selectedRows" />
  786. <div class="right">
  787. <span
  788. class="material-icons drag-icon"
  789. @mousedown.left="onDragBox"
  790. @touchstart="onDragBox"
  791. @dblclick="resetBulkActionsPosition()"
  792. >
  793. drag_indicator
  794. </span>
  795. </div>
  796. </div>
  797. </div>
  798. </template>
  799. <script>
  800. import { mapGetters } from "vuex";
  801. import draggable from "vuedraggable";
  802. import Toast from "toasters";
  803. import keyboardShortcuts from "@/keyboardShortcuts";
  804. import ws from "@/ws";
  805. export default {
  806. components: {
  807. draggable
  808. },
  809. props: {
  810. /*
  811. Column properties:
  812. name: Unique lowercase name
  813. displayName: Nice name for the column header
  814. properties: The properties this column needs to show data
  815. sortable: Boolean for whether the order of a particular column can be changed
  816. sortProperty: The property the backend will sort on if this column gets sorted, e.g. title
  817. hidable: Boolean for whether a column can be hidden
  818. defaultVisibility: Default visibility for a column, either "shown" or "hidden"
  819. draggable: Boolean for whether a column can be dragged/reordered,
  820. resizable: Boolean for whether a column can be resized
  821. minWidth: Minimum width of column, e.g. 50px
  822. width: Width of column, e.g. 100px
  823. maxWidth: Maximum width of column, e.g. 150px
  824. */
  825. columnDefault: { type: Object, default: () => {} },
  826. columns: { type: Array, default: null },
  827. filters: { type: Array, default: null },
  828. dataAction: { type: String, default: null },
  829. name: { type: String, default: null },
  830. maxWidth: { type: Number, default: 1880 },
  831. query: { type: Boolean, default: true },
  832. keyboardShortcuts: { type: Boolean, default: true },
  833. events: { type: Object, default: () => {} }
  834. },
  835. data() {
  836. return {
  837. page: 1,
  838. pageSize: 10,
  839. rows: [],
  840. count: 0, // TODO Rename
  841. sort: {},
  842. orderedColumns: [],
  843. shownColumns: [],
  844. columnDragOptions() {
  845. return {
  846. animation: 200,
  847. group: "columns",
  848. disabled: false,
  849. ghostClass: "draggable-list-ghost",
  850. filter: ".ignore-elements",
  851. fallbackTolerance: 50
  852. };
  853. },
  854. editingFilters: [],
  855. appliedFilters: [],
  856. filterOperator: "or",
  857. appliedFilterOperator: "or",
  858. filterOperators: [
  859. {
  860. name: "or",
  861. displayName: "OR"
  862. },
  863. {
  864. name: "and",
  865. displayName: "AND"
  866. },
  867. {
  868. name: "nor",
  869. displayName: "NOR"
  870. }
  871. ],
  872. resizing: {},
  873. allFilterTypes: {
  874. contains: {
  875. name: "contains",
  876. displayName: "Contains"
  877. },
  878. exact: {
  879. name: "exact",
  880. displayName: "Exact"
  881. },
  882. regex: {
  883. name: "regex",
  884. displayName: "Regex"
  885. },
  886. datetimeBefore: {
  887. name: "datetimeBefore",
  888. displayName: "Before"
  889. },
  890. datetimeAfter: {
  891. name: "datetimeAfter",
  892. displayName: "After"
  893. },
  894. numberLesserEqual: {
  895. name: "numberLesserEqual",
  896. displayName: "Less than or equal to"
  897. },
  898. numberLesser: {
  899. name: "numberLesser",
  900. displayName: "Less than"
  901. },
  902. numberGreater: {
  903. name: "numberGreater",
  904. displayName: "Greater than"
  905. },
  906. numberGreaterEqual: {
  907. name: "numberGreaterEqual",
  908. displayName: "Greater than or equal to"
  909. },
  910. numberEquals: {
  911. name: "numberEquals",
  912. displayName: "Equals"
  913. },
  914. boolean: {
  915. name: "boolean",
  916. displayName: "Boolean"
  917. }
  918. },
  919. bulkPopup: {
  920. top: 0,
  921. left: 0,
  922. pos1: 0,
  923. pos2: 0,
  924. pos3: 0,
  925. pos4: 0
  926. },
  927. addFilterValue: null,
  928. showFiltersDropdown: false,
  929. showColumnsDropdown: false,
  930. lastColumnResizerTapped: null,
  931. lastColumnResizerTappedDate: 0,
  932. lastBulkActionsTappedDate: 0,
  933. autosuggest: {
  934. inputFocussed: {},
  935. containerFocussed: {},
  936. itemFocussed: {},
  937. keydownInputTimeout: {},
  938. items: {},
  939. allItems: {
  940. genres: ["edm", "pop", "test"]
  941. }
  942. }
  943. };
  944. },
  945. computed: {
  946. properties() {
  947. return Array.from(
  948. new Set(
  949. this.sortedFilteredColumns.flatMap(
  950. column => column.properties
  951. )
  952. )
  953. );
  954. },
  955. lastPage() {
  956. return Math.ceil(this.count / this.pageSize);
  957. },
  958. sortedFilteredColumns() {
  959. return this.orderedColumns.filter(
  960. column => this.shownColumns.indexOf(column.name) !== -1
  961. );
  962. },
  963. hidableSortedColumns() {
  964. return this.orderedColumns.filter(column => column.hidable);
  965. },
  966. lastSelectedItemIndex() {
  967. return this.rows.findIndex(item => item.highlighted);
  968. },
  969. selectedRows() {
  970. return this.rows.filter(row => row.selected);
  971. },
  972. hasCheckboxes() {
  973. return (
  974. this.$slots["bulk-actions"] != null ||
  975. this.$slots["bulk-actions-right"] != null
  976. );
  977. },
  978. ...mapGetters({
  979. socket: "websockets/getSocket"
  980. })
  981. },
  982. watch: {
  983. selectedRows(newSelectedRows, oldSelectedRows) {
  984. // If selected rows goes from zero to one or more selected, trigger onWindowResize, as otherwise the popup could be out of bounds
  985. if (oldSelectedRows.length === 0 && newSelectedRows.length > 0)
  986. this.onWindowResize();
  987. }
  988. },
  989. mounted() {
  990. const tableSettings = this.getTableSettings();
  991. const columns = [
  992. ...this.columns.map(column => ({
  993. ...this.columnDefault,
  994. ...column
  995. })),
  996. {
  997. name: "placeholder",
  998. displayName: "",
  999. properties: [],
  1000. sortable: false,
  1001. hidable: false,
  1002. draggable: false,
  1003. resizable: false,
  1004. minWidth: "auto",
  1005. width: "auto",
  1006. maxWidth: "auto"
  1007. }
  1008. ];
  1009. if (this.hasCheckboxes)
  1010. columns.unshift({
  1011. name: "select",
  1012. displayName: "",
  1013. properties: [],
  1014. sortable: false,
  1015. hidable: false,
  1016. draggable: false,
  1017. resizable: false,
  1018. minWidth: 47,
  1019. defaultWidth: 47,
  1020. maxWidth: 47
  1021. });
  1022. if (this.events && this.events.updated)
  1023. columns.unshift({
  1024. name: "updatedPlaceholder",
  1025. displayName: "",
  1026. properties: [],
  1027. sortable: false,
  1028. hidable: false,
  1029. draggable: false,
  1030. resizable: false,
  1031. minWidth: 5,
  1032. width: 5,
  1033. maxWidth: 5
  1034. });
  1035. this.orderedColumns = columns.sort((columnA, columnB) => {
  1036. // Always places updatedPlaceholder column in the first position
  1037. if (columnA.name === "updatedPlaceholder") return -1;
  1038. if (columnB.name === "updatedPlaceholder") return 1;
  1039. // Always places select column in the second position
  1040. if (columnA.name === "select") return -1;
  1041. if (columnB.name === "select") return 1;
  1042. // Always places placeholder column in the last position
  1043. if (columnA.name === "placeholder") return 1;
  1044. if (columnB.name === "placeholder") return -1;
  1045. // If there are no table settings stored, use default ordering
  1046. if (!tableSettings || !tableSettings.columnOrder) return 0;
  1047. const indexA = tableSettings.columnOrder.indexOf(columnA.name);
  1048. const indexB = tableSettings.columnOrder.indexOf(columnB.name);
  1049. // If either of the columns is not stored in the table settings, use default ordering
  1050. if (indexA === -1 || indexB === -1) return 0;
  1051. return indexA - indexB;
  1052. });
  1053. this.shownColumns = this.orderedColumns
  1054. .filter(column => {
  1055. // If table settings exist, use shownColumns from settings to determine which columns to show
  1056. if (tableSettings && tableSettings.shownColumns)
  1057. return (
  1058. tableSettings.shownColumns.indexOf(column.name) !== -1
  1059. );
  1060. // Table settings don't exist, only show if the default visibility isn't hidden
  1061. return column.defaultVisibility !== "hidden";
  1062. })
  1063. .map(column => column.name);
  1064. this.recalculateWidths();
  1065. if (tableSettings) {
  1066. // If table settings' page is an integer, use it for the page
  1067. if (Number.isInteger(tableSettings?.page))
  1068. this.page = tableSettings.page;
  1069. // If table settings' pageSize is an integer, use it for the pageSize
  1070. if (Number.isInteger(tableSettings?.pageSize))
  1071. this.pageSize = tableSettings.pageSize;
  1072. // If table settings' columnSort exists, sort all still existing columns based on table settings' columnSort object
  1073. if (tableSettings.columnSort) {
  1074. Object.entries(tableSettings.columnSort).forEach(
  1075. ([columnName, sortDirection]) => {
  1076. if (
  1077. this.columns.find(
  1078. column => column.name === columnName
  1079. )
  1080. )
  1081. this.sort[columnName] = sortDirection;
  1082. }
  1083. );
  1084. }
  1085. // If table settings' columnWidths exists, load the stored widths into the columns
  1086. if (tableSettings.columnWidths) {
  1087. this.orderedColumns = this.orderedColumns.map(orderedColumn => {
  1088. const columnWidth = tableSettings.columnWidths.find(
  1089. column => column.name === orderedColumn.name
  1090. )?.width;
  1091. if (orderedColumn.resizable && columnWidth)
  1092. return { ...orderedColumn, width: columnWidth };
  1093. return orderedColumn;
  1094. });
  1095. }
  1096. if (
  1097. tableSettings.filter &&
  1098. tableSettings.filter.appliedFilters &&
  1099. tableSettings.filter.appliedFilterOperator
  1100. ) {
  1101. const { appliedFilters, appliedFilterOperator } =
  1102. tableSettings.filter;
  1103. // Set the applied filter operator and filter operator to the value stored in table settings
  1104. this.appliedFilterOperator = this.filterOperator =
  1105. appliedFilterOperator;
  1106. // Set the applied filters and editing filters to the value stored in table settings, for all filters that are allowed
  1107. this.appliedFilters = appliedFilters.filter(appliedFilter =>
  1108. this.filters.find(
  1109. filter => appliedFilter.filter.name === filter.name
  1110. )
  1111. );
  1112. this.editingFilters = appliedFilters.filter(appliedFilter =>
  1113. this.filters.find(
  1114. filter => appliedFilter.filter.name === filter.name
  1115. )
  1116. );
  1117. }
  1118. }
  1119. this.resetBulkActionsPosition();
  1120. this.$nextTick(() => {
  1121. this.onWindowResize();
  1122. window.addEventListener("resize", this.onWindowResize);
  1123. });
  1124. ws.onConnect(this.init);
  1125. if (this.events && this.events.updated)
  1126. this.socket.on(`event:${this.events.updated.event}`, res => {
  1127. const index = this.rows
  1128. .map(row => row._id)
  1129. .indexOf(
  1130. this.events.updated.id
  1131. .split(".")
  1132. .reduce(
  1133. (previous, current) =>
  1134. (previous && previous[current]) || null,
  1135. res.data
  1136. )
  1137. );
  1138. const row = this.events.updated.item
  1139. .split(".")
  1140. .reduce(
  1141. (previous, current) =>
  1142. (previous && previous[current]) || null,
  1143. res.data
  1144. );
  1145. this.updateData(index, row);
  1146. });
  1147. if (this.events && this.events.removed)
  1148. this.socket.on(`event:${this.events.removed.event}`, res => {
  1149. const index = this.rows
  1150. .map(row => row._id)
  1151. .indexOf(
  1152. this.events.removed.id
  1153. .split(".")
  1154. .reduce(
  1155. (previous, current) =>
  1156. (previous && previous[current]) || null,
  1157. res.data
  1158. )
  1159. );
  1160. this.removeData(index);
  1161. });
  1162. if (this.keyboardShortcuts) {
  1163. // Navigation section
  1164. // Page navigation section
  1165. keyboardShortcuts.registerShortcut("advancedTable.previousPage", {
  1166. keyCode: 37, // 'Left arrow' key
  1167. ctrl: true,
  1168. preventDefault: true,
  1169. handler: () => {
  1170. // Previous page
  1171. this.changePage(this.page - 1);
  1172. }
  1173. });
  1174. keyboardShortcuts.registerShortcut("advancedTable.nextPage", {
  1175. keyCode: 39, // 'Right arrow' key
  1176. ctrl: true,
  1177. preventDefault: true,
  1178. handler: () => {
  1179. // Next page
  1180. this.changePage(this.page + 1);
  1181. }
  1182. });
  1183. keyboardShortcuts.registerShortcut("advancedTable.firstPage", {
  1184. keyCode: 37, // 'Left arrow' key
  1185. ctrl: true,
  1186. shift: true,
  1187. preventDefault: true,
  1188. handler: () => {
  1189. // First page
  1190. this.changePage(1);
  1191. }
  1192. });
  1193. keyboardShortcuts.registerShortcut("advancedTable.lastPage", {
  1194. keyCode: 39, // 'Right arrow' key
  1195. ctrl: true,
  1196. shift: true,
  1197. preventDefault: true,
  1198. handler: () => {
  1199. // Last page
  1200. this.changePage(this.lastPage);
  1201. }
  1202. });
  1203. // Reset localStorage section
  1204. keyboardShortcuts.registerShortcut(
  1205. "advancedTable.resetLocalStorage",
  1206. {
  1207. keyCode: 116, // 'F5' key
  1208. ctrl: true,
  1209. preventDefault: false,
  1210. handler: () => {
  1211. // Reset local storage
  1212. console.log("Reset local storage");
  1213. localStorage.removeItem(
  1214. `advancedTableSettings:${this.name}`
  1215. );
  1216. this.$router.push({ query: "" });
  1217. }
  1218. }
  1219. );
  1220. // Selecting section
  1221. keyboardShortcuts.registerShortcut("advancedTable.selectAll", {
  1222. keyCode: 65, // 'A' key
  1223. ctrl: true,
  1224. preventDefault: true,
  1225. handler: () => {
  1226. this.toggleAllRows();
  1227. }
  1228. });
  1229. // Popup actions section
  1230. for (let i = 1; i <= 9; i += 1) {
  1231. keyboardShortcuts.registerShortcut(
  1232. `advancedTable.executePopupAction${i}`,
  1233. {
  1234. keyCode: 48 + i, // '1-9' keys, where 49 is 1 and 57 is 9
  1235. ctrl: true,
  1236. preventDefault: true,
  1237. handler: () => {
  1238. // Execute popup action 1-9
  1239. if (this.selectedRows.length === 0) return;
  1240. const bulkActionsElement =
  1241. this.$refs["bulk-popup"].querySelector(
  1242. ".bulk-actions"
  1243. );
  1244. bulkActionsElement.children[i - 1].click();
  1245. }
  1246. }
  1247. );
  1248. }
  1249. keyboardShortcuts.registerShortcut(
  1250. `advancedTable.selectPopupAction1`,
  1251. {
  1252. keyCode: 48, // '0' key
  1253. ctrl: true,
  1254. preventDefault: true,
  1255. handler: () => {
  1256. // Select popup action 0
  1257. if (this.selectedRows.length === 0) return;
  1258. const bulkActionsElement =
  1259. this.$refs["bulk-popup"].querySelector(
  1260. ".bulk-actions"
  1261. );
  1262. bulkActionsElement.children[
  1263. bulkActionsElement.children.length - 1
  1264. ].focus();
  1265. }
  1266. }
  1267. );
  1268. }
  1269. },
  1270. unmounted() {
  1271. window.removeEventListener("resize", this.onWindowResize);
  1272. if (this.storeTableSettingsDebounceTimeout)
  1273. clearTimeout(this.storeTableSettingsDebounceTimeout);
  1274. if (this.keyboardShortcuts) {
  1275. const shortcutNames = [
  1276. // Navigation
  1277. "advancedTable.previousPage",
  1278. "advancedTable.nextPage",
  1279. "advancedTable.firstPage",
  1280. "advancedTable.lastPage",
  1281. // Reset localStorage
  1282. "advancedTable.resetLocalStorage",
  1283. // Selecting
  1284. "advancedTable.selectAll",
  1285. // Popup actions
  1286. "advancedTable.executePopupAction1",
  1287. "advancedTable.executePopupAction2",
  1288. "advancedTable.executePopupAction3",
  1289. "advancedTable.executePopupAction4",
  1290. "advancedTable.executePopupAction5",
  1291. "advancedTable.executePopupAction6",
  1292. "advancedTable.executePopupAction7",
  1293. "advancedTable.executePopupAction8",
  1294. "advancedTable.executePopupAction9",
  1295. "advancedTable.selectPopupAction1"
  1296. ];
  1297. shortcutNames.forEach(shortcutName => {
  1298. keyboardShortcuts.unregisterShortcut(shortcutName);
  1299. });
  1300. }
  1301. },
  1302. methods: {
  1303. init() {
  1304. this.getData();
  1305. if (this.query) this.setQuery();
  1306. if (this.events) {
  1307. if (this.events.room)
  1308. this.socket.dispatch(
  1309. "apis.joinRoom",
  1310. this.events.room,
  1311. () => {}
  1312. );
  1313. if (this.events.adminRoom)
  1314. this.socket.dispatch(
  1315. "apis.joinAdminRoom",
  1316. this.events.adminRoom,
  1317. () => {}
  1318. );
  1319. }
  1320. this.filters.forEach(filter => {
  1321. if (filter.autosuggest && filter.autosuggestDataAction) {
  1322. this.socket.dispatch(filter.autosuggestDataAction, res => {
  1323. if (res.status === "success") {
  1324. const { items } = res.data;
  1325. this.autosuggest.allItems[filter.name] = items;
  1326. } else {
  1327. new Toast(res.message);
  1328. }
  1329. });
  1330. }
  1331. });
  1332. },
  1333. getData() {
  1334. this.socket.dispatch(
  1335. this.dataAction,
  1336. this.page,
  1337. this.pageSize,
  1338. this.properties,
  1339. this.sort,
  1340. this.appliedFilters.map(filter => ({
  1341. ...filter,
  1342. filterType: filter.filterType.name
  1343. })),
  1344. this.appliedFilterOperator,
  1345. res => {
  1346. console.log(111, res);
  1347. if (res.status === "success") {
  1348. const { data, count } = res.data;
  1349. this.rows = data.map(row => ({
  1350. ...row,
  1351. selected: false
  1352. }));
  1353. this.count = count;
  1354. } else {
  1355. new Toast(res.message);
  1356. }
  1357. }
  1358. );
  1359. },
  1360. changePageSize() {
  1361. this.page = 1;
  1362. this.getData();
  1363. this.storeTableSettings();
  1364. },
  1365. changePage(page) {
  1366. if (page < 1) return;
  1367. if (page > this.lastPage) return;
  1368. if (page === this.page) return;
  1369. this.page = page;
  1370. this.getData();
  1371. if (this.query) this.setQuery();
  1372. },
  1373. changeSort(column) {
  1374. if (column.sortable) {
  1375. const { sortProperty } = column;
  1376. if (this.sort[sortProperty] === undefined)
  1377. this.sort[sortProperty] = "ascending";
  1378. else if (this.sort[sortProperty] === "ascending")
  1379. this.sort[sortProperty] = "descending";
  1380. else if (this.sort[sortProperty] === "descending")
  1381. delete this.sort[sortProperty];
  1382. this.getData();
  1383. this.storeTableSettings();
  1384. }
  1385. },
  1386. toggleColumnVisibility(column) {
  1387. if (!column.hidable) return false;
  1388. if (this.shownColumns.indexOf(column.name) !== -1) {
  1389. if (this.shownColumns.length <= 3)
  1390. return new Toast(
  1391. `Unable to hide column ${column.displayName}, there must be at least 1 visibile column`
  1392. );
  1393. this.shownColumns.splice(
  1394. this.shownColumns.indexOf(column.name),
  1395. 1
  1396. );
  1397. } else {
  1398. this.shownColumns.push(column.name);
  1399. }
  1400. this.recalculateWidths();
  1401. this.getData();
  1402. return this.storeTableSettings();
  1403. },
  1404. toggleSelectedRow(itemIndex, event) {
  1405. const { shiftKey, ctrlKey } = event;
  1406. // Shift was pressed, so attempt to select all items between the clicked item and last clicked item
  1407. if (shiftKey) {
  1408. // If the clicked item is already selected, prevent default, otherwise the checkbox will be unchecked
  1409. if (this.rows[itemIndex].selected) event.preventDefault();
  1410. // If there is a last clicked item
  1411. if (this.lastSelectedItemIndex >= 0) {
  1412. // Clicked item is lower than last item, so select upwards until it reaches the last selected item
  1413. if (itemIndex > this.lastSelectedItemIndex) {
  1414. for (
  1415. let itemIndexUp = itemIndex;
  1416. itemIndexUp > this.lastSelectedItemIndex;
  1417. itemIndexUp -= 1
  1418. ) {
  1419. if (!this.rows[itemIndexUp].removed)
  1420. this.rows[itemIndexUp].selected = true;
  1421. }
  1422. }
  1423. // Clicked item is higher than last item, so select downwards until it reaches the last selected item
  1424. else if (itemIndex < this.lastSelectedItemIndex) {
  1425. for (
  1426. let itemIndexDown = itemIndex;
  1427. itemIndexDown < this.lastSelectedItemIndex;
  1428. itemIndexDown += 1
  1429. ) {
  1430. if (!this.rows[itemIndexDown].removed)
  1431. this.rows[itemIndexDown].selected = true;
  1432. }
  1433. }
  1434. }
  1435. }
  1436. // Ctrl was pressed, so attempt to unselect all items between the clicked item and last clicked item
  1437. else if (ctrlKey) {
  1438. // If the clicked item is already unselected, prevent default, otherwise the checkbox will be checked
  1439. if (!this.rows[itemIndex].selected) event.preventDefault();
  1440. // If there is a last clicked item
  1441. if (this.lastSelectedItemIndex >= 0) {
  1442. // Clicked item is lower than last item, so unselect upwards until it reaches the last selected item
  1443. if (itemIndex > this.lastSelectedItemIndex) {
  1444. for (
  1445. let itemIndexUp = itemIndex;
  1446. itemIndexUp >= this.lastSelectedItemIndex;
  1447. itemIndexUp -= 1
  1448. ) {
  1449. if (!this.rows[itemIndexUp].removed)
  1450. this.rows[itemIndexUp].selected = false;
  1451. }
  1452. }
  1453. // Clicked item is higher than last item, so unselect downwards until it reaches the last selected item
  1454. else if (itemIndex < this.lastSelectedItemIndex) {
  1455. for (
  1456. let itemIndexDown = itemIndex;
  1457. itemIndexDown <= this.lastSelectedItemIndex;
  1458. itemIndexDown += 1
  1459. ) {
  1460. if (!this.rows[itemIndexDown].removed)
  1461. this.rows[itemIndexDown].selected = false;
  1462. }
  1463. }
  1464. }
  1465. }
  1466. // Neither ctrl nor shift were pressed, so toggle clicked item
  1467. else {
  1468. this.rows[itemIndex].selected = !this.rows[itemIndex].selected;
  1469. }
  1470. // Set the last clicked item to no longer be highlighted, if it exists
  1471. if (this.lastSelectedItemIndex >= 0)
  1472. this.rows[this.lastSelectedItemIndex].highlighted = false;
  1473. // Set the clicked item to be highlighted
  1474. this.rows[itemIndex].highlighted = true;
  1475. },
  1476. toggleAllRows() {
  1477. if (
  1478. this.rows.filter(row => !row.removed).length >
  1479. this.selectedRows.length
  1480. ) {
  1481. this.rows = this.rows.map(row => {
  1482. if (row.removed) return row;
  1483. return { ...row, selected: true };
  1484. });
  1485. } else {
  1486. this.rows = this.rows.map(row => {
  1487. if (row.removed) return row;
  1488. return { ...row, selected: false };
  1489. });
  1490. }
  1491. },
  1492. highlightUp(itemIndex) {
  1493. if (itemIndex === 0) return;
  1494. const newItemIndex = itemIndex - 1;
  1495. this.highlightRow(newItemIndex);
  1496. },
  1497. highlightDown(itemIndex) {
  1498. if (itemIndex === this.rows.length - 1) return;
  1499. const newItemIndex = itemIndex + 1;
  1500. this.highlightRow(newItemIndex);
  1501. },
  1502. highlightRow(itemIndex) {
  1503. const rowElement = this.$refs[`row-${itemIndex}`];
  1504. // Set the last clicked item to no longer be highlighted, if it exists
  1505. if (this.lastSelectedItemIndex >= 0)
  1506. this.rows[this.lastSelectedItemIndex].highlighted = false;
  1507. if (rowElement) rowElement.focus();
  1508. // Set the item to be highlighted
  1509. this.rows[itemIndex].highlighted = true;
  1510. },
  1511. selectUp(itemIndex) {
  1512. if (itemIndex === 0) return;
  1513. const newItemIndex = itemIndex - 1;
  1514. if (!this.rows[itemIndex].removed)
  1515. this.rows[itemIndex].selected = true;
  1516. if (!this.rows[newItemIndex].removed)
  1517. this.rows[newItemIndex].selected = true;
  1518. this.highlightRow(newItemIndex);
  1519. },
  1520. selectDown(itemIndex) {
  1521. if (itemIndex === this.rows.length - 1) return;
  1522. const newItemIndex = itemIndex + 1;
  1523. if (!this.rows[itemIndex].removed)
  1524. this.rows[itemIndex].selected = true;
  1525. if (!this.rows[newItemIndex].removed)
  1526. this.rows[newItemIndex].selected = true;
  1527. this.highlightRow(newItemIndex);
  1528. },
  1529. unselectUp(itemIndex) {
  1530. if (itemIndex === 0) return;
  1531. const newItemIndex = itemIndex - 1;
  1532. if (!this.rows[itemIndex].removed)
  1533. this.rows[itemIndex].selected = false;
  1534. if (!this.rows[newItemIndex].removed)
  1535. this.rows[newItemIndex].selected = false;
  1536. this.highlightRow(newItemIndex);
  1537. },
  1538. unselectDown(itemIndex) {
  1539. if (itemIndex === this.rows.length - 1) return;
  1540. const newItemIndex = itemIndex + 1;
  1541. if (!this.rows[itemIndex].removed)
  1542. this.rows[itemIndex].selected = false;
  1543. if (!this.rows[newItemIndex].removed)
  1544. this.rows[newItemIndex].selected = false;
  1545. this.highlightRow(newItemIndex);
  1546. },
  1547. addFilterItem() {
  1548. this.editingFilters.push({
  1549. data: "",
  1550. filter: this.addFilterValue,
  1551. filterType:
  1552. this.allFilterTypes[this.addFilterValue.defaultFilterType]
  1553. });
  1554. },
  1555. removeFilterItem(index) {
  1556. this.editingFilters.splice(index, 1);
  1557. },
  1558. columnResizingStart(column, event) {
  1559. const eventIsTouch = event.type === "touchstart";
  1560. if (eventIsTouch) {
  1561. // Handle double click from touch (if this method is called for the same column twice in a row within one second)
  1562. if (
  1563. this.lastColumnResizerTapped === column &&
  1564. Date.now() - this.lastColumnResizerTappedDate <= 1000
  1565. ) {
  1566. this.columnResetWidth(column);
  1567. this.lastColumnResizerTapped = null;
  1568. this.lastColumnResizerTappedDate = 0;
  1569. return;
  1570. }
  1571. this.lastColumnResizerTapped = column;
  1572. this.lastColumnResizerTappedDate = Date.now();
  1573. }
  1574. this.resizing.resizing = true;
  1575. this.resizing.resizingColumn = column;
  1576. this.resizing.width = event.target.parentElement.offsetWidth;
  1577. this.resizing.lastX = eventIsTouch
  1578. ? event.targetTouches[0].clientX
  1579. : event.x;
  1580. },
  1581. columnResizing(event) {
  1582. if (this.resizing.resizing) {
  1583. const eventIsTouch = event.type === "touchmove";
  1584. if (!eventIsTouch && event.buttons !== 1) {
  1585. this.resizing.resizing = false;
  1586. this.storeTableSettings();
  1587. }
  1588. const x = eventIsTouch
  1589. ? event.changedTouches[0].clientX
  1590. : event.x;
  1591. this.resizing.width -= this.resizing.lastX - x;
  1592. this.resizing.lastX = x;
  1593. if (
  1594. this.resizing.resizingColumn.minWidth &&
  1595. this.resizing.resizingColumn.maxWidth
  1596. ) {
  1597. this.resizing.resizingColumn.width = Math.max(
  1598. Math.min(
  1599. this.resizing.resizingColumn.maxWidth,
  1600. this.resizing.width
  1601. ),
  1602. this.resizing.resizingColumn.minWidth
  1603. );
  1604. } else if (this.resizing.resizingColumn.minWidth) {
  1605. this.resizing.resizingColumn.width = Math.max(
  1606. this.resizing.width,
  1607. this.resizing.resizingColumn.minWidth
  1608. );
  1609. } else if (this.resizing.resizingColumn.maxWidth) {
  1610. this.resizing.resizingColumn.width = Math.min(
  1611. this.resizing.resizingColumn.maxWidth,
  1612. this.resizing.width
  1613. );
  1614. } else {
  1615. this.resizing.resizingColumn.width = this.resizing.width;
  1616. }
  1617. this.resizing.width = this.resizing.resizingColumn.width;
  1618. console.log(`New width: ${this.resizing.width}px`);
  1619. this.storeTableSettings();
  1620. }
  1621. },
  1622. columnResizingStop() {
  1623. this.resizing.resizing = false;
  1624. this.storeTableSettings();
  1625. },
  1626. columnResetWidth(column) {
  1627. const index = this.orderedColumns.indexOf(column);
  1628. if (column.defaultWidth && !Number.isNaN(column.defaultWidth))
  1629. this.orderedColumns[index].width = column.defaultWidth;
  1630. else if (
  1631. column.calculatedWidth &&
  1632. !Number.isNaN(column.calculatedWidth)
  1633. )
  1634. this.orderedColumns[index].width = column.calculatedWidth;
  1635. this.storeTableSettings();
  1636. },
  1637. filterTypes(filter) {
  1638. if (!filter || !filter.filterTypes) return [];
  1639. return filter.filterTypes.map(
  1640. filterType => this.allFilterTypes[filterType]
  1641. );
  1642. },
  1643. changeFilterType(index) {
  1644. this.editingFilters[index].filterType =
  1645. this.allFilterTypes[
  1646. this.editingFilters[index].filter.defaultFilterType
  1647. ];
  1648. },
  1649. onDragBox(e) {
  1650. const e1 = e || window.event;
  1651. const e1IsTouch = e1.type === "touchstart";
  1652. e1.preventDefault();
  1653. if (e1IsTouch) {
  1654. // Handle double click from touch (if this method is twice in a row within one second)
  1655. if (Date.now() - this.lastBulkActionsTappedDate <= 1000) {
  1656. this.resetBulkActionsPosition();
  1657. this.lastBulkActionsTappedDate = 0;
  1658. return;
  1659. }
  1660. this.lastBulkActionsTappedDate = Date.now();
  1661. }
  1662. this.bulkPopup.pos3 = e1IsTouch
  1663. ? e1.changedTouches[0].clientX
  1664. : e1.clientX;
  1665. this.bulkPopup.pos4 = e1IsTouch
  1666. ? e1.changedTouches[0].clientY
  1667. : e1.clientY;
  1668. document.onmousemove = document.ontouchmove = e => {
  1669. const e2 = e || window.event;
  1670. const e2IsTouch = e2.type === "touchmove";
  1671. if (!e2IsTouch) e2.preventDefault();
  1672. // Get the clientX and clientY
  1673. const e2ClientX = e2IsTouch
  1674. ? e2.changedTouches[0].clientX
  1675. : e2.clientX;
  1676. const e2ClientY = e2IsTouch
  1677. ? e2.changedTouches[0].clientY
  1678. : e2.clientY;
  1679. // calculate the new cursor position:
  1680. this.bulkPopup.pos1 = this.bulkPopup.pos3 - e2ClientX;
  1681. this.bulkPopup.pos2 = this.bulkPopup.pos4 - e2ClientY;
  1682. this.bulkPopup.pos3 = e2ClientX;
  1683. this.bulkPopup.pos4 = e2ClientY;
  1684. // set the element's new position:
  1685. this.bulkPopup.top -= this.bulkPopup.pos2;
  1686. this.bulkPopup.left -= this.bulkPopup.pos1;
  1687. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1688. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1689. this.bulkPopup.top = document.body.clientHeight - 50;
  1690. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1691. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1692. this.bulkPopup.left = document.body.clientWidth - 400;
  1693. };
  1694. document.onmouseup = document.ontouchend = () => {
  1695. document.onmouseup = null;
  1696. document.ontouchend = null;
  1697. document.onmousemove = null;
  1698. document.ontouchmove = null;
  1699. };
  1700. },
  1701. resetBulkActionsPosition() {
  1702. this.bulkPopup.top = document.body.clientHeight - 56;
  1703. this.bulkPopup.left = document.body.clientWidth / 2 - 200;
  1704. },
  1705. applyFilterAndGetData() {
  1706. this.appliedFilters = JSON.parse(
  1707. JSON.stringify(this.editingFilters)
  1708. );
  1709. this.appliedFilterOperator = this.filterOperator;
  1710. this.page = 1;
  1711. this.getData();
  1712. this.storeTableSettings();
  1713. },
  1714. recalculateWidths() {
  1715. let noWidthCount = 0;
  1716. let calculatedWidth = 0;
  1717. this.orderedColumns.forEach(column => {
  1718. if (this.shownColumns.indexOf(column.name) !== -1)
  1719. if (
  1720. Number.isFinite(column.width) &&
  1721. !Number.isFinite(column.calculatedWidth)
  1722. ) {
  1723. calculatedWidth += column.width;
  1724. } else if (Number.isFinite(column.defaultWidth)) {
  1725. calculatedWidth += column.defaultWidth;
  1726. } else {
  1727. noWidthCount += 1;
  1728. }
  1729. });
  1730. calculatedWidth = Math.floor(
  1731. (Math.min(this.maxWidth, document.body.clientWidth) -
  1732. calculatedWidth) /
  1733. (noWidthCount - 1)
  1734. );
  1735. this.orderedColumns = this.orderedColumns.map(column => {
  1736. const orderedColumn = column;
  1737. if (this.shownColumns.indexOf(orderedColumn.name) !== -1) {
  1738. let newWidth;
  1739. if (Number.isFinite(orderedColumn.defaultWidth)) {
  1740. newWidth = orderedColumn.defaultWidth;
  1741. } else {
  1742. // eslint-disable-next-line no-param-reassign
  1743. newWidth = orderedColumn.calculatedWidth = Math.min(
  1744. Math.max(
  1745. orderedColumn.minWidth || 100, // fallback 100px min width
  1746. calculatedWidth
  1747. ),
  1748. orderedColumn.maxWidth || 1000 // fallback 1000px max width
  1749. );
  1750. }
  1751. if (newWidth && !Number.isFinite(orderedColumn.width))
  1752. orderedColumn.width = newWidth;
  1753. }
  1754. return orderedColumn;
  1755. });
  1756. },
  1757. columnOrderChanged() {
  1758. this.storeTableSettings();
  1759. },
  1760. getTableSettings() {
  1761. const urlTableSettings = {};
  1762. if (this.query) {
  1763. if (this.$route.query.page)
  1764. urlTableSettings.page = Number.parseInt(
  1765. this.$route.query.page
  1766. );
  1767. if (this.$route.query.pageSize)
  1768. urlTableSettings.pageSize = Number.parseInt(
  1769. this.$route.query.pageSize
  1770. );
  1771. if (this.$route.query.shownColumns)
  1772. urlTableSettings.shownColumns = JSON.parse(
  1773. this.$route.query.shownColumns
  1774. );
  1775. if (this.$route.query.columnOrder)
  1776. urlTableSettings.columnOrder = JSON.parse(
  1777. this.$route.query.columnOrder
  1778. );
  1779. if (this.$route.query.columnWidths)
  1780. urlTableSettings.columnWidths = JSON.parse(
  1781. this.$route.query.columnWidths
  1782. );
  1783. if (this.$route.query.columnSort)
  1784. urlTableSettings.columnSort = JSON.parse(
  1785. this.$route.query.columnSort
  1786. );
  1787. if (this.$route.query.filter)
  1788. urlTableSettings.filter = JSON.parse(
  1789. this.$route.query.filter
  1790. );
  1791. }
  1792. const localStorageTableSettings = JSON.parse(
  1793. localStorage.getItem(`advancedTableSettings:${this.name}`)
  1794. );
  1795. return {
  1796. ...localStorageTableSettings,
  1797. ...urlTableSettings
  1798. };
  1799. },
  1800. storeTableSettings() {
  1801. // Clear debounce timeout
  1802. if (this.storeTableSettingsDebounceTimeout)
  1803. clearTimeout(this.storeTableSettingsDebounceTimeout);
  1804. // Resizing calls this function a lot, so rather than saving dozens of times a second, use debouncing
  1805. this.storeTableSettingsDebounceTimeout = setTimeout(() => {
  1806. if (this.query) this.setQuery();
  1807. this.setLocalStorage();
  1808. }, 250);
  1809. },
  1810. setQuery() {
  1811. const queryObject = {
  1812. ...this.$route.query,
  1813. page: this.page,
  1814. pageSize: this.pageSize,
  1815. filter: JSON.stringify({
  1816. appliedFilters: this.appliedFilters,
  1817. appliedFilterOperator: this.appliedFilterOperator
  1818. }),
  1819. columnSort: JSON.stringify(this.sort),
  1820. columnOrder: JSON.stringify(
  1821. this.orderedColumns.map(column => column.name)
  1822. ),
  1823. columnWidths: JSON.stringify(
  1824. this.orderedColumns.map(column => ({
  1825. name: column.name,
  1826. width: column.width
  1827. }))
  1828. ),
  1829. shownColumns: JSON.stringify(this.shownColumns)
  1830. };
  1831. const queryString = `?${Object.keys(queryObject)
  1832. .map(key => `${key}=${queryObject[key]}`)
  1833. .join("&")}`;
  1834. window.history.replaceState(null, null, queryString);
  1835. },
  1836. setLocalStorage() {
  1837. localStorage.setItem(
  1838. `advancedTableSettings:${this.name}`,
  1839. JSON.stringify({
  1840. pageSize: this.pageSize,
  1841. filter: {
  1842. appliedFilters: this.appliedFilters,
  1843. appliedFilterOperator: this.appliedFilterOperator
  1844. },
  1845. columnSort: this.sort,
  1846. columnOrder: this.orderedColumns.map(column => column.name),
  1847. columnWidths: this.orderedColumns.map(column => ({
  1848. name: column.name,
  1849. width: column.width
  1850. })),
  1851. shownColumns: this.shownColumns
  1852. })
  1853. );
  1854. },
  1855. onWindowResize() {
  1856. // Only change the position if the popup is actually visible
  1857. if (this.selectedRows.length === 0) return;
  1858. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1859. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1860. this.bulkPopup.top = document.body.clientHeight - 50;
  1861. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1862. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1863. this.bulkPopup.left = document.body.clientWidth - 400;
  1864. },
  1865. updateData(index, data) {
  1866. this.rows[index] = { ...this.rows[index], ...data, updated: true };
  1867. },
  1868. removeData(index) {
  1869. this.rows[index] = {
  1870. ...this.rows[index],
  1871. selected: false,
  1872. removed: true
  1873. };
  1874. },
  1875. blurFilterInput(filter, event) {
  1876. if (
  1877. event.relatedTarget &&
  1878. event.relatedTarget.classList.contains("autosuggest-item")
  1879. )
  1880. this.autosuggest.itemFocussed[filter.filter.name] = true;
  1881. this.autosuggest.inputFocussed[filter.filter.name] = false;
  1882. },
  1883. focusFilterInput(filter) {
  1884. this.autosuggest.inputFocussed[filter.filter.name] = true;
  1885. },
  1886. keydownFilterInput(filter) {
  1887. const { name } = filter.filter;
  1888. clearTimeout(this.autosuggest.keydownInputTimeout[name]);
  1889. this.autosuggest.keydownInputTimeout[name] = setTimeout(() => {
  1890. if (filter.data.length > 1) {
  1891. this.autosuggest.items[name] = this.autosuggest.allItems[
  1892. name
  1893. ]?.filter(item =>
  1894. item.toLowerCase().startsWith(filter.data.toLowerCase())
  1895. );
  1896. } else this.autosuggest.items[name] = [];
  1897. }, 1000);
  1898. },
  1899. focusFilterAutosuggestContainer(filter) {
  1900. this.autosuggest.containerFocussed[filter.filter.name] = true;
  1901. },
  1902. blurFilterAutosuggestContainer(filter) {
  1903. this.autosuggest.containerFocussed[filter.filter.name] = false;
  1904. },
  1905. selectAutosuggestItem(index, filter, item) {
  1906. this.editingFilters[index].data = item;
  1907. this.autosuggest.items[filter.filter.name] = [];
  1908. },
  1909. focusAutosuggestItem(filter) {
  1910. this.autosuggest.itemFocussed[filter.filter.name] = true;
  1911. },
  1912. blurAutosuggestItem(filter, event) {
  1913. if (
  1914. !event.relatedTarget ||
  1915. !event.relatedTarget.classList.contains("autosuggest-item")
  1916. )
  1917. this.autosuggest.itemFocussed[filter.filter.name] = false;
  1918. }
  1919. }
  1920. };
  1921. </script>
  1922. <style lang="scss" scoped>
  1923. .night-mode {
  1924. .table-outer-container {
  1925. .table-container .table {
  1926. &,
  1927. thead th {
  1928. background-color: var(--dark-grey-3) !important;
  1929. color: var(--light-grey-2);
  1930. }
  1931. tr {
  1932. th,
  1933. td {
  1934. border-color: var(--dark-grey) !important;
  1935. &:first-child {
  1936. background-color: var(--dark-grey-3) !important;
  1937. }
  1938. }
  1939. &:nth-child(even) {
  1940. &,
  1941. td:first-child {
  1942. background-color: var(--dark-grey-2) !important;
  1943. }
  1944. }
  1945. &:hover,
  1946. &:focus,
  1947. &.highlighted {
  1948. th,
  1949. td {
  1950. &,
  1951. &:first-child {
  1952. background-color: var(--dark-grey-4) !important;
  1953. }
  1954. }
  1955. }
  1956. &.updated td:first-child {
  1957. background-color: var(--primary-color) !important;
  1958. }
  1959. }
  1960. &.has-checkboxes tbody tr {
  1961. td:nth-child(2) {
  1962. background-color: var(--dark-grey-3) !important;
  1963. }
  1964. &:nth-child(even) td:nth-child(2) {
  1965. background-color: var(--dark-grey-2) !important;
  1966. }
  1967. &.updated td:first-child {
  1968. background-color: var(--primary-color) !important;
  1969. }
  1970. &:hover,
  1971. &:focus,
  1972. &.highlighted {
  1973. th,
  1974. td {
  1975. &:nth-child(2) {
  1976. background-color: var(--dark-grey-4) !important;
  1977. }
  1978. }
  1979. }
  1980. }
  1981. }
  1982. .table-header,
  1983. .table-footer {
  1984. background-color: var(--dark-grey-3);
  1985. color: var(--light-grey-2);
  1986. }
  1987. .table-no-results {
  1988. background-color: var(--dark-grey-3);
  1989. color: var(--light-grey-2);
  1990. border-color: var(--dark-grey) !important;
  1991. }
  1992. .label.control {
  1993. background-color: var(--dark-grey) !important;
  1994. border-color: var(--grey-3) !important;
  1995. color: var(--white) !important;
  1996. }
  1997. }
  1998. .bulk-popup {
  1999. border: 0;
  2000. background-color: var(--dark-grey-2);
  2001. color: var(--white);
  2002. .material-icons {
  2003. color: var(--white);
  2004. }
  2005. }
  2006. .autosuggest-container {
  2007. background-color: var(--dark-grey) !important;
  2008. .autosuggest-item {
  2009. background-color: var(--dark-grey) !important;
  2010. color: var(--white) !important;
  2011. border-color: var(--dark-grey) !important;
  2012. }
  2013. .autosuggest-item:hover,
  2014. .autosuggest-item:focus {
  2015. background-color: var(--dark-grey-2) !important;
  2016. }
  2017. }
  2018. }
  2019. .table-outer-container {
  2020. border-radius: 5px;
  2021. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  2022. margin: 10px 0;
  2023. overflow: hidden;
  2024. .table-container {
  2025. overflow-x: auto;
  2026. table {
  2027. border-collapse: separate;
  2028. table-layout: fixed;
  2029. thead {
  2030. tr {
  2031. th {
  2032. height: 40px;
  2033. line-height: 40px;
  2034. border: 1px solid var(--light-grey-2);
  2035. border-width: 1px 1px 1px 0;
  2036. padding: 0;
  2037. &:last-child {
  2038. border-width: 1px 0 1px;
  2039. }
  2040. &.sortable {
  2041. cursor: pointer;
  2042. }
  2043. & > div {
  2044. display: flex;
  2045. white-space: nowrap;
  2046. padding: 8px 10px;
  2047. & > span {
  2048. margin-left: 5px;
  2049. &:first-child {
  2050. margin-left: 0;
  2051. margin-right: auto;
  2052. }
  2053. & > .material-icons {
  2054. font-size: 22px;
  2055. position: relative;
  2056. top: 6px;
  2057. cursor: pointer;
  2058. &.active {
  2059. color: var(--primary-color);
  2060. }
  2061. &:hover,
  2062. &:focus {
  2063. filter: brightness(90%);
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. }
  2070. }
  2071. tbody {
  2072. tr {
  2073. &.highlighted {
  2074. background-color: var(--light-grey);
  2075. }
  2076. &.updated {
  2077. td:first-child {
  2078. background-color: var(--primary-color) !important;
  2079. }
  2080. }
  2081. td {
  2082. border: 1px solid var(--light-grey-2);
  2083. border-width: 0 1px 1px 0;
  2084. &:last-child {
  2085. border-width: 0 0 1px;
  2086. }
  2087. /deep/ .row-options {
  2088. display: flex;
  2089. justify-content: space-evenly;
  2090. .icon-with-button {
  2091. height: 30px;
  2092. width: 30px;
  2093. }
  2094. }
  2095. }
  2096. &.removed {
  2097. filter: grayscale(100%);
  2098. cursor: not-allowed;
  2099. user-select: none;
  2100. td .removed-overlay {
  2101. position: absolute;
  2102. top: 0;
  2103. left: 0;
  2104. bottom: 0;
  2105. right: 5px;
  2106. z-index: 5;
  2107. }
  2108. }
  2109. }
  2110. }
  2111. }
  2112. table {
  2113. thead tr,
  2114. tbody tr {
  2115. th,
  2116. td {
  2117. position: relative;
  2118. white-space: nowrap;
  2119. text-overflow: ellipsis;
  2120. overflow: hidden;
  2121. &:first-child {
  2122. display: table-cell;
  2123. position: sticky;
  2124. left: 0;
  2125. background-color: var(--white);
  2126. z-index: 2;
  2127. & > .updated-tooltip {
  2128. position: absolute;
  2129. top: 0;
  2130. left: 0;
  2131. bottom: 0;
  2132. right: 0;
  2133. }
  2134. }
  2135. .resizer {
  2136. height: 100%;
  2137. width: 5px;
  2138. background-color: transparent;
  2139. cursor: col-resize;
  2140. position: absolute;
  2141. right: 0;
  2142. top: 0;
  2143. }
  2144. }
  2145. &:nth-child(even) td:first-child {
  2146. background-color: #fafafa;
  2147. }
  2148. &:hover,
  2149. &:focus,
  2150. &.highlighted {
  2151. th,
  2152. td {
  2153. &,
  2154. &:first-child {
  2155. background-color: var(--light-grey);
  2156. }
  2157. }
  2158. }
  2159. }
  2160. &.has-checkboxes {
  2161. thead,
  2162. tbody {
  2163. tr {
  2164. th,
  2165. td {
  2166. &:nth-child(2) {
  2167. display: table-cell;
  2168. position: sticky;
  2169. left: 5px;
  2170. background-color: var(--white);
  2171. z-index: 2;
  2172. }
  2173. }
  2174. &:hover,
  2175. &:focus,
  2176. &.highlighted {
  2177. th,
  2178. td {
  2179. &:nth-child(2) {
  2180. background-color: var(--light-grey);
  2181. }
  2182. }
  2183. }
  2184. &.updated td:first-child {
  2185. background-color: var(--primary-color);
  2186. }
  2187. }
  2188. }
  2189. }
  2190. }
  2191. }
  2192. .table-header,
  2193. .table-footer {
  2194. display: flex;
  2195. flex-direction: row;
  2196. flex-wrap: wrap;
  2197. justify-content: space-between;
  2198. line-height: 36px;
  2199. background-color: var(--white);
  2200. }
  2201. .table-header > div {
  2202. display: flex;
  2203. flex-direction: row;
  2204. > span > .control {
  2205. margin: 5px;
  2206. }
  2207. .filters-indicator {
  2208. line-height: 46px;
  2209. display: flex;
  2210. align-items: center;
  2211. column-gap: 4px;
  2212. }
  2213. }
  2214. .table-footer {
  2215. .page-controls,
  2216. .page-size > .control {
  2217. display: flex;
  2218. flex-direction: row;
  2219. margin-bottom: 0 !important;
  2220. button {
  2221. margin: 5px;
  2222. font-size: 20px;
  2223. }
  2224. p,
  2225. label {
  2226. margin: 5px;
  2227. font-size: 14px;
  2228. font-weight: 600;
  2229. }
  2230. &.select::after {
  2231. top: 18px;
  2232. }
  2233. }
  2234. }
  2235. .table-no-results {
  2236. display: flex;
  2237. flex-direction: row;
  2238. justify-content: center;
  2239. border-bottom: 1px solid var(--light-grey-2);
  2240. font-size: 18px;
  2241. line-height: 50px;
  2242. background-color: var(--white);
  2243. }
  2244. }
  2245. .control.is-grouped {
  2246. display: flex;
  2247. & > .control {
  2248. &.label {
  2249. height: 36px;
  2250. background-color: var(--white);
  2251. border: 1px solid var(--light-grey-2);
  2252. color: var(--dark-grey-2);
  2253. appearance: none;
  2254. border-radius: 3px;
  2255. font-size: 14px;
  2256. line-height: 34px;
  2257. padding-left: 8px;
  2258. padding-right: 8px;
  2259. }
  2260. &.select.is-expanded > select {
  2261. width: 100%;
  2262. }
  2263. & > input,
  2264. & > select,
  2265. & > .button,
  2266. &.label {
  2267. border-radius: 0;
  2268. }
  2269. &:first-child {
  2270. & > input,
  2271. & > select,
  2272. & > .button,
  2273. &.label {
  2274. border-radius: 5px 0 0 5px;
  2275. }
  2276. }
  2277. &:last-child {
  2278. & > input,
  2279. & > select,
  2280. & > .button,
  2281. &.label {
  2282. border-radius: 0 5px 5px 0;
  2283. }
  2284. }
  2285. & > .button {
  2286. font-size: 22px;
  2287. }
  2288. }
  2289. @media screen and (max-width: 600px) {
  2290. &.advanced-filter {
  2291. flex-wrap: wrap;
  2292. .control.select {
  2293. width: 50%;
  2294. select {
  2295. width: 100%;
  2296. }
  2297. }
  2298. .control {
  2299. margin-bottom: 0 !important;
  2300. &:nth-child(1) select {
  2301. border-radius: 5px 0 0 0;
  2302. }
  2303. &:nth-child(2) select {
  2304. border-radius: 0 5px 0 0;
  2305. }
  2306. &:nth-child(3) input {
  2307. border-radius: 0 0 0 5px;
  2308. }
  2309. &:nth-child(4) button {
  2310. border-radius: 0 0 5px 0;
  2311. }
  2312. }
  2313. }
  2314. }
  2315. }
  2316. .autosuggest-container {
  2317. position: absolute;
  2318. background: var(--white);
  2319. width: calc(100% + 1px);
  2320. top: 35px;
  2321. z-index: 200;
  2322. overflow: auto;
  2323. max-height: 98px;
  2324. clear: both;
  2325. .autosuggest-item {
  2326. padding: 8px;
  2327. display: block;
  2328. border: 1px solid var(--light-grey-2);
  2329. margin-top: -1px;
  2330. line-height: 16px;
  2331. cursor: pointer;
  2332. -webkit-user-select: none;
  2333. -ms-user-select: none;
  2334. -moz-user-select: none;
  2335. user-select: none;
  2336. }
  2337. .autosuggest-item:hover,
  2338. .autosuggest-item:focus {
  2339. background-color: var(--light-grey);
  2340. }
  2341. .autosuggest-item:first-child {
  2342. border-top: none;
  2343. }
  2344. .autosuggest-item:last-child {
  2345. border-radius: 0 0 3px 3px;
  2346. }
  2347. }
  2348. .advanced-filter {
  2349. .control {
  2350. position: relative;
  2351. }
  2352. }
  2353. .advanced-filter-bottom {
  2354. display: flex;
  2355. .button {
  2356. font-size: 16px !important;
  2357. width: 100%;
  2358. }
  2359. .control {
  2360. margin: 0 !important;
  2361. }
  2362. }
  2363. /deep/ .bulk-popup {
  2364. display: flex;
  2365. position: fixed;
  2366. flex-direction: row;
  2367. width: 100%;
  2368. max-width: 400px;
  2369. line-height: 36px;
  2370. z-index: 5;
  2371. border: 1px solid var(--light-grey-3);
  2372. border-radius: 5px;
  2373. box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  2374. background-color: var(--white);
  2375. color: var(--dark-grey);
  2376. padding: 5px;
  2377. .right {
  2378. display: flex;
  2379. flex-direction: row;
  2380. margin-left: auto;
  2381. }
  2382. .drag-icon {
  2383. position: relative;
  2384. top: 6px;
  2385. color: var(--dark-grey);
  2386. cursor: move;
  2387. }
  2388. .bulk-actions {
  2389. display: flex;
  2390. flex-direction: row;
  2391. width: 100%;
  2392. justify-content: space-evenly;
  2393. .material-icons {
  2394. position: relative;
  2395. top: 6px;
  2396. margin-left: 5px;
  2397. cursor: pointer;
  2398. color: var(--primary-color);
  2399. &:hover,
  2400. &:focus {
  2401. filter: brightness(90%);
  2402. }
  2403. }
  2404. .delete-icon {
  2405. color: var(--dark-red);
  2406. }
  2407. }
  2408. }
  2409. </style>