Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:WardCunningham/Smallest-Federated…

…-Wiki

Conflicts:
	client/client.js
	client/lib/legacy.coffee
  • Loading branch information...
commit bf7daef1afacf5cc2e4d89fdbc0f32a4ed46b6ec 2 parents 25d9455 + c09d3f7
@nrn authored
View
2  client/client.js
@@ -751,7 +751,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
wiki.addToJournal(pageElement.find('.journal'), {
type: 'fork',
site: site,
- date: (new Date()).getTime()
+ date: action.date
});
}
if (wiki.useLocalStorage()) {
View
2  client/lib/pageHandler.coffee
@@ -77,7 +77,7 @@ pageHandler.put = (pageElement, action) ->
wiki.addToJournal pageElement.find('.journal'),
type: 'fork'
site: site
- date: (new Date()).getTime()
+ date: action.date
if wiki.useLocalStorage()
pushToLocal(pageElement, action)
pageElement.addClass("local")
View
59 client/plugins/method.coffee
@@ -0,0 +1,59 @@
+window.plugins.method =
+ emit: (div, item) ->
+ bind: (div, item) ->
+ title = div.parents('.page:first').find('h1').text().trim()
+ data = wiki.getData()
+ throw "can't find data" unless data?
+ for row in data
+ input = row if row.Material == title
+ throw "can't find #{title} in data" unless input?
+
+ sum = (v) ->
+ _.reduce v, (s,n) -> s += n
+
+ avg = (v) ->
+ sum(v)/v.length
+
+ round = (n) ->
+ return '?' unless n?
+ if n.toString().match /\.\d\d\d/
+ n.toFixed 2
+ else
+ n
+
+ calculate = (item) ->
+ list = []
+ for line in item.text.split "\n"
+ color = '#eee'
+ value = comment = null
+ try
+ if input[line]?
+ value = input[line]
+ comment = input["#{line} Assumptions"] || null
+ else if line.match /^[0-9\.-]/
+ value = +line
+ else if line == 'SUM'
+ color = '#ddd'
+ [value, list] = [sum(list), []]
+ else if line == 'AVG'
+ color = '#ddd'
+ [value, list] = [avg(list), []]
+ else
+ color = '#edd'
+ catch err
+ color = '#edd'
+ value = null
+ comment = err.message
+
+ list.push +value if value? and ! isNaN +value
+
+ annotate = (text) ->
+ return '' unless text?
+ " <span title=\"#{text}\">*</span>"
+
+ "<tr style=\"background:#{color};\"><td style=\"width: 70%;\">#{line}#{annotate comment}<td><b>#{round value}</b>"
+
+ text = calculate(item).join "\n"
+ table = $(title+'<table style="width:100%; background:#eee; padding:.8em;"/>').html text
+ div.append table
+ div.dblclick -> wiki.textEditor div, item
View
78 client/plugins/method.js
@@ -0,0 +1,78 @@
+(function() {
+
+ window.plugins.method = {
+ emit: function(div, item) {},
+ bind: function(div, item) {
+ var avg, calculate, data, input, round, row, sum, table, text, title, _i, _len;
+ title = div.parents('.page:first').find('h1').text().trim();
+ data = wiki.getData();
+ if (data == null) throw "can't find data";
+ for (_i = 0, _len = data.length; _i < _len; _i++) {
+ row = data[_i];
+ if (row.Material === title) input = row;
+ }
+ if (input == null) throw "can't find " + title + " in data";
+ sum = function(v) {
+ return _.reduce(v, function(s, n) {
+ return s += n;
+ });
+ };
+ avg = function(v) {
+ return sum(v) / v.length;
+ };
+ round = function(n) {
+ if (n == null) return '?';
+ if (n.toString().match(/\.\d\d\d/)) {
+ return n.toFixed(2);
+ } else {
+ return n;
+ }
+ };
+ calculate = function(item) {
+ var annotate, color, comment, line, list, value, _j, _len2, _ref, _ref2, _ref3, _results;
+ list = [];
+ _ref = item.text.split("\n");
+ _results = [];
+ for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) {
+ line = _ref[_j];
+ color = '#eee';
+ value = comment = null;
+ try {
+ if (input[line] != null) {
+ value = input[line];
+ comment = input["" + line + " Assumptions"] || null;
+ } else if (line.match(/^[0-9\.-]/)) {
+ value = +line;
+ } else if (line === 'SUM') {
+ color = '#ddd';
+ _ref2 = [sum(list), []], value = _ref2[0], list = _ref2[1];
+ } else if (line === 'AVG') {
+ color = '#ddd';
+ _ref3 = [avg(list), []], value = _ref3[0], list = _ref3[1];
+ } else {
+ color = '#edd';
+ }
+ } catch (err) {
+ color = '#edd';
+ value = null;
+ comment = err.message;
+ }
+ if ((value != null) && !isNaN(+value)) list.push(+value);
+ annotate = function(text) {
+ if (text == null) return '';
+ return " <span title=\"" + text + "\">*</span>";
+ };
+ _results.push("<tr style=\"background:" + color + ";\"><td style=\"width: 70%;\">" + line + (annotate(comment)) + "<td><b>" + (round(value)) + "</b>");
+ }
+ return _results;
+ };
+ text = calculate(item).join("\n");
+ table = $(title + '<table style="width:100%; background:#eee; padding:.8em;"/>').html(text);
+ div.append(table);
+ return div.dblclick(function() {
+ return wiki.textEditor(div, item);
+ });
+ }
+ };
+
+}).call(this);
View
2  client/test/testclient.js
@@ -778,7 +778,7 @@ require.define("/lib/pageHandler.coffee", function (require, module, exports, __
wiki.addToJournal(pageElement.find('.journal'), {
type: 'fork',
site: site,
- date: (new Date()).getTime()
+ date: action.date
});
}
if (wiki.useLocalStorage()) {
Please sign in to comment.
Something went wrong with that request. Please try again.