voluntary 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +1 -1
  4. data/app/assets/javascripts/voluntary/lib/jquery-competitive_list.js +533 -0
  5. data/app/controllers/comments_controller.rb +1 -3
  6. data/app/controllers/concerns/voluntary/v1/base_controller.rb +1 -5
  7. data/app/controllers/home_controller.rb +0 -1
  8. data/app/controllers/workflow/project_owner_controller.rb +17 -15
  9. data/app/controllers/workflow/tasks_controller.rb +1 -1
  10. data/app/models/ability.rb +3 -7
  11. data/app/models/comment.rb +1 -1
  12. data/app/models/product/music_metadata_enrichment.rb +2 -0
  13. data/app/models/product.rb +0 -27
  14. data/app/models/project.rb +0 -1
  15. data/app/models/project_user.rb +2 -3
  16. data/app/models/user.rb +4 -3
  17. data/app/views/layouts/application.html.erb +0 -4
  18. data/app/views/layouts/shared/_flash_messages.html.erb +2 -2
  19. data/app/views/workflow/project_owner/index.html.erb +7 -7
  20. data/config/locales/en.yml +1 -2
  21. data/config/locales/general/en.yml +2 -8
  22. data/config/locales/workflow/en.yml +1 -5
  23. data/config/routes/workflow.rb +0 -25
  24. data/config/routes.rb +0 -35
  25. data/db/migrate/20131018143613_replace_user_by_polymorphic_resource_in_candidatures.rb +4 -4
  26. data/db/migrate/20150802141840_drop_recruiting_unless_recruiting_plugin_present.rb +59 -0
  27. data/lib/generators/voluntary/install/templates/features/support/paths.rb +0 -14
  28. data/lib/generators/voluntary/product_dummy/templates/config/main_navigation.rb +1 -260
  29. data/lib/generators/voluntary/product_dummy/templates/features/step_definitions/comment_steps.rb +1 -1
  30. data/lib/generators/voluntary/product_dummy/templates/features/step_definitions/custom_web_steps.rb +5 -0
  31. data/lib/generators/voluntary/product_dummy/templates/features/support/integration_sessions_controller.rb +1 -1
  32. data/lib/generators/voluntary/product_dummy/templates/features/support/paths.rb +0 -14
  33. data/lib/voluntary/navigation.rb +34 -74
  34. data/lib/voluntary/test/rspec_helpers/factories.rb +10 -17
  35. data/lib/voluntary/version.rb +1 -1
  36. data/lib/voluntary.rb +1 -2
  37. metadata +37 -44
  38. data/app/assets/javascripts/voluntary/lib/competitive_list.js +0 -484
  39. data/app/controllers/candidatures_controller.rb +0 -84
  40. data/app/controllers/vacancies_controller.rb +0 -88
  41. data/app/controllers/workflow/candidatures_controller.rb +0 -20
  42. data/app/controllers/workflow/vacancies_controller.rb +0 -17
  43. data/app/models/candidature.rb +0 -38
  44. data/app/models/state_machines/candidature.rb +0 -64
  45. data/app/models/state_machines/vacancy.rb +0 -49
  46. data/app/models/vacancy.rb +0 -43
  47. data/app/views/candidatures/_form.html.erb +0 -13
  48. data/app/views/candidatures/edit.html.erb +0 -3
  49. data/app/views/candidatures/index.html.erb +0 -11
  50. data/app/views/candidatures/new.html.erb +0 -3
  51. data/app/views/candidatures/show.html.erb +0 -18
  52. data/app/views/vacancies/_form.html.erb +0 -15
  53. data/app/views/vacancies/edit.html.erb +0 -3
  54. data/app/views/vacancies/index.html.erb +0 -7
  55. data/app/views/vacancies/new.html.erb +0 -3
  56. data/app/views/vacancies/show.html.erb +0 -15
  57. data/app/views/workflow/project_owner/_candidatures.html.erb +0 -32
  58. data/app/views/workflow/project_owner/_vacancies.html.erb +0 -27
  59. data/config/locales/resources/candidature/en.yml +0 -19
  60. data/config/locales/resources/vacancy/en.yml +0 -29
  61. data/lib/generators/voluntary/product_dummy/templates/features/step_definitions/candidature_steps.rb +0 -34
  62. data/lib/generators/voluntary/product_dummy/templates/features/step_definitions/vacancy_steps.rb +0 -32
@@ -1,484 +0,0 @@
1
- (function() {
2
- this.CompetitiveList = (function() {
3
- CompetitiveList.prototype.competitiveListOptions = [];
4
-
5
- CompetitiveList.prototype.competitors = [];
6
-
7
- CompetitiveList.prototype.competitorsOfCompetitor = {};
8
-
9
- CompetitiveList.prototype.defeatedCompetitorsByCompetitor = {};
10
-
11
- CompetitiveList.prototype.outmatchedCompetitorsByCompetitor = {};
12
-
13
- CompetitiveList.prototype.matchesLeft = 0;
14
-
15
- CompetitiveList.prototype.currentMatch = null;
16
-
17
- CompetitiveList.prototype.currentMatchIndex = 0;
18
-
19
- CompetitiveList.prototype.currentAutoWinnerMatches = [];
20
-
21
- CompetitiveList.prototype.movingCompetitorToPosition = false;
22
-
23
- function CompetitiveList(options) {
24
- this.competitiveListOptions = options;
25
- this.competitiveListOptions || (this.competitiveListOptions = {});
26
- $(document.body).on("click", this.competitiveListOptions['id'] + " .competitive_list_start_link", (function(_this) {
27
- return function(event) {
28
- event.preventDefault();
29
- return _this.start();
30
- };
31
- })(this));
32
- $(document.body).on("click", this.competitiveListOptions['id'] + " .save_match_results_link", (function(_this) {
33
- return function(event) {
34
- event.preventDefault();
35
- _this.sortByMostWins();
36
- return $(_this.competitiveListOptions['id'] + " .save_match_results_link").hide();
37
- };
38
- })(this));
39
- $(document.body).on("click", this.competitiveListOptions['id'] + "_buttons .cancel_tournament_button", (function(_this) {
40
- return function(event) {
41
- event.preventDefault();
42
- return _this.cancelTournament();
43
- };
44
- })(this));
45
- $(document.body).on("click", this.competitiveListOptions['id'] + "_buttons .select_winner_button", (function(_this) {
46
- return function(event) {
47
- event.preventDefault();
48
- return _this.appointWinnerOfMatchByInput();
49
- };
50
- })(this));
51
- }
52
-
53
- CompetitiveList.meaningOfLife = function() {
54
- return 42;
55
- };
56
-
57
- CompetitiveList.prototype.start = function() {
58
- var matchesAlreadyExist, matchesWithoutWinner;
59
- matchesAlreadyExist = false;
60
- window.matches || (window.matches = []);
61
- if (window.matches.length > 0) {
62
- matchesAlreadyExist = true;
63
- }
64
- this.setCompetitors();
65
- this.competitorsOfCompetitor = {};
66
- this.defeatedCompetitorsByCompetitor = {};
67
- this.outmatchedCompetitorsByCompetitor = {};
68
- if (matchesAlreadyExist) {
69
- if (confirm('Remove previous results and start over?')) {
70
- window.matches = [];
71
- } else {
72
- this.removeMatchesOfNonExistingCompetitors();
73
- }
74
- }
75
- this.generateMatches();
76
- matchesWithoutWinner = jQuery.map(window.matches, function(m) {
77
- if (m['winner'] === void 0) {
78
- return m;
79
- }
80
- });
81
- this.matchesLeft = matchesWithoutWinner.length;
82
- if (this.nextMatch(true)) {
83
- return $('#bootstrap_modal').modal('show');
84
- }
85
- };
86
-
87
- CompetitiveList.prototype.setCompetitors = function() {
88
- return this.competitors = jQuery.map($('.competitive_list li'), function(c) {
89
- return $(c).data('id');
90
- });
91
- };
92
-
93
- CompetitiveList.prototype.removeMatchesOfNonExistingCompetitors = function() {
94
- return $.each(window.matches, (function(_this) {
95
- return function(index, match) {
96
- var base, base1, loserId, name, name1, notExistingCompetitors;
97
- notExistingCompetitors = jQuery.map(match['competitors'], function(c) {
98
- if ($.inArray(c, _this.competitors) === -1) {
99
- return c;
100
- }
101
- });
102
- if (notExistingCompetitors.length > 0) {
103
- return window.matches = _this.removeItemFromArray(window.matches, match);
104
- } else {
105
- (base = _this.competitorsOfCompetitor)[name = match['competitors'][0]] || (base[name] = []);
106
- _this.competitorsOfCompetitor[match['competitors'][0]].push(match['competitors'][1]);
107
- (base1 = _this.competitorsOfCompetitor)[name1 = match['competitors'][1]] || (base1[name1] = []);
108
- _this.competitorsOfCompetitor[match['competitors'][1]].push(match['competitors'][0]);
109
- if (match['winner'] !== void 0) {
110
- loserId = _this.otherCompetitorOfMatch(match, match['winner']);
111
- return _this.updateDefeatedAndOutmatchedCompetitorsByCompetitor(match['winner'], loserId);
112
- }
113
- }
114
- };
115
- })(this));
116
- };
117
-
118
- CompetitiveList.prototype.removeItemFromArray = function(array, item) {
119
- var list;
120
- list = [];
121
- jQuery.each(array, function(index, workingItem) {
122
- if (JSON.stringify(workingItem) !== JSON.stringify(item)) {
123
- return list.push(workingItem);
124
- }
125
- });
126
- return list;
127
- };
128
-
129
- CompetitiveList.prototype.generateMatches = function() {
130
- return $.each(this.competitors, (function(_this) {
131
- return function(index, competitorId) {
132
- var base;
133
- (base = _this.competitorsOfCompetitor)[competitorId] || (base[competitorId] = []);
134
- return $.each(_this.competitors, function(index, otherCompetitorId) {
135
- var base1;
136
- (base1 = _this.competitorsOfCompetitor)[otherCompetitorId] || (base1[otherCompetitorId] = []);
137
- if (competitorId !== otherCompetitorId && $.inArray(otherCompetitorId, _this.competitorsOfCompetitor[competitorId]) === -1) {
138
- window.matches.push({
139
- competitors: [competitorId, otherCompetitorId]
140
- });
141
- _this.competitorsOfCompetitor[competitorId].push(otherCompetitorId);
142
- return _this.competitorsOfCompetitor[otherCompetitorId].push(competitorId);
143
- }
144
- });
145
- };
146
- })(this));
147
- };
148
-
149
- CompetitiveList.prototype.nextMatch = function(from_start) {
150
- var autoWinnerMatchesHtml, competitorStrings, html, i, modalBodyHtml, modalFooterHtml, modalTitle, radioButtons, rows;
151
- autoWinnerMatchesHtml = '';
152
- if (this.currentAutoWinnerMatches.length > 0) {
153
- this.currentMatch = window.matches[this.currentMatchIndex];
154
- rows = "";
155
- $.each(this.currentAutoWinnerMatches, (function(_this) {
156
- return function(index, match) {
157
- var even_or_odd, html, manualWinnerChangedHtml;
158
- even_or_odd = '';
159
- if (index % 2 === 0) {
160
- even_or_odd = 'even';
161
- } else {
162
- even_or_odd = 'odd';
163
- }
164
- manualWinnerChangedHtml = '';
165
- if (match['manual_winner_changed'] === true) {
166
- manualWinnerChangedHtml = "<a class=\"bootstrap_tooltip\" href=\"#\" data-toggle=\"tooltip\" title=\"The winner you once have set has been changed automatically!\">\n <i class='icon-warning-sign'/>\n</a>";
167
- }
168
- return rows += html = "<tr class=\"" + even_or_odd + "\">\n <td>\n " + manualWinnerChangedHtml + "\n </td>\n <td style=\"width:200px\">" + (_this.nameOfCompetitor(match['winner'], false)) + "</td>\n <td><input type=\"radio\" checked=\"checked\" disabled=\"disabled\"/></td>\n <td>&nbsp;&nbsp;VS.&nbsp;&nbsp;&nbsp;</td>\n <td><input type=\"radio\" disabled=\"disabled\"/></td>\n <td>&nbsp;&nbsp;&nbsp;</td>\n <td style=\"width:200px\">" + (_this.nameOfCompetitor(_this.otherCompetitorOfMatch(match, match['winner']), false)) + "</td>\n <td style=\"text-align:center\">\n <a class=\"bootstrap_tooltip\" href=\"#\" data-toggle=\"tooltip\" data-html=\"true\" title=\"" + match['auto_winner_reason'] + "\">\n <i class=\"icon-question-sign\"/>\n </a>\n </td>\n <td style=\"width:200px\">" + (_this.nameOfCompetitor(match['foot_note_competitor'], false)) + "</td>\n</tr> ";
169
- };
170
- })(this));
171
- autoWinnerMatchesHtml = "<h4>Auto Winners due to Result of last Match</h4>\n<table>\n <tr>\n <td><strong>Last Match was:&nbsp;&nbsp;</strong></td>\n <td>" + (this.nameOfCompetitor(this.currentMatch['winner'], false)) + "</td>\n <td>&nbsp;&nbsp;<input type=\"radio\" checked=\"checked\" disabled=\"disabled\"/></td>\n <td>&nbsp;&nbsp;VS.&nbsp;&nbsp;&nbsp;</td>\n <td><input type=\"radio\" disabled=\"disabled\"/></td>\n <td>&nbsp;&nbsp;&nbsp;</td>\n <td>" + (this.nameOfCompetitor(this.otherCompetitorOfMatch(this.currentMatch, this.currentMatch['winner']), false)) + "</td>\n </tr>\n</table>\n<table class=\"table table-striped\">\n <thead>\n <tr class=\"odd\">\n <th></th>\n <th>Winner</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th>Loser</th>\n <th>Reason</th>\n <th>[1]</th>\n </tr>\n </thead>\n <tbody>\n " + rows + "\n </tbody>\n</table> ";
172
- }
173
- this.currentMatch = null;
174
- $.each(window.matches, (function(_this) {
175
- return function(index, match) {
176
- if (match['winner'] === void 0) {
177
- _this.currentMatch = match;
178
- _this.currentMatchIndex = index;
179
- return false;
180
- }
181
- };
182
- })(this));
183
- if (from_start === true && this.currentMatch === null) {
184
- alert('No matches to rate left.');
185
- return false;
186
- } else {
187
- $(this.competitiveListOptions['id'] + " .save_match_results_link").show();
188
- }
189
- modalBodyHtml = '';
190
- modalTitle = '';
191
- modalFooterHtml = '';
192
- if (this.currentMatch === null) {
193
- modalTitle = 'No matches to rate left.';
194
- modalFooterHtml = "<p id=\"" + (this.competitiveListOptions['id'].replace('#', '')) + "_buttons\">\n <button type=\"button\" class=\"cancel_tournament_button\" class=\"btn\">Save match results and close window</button>\n</p> ";
195
- } else {
196
- modalTitle = "Appoint Winner (" + this.matchesLeft + " matches left)";
197
- radioButtons = [];
198
- competitorStrings = [];
199
- i = 0;
200
- $.each(this.currentMatch['competitors'], (function(_this) {
201
- return function(index, competitorId) {
202
- var checked;
203
- checked = ' checked="checked"';
204
- if (i === 1) {
205
- checked = '';
206
- }
207
- radioButtons.push('<input type="radio" ' + checked + ' name="winner" value="' + competitorId + '" style="position:relative; top:-5px "/>');
208
- competitorStrings.push(_this.nameOfCompetitor(competitorId, true));
209
- return i += 1;
210
- };
211
- })(this));
212
- modalBodyHtml += "<div class=\"controls\" style=\"margin-left:50px\">\n <table>\n <tr> \n <td style=\"width:325px; text-align:right;\">\n " + competitorStrings[0] + "\n </td>\n <td>&nbsp;&nbsp;&nbsp;</td>\n <td>" + radioButtons[0] + "</td>\n <td>&nbsp;&nbsp;VS.&nbsp;&nbsp;&nbsp;</td>\n <td>" + radioButtons[1] + "</td>\n <td>\n &nbsp;&nbsp;&nbsp;\n </td>\n <td style=\"width:325px\">\n " + competitorStrings[1] + "\n </td>\n </tr>\n </table>\n</div> ";
213
- modalFooterHtml = "<p id=\"" + (this.competitiveListOptions['id'].replace('#', '')) + "_buttons\">\n <button type=\"button\" class=\"cancel_tournament_button\" class=\"btn\">Save match results and close window</button> &nbsp;&nbsp;&nbsp;&nbsp;\n <button type=\"button\" class=\"select_winner_button\" class=\"btn btn-primary\">Submit</button>\n</p>";
214
- }
215
- modalBodyHtml += autoWinnerMatchesHtml;
216
- html = "<form class=\"form-inline\" style=\"margin:0px;\">\n <div class=\"modal-header\">\n <button type=\"button\" id=\"close_bootstrap_modal_button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">&times;</button>\n <h3>" + modalTitle + "</h3>\n </div>\n <div class=\"modal-body scrollable-modal-body\">\n " + modalBodyHtml + "\n </div>\n <div class=\"modal-footer\" style=\"text-align:left;\">\n " + modalFooterHtml + "\n </div>\n</form>";
217
- $('#bootstrap_modal').html(html);
218
- $('.bootstrap_tooltip').tooltip();
219
- this.currentAutoWinnerMatches = [];
220
- return true;
221
- };
222
-
223
- CompetitiveList.prototype.otherCompetitorOfMatch = function(match, competitorId) {
224
- var otherCompetitors;
225
- otherCompetitors = jQuery.map(match['competitors'], function(c) {
226
- if (c !== competitorId) {
227
- return c;
228
- }
229
- });
230
- return otherCompetitors[0];
231
- };
232
-
233
- CompetitiveList.prototype.nameOfCompetitor = function(competitorId, considerProc) {
234
- var competitorDomElement;
235
- competitorDomElement = $('#competitor_' + competitorId);
236
- if (considerProc === false || this.competitiveListOptions['competitor_name_proc'] === void 0 || $(competitorDomElement).find('.competitor_name').data('proc-argument') === void 0) {
237
- return $(competitorDomElement).find('.competitor_name').html();
238
- } else {
239
- return this.competitiveListOptions['competitor_name_proc']($(competitorDomElement).find('.competitor_name').data('proc-argument'));
240
- }
241
- };
242
-
243
- CompetitiveList.prototype.cancelTournament = function() {
244
- this.sortByMostWins();
245
- $(this.competitiveListOptions['id'] + " .save_match_results_link").hide();
246
- return $('#bootstrap_modal').modal('hide');
247
- };
248
-
249
- CompetitiveList.prototype.appointWinnerOfMatchByInput = function() {
250
- var loserId, winnerId;
251
- winnerId = parseInt($("input[name='winner']:checked").val());
252
- loserId = this.otherCompetitorOfMatch(this.currentMatch, winnerId);
253
- this.appointWinnerOfMatch(this.currentMatchIndex, winnerId, loserId, true);
254
- return this.nextMatch(false);
255
- };
256
-
257
- CompetitiveList.prototype.appointWinnerOfMatch = function(matchIndex, winnerId, loserId, decrementMatchesLeft) {
258
- window.matches[matchIndex]['winner'] = winnerId;
259
- if (decrementMatchesLeft) {
260
- this.matchesLeft = this.matchesLeft - 1;
261
- }
262
- this.updateDefeatedAndOutmatchedCompetitorsByCompetitor(winnerId, loserId);
263
- this.letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser(winnerId, loserId);
264
- return this.letOutMatchedCompetitorsOfWinnerWinAgainstLoser(winnerId, loserId);
265
- };
266
-
267
- CompetitiveList.prototype.updateDefeatedAndOutmatchedCompetitorsByCompetitor = function(winnerId, loserId) {
268
- var base, base1;
269
- (base = this.defeatedCompetitorsByCompetitor)[winnerId] || (base[winnerId] = []);
270
- this.defeatedCompetitorsByCompetitor[winnerId].push(loserId);
271
- (base1 = this.outmatchedCompetitorsByCompetitor)[loserId] || (base1[loserId] = []);
272
- return this.outmatchedCompetitorsByCompetitor[loserId].push(winnerId);
273
- };
274
-
275
- CompetitiveList.prototype.letWinnerWinMatchesAgainstCompetitorsWhichLoseAgainstLoser = function(winnerId, loserId) {
276
- var base;
277
- (base = this.defeatedCompetitorsByCompetitor)[loserId] || (base[loserId] = []);
278
- return $.each(window.matches, (function(_this) {
279
- return function(index, match) {
280
- var manual_winner_changed, matchCompetitorsWhichHaveBeenDefeatedByLoser, otherLoserId;
281
- if (match['winner'] === winnerId || $.inArray(winnerId, match['competitors']) === -1) {
282
- return true;
283
- }
284
- matchCompetitorsWhichHaveBeenDefeatedByLoser = jQuery.map(match['competitors'], function(c) {
285
- if ($.inArray(c, _this.defeatedCompetitorsByCompetitor[loserId]) > -1) {
286
- return c;
287
- }
288
- });
289
- if (matchCompetitorsWhichHaveBeenDefeatedByLoser.length === 0) {
290
- return true;
291
- }
292
- otherLoserId = _this.otherCompetitorOfMatch(match, winnerId);
293
- manual_winner_changed = false;
294
- if (match['winner'] !== void 0) {
295
- _this.removeCompetitorsComparisonResult(winnerId, otherLoserId);
296
- if (!(_this.movingCompetitorToPosition === true || match['auto_winner'] === true)) {
297
- manual_winner_changed = true;
298
- }
299
- }
300
- window.matches[index]['manual_winner_changed'] = manual_winner_changed;
301
- _this.appointWinnerOfMatch(index, winnerId, otherLoserId, match['winner'] === void 0);
302
- if (_this.movingCompetitorToPosition === true) {
303
- return true;
304
- }
305
- window.matches[index]['auto_winner'] = true;
306
- window.matches[index]['foot_note_competitor'] = loserId;
307
- window.matches[index]['auto_winner_type'] = 0;
308
- if (winnerId === _this.currentMatch['winner'] && loserId === _this.otherCompetitorOfMatch(_this.currentMatch, _this.currentMatch['winner'])) {
309
- window.matches[index]['auto_winner_recursion'] = false;
310
- window.matches[index]['auto_winner_reason'] = 'loser has been defeated because he loses against the loser <sup>[1]</sup> of last match';
311
- } else {
312
- window.matches[index]['auto_winner_recursion'] = true;
313
- window.matches[index]['auto_winner_reason'] = 'loser has been defeated because he loses against the loser <sup>[1]</sup> of last auto winner match';
314
- }
315
- return _this.currentAutoWinnerMatches.push(window.matches[index]);
316
- };
317
- })(this));
318
- };
319
-
320
- CompetitiveList.prototype.removeCompetitorsComparisonResult = function(winnerId, loserId) {
321
- var base;
322
- (base = this.outmatchedCompetitorsByCompetitor)[winnerId] || (base[winnerId] = []);
323
- this.outmatchedCompetitorsByCompetitor[winnerId] = this.removeItemFromArray(this.outmatchedCompetitorsByCompetitor[winnerId], loserId);
324
- return this.defeatedCompetitorsByCompetitor[loserId] = this.removeItemFromArray(this.defeatedCompetitorsByCompetitor[loserId], winnerId);
325
- };
326
-
327
- CompetitiveList.prototype.letOutMatchedCompetitorsOfWinnerWinAgainstLoser = function(winnerId, loserId) {
328
- var base;
329
- (base = this.outmatchedCompetitorsByCompetitor)[winnerId] || (base[winnerId] = []);
330
- return $.each(this.outmatchedCompetitorsByCompetitor[winnerId], (function(_this) {
331
- return function(index, competitorId) {
332
- return $.each(window.matches, function(index, match) {
333
- var manual_winner_changed;
334
- if ($.inArray(competitorId, match['competitors']) > -1 && $.inArray(loserId, match['competitors']) > -1 && match['winner'] !== competitorId) {
335
- manual_winner_changed = false;
336
- if (match['winner'] !== void 0) {
337
- _this.removeCompetitorsComparisonResult(competitorId, loserId);
338
- if (!(_this.movingCompetitorToPosition === true || match['auto_winner'] === true)) {
339
- manual_winner_changed = true;
340
- }
341
- }
342
- _this.appointWinnerOfMatch(index, competitorId, loserId, match['winner'] === void 0);
343
- window.matches[index]['manual_winner_changed'] = manual_winner_changed;
344
- if (_this.movingCompetitorToPosition === true) {
345
- return true;
346
- }
347
- window.matches[index]['auto_winner'] = true;
348
- window.matches[index]['auto_winner_type'] = 1;
349
- window.matches[index]['foot_note_competitor'] = winnerId;
350
- if (winnerId === _this.currentMatch['winner'] && loserId === _this.otherCompetitorOfMatch(_this.currentMatch, _this.currentMatch['winner'])) {
351
- window.matches[index]['auto_winner_recursion'] = false;
352
- window.matches[index]['auto_winner_reason'] = "loser of last match has been defeated by outmatched competitor of<br/>winner <sup>[1]</sup>";
353
- } else {
354
- window.matches[index]['auto_winner_recursion'] = true;
355
- window.matches[index]['auto_winner_reason'] = "loser of last auto winner match has been defeated by outmatched competitor of winner <sup>[1]</sup>";
356
- }
357
- _this.currentAutoWinnerMatches.push(match);
358
- return false;
359
- }
360
- });
361
- };
362
- })(this));
363
- };
364
-
365
- CompetitiveList.prototype.moveCompetitorToPosition = function(competitorId, position, after_update_request_proc) {
366
- var defeatedCompetitor, outmatchedCompetitor, positionOfdefeatedCompetitor, positions;
367
- if (after_update_request_proc == null) {
368
- after_update_request_proc = null;
369
- }
370
- this.movingCompetitorToPosition = true;
371
- this.setCompetitors();
372
- this.competitorsOfCompetitor = {};
373
- this.removeMatchesOfNonExistingCompetitors();
374
- this.generateMatches();
375
- positions = this.getPositions();
376
- outmatchedCompetitor = null;
377
- defeatedCompetitor = null;
378
- positionOfdefeatedCompetitor = positions[position] === competitorId ? position + 1 : position;
379
- if (position > Object.keys(positions).length) {
380
- alert('This position is not available!');
381
- if (after_update_request_proc !== null) {
382
- after_update_request_proc();
383
- }
384
- this.movingCompetitorToPosition = false;
385
- return;
386
- }
387
- if (!(position === 1 || (position - 1) > Object.keys(positions).length)) {
388
- outmatchedCompetitor = positions[position - 1];
389
- }
390
- if (!(positionOfdefeatedCompetitor > Object.keys(positions).length)) {
391
- defeatedCompetitor = positions[positionOfdefeatedCompetitor];
392
- }
393
- $.each(window.matches, (function(_this) {
394
- return function(index, match) {
395
- var loserId, otherCompetitorId, winnerId;
396
- if ($.inArray(competitorId, match['competitors']) === -1) {
397
- return true;
398
- }
399
- winnerId = null;
400
- loserId = null;
401
- otherCompetitorId = _this.otherCompetitorOfMatch(match, competitorId);
402
- if (otherCompetitorId === outmatchedCompetitor && match['winner'] !== otherCompetitorId) {
403
- winnerId = otherCompetitorId;
404
- loserId = competitorId;
405
- outmatchedCompetitor = null;
406
- } else if (otherCompetitorId === defeatedCompetitor && match['winner'] !== competitorId) {
407
- winnerId = competitorId;
408
- loserId = otherCompetitorId;
409
- defeatedCompetitor = null;
410
- }
411
- if (winnerId === null) {
412
- return true;
413
- }
414
- if (match['winner'] !== void 0) {
415
- _this.removeCompetitorsComparisonResult(winnerId, loserId);
416
- }
417
- _this.currentMatch = match;
418
- _this.currentMatchIndex = index;
419
- _this.appointWinnerOfMatch(index, winnerId, loserId, false);
420
- if (outmatchedCompetitor === null && defeatedCompetitor === null) {
421
- return false;
422
- }
423
- };
424
- })(this));
425
- this.sortByMostWins(after_update_request_proc);
426
- return this.movingCompetitorToPosition = false;
427
- };
428
-
429
- CompetitiveList.prototype.sortByMostWins = function(after_update_request_proc) {
430
- var $wrapper, data, winsByCompetitor;
431
- if (after_update_request_proc == null) {
432
- after_update_request_proc = null;
433
- }
434
- winsByCompetitor = {};
435
- $.each(this.competitors, (function(_this) {
436
- return function(index, competitorId) {
437
- return winsByCompetitor[competitorId] = 0;
438
- };
439
- })(this));
440
- $.each(window.matches, function(index, match) {
441
- delete window.matches[index]['auto_winner_reason'];
442
- return winsByCompetitor[match['winner']] += 1;
443
- });
444
- $.each(Object.keys(winsByCompetitor), function(index, competitorId) {
445
- return $('#competitor_' + competitorId).data('wins', winsByCompetitor[competitorId]);
446
- });
447
- $wrapper = $('.competitive_list');
448
- $wrapper.find('li').sort(function(a, b) {
449
- return +parseInt($(b).data('wins')) - +parseInt($(a).data('wins'));
450
- }).appendTo($wrapper);
451
- if ($('.competitive_list').data('update-all-positions-path') !== void 0) {
452
- data = {
453
- _method: 'put',
454
- positions: this.getPositions(),
455
- matches: JSON.stringify(window.matches)
456
- };
457
- return $.post($('.competitive_list').data('update-all-positions-path'), data).always((function(_this) {
458
- return function() {
459
- if (after_update_request_proc !== null) {
460
- return after_update_request_proc();
461
- }
462
- };
463
- })(this));
464
- }
465
- };
466
-
467
- CompetitiveList.prototype.getPositions = function() {
468
- var currentPosition, positions;
469
- positions = {};
470
- currentPosition = 1;
471
- $.each($('.competitive_list li'), function(index, element) {
472
- positions[currentPosition] = $(element).data('id');
473
- $(element).data('position', currentPosition);
474
- $(element).find('.competitor_position').html(currentPosition);
475
- return currentPosition += 1;
476
- });
477
- return positions;
478
- };
479
-
480
- return CompetitiveList;
481
-
482
- })();
483
-
484
- }).call(this);
@@ -1,84 +0,0 @@
1
- class CandidaturesController < ApplicationController
2
- include Applicat::Mvc::Controller::Resource
3
-
4
- before_filter :find_candidature, only: [:show, :edit, :update, :destroy]
5
- before_filter :find_vacancy, only: [:index, :new, :edit]
6
-
7
- load_and_authorize_resource
8
-
9
- transition_actions Candidature::EVENTS
10
-
11
- helper_method :parent
12
-
13
- respond_to :html, :js, :json
14
-
15
- def index
16
- @candidatures = if @vacancy
17
- @vacancy.candidatures.includes(:vacancy, :resource)
18
- else
19
- Candidature.includes(:vacancy, :resource).where(resource_type: 'User')
20
- end
21
- end
22
-
23
- def show
24
- @vacancy = @candidature.vacancy
25
- @comments = @candidature.comments
26
- end
27
-
28
- def new
29
- @candidature = Candidature.new
30
- @candidature.vacancy = parent
31
- end
32
-
33
- def create
34
- @candidature = Candidature.new(params[:candidature])
35
- @candidature.resource_type = 'User'
36
- @candidature.resource_id = current_user.id
37
-
38
- if @candidature.save
39
- redirect_to @candidature, notice: t('general.form.successfully_created')
40
- else
41
- render :new
42
- end
43
- end
44
-
45
- def edit
46
- end
47
-
48
- def update
49
- if @candidature.update_attributes(params[:candidature])
50
- redirect_to @candidature, notice: t('general.form.successfully_updated')
51
- else
52
- render :edit
53
- end
54
- end
55
-
56
- def destroy
57
- @candidature.destroy
58
- redirect_to candidatures_url, notice: t('general.form.destroyed')
59
- end
60
-
61
- def resource
62
- @candidature
63
- end
64
-
65
- def parent
66
- @vacancy
67
- end
68
-
69
- protected
70
-
71
- def set_twitter_sidenav_level
72
- @twitter_sidenav_level = 5
73
- end
74
-
75
- private
76
-
77
- def find_candidature
78
- @candidature = Candidature.includes(:vacancy, :resource, :comments).friendly.find(params[:id])
79
- end
80
-
81
- def find_vacancy
82
- @vacancy = params[:vacancy_id].present? ? Vacancy.friendly.find(params[:vacancy_id]) : nil
83
- end
84
- end
@@ -1,88 +0,0 @@
1
- class VacanciesController < ApplicationController
2
- include Applicat::Mvc::Controller::Resource
3
-
4
- before_filter :find_vacancy
5
-
6
- load_and_authorize_resource
7
-
8
- before_filter :find_project, only: [:index, :new, :edit]
9
-
10
- respond_to :html, :js, :json
11
-
12
- def index
13
- @vacancies = @project ? @project.vacancies : Vacancy.all
14
- end
15
-
16
- def show
17
- @comments = @vacancy.comments
18
- end
19
-
20
- def new
21
- @vacancy = Vacancy.new
22
-
23
- @vacancy.project = @project if @project
24
- end
25
-
26
- def create
27
- @vacancy = Vacancy.new(params[:vacancy])
28
-
29
- if @vacancy.project.user_id == current_user.id
30
- @vacancy.do_open
31
- else
32
- @vacancy.author_id = current_user.id
33
- @vacancy.recommend
34
- end
35
-
36
- if @vacancy.save
37
- redirect_to @vacancy, notice: t('general.form.successfully_created')
38
- else
39
- render :new
40
- end
41
- end
42
-
43
- def edit
44
- @vacancy = Vacancy.friendly.find(params[:id])
45
- end
46
-
47
- def update
48
- @vacancy = Vacancy.friendly.find(params[:id])
49
-
50
- if @vacancy.update_attributes(params[:vacancy])
51
- redirect_to @vacancy, notice: t('general.form.successfully_updated')
52
- else
53
- render :edit
54
- end
55
- end
56
-
57
- def destroy
58
- @vacancy = Vacancy.friendly.find(params[:id])
59
- @vacancy.destroy
60
- redirect_to vacancies_url, notice: t('general.form.destroyed')
61
- end
62
-
63
- def resource
64
- @vacancy
65
- end
66
-
67
- transition_actions Vacancy::EVENTS
68
-
69
- protected
70
-
71
- def before_my_state
72
- # e.g. set attributes of resource
73
- end
74
-
75
- private
76
-
77
- def find_vacancy
78
- return unless params[:id].present?
79
-
80
- @vacancy = Vacancy
81
- @vacancy = @vacancy.includes(:project, :candidatures, :comments) if action_name == 'show'
82
- @vacancy = @vacancy.friendly.find(params[:id])
83
- end
84
-
85
- def find_project
86
- @project = params[:project_id].present? ? Project.friendly.find(params[:project_id]) : nil
87
- end
88
- end
@@ -1,20 +0,0 @@
1
- class Workflow::CandidaturesController < ApplicationController
2
- def new
3
- state_action
4
- end
5
-
6
- def accepted
7
- state_action
8
- end
9
-
10
- def denied
11
- state_action
12
- end
13
-
14
- private
15
-
16
- def state_action
17
- @candidatures = current_user.offeror_candidatures.where(state: action_name).includes(:vacancy, :resource)
18
- render 'candidatures/index'
19
- end
20
- end