Parcourir la source

added phone lst button

Tomi Cvetic il y a 7 ans
Parent
commit
fc1833a634
3 fichiers modifiés avec 55 ajouts et 22 suppressions
  1. 34 2
      src/App.js
  2. 16 16
      src/player/index.js
  3. 5 4
      src/playerList/state.js

+ 34 - 2
src/App.js

@@ -69,6 +69,7 @@ class App extends React.Component {
     this.filterPlayers = this.filterPlayers.bind(this)
     this.generateSchedule = this.generateSchedule.bind(this)
     this.generatePayTable = this.generatePayTable.bind(this)
+    this.generatePhoneList = this.generatePhoneList.bind(this)
   }
 
   calculateMatchFilters () {
@@ -136,7 +137,7 @@ class App extends React.Component {
     worksheets['Calendar'] = worksheet
     this.setState({ worksheets })
 
-    if (worksheet[2].length < 8  | worksheet[2].length > 9) {
+    if (worksheet[2].length < 8 | worksheet[2].length > 9) {
       throw Error('Wrong file structure.')
     }
     const matches = worksheet.slice(2, worksheet.length).map((matchData) => new Match.MatchClass(matchData))
@@ -204,7 +205,7 @@ class App extends React.Component {
       String(this.state.match.dates[key]) === this.matchDate.value
     )
 
-    placeArray.forEach((place) => {
+    placeArray.forEach(place => {
       let header = [
         [`Spielplan für den ${date} (${place})`],
         [],
@@ -222,6 +223,36 @@ class App extends React.Component {
     Excel.saveAs(matchlist, 'Spielliste.xlsx')
   }
 
+  generatePhoneList (event) {
+    event.preventDefault()
+
+    const phoneMail = new Excel.Workbook()
+    phoneMail.SheetNames = []
+    phoneMail.Sheets = {}
+
+    const dataList = [
+      ['Vorname', 'Nachname', 'Anrede', 'Geschlecht', 'Handy', 'E-Mail']
+    ]
+    const phonePot = []
+
+    const players = this.state.player.filtered
+    players.forEach(player => {
+      if (!player.phone.match(/^FEHLER/) && !phonePot.includes(player.phone)) {
+        phonePot.push(player.phone)
+        dataList.push([
+          player.Vorname,
+          player.Name,
+          2,
+          player.geschlecht === 'w' ? 2 : 1,
+          player.phone
+        ])
+      }
+    })
+    phoneMail.Sheets['Sheet1'] = Excel.SheetFromArray(dataList)
+    phoneMail.SheetNames.push('Sheet1')
+    Excel.saveAs(phoneMail, 'Telefon.xlsx')
+  }
+
   calculatePayDate () {
     if ((this.state.player.players.length === 0) | (this.state.match.matches.length === 0)) {
       return
@@ -385,6 +416,7 @@ class App extends React.Component {
           </select>
           <button onClick={this.generateSchedule} disabled={!this.state.match.filtered.length}>Spielliste generieren</button>
           <button onClick={this.generatePayTable} disabled={(!this.state.match.filtered.length | !this.state.player.filtered.length)}>Zahlliste generieren</button>
+          <button onClick={this.generatePhoneList} disabled={!this.state.player.players.length}>Telefonliste generieren</button>
         </form>
         <MatchList match={this.state.match} />
         <PhoneList filtered={this.state.match.filtered} players={this.state.player.players} />

+ 16 - 16
src/player/index.js

@@ -11,15 +11,12 @@ function normalizePhone (item) {
   }
   if (phone.length === 0) {
     return null
-  }
-  else if (phone.length === 9) {
+  } else if (phone.length === 9) {
     // Assume swiss number
     phone = `+41${phone}`
-  }
-  else if (phone.length === 11) {
+  } else if (phone.length === 11) {
     phone = `+${phone}`
-  }
-  else {
+  } else {
     return `FEHLER (falsche Länge): ${phone}`
   }
 
@@ -49,6 +46,14 @@ class Player {
   constructor (data) {
     this.Konkurrenz = normalize(data[0])
     this.Lizenz = normalize(data[2])
+    this.geschlecht = null
+    if (this.Konkurrenz) {
+      if (this.Konkurrenz[0] === 'M') {
+        this.geschlecht = 'm'
+      } else if (this.Konkurrenz[0] === 'W') {
+        this.geschlecht = 'w'
+      }
+    }
     this.Name = normalize(data[5])
     this.Vorname = normalize(data[6])
     this.Geburtsdatum = data[7]
@@ -72,20 +77,15 @@ class Player {
     this.name = this.isDoubles ? `${this.Name} ${this.Vorname} / ${this.NameDP} ${this.VornameDP}` : `${this.Name} ${this.Vorname}`
     if (this.Mobile && this.Mobile.match(reMobile)) {
       this.phone = this.Mobile
-    }
-    else if (this.TelP && this.TelP.match(reMobile)) {
+    } else if (this.TelP && this.TelP.match(reMobile)) {
       this.phone = this.TelP
-    }
-    else if (this.TelG && this.TelG.match(reMobile)) {
+    } else if (this.TelG && this.TelG.match(reMobile)) {
       this.phone = this.TelG
-    }
-    else if (this.Mobile && this.Mobile.match(/FEHLER/)) {
+    } else if (this.Mobile && this.Mobile.match(/FEHLER/)) {
       this.phone = this.Mobile
-    }
-    else if (this.TelP && this.TelP.match(/FEHLER/)) {
+    } else if (this.TelP && this.TelP.match(/FEHLER/)) {
       this.phone = this.TelP
-    }
-    else if (this.TelG && this.TelG.match(/FEHLER/)) {
+    } else if (this.TelG && this.TelG.match(/FEHLER/)) {
       this.phone = this.TelG
     }
   }

+ 5 - 4
src/playerList/state.js

@@ -6,12 +6,13 @@
  * Collection of everything which has to do with state changes.
  **/
 
-
 /** actionTypes define what actions are handeled by the reducer. */
 export const actions = {
   setState: players => {
-    type: 'SET_PLAYERS',
-    players
+    return {
+      type: 'SET_PLAYERS',
+      players
+    }
   }
 }
 console.log('State actions', actions)
@@ -27,4 +28,4 @@ export function reducer (state = [], action) {
 }
 
 /** sagas are asynchronous workers (JS generators) to handle the state. */
-export function * saga () {}
+export function * saga () {}