AdvancedTable.vue 59 KB

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