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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
let previousPath;
FlowRouter.triggers.exit([({path}) => {
previousPath = path;
}]);
FlowRouter.route('/', {
name: 'home',
triggersEnter: [AccountsTemplates.ensureSignedIn],
action() {
Session.set('currentBoard', null);
Session.set('currentCard', null);
Filter.reset();
EscapeActions.executeAll();
BlazeLayout.render('defaultLayout', {
headerBar: 'boardListHeaderBar',
content: 'boardList',
});
},
});
FlowRouter.route('/b/:id/:slug', {
name: 'board',
action(params) {
const currentBoard = params.id;
const previousBoard = Session.get('currentBoard');
Session.set('currentBoard', currentBoard);
Session.set('currentCard', null);
// If we close a card, we'll execute again this route action but we don't
// want to excape every current actions (filters, etc.)
if (previousBoard !== currentBoard) {
EscapeActions.executeAll();
} else {
EscapeActions.executeUpTo('popup-close');
}
BlazeLayout.render('defaultLayout', {
headerBar: 'boardHeaderBar',
content: 'board',
});
},
});
FlowRouter.route('/b/:boardId/:slug/:cardId', {
name: 'card',
action(params) {
EscapeActions.executeUpTo('inlinedForm');
Session.set('currentBoard', params.boardId);
Session.set('currentCard', params.cardId);
BlazeLayout.render('defaultLayout', {
headerBar: 'boardHeaderBar',
content: 'board',
});
},
});
FlowRouter.route('/shortcuts', {
name: 'shortcuts',
action() {
const shortcutsTemplate = 'keyboardShortcuts';
EscapeActions.executeUpTo('popup-close');
if (previousPath) {
Modal.open(shortcutsTemplate, {
header: 'shortcutsModalTitle',
onCloseGoTo: previousPath,
});
} else {
BlazeLayout.render('defaultLayout', {
headerBar: 'shortcutsHeaderBar',
content: shortcutsTemplate,
});
}
},
});
FlowRouter.route('/import', {
name: 'import',
triggersEnter: [
AccountsTemplates.ensureSignedIn,
() => {
Session.set('currentBoard', null);
Session.set('currentCard', null);
Filter.reset();
EscapeActions.executeAll();
},
],
action() {
BlazeLayout.render('defaultLayout', {
headerBar: 'importHeaderBar',
content: 'import',
});
},
});
FlowRouter.notFound = {
action() {
BlazeLayout.render('defaultLayout', { content: 'notFound' });
},
};
// We maintain a list of redirections to ensure that we don't break old URLs
// when we change our routing scheme.
const redirections = {
'/boards': '/',
'/boards/:id/:slug': '/b/:id/:slug',
'/boards/:id/:slug/:cardId': '/b/:id/:slug/:cardId',
};
_.each(redirections, (newPath, oldPath) => {
FlowRouter.route(oldPath, {
triggersEnter: [(context, redirect) => {
redirect(FlowRouter.path(newPath, context.params));
}],
});
});
// As it is not possible to use template helpers in the page <head> we create a
// reactive function whose role is to set any page-specific tag in the <head>
// using the `kadira:dochead` package. Currently we only use it to display the
// board title if we are in a board page (see #364) but we may want to support
// some <meta> tags in the future.
const appTitle = 'Wekan';
// XXX The `Meteor.startup` should not be necessary -- we don't need to wait for
// the complete DOM to be ready to call `DocHead.setTitle`. But the problem is
// that the global variable `Boards` is undefined when this file loads so we
// wait a bit until hopefully all files are loaded. This will be fixed in a
// clean way once Meteor will support ES6 modules -- hopefully in Meteor 1.3.
Meteor.isClient && Meteor.startup(() => {
Tracker.autorun(() => {
const currentBoard = Boards.findOne(Session.get('currentBoard'));
const titleStack = [appTitle];
if (currentBoard) {
titleStack.push(currentBoard.title);
}
DocHead.setTitle(titleStack.reverse().join(' - '));
});
});
|