AdvancedTable.vue 60 KB

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