Search:
Template:MindTouch > IDF > Views > Guide

Guide

    Table of contents
    No headers
    /***
        USAGE:
    
        Guide(description)
            Show a content guide that organizes the tree rooted at the guide pages into types of pages (topics, tutorials, troubleshooting and reference).
    
        PARAMETERS:
    
        description : str
            Description of what this guide covers.
    
    ***/
    
    // Redirect to custom page, if any
    var template_custom = __page.path .. 'Custom';
    if (wiki.pageexists(template_custom)) {
        return template(template_custom, $);
    }
    
    var description = $0 ?? $description;
    
    // select appropriate guide
    var guide = __request.args.guide ?? 'guide';
    switch(guide) {
    case 'guide':
    case 'troubleshooting':
    case 'reference':
    case 'tutorial':
    case 'history':
        break;
    default:
        
        // invalid key, replace with safe default
        let guide = 'guide';
    }
    
    // check if we have a cached version
    var cachekey = null;
    if(__env.webcache && guide !== 'history') {
        let cachekey = 
            page.id .. '-' ..
            wiki.recentchangestimestamp{ path: 'Template:MindTouch' } .. '-' ..
            wiki.recentchangestimestamp{ pages: true, tags: true, comments: false, files: false };
        if(__request.args.nocache) {
            webcache.clear(cachekey);
            let cachekey = null;
        } else {
            var cached = webcache.fetch(cachekey);
            if(cached) {
                <div style="display: none"> "IDF guide rendered from cache" </div>
                return cached;
            }
        }
    }
    
    // build document
    var result = (
    
        // build list of all child pages in order of appearance
        var common_parents = page.parents;
        var tree = wiki.tree();
        var pageids = [ xml.num(id) foreach var id in tree["//@pageid"] ];
        var pages = {
            (p.id): p .. {
                parents: list.splice(p.parents, 0, #common_parents),
                topic: #[ t foreach var t in tags where string.startswith(t.value, 'article:topic') ] > 0,
                tutorial: #[ t foreach var t in tags where string.startswith(t.value, 'article:task-tutorial') ] > 0,
                troubleshooting: #[ t foreach var t in tags where string.startswith(t.value, 'article:task-troubleshooting') ] > 0,
                reference: #[ t foreach var t in tags where string.startswith(t.value, 'article:reference') ] > 0,
                beginner: #[ t foreach var t in tags where string.endswith(t.value, 'beginner') ] > 0,
                intermediate: #[ t foreach var t in tags where string.endswith(t.value, 'intermediate') ] > 0,
                advanced: #[ t foreach var t in tags where string.endswith(t.value, 'advanced') ] > 0,
                feature: #[ t foreach var t in tags where string.endswith(t.value, 'feature') ] > 0,
                sample: #[ t foreach var t in tags where string.endswith(t.value, 'sample') ] > 0
            } foreach
                var id in pageids,
                var p = wiki.getpage(id),
                var tags = p.tags
        };
        var topics = [ p foreach var id in pageids, var p = pages[id], if p.topic ];
        var tutorials = [ p foreach var id in pageids, var p = pages[id], if p.tutorial ];
        var troubleshootings = [ p foreach var id in pageids, var p = pages[id], if p.troubleshooting ];
        var references = [ p foreach var id in pageids, var p = pages[id], if p.reference ];
       
        // the guide expects to be within a <table>
        <td>
            <div class="mindtouch-content mindtouch-collection">
          
                // can preload when not on history tab
                var class_preload = (guide != 'history') ? 'mt-guide-preload' : '';  
          
                /*
                 * Master Tabs
                 */
                <div class="mt-control-nav">
                    <ul>
                        <li>
                            <a rel="custom" href=(page.uri & { guide: nil }) id="guide-guide" class=(class_preload)>
                                wiki.localize("MindTouch.IDF.guide");
                                " ";
                                <span class="count">"("; #topics; ")";</span>
                            </a>
                        </li>
                        <li>
                            <a rel="custom" href=(page.uri & { guide: "tutorial" }) id="guide-tutorial" class=(class_preload)>
                                wiki.localize("MindTouch.IDF.tutorial");
                                " ";
                                <span class="count">"("; #tutorials; ")";</span>
                            </a>
                        </li>
                        <li>
                            <a rel="custom" href=(page.uri & { guide: "reference" }) id="guide-reference" class=(class_preload)>
                                wiki.localize("MindTouch.IDF.reference");
                                " ";
                                <span class="count">"("; #references; ")";</span>
                            </a>
                        </li>
                        <li>
                            <a rel="custom" href=(page.uri & { guide: "troubleshooting" }) id="guide-troubleshooting" class=(class_preload)>
                                wiki.localize("MindTouch.IDF.troubleshooting");
                                " ";
                                <span class="count">"("; #troubleshootings; ")";</span>
                            </a>
                        </li>
                        <li class=(guide === "history" ? "active" : _)>
                            <a rel="custom" href=(page.uri & { guide: "history" }) id="guide-history">
                                wiki.localize("MindTouch.IDF.history");
                            </a>
                        </li>
                    </ul>
                </div>
          
                // all tabs except history are preloaded; render them in full, but hide with CSS
                if (guide == 'history') {
                    <div class="page-history">
                        Template("MindTouch/IDF/Controls/ListChanges", {
                            limit: 100,
                            depth: 'infinity'
                        });
                    </div>
                } else {
              
                    /*
                     * Tutorials Tab
                     */
                    <div style='display: none;' class="guide-content" id="guide-tutorial-content">
                        if(#tutorials == 0) {
                            <div class="mt-control-nocontent">
                                <p class="nocontent-title">wiki.localize("MindTouch.IDF.tutorial.empty");</p>
                                <p>wiki.localize("MindTouch.IDF.tutorial.text");</p>
                            </div>
                        } else {
                            <div class="mt-control-pagelist">      
                                <div class="mt-control-subnav">
                                    <p>wiki.localize("MindTouch.IDF.tutorial.view");</p>
                                    <ul>
                                        <li><a href="#tutorial-beginner">
                                            wiki.localize("MindTouch.IDF.tutorial.beginner.short");</a>
                                        </li>
                                        <li><a href="#tutorial-intermediate">
                                            wiki.localize("MindTouch.IDF.tutorial.intermediate.short");</a>
                                        </li>
                                        <li><a href="#tutorial-advanced">
                                            wiki.localize("MindTouch.IDF.tutorial.advanced.short");</a>
                                        </li>
                                    </ul>
                                </div>
                          
                                var p = [ p foreach var p in tutorials where p.beginner ];
                                if(#p > 0) {
                                    <div class="subtitle" id="tutorial-beginner">
                                        wiki.localize("MindTouch.IDF.tutorial.beginner");
                                    </div>
                                    template("MindTouch/IDF/Controls/PageListWithBreadcrumbs", {
                                        pages: p,
                                        heading: "h4"
                                    });
                                }
                          
                                var p = [ p foreach var p in tutorials where p.intermediate ];
                                if(#p > 0) {
                                    <div class="subtitle" id="tutorial-intermediate">
                                        wiki.localize("MindTouch.IDF.tutorial.intermediate");
                                    </div>
                                    template("MindTouch/IDF/Controls/PageListWithBreadcrumbs", {
                                        pages: p,
                                        heading: "h4"
                                    });
                                }
                          
                                var p = [ p foreach var p in tutorials where p.advanced ];
                                if(#p > 0) {
                                    <div class="subtitle" id="tutorial-advanced">
                                        wiki.localize("MindTouch.IDF.tutorial.advanced");
                                    </div>
                                    template("MindTouch/IDF/Controls/PageListWithBreadcrumbs", {
                                        pages: p,
                                        heading: "h4"
                                    });
                                }
                            </div>
                        }
                     </div> // end tutorial
          
                    /*
                     * Troubleshooting Tab
                     */
                    <div style='display: none;' id="guide-troubleshooting-content" class="guide-content">
                        if(#troubleshootings == 0) {
                            <div class="mt-control-nocontent">
                                <p class="nocontent-title">wiki.localize("MindTouch.IDF.troubleshooting.empty");</p>
                                <p>wiki.localize("MindTouch.IDF.troubleshooting.text");</p>
                            </div>
                        } else {
                            <div class="mt-control-pagelist">
                            <div class="subtitle">
                                 wiki.localize("MindTouch.IDF.troubleshooting.subtitle");
                            </div>
                            template("MindTouch/IDF/Controls/PageListWithBreadcrumbs", {
                                pages: troubleshootings
                            });
                            </div>
                        }
                    </div>
          
                    /*
                     * Reference Tab
                     */
                    <div style='display: none;' id="guide-reference-content" class="guide-content">
                        if(#references == 0) {
                            <div class="mt-control-nocontent">
                                <p class="nocontent-title">wiki.localize("MindTouch.IDF.reference.empty");</p>
                                <p>wiki.localize("MindTouch.IDF.reference.text");</p>
                            </div>
                        } else {
                            <div class="mt-control-pagelist">
                                <div class="mt-control-subnav">
                                    <p>wiki.localize("MindTouch.IDF.reference.view");</p>
                                    <ul>
                                        <li><a href="#reference-feature">
                                            wiki.localize("MindTouch.IDF.reference.feature.short");</a>
                                        </li>
                                        <li><a href="#reference-sample">
                                            wiki.localize("MindTouch.IDF.reference.sample.short");</a>
                                        </li>
                                    </ul>
                                </div>
                          
                                var p = [ p foreach var p in references where p.feature ];
                                if(#p > 0) {
                                    <div class="subtitle" id="reference-feature">
                                        wiki.localize("MindTouch.IDF.reference.feature");
                                    </div>
                                    template("MindTouch/IDF/Controls/PageListWithBreadcrumbs", {
                                        pages: p,
                                        heading: "h4"
                                    });
                                }
                          
                                var p = [ p foreach var p in references where p.sample ];
                                if(#p > 0) {
                                    <div class="subtitle" id="reference-sample">
                                        wiki.localize("MindTouch.IDF.reference.sample");
                                    </div>
                                    template("MindTouch/IDF/Controls/PageListWithBreadcrumbs", {
                                        pages: p,
                                        heading: "h4"
                                    });
                                }
          
                            </div>
                        }
                    </div>
          
                    /*
                     * Main guide page
                     */
                    <div class="guide-content" id="guide-guide-content">  
                        wiki.template("MindTouch/IDF/Views/GuideContent", { description: description, pages: pages });
                    </div>
                }
            </div>
        </td>
    );
    
    // keep generated document
    cachekey ? webcache.store(cachekey, result, 2592000) : result;
    
    $(function(){
        $('a.mt-guide-preload').attr('href', '#').click(function() {
            $('.mt-control-nav li').removeClass('active');
            $('.guide-content').hide();
            
            $('#' + $(this).attr('id') + '-content').show();
            $(this).parent().addClass('active');
            return false;
        });
        // show active tab
        $('#guide-' + {{ guide }}).click();
    });
    
    #pageText  table,
    #pageText table td {
        border: none;
    }
    

    Files (0)

     

    Comments (0)

    You must login to post a comment.