all repos — litestore @ 5146101b6d0e3ff95473404884c2c365fd3a4f7a

A minimalist nosql document store.

src/admin/js/components/doclist.js

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
(function(){
  'use strict';
  var app = window.LS || (window.LS = {});
  var u = app.utils;

  app.doclist = {};

  // Subcomponent
  app.doclist.panel = {

    /**
     * @typedef {Object} DoclistPanelConfig
     * @prop {string} id
     * @prop {string[]} tags
     * @prop {string} content
     *
     * @param {Function} ctrl
     * @param {DoclistPanelConfig} args
     */
    view: function(ctrl, args){
      var obj = {};
      var path = (args.id.match(/\.html?$/)) ? "/html/" : "/document/view/";
      obj.title = m("a", {href: path+args.id, config: m.route}, [args.id]);
      obj.content = m("div", [
        m("p", [args.content]),
        m("p", args.tags.map(function(tag){
          return u.taglink({name: tag, key: u.guid()});
        }))
      ]);
      return m(".row.search-result", m(".col-md-12", [u.panel(obj)]));
    }
  };

  /**
   * @param {Function} ctrl
   * @param {Object} args
   * @param {string} args.title
   * @param {string} args.subtitle
   * @param {array.} args.items
   * @param {PaginatorConfig} args.querydata
   */
  app.doclist.view = function(ctrl, args){
    var results = m(".row", [m(".col-md-12", args.items.map(function(item){
      item.key = u.guid();
      return m.component(app.doclist.panel, item);
    }))]);

    return m("section", [
      m(".row", [args.title]),
      m(".row", [args.subtitle]),
      m(".row.text-center", [u.paginator(args.querydata)]),
      results,
      m(".row.text-center", [u.paginator(args.querydata)])
    ]);
  };

}());