-
Notifications
You must be signed in to change notification settings - Fork 68
Add admin panel enhancements according to #3283 #618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xkello
wants to merge
3
commits into
develop
Choose a base branch
from
implement-3283
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ | |
| <PInputText | ||
| placeholder="Search accounts" | ||
| data-cy="search-members-field" | ||
| v-model="searchByName" | ||
| v-model="search" | ||
| class="w-full" | ||
| @input="onSearch" | ||
| /> | ||
|
|
@@ -44,49 +44,45 @@ | |
| :first="(options.page - 1) * options.itemsPerPage" | ||
| :sort-field="options.sortBy[0]" | ||
| :sort-order="options.sortDesc[0] ? -1 : 1" | ||
| :rowHover="true" | ||
| removableSort | ||
| reorderable-columns | ||
| @page="onPage" | ||
| @row-click="rowClick" | ||
| @sort="onSort" | ||
| data-cy="accounts-table" | ||
| > | ||
| <template v-for="header in headers" :key="header.field"> | ||
| <PColumn | ||
| v-if="header.field === 'username'" | ||
| :field="header.field" | ||
| :header="header.header" | ||
| :sortable="header.sortable" | ||
| > | ||
| <template #body="slotProps"> | ||
| <router-link | ||
| class="title-t4" | ||
| :to="{ | ||
| name: 'account', | ||
| params: { username: slotProps.data.username } | ||
| }" | ||
| > | ||
| {{ slotProps.data.username }} | ||
| </router-link> | ||
| </template> | ||
| </PColumn> | ||
| <PColumn | ||
| v-else-if="header.field === 'active'" | ||
| :header="header.header" | ||
| :field="header.field" | ||
| > | ||
| <template #body="slotProps"> | ||
| <i v-if="slotProps.data.active" class="ti ti-check" /> | ||
| <PColumn field="username" header="Username" :sortable="true"> | ||
| <template #body="{ data }"> | ||
| <router-link | ||
| :to="accountRoute(data)" | ||
| class="dt-row-link title-t4" | ||
| > | ||
| {{ data.username }} | ||
| </router-link> | ||
| </template> | ||
| </PColumn> | ||
| <PColumn field="email" header="Email" :sortable="true"> | ||
| <template #body="{ data }"> | ||
| <router-link :to="accountRoute(data)" class="dt-row-link"> | ||
| {{ data.email }} | ||
| </router-link> | ||
| </template> | ||
| </PColumn> | ||
| <PColumn field="profile.name" header="Full name"> | ||
| <template #body="{ data }"> | ||
| <router-link :to="accountRoute(data)" class="dt-row-link"> | ||
| {{ data.profile?.name }} | ||
| </router-link> | ||
| </template> | ||
| </PColumn> | ||
| <PColumn field="active" header="Active"> | ||
| <template #body="{ data }"> | ||
| <router-link :to="accountRoute(data)" class="dt-row-link"> | ||
| <i v-if="data.active" class="ti ti-check" /> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just note from some users. We could add here just text Active / Inactive as icon is not copy able. |
||
| <i v-else class="ti ti-x" /> | ||
| </template> | ||
| </PColumn> | ||
| <PColumn | ||
| v-else | ||
| :field="header.field" | ||
| :header="header.header" | ||
| :sortable="header.sortable" | ||
| ></PColumn> | ||
| </template> | ||
| </router-link> | ||
| </template> | ||
| </PColumn> | ||
| <template #paginatorstart> | ||
| <PButton | ||
| icon="ti ti-refresh" | ||
|
|
@@ -106,18 +102,12 @@ | |
| <script lang="ts"> | ||
| import { | ||
| PaginatedUsersParams, | ||
| useDataTableSearch, | ||
| useDialogStore, | ||
| TableDataHeader, | ||
| AppContainer, | ||
| AppSection | ||
| } from '@mergin/lib' | ||
| import debounce from 'lodash/debounce' | ||
| import { mapActions, mapState } from 'pinia' | ||
| import { | ||
| DataTablePageEvent, | ||
| DataTableRowClickEvent, | ||
| DataTableSortEvent | ||
| } from 'primevue/datatable' | ||
| import { mapState } from 'pinia' | ||
| import { defineComponent } from 'vue' | ||
|
|
||
| import { AdminRoutes } from '@/modules' | ||
|
|
@@ -130,88 +120,52 @@ export default defineComponent({ | |
| AppContainer, | ||
| AppSection | ||
| }, | ||
| data() { | ||
| setup() { | ||
| const adminStore = useAdminStore() | ||
| const dialogStore = useDialogStore() | ||
|
|
||
| const tableSearch = useDataTableSearch({ | ||
| defaultSortBy: 'username', | ||
| defaultSortDesc: false | ||
| }) | ||
|
|
||
| tableSearch.setFetchFn((signal) => { | ||
| const { options, search } = tableSearch | ||
| const params: PaginatedUsersParams = { | ||
| page: options.page, | ||
| per_page: options.itemsPerPage | ||
| } | ||
| if (options.sortBy[0]) { | ||
| params.descending = options.sortDesc[0] | ||
| params.order_by = options.sortBy[0] | ||
| } | ||
| if (search.value) params.like = search.value.trim() | ||
| adminStore.fetchUsers({ params, signal }) | ||
| }) | ||
|
|
||
| return { | ||
| options: { | ||
| sortBy: ['username'], | ||
| sortDesc: [false], | ||
| itemsPerPage: 20, | ||
| page: 1, | ||
| perPageOptions: [20, 50, 100] | ||
| }, | ||
| searchByName: '', | ||
| headers: [ | ||
| { field: 'username', header: 'Username', sortable: true }, | ||
| { field: 'email', header: 'Email', sortable: true }, | ||
| { field: 'profile.name', header: 'Full name' }, | ||
| { field: 'active', header: 'Active' } | ||
| ] as TableDataHeader[] | ||
| ...tableSearch, | ||
| show: dialogStore.show.bind(dialogStore) | ||
| } | ||
| }, | ||
| computed: { | ||
| ...mapState(useAdminStore, ['users', 'loading']) | ||
| }, | ||
| created() { | ||
| this.resetPaging = debounce(this.resetPaging, 1000) | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| this.initFromQuery() | ||
| this.doFetch() | ||
| }, | ||
| methods: { | ||
| ...mapActions(useAdminStore, ['fetchUsers']), | ||
| ...mapActions(useDialogStore, ['show']), | ||
|
|
||
| onSearch() { | ||
| this.resetPaging() | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| }, | ||
|
|
||
| async resetPaging() { | ||
| this.options.page = 1 | ||
| }, | ||
|
|
||
| getParams(): PaginatedUsersParams { | ||
| const params = { | ||
| page: this.options.page, | ||
| per_page: this.options.itemsPerPage | ||
| } as PaginatedUsersParams | ||
| if (this.options.sortBy[0]) { | ||
| params.descending = this.options.sortDesc[0] | ||
| params.order_by = this.options.sortBy[0] | ||
| } | ||
| if (this.searchByName) { | ||
| params.like = this.searchByName.trim() | ||
| } | ||
| return params | ||
| }, | ||
|
|
||
| onRefresh() { | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| }, | ||
|
|
||
| onPage(event: DataTablePageEvent) { | ||
| this.options.page = event.page + 1 | ||
| this.options.itemsPerPage = event.rows | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| }, | ||
|
|
||
| onSort(event: DataTableSortEvent) { | ||
| this.options.sortBy[0] = event.sortField?.toString() | ||
| this.options.sortDesc[0] = event.sortOrder < 1 | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| }, | ||
|
|
||
| rowClick(event: DataTableRowClickEvent) { | ||
| this.$router.push({ | ||
| name: AdminRoutes.ACCOUNT, | ||
| params: { username: event.data.username } | ||
| }) | ||
| accountRoute(data) { | ||
| return { name: AdminRoutes.ACCOUNT, params: { username: data.username } } | ||
| }, | ||
|
|
||
| createUserDialog() { | ||
| const dialog = { maxWidth: 500, header: 'Create user' } | ||
| const listeners = { | ||
| success: () => { | ||
| this.resetPaging() | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| this.options.page = 1 | ||
| this.doFetch() | ||
| } | ||
| } | ||
| this.show({ | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means also for other tables. We could probably live with this config json as we can then extend it and have one default column when slot is not used.