feat: edit categories
This commit is contained in:
parent
7128e08408
commit
872aa7794c
|
@ -255,6 +255,17 @@ QtObject:
|
||||||
error "Error creating the category", msg = e.msg
|
error "Error creating the category", msg = e.msg
|
||||||
result = fmt"Error creating the category: {e.msg}"
|
result = fmt"Error creating the category: {e.msg}"
|
||||||
|
|
||||||
|
|
||||||
|
proc editCommunityCategory*(self: CommunitiesView, communityId: string, categoryId: string, name: string, channels: string): string {.slot.} =
|
||||||
|
result = ""
|
||||||
|
try:
|
||||||
|
let channelSeq = map(parseJson(channels).getElems(), proc(x:JsonNode):string = x.getStr().replace(communityId, ""))
|
||||||
|
self.status.chat.editCommunityCategory(communityId, categoryId, name, channelSeq)
|
||||||
|
except Exception as e:
|
||||||
|
error "Error editing the category", msg = e.msg
|
||||||
|
result = fmt"Error editing the category: {e.msg}"
|
||||||
|
|
||||||
|
|
||||||
proc deleteCommunityCategory*(self: CommunitiesView, communityId: string, categoryId: string): string {.slot.} =
|
proc deleteCommunityCategory*(self: CommunitiesView, communityId: string, categoryId: string): string {.slot.} =
|
||||||
result = ""
|
result = ""
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import NimQml, std/wrapnils
|
import NimQml, std/wrapnils, json
|
||||||
import ../../../status/[chat/chat, status]
|
import ../../../status/[chat/chat, status]
|
||||||
import channels_list
|
import channels_list
|
||||||
import ../../../eventemitter
|
import ../../../eventemitter
|
||||||
|
@ -182,6 +182,13 @@ QtObject:
|
||||||
QtProperty[QVariant] members:
|
QtProperty[QVariant] members:
|
||||||
read = getMembers
|
read = getMembers
|
||||||
|
|
||||||
|
proc getChatIdsByCategory*(self: CommunityItemView, categoryId: string): string {.slot.} =
|
||||||
|
var res:seq[string] = @[]
|
||||||
|
for chat in self.communityItem.chats:
|
||||||
|
if chat.categoryId == categoryId:
|
||||||
|
res.add(chat.id)
|
||||||
|
return $(%*res)
|
||||||
|
|
||||||
proc getCommunityMembershipRequest*(self: CommunityItemView): QVariant {.slot.} =
|
proc getCommunityMembershipRequest*(self: CommunityItemView): QVariant {.slot.} =
|
||||||
result = newQVariant(self.communityMembershipRequestList)
|
result = newQVariant(self.communityMembershipRequestList)
|
||||||
|
|
||||||
|
|
|
@ -450,6 +450,9 @@ proc createCommunityChannel*(self: ChatModel, communityId: string, name: string,
|
||||||
proc createCommunityCategory*(self: ChatModel, communityId: string, name: string, channels: seq[string]): CommunityCategory =
|
proc createCommunityCategory*(self: ChatModel, communityId: string, name: string, channels: seq[string]): CommunityCategory =
|
||||||
result = status_chat.createCommunityCategory(communityId, name, channels)
|
result = status_chat.createCommunityCategory(communityId, name, channels)
|
||||||
|
|
||||||
|
proc editCommunityCategory*(self: ChatModel, communityId: string, categoryId: string, name: string, channels: seq[string]) =
|
||||||
|
status_chat.editCommunityCategory(communityId, categoryId, name, channels)
|
||||||
|
|
||||||
proc deleteCommunityCategory*(self: ChatModel, communityId: string, categoryId: string) =
|
proc deleteCommunityCategory*(self: ChatModel, communityId: string, categoryId: string) =
|
||||||
status_chat.deleteCommunityCategory(communityId, categoryId)
|
status_chat.deleteCommunityCategory(communityId, categoryId)
|
||||||
|
|
||||||
|
|
|
@ -348,6 +348,18 @@ proc createCommunityCategory*(communityId: string, name: string, channels: seq[s
|
||||||
result.name = v["name"].getStr()
|
result.name = v["name"].getStr()
|
||||||
result.position = v{"position"}.getInt()
|
result.position = v{"position"}.getInt()
|
||||||
|
|
||||||
|
|
||||||
|
proc editCommunityCategory*(communityId: string, categoryId: string, name: string, channels: seq[string]) =
|
||||||
|
let rpcResult = callPrivateRPC("editCommunityCategory".prefix, %*[
|
||||||
|
{
|
||||||
|
"communityId": communityId,
|
||||||
|
"categoryId": categoryId,
|
||||||
|
"categoryName": name,
|
||||||
|
"chatIds": channels
|
||||||
|
}]).parseJSON()
|
||||||
|
if rpcResult.contains("error"):
|
||||||
|
raise newException(StatusGoException, rpcResult["error"]["message"].getStr())
|
||||||
|
|
||||||
proc reorderCommunityChat*(communityId: string, categoryId: string, chatId: string, position: int) =
|
proc reorderCommunityChat*(communityId: string, categoryId: string, chatId: string, position: int) =
|
||||||
let rpcResult = callPrivateRPC("reorderCommunityChat".prefix, %*[
|
let rpcResult = callPrivateRPC("reorderCommunityChat".prefix, %*[
|
||||||
{
|
{
|
||||||
|
|
|
@ -100,6 +100,14 @@ Column {
|
||||||
icon.source: "../../../img/edit.svg"
|
icon.source: "../../../img/edit.svg"
|
||||||
icon.width: 20
|
icon.width: 20
|
||||||
icon.height: 20
|
icon.height: 20
|
||||||
|
onTriggered: {
|
||||||
|
openPopup(createCategoryPopup, {
|
||||||
|
communityId: chatsModel.communities.activeCommunity.id,
|
||||||
|
isEdit: true,
|
||||||
|
categoryId: model.categoryId,
|
||||||
|
categoryName: model.name
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Separator {
|
Separator {
|
||||||
|
@ -159,7 +167,7 @@ Column {
|
||||||
channelModel: chatsModel.communities.activeCommunity.chats
|
channelModel: chatsModel.communities.activeCommunity.chats
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageDialog {
|
MessageDialog {
|
||||||
id: deleteError
|
id: deleteError
|
||||||
title: qsTr("Error deleting the category")
|
title: qsTr("Error deleting the category")
|
||||||
icon: StandardIcon.Critical
|
icon: StandardIcon.Critical
|
||||||
|
|
|
@ -8,11 +8,12 @@ import "../../../../shared/status"
|
||||||
Rectangle {
|
Rectangle {
|
||||||
property string name: "channel-name"
|
property string name: "channel-name"
|
||||||
property string channelId: "channel-id"
|
property string channelId: "channel-id"
|
||||||
|
property bool isEdit: false
|
||||||
|
property alias checked: chk.checked
|
||||||
property string categoryId: ""
|
property string categoryId: ""
|
||||||
property var onItemChecked
|
property var onItemChecked
|
||||||
property bool isHovered: false
|
property bool isHovered: false
|
||||||
id: container
|
id: container
|
||||||
visible: categoryId == ""
|
|
||||||
height: visible ? 52 : 0
|
height: visible ? 52 : 0
|
||||||
width: 425
|
width: 425
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
|
|
@ -8,17 +8,28 @@ import "../../../../shared/status"
|
||||||
|
|
||||||
ModalPopup {
|
ModalPopup {
|
||||||
property string communityId
|
property string communityId
|
||||||
|
property string categoryId
|
||||||
|
property string categoryName: ""
|
||||||
|
property var channels: []
|
||||||
|
|
||||||
|
property bool isEdit: false
|
||||||
|
readonly property int maxDescChars: 140
|
||||||
property string nameValidationError: ""
|
property string nameValidationError: ""
|
||||||
property bool isValid: nameInput.isValid
|
property bool isValid: nameInput.isValid
|
||||||
|
|
||||||
property var channels: []
|
|
||||||
|
|
||||||
id: popup
|
id: popup
|
||||||
height: 453
|
height: 453
|
||||||
|
|
||||||
onOpened: {
|
onOpened: {
|
||||||
nameInput.text = "";
|
nameInput.text = isEdit ? categoryName : "";
|
||||||
|
if(isEdit){
|
||||||
|
channels = JSON.parse(chatsModel.communities.activeCommunity.getChatIdsByCategory(categoryId))
|
||||||
|
}
|
||||||
nameInput.forceActiveFocus(Qt.MouseFocusReason)
|
nameInput.forceActiveFocus(Qt.MouseFocusReason)
|
||||||
|
if(isEdit){
|
||||||
|
validate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onClosed: destroy()
|
onClosed: destroy()
|
||||||
|
|
||||||
|
@ -27,7 +38,9 @@ ModalPopup {
|
||||||
return isValid
|
return isValid
|
||||||
}
|
}
|
||||||
|
|
||||||
title: qsTr("New category")
|
title: isEdit ?
|
||||||
|
qsTr("Edit category") :
|
||||||
|
qsTr("New category")
|
||||||
|
|
||||||
ScrollView {
|
ScrollView {
|
||||||
property ScrollBar vScrollBar: ScrollBar.vertical
|
property ScrollBar vScrollBar: ScrollBar.vertical
|
||||||
|
@ -86,12 +99,13 @@ ModalPopup {
|
||||||
|
|
||||||
StatusSectionHeadline {
|
StatusSectionHeadline {
|
||||||
id: chatsTitle
|
id: chatsTitle
|
||||||
text: qsTr("Chats")
|
text: qsTr("Channels")
|
||||||
anchors.top: sep.bottom
|
anchors.top: sep.bottom
|
||||||
anchors.topMargin: Style.current.smallPadding
|
anchors.topMargin: Style.current.smallPadding
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
|
id: communityChannelList
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
model: chatsModel.communities.activeCommunity.chats
|
model: chatsModel.communities.activeCommunity.chats
|
||||||
anchors.top: chatsTitle.bottom
|
anchors.top: chatsTitle.bottom
|
||||||
|
@ -102,6 +116,8 @@ ModalPopup {
|
||||||
name: model.name
|
name: model.name
|
||||||
channelId: model.id
|
channelId: model.id
|
||||||
categoryId: model.categoryId
|
categoryId: model.categoryId
|
||||||
|
checked: popup.isEdit ? channels.indexOf(model.id) > - 1 : false
|
||||||
|
visible: popup.isEdit ? model.categoryId == popup.categoryId || model.categoryId == "" : model.categoryId == ""
|
||||||
onItemChecked: function(channelId, itemChecked){
|
onItemChecked: function(channelId, itemChecked){
|
||||||
var idx = channels.indexOf(channelId)
|
var idx = channels.indexOf(channelId)
|
||||||
if(itemChecked){
|
if(itemChecked){
|
||||||
|
@ -117,14 +133,88 @@ ModalPopup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Separator {
|
||||||
|
id: sep2
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.top: communityChannelList.bottom
|
||||||
|
anchors.topMargin: Style.current.padding
|
||||||
|
anchors.leftMargin: -Style.current.padding
|
||||||
|
anchors.rightMargin: -Style.current.padding
|
||||||
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: deleteCategory
|
||||||
|
anchors.top: sep2.bottom
|
||||||
|
anchors.topMargin: Style.current.padding
|
||||||
|
width: deleteBtn.width + deleteTxt.width + Style.current.padding
|
||||||
|
height: deleteBtn.height
|
||||||
|
|
||||||
|
|
||||||
|
StatusRoundButton {
|
||||||
|
id: deleteBtn
|
||||||
|
icon.name: "delete"
|
||||||
|
size: "medium"
|
||||||
|
type: "warn"
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
id: deleteTxt
|
||||||
|
text: qsTr("Delete category")
|
||||||
|
color: Style.current.red
|
||||||
|
anchors.left: deleteBtn.right
|
||||||
|
anchors.leftMargin: Style.current.padding
|
||||||
|
anchors.verticalCenter: deleteBtn.verticalCenter
|
||||||
|
font.pixelSize: 15
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
onClicked: {
|
||||||
|
openPopup(deleteCategoryConfirmationDialogComponent, {
|
||||||
|
title: qsTr("Delete %1 category").arg(categoryName),
|
||||||
|
confirmationText: qsTr("Are you sure you want to delete %1 category? Channels inside the category won’t be deleted.").arg(categoryName)
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: deleteCategoryConfirmationDialogComponent
|
||||||
|
ConfirmationDialog {
|
||||||
|
btnType: "warn"
|
||||||
|
height: 216
|
||||||
|
showCancelButton: true
|
||||||
|
onClosed: {
|
||||||
|
destroy()
|
||||||
|
}
|
||||||
|
onCancelButtonClicked: {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
onConfirmButtonClicked: function(){
|
||||||
|
const error = chatsModel.communities.deleteCommunityCategory(chatsModel.communities.activeCommunity.id, popup.categoryId)
|
||||||
|
if (error) {
|
||||||
|
creatingError.text = error
|
||||||
|
return creatingError.open()
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
popup.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
footer: StatusButton {
|
footer: StatusButton {
|
||||||
enabled: popup.isValid
|
enabled: popup.isValid
|
||||||
//% "Create"
|
text: isEdit ?
|
||||||
text: qsTrId("create")
|
qsTr("Save") :
|
||||||
|
qsTr("Create")
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (!validate()) {
|
if (!validate()) {
|
||||||
|
@ -132,19 +222,27 @@ ModalPopup {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const error = chatsModel.communities.createCommunityCategory(communityId, Utils.filterXSS(nameInput.text), JSON.stringify(channels))
|
let error = ""
|
||||||
|
|
||||||
|
if(isEdit){
|
||||||
|
error = chatsModel.communities.editCommunityCategory(communityId, categoryId, Utils.filterXSS(nameInput.text), JSON.stringify(channels))
|
||||||
|
} else {
|
||||||
|
error = chatsModel.communities.createCommunityCategory(communityId, Utils.filterXSS(nameInput.text), JSON.stringify(channels))
|
||||||
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
creatingError.text = error
|
categoryError.text = error
|
||||||
return creatingError.open()
|
return categoryError.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
popup.close()
|
popup.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageDialog {
|
MessageDialog {
|
||||||
id: creatingError
|
id: categoryError
|
||||||
title: qsTr("Error creating the category")
|
title: isEdit ?
|
||||||
|
qsTr("Error editing the category") :
|
||||||
|
qsTr("Error creating the category")
|
||||||
icon: StandardIcon.Critical
|
icon: StandardIcon.Critical
|
||||||
standardButtons: StandardButton.Ok
|
standardButtons: StandardButton.Ok
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue