Skip to content

Commit

Permalink
sort of ok
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Aug 25, 2024
1 parent 859332b commit 316dab4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
4 changes: 2 additions & 2 deletions papermerge/core/page_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
logger = logging.getLogger(__name__)


def apply_pages_op(items: List[PageAndRotOp]) -> List[PyDocVer]:
def apply_pages_op(items: List[PageAndRotOp]) -> List[PyDocument]:
pages = Page.objects.filter(
pk__in=[item.page.id for item in items]
)
Expand Down Expand Up @@ -51,7 +51,7 @@ def apply_pages_op(items: List[PageAndRotOp]) -> List[PyDocVer]:
)
notify_generate_previews(str(doc.id))

return doc.versions.all()
return doc


def copy_pdf_pages(
Expand Down
7 changes: 4 additions & 3 deletions papermerge/core/routers/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from papermerge.core.page_ops import move_pages as api_move_pages
from papermerge.core.schemas import ExtractPagesOut, MovePagesOut
from papermerge.core.schemas.documents import DocumentVersion as PyDocVer
from papermerge.core.schemas.documents import Document as PyDocument
from papermerge.core.schemas.pages import (ExtractPagesIn, MovePagesIn,
PageAndRotOp)
from papermerge.core.utils import image
Expand Down Expand Up @@ -136,7 +137,7 @@ def apply_page_operations(
schemas.User,
Security(get_current_user, scopes=[scopes.PAGE_UPDATE])
],
) -> List[PyDocVer]:
) -> PyDocument:
"""Applies reorder, delete and/or rotate operation(s) on a set of pages.
Required scope: `{scope}`
Expand All @@ -156,9 +157,9 @@ def apply_page_operations(
When `angle` > 0 -> the rotation is clockwise.
When `angle` < 0 -> the rotation is counterclockwise.
"""
new_versions = apply_pages_op(items)
new_doc = apply_pages_op(items)

return [PyDocVer.model_validate(version) for version in new_versions]
return PyDocument.model_validate(new_doc)


@router.post("/move")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function ThumbnailsToggle() {
page: {id: p.page.id, number: p.page.number}
}
})
dispatch(applyPageOpChanges(_pages))
dispatch(applyPageOpChanges({pages, panel: mode}))
}
}

Expand Down
53 changes: 50 additions & 3 deletions ui2/src/slices/dualPanel/dualPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,20 @@ export const fetchPaginatedDocument = createAsyncThunk<DocumentType, ThunkArgs>(
}
)

export const applyPageOpChanges = createAsyncThunk<void, ApplyPagesType[]>(
type ApplyPageOpChangesThunkArgs = {
panel: PanelMode
pages: ApplyPagesType[]
}

export const applyPageOpChanges = createAsyncThunk<
DocumentType,
ApplyPageOpChangesThunkArgs
>(
"document/applyPageOpChanges",
async (pages: ApplyPagesType[]) => {
axios.post("/api/pages/", pages)
async ({pages}: ApplyPageOpChangesThunkArgs) => {
const response = await axios.post("/api/pages/", pages)
const doc = response.data as DocumentType
return doc
}
)

Expand Down Expand Up @@ -559,6 +569,43 @@ const dualPanelSlice = createSlice({
removeNodesHelper(state, nodeIds)
}
)
builder.addCase(applyPageOpChanges.fulfilled, (state, action) => {
if (action.meta.arg.panel == "main") {
const versionNumbers = action.payload.versions.map(v => v.number)
state.mainPanel.viewer = {
breadcrumb: action.payload.breadcrumb,
versions: injectPageRotOp(action.payload.versions),
currentVersion: Math.max(...versionNumbers),
currentPage: 1,
thumbnailsPanelOpen: mainThumbnailsPanelInitialState(),
zoomFactor: 100,
selectedIds: [],
//@ts-ignore
initialPages: getLatestVersionPages(action.payload.versions)
}
return
}

if (action.meta.arg.panel == "secondary") {
const versionNumbers = action.payload.versions.map(v => v.number)
state.secondaryPanel = {
commander: null,
searchResults: null,
viewer: {
breadcrumb: action.payload.breadcrumb,
versions: injectPageRotOp(action.payload.versions),
currentVersion: Math.max(...versionNumbers),
currentPage: 1,
thumbnailsPanelOpen: secondaryThumbnailsPanelInitialState(),
zoomFactor: 100,
selectedIds: [],
//@ts-ignore
initialPages: getLatestVersionPages(action.payload.versions)
}
}
return
}
})
builder.addCase(fetchPaginatedDocument.fulfilled, (state, action) => {
if (action.meta.arg.panel == "main") {
const versionNumbers = action.payload.versions.map(v => v.number)
Expand Down

0 comments on commit 316dab4

Please sign in to comment.