Search:
Template:MindTouch > IDF > Controls > ListChanges

ListChanges

    Table of contents
    No headers
    /***
        USAGE:
    
        ListChanges(page, limit)
            create a list of recent changes for the given page
    
        PARAMETERS:
    
        (optional) page : num/str
            page for which to retrieve changes; defaults to current page
    
        (optional) limit : num
            maximum number of changes to show; defaults to 50
    
        (optional) depth : str
            depth to traverse; defaults to 0
    
    ***/
    
    var source_page = $0 ?? $page ?? page.id;
    var limit = $1 ?? $limit ?? 50;
    var depth = $2 ?? $depth ?? 0;
    
    var feedUri = wiki.getpage(source_page).feed & {limit: limit, format: 'rawdaily', depth: depth};
    var changes = wiki.api(feedUri)['change'];
    
    var dates = {};
    var ordered_dates = [];
    var dateFormat = 'yyyyMMdd';
    
    // collect dates into day-by-day aggregate
    foreach (var c in changes) {
        var changeDate = date.parse(xml.text(c, 'rc_timestamp'), 'yyyyMMddHHmmss');
        var dateTitle = date.format(changeDate, dateFormat);
    
        if (!dates[dateTitle]) {
            let dates = dates .. {(dateTitle): []};
            let ordered_dates = ordered_dates .. [dateTitle];
        }
    
        let dates = dates .. {(dateTitle): dates[dateTitle] .. [c]};
    }
    
    if (#changes > 0) {
        <div class="noindex">
        <ul class="recentchanges">
        foreach (var dateTitle in ordered_dates) {
        let dateChanges = dates[dateTitle];
        
        // convert to user-friendly format
        let sectionDate = date.parse(dateTitle, dateFormat);
    
        <li class="recentchanges-datetitle">
            Template('MindTouch/Controls/DateTime', {date:sectionDate, format: 'date'});
        </li>
    
        foreach (var c in dateChanges) {
            var pageId =  xml.num(c, 'rc_cur_id');
            var page = wiki.getPage(pageId);
            var username = xml.text(c, 'rc_user_name');
            var user = wiki.getuser(username);
            var changeDate = date.parse(xml.text(c, 'rc_timestamp'), 'yyyyMMddHHmmss');
            var pageExists = xml.num(c, 'rc_page_exists');
            var pageTitle = xml.text(c, 'rc_title');
    
            <li>
                pageExists ? web.link(page.uri, page.title) : pageTitle; 
                <div class="recentchanges-details">
                    wiki.localize('MindTouch.Templates.ListChanges.updated.by') .. ' ';
              
                    user ? <a href=(user.uri)>username</a> : username;
                    ' ';
                    wiki.localize('MindTouch.Templates.ListChanges.updated.at') .. ' ';
                    <span class="recentchanges-date">Template('MindTouch/Controls/DateTime', {date:changeDate, format:'time'})</span>
                    ': ';
                    <span class="recentchanges-change">xml.text(c, 'rc_comment');</span>
                </div>
            </li>
            }
        }
        </ul>
        </div>
    }
    
    
    ul.recentchanges {
       padding: 0px;
       margin: 0px 0px 0px 10px;
    }
    
    ul.recentchanges li {
       margin-left: 20px;
       padding-bottom: 10px;
    }
    
    ul.recentchanges .recentchanges-datetitle {
       font-size: 18px;
       font-weight: bold;
       margin: 25px 0px 5px 0px;
       padding-bottom: 5px;
       border-bottom: 1px solid #eaeaea;
    }
    

    Files (0)

     

    Comments (0)

    You must login to post a comment.