AdvancedTable.vue 58 KB

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