/
commit.js
69 lines (62 loc) · 1.76 KB
/
commit.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
58
59
60
61
62
63
64
65
66
67
68
69
/*
* List, view and update commit page.
*/
exports.list = function (req, res) {
var type = req.params.type === undefined ? 'data' : req.params.type,
backup = res.app.settings.backup[type];
res.render('commits/list', {
type: type,
title: type == 'program' ? 'Nuxeo Program' : 'Nuxeo Data',
list: backup.list(),
head: backup.head()
});
};
exports.view = function (req, res, next) {
var commit,
type = req.params.type,
id = req.params.id,
backup = res.app.settings.backup[type];
if (id) {
commit = backup.get(id);
}
if (commit !== undefined) {
res.render('commits/view', {
command: '',
type: type,
title: type == 'program' ? 'Nuxeo Program' : 'Nuxeo Data',
commit: commit,
diff: backup.diff(id).split(/\r?\n/g)
});
} else {
next(new Error('Cannot find commit ' + id));
}
};
exports.update = function (req, res, next) {
var commit,
result,
type = req.params.type,
id = req.params.id,
command = req.body.command,
backup = res.app.settings.backup[type];
if (id) {
commit = backup.get(id);
}
if (command != 'checkout') {
next(new Error('The application only supports checkout commands yet!'));
} else if (commit === undefined) {
next(new Error('Cannot find commit ' + id));
} else {
//Always saving current working files before trying to restore an old commit
backup.run();
//Restore commit
result = backup.restore(id);
res.render('commits/update', {
command: command,
type: type,
title: type == 'program' ? 'Nuxeo Program' : 'Nuxeo Data',
commit: commit,
head: backup.head(),
diff: backup = backup.diff(id).split(/\r?\n/g)
});
}
};