From 7f9577a3862b4d93eb4bd85badd6928e0c07d66a Mon Sep 17 00:00:00 2001 From: JustSong Date: Wed, 14 Jun 2023 12:14:08 +0800 Subject: [PATCH] feat: now one channel can belong to multiple groups (close #153) --- model/ability.go | 15 +++++++++------ web/src/pages/Channel/EditChannel.js | 14 ++++++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/model/ability.go b/model/ability.go index 26ff65d2..1b33916c 100644 --- a/model/ability.go +++ b/model/ability.go @@ -30,15 +30,18 @@ func GetRandomSatisfiedChannel(group string, model string) (*Channel, error) { func (channel *Channel) AddAbilities() error { models_ := strings.Split(channel.Models, ",") + groups_ := strings.Split(channel.Group, ",") abilities := make([]Ability, 0, len(models_)) for _, model := range models_ { - ability := Ability{ - Group: channel.Group, - Model: model, - ChannelId: channel.Id, - Enabled: channel.Status == common.ChannelStatusEnabled, + for _, group := range groups_ { + ability := Ability{ + Group: group, + Model: model, + ChannelId: channel.Id, + Enabled: channel.Status == common.ChannelStatusEnabled, + } + abilities = append(abilities, ability) } - abilities = append(abilities, ability) } return DB.Create(&abilities).Error } diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index 9bce5d9a..e25ab2de 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -15,8 +15,8 @@ const EditChannel = () => { key: '', base_url: '', other: '', - group: 'default', models: [], + groups: ['default'] }; const [batch, setBatch] = useState(false); const [inputs, setInputs] = useState(originInputs); @@ -37,6 +37,11 @@ const EditChannel = () => { } else { data.models = data.models.split(",") } + if (data.group === "") { + data.groups = [] + } else { + data.groups = data.group.split(",") + } setInputs(data); } else { showError(message); @@ -94,6 +99,7 @@ const EditChannel = () => { } let res; localInputs.models = localInputs.models.join(",") + localInputs.group = localInputs.groups.join(",") if (isEdit) { res = await API.put(`/api/channel/`, { ...localInputs, id: parseInt(channelId) }); } else { @@ -185,14 +191,14 @@ const EditChannel = () => {