Просмотр исходного кода

delete page recursively and Individually

yohei0125 4 лет назад
Родитель
Сommit
26fa51c16c

+ 1 - 0
packages/app/src/client/services/ContextExtractor.tsx

@@ -50,6 +50,7 @@ const ContextExtractorOnce: FC = () => {
   const revisionId = mainContent?.getAttribute('data-page-revision-id');
   const path = decodeURI(mainContent?.getAttribute('data-path') || '');
   const pageId = mainContent?.getAttribute('data-page-id') || JSON.parse(notFoundContent?.getAttribute('data-empty-page-id') || jsonNull);
+
   const revisionCreatedAt = +(mainContent?.getAttribute('data-page-revision-created') || '');
 
   // createdAt

+ 5 - 4
packages/app/src/components/Navbar/GrowiContextualSubNavigation.tsx

@@ -235,14 +235,15 @@ const GrowiContextualSubNavigation = (props) => {
 
     const className = `d-flex flex-column align-items-end justify-content-center ${isViewMode ? ' h-50' : ''}`;
 
-    const displayedPageId = pageId;
+    console.log('pageId', pageId);
+
     return (
       <>
         <div className={className}>
-          { displayedPageId != null && isViewMode && (
+          { pageId != null && isViewMode && (
             <SubNavButtons
               isCompactMode={isCompactMode}
-              pageId={displayedPageId}
+              pageId={pageId}
               shareLinkId={shareLinkId}
               revisionId={revisionId}
               path={path}
@@ -251,7 +252,7 @@ const GrowiContextualSubNavigation = (props) => {
               additionalMenuItemRenderer={props => (
                 <AdditionalMenuItems
                   {...props}
-                  pageId={displayedPageId}
+                  pageId={pageId}
                   revisionId={revisionId}
                   isLinkSharingDisabled={isLinkSharingDisabled}
                   onClickTemplateMenuItem={templateMenuItemClickHandler}

+ 6 - 7
packages/app/src/server/routes/page.js

@@ -278,11 +278,11 @@ module.exports = function(crowi, app) {
     renderVars.isNotFoundPermalink = !isPath && !await Page.exists({ _id: pathOrId });
   }
 
-  async function addRenderVarsWhenEmptyPage(renderVars, emptyPagePermalink) {
-    if (emptyPagePermalink == null) {
+  async function addRenderVarsWhenEmptyPage(renderVars, emptyPageId) {
+    if (emptyPageId == null) {
       return;
     }
-    renderVars.emptyPagePermalink = emptyPagePermalink;
+    renderVars.emptyPageId = emptyPageId;
   }
 
   function replacePlaceholdersOfTemplate(template, req) {
@@ -340,9 +340,8 @@ module.exports = function(crowi, app) {
     await addRenderVarsForDescendants(renderVars, path, req.user, offset, limit, true);
     await addRenderVarsForPageTree(renderVars, pathOrId, req.user);
     await addRenderVarsWhenNotFound(renderVars, pathOrId);
-    if (req.emptyPagePermalink != null) {
-    // isEmpty かどうかをフロントに伝える
-      await addRenderVarsWhenEmptyPage(renderVars, req.emptyPagePermalink);
+    if (req.emptyPageId != null) {
+      await addRenderVarsWhenEmptyPage(renderVars, req.emptyPageId);
     }
     return res.render(view, renderVars);
   }
@@ -660,7 +659,7 @@ module.exports = function(crowi, app) {
       return _notFound(req, res);
     }
     if (isEmptyPage) {
-      req.emptyPagePermalink = pages[0]._id;
+      req.emptyPageId = pages[0]._id;
       return _notFound(req, res);
     }
 

+ 0 - 3
packages/app/src/server/service/page.ts

@@ -1419,9 +1419,6 @@ class PageService {
   private async deleteEmptyTarget(page): Promise<void> {
     const Page = mongoose.model('Page') as unknown as PageModel;
 
-    // update descendantCount of ancestors' before removeLeafEmptyPages
-    await this.updateDescendantCountOfAncestors(page._id, -page.descendantCount, false);
-
     await Page.deleteOne({ _id: page._id, isEmpty: true });
   }
 

+ 1 - 1
packages/app/src/server/views/layout-growi/not_found.html

@@ -6,12 +6,12 @@
   <div
     id="growi-pagetree-not-found-context"
     data-not-found-target-path-or-id="{% if notFoundTargetPathOrId %}{{notFoundTargetPathOrId|json}}{% endif %}"
-    data-empty-page-id="{%if emptyPagePermalink %}{{emptyPagePermalink|json}}{% endif %}"
   >
   </div>
   <div
     id="growi-not-found-context"
     data-is-not-found-permalink="{% if isNotFoundPermalink %}{{isNotFoundPermalink|json}}{% endif %}"
+    data-empty-page-id="{%if emptyPageId %}{{emptyPageId|json}}{% endif %}"
   >
   </div>
   <div class="grw-container-convertible">