浏览代码

added phone number and email list.

Tomislav Cvetic 7 年之前
父节点
当前提交
1b9587b9be

+ 6 - 2
src/App.js

@@ -4,6 +4,8 @@ import Match from './match'         // Everything that has to do with matches
 import Excel from './excel'         // Helper files to create Excel files
 import { date2s, time2s } from './helpers'
 import 'bootstrap/dist/css/bootstrap.css'
+import EmailList from './lists/components/EmailList'
+import PhoneList from './lists/components/PhoneList'
 
 /**
  * General Application Design
@@ -267,7 +269,7 @@ class App extends React.Component {
         [],
         [`${place}`, null, '50.- oder 30.- (Junioren Jg. 1999 oder jünger)'],
         [],
-        ['bereits bez.', 'Kat.', 'Name', 'Betrag bez.', 'Quittung abgeben']
+        ['bereits bez.', 'Kat.', 'Zeit', 'Name', 'Betrag bez.', 'Quittung abgeben']
       ]
 
       // Per place
@@ -384,8 +386,10 @@ class App extends React.Component {
           <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>
         </form>
-        <PlayerList player={this.state.player} />
         <MatchList match={this.state.match} />
+        <PhoneList filtered={this.state.match.filtered} players={this.state.player.players} />
+        <EmailList filtered={this.state.match.filtered} players={this.state.player.players} />
+        <PlayerList player={this.state.player} />
       </div>
     )
   }

+ 27 - 0
src/lists/components/EmailList.js

@@ -0,0 +1,27 @@
+import React from 'react'
+
+class EmailList extends React.Component {
+  render () {
+    const filtered = this.props.filtered
+    const players = this.props.players
+
+    const emailList = []
+    filtered.forEach((match, key) => {
+      const player = players.find(player => 
+        (player.name === match.Spieler1) && (player.Konkurrenz === match.Konkurrenz)
+      )
+      if (!emailList.includes(player.Email)) {
+        emailList.push(player.Email)
+      }
+    })
+
+    return (
+      <div>
+        <h2>Email Adressen</h2>
+        <p>{emailList.join('; ')}</p>
+      </div>
+    )
+  }
+}
+
+export default EmailList

+ 27 - 0
src/lists/components/PhoneList.js

@@ -0,0 +1,27 @@
+import React from 'react'
+
+class PhoneList extends React.Component {
+  render () {
+    const filtered = this.props.filtered
+    const players = this.props.players
+
+    const phoneList = []
+    filtered.forEach((match, key) => {
+        const player = players.find(player => 
+            (player.name === match.Spieler1) && (player.Konkurrenz === match.Konkurrenz)
+        )
+        if (!phoneList.includes(player.phone)) {
+            phoneList.push(player.phone)
+        }
+    })
+
+    return (
+      <div>
+        <h2>Telefonnummern</h2>
+        <p>{phoneList.join('; ')}</p>
+      </div>
+    )
+  }
+}
+
+export default PhoneList

+ 2 - 4
src/player/components/player-disp.js

@@ -15,10 +15,8 @@ class PlayerDisp extends React.Component {
         <td>{player.BezahltAm ? `${date2s(player.BezahltAm)} ${time2s(player.BezahltAm)}` : 'Unbekannt'}</td>
         <td>{player.isJunior ? 'Junior' : ''}</td>
         <td>{player.isJuniorDP ? 'DP Junior' : ''}</td>
-        <td>{player.TelP}</td>
-        <td>{player.TelG}</td>
-        <td>{player.Mobile}</td>
-        <td>{null}</td>
+        <td>{player.phone}</td>
+        <td>{player.Email}</td>
       </tr>
     )
   }

+ 1 - 3
src/player/components/player-list.js

@@ -20,10 +20,8 @@ class PlayerList extends React.Component {
               <th>Bezahlt Am</th>
               <th>Junior</th>
               <th>DP Junior</th>
-              <th>Tel P</th>
-              <th>Tel G</th>
-              <th>Mobile</th>
               <th>Telefon</th>
+              <th>E-Mail</th>
             </tr>
           </thead>
           <tbody>

+ 36 - 12
src/player/index.js

@@ -5,23 +5,26 @@ function normalize (item) {
 }
 
 function normalizePhone (item) {
-  let phone = String(item).replace(/\s|\+|\(|\)|\/|,|-|'/g, '').replace(/^0+/, '')
+  let phone = String(item).replace(/\s|\+|\/|,|-|'/g, '').replace(/\(0\)/, '').replace(/^0+/, '')
   if (phone.match(/[^\d*]/)) {
-    return `FEHLER: ${phone}`
+    return `FEHLER (nicht-numerische Zeichen): ${phone}`
   }
-  if (phone.length === 9) {
-    // Missing 0
-    phone = `0${phone}`
+  if (phone.length === 0) {
+    return null
   }
-
-  const len = phone.length
-  if (phone[len - 10] === '0') {
-    return `${phone.substring(len - 10, len - 7)} ${phone.substring(len - 7, len - 4)} ${phone.substring(len - 4, len - 2)} ${phone.substring(len - 2, len)}`
+  else if (phone.length === 9) {
+    // Assume swiss number
+    phone = `+41${phone}`
+  }
+  else if (phone.length === 11) {
+    phone = `+${phone}`
   }
-  if (len > 10) {
-    return `FEHLER: ${phone} ${phone.substring(0, len - 7)}`
+  else {
+    return `FEHLER (falsche Länge): ${phone}`
   }
-  return `${phone}`
+
+  const len = phone.length
+  return phone
 }
 
 const state = {
@@ -31,6 +34,8 @@ const state = {
   filters: {}
 }
 
+const reMobile = /^\+417/
+
 /** Class representing a player */
 class Player {
   /**
@@ -50,6 +55,7 @@ class Player {
     this.TelP = normalizePhone(data[13])
     this.TelG = normalizePhone(data[14])
     this.Mobile = normalizePhone(data[15])
+    this.Email = normalize(data[16])
     this.Klassierung = normalize(data[17])
     this.LizenzDP = normalize(data[23])
     this.NameDP = normalize(data[24])
@@ -64,6 +70,24 @@ class Player {
     this.isJunior = (this.Geburtsdatum) ? this.Geburtsdatum.getTime() >= (new Date((new Date()).getFullYear() - 18, 11, 31, 23, 59, 59, 999)).getTime() : false
     this.isJuniorDP = (this.isDoubles & !!this.GeburtsdatumDP) ? this.GeburtsdatumDP.getTime() >= (new Date((new Date()).getFullYear() - 18, 11, 31, 23, 59, 59, 999)).getTime() : false
     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)) {
+      this.phone = this.TelP
+    }
+    else if (this.TelG && this.TelG.match(reMobile)) {
+      this.phone = this.TelG
+    }
+    else if (this.Mobile && this.Mobile.match(/FEHLER/)) {
+      this.phone = this.Mobile
+    }
+    else if (this.TelP && this.TelP.match(/FEHLER/)) {
+      this.phone = this.TelP
+    }
+    else if (this.TelG && this.TelG.match(/FEHLER/)) {
+      this.phone = this.TelG
+    }
   }
 }