Browse Source

toastr and moved logic to model

sou 7 years ago
parent
commit
fa7aafddd9

+ 15 - 0
lib/models/page.js

@@ -1059,8 +1059,14 @@ module.exports = function(crowi) {
   pageSchema.statics.deletePage = function(pageData, user, options) {
     var Page = this
       , newPath = Page.getDeletedPageName(pageData.path)
+      , isTrashed = checkIfTrashed(pageData.path)
       ;
+
     if (Page.isDeletableName(pageData.path)) {
+      if (isTrashed) {
+        return Page.completelyDeletePage(pageData, user, options);
+      }
+
       return Page.rename(pageData, newPath, user, {createRedirectPage: true})
         .then((updatedPageData) => {
           return Page.updatePageProperty(updatedPageData, {status: STATUS_DELETED, lastUpdateUser: user});
@@ -1074,12 +1080,21 @@ module.exports = function(crowi) {
     }
   };
 
+  const checkIfTrashed = (path) => {
+    return (path.search(/^\/trash/) !== -1);
+  };
+
   pageSchema.statics.deletePageRecursively = function(pageData, user, options) {
     var Page = this
       , path = pageData.path
       , options = options || {}
+      , isTrashed = checkIfTrashed(pageData.path);
       ;
 
+    if (isTrashed) {
+      return Page.completelyDeletePageRecursively(pageData, user, options);
+    }
+
     return Page.generateQueryToListWithDescendants(path, user, options)
       .then(function(pages) {
         return Promise.all(pages.map(function(page) {

+ 1 - 1
lib/models/revision.js

@@ -12,7 +12,7 @@ module.exports = function(crowi) {
     body: { type: String, required: true, get: (data) => {
       // replace CR/CRLF to LF above v3.1.5
       // see https://github.com/weseek/growi/issues/463
-      return data && data.replace(/\r\n?/g, '\n');
+      return data ? data.replace(/\r\n?/g, '\n') : '';
     }},
     format: { type: String, default: 'markdown' },
     author: { type: ObjectId, ref: 'User' },

+ 2 - 7
lib/routes/page.js

@@ -1081,17 +1081,12 @@ module.exports = function(crowi, app) {
     var previousRevision = req.body.revision_id || null;
 
     // get completely flag
-    let isCompletely = (req.body.completely !== undefined);
+    const isCompletely = (req.body.completely != null);
     // get recursively flag
-    const isRecursively = (req.body.recursively !== undefined);
+    const isRecursively = (req.body.recursively != null);
 
     Page.findPageByIdAndGrantedUser(pageId, req.user)
       .then(function(pageData) {
-        const isTrashed = pageData.path.search(/^\/trash/) !== -1;
-        if (isTrashed) {
-          isCompletely = true;
-        }
-
         debug('Delete page', pageData._id, pageData.path);
 
         if (isCompletely) {

+ 11 - 1
resource/js/components/SearchPage/SearchResult.js

@@ -1,5 +1,6 @@
 import React from 'react';
 import PropTypes from 'prop-types';
+import * as toastr from 'toastr';
 
 import Page from '../PageList/Page';
 import SearchResultList from './SearchResultList';
@@ -133,7 +134,16 @@ export default class SearchResult extends React.Component {
     .then(() => {
       window.location.reload();
     })
-    .catch(err => {});
+    .catch(err => {
+      toastr.error(err, 'Error occured', {
+        closeButton: true,
+        progressBar: true,
+        newestOnTop: false,
+        showDuration: '100',
+        hideDuration: '100',
+        timeOut: '3000',
+      });
+    });
   }
 
   /**