This commit is contained in:
Lurkars
2020-11-02 08:29:52 +01:00
commit b7b4e2d032
126 changed files with 18263 additions and 0 deletions
@@ -0,0 +1,17 @@
<h1 mat-dialog-title>{{'username.generate' | i18n}}</h1>
<div mat-dialog-content>
<mat-form-field>
<mat-chip-list #chipList [multiple]="true" [selectable]="true" cdkDropList cdkDropListOrientation="horizontal"
(cdkDropListDropped)="drop($event)">
<mat-chip *ngFor="let dict of dicts" cdkDrag [selected]="dict.selected" (click)="toggle(dict)">
{{dict.name}}
</mat-chip>
</mat-chip-list>
</mat-form-field>
</div>
<div mat-dialog-actions>
<button mat-button (click)="onOkClick()">Ok</button>
</div>
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UsernameDialog } from './username.dialog';
describe('UsernameDialog', () => {
let component: UsernameDialog;
let fixture: ComponentFixture<UsernameDialog>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ UsernameDialog ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(UsernameDialog);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,64 @@
import { Component } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { uniqueNamesGenerator, Config, adjectives, colors, animals } from 'unique-names-generator';
@Component({
selector: 'app-username-dialog',
templateUrl: './username.dialog.html',
styleUrls: ['./username.dialog.scss']
})
export class UsernameDialog {
dicts: any[] = [
{
name: 'adjectives',
dict: adjectives,
selected: true
}, {
name: 'colors',
dict: colors,
selected: true
}, {
name: 'animals',
dict: animals,
selected: true
}
];
username: String;
constructor(public dialogRef: MatDialogRef<UsernameDialog>) {
}
onOkClick(): void {
let dictsToUse = this.dicts.filter(dict => dict.selected);
const config: Config = {
dictionaries: dictsToUse.map(dict => dict.dict),
separator: "",
style: "capital",
length: dictsToUse.length
};
this.username = uniqueNamesGenerator(config);
console.log(this.username);
}
toggle(dict) {
dict.selected = !dict.selected;
}
drop(event: CdkDragDrop<any[]>) {
moveItemInArray(this.dicts, event.previousIndex, event.currentIndex);
}
}