Skip to content
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

Feat/doc sign #17

Merged
merged 7 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 87 additions & 42 deletions src/browse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,56 @@
{{ resource.name }}
</h4>

<resource-actions
v-if="showResourceActions"
:bulk-actions="bulkActionsList"
:create-resource-url="createResourceUrl"
:current-resource="resource"
:custom-filter-fields="customFilterFields"
:filterable-fields="filterableFields"
:search-options="searchOptions"
:show-bulk-actions="showBulkActions"
:show-create-resource="showCreateResource"
:show-search-filters="showSearchFilters"
@getData="getData"
@run-action="runAction"
@show-custom-filters-form="$modal.show('custom-filters-form')"
/>
<slot :data="{searchOptions}" name="resource-actions" v-bind="{ searchOptions, getData, filterableFields }">
jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved
<resource-actions
v-if="showResourceActions"
:bulk-actions="bulkActionsList"
:create-resource-url="createResourceUrl"
:current-resource="resource"
:custom-filter-fields="customFilterFields"
:filterable-fields="filterableFields"
:search-options="searchOptions"
:show-bulk-actions="showBulkActions"
:show-create-resource="showCreateResource"
:show-search-filters="showSearchFilters"
@getData="getData"
@run-action="runAction"
@show-custom-filters-form="$modal.show('custom-filters-form')"
/>
</slot>

<div v-show="!loading">
<div class="table-container m-b-0">
<div v-if="showPagination && showPaginationTop" class="pagination-controls pc-top row">
<template v-if="showResultsPerPage">
<div class="col-auto">
<label class="mb-0">Results per page:</label>
</div>
<div class="col-auto">
<multiselect
v-model="selectedPerPage"
:allow-empty="false"
:show-labels="false"
:options="resultsPerPageOptions"
:searchable="false"
placeholder=""
@input="changePerPage"
/>
</div>
<div v-show="totalPages > 1" class="col-auto separator">
|
</div>
</template>
<vuetable-pagination
ref="paginationTop"
:css="pagination"
class="col-auto"
@vuetable-pagination:change-page="onChangePage"
/>
<slot name="before-table-left" />
jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved

<div class="d-flex">
<template v-if="showResultsPerPage">
<div class="col-auto">
<label class="mb-0">Results per page:</label>
</div>
<div class="col-auto">
<multiselect
v-model="selectedPerPage"
:allow-empty="false"
:show-labels="false"
:options="resultsPerPageOptions"
:searchable="false"
placeholder=""
@input="changePerPage"
/>
</div>
<div v-show="totalPages > 1" class="col-auto separator">
|
</div>
</template>
<vuetable-pagination
ref="paginationTop"
:css="pagination"
class="col-auto"
@vuetable-pagination:change-page="onChangePage"
/>
</div>
</div>
<div class="table-responsive">
<vuetable
Expand Down Expand Up @@ -370,13 +377,19 @@ export default {
},
searchableFields() {
return this.tableFields.filter(field => field.searchable).map(field => field.name);
},
mainDateField() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what happens where there is more than one date field in the filterable fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should't be more than one by the moment that's why is called mainDateField; but later, maybe we can allow the User decide which date field to use or address the problem in custom filters.

what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later is okay.

const mainDateField = this.tableFields.filter(field => field.dateFilter).map(field => field.name);
return mainDateField.length ? mainDateField[0] : "";
}
},
watch: {
appendParams() {
this.vuetableQueryParams = _clone(this.appendParams);
},
resource() {
this.$refs.Vuetable.resetData()
this.vuetableQueryParams.q = null
jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved
this.getSchema(this.resource);
}
},
Expand Down Expand Up @@ -440,16 +453,22 @@ export default {
},
getData(searchOptions) {
let params = "";
const fixedFilters = Object.keys(searchOptions.fixedFilters || {})
const dateFilters = Object.keys(searchOptions.dates || {})
jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved
let searchableFields = [];
searchOptions.text = searchOptions.text.trim();

if (searchOptions.text.length) {
if (!searchOptions.filters.length) {
params += this.getParams(this.searchableFields, searchOptions);
searchableFields = this.searchableFields.filter(field => !fixedFilters.includes(field) && !dateFilters.includes(field))
jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved
} else {
params += this.getParams(searchOptions.filters, searchOptions);
searchableFields = searchOptions.filters.filter(field => !fixedFilters.includes(field) && !dateFilters.includes(field))
jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved
}
params += this.getParams(searchableFields, searchOptions);
}

params = this.getFixedFilters(searchOptions, params)
jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved

this.vuetableQueryParams.q = `(${params})`;
this.refresh();
},
Expand All @@ -469,6 +488,32 @@ export default {
(this.showActionsDelete || this.showActionsEdit) && this.tableFields.push(this.vuetableActions);
});
},

getFixedFilters(searchOptions, params) {
let fixedFilters = Object.entries(searchOptions.fixedFilters || {});
const dateFilters = Object.entries(searchOptions.dates || {});
let dateValues = ""
jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved

if (fixedFilters.length || dateFilters.length) {
fixedFilters = fixedFilters.map(([filterName, value]) => `${filterName}:${value}`).join(";");

jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved
if (dateFilters.length && this.mainDateField) {
let dateFilterValue = this.formatDate(searchOptions.dates.start);
if (searchOptions.dates.end) {
dateFilterValue += `,${this.mainDateField}<${this.formatDate(searchOptions.dates.end)}`;
}
dateValues = `${this.mainDateField}>${dateFilterValue}`;
}
params = [params, dateValues, fixedFilters].filter(val => val).join(",");
}

return params;
},

jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved
formatDate(date) {
return date ? date.toISOString().slice(0, 10) : ""
jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved
},

jesusantguerrero marked this conversation as resolved.
Show resolved Hide resolved
getSelectedRows() {
return this.$refs.Vuetable.selectedTo;
},
Expand Down
1 change: 1 addition & 0 deletions src/components/resource-actions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
</a>
</div>
</dropdown>

<div class="col-auto">
<router-link
v-if="showCreateResource"
Expand Down