added poll binding + proper poll type change

This commit is contained in:
Nicolas Constant 2019-08-24 20:49:54 -04:00
parent a06d178bae
commit 8ba78b3c19
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
5 changed files with 41 additions and 13 deletions

View File

@ -1,17 +1,20 @@
<div class="poll-editor">
<div class="poll-editor__entries">
<div *ngFor="let e of entries">
<app-poll-entry class="poll-editor__entry" [entry]="e" (removeEvent)="removeElement(e)"></app-poll-entry>
<app-poll-entry class="poll-editor__entry" [entry]="e" (removeEvent)="removeElement(e)"
(toogleMultiEvent)="toogleMulti()"></app-poll-entry>
</div>
</div>
<div class="poll-editor__footer">
<a href (click)="addEntry()">
Add entry
</a>
<select [(ngModel)]="selectedId">
<select [(ngModel)]="selectedId" class="poll-editor__footer--select-duration">
<option *ngFor="let d of delayChoice" [ngValue]="d.id">{{d.label}}</option>
</select>
<a href (click)="addEntry()" class="poll-editor__footer--add-choice">
<fa-icon [icon]="faPlus"></fa-icon> Add a choice
</a>
</div>
</div>

View File

@ -15,7 +15,23 @@
}
&__footer {
transition: all .2s;
border-top: 1px solid $poll-editor-separator;
min-height: 30px;
padding: 5px;
&--add-choice {
color: rgb(49, 49, 49);
padding: 0 5px 0 5px;
&:hover {
text-decoration: none;
color: rgb(122, 122, 122);
}
}
&--select-duration {
float: right;
}
}
}

View File

@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { PollEntry } from './poll-entry/poll-entry.component';
import { faPlus } from "@fortawesome/free-solid-svg-icons";
@Component({
selector: 'app-poll-editor',
@ -8,15 +9,17 @@ import { PollEntry } from './poll-entry/poll-entry.component';
styleUrls: ['./poll-editor.component.scss']
})
export class PollEditorComponent implements OnInit {
faPlus = faPlus;
private entryUuid: number = 0;
entries: PollEntry[] = [];
delayChoice: Delay[] = [];
selectedId: string;
private multiSelected: boolean;
constructor() {
this.entries.push(new PollEntry(this.getEntryUuid()));
this.entries.push(new PollEntry(this.getEntryUuid()));
this.entries.push(new PollEntry(this.getEntryUuid(), this.multiSelected));
this.entries.push(new PollEntry(this.getEntryUuid(), this.multiSelected));
this.delayChoice.push(new Delay(60 * 5, "5 minutes"));
this.delayChoice.push(new Delay(60 * 30, "30 minutes"));
@ -41,13 +44,20 @@ export class PollEditorComponent implements OnInit {
}
addEntry(): boolean {
this.entries.push(new PollEntry(this.getEntryUuid()));
this.entries.push(new PollEntry(this.getEntryUuid(), this.multiSelected));
return false;
}
removeElement(entry: PollEntry){
this.entries = this.entries.filter(x => x.id != entry.id);
}
toogleMulti() {
this.multiSelected = !this.multiSelected;
this.entries.forEach((e: PollEntry) => {
e.isMulti = this.multiSelected;
});
}
}
class Delay {

View File

@ -11,6 +11,6 @@
</a>
</div>
<div class="poll-entry__label">
<input type="text" [(ngModel)]="entry.label" class="poll-entry__label--input"/>
<input type="text" [(ngModel)]="entry.label" class="poll-entry__label--input" [(ngModel)]="entry.label"/>
</div>
</div>

View File

@ -32,9 +32,8 @@ export class PollEntryComponent implements OnInit {
}
export class PollEntry {
constructor(public id: number) {
constructor(public id: number, public isMulti: boolean) {
}
public isMulti: boolean;
public label: string;
}