feat: use URL query parameters to initialize textarea
?names parameter is now used to initialize the playerNames textarea
This commit is contained in:
22
README.md
22
README.md
@@ -1,5 +1,9 @@
|
|||||||
# Vb
|
# Vb
|
||||||
A Team Randomizer built using Angular, installable as a progressive web app (PWA).
|
A Team Randomizer built using Angular and Bootstrap, installable as a progressive web app (PWA).
|
||||||
|
Supports setting names using URL query parameters:
|
||||||
|
```url
|
||||||
|
https://vb.example.org?names=Me,Myself,I
|
||||||
|
```
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
@@ -11,6 +15,12 @@ ng serve
|
|||||||
|
|
||||||
Once the server is running, open your browser and navigate to `http://localhost:4200/`. The application will automatically reload whenever you modify any of the source files.
|
Once the server is running, open your browser and navigate to `http://localhost:4200/`. The application will automatically reload whenever you modify any of the source files.
|
||||||
|
|
||||||
|
Alternatively, to open the server to the network instead of just localhost, use
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run serve
|
||||||
|
```
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
To build the project run:
|
To build the project run:
|
||||||
@@ -20,12 +30,4 @@ ng build
|
|||||||
```
|
```
|
||||||
|
|
||||||
This will compile your project and store the build artifacts in the `dist/` directory.
|
This will compile your project and store the build artifacts in the `dist/` directory.
|
||||||
As this is a static site, simply move the contents of browser/ to a directory that can be served by nginx or apache.
|
As this is a static site, simply move the contents of `dist/vb/browser/` to a directory that can be served by nginx or apache.
|
||||||
|
|
||||||
## Running unit tests
|
|
||||||
|
|
||||||
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
ng test
|
|
||||||
```
|
|
||||||
@@ -23,20 +23,23 @@
|
|||||||
<input type="number" pattern="\d*" [(ngModel)]="nTeamsValue" id="nTeamsField" class="form-control" >
|
<input type="number" pattern="\d*" [(ngModel)]="nTeamsValue" id="nTeamsField" class="form-control" >
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form>
|
<form>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<label for="playerNames">Names</label>
|
<label for="playerNames">Names</label>
|
||||||
<textarea class="form-control mb-3"
|
<textarea [(ngModel)]="playerNamesValue"
|
||||||
|
class="form-control mb-3"
|
||||||
rows="18"
|
rows="18"
|
||||||
cols="30"
|
cols="30"
|
||||||
style="text-align: left;"
|
style="text-align: left;"
|
||||||
|
name="playerNames"
|
||||||
#playerNames
|
#playerNames
|
||||||
id="playerNames"
|
id="playerNames"
|
||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" (click)="onButtonGenerate(playerNames.value)" class="btn btn-primary">Generate</button>
|
<button type="button" (click)="onButtonGenerate(playerNames.value)" class="btn btn-primary">Generate</button>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Component } from '@angular/core';
|
import { AfterViewInit, Component, OnInit} from '@angular/core';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule } from '@angular/forms';
|
||||||
import { RouterOutlet } from '@angular/router';
|
import { RouterOutlet, ActivatedRoute } from '@angular/router';
|
||||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
@@ -11,14 +11,24 @@ import { CommonModule } from '@angular/common';
|
|||||||
templateUrl: './app.component.html',
|
templateUrl: './app.component.html',
|
||||||
styleUrl: './app.component.less'
|
styleUrl: './app.component.less'
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent implements OnInit {
|
||||||
title = 'vb';
|
title = 'vb';
|
||||||
|
playerNamesValue = "";
|
||||||
numTeamsSelectorValue = "2";
|
numTeamsSelectorValue = "2";
|
||||||
numTeamsSelected = 2;
|
numTeamsSelected = 2;
|
||||||
nTeamsValue = "4";
|
nTeamsValue = "4";
|
||||||
teamsArray: string[][] = [];
|
teamsArray: string[][] = [];
|
||||||
displayedColumns = ["teamCount", "teamNames"];
|
displayedColumns = ["teamCount", "teamNames"];
|
||||||
|
|
||||||
|
constructor(private activatedRoute: ActivatedRoute){}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
//consiedr using Angular's ActivatedRoute here instead
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
const names = params.get('names')?.replaceAll(',', '\n');
|
||||||
|
if (names) this.playerNamesValue = names;
|
||||||
|
}
|
||||||
|
|
||||||
onButtonGenerate(textinput: string): void{
|
onButtonGenerate(textinput: string): void{
|
||||||
if(this.numTeamsSelectorValue === 'n'){
|
if(this.numTeamsSelectorValue === 'n'){
|
||||||
this.numTeamsSelected = Number(this.nTeamsValue);
|
this.numTeamsSelected = Number(this.nTeamsValue);
|
||||||
@@ -26,7 +36,7 @@ export class AppComponent {
|
|||||||
else{
|
else{
|
||||||
this.numTeamsSelected = Number(this.numTeamsSelectorValue);
|
this.numTeamsSelected = Number(this.numTeamsSelectorValue);
|
||||||
}
|
}
|
||||||
let names = textinput
|
let names = this.playerNamesValue
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map(function(str){return str.trim();})
|
.map(function(str){return str.trim();})
|
||||||
.filter(function(str){return str}); // boolean interpretation is same as non-empty
|
.filter(function(str){return str}); // boolean interpretation is same as non-empty
|
||||||
|
|||||||
Reference in New Issue
Block a user