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

Data protected entity default filter #1032

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 21 additions & 11 deletions apps/vue/src/components/Table/src/BasicTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
<slot :name="item" v-bind="data || {}"></slot>
</template>
<template #advanceBefore>
<Button
v-if="getAdvancedSearchProps?.useAdvancedSearch"
type="link"
size="small"
@click="handleAdvanceSearch"
>
{{ t('component.table.advancedSearch.title') }}
</Button>
<Badge v-if="getAdvancedSearchProps?.useAdvancedSearch" :count="advancedSearchInput?.paramters.length">
<Button
type="link"
size="small"
@click="handleAdvanceSearch"
>
{{ t('component.table.advancedSearch.title') }}
</Button>
</Badge>
</template>
</BasicForm>

Expand Down Expand Up @@ -55,7 +56,7 @@
ref="advancedSearchRef"
@register="registerAdSearchModal"
v-bind="getAdvancedSearchProps"
@change="handleAdvanceSearchChange"
@change="handleAdvanceSearchChanged"
@search="handleAdvanceSearchInfoChange"
/>
</div>
Expand All @@ -70,13 +71,14 @@
} from './types/table';

import { defineComponent, ref, reactive, computed, unref, toRaw, inject, watchEffect, nextTick } from 'vue';
import { Button, Table } from 'ant-design-vue';
import { Badge, Button, Table } from 'ant-design-vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { useModal } from '/@/components/Modal/index';
import { PageWrapperFixedHeightKey } from '/@/components/Page';
import HeaderCell from './components/HeaderCell.vue';
import AdvancedSearch from './components/AdvancedSearch.vue';
import { InnerHandlers } from './types/table';
import { DynamicQueryable } from './types/advancedSearch';

import { usePagination } from './hooks/usePagination';
import { useColumns } from './hooks/useColumns';
Expand Down Expand Up @@ -105,6 +107,7 @@
name: 'BasicTable',
components: {
Table,
Badge,
BasicForm,
Button,
HeaderCell,
Expand Down Expand Up @@ -137,6 +140,7 @@
const wrapRef = ref(null);
const formRef = ref(null);
const advancedSearchRef = ref<any>(null);
const advancedSearchInput = ref<DynamicQueryable>();
const innerPropsRef = ref<Partial<BasicTableProps>>();

const { prefixCls } = useDesign('basic-table');
Expand Down Expand Up @@ -276,6 +280,11 @@
getDataSourceRef,
);

function handleAdvanceSearchChanged(queryable: DynamicQueryable) {
advancedSearchInput.value = queryable;
handleAdvanceSearchChange(queryable);
}

const {
getFormProps,
getAdvancedSearchProps,
Expand Down Expand Up @@ -401,12 +410,13 @@
formRef,
tableElRef,
advancedSearchRef,
advancedSearchInput,
getBindValues,
getLoading,
registerForm,
handleSearchInfoChange,
registerAdSearchModal,
handleAdvanceSearchChange,
handleAdvanceSearchChanged,
handleAdvanceSearchInfoChange,
handleSearchInfoReset,
handleAdvanceSearch,
Expand Down
17 changes: 5 additions & 12 deletions apps/vue/src/components/Table/src/components/AdvancedSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,14 @@
newParamter.value = false;
}
formMdel.paramters.push(newParamter);
emits('change', formMdel);
}
}

function handleDelField(paramter) {
const index = formMdel.paramters.findIndex(p => p.field === paramter.field);
formMdel.paramters.splice(index, 1);
emits('change', getSearchInput());
emits('change', formMdel);
}

function handleFieldChange(field, record) {
Expand All @@ -344,26 +345,18 @@
if (defineParam.javaScriptType === 'boolean') {
record.value = false;
}
emits('change', getSearchInput());
emits('change', formMdel);
}
}

function handleSubmit() {
emits('search', getSearchInput());
emits('search', formMdel);
closeModal();
}

function resetFields() {
formMdel.paramters = [];
emits('change', getSearchInput());
}

function getSearchInput() {
const searchInput = {
// 过滤未定义值
paramters: formMdel.paramters.filter(p => p.value !== undefined)
};
return searchInput;
emits('change', formMdel);
}

function setLoading(loading: boolean) {
Expand Down
17 changes: 11 additions & 6 deletions apps/vue/src/components/Table/src/hooks/useDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,17 @@ export function useDataSource(
} = unref(propsRef);
let fetchApi = api;
// 高级查询条件支持
const searchInput = cloneDeep(getFieldsValue());
if (advancedSearchConfig?.useAdvancedSearch) {
const searchInput = getFieldsValue();
if (Reflect.has(searchInput, 'queryable') &&
Array.isArray(searchInput.queryable?.paramters) &&
searchInput.queryable.paramters.length > 0)
fetchApi = advancedSearchConfig?.fetchApi;
if (Reflect.has(searchInput, 'queryable')
&& searchInput?.queryable?.paramters
&& Array.isArray(searchInput.queryable?.paramters)) {
searchInput.queryable.paramters = searchInput.queryable.paramters
.filter((p) => p.value !== undefined);
if (searchInput.queryable.paramters.length > 0) {
fetchApi = advancedSearchConfig?.fetchApi;
}
}
}
if (!fetchApi || !isFunction(fetchApi)) return;
try {
Expand Down Expand Up @@ -275,7 +280,7 @@ export function useDataSource(

let params: Recordable = merge(
pageParams,
useSearchForm ? getFieldsValue() : {},
useSearchForm ? searchInput : {},
searchInfo,
opt?.searchInfo ?? {},
defSort,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using LINGYUN.Abp.Webhooks;
using LINGYUN.Abp.Webhooks.EventBus;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.MultiTenancy;

namespace LY.MicroService.Applications.Single.EventBus.Distributed;

public class WebhooksEventHandler :
IDistributedEventHandler<WebhooksEventData>,
ITransientDependency
{
public IWebhookEventStore WebhookEventStore { get; set; }

private readonly ICurrentTenant _currentTenant;
private readonly IBackgroundJobManager _backgroundJobManager;
private readonly IWebhookSubscriptionManager _webhookSubscriptionManager;

public WebhooksEventHandler(
IWebhookSubscriptionManager webhookSubscriptionManager,
ICurrentTenant currentTenant,
IBackgroundJobManager backgroundJobManager)
{
_currentTenant = currentTenant;
_backgroundJobManager = backgroundJobManager;
_webhookSubscriptionManager = webhookSubscriptionManager;

WebhookEventStore = NullWebhookEventStore.Instance;
}

public async virtual Task HandleEventAsync(WebhooksEventData eventData)
{
var subscriptions = await _webhookSubscriptionManager
.GetAllSubscriptionsOfTenantsIfFeaturesGrantedAsync(
eventData.TenantIds,
eventData.WebhookName);

await PublishAsync(eventData.WebhookName, eventData.Data, subscriptions, eventData.SendExactSameData, eventData.Headers);
}

protected async virtual Task PublishAsync(
string webhookName,
string data,
List<WebhookSubscriptionInfo> webhookSubscriptions,
bool sendExactSameData = false,
WebhookHeader headers = null)
{
if (webhookSubscriptions.IsNullOrEmpty())
{
return;
}

var subscriptionsGroupedByTenant = webhookSubscriptions.GroupBy(x => x.TenantId);

foreach (var subscriptionGroupedByTenant in subscriptionsGroupedByTenant)
{
var webhookInfo = await SaveAndGetWebhookAsync(subscriptionGroupedByTenant.Key, webhookName, data);

foreach (var webhookSubscription in subscriptionGroupedByTenant)
{
var headersToSend = webhookSubscription.Headers;
if (headers != null)
{
if (headers.UseOnlyGivenHeaders)//do not use the headers defined in subscription
{
headersToSend = headers.Headers;
}
else
{
//use the headers defined in subscription. If additional headers has same header, use additional headers value.
foreach (var additionalHeader in headers.Headers)
{
headersToSend[additionalHeader.Key] = additionalHeader.Value;
}
}
}

await _backgroundJobManager.EnqueueAsync(new WebhookSenderArgs
{
TenantId = webhookSubscription.TenantId,
WebhookEventId = webhookInfo.Id,
Data = webhookInfo.Data,
WebhookName = webhookInfo.WebhookName,
WebhookSubscriptionId = webhookSubscription.Id,
Headers = headersToSend,
Secret = webhookSubscription.Secret,
WebhookUri = webhookSubscription.WebhookUri,
SendExactSameData = sendExactSameData
});
}
}
}

protected async virtual Task<WebhookEvent> SaveAndGetWebhookAsync(
Guid? tenantId,
string webhookName,
string data)
{
var webhookInfo = new WebhookEvent
{
WebhookName = webhookName,
Data = data,
TenantId = tenantId
};

var webhookId = await WebhookEventStore.InsertAndGetIdAsync(webhookInfo);
webhookInfo.Id = webhookId;

return webhookInfo;
}
}
Loading