9 Commits
v2.0 ... v2.2.1

Author SHA1 Message Date
eneller
29633a94c0 feat: better table formatting 2025-03-12 22:57:53 +01:00
eneller
3d3a177b7c fix: ServiceWorker intercepting requests
created wrapper for SW to exclude paths because ngsw-config only
disables caching, but the SW would still handle the request
2025-03-05 22:57:56 +01:00
eneller
07b84586b6 Revert "fix: serviceworker doesnt intercept other urls"
This reverts commit 5267eb6ab1.
2025-03-05 21:16:49 +01:00
eneller
5267eb6ab1 fix: serviceworker doesnt intercept other urls
since i am using the same subdomain also for '/redirects', they were
being intercepted by the service worker
chrome now blocks the redirect altogether because of CORS when redirects
are not allowed (default on linux chromium)
2025-03-04 23:44:50 +01:00
eneller
5daa64d962 chore: audit fix 2025-03-02 00:10:51 +01:00
eneller
b939f4d4f3 style: better type hint 2025-03-01 23:38:00 +01:00
eneller
8e04cc97ba feat: use URL query parameters to initialize textarea
?names parameter is now used to initialize the playerNames textarea
2025-02-02 15:15:35 +01:00
eneller
5b66e1907c chore: npm audit fix 2025-02-02 13:21:59 +01:00
eneller
55bea1a923 doc: README.md 2025-02-02 09:45:13 +01:00
8 changed files with 1633 additions and 1252 deletions

View File

@@ -1,8 +1,11 @@
# 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
```
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.0.2.
## Development server
## Development
To start a local development server, run:
@@ -12,18 +15,10 @@ 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.
## Code scaffolding
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
Alternatively, to open the server to the network instead of just localhost, use
```bash
ng generate component component-name
```
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
```bash
ng generate --help
npm run serve
```
## Building
@@ -34,26 +29,5 @@ To build the project run:
ng build
```
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.
## 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.
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 `dist/vb/browser/` to a directory that can be served by nginx or apache.

View File

@@ -30,7 +30,8 @@
{
"glob": "**/*",
"input": "public"
}
},
"src/sw.js"
],
"styles": [
"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,8 +1,3 @@
<style>
*{
text-align: center;
}
</style>
<main class="main">
<div class="row justify-content-md-center">
<h1>Please select the number of teams:</h1>
@@ -23,21 +18,24 @@
<input type="number" pattern="\d*" [(ngModel)]="nTeamsValue" id="nTeamsField" class="form-control" >
</div>
</div>
<form>
<div class="container">
<label for="playerNames">Names</label>
<textarea class="form-control mb-3"
<textarea [(ngModel)]="playerNamesValue"
class="form-control mb-3"
rows="18"
cols="30"
style="text-align: left;"
name="playerNames"
#playerNames
id="playerNames"
></textarea>
</div>
<button type="button" (click)="onButtonGenerate(playerNames.value)" class="btn btn-primary">Generate</button>
</form>
<table class="table table-striped">
<table class="table table-striped custom-table">
<thead>
<tr>
<th scope="col">Size</th>
@@ -47,8 +45,8 @@
<tbody>
@for (team of teamsArray; track $index) {
<tr>
<td>{{ team.length | number }}</td>
<td>{{ team }}</td>
<td style="text-wrap: wrap;">{{ team.length | number }}</td>
<td class="wrap-cell">{{ team }}</td>
</tr>
}
</tbody>

View File

@@ -0,0 +1,11 @@
*{
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 { Component } from '@angular/core';
import { AfterViewInit, Component, OnInit} from '@angular/core';
import { FormsModule } from '@angular/forms';
import { RouterOutlet } from '@angular/router';
import { RouterOutlet, ActivatedRoute } from '@angular/router';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { CommonModule } from '@angular/common';
@@ -11,14 +11,24 @@ import { CommonModule } from '@angular/common';
templateUrl: './app.component.html',
styleUrl: './app.component.less'
})
export class AppComponent {
export class AppComponent implements OnInit {
title = 'vb';
playerNamesValue = "";
numTeamsSelectorValue = "2";
numTeamsSelected = 2;
nTeamsValue = "4";
teamsArray: string[][] = [];
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{
if(this.numTeamsSelectorValue === 'n'){
this.numTeamsSelected = Number(this.nTeamsValue);
@@ -26,7 +36,7 @@ export class AppComponent {
else{
this.numTeamsSelected = Number(this.numTeamsSelectorValue);
}
let names = textinput
let names = this.playerNamesValue
.split('\n')
.map(function(str){return str.trim();})
.filter(function(str){return str}); // boolean interpretation is same as non-empty
@@ -37,7 +47,7 @@ export class AppComponent {
var playersPerTeam = Math.floor(names.length / this.numTeamsSelected);
let nameslen = names.length;
function* iter(list: any){
function* iter(list: any[]){
let index = 0;
while(true){
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';
export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideClientHydration(withEventReplay()), provideAnimationsAsync('noop'), provideServiceWorker('ngsw-worker.js', {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideClientHydration(withEventReplay()), provideAnimationsAsync('noop'), provideServiceWorker('./sw.js', {
enabled: !isDevMode(),
registrationStrategy: 'registerWhenStable:30000'
})]

12
src/sw.js Normal file
View File

@@ -0,0 +1,12 @@
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');