AdvancedTable.vue 59 KB

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