sou 7 лет назад
Родитель
Сommit
5e60846c33
3 измененных файлов с 38 добавлено и 4 удалено
  1. 1 0
      lib/routes/index.js
  2. 32 4
      lib/routes/page.js
  3. 5 0
      lib/views/modal/create_page.html

+ 1 - 0
lib/routes/index.js

@@ -178,6 +178,7 @@ module.exports = function(crowi, app) {
   app.get( '/_api/attachments.list'   , accessTokenParser , loginRequired(crowi, app, false) , attachment.api.list);
   app.post('/_api/attachments.add'    , uploads.single('file'), accessTokenParser, loginRequired(crowi, app) ,csrf, attachment.api.add);
   app.post('/_api/attachments.remove' , accessTokenParser , loginRequired(crowi, app) , csrf, attachment.api.remove);
+  app.get('/_api/page.template'   , accessTokenParser , loginRequired(crowi, app, false) , page.api.template);
 
   app.get( '/_api/revisions.get'      , accessTokenParser , loginRequired(crowi, app, false) , revision.api.get);
   app.get( '/_api/revisions.ids'      , accessTokenParser , loginRequired(crowi, app, false) , revision.api.ids);

+ 32 - 4
lib/routes/page.js

@@ -871,15 +871,15 @@ module.exports = function(crowi, app) {
       return res.json(ApiResponse.error(new Error('Parameter path or page_id is required.')));
     }
 
-    let pageFinder;
+    let templateFinder;
     if (pageId) { // prioritized
-      pageFinder = Page.findPageByIdAndGrantedUser(pageId, req.user);
+      templateFinder = Page.findPageByIdAndGrantedUser(pageId, req.user);
     }
     else if (pagePath) {
-      pageFinder = Page.findPage(pagePath, req.user, revisionId);
+      templateFinder = Page.findPage(pagePath, req.user, revisionId);
     }
 
-    pageFinder.then(function(pageData) {
+    templateFinder.then(function(pageData) {
       var result = {};
       result.page = pageData;
 
@@ -1185,5 +1185,33 @@ module.exports = function(crowi, app) {
     });
   };
 
+  /**
+   * @api {get} /pages.get Get page data
+   * @apiName GetPage
+   * @apiGroup Page
+   *
+   * @apiParam {String} page_id
+   * @apiParam {String} path
+   * @apiParam {String} revision_id
+   */
+  api.template = function(req, res) {
+    const pagePath = req.query.path || null;
+
+    if (!pagePath) {
+      return res.json(ApiResponse.error(new Error('Parameter path is required.')));
+    }
+
+    const templateFinder = Page.checkIfTemplatesExist(pagePath);
+
+    templateFinder.then(function(templateInfo) {
+      var result = {};
+      result.templateInfo = templateInfo;
+
+      return res.json(ApiResponse.success(result));
+    }).catch(function(err) {
+      return res.json(ApiResponse.error(err));
+    });
+  };
+
   return actions;
 };

+ 5 - 0
lib/views/modal/create_page.html

@@ -75,6 +75,11 @@
       pagePath = pagePath.slice(0, -1);
     };
 
+    $.get(`/_api/page.template?path=${pagePath}`)
+    .then(templateInfo => {
+      console.log('data', templateInfo);
+    });
+
     $("#template-type").on("change", () => {
       if ($("#template-type").val() === "local") {
         href = pagePath + "/__template#edit-form";