Skip to content

Commit 8e04cc9

Browse files
committed
feat: use URL query parameters to initialize textarea
?names parameter is now used to initialize the playerNames textarea
1 parent 5b66e19 commit 8e04cc9

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Vb
2-
A Team Randomizer built using Angular, installable as a progressive web app (PWA).
2+
A Team Randomizer built using Angular and Bootstrap, installable as a progressive web app (PWA).
3+
Supports setting names using URL query parameters:
4+
```url
5+
https://vb.example.org?names=Me,Myself,I
6+
```
37

48
## Development
59

@@ -11,6 +15,12 @@ ng serve
1115

1216
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.
1317

18+
Alternatively, to open the server to the network instead of just localhost, use
19+
20+
```bash
21+
npm run serve
22+
```
23+
1424
## Building
1525

1626
To build the project run:
@@ -20,12 +30,4 @@ ng build
2030
```
2131

2232
This will compile your project and store the build artifacts in the `dist/` directory.
23-
As this is a static site, simply move the contents of browser/ to a directory that can be served by nginx or apache.
24-
25-
## Running unit tests
26-
27-
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
28-
29-
```bash
30-
ng test
31-
```
33+
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.

src/app/app.component.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@ <h1>Please select the number of teams:</h1>
2323
<input type="number" pattern="\d*" [(ngModel)]="nTeamsValue" id="nTeamsField" class="form-control" >
2424
</div>
2525
</div>
26+
2627
<form>
2728
<div class="container">
2829
<label for="playerNames">Names</label>
29-
<textarea class="form-control mb-3"
30+
<textarea [(ngModel)]="playerNamesValue"
31+
class="form-control mb-3"
3032
rows="18"
3133
cols="30"
3234
style="text-align: left;"
35+
name="playerNames"
3336
#playerNames
3437
id="playerNames"
3538
></textarea>
3639
</div>
3740
<button type="button" (click)="onButtonGenerate(playerNames.value)" class="btn btn-primary">Generate</button>
38-
3941
</form>
42+
4043
<table class="table table-striped">
4144
<thead>
4245
<tr>

src/app/app.component.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Component } from '@angular/core';
1+
import { AfterViewInit, Component, OnInit} from '@angular/core';
22
import { FormsModule } from '@angular/forms';
3-
import { RouterOutlet } from '@angular/router';
3+
import { RouterOutlet, ActivatedRoute } from '@angular/router';
44
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
55

66
import { CommonModule } from '@angular/common';
@@ -11,22 +11,32 @@ import { CommonModule } from '@angular/common';
1111
templateUrl: './app.component.html',
1212
styleUrl: './app.component.less'
1313
})
14-
export class AppComponent {
14+
export class AppComponent implements OnInit {
1515
title = 'vb';
16+
playerNamesValue = "";
1617
numTeamsSelectorValue = "2";
1718
numTeamsSelected = 2;
1819
nTeamsValue = "4";
1920
teamsArray: string[][] = [];
2021
displayedColumns = ["teamCount", "teamNames"];
2122

23+
constructor(private activatedRoute: ActivatedRoute){}
24+
25+
ngOnInit(): void {
26+
//consiedr using Angular's ActivatedRoute here instead
27+
const params = new URLSearchParams(window.location.search);
28+
const names = params.get('names')?.replaceAll(',', '\n');
29+
if (names) this.playerNamesValue = names;
30+
}
31+
2232
onButtonGenerate(textinput: string): void{
2333
if(this.numTeamsSelectorValue === 'n'){
2434
this.numTeamsSelected = Number(this.nTeamsValue);
2535
}
2636
else{
2737
this.numTeamsSelected = Number(this.numTeamsSelectorValue);
2838
}
29-
let names = textinput
39+
let names = this.playerNamesValue
3040
.split('\n')
3141
.map(function(str){return str.trim();})
3242
.filter(function(str){return str}); // boolean interpretation is same as non-empty

0 commit comments

Comments
 (0)