Commit ea8eddf9 authored by Dennis Willers's avatar Dennis Willers
Browse files

Implement Request isSpielSession and toggle buttons if game exist

parent 3da4c57a
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -26,6 +26,11 @@ export class TabuMiddlewareService {
    return this.request('GET', `${environment.tabuMiddlewareURL}SpielSession`);
  }

  isSpielSession(req: any): Promise<any> {
    console.log('json: ', req);
    return this.request('POST', `${environment.tabuMiddlewareURL}isSpielSession`, req);
  }

  addSpielSession(event: any): Promise<any> {
    return this.request('POST', `${environment.tabuMiddlewareURL}addSpielSession`, event);
  }
+2 −2
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@
      </form>
    </mat-card-content>
    <mat-card-actions>
      <button [disabled]="buttonsDisabled" mat-raised-button color="primary" (click)="getSpielSessions()">Spiel erstellen</button>
      <button [disabled]="buttonsDisabled" mat-raised-button color="primary" (click)="joinGame()">Spiel beitreten</button>
      <button [disabled]="buttonCreateGameDisabled" mat-raised-button color="primary" (click)="getSpielSessions()">Spiel erstellen</button>
      <button [disabled]="buttonJoinGameDisabled" mat-raised-button color="primary" (click)="joinGame()">Spiel beitreten</button>
    </mat-card-actions>
  </mat-card>
</div>
+20 −3
Original line number Diff line number Diff line
@@ -9,7 +9,8 @@ import {TabuMiddlewareService} from '../dao/TabuMiddlewareService';
})
export class SelectGameComponent implements OnInit {

  buttonsDisabled = true;
  buttonCreateGameDisabled = true;
  buttonJoinGameDisabled = true;
  constructor(private router: Router,
              private server: TabuMiddlewareService) { }

@@ -36,7 +37,23 @@ export class SelectGameComponent implements OnInit {
  }

  checkSpielname(spielname: string): void {
    console.log(spielname)
    this.buttonsDisabled = spielname.length === 0;
    if (spielname.length === 0) {
      this.buttonCreateGameDisabled = true;
      this.buttonJoinGameDisabled = true;
      return;
    } else {
      console.log(spielname);
      this.server.isSpielSession({"spielname": '' + spielname + ''}).then(value => {
        console.log('Response: ', value.status);
        const status = JSON.parse(value.status);
        if (status) {
          this.buttonCreateGameDisabled = true;
          this.buttonJoinGameDisabled = false;
        } else {
          this.buttonCreateGameDisabled = false;
          this.buttonJoinGameDisabled = true;
        }
      });
    }
  }
}