AdvancedTable.vue 59 KB

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