AdvancedTable.vue 59 KB

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