AdvancedTable.vue 58 KB

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