Skip to content

Commit

Permalink
first version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
smilix committed Sep 14, 2013
0 parents commit 009df36
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
node_modules
.DS_Store
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# en_pad-lister

A plugin for Etherpad-lite that shows a list of all pads sorted by last edit date.
11 changes: 11 additions & 0 deletions ep.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"parts": [
{
"name": "en_pad-lister",
"hooks": {
"expressCreateServer" : "ep_pad-lister/index:registerRoute",
"eejsBlock_indexWrapper": "ep_pad-lister/index"
}
}
]
}
64 changes: 64 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';

var eejs = require('ep_etherpad-lite/node/eejs');
var padManager = require('ep_etherpad-lite/node/db/PadManager');
var dateFormat = require('dateformat');

exports.eejsBlock_indexWrapper = function (hook_name, args, cb) {
args.content = args.content + eejs.require("ep_pad-lister/templates/linkToList.ejs");
return cb();
}

exports.registerRoute = function (hook_name, args, cb) {
var h = '<b>test</b>'
args.app.get('/pad-lister/static/bootstrap.min.css', function (req, res) {
res.sendfile(__dirname + '/static/css/bootstrap.min.css');
});

args.app.get('/pad-lister', function (req, res) {
getDetailedPadList(function (pads) {
var render_args = {
pads: pads
};
res.send(eejs.require('ep_pad-lister/templates/list.html', render_args));
});
});
};

function getDetailedPadList(callback) {
var padNames = padManager.listAllPads().padIDs;

var padData = [];
padNames.forEach(function (padName) {
padManager.getPad(padName, function (err, pad) {
pad.getLastEdit(function (err, time) {
padData.push({
name: padName,
lastRevision: pad.head,
lastAccess: time
});

if (padData.length === padNames.length) {
// sort
padData = sortPadData(padData);
// format each timestamp
padData.forEach(function (padObj) {
padObj.lastAccess = formatDate(padObj.lastAccess);
});
callback(padData);
}
});
}); // end getPad
}); // end forEach
}

// sort by last access
function sortPadData(padData){
return padData.sort(function (a, b) {
return b.lastAccess - a.lastAccess;
});
}

function formatDate(timestamp) {
return dateFormat(new Date(timestamp), 'dd.mm.yyyy hh:MM:ss');
}
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "ep_pad-lister",
"version": "1.0.0",
"description": "Provides a separate list with pads, ordered by last edit.",
"author": "[email protected]",
"readmeFilename": "README.md",
"dependencies": {
"dateformat": "1.0.6-1.2.3"
},
"engines": {
"node": ">= 0.10.3"
},
"repository": {
"type": "git",
"url": "http://github.com/ktt/en_pad-lister.git"
}
}
235 changes: 235 additions & 0 deletions static/css/bootstrap.min.css

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions templates/linkToList.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="pad-lister-link-container">
Get an overview of <em>all</em> pads in the <a href="pad-lister">Padlist</a>!
</div>
47 changes: 47 additions & 0 deletions templates/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<title>Padlist</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<link href="/pad-lister/static/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
body {
font-size: 16px;
}
</style>
</head>
<body>

<div class="jumbotron">
<div class="container">
<h1>Padlist</h1>

<p>All pads, sorted by last edit date.</p>
</div>
</div>

<div class="container">

<table class="table table-striped table-hover">
<thead>
<tr>
<th>Pad</th>
<th>Revision</th>
<th>Last edit date</th>
</tr>
</thead>
<tbody>
<% pads.forEach(function (pad) { %>
<tr>
<td><a href="/public/<%= pad.name %>"><%= pad.name %></a></td>
<td><%= pad.lastRevision %></td>
<td><%= pad.lastAccess %></td>
</tr>
<% }) %>
</tbody>
</table>

</div>
</body>
</html>

0 comments on commit 009df36

Please sign in to comment.