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

Merge pull request #146 from weseek/imprv/move-delete-recursively

Imprv/121 Add recursively option for Move operation
Yuki Takei 8 лет назад
Родитель
Сommit
51544f5f9c
4 измененных файлов с 40 добавлено и 2 удалено
  1. 4 1
      lib/locales/ja/translation.json
  2. 21 0
      lib/models/page.js
  3. 8 1
      lib/routes/page.js
  4. 7 0
      lib/views/modal/rename.html

+ 4 - 1
lib/locales/ja/translation.json

@@ -150,9 +150,12 @@
   "New page name": "移動先のページ名",
   "New page name": "移動先のページ名",
   "Current page name": "現在のページ名",
   "Current page name": "現在のページ名",
   "Redirect": "リダイレクトする",
   "Redirect": "リダイレクトする",
+  "Move recursively": "再帰的に移動する",
   "modal_rename": {
   "modal_rename": {
     "help": {
     "help": {
-      "redirect": "チェックを入れると、<code>%s</code>にアクセスされた際に自動的に新しいページにジャンプします。"
+      "redirect": "チェックを入れると、<code>%s</code>にアクセスされた際に自動的に新しいページにジャンプします。",
+      "recursive": "チェックを入れると、<code>%s</code>配下のページも移動します。"
+
     }
     }
   },
   },
 
 

+ 21 - 0
lib/models/page.js

@@ -1025,6 +1025,27 @@ module.exports = function(crowi) {
     });
     });
   };
   };
 
 
+  pageSchema.statics.renameRecursively = function(pageData, newPagePathPrefix, user, options) {
+    var Page = this
+      , path = pageData.path
+      , pathRegExp = new RegExp('^' + path, 'i');
+
+    return new Promise(function(resolve, reject) {
+      Page
+      .generateQueryToListByStartWith(path, user, options)
+      .then(function(pages) {
+        Promise.all(pages.map(function(page) {
+          newPagePath = page.path.replace(pathRegExp, newPagePathPrefix);
+          return Page.rename(page, newPagePath, user, options);
+        }))
+        .then(function() {
+          pageData.path = newPagePathPrefix;
+          return resolve();
+        });
+      });
+    });
+  };
+
   pageSchema.statics.getHistories = function() {
   pageSchema.statics.getHistories = function() {
     // TODO
     // TODO
     return;
     return;

+ 8 - 1
lib/routes/page.js

@@ -1074,6 +1074,7 @@ module.exports = function(crowi, app) {
       createRedirectPage: req.body.create_redirect || 0,
       createRedirectPage: req.body.create_redirect || 0,
       moveUnderTrees: req.body.move_trees || 0,
       moveUnderTrees: req.body.move_trees || 0,
     };
     };
+    var isRecursiveMove = req.body.move_recursively || 0;
     var page = {};
     var page = {};
 
 
     if (!Page.isCreatableName(newPagePath)) {
     if (!Page.isCreatableName(newPagePath)) {
@@ -1093,7 +1094,13 @@ module.exports = function(crowi, app) {
           throw new Error('Someone could update this page, so couldn\'t delete.');
           throw new Error('Someone could update this page, so couldn\'t delete.');
         }
         }
 
 
-        return Page.rename(pageData, newPagePath, req.user, options);
+        if (isRecursiveMove) {
+          return Page.renameRecursively(pageData, newPagePath, req.user, options);
+        }
+        else {
+          return Page.rename(pageData, newPagePath, req.user, options);
+        }
+
       }).then(function() {
       }).then(function() {
         var result = {};
         var result = {};
         result.page = page;
         result.page = page;

+ 7 - 0
lib/views/modal/rename.html

@@ -20,6 +20,13 @@
                 <input type="text" class="form-control" name="new_path" id="newPageName" value="{{ page.path }}">
                 <input type="text" class="form-control" name="new_path" id="newPageName" value="{{ page.path }}">
               </div>
               </div>
             </div>
             </div>
+            <div class="checkbox">
+              <label>
+                <input name="move_recursively" value="1" type="checkbox" checked> {{ t('Move recursively') }}
+              </label>
+              <p class="help-block"> {{ t('modal_rename.help.recursive', page.path) }}
+              </p>
+            </div>
             <div class="checkbox">
             <div class="checkbox">
                <label>
                <label>
                  <input name="create_redirect" value="1"  type="checkbox"> {{ t('Redirect') }}
                  <input name="create_redirect" value="1"  type="checkbox"> {{ t('Redirect') }}