AdvancedTable.vue 58 KB

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