AdvancedTable.vue 58 KB

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