From f683ee441aff6edeadd31bbaafdf74ffdaa07e43 Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Sat, 1 Dec 2018 12:38:22 +0200
Subject: [PATCH 01/12] refactor(mock-team-matches): Method now gets the things
 to generate from outside

---
 server/routers/matchTeam_router.js | 60 +++++++++++++-----------------
 1 file changed, 26 insertions(+), 34 deletions(-)

diff --git a/server/routers/matchTeam_router.js b/server/routers/matchTeam_router.js
index 2e4c061..b6fb3bb 100644
--- a/server/routers/matchTeam_router.js
+++ b/server/routers/matchTeam_router.js
@@ -1,18 +1,30 @@
 'use strict'
 const express = require('express')
+
 const db = require('../utilities/mongo_connection')
+
 const MsLogger = require('@first-lego-league/ms-logger').Logger()
 
 const RANDOM_ID_LENGTH = 25
+const stages = [
+  {
+    stageName: 'practice',
+    matchAmount: 1
+  },
+  {
+    stageName: 'ranking',
+    matchAmount: 3
+  }
+]
 
 exports.getRouter = function () {
   const router = express.Router()
 
   router.get('/:team/matches', (req, res) => {
     db.connection().then(connection => {
-      connection.db().collection('matches').find({ 'matchTeams.teamNumber': parseInt(req.params.team) }).toArray().then(data => {
+      connection.db().collection('matches').find({'matchTeams.teamNumber': parseInt(req.params.team)}).toArray().then(data => {
         if (!data || data.length === 0) {
-          res.send(getDefaultMatchesForTeam(parseInt(req.params.team)))
+          res.send(getDefaultMatchesForTeam(parseInt(req.params.team), stages))
           return
         }
 
@@ -28,41 +40,21 @@ exports.getRouter = function () {
   return router
 }
 
-function getDefaultMatchesForTeam (teamNumber) {
-  const practice = {
-    '_id': createRandomId(RANDOM_ID_LENGTH),
-    'matchId': 1,
-    'stage': 'practice',
-    'matchTeams': [
-      {
-        'teamNumber': teamNumber,
-        'tableId': null
-      }
-    ]
-  }
+function getDefaultMatchesForTeam (teamNumber, stages) {
+  const matches = []
 
-  const ranking = {
-    '_id': createRandomId(RANDOM_ID_LENGTH),
-    'matchId': 1,
-    'stage': 'ranking',
-    'matchTeams': [
-      {
+  for (const stage in stages) {
+    for (let i = 1; i <= stages[stage].matchAmount; i++) {
+      const match = {}
+      match._id = createRandomId(RANDOM_ID_LENGTH)
+      match.stage = stages[stage].stageName
+      match.matchId = i
+      match.matchTeams = [{
         'teamNumber': teamNumber,
         'tableId': null
-      }
-    ]
-  }
-
-  let matches = []
-  matches.push(practice)
-
-  for (let i = 1; i <= 3; i++) {
-    let match = {}
-    match._id = createRandomId(RANDOM_ID_LENGTH)
-    match.matchId = i
-    match.stage = ranking.stage
-    match.matchTeams = ranking.matchTeams
-    matches.push(match)
+      }]
+      matches.push(match)
+    }
   }
 
   return matches

From 29ca203f5ff477fca0e8d46b64833083c2f11087 Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Sat, 1 Dec 2018 15:39:16 +0200
Subject: [PATCH 02/12] feat(configure-amount-of-matches): Added settings for
 amount of matches

---
 server/logic/settings_logic.js | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/server/logic/settings_logic.js b/server/logic/settings_logic.js
index 5c14426..5c59ba8 100644
--- a/server/logic/settings_logic.js
+++ b/server/logic/settings_logic.js
@@ -8,11 +8,27 @@ const SETTING_COLLECTION_NAME = 'settings'
 function setDefaultSettings () {
   const defaultSettings = {
     'tournamentStage': 'practice',
-    'tournamentTitle': 'World Festival Houston 2019'
+    'tournamentTitle': 'World Festival Houston 2019',
+    'practiceAmountOfMatches': 1,
+    'rankingAmountOfMatches': 3
   }
+
   db.connection().then(connection => {
-    connection.db().collection(SETTING_COLLECTION_NAME).findOne().then(response => {
-      if (!response) {
+    connection.db().collection(SETTING_COLLECTION_NAME).find({}).toArray().then(response => {
+      const promises = []
+      if (response.length > 0) {
+        response = response[0]
+        for (const setting of Object.keys(defaultSettings)) {
+          if (!response[setting]) {
+            const toSet = {}
+            toSet[setting] = defaultSettings[setting]
+            promises.push(connection.db().collection(SETTING_COLLECTION_NAME).updateOne({}, {
+              $set: toSet
+            }))
+          }
+        }
+        return Promise.all(promises)
+      } else {
         return connection.db().collection(SETTING_COLLECTION_NAME).insert(defaultSettings)
       }
     })

From a75a6927f3a272591c11bfa008e7967ea53c74b0 Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Sat, 1 Dec 2018 18:58:50 +0200
Subject: [PATCH 03/12] feat(configure-amount-of-matches): Amount of matches is
 now calculated based on the settings

---
 server/routers/matchTeam_router.js | 39 ++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/server/routers/matchTeam_router.js b/server/routers/matchTeam_router.js
index b6fb3bb..60ced9b 100644
--- a/server/routers/matchTeam_router.js
+++ b/server/routers/matchTeam_router.js
@@ -2,20 +2,11 @@
 const express = require('express')
 
 const db = require('../utilities/mongo_connection')
+const settings = require('../logic/settings_logic')
 
 const MsLogger = require('@first-lego-league/ms-logger').Logger()
 
 const RANDOM_ID_LENGTH = 25
-const stages = [
-  {
-    stageName: 'practice',
-    matchAmount: 1
-  },
-  {
-    stageName: 'ranking',
-    matchAmount: 3
-  }
-]
 
 exports.getRouter = function () {
   const router = express.Router()
@@ -24,10 +15,10 @@ exports.getRouter = function () {
     db.connection().then(connection => {
       connection.db().collection('matches').find({'matchTeams.teamNumber': parseInt(req.params.team)}).toArray().then(data => {
         if (!data || data.length === 0) {
-          res.send(getDefaultMatchesForTeam(parseInt(req.params.team), stages))
-          return
+          return getDefaultStages().then(stages => {
+            res.send(getDefaultMatchesForTeam(parseInt(req.params.team), stages))
+          })
         }
-
         res.send(data)
       })
     }).catch(err => {
@@ -60,6 +51,28 @@ function getDefaultMatchesForTeam (teamNumber, stages) {
   return matches
 }
 
+function getDefaultStages () {
+  const stages = [
+    {
+      stageName: 'practice',
+      matchAmount: 1
+    },
+    {
+      stageName: 'ranking',
+      matchAmount: 3
+    }
+  ]
+
+  let practice = settings.getSetting('practiceAmountOfMatches')
+  let ranking = settings.getSetting('rankingAmountOfMatches')
+
+  return Promise.all([practice, ranking]).then(data => {
+    stages.filter(x => x.stageName == 'practice')[0].matchAmount = data[0]
+    stages.filter(x => x.stageName == 'ranking')[0].matchAmount = data[1]
+    return stages
+  })
+}
+
 function createRandomId (length) {
   let text = ''
   const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'

From 8915ddb8b57950cd327cf2cf669eee9c25d041d3 Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Sat, 1 Dec 2018 19:19:05 +0200
Subject: [PATCH 04/12] feat(configure-amount-of-matches): Added ui to the
 amount of matches settings

---
 .../tournament-settings.component.html        | 61 +++++++++++++------
 .../tournament-settings.component.ts          | 12 +++-
 2 files changed, 53 insertions(+), 20 deletions(-)

diff --git a/client/app/pages/tournament-settings/tournament-settings.component.html b/client/app/pages/tournament-settings/tournament-settings.component.html
index a4f1fb0..e0427fe 100644
--- a/client/app/pages/tournament-settings/tournament-settings.component.html
+++ b/client/app/pages/tournament-settings/tournament-settings.component.html
@@ -10,27 +10,48 @@ <h3>Settings</h3>
             <div *ngIf="!loading">
                 <fieldset class="fieldset">
                     <legend>Tournament</legend>
-                    <h5>{{settings['tournamentStage'].display}}</h5>
-                    <div class="input-group">
-                        <select class="input-group-field" [(ngModel)]="settings['tournamentStage'].value"
-                                [disabled]="settings['tournamentStage'].options == undefined">
-                            <option *ngFor="let option of settings['tournamentStage'].options" value="{{option}}">
-                                {{option}}
-                            </option>
-                        </select>
-                        <div class="input-group-button">
-                            <button class="button" (click)="save('tournamentStage')"
-                                    [disabled]="settings['tournamentStage'].options == undefined"><i
-                                    class="fa fa-save"></i>&nbsp; Save
+                    <div class="grid-x grid-margin-x">
+                        <div class="cell medium-6">
+                            <h5>{{settings['tournamentStage'].display}}</h5>
+                            <div class="input-group">
+                                <select class="input-group-field" [(ngModel)]="settings['tournamentStage'].value"
+                                        [disabled]="settings['tournamentStage'].options == undefined">
+                                    <option *ngFor="let option of settings['tournamentStage'].options"
+                                            value="{{option}}">
+                                        {{option}}
+                                    </option>
+                                </select>
+                                <div class="input-group-button">
+                                    <button class="button" (click)="save('tournamentStage')"
+                                            [disabled]="settings['tournamentStage'].options == undefined"><i
+                                            class="fa fa-save"></i>&nbsp; Save
+                                    </button>
+                                </div>
+                            </div>
+
+                            <h5>Delete Tournament Data</h5>
+                            <label>Press Delete to delete Teams and Matches. <br/> Note: You must first delete all
+                                scoring data.</label>
+                            <button class="button alert" data-open="model-delete"
+                                    (click)="setDeleteModel(tournamentDataService)" [disabled]="!hasDataInDb">Delete
                             </button>
                         </div>
-                    </div>
+                        <div class="cell medium-6">
+                            <h5>Number of rounds</h5>
+                            <label>
+                                Set the default number of rounds.
+                                <br>
+                                This setting is used when you import a partial schedule file or a team list.
+                            </label>
 
-                    <h5>Delete Tournament Data</h5>
-                    <label>Press Delete to delete Teams and Matches. <br/> Note: You must first delete all scoring data.</label>
-                    <button class="button alert" data-open="model-delete"
-                            (click)="setDeleteModel(tournamentDataService)" [disabled]="!hasDataInDb">Delete
-                    </button>
+                            {{settings['practiceAmountOfMatches'].display}}
+                            <input type="number" [(ngModel)]="settings['practiceAmountOfMatches'].value" >
+                            {{settings['rankingAmountOfMatches'].display}}
+                            <input type="number" [(ngModel)]="settings['rankingAmountOfMatches'].value" >
+
+                            <button class="button" (click)="save('practiceAmountOfMatches'); save('rankingAmountOfMatches')" [disabled]=""><i class="fa fa-save"></i>&nbsp; Save</button>
+                        </div>
+                    </div>
                 </fieldset>
 
                 <fieldset class="fieldset">
@@ -39,7 +60,9 @@ <h5>{{settings['tournamentTitle'].display}}</h5>
                     <div class="input-group">
                         <input type="text" [(ngModel)]="settings['tournamentTitle'].value" class="input-group-field">
                         <div class="input-group-button">
-                            <button class="button" (click)="save('tournamentTitle')"><i class="fa fa-save"></i>&nbsp; Save</button>
+                            <button class="button" (click)="save('tournamentTitle')"><i class="fa fa-save"></i>&nbsp;
+                                Save
+                            </button>
                         </div>
                     </div>
                 </fieldset>
diff --git a/client/app/pages/tournament-settings/tournament-settings.component.ts b/client/app/pages/tournament-settings/tournament-settings.component.ts
index c688f5c..f2256b8 100644
--- a/client/app/pages/tournament-settings/tournament-settings.component.ts
+++ b/client/app/pages/tournament-settings/tournament-settings.component.ts
@@ -43,6 +43,16 @@ export class TournamentSettingsComponent implements OnInit {
                         display: 'Stage',
                         value: settings['tournamentStage'],
                         name: 'tournamentStage'
+                    },
+                    practiceAmountOfMatches: {
+                        display: 'Amount of practice rounds',
+                        value: settings['practiceAmountOfMatches'],
+                        name: 'practiceAmountOfMatches'
+                    },
+                    rankingAmountOfMatches: {
+                        display: 'Amount of ranking rounds',
+                        value: settings['rankingAmountOfMatches'],
+                        name: 'rankingAmountOfMatches'
                     }
                 }
                 this.tournamentSettingsService.getStages().subscribe(
@@ -66,7 +76,7 @@ export class TournamentSettingsComponent implements OnInit {
         this.tournamentSettingsService.saveSetting(setting, this.settings[setting].value).subscribe(
             response => {
                 this.loading = false;
-                this.notification.success("Setting saved successfully")
+                this.notification.success(`${this.settings[setting].display} saved successfully`)
             },
             err => {
                 this.notification.error("Oh no! Something went wrong while trying to save...")

From ce771b0c42c906e00e9ed9a3def8fad16a7d6d70 Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Wed, 5 Dec 2018 20:51:47 +0200
Subject: [PATCH 05/12] feat(configure-amount-of-matches): Changed keys name

---
 .../tournament-settings.component.html               | 10 +++++-----
 .../tournament-settings.component.ts                 | 12 ++++++------
 server/logic/settings_logic.js                       |  4 ++--
 server/routers/matchTeam_router.js                   |  4 ++--
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/client/app/pages/tournament-settings/tournament-settings.component.html b/client/app/pages/tournament-settings/tournament-settings.component.html
index e0427fe..6336fe6 100644
--- a/client/app/pages/tournament-settings/tournament-settings.component.html
+++ b/client/app/pages/tournament-settings/tournament-settings.component.html
@@ -44,12 +44,12 @@ <h5>Number of rounds</h5>
                                 This setting is used when you import a partial schedule file or a team list.
                             </label>
 
-                            {{settings['practiceAmountOfMatches'].display}}
-                            <input type="number" [(ngModel)]="settings['practiceAmountOfMatches'].value" >
-                            {{settings['rankingAmountOfMatches'].display}}
-                            <input type="number" [(ngModel)]="settings['rankingAmountOfMatches'].value" >
+                            {{settings['numberOfPracticeRounds'].display}}
+                            <input type="number" [(ngModel)]="settings['numberOfPracticeRounds'].value" >
+                            {{settings['numberOfRankingRounds'].display}}
+                            <input type="number" [(ngModel)]="settings['numberOfRankingRounds'].value" >
 
-                            <button class="button" (click)="save('practiceAmountOfMatches'); save('rankingAmountOfMatches')" [disabled]=""><i class="fa fa-save"></i>&nbsp; Save</button>
+                            <button class="button" (click)="save('numberOfPracticeRounds'); save('numberOfRankingRounds')" [disabled]=""><i class="fa fa-save"></i>&nbsp; Save</button>
                         </div>
                     </div>
                 </fieldset>
diff --git a/client/app/pages/tournament-settings/tournament-settings.component.ts b/client/app/pages/tournament-settings/tournament-settings.component.ts
index f2256b8..65c1f83 100644
--- a/client/app/pages/tournament-settings/tournament-settings.component.ts
+++ b/client/app/pages/tournament-settings/tournament-settings.component.ts
@@ -44,15 +44,15 @@ export class TournamentSettingsComponent implements OnInit {
                         value: settings['tournamentStage'],
                         name: 'tournamentStage'
                     },
-                    practiceAmountOfMatches: {
+                    numberOfPracticeRounds: {
                         display: 'Amount of practice rounds',
-                        value: settings['practiceAmountOfMatches'],
-                        name: 'practiceAmountOfMatches'
+                        value: settings['numberOfPracticeRounds'],
+                        name: 'numberOfPracticeRounds'
                     },
-                    rankingAmountOfMatches: {
+                    numberOfRankingRounds: {
                         display: 'Amount of ranking rounds',
-                        value: settings['rankingAmountOfMatches'],
-                        name: 'rankingAmountOfMatches'
+                        value: settings['numberOfRankingRounds'],
+                        name: 'numberOfRankingRounds'
                     }
                 }
                 this.tournamentSettingsService.getStages().subscribe(
diff --git a/server/logic/settings_logic.js b/server/logic/settings_logic.js
index 5c59ba8..9dbc171 100644
--- a/server/logic/settings_logic.js
+++ b/server/logic/settings_logic.js
@@ -9,8 +9,8 @@ function setDefaultSettings () {
   const defaultSettings = {
     'tournamentStage': 'practice',
     'tournamentTitle': 'World Festival Houston 2019',
-    'practiceAmountOfMatches': 1,
-    'rankingAmountOfMatches': 3
+    'numberOfPracticeRounds': 1,
+    'numberOfRankingRounds': 3
   }
 
   db.connection().then(connection => {
diff --git a/server/routers/matchTeam_router.js b/server/routers/matchTeam_router.js
index 60ced9b..984accf 100644
--- a/server/routers/matchTeam_router.js
+++ b/server/routers/matchTeam_router.js
@@ -63,8 +63,8 @@ function getDefaultStages () {
     }
   ]
 
-  let practice = settings.getSetting('practiceAmountOfMatches')
-  let ranking = settings.getSetting('rankingAmountOfMatches')
+  let practice = settings.getSetting('numberOfPracticeRounds')
+  let ranking = settings.getSetting('numberOfRankingRounds')
 
   return Promise.all([practice, ranking]).then(data => {
     stages.filter(x => x.stageName == 'practice')[0].matchAmount = data[0]

From 9588d33ced2660050ef263d4ee207307cfbca3b4 Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Wed, 5 Dec 2018 20:53:13 +0200
Subject: [PATCH 06/12] feat(configure-amount-of-matches): Searching for
 setting with find one

---
 server/logic/settings_logic.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/logic/settings_logic.js b/server/logic/settings_logic.js
index 9dbc171..9f9372c 100644
--- a/server/logic/settings_logic.js
+++ b/server/logic/settings_logic.js
@@ -14,7 +14,7 @@ function setDefaultSettings () {
   }
 
   db.connection().then(connection => {
-    connection.db().collection(SETTING_COLLECTION_NAME).find({}).toArray().then(response => {
+    connection.db().collection(SETTING_COLLECTION_NAME).findOne({}).then(response => {
       const promises = []
       if (response.length > 0) {
         response = response[0]

From 37ba2160ae9d6f99d1847c07eac7d210ed3e459a Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Wed, 5 Dec 2018 20:55:17 +0200
Subject: [PATCH 07/12] feat(configure-amount-of-matches): Searching for
 setting with find one

---
 server/logic/settings_logic.js | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/server/logic/settings_logic.js b/server/logic/settings_logic.js
index 9f9372c..d0a3467 100644
--- a/server/logic/settings_logic.js
+++ b/server/logic/settings_logic.js
@@ -16,8 +16,7 @@ function setDefaultSettings () {
   db.connection().then(connection => {
     connection.db().collection(SETTING_COLLECTION_NAME).findOne({}).then(response => {
       const promises = []
-      if (response.length > 0) {
-        response = response[0]
+      if (response) {
         for (const setting of Object.keys(defaultSettings)) {
           if (!response[setting]) {
             const toSet = {}

From ce0ffcda325fcab52355893176ae79c8aa174548 Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Wed, 5 Dec 2018 20:57:34 +0200
Subject: [PATCH 08/12] feat(configure-amount-of-matches): removed promises
 names

---
 server/routers/matchTeam_router.js | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/server/routers/matchTeam_router.js b/server/routers/matchTeam_router.js
index 984accf..b556ec3 100644
--- a/server/routers/matchTeam_router.js
+++ b/server/routers/matchTeam_router.js
@@ -13,7 +13,7 @@ exports.getRouter = function () {
 
   router.get('/:team/matches', (req, res) => {
     db.connection().then(connection => {
-      connection.db().collection('matches').find({'matchTeams.teamNumber': parseInt(req.params.team)}).toArray().then(data => {
+      connection.db().collection('matches').find({ 'matchTeams.teamNumber': parseInt(req.params.team) }).toArray().then(data => {
         if (!data || data.length === 0) {
           return getDefaultStages().then(stages => {
             res.send(getDefaultMatchesForTeam(parseInt(req.params.team), stages))
@@ -63,14 +63,13 @@ function getDefaultStages () {
     }
   ]
 
-  let practice = settings.getSetting('numberOfPracticeRounds')
-  let ranking = settings.getSetting('numberOfRankingRounds')
-
-  return Promise.all([practice, ranking]).then(data => {
-    stages.filter(x => x.stageName == 'practice')[0].matchAmount = data[0]
-    stages.filter(x => x.stageName == 'ranking')[0].matchAmount = data[1]
-    return stages
-  })
+  return Promise.all([settings.getSetting('numberOfPracticeRounds'),
+    settings.getSetting('numberOfRankingRounds')])
+    .then(data => {
+      stages.filter(x => x.stageName == 'practice')[0].matchAmount = data[0]
+      stages.filter(x => x.stageName == 'ranking')[0].matchAmount = data[1]
+      return stages
+    })
 }
 
 function createRandomId (length) {

From 1a290e0e4a7a893dacd74a9a00242f85f04dc700 Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Wed, 5 Dec 2018 21:00:04 +0200
Subject: [PATCH 09/12] feat(configure-amount-of-matches): Changed text in UI

---
 .../tournament-settings/tournament-settings.component.html    | 4 +---
 .../tournament-settings/tournament-settings.component.ts      | 4 ++--
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/client/app/pages/tournament-settings/tournament-settings.component.html b/client/app/pages/tournament-settings/tournament-settings.component.html
index 6336fe6..902f120 100644
--- a/client/app/pages/tournament-settings/tournament-settings.component.html
+++ b/client/app/pages/tournament-settings/tournament-settings.component.html
@@ -37,10 +37,8 @@ <h5>Delete Tournament Data</h5>
                             </button>
                         </div>
                         <div class="cell medium-6">
-                            <h5>Number of rounds</h5>
+                            <h5>Number of rounds per stage</h5>
                             <label>
-                                Set the default number of rounds.
-                                <br>
                                 This setting is used when you import a partial schedule file or a team list.
                             </label>
 
diff --git a/client/app/pages/tournament-settings/tournament-settings.component.ts b/client/app/pages/tournament-settings/tournament-settings.component.ts
index 65c1f83..753640a 100644
--- a/client/app/pages/tournament-settings/tournament-settings.component.ts
+++ b/client/app/pages/tournament-settings/tournament-settings.component.ts
@@ -45,12 +45,12 @@ export class TournamentSettingsComponent implements OnInit {
                         name: 'tournamentStage'
                     },
                     numberOfPracticeRounds: {
-                        display: 'Amount of practice rounds',
+                        display: 'Practice rounds',
                         value: settings['numberOfPracticeRounds'],
                         name: 'numberOfPracticeRounds'
                     },
                     numberOfRankingRounds: {
-                        display: 'Amount of ranking rounds',
+                        display: 'Ranking rounds',
                         value: settings['numberOfRankingRounds'],
                         name: 'numberOfRankingRounds'
                     }

From 82fe88abea8d2c8a755c2355622a8e4231dd0205 Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Wed, 5 Dec 2018 21:10:31 +0200
Subject: [PATCH 10/12] feat(configure-amount-of-matches): Client validation
 for amount of rounds

---
 .../tournament-settings.component.html        |  6 ++--
 .../tournament-settings.component.ts          | 35 ++++++++++++++++---
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/client/app/pages/tournament-settings/tournament-settings.component.html b/client/app/pages/tournament-settings/tournament-settings.component.html
index 902f120..e03f70d 100644
--- a/client/app/pages/tournament-settings/tournament-settings.component.html
+++ b/client/app/pages/tournament-settings/tournament-settings.component.html
@@ -43,11 +43,11 @@ <h5>Number of rounds per stage</h5>
                             </label>
 
                             {{settings['numberOfPracticeRounds'].display}}
-                            <input type="number" [(ngModel)]="settings['numberOfPracticeRounds'].value" >
+                            <input type="number" [(ngModel)]="settings['numberOfPracticeRounds'].value" min="{{MIN_AMOUNT_OF_ROUNDS}}" max="{{MAX_AMOUNT_OF_ROUNDS}}">
                             {{settings['numberOfRankingRounds'].display}}
-                            <input type="number" [(ngModel)]="settings['numberOfRankingRounds'].value" >
+                            <input type="number" [(ngModel)]="settings['numberOfRankingRounds'].value" min="{{MIN_AMOUNT_OF_ROUNDS}}" max="{{MAX_AMOUNT_OF_ROUNDS}}">
 
-                            <button class="button" (click)="save('numberOfPracticeRounds'); save('numberOfRankingRounds')" [disabled]=""><i class="fa fa-save"></i>&nbsp; Save</button>
+                            <button class="button" (click)="saveNumberOFRounds()" [disabled]=""><i class="fa fa-save"></i>&nbsp; Save</button>
                         </div>
                     </div>
                 </fieldset>
diff --git a/client/app/pages/tournament-settings/tournament-settings.component.ts b/client/app/pages/tournament-settings/tournament-settings.component.ts
index 753640a..ea87d1a 100644
--- a/client/app/pages/tournament-settings/tournament-settings.component.ts
+++ b/client/app/pages/tournament-settings/tournament-settings.component.ts
@@ -4,6 +4,7 @@ import {Notifications} from "../../shared/services/notifications.service";
 import {st} from "../../../../node_modules/@angular/core/src/render3";
 import {DeleteService} from "../../shared/services/delete-service.service";
 import {TournamentDataService} from "../../shared/services/tournament-data.service";
+import {forkJoin} from "rxjs";
 
 @Component({
     selector: 'app-tournament-settings',
@@ -16,6 +17,9 @@ export class TournamentSettingsComponent implements OnInit {
     public loading: boolean = true;
     public hasDataInDb = false;
 
+    public MIN_AMOUNT_OF_ROUNDS = 0;
+    public MAX_AMOUNT_OF_ROUNDS = 5
+
     constructor(private tournamentSettingsService: TournamentSettingsService,
                 public tournamentDataService: TournamentDataService,
                 private notification: Notifications,
@@ -24,7 +28,7 @@ export class TournamentSettingsComponent implements OnInit {
 
     ngOnInit() {
         this.reload();
-        this.tournamentDataService.dataReload.subscribe(()=>{
+        this.tournamentDataService.dataReload.subscribe(() => {
             this.reload()
         })
     }
@@ -83,12 +87,35 @@ export class TournamentSettingsComponent implements OnInit {
             })
     }
 
-    setDeleteModel(model){
+    saveNumberOFRounds() {
+        if (this.doesValueBetween(this.settings['numberOfPracticeRounds'].value, this.MIN_AMOUNT_OF_ROUNDS, this.MAX_AMOUNT_OF_ROUNDS) &&
+            this.doesValueBetween(this.settings['numberOfRankingRounds'].value, this.MIN_AMOUNT_OF_ROUNDS, this.MAX_AMOUNT_OF_ROUNDS)) {
+            forkJoin(this.tournamentSettingsService.saveSetting('numberOfPracticeRounds', this.settings['numberOfPracticeRounds'].value),
+                     this.tournamentSettingsService.saveSetting('numberOfRankingRounds', this.settings['numberOfRankingRounds'].value))
+                .subscribe(
+                    response => {
+                        this.notification.success(`Number of rounds saved successfully`)
+                    },
+                    error => {
+                        this.notification.error("Oh no! Something went wrong while trying to save number of rounds")
+                    }
+                )
+        } else {
+            this.notification.error(`Number of round per stage need to be between ${this.MIN_AMOUNT_OF_ROUNDS} and ${this.MAX_AMOUNT_OF_ROUNDS}`)
+        }
+
+    }
+
+    doesValueBetween(value, min, max) {
+        return value >= min && value <= max;
+    }
+
+    setDeleteModel(model) {
         this.deleteModalsService.setDeleteModel(model);
     }
 
-    haveDataInDb(){
-        this.tournamentDataService.hasData().subscribe(result=>{
+    haveDataInDb() {
+        this.tournamentDataService.hasData().subscribe(result => {
             this.hasDataInDb = result
         })
     }

From 318b7d6b73b5bb45a49f0eb900da2f27572f9316 Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Tue, 11 Dec 2018 21:06:22 +0200
Subject: [PATCH 11/12] feat(configure-amount-of-matches): Changed tournament
 setting ui

---
 .../tournament-settings.component.html        | 94 ++++++++++++-------
 1 file changed, 61 insertions(+), 33 deletions(-)

diff --git a/client/app/pages/tournament-settings/tournament-settings.component.html b/client/app/pages/tournament-settings/tournament-settings.component.html
index e03f70d..ed97600 100644
--- a/client/app/pages/tournament-settings/tournament-settings.component.html
+++ b/client/app/pages/tournament-settings/tournament-settings.component.html
@@ -10,46 +10,74 @@ <h3>Settings</h3>
             <div *ngIf="!loading">
                 <fieldset class="fieldset">
                     <legend>Tournament</legend>
+                    <h5>{{settings['tournamentStage'].display}}</h5>
                     <div class="grid-x grid-margin-x">
-                        <div class="cell medium-6">
-                            <h5>{{settings['tournamentStage'].display}}</h5>
-                            <div class="input-group">
-                                <select class="input-group-field" [(ngModel)]="settings['tournamentStage'].value"
-                                        [disabled]="settings['tournamentStage'].options == undefined">
-                                    <option *ngFor="let option of settings['tournamentStage'].options"
-                                            value="{{option}}">
-                                        {{option}}
-                                    </option>
-                                </select>
-                                <div class="input-group-button">
-                                    <button class="button" (click)="save('tournamentStage')"
-                                            [disabled]="settings['tournamentStage'].options == undefined"><i
-                                            class="fa fa-save"></i>&nbsp; Save
-                                    </button>
-                                </div>
-                            </div>
-
-                            <h5>Delete Tournament Data</h5>
-                            <label>Press Delete to delete Teams and Matches. <br/> Note: You must first delete all
-                                scoring data.</label>
-                            <button class="button alert" data-open="model-delete"
-                                    (click)="setDeleteModel(tournamentDataService)" [disabled]="!hasDataInDb">Delete
+                        <div class="cell medium-4">
+                            <select class="input-group-field" [(ngModel)]="settings['tournamentStage'].value"
+                                    [disabled]="settings['tournamentStage'].options == undefined">
+                                <option *ngFor="let option of settings['tournamentStage'].options"
+                                        value="{{option}}">
+                                    {{option}}
+                                </option>
+                            </select>
+                        </div>
+                        <div class="cell medium-2">
+                            <button class="button" (click)="save('tournamentStage')"
+                                    [disabled]="settings['tournamentStage'].options == undefined"><i
+                                    class="fa fa-save"></i>&nbsp; Save
                             </button>
                         </div>
-                        <div class="cell medium-6">
-                            <h5>Number of rounds per stage</h5>
-                            <label>
-                                This setting is used when you import a partial schedule file or a team list.
-                            </label>
+                    </div>
+
+                    <div class="cell medium-2">
+                        <h5>Number of rounds per stage</h5>
+                        <label>
+                            This setting is used when you import a partial schedule file or a team list.
+                        </label>
+                    </div>
 
-                            {{settings['numberOfPracticeRounds'].display}}
-                            <input type="number" [(ngModel)]="settings['numberOfPracticeRounds'].value" min="{{MIN_AMOUNT_OF_ROUNDS}}" max="{{MAX_AMOUNT_OF_ROUNDS}}">
-                            {{settings['numberOfRankingRounds'].display}}
-                            <input type="number" [(ngModel)]="settings['numberOfRankingRounds'].value" min="{{MIN_AMOUNT_OF_ROUNDS}}" max="{{MAX_AMOUNT_OF_ROUNDS}}">
+                    <div class="grid-x grid-margin-x">
+                        <div class="cell medium-6">
+                            <div class="grid-y">
+                                <div class="cell medium-1">
+                                    <div class="grid-x grid-margin-x">
+                                        <div class="cell medium-4">
+                                            {{settings['numberOfPracticeRounds'].display}}
+                                        </div>
+                                        <div class="cell medium-4">
+                                            {{settings['numberOfRankingRounds'].display}}
+                                        </div>
+                                    </div>
+                                </div>
+                                <div class="cell medium-1">
+                                    <div class="grid-x grid-margin-x">
+                                        <div class="cell medium-4">
+                                            <input type="number" [(ngModel)]="settings['numberOfPracticeRounds'].value"
+                                                   min="{{MIN_AMOUNT_OF_ROUNDS}}" max="{{MAX_AMOUNT_OF_ROUNDS}}">
+                                        </div>
+                                        <div class="cell medium-4">
+                                            <input type="number" [(ngModel)]="settings['numberOfRankingRounds'].value"
+                                                   min="{{MIN_AMOUNT_OF_ROUNDS}}" max="{{MAX_AMOUNT_OF_ROUNDS}}">
+                                        </div>
+                                        <div class="cell medium-2">
+                                            <button class="button" (click)="saveNumberOFRounds()" [disabled]=""><i
+                                                    class="fa fa-save"></i>&nbsp; Save
+                                            </button>
+                                        </div>
 
-                            <button class="button" (click)="saveNumberOFRounds()" [disabled]=""><i class="fa fa-save"></i>&nbsp; Save</button>
+                                    </div>
+                                </div>
+                            </div>
                         </div>
                     </div>
+
+                    <h5>Delete Tournament Data</h5>
+                    <label>Press Delete to delete Teams and Matches. <br/> Note: You must first delete all scoring
+                        data.</label>
+                    <button class="button alert" data-open="model-delete"
+                            (click)="setDeleteModel(tournamentDataService)" [disabled]="!hasDataInDb">Delete
+                    </button>
+
                 </fieldset>
 
                 <fieldset class="fieldset">

From 94f9de54f3045197102e6fa6d885e31b8471e604 Mon Sep 17 00:00:00 2001
From: Tal Taub <taltaub22@gmail.com>
Date: Sat, 15 Dec 2018 12:13:45 +0200
Subject: [PATCH 12/12] Changed error notification text on validation

---
 .../pages/tournament-settings/tournament-settings.component.ts  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/client/app/pages/tournament-settings/tournament-settings.component.ts b/client/app/pages/tournament-settings/tournament-settings.component.ts
index ea87d1a..1386b7d 100644
--- a/client/app/pages/tournament-settings/tournament-settings.component.ts
+++ b/client/app/pages/tournament-settings/tournament-settings.component.ts
@@ -101,7 +101,7 @@ export class TournamentSettingsComponent implements OnInit {
                     }
                 )
         } else {
-            this.notification.error(`Number of round per stage need to be between ${this.MIN_AMOUNT_OF_ROUNDS} and ${this.MAX_AMOUNT_OF_ROUNDS}`)
+            this.notification.error(`Valid rounds per stage is between ${this.MIN_AMOUNT_OF_ROUNDS} and ${this.MAX_AMOUNT_OF_ROUNDS}`)
         }
 
     }