forked from JackAdams/constellation-autopublish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautopublish-client.js
62 lines (55 loc) · 2.48 KB
/
autopublish-client.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
// Hook in to constellation UI
var Constellation = Package["planable:console"].Constellation;
var API = Package["planable:console"].API;
API.addTab({
name: 'Autopublish',
headerContentTemplate: 'Constellation_autopublish',
guideContentTemplate: 'Constellation_autopublish_guide',
noOpen:true,
onClick: "toggleAutopublish"
});
API.registerCallbacks({
toggleAutopublish : function () {
var ConstellationDict = Constellation.ConstellationDict;
var autoPublishAll = ConstellationDict.get('Constellation_autopublish_all');
ConstellationDict.set('Constellation_autopublish_all', !autoPublishAll);
// If we're switching off autopublish, we need to reset the current collection index number to 0
if (!ConstellationDict.get('Constellation_autopublish_all')) {
var currentTab = API.getCurrentTab();
if (currentTab && currentTab.type === 'collection') {
var C = Constellation;
C.ConstellationDict.set(C.sessKey(currentTab.id), 0);
}
}
}
});
var autoPublishAll = function () {
var ConstellationDict = Constellation.ConstellationDict;
return ConstellationDict.get('Constellation_autopublish_all');
}
Tracker.autorun(function () {
var TabStates = Constellation.TabStates;
var ConstellationDict = Constellation.ConstellationDict;
var ConstellationAutopublished = ConstellationDict.get('Constellation_autopublished') || [];
var ConstellationNotAutopublished = ConstellationDict.get('Constellation_not_autopublished') || [];
if (autoPublishAll() || (ConstellationAutopublished && ConstellationAutopublished.length)) {
var allCollections = ConstellationDict && ConstellationDict.get('Constellation').collections && _.difference(ConstellationDict.get('Constellation').collections, ConstellationNotAutopublished) || [];
var collections = (autoPublishAll()) ? allCollections : ConstellationAutopublished;
ConstellationDict.set('Constellation_autopublish_subscription_ready', false);
Meteor.subscribe('Constellation_autopublish', _.filter(collections, function (collection) {
return TabStates.get(collection) && Constellation.Collection(collection) && !Constellation.collectionIsLocal(collection);
}), function () {
Tracker.afterFlush(function () {
ConstellationDict.set('Constellation_autopublish_subscription_ready', true);
});
});
}
else {
ConstellationDict.set('Constellation_autopublish_subscription_ready', true);
}
});
Template.Constellation_autopublish.helpers({
autopublish: function () {
return autoPublishAll();
}
});