feat: 3 screens for rotations
commit563116331fAuthor: eneller <erikneller@gmx.de> Date: Sun Feb 1 10:28:19 2026 +0100 fix: edit list items commit1946c599beAuthor: eneller <erikneller@gmx.de> Date: Sun Feb 1 10:19:16 2026 +0100 fix: minor misc ui and data commit7c7762515bAuthor: eneller <erikneller@gmx.de> Date: Sat Jan 31 23:02:01 2026 +0100 feat: navbar commitaaa0ab0638Author: eneller <erikneller@gmx.de> Date: Sat Jan 31 21:05:23 2026 +0100 feat: remove players commit4082932095Author: eneller <erikneller@gmx.de> Date: Sat Jan 31 20:36:49 2026 +0100 feat: dataservice commitb6d34ce262Author: eneller <erikneller@gmx.de> Date: Sat Jan 31 17:12:37 2026 +0100 wip: rotations accordion commit764ce43138Author: eneller <erikneller@gmx.de> Date: Sat Jan 31 16:29:11 2026 +0100 refactor: basic screen commit1bc97df0daAuthor: eneller <erikneller@gmx.de> Date: Sat Jan 31 15:52:06 2026 +0100 feat: deduplicated player adding commit5408a8d9b6Author: eneller <erikneller@gmx.de> Date: Sat Jan 31 00:31:01 2026 +0100 central players list commit665cb25d34Author: eneller <erikneller@gmx.de> Date: Fri Jan 30 23:15:16 2026 +0100 feat: modal commit3b8e5145c3Author: eneller <erikneller@gmx.de> Date: Fri Jan 30 22:51:09 2026 +0100 wip: player modal commit51414f5a99Author: eneller <erikneller@gmx.de> Date: Fri Jan 30 22:03:48 2026 +0100 refactor: extract randomizer to component
This commit is contained in:
@@ -1,77 +1,40 @@
|
||||
import { Component, OnInit} from '@angular/core';
|
||||
import { Component, inject, OnInit} from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { RouterOutlet, ActivatedRoute } from '@angular/router';
|
||||
import { RouterOutlet, ActivatedRoute, RouterLink } from '@angular/router';
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { filter, take } from 'rxjs';
|
||||
import { ScreenBasicComponent } from "./screen-basic/screen-basic.component";
|
||||
import { ScreenRotationsComponent } from './screen-rotations/screen-rotations.component';
|
||||
import { Player } from './model';
|
||||
import { ScreenEditComponent } from './screen-edit/screen-edit.component';
|
||||
import { DataService } from './data.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
imports: [NgbModule, RouterOutlet, CommonModule, FormsModule],
|
||||
imports: [NgbModule, RouterOutlet, CommonModule, FormsModule, ScreenBasicComponent, ScreenRotationsComponent, ScreenEditComponent, RouterLink],
|
||||
templateUrl: './app.component.html',
|
||||
styleUrl: './app.component.less'
|
||||
})
|
||||
export class AppComponent implements OnInit {
|
||||
title = 'vb';
|
||||
playerNamesValue = "";
|
||||
numTeamsSelectorValue = "2";
|
||||
numTeamsSelected = 2;
|
||||
nTeamsValue = "4";
|
||||
teamsArray: string[][] = [];
|
||||
duplicateNames: string[] = [];
|
||||
data = inject(DataService);
|
||||
|
||||
constructor(private activatedRoute: ActivatedRoute){}
|
||||
constructor(public route: ActivatedRoute){}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.activatedRoute.queryParams.pipe(
|
||||
this.route.queryParams.pipe(
|
||||
filter(params => Object.keys(params).length > 0), // Only proceed if params are not empty
|
||||
take(1)
|
||||
).subscribe(params => {
|
||||
const names = params['names']?.replaceAll(',', '\n');
|
||||
if (names) {
|
||||
this.playerNamesValue = names;
|
||||
if (params['names']){
|
||||
this.data.setPlayers(
|
||||
params['names'].split(',').map((name: string) => new Player(name))
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onButtonGenerate(textinput: string): void{
|
||||
if(this.numTeamsSelectorValue === 'n'){
|
||||
this.numTeamsSelected = Number(this.nTeamsValue);
|
||||
}
|
||||
else{
|
||||
this.numTeamsSelected = Number(this.numTeamsSelectorValue);
|
||||
}
|
||||
let nameslist = this.playerNamesValue
|
||||
.split('\n')
|
||||
.map(function(str){return str.trim();})
|
||||
.filter(function(str){return str}); // boolean interpretation is same as non-empty
|
||||
// remove duplicates by using a Set
|
||||
let namesset = new Set(nameslist);
|
||||
let names = [...namesset];
|
||||
|
||||
|
||||
let teams = Array.from({ length: this.numTeamsSelected }, () => []);
|
||||
let playersPerTeam = Math.floor(names.length / this.numTeamsSelected);
|
||||
|
||||
let nameslen = names.length;
|
||||
function* iter(list: any[]){
|
||||
let index = 0;
|
||||
while(true){
|
||||
yield list[index % list.length];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
let iterator = iter(teams);
|
||||
for(let i =0; i < nameslen; i++){
|
||||
let index = Math.floor(Math.random()* names.length);
|
||||
let n = names[index];
|
||||
names.splice(index,1);
|
||||
let team = iterator.next().value;
|
||||
team.push(n);
|
||||
|
||||
}
|
||||
this.teamsArray = teams;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user