Commit b74bb6d9 authored by Boris Kocherov's avatar Boris Kocherov

workflow_history support

parent 048dea6e
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
(function (window, jIO, RSVP, console, Blob, jstoxml, base64js) { (function (window, jIO, RSVP, console, Blob, jstoxml, base64js) {
"use strict"; "use strict";
var CurrentTimestamp = new Date().getTime() / 1000;
function string2blob(s) { function string2blob(s) {
var l = s.length, var l = s.length,
array = new Uint8Array(l); array = new Uint8Array(l);
...@@ -14,15 +16,20 @@ ...@@ -14,15 +16,20 @@
} }
function generateZopeData(obj) { function generateZopeData(obj) {
var records = []; var records = [], records_count = 1, tasks = [];
function pickle(obj) { function pickle(obj) {
var type = typeof obj, var type = typeof obj,
items = []; items = [];
if (obj === null) {
type = 'null';
}
if (Array.isArray(obj)) { if (Array.isArray(obj)) {
type = 'array'; type = 'array';
} }
switch (type) { switch (type) {
case "null":
return {none: ""};
case "string": case "string":
// TODO cdata fix // TODO cdata fix
obj = obj obj = obj
...@@ -40,26 +47,91 @@ ...@@ -40,26 +47,91 @@
items.push(pickle(obj[i])); items.push(pickle(obj[i]));
} }
return {tuple: items}; return {tuple: items};
// case "function": return obj.name || obj.toString(); case "function":
return obj();
case "number":
return {float: obj};
case "object": case "object":
if (obj.persistent) {
return obj;
}
for (var key in obj) { for (var key in obj) {
if (obj.hasOwnProperty(key)) { if (obj.hasOwnProperty(key)) {
items.push({ if (key === "workflow_history") {
item: { items.push({
key: { item: {
string: key key: {
}, string: key
value: pickle(obj[key]) },
} value: add_workflow_history(obj[key])
}); }
});
} else {
items.push({
item: {
key: {
string: key
},
value: pickle(obj[key])
}
});
}
} }
} }
return {dictionary: items}; return {dictionary: items};
default: default:
return obj.toString(); return obj.toString();
} }
}
function pickle_date(timestamp) {
return function () {
return {
object: [
{
klass: {
_name: "global",
_attrs: {
name: "DateTime",
module: "DateTime.DateTime"
}
}
},
pickle([null]),
{
state: pickle([
timestamp,
"UTC"
])
}
]
};
};
}
function add_workflow_history(obj) {
return add_record("PersistentMapping", "Persistence.mapping",
function () {
var workflows = {};
Object.keys(obj).forEach(function (key) {
if (obj.hasOwnProperty(key)) {
workflows[key] = add_record("WorkflowHistoryList",
"Products.ERP5Type.patches.WorkflowTool",
function () {
obj[key].time = pickle_date(CurrentTimestamp);
obj[key].actor = "zope";
return {
tuple: [
pickle(null),
{list: pickle(obj[key])}
]
};
}
);
}
});
return pickle({data: workflows});
});
} }
function longToByteArray(/*long*/long) { function longToByteArray(/*long*/long) {
...@@ -78,31 +150,46 @@ ...@@ -78,31 +150,46 @@
} }
function add_record(name, module, obj) { function add_record(name, module, obj) {
var id = records.length + 1; var id = records_count++,
records.push({ base64 = base64js.fromByteArray(longToByteArray(id));
_name: "record", tasks.push(function () {
_attrs: { return {
id: id, _name: "record",
aka: base64js.fromByteArray(longToByteArray(id)) _attrs: {
}, id: id,
_content: [ aka: base64
{ },
pickle: { _content: [
_name: "global", {
_attrs: { pickle: {
name: name, _name: "global",
module: module _attrs: {
name: name,
module: module
}
} }
},
{
pickle: obj()
} }
}, ]
{ };
pickle: pickle(obj)
}
]
}); });
return {
persistent: {
_name: "string",
_attrs: {encoding: "base64"},
_content: base64
}
};
} }
add_record(obj.portal_type, "erp5.portal_type", obj); add_record(obj.portal_type, "erp5.portal_type", function () {
return pickle(obj);
});
while (tasks.length > 0) {
records.push(tasks.shift()());
}
return jstoxml.toXML({ return jstoxml.toXML({
ZopeData: records ZopeData: records
}, {header: true, indent: ' '}); }, {header: true, indent: ' '});
...@@ -170,7 +257,8 @@ ...@@ -170,7 +257,8 @@
Fs2Erp5Storage.prototype.repair = function () { Fs2Erp5Storage.prototype.repair = function () {
// Transform id attachment ( file path ) to id list / attachments // Transform id attachment ( file path ) to id list / attachments
var context = this; var context = this,
bt_folder = {};
return context._sub_storage.repair() return context._sub_storage.repair()
.push(function () { .push(function () {
return jIO.util.ajax({ return jIO.util.ajax({
...@@ -180,7 +268,7 @@ ...@@ -180,7 +268,7 @@
}); });
}) })
.push(function (response) { .push(function (response) {
var scopes, i, x, scope, bt_folder = {}, size = 0, var scopes, i, x, scope, size = 0,
path; path;
function add_metafile(fname, body) { function add_metafile(fname, body) {
...@@ -237,8 +325,8 @@ ...@@ -237,8 +325,8 @@
}) })
.push(function (result) { .push(function (result) {
var id, path, last_index, filename, ext, i, size, var id, path, last_index, filename, ext, i, size,
xmldoc = {}, bt_links = {}, path_templates = [], xmldoc, bt_links = {}, path_templates = [],
generated_appcache = []; generated_appcache = [], document_publication_wfl;
for (id in result) { for (id in result) {
if ( if (
result.hasOwnProperty(id) && result.hasOwnProperty(id) &&
...@@ -247,6 +335,7 @@ ...@@ -247,6 +335,7 @@
!id.startsWith("erp5_/") && //rmove meta of package !id.startsWith("erp5_/") && //rmove meta of package
!id.startsWith("assets/") // remove github added assets !id.startsWith("assets/") // remove github added assets
) { ) {
xmldoc = {};
last_index = id.lastIndexOf("/") + 1; last_index = id.lastIndexOf("/") + 1;
if (last_index === id.length) { if (last_index === id.length) {
path = id || "/"; path = id || "/";
...@@ -255,8 +344,13 @@ ...@@ -255,8 +344,13 @@
path = id.substring(0, last_index); path = id.substring(0, last_index);
filename = id.substring(last_index); filename = id.substring(last_index);
} }
xmldoc = { xmldoc.version = context._options.version;
version: context._options.version document_publication_wfl = {
action: "publish_alive",
validation_state: "published_alive"
};
xmldoc.workflow_history = {
document_publication_workflow: document_publication_wfl
}; };
path = path + filename; path = path + filename;
size = 0; size = 0;
...@@ -310,6 +404,8 @@ ...@@ -310,6 +404,8 @@
xmldoc.title = filename; xmldoc.title = filename;
xmldoc.filename = filename; xmldoc.filename = filename;
xmldoc.content_type = "image/" + ext; xmldoc.content_type = "image/" + ext;
document_publication_wfl.action = "publish";
document_publication_wfl.validation_state = "published";
break; break;
case "json": case "json":
xmldoc.portal_type = "File"; xmldoc.portal_type = "File";
...@@ -325,6 +421,8 @@ ...@@ -325,6 +421,8 @@
if (xmldoc.portal_type === "File") { if (xmldoc.portal_type === "File") {
path = "document_module"; path = "document_module";
xmldoc.title = filename; xmldoc.title = filename;
document_publication_wfl.action = "publish";
document_publication_wfl.validation_state = "published";
} }
if (!bt_links.hasOwnProperty(path)) { if (!bt_links.hasOwnProperty(path)) {
bt_links[path] = 1; bt_links[path] = 1;
...@@ -345,8 +443,11 @@ ...@@ -345,8 +443,11 @@
context._id_dict[path][xmldoc.id + '.xml'] = xmldoc; context._id_dict[path][xmldoc.id + '.xml'] = xmldoc;
} }
} }
context._id_dict[context.path_prefix_meta].template_path_list = path_templates = string2blob(path_templates.join("\n"));
string2blob(path_templates.join("\n")); bt_folder.template_path_list = path_templates;
bt_folder.template_keep_workflow_path_list = path_templates;
bt_folder.template_keep_last_workflow_history_only_path_list =
path_templates;
// generate appcache as list of all packaged files // generate appcache as list of all packaged files
xmldoc = { xmldoc = {
...@@ -355,6 +456,12 @@ ...@@ -355,6 +456,12 @@
default_reference: "", default_reference: "",
portal_type: "Web Manifest", portal_type: "Web Manifest",
content_type: "application/json", content_type: "application/json",
workflow_history: {
document_publication_workflow: {
action: "publish_alive",
validation_state: "published_alive"
}
},
text_content: "CACHE MANIFEST\nCACHE:\n" + text_content: "CACHE MANIFEST\nCACHE:\n" +
generated_appcache.join("\n") + "\nNETWORK:\n*" generated_appcache.join("\n") + "\nNETWORK:\n*"
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment