feat(inbounds): add multi-select and bulk delete
Mirror the clients page: checkbox selection on the desktop table and on
mobile cards, with a danger Delete button in the toolbar that removes all
selected inbounds in one call.
Backend adds POST /panel/api/inbounds/bulkDel, which loops the existing
DelInbound per id (xray restarts at most once) and returns {deleted,
skipped}. Frontend shows a confirm modal plus a result toast, clears the
selection on success, adds bulk-delete i18n keys across all 13 languages,
and documents the endpoint in the in-panel API docs.
This commit is contained in:
21 files changed
+315
-4
No files matched your search
@@ -69,6 +69,7 @@ func (a *InboundController) initRouter(g *gin.RouterGroup) {
|
||||
|
||||
g.POST("/add", a.addInbound)
|
||||
g.POST("/del/:id", a.delInbound)
|
||||
g.POST("/bulkDel", a.bulkDelInbounds)
|
||||
g.POST("/update/:id", a.updateInbound)
|
||||
g.POST("/setEnable/:id", a.setInboundEnable)
|
||||
g.POST("/:id/resetTraffic", a.resetInboundTraffic)
|
||||
@@ -179,6 +180,32 @@ func (a *InboundController) delInbound(c *gin.Context) {
|
||||
notifyClientsChanged()
|
||||
}
|
||||
|
||||
type bulkDelInboundsRequest struct {
|
||||
Ids []int `json:"ids"`
|
||||
}
|
||||
|
||||
// bulkDelInbounds deletes several inbounds in one call. Failures are
|
||||
// reported per id and the rest still proceed; xray restarts at most once.
|
||||
func (a *InboundController) bulkDelInbounds(c *gin.Context) {
|
||||
var req bulkDelInboundsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||
return
|
||||
}
|
||||
result, needRestart, err := a.inboundService.DelInbounds(req.Ids)
|
||||
if err != nil {
|
||||
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||
return
|
||||
}
|
||||
jsonObj(c, result, nil)
|
||||
if needRestart {
|
||||
a.xrayService.SetToNeedRestart()
|
||||
}
|
||||
user := session.GetLoginUser(c)
|
||||
a.broadcastInboundsUpdate(user.Id)
|
||||
notifyClientsChanged()
|
||||
}
|
||||
|
||||
// updateInbound updates an existing inbound configuration.
|
||||
func (a *InboundController) updateInbound(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
|
||||
@@ -617,6 +617,37 @@ func (s *InboundService) DelInbound(id int) (bool, error) {
|
||||
return needRestart, db.Delete(model.Inbound{}, id).Error
|
||||
}
|
||||
|
||||
type BulkDelInboundResult struct {
|
||||
Deleted int `json:"deleted"`
|
||||
Skipped []BulkDelInboundReport `json:"skipped,omitempty"`
|
||||
}
|
||||
|
||||
type BulkDelInboundReport struct {
|
||||
Id int `json:"id"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
// DelInbounds removes every inbound in the list, reusing the single-delete
|
||||
// path per id. Failures are recorded in Skipped and processing continues for
|
||||
// the rest; the aggregated needRestart is returned so the caller restarts
|
||||
// xray at most once.
|
||||
func (s *InboundService) DelInbounds(ids []int) (BulkDelInboundResult, bool, error) {
|
||||
result := BulkDelInboundResult{}
|
||||
needRestart := false
|
||||
for _, id := range ids {
|
||||
r, err := s.DelInbound(id)
|
||||
if err != nil {
|
||||
result.Skipped = append(result.Skipped, BulkDelInboundReport{Id: id, Reason: err.Error()})
|
||||
continue
|
||||
}
|
||||
result.Deleted++
|
||||
if r {
|
||||
needRestart = true
|
||||
}
|
||||
}
|
||||
return result, needRestart, nil
|
||||
}
|
||||
|
||||
func (s *InboundService) GetInbound(id int) (*model.Inbound, error) {
|
||||
db := database.GetDB()
|
||||
inbound := &model.Inbound{}
|
||||
|
||||
@@ -296,6 +296,10 @@
|
||||
"deleteConfirmContent": "سيؤدي هذا إلى إزالة الإدخال وجميع عملائه. لا يمكن التراجع.",
|
||||
"resetConfirmTitle": "إعادة تعيين ترافيك \"{remark}\"؟",
|
||||
"resetConfirmContent": "يعيد عدادات الإرسال/الاستقبال لهذا الإدخال إلى 0.",
|
||||
"selectedCount": "{count} محدد",
|
||||
"selectAll": "تحديد الكل",
|
||||
"bulkDeleteConfirmTitle": "حذف {count} إدخال؟",
|
||||
"bulkDeleteConfirmContent": "سيؤدي هذا إلى إزالة الإدخالات المحددة وجميع عملائها. لا يمكن التراجع.",
|
||||
"cloneConfirmTitle": "نسخ الإدخال \"{remark}\"؟",
|
||||
"cloneConfirmContent": "ينشئ نسخة بمنفذ جديد وقائمة عملاء فارغة.",
|
||||
"delAllClients": "حذف جميع العملاء",
|
||||
@@ -421,6 +425,8 @@
|
||||
"inboundsUpdateSuccess": "تم تحديث الواردات بنجاح",
|
||||
"inboundUpdateSuccess": "تم تحديث الوارد بنجاح",
|
||||
"inboundCreateSuccess": "تم إنشاء الوارد بنجاح",
|
||||
"bulkDeleted": "تم حذف {count} إدخال",
|
||||
"bulkDeletedMixed": "تم حذف {ok}, وفشل {failed}",
|
||||
"inboundDeleteSuccess": "تم حذف الوارد بنجاح",
|
||||
"inboundClientAddSuccess": "تمت إضافة عميل(عملاء) وارد",
|
||||
"inboundClientDeleteSuccess": "تم حذف عميل وارد",
|
||||
|
||||
Loaded 3 of 21 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user