13 Commits

Author SHA1 Message Date
eneller
6596d30bd6 center nTeamsSelector 2025-01-06 18:32:41 +01:00
eneller
497b64fe3f remove angular material completely 2025-01-06 15:25:24 +01:00
eneller
4d58880493 replace angular material components with bootstrap 2025-01-06 15:23:05 +01:00
eneller
dcf25ea969 add ng-bootstrap 2025-01-06 13:13:05 +01:00
eneller
48bbdab308 implement nTeams 2024-11-28 11:07:07 +01:00
eneller
f7f8482bc9 update icons 2024-11-28 09:17:20 +01:00
eneller
e0a319b32a make pwa for offline usage 2024-11-28 08:48:14 +01:00
eneller
4be3649d43 add padding to nTeamsToggle 2024-11-28 00:53:27 +01:00
eneller
2a596b15c8 fully functional using angular 2024-11-28 00:32:41 +01:00
eneller
d2090f30d4 basic ui alignment, add nTeams 2024-11-27 23:42:54 +01:00
eneller
97f01f924a add basic ui elements 2024-11-27 22:40:23 +01:00
eneller
102f589869 add angular material 2024-11-27 22:01:32 +01:00
eneller
7f5978b226 Initial Angular Commit 2024-11-27 20:15:11 +01:00
8 changed files with 1252 additions and 1633 deletions

View File

@@ -1,11 +1,8 @@
# Vb # Vb
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 This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.0.2.
## Development server
To start a local development server, run: To start a local development server, run:
@@ -15,10 +12,18 @@ 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 ## Code scaffolding
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
```bash ```bash
npm run serve ng generate component component-name
```
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
```bash
ng generate --help
``` ```
## Building ## Building
@@ -29,5 +34,26 @@ To build the project run:
ng build 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. By default, the production build optimizes your application for performance and speed.
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
```
## Running end-to-end tests
For end-to-end (e2e) testing, run:
```bash
ng e2e
```
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
## Additional Resources
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.

View File

@@ -30,8 +30,7 @@
{ {
"glob": "**/*", "glob": "**/*",
"input": "public" "input": "public"
}, }
"src/sw.js"
], ],
"styles": [ "styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css", "node_modules/bootstrap/dist/css/bootstrap.min.css",

2773
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,8 @@
<style>
*{
text-align: center;
}
</style>
<main class="main"> <main class="main">
<div class="row justify-content-md-center"> <div class="row justify-content-md-center">
<h1>Please select the number of teams:</h1> <h1>Please select the number of teams:</h1>
@@ -18,24 +23,21 @@
<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 [(ngModel)]="playerNamesValue" <textarea class="form-control mb-3"
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>
<table class="table table-striped custom-table"> </form>
<table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th scope="col">Size</th> <th scope="col">Size</th>
@@ -45,8 +47,8 @@
<tbody> <tbody>
@for (team of teamsArray; track $index) { @for (team of teamsArray; track $index) {
<tr> <tr>
<td style="text-wrap: wrap;">{{ team.length | number }}</td> <td>{{ team.length | number }}</td>
<td class="wrap-cell">{{ team }}</td> <td>{{ team }}</td>
</tr> </tr>
} }
</tbody> </tbody>

View File

@@ -1,11 +0,0 @@
*{
text-align: center;
}
.custom-table {
//table-layout: fixed;
width: 100%; /* Or a specific max-width */
}
.wrap-cell{
word-break: break-word;
white-space: normal;
}

View File

@@ -1,6 +1,6 @@
import { AfterViewInit, Component, OnInit} from '@angular/core'; import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { RouterOutlet, ActivatedRoute } from '@angular/router'; import { RouterOutlet } 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,24 +11,14 @@ import { CommonModule } from '@angular/common';
templateUrl: './app.component.html', templateUrl: './app.component.html',
styleUrl: './app.component.less' styleUrl: './app.component.less'
}) })
export class AppComponent implements OnInit { export class AppComponent {
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 {
//TODO consider 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);
@@ -36,7 +26,7 @@ export class AppComponent implements OnInit {
else{ else{
this.numTeamsSelected = Number(this.numTeamsSelectorValue); this.numTeamsSelected = Number(this.numTeamsSelectorValue);
} }
let names = this.playerNamesValue let names = textinput
.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
@@ -47,7 +37,7 @@ export class AppComponent implements OnInit {
var playersPerTeam = Math.floor(names.length / this.numTeamsSelected); var playersPerTeam = Math.floor(names.length / this.numTeamsSelected);
let nameslen = names.length; let nameslen = names.length;
function* iter(list: any[]){ function* iter(list: any){
let index = 0; let index = 0;
while(true){ while(true){
yield list[index % list.length]; yield list[index % list.length];

View File

@@ -7,7 +7,7 @@ import { provideAnimationsAsync } from '@angular/platform-browser/animations/asy
import { provideServiceWorker } from '@angular/service-worker'; import { provideServiceWorker } from '@angular/service-worker';
export const appConfig: ApplicationConfig = { export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideClientHydration(withEventReplay()), provideAnimationsAsync('noop'), provideServiceWorker('./sw.js', { providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideClientHydration(withEventReplay()), provideAnimationsAsync('noop'), provideServiceWorker('ngsw-worker.js', {
enabled: !isDevMode(), enabled: !isDevMode(),
registrationStrategy: 'registerWhenStable:30000' registrationStrategy: 'registerWhenStable:30000'
})] })]

View File

@@ -1,12 +0,0 @@
self.addEventListener('fetch', event => {
if (event &&
event.request &&
event.request.url &&
// check if basename includes a dot, i.e. if it is not a file
! event.request.url.split(/[\\/]/).pop().includes(".")
) {
event.stopImmediatePropagation();
}
});
self.importScripts('./ngsw-worker.js');