Yuki Takei 4 лет назад
Родитель
Сommit
073b8e4770

+ 11 - 10
packages/plugin-lsx/src/client/js/components/Lsx.jsx

@@ -40,14 +40,14 @@ export class Lsx extends React.Component {
         isError: this.props.lsxStateCache.isError,
         errorMessage: this.props.lsxStateCache.errorMessage,
       });
-      return;   // go to render()
+      return; // go to render()
     }
 
     // add slash ensure not to forward match to another page
     // ex: '/Java/' not to match to '/JavaScript'
-    let pagePath = pathUtils.addTrailingSlash(lsxContext.pagePath);
+    const pagePath = pathUtils.addTrailingSlash(lsxContext.pagePath);
 
-    this.props.crowi.apiGet('/plugins/lsx', {pagePath, options: lsxContext.options})
+    this.props.crowi.apiGet('/plugins/lsx', { pagePath, options: lsxContext.options })
       .then((res) => {
         if (res.ok) {
           const nodeTree = this.generatePageNodeTree(pagePath, res.pages);
@@ -79,7 +79,7 @@ export class Lsx extends React.Component {
    * @memberOf Lsx
    */
   generatePageNodeTree(rootPagePath, pages) {
-    let pathToNodeMap = {};
+    const pathToNodeMap = {};
 
     pages.forEach((page) => {
       // add slash ensure not to forward match to another page
@@ -91,13 +91,13 @@ export class Lsx extends React.Component {
         return;
       }
 
-      const node = this.generatePageNode(pathToNodeMap, rootPagePath, pagePath);  // this will not be null
+      const node = this.generatePageNode(pathToNodeMap, rootPagePath, pagePath); // this will not be null
       // set the Page substance
       node.page = page;
     });
 
     // return root objects
-    let rootNodes = [];
+    const rootNodes = [];
     Object.keys(pathToNodeMap).forEach((pagePath) => {
       // exclude '/'
       if (pagePath === '/') {
@@ -143,7 +143,7 @@ export class Lsx extends React.Component {
      */
     // get or create parent node
     const parentPath = this.getParentPath(pagePath);
-    let parentNode = this.generatePageNode(pathToNodeMap, rootPagePath, parentPath);
+    const parentNode = this.generatePageNode(pathToNodeMap, rootPagePath, parentPath);
     // associate to patent
     if (parentNode != null) {
       parentNode.children.push(node);
@@ -189,14 +189,15 @@ export class Lsx extends React.Component {
       );
     }
     // render tree
-    else {
-      return <LsxListView nodeTree={this.state.nodeTree} lsxContext={this.props.lsxContext} />;
-    }
+
+    return <LsxListView nodeTree={this.state.nodeTree} lsxContext={this.props.lsxContext} />;
+
   }
 
   render() {
     return <div className="lsx">{this.renderContents()}</div>;
   }
+
 }
 
 Lsx.propTypes = {

+ 6 - 5
packages/plugin-lsx/src/client/js/components/LsxPageList/LsxListView.jsx

@@ -20,21 +20,22 @@ export class LsxListView extends React.Component {
     // no contents
     if (this.props.nodeTree.length == 0) {
       return <div className="text-muted">
-          <small>
-            <i className="fa fa-fw fa-info-circle" aria-hidden="true"></i>
+        <small>
+          <i className="fa fa-fw fa-info-circle" aria-hidden="true"></i>
             $lsx(<a href={this.props.lsxContext.pagePath}>{this.props.lsxContext.pagePath}</a>) has no contents
-          </small>
-        </div>;
+        </small>
+      </div>;
     }
 
     return (
       <div className="page-list lsx">
         <ul className="page-list-ul">
-        {listView}
+          {listView}
         </ul>
       </div>
     );
   }
+
 }
 
 LsxListView.propTypes = {

+ 5 - 4
packages/plugin-lsx/src/client/js/components/LsxPageList/LsxPage.jsx

@@ -27,16 +27,16 @@ export class LsxPage extends React.Component {
     const pageNode = this.props.pageNode;
 
     if (pageNode.page !== undefined) {
-      this.setState({isExists: true});
+      this.setState({ isExists: true });
     }
     if (pageNode.children.length > 0) {
-      this.setState({hasChildren: true});
+      this.setState({ hasChildren: true });
     }
 
     // process depth option
     const optDepth = this.props.lsxContext.getOptDepth();
     if (optDepth === undefined) {
-      this.setState({isLinkable: true});
+      this.setState({ isLinkable: true });
     }
     else {
       const depth = this.props.depth;
@@ -45,7 +45,7 @@ export class LsxPage extends React.Component {
       // console.log(pageNode.pagePath, {depth, decGens, 'optDepth.start': optDepth.start, 'optDepth.end': optDepth.end});
 
       const isLinkable = optDepth.start <= depth;
-      this.setState({isLinkable});
+      this.setState({ isLinkable });
     }
   }
 
@@ -96,6 +96,7 @@ export class LsxPage extends React.Component {
       </li>
     );
   }
+
 }
 
 LsxPage.propTypes = {

+ 2 - 1
packages/plugin-lsx/src/client/js/components/LsxPageList/PagePathWrapper.jsx

@@ -7,7 +7,7 @@ export class PagePathWrapper extends React.Component {
 
   render() {
 
-    let classNames = [];
+    const classNames = [];
     if (!this.props.isExists) {
       classNames.push('lsx-page-not-exist');
     }
@@ -16,6 +16,7 @@ export class PagePathWrapper extends React.Component {
       <PagePath page={{ path: this.props.pagePath }} isShortPathOnly={true} additionalClassNames={classNames} />
     );
   }
+
 }
 
 PagePathWrapper.propTypes = {

+ 2 - 1
packages/plugin-lsx/src/client/js/components/PageNode.js

@@ -32,7 +32,7 @@ export class PageNode {
   */
 
   static instanciateFrom(obj) {
-    let pageNode = new PageNode(obj.pagePath);
+    const pageNode = new PageNode(obj.pagePath);
     pageNode.page = obj.page;
 
     // instanciate recursively
@@ -42,4 +42,5 @@ export class PageNode {
 
     return pageNode;
   }
+
 }

+ 5 - 5
packages/plugin-lsx/src/client/js/util/Interceptor/LsxPostRenderInterceptor.js

@@ -23,8 +23,8 @@ export class LsxPostRenderInterceptor extends BasicInterceptor {
    */
   isInterceptWhen(contextName) {
     return (
-      contextName === 'postRenderHtml' ||
-      contextName === 'postRenderPreviewHtml'
+      contextName === 'postRenderHtml'
+      || contextName === 'postRenderPreviewHtml'
     );
   }
 
@@ -32,7 +32,7 @@ export class LsxPostRenderInterceptor extends BasicInterceptor {
    * @inheritdoc
    */
   process(contextName, ...args) {
-    const context = Object.assign(args[0]);   // clone
+    const context = Object.assign(args[0]); // clone
 
     // forEach keys of lsxContextMap
     Object.keys(context.lsxContextMap).forEach((renderId) => {
@@ -40,7 +40,7 @@ export class LsxPostRenderInterceptor extends BasicInterceptor {
 
       if (elem) {
         // get LsxContext instance from context
-        let lsxContext = context.lsxContextMap[renderId];
+        const lsxContext = context.lsxContextMap[renderId];
 
         // check cache exists
         const cacheKey = LsxCacheHelper.generateCacheKeyFromContext(lsxContext);
@@ -56,7 +56,7 @@ export class LsxPostRenderInterceptor extends BasicInterceptor {
   renderReactDOM(lsxContext, lsxStateCache, elem) {
     ReactDOM.render(
       <Lsx crowi={this.crowi} lsxContext={lsxContext} lsxStateCache={lsxStateCache} />,
-      elem
+      elem,
     );
   }
 

+ 6 - 5
packages/plugin-lsx/src/client/js/util/Interceptor/LsxPreRenderInterceptor.js

@@ -21,8 +21,8 @@ export class LsxPreRenderInterceptor extends BasicInterceptor {
    */
   isInterceptWhen(contextName) {
     return (
-      contextName === 'preRenderHtml' ||
-      contextName === 'preRenderPreviewHtml'
+      contextName === 'preRenderHtml'
+      || contextName === 'preRenderPreviewHtml'
     );
   }
 
@@ -30,7 +30,7 @@ export class LsxPreRenderInterceptor extends BasicInterceptor {
    * @inheritdoc
    */
   process(contextName, ...args) {
-    const context = Object.assign(args[0]);   // clone
+    const context = Object.assign(args[0]); // clone
     const parsedHTML = context.parsedHTML;
     const currentPagePath = context.currentPagePath;
     this.initializeCache(contextName);
@@ -48,13 +48,13 @@ export class LsxPreRenderInterceptor extends BasicInterceptor {
       lsxArgs = lsxArgs.trim();
 
       // create contexts
-      let lsxContext = new LsxContext();
+      const lsxContext = new LsxContext();
       lsxContext.currentPagePath = currentPagePath;
       lsxContext.tagExpression = tagExpression;
       lsxContext.fromPagePath = fromPagePath;
       lsxContext.lsxArgs = lsxArgs;
 
-      const renderId = 'lsx-' + this.createRandomStr(8);
+      const renderId = `lsx-${this.createRandomStr(8)}`;
 
       context.lsxContextMap[renderId] = lsxContext;
 
@@ -99,4 +99,5 @@ export class LsxPreRenderInterceptor extends BasicInterceptor {
     }
     return generated;
   }
+
 }

+ 2 - 1
packages/plugin-lsx/src/client/js/util/LsxCacheHelper.js

@@ -67,7 +67,7 @@ export class LsxCacheHelper {
    * @memberOf LsxCacheHelper
    */
   static cacheState(key, lsxState) {
-    let cacheObj = LsxCacheHelper.retrieveFromSessionStorage();
+    const cacheObj = LsxCacheHelper.retrieveFromSessionStorage();
     cacheObj[key] = lsxState;
 
     LsxCacheHelper.saveToSessionStorage(cacheObj);
@@ -83,4 +83,5 @@ export class LsxCacheHelper {
   static clearAllStateCaches() {
     LsxCacheHelper.saveToSessionStorage({});
   }
+
 }

+ 11 - 10
packages/plugin-lsx/src/client/js/util/LsxContext.js

@@ -27,7 +27,8 @@ export class LsxContext {
 
     if (this.lsxArgs.length > 0) {
       const splittedArgs = this.lsxArgs.split(',');
-      let firstArgsKey, firstArgsValue;
+      let firstArgsKey; let
+        firstArgsValue;
 
       splittedArgs.forEach((arg, index) => {
         arg = arg.trim();
@@ -50,10 +51,9 @@ export class LsxContext {
       //   1: lsx(prefix=..., ...)
       //   2: lsx(firstArgs, ...)
       //   3: fromPagePath
-      specifiedPath =
-          this.options.prefix ||
-          ((firstArgsValue === true) ? firstArgsKey : undefined) ||
-          this.fromPagePath;
+      specifiedPath = this.options.prefix
+          || ((firstArgsValue === true) ? firstArgsKey : undefined)
+          || this.fromPagePath;
     }
 
     // resolve pagePath
@@ -63,9 +63,9 @@ export class LsxContext {
     //        `pagePath` to be /fuga
     //   when `fromPagePath`=/hoge and `specifiedPath`=undefined,
     //        `pagePath` to be /hoge
-    this.pagePath = (specifiedPath !== undefined) ?
-      decodeURIComponent(url.resolve(pathUtils.addTrailingSlash(this.fromPagePath), specifiedPath)):
-      this.fromPagePath;
+    this.pagePath = (specifiedPath !== undefined)
+      ? decodeURIComponent(url.resolve(pathUtils.addTrailingSlash(this.fromPagePath), specifiedPath))
+      : this.fromPagePath;
 
     this.isParsed = true;
   }
@@ -99,10 +99,10 @@ export class LsxContext {
 
       // determine end
       if (operator === ':') {
-        end = +match[4] || -1;  // set last(-1) if undefined
+        end = +match[4] || -1; // set last(-1) if undefined
       }
       else if (operator === '+') {
-        end = +match[4] || 0;   // plus zero if undefined
+        end = +match[4] || 0; // plus zero if undefined
         end += start;
       }
     }
@@ -114,4 +114,5 @@ export class LsxContext {
 
     return { start, end };
   }
+
 }

+ 3 - 3
packages/plugin-lsx/src/meta.js

@@ -3,9 +3,9 @@ const path = require('path');
 module.exports = {
   pluginSchemaVersion: 2,
   serverEntries: [
-    path.join(__dirname, 'server-entry.js')
+    path.join(__dirname, 'server-entry.js'),
   ],
   clientEntries: [
-    path.join(__dirname, 'client-entry.js')
-  ]
+    path.join(__dirname, 'client-entry.js'),
+  ],
 };

+ 13 - 11
packages/plugin-lsx/src/server/routes/lsx.js

@@ -1,4 +1,5 @@
 const { customTagUtils } = require('growi-commons');
+
 const { OptionParser } = customTagUtils;
 
 class Lsx {
@@ -25,11 +26,11 @@ class Lsx {
 
     // count slash
     const slashNum = pagePath.split('/').length - 1;
-    const depthStart = slashNum;            // start is not affect to fetch page
+    const depthStart = slashNum; // start is not affect to fetch page
     const depthEnd = slashNum + end - 1;
 
     return query.and({
-      path: new RegExp(`^(\\/[^\\/]*){${depthStart},${depthEnd}}$`)
+      path: new RegExp(`^(\\/[^\\/]*){${depthStart},${depthEnd}}$`),
     });
   }
 
@@ -96,16 +97,17 @@ class Lsx {
       isReversed = (optionsReverse === 'true');
     }
 
-    let sortOption = {};
+    const sortOption = {};
     sortOption[optionsSort] = isReversed ? -1 : 1;
     return query.sort(sortOption);
   }
+
 }
 
 module.exports = (crowi, app) => {
-  const Page = crowi.model('Page')
-    , ApiResponse = crowi.require('../util/apiResponse')
-    , actions = {};
+  const Page = crowi.model('Page');
+  const ApiResponse = crowi.require('../util/apiResponse');
+  const actions = {};
 
   /**
    *
@@ -117,7 +119,7 @@ module.exports = (crowi, app) => {
   async function generateBaseQueryBuilder(pagePath, user) {
     let baseQuery = Page.find();
     if (Page.PageQueryBuilder == null) {
-      if (Page.generateQueryToListWithDescendants != null) {  // for Backward compatibility (<= GROWI v3.2.x)
+      if (Page.generateQueryToListWithDescendants != null) { // for Backward compatibility (<= GROWI v3.2.x)
         baseQuery = Page.generateQueryToListWithDescendants(pagePath, user, {});
       }
       else if (Page.generateQueryToListByStartWith != null) { // for Backward compatibility (<= crowi-plus v2.0.7)
@@ -145,9 +147,9 @@ module.exports = (crowi, app) => {
   }
 
   actions.listPages = async(req, res) => {
-    let user = req.user;
-    let pagePath = req.query.pagePath;
-    let options = JSON.parse(req.query.options);
+    const user = req.user;
+    const pagePath = req.query.pagePath;
+    const options = JSON.parse(req.query.options);
 
     const builder = await generateBaseQueryBuilder(pagePath, user);
 
@@ -165,7 +167,7 @@ module.exports = (crowi, app) => {
       query = Lsx.addSortCondition(query, pagePath, options.sort, options.reverse);
 
       const pages = await query.exec();
-      res.json(ApiResponse.success({pages}));
+      res.json(ApiResponse.success({ pages }));
     }
     catch (error) {
       return res.json(ApiResponse.error(error));