adjust bulk creation
This commit is contained in:
@@ -48,6 +48,24 @@ func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, host
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
case "addbulk":
|
||||||
|
var clients []*model.Client
|
||||||
|
err = json.Unmarshal(data, &clients)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(clients[0].Inbounds, &inboundIds)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = s.updateLinksWithFixedInbounds(tx, clients, inboundIds, hostname)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = tx.Save(clients).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
case "del":
|
case "del":
|
||||||
var id uint
|
var id uint
|
||||||
err = json.Unmarshal(data, &id)
|
err = json.Unmarshal(data, &id)
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
v-model="clientInbounds"
|
v-model="clientInbounds"
|
||||||
:items="inboundTags"
|
:items="inboundTags"
|
||||||
:label="$t('client.inboundTags')"
|
:label="$t('client.inboundTags')"
|
||||||
|
:return-object="false"
|
||||||
multiple
|
multiple
|
||||||
chips
|
chips
|
||||||
hide-details
|
hide-details
|
||||||
@@ -236,7 +237,7 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
clientInbounds: {
|
clientInbounds: {
|
||||||
get() { return this.client.inbounds.length>0 ? this.client.inbounds : [] },
|
get() { return this.client.inbounds.length>0 ? this.client.inbounds : [] },
|
||||||
set(v:any[]) { this.client.inbounds = v.length == 0 ? [] : v.map(i => i.value) }
|
set(v:number[]) { this.client.inbounds = v.length == 0 ? [] : v }
|
||||||
},
|
},
|
||||||
expDate: {
|
expDate: {
|
||||||
get() { return this.client.expiry},
|
get() { return this.client.expiry},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<v-dialog transition="dialog-bottom-transition" width="800">
|
<v-dialog transition="dialog-bottom-transition" width="800">
|
||||||
<v-card class="rounded-lg">
|
<v-card class="rounded-lg">
|
||||||
<v-card-title>
|
<v-card-title>
|
||||||
{{ $t('bulk.add') }}
|
{{ $t('actions.addbulk') }}
|
||||||
</v-card-title>
|
</v-card-title>
|
||||||
<v-divider></v-divider>
|
<v-divider></v-divider>
|
||||||
<v-card-text style="padding: 0 16px; overflow-y: scroll;">
|
<v-card-text style="padding: 0 16px; overflow-y: scroll;">
|
||||||
@@ -53,6 +53,7 @@
|
|||||||
v-model="bulkData.clientInbounds"
|
v-model="bulkData.clientInbounds"
|
||||||
:items="inboundTags"
|
:items="inboundTags"
|
||||||
:label="$t('client.inboundTags')"
|
:label="$t('client.inboundTags')"
|
||||||
|
:return-object="false"
|
||||||
multiple
|
multiple
|
||||||
chips
|
chips
|
||||||
hide-details
|
hide-details
|
||||||
@@ -60,6 +61,7 @@
|
|||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-container>
|
</v-container>
|
||||||
|
<pre dir="ltr">{{ bulkData }}</pre>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-spacer></v-spacer>
|
<v-spacer></v-spacer>
|
||||||
@@ -133,6 +135,7 @@ export default {
|
|||||||
push.error(i18n.global.t('error.dplData'))
|
push.error(i18n.global.t('error.dplData'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.clients = []
|
||||||
this.loading = true
|
this.loading = true
|
||||||
for(let i=0;i<this.count;i++){
|
for(let i=0;i<this.count;i++){
|
||||||
const name = this.genByPattern(this.bulkData.name, i)
|
const name = this.genByPattern(this.bulkData.name, i)
|
||||||
@@ -150,8 +153,7 @@ export default {
|
|||||||
group: this.bulkData.group
|
group: this.bulkData.group
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
this.$emit('save', this.clients, this.bulkData.clientInbounds)
|
this.$emit('save', this.clients)
|
||||||
this.resetData() // reset to default
|
|
||||||
this.loading = false
|
this.loading = false
|
||||||
},
|
},
|
||||||
genByPattern(pattern: any[], order :number){
|
genByPattern(pattern: any[], order :number){
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ export default {
|
|||||||
actions: {
|
actions: {
|
||||||
action: "Action",
|
action: "Action",
|
||||||
add: "Add",
|
add: "Add",
|
||||||
|
addbulk: "Add Bulk",
|
||||||
new: "New",
|
new: "New",
|
||||||
edit: "Edit",
|
edit: "Edit",
|
||||||
del: "Delete",
|
del: "Delete",
|
||||||
@@ -173,7 +174,6 @@ export default {
|
|||||||
sub: "External Subscription",
|
sub: "External Subscription",
|
||||||
},
|
},
|
||||||
bulk: {
|
bulk: {
|
||||||
add: "Add Bulk",
|
|
||||||
order: "Order",
|
order: "Order",
|
||||||
random: "Random",
|
random: "Random",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ export default {
|
|||||||
actions: {
|
actions: {
|
||||||
action: "فرمان",
|
action: "فرمان",
|
||||||
add: "ایجاد",
|
add: "ایجاد",
|
||||||
|
addbulk: "ایجاد انبوه",
|
||||||
new: "جدید",
|
new: "جدید",
|
||||||
edit: "ویرایش",
|
edit: "ویرایش",
|
||||||
del: "حذف",
|
del: "حذف",
|
||||||
@@ -172,7 +173,6 @@ export default {
|
|||||||
sub: "سابسکریپشن خارجی",
|
sub: "سابسکریپشن خارجی",
|
||||||
},
|
},
|
||||||
bulk: {
|
bulk: {
|
||||||
add: "ایجاد انبوه",
|
|
||||||
order: "ترتیب",
|
order: "ترتیب",
|
||||||
random: "تصادفی",
|
random: "تصادفی",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ export default {
|
|||||||
actions: {
|
actions: {
|
||||||
action: "Действие",
|
action: "Действие",
|
||||||
add: "Добавить",
|
add: "Добавить",
|
||||||
|
addbulk: "Добавить пакетно",
|
||||||
new: "Новый",
|
new: "Новый",
|
||||||
edit: "Редактировать",
|
edit: "Редактировать",
|
||||||
del: "Удалить",
|
del: "Удалить",
|
||||||
@@ -173,7 +174,6 @@ export default {
|
|||||||
sub: "Внешняя подписка",
|
sub: "Внешняя подписка",
|
||||||
},
|
},
|
||||||
bulk: {
|
bulk: {
|
||||||
add: "Добавить пакетно",
|
|
||||||
order: "Порядок",
|
order: "Порядок",
|
||||||
random: "Случайный",
|
random: "Случайный",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ export default {
|
|||||||
actions: {
|
actions: {
|
||||||
action: "Hành động",
|
action: "Hành động",
|
||||||
add: "Thêm",
|
add: "Thêm",
|
||||||
|
addbulk: "Thêm Hàng loạt",
|
||||||
new: "Mới",
|
new: "Mới",
|
||||||
edit: "Chỉnh sửa",
|
edit: "Chỉnh sửa",
|
||||||
del: "Xóa",
|
del: "Xóa",
|
||||||
@@ -171,7 +172,6 @@ export default {
|
|||||||
sub: "Đăng ký bên ngoài",
|
sub: "Đăng ký bên ngoài",
|
||||||
},
|
},
|
||||||
bulk: {
|
bulk: {
|
||||||
add: "Thêm Hàng loạt",
|
|
||||||
order: "Sắp xếp",
|
order: "Sắp xếp",
|
||||||
random: "Ngẫu nhiên",
|
random: "Ngẫu nhiên",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ export default {
|
|||||||
actions: {
|
actions: {
|
||||||
action: "操作",
|
action: "操作",
|
||||||
add: "添加",
|
add: "添加",
|
||||||
|
addbulk: "批量添加",
|
||||||
new: "新建",
|
new: "新建",
|
||||||
edit: "编辑",
|
edit: "编辑",
|
||||||
del: "删除",
|
del: "删除",
|
||||||
@@ -171,7 +172,6 @@ export default {
|
|||||||
sub: "外部订阅",
|
sub: "外部订阅",
|
||||||
},
|
},
|
||||||
bulk: {
|
bulk: {
|
||||||
add: "批量添加",
|
|
||||||
order: "排序",
|
order: "排序",
|
||||||
random: "随机",
|
random: "随机",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ export default {
|
|||||||
actions: {
|
actions: {
|
||||||
action: "操作",
|
action: "操作",
|
||||||
add: "添加",
|
add: "添加",
|
||||||
|
addbulk: "批量添加",
|
||||||
new: "新建",
|
new: "新建",
|
||||||
edit: "編輯",
|
edit: "編輯",
|
||||||
del: "刪除",
|
del: "刪除",
|
||||||
@@ -172,7 +173,6 @@ export default {
|
|||||||
sub: "外部訂閱",
|
sub: "外部訂閱",
|
||||||
},
|
},
|
||||||
bulk: {
|
bulk: {
|
||||||
add: "批量添加",
|
|
||||||
order: "排序",
|
order: "排序",
|
||||||
random: "隨機",
|
random: "隨機",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
<template v-slot:prepend>
|
<template v-slot:prepend>
|
||||||
<v-icon icon="mdi-account-multiple-plus"></v-icon>
|
<v-icon icon="mdi-account-multiple-plus"></v-icon>
|
||||||
</template>
|
</template>
|
||||||
<v-list-item-title v-text="$t('bulk.add')"></v-list-item-title>
|
<v-list-item-title v-text="$t('actions.addbulk')"></v-list-item-title>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</v-list>
|
</v-list>
|
||||||
</v-menu>
|
</v-menu>
|
||||||
@@ -535,8 +535,20 @@ const closeBulk = () => {
|
|||||||
addBulkModal.value = false
|
addBulkModal.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveBulk = async (bulkClients: Client[], clientInbounds: number[]) => {
|
const saveBulk = async (bulkClients: Client[]) => {
|
||||||
clients.value.push(...bulkClients)
|
// Check duplicate name
|
||||||
closeBulk()
|
const oldNames = new Set(clients.value.map(c => c.name))
|
||||||
|
const newNames = new Set(bulkClients.map(c => c.name))
|
||||||
|
const allNames = new Set([...clients.value.map(c => c.name), ...bulkClients.map(c => c.name)])
|
||||||
|
if (newNames.size != bulkClients.length || oldNames.size + newNames.size != allNames.size) {
|
||||||
|
push.error({
|
||||||
|
message: i18n.global.t('error.dplData') + ": " + i18n.global.t('client.name')
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// save data
|
||||||
|
const success = await Data().save("clients", "addbulk", bulkClients)
|
||||||
|
if (success) closeBulk()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
Reference in New Issue
Block a user