Adding Dockerfile / removing bower
[tech-radar.git] / src / models / radar.js
1 tr.models.Radar = function() {
2 var self, quadrants, blipNumber;
3
4 blipNumber = 0;
5 quadrants = { I: null, II: null, III: null, IV: null };
6 self = {};
7
8 function setNumbers(blips) {
9 blips.forEach(function (blip) {
10 blip.setNumber(++blipNumber);
11 });
12 }
13
14 self.setFirstQuadrant = function (quadrant) {
15 quadrants.I = quadrant;
16 setNumbers(quadrants.I.blips());
17 };
18
19 self.setSecondQuadrant = function (quadrant) {
20 quadrants.II = quadrant;
21 setNumbers(quadrants.II.blips());
22 };
23
24 self.setThirdQuadrant = function (quadrant) {
25 quadrants.III = quadrant;
26 setNumbers(quadrants.III.blips());
27 };
28
29 self.setFourthQuadrant = function (quadrant) {
30 quadrants.IV = quadrant;
31 setNumbers(quadrants.IV.blips());
32 };
33
34 function allQuadrants() {
35 var all = [];
36
37 for (var p in quadrants) {
38 if (quadrants.hasOwnProperty(p) && quadrants[p] != null) {
39 all.push(quadrants[p]);
40 }
41 }
42
43 return all;
44 }
45
46 function allBlips() {
47 return allQuadrants().reduce(function (blips, quadrant) {
48 return blips.concat(quadrant.blips());
49 }, []);
50 }
51
52 self.hasQuadrants = function () {
53 return !!quadrants.I || !!quadrants.II || !!quadrants.III || !!quadrants.IV;
54 }
55
56 self.cycles = function () {
57 var cycleHash, cycleArray;
58
59 cycleArray = [];
60 cycleHash = {};
61
62 allBlips().forEach(function (blip) {
63 cycleHash[blip.cycle().name()] = blip.cycle();
64 });
65
66 for (var p in cycleHash) {
67 if (cycleHash.hasOwnProperty(p)) {
68 cycleArray.push(cycleHash[p]);
69 }
70 }
71
72 return cycleArray.slice(0).sort(function (a, b) { return a.order() - b.order(); });
73 };
74
75 self.quadrants = function () {
76 return quadrants;
77 };
78
79 return self;
80 };