From 04daf2b09894a26d30d17a77c57a6d367199bb2b Mon Sep 17 00:00:00 2001 From: TimofeyBoyko Date: Wed, 20 Jul 2022 09:24:24 +0300 Subject: [PATCH] Web:Files:FilesActionsStore: add group operations for pin and archive rooms --- .../Client/src/store/FilesActionsStore.js | 92 ++++++++++++++++--- 1 file changed, 78 insertions(+), 14 deletions(-) diff --git a/products/ASC.Files/Client/src/store/FilesActionsStore.js b/products/ASC.Files/Client/src/store/FilesActionsStore.js index 6666a79ac5..dc2c993d23 100644 --- a/products/ASC.Files/Client/src/store/FilesActionsStore.js +++ b/products/ASC.Files/Client/src/store/FilesActionsStore.js @@ -760,16 +760,25 @@ class FilesActionStore { const items = Array.isArray(id) ? id : [id]; + const actions = []; + switch (action) { case "pin": - return pinRoom(items) + items.forEach((item) => { + actions.push(pinRoom(item)); + }); + + return Promise.all(actions) .then(() => { this.updateCurrentFolder(null, items); }) .then(() => setSelected("close")) .finally(() => toastr.success("Room pinned")); case "unpin": - return unpinRoom(items) + items.forEach((item) => { + actions.push(unpinRoom(item)); + }); + return Promise.all(actions) .then(() => { this.updateCurrentFolder(null, items); }) @@ -814,9 +823,15 @@ class FilesActionStore { addActiveItems(null, items); + const actions = []; + switch (action) { case "archive": - return moveRoomToArchive(items) + items.forEach((item) => { + actions.push(moveRoomToArchive(item)); + }); + + return Promise.all(actions) .then(async (res) => { if (res[0]?.error) return Promise.reject(res[0].error); const data = res ? res : null; @@ -836,7 +851,10 @@ class FilesActionStore { }) .finally(() => clearActiveOperations(null, items)); case "unarchive": - return removeRoomFromArchive(items) + items.forEach((item) => { + actions.push(removeRoomFromArchive(item)); + }); + return Promise.all(actions) .then(async (res) => { if (res[0]?.error) return Promise.reject(res[0].error); const data = res ? res : null; @@ -1143,6 +1161,54 @@ class FilesActionStore { return result; }; + pinRooms = () => { + const { selection } = this.filesStore; + + const items = []; + + selection.forEach((item) => { + if (!item.pinned) items.push(item.id); + }); + + this.setPinAction("pin", items); + }; + + unpinRooms = () => { + const { selection } = this.filesStore; + + const items = []; + + selection.forEach((item) => { + if (item.pinned) items.push(item.id); + }); + + this.setPinAction("unpin", items); + }; + + moveRoomsToArchive = () => { + const { selection } = this.filesStore; + + const items = []; + + selection.forEach((item) => { + items.push(item.id); + }); + + this.setArchiveAction("archive", items); + }; + + moveRoomsFromArchive = () => { + const { selection } = this.filesStore; + + const items = []; + + selection.forEach((item) => { + items.push(item.id); + }); + + this.setArchiveAction("unarchive", items); + }; + getOption = (option, t) => { const { setSharingPanelVisible, @@ -1204,35 +1270,33 @@ class FilesActionStore { case "pin": return { key: "pin", - label: "Pin to top", + label: t("Pin"), iconUrl: "/static/images/pin.react.svg", - onClick: (e) => { - console.log(e.target); - }, + onClick: this.pinRooms, disabled: false, }; case "unpin": return { key: "unpin", - label: "Unpin", + label: t("Unpin"), iconUrl: "/static/images/unpin.react.svg", - onClick: () => console.log("unpin"), + onClick: this.unpinRooms, disabled: false, }; case "archive": return { key: "archive", - label: "Move to archive", + label: t("ToArchive"), iconUrl: "/static/images/room.archive.svg", - onClick: () => console.log("to archive"), + onClick: this.moveRoomsToArchive, disabled: false, }; case "unarchive": return { key: "unarchive", - label: "Move from archive", + label: t("FromArchive"), iconUrl: "/static/images/room.archive.svg", - onClick: () => console.log("from archive"), + onClick: this.moveRoomsFromArchive, disabled: false, };