Skip to content

Commit

Permalink
Routes document revision change through manager
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Jan 8, 2024
1 parent f70c95d commit 10d70e6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/common/dialog/RevisionsDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
export let enabled: boolean = false;
export let revisions: Revision[] | null = [];
export let onSave: (enabled: boolean) => void;
export let onCancel: () => {};
export let onCancel: () => void;
$: sortedRevisions =
revisions?.sort((a, b) => {
Expand Down
6 changes: 3 additions & 3 deletions src/common/dialog/RevisionsDialogContainer.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { changeRevisionControl } from "../../api/document.js";
import { changeRevisionControlForDocuments } from "../../manager/documents";
import { viewer } from "../../viewer/viewer.js";
import RevisionsDialog from "./RevisionsDialog.svelte";
import emitter from "../../emit.js";
Expand All @@ -12,8 +12,8 @@
const documentId = document?.id;
const revisions = document?.revisions;
const enabled = document?.revisionControl;
const onSave = (enabled: boolean) => {
changeRevisionControl([documentId], enabled);
const onSave = async (enabled: boolean) => {
await changeRevisionControlForDocuments([document], enabled);
emit.dismiss();
};
const onCancel = () => {
Expand Down
23 changes: 20 additions & 3 deletions src/manager/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {
editMetadata,
addData,
removeData,
} from "@/api/document.js";
changeRevisionControl,
} from "../api/document.js";
import {
addDocumentsToProject,
removeDocumentsFromProject,
} from "@/api/project.js";
import { layout, hideAccess } from "./layout.js";
} from "../api/project.js";
import { layout, hideAccess, hideRevisions } from "./layout.js";
import { wrapLoad, wrapSeparate } from "@/util/wrapLoad.js";
import { showConfirm } from "./confirmDialog.js";
import { router } from "@/router/router.js";
Expand Down Expand Up @@ -433,6 +434,22 @@ export async function changeAccessForDocuments(
hideAccess();
}

export async function changeRevisionControlForDocuments(
documents,
revision_control,
) {
await wrapLoad(layout, async () => {
await changeRevisionControl(
documents.map((doc) => doc.id),
revision_control,
);
documents.forEach((doc) =>
updateInCollection(doc, (d) => (d.doc = { ...d.doc, revision_control })),
);
});
hideRevisions();
}

export async function changeOwnerForDocuments(
documents,
user,
Expand Down

0 comments on commit 10d70e6

Please sign in to comment.