AdvancedTable.vue 59 KB

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