File

src/app/pages/voting/voting-choice/voting-choice.component.ts

Description

each vote choice takes a configuration from the container of all choices. this component is used to select a date choice, or a name answer

Metadata

selector framadate-voting-choice
styleUrls ./voting-choice.component.scss
templateUrl ./voting-choice.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(el: ElementRef, config: ConfigService)
Parameters :
Name Type Optional
el ElementRef No
config ConfigService No

Inputs

choice
Type : any
choice_id
Type : any
choices_count
Type : any
poll
Type : any
pollIsSpecialDate
Type : boolean
Default value : false
simpleAnswer
Type : boolean
Default value : true

Methods

setAnswserTo
setAnswserTo(newAnswer: "yes" | "no" | "maybe" | null)
Parameters :
Name Type Optional
newAnswer "yes" | "no" | "maybe" | null No
Returns : void

Properties

Public showChangeChoicebutton
Default value : false
import {Component, ElementRef, Input} from '@angular/core';
import {ConfigService} from "../../../services/config.service";

interface VoteChoice {
    votes?: {
        yes: number
        no: number
        maybe: number
        notAnswered: number
    };
    name?: string;
    date?: Date;
    answer: 'yes' | 'no' | 'maybe' | null;
    simpleAnswer?: boolean
    false; // enable if we display only a togglable "yes"
}

/**
 * each vote choice takes a configuration from the container of all choices.
 * this component is used to select a date choice, or a name answer
 */
@Component({
    selector: 'framadate-voting-choice',
    templateUrl: './voting-choice.component.html',
    styleUrls: ['./voting-choice.component.scss']
})
export class VotingChoiceComponent {

    public showChangeChoicebutton = false;
    @Input() public choice: any;
    @Input() public choices_count: any;
    @Input() public choice_id: any;
    @Input() public poll: any;
    @Input() public simpleAnswer: boolean = true;
    @Input() public pollIsSpecialDate: boolean = false;

    constructor(private el: ElementRef,
                private config: ConfigService) {

        if (this.poll && this.poll.allowedAnswers) {
            this.simpleAnswer = this.poll.allowedAnswers.length == 1
        }
    }

    setAnswserTo(newAnswer: 'yes' | 'no' | 'maybe' | null) {
        if (this.simpleAnswer) {
            // only toggle yes to no
            if (this.choice.answer && this.choice.answer === 'yes') {
                this.choice.answer = 'no';
                this.config.myTempVoteStack--;
            } else {
                this.choice.answer = newAnswer;
                this.config.myTempVoteStack++;
            }

        } else {
            this.choice.answer = newAnswer;
            if (this.choice.answer !== newAnswer) {
                if (newAnswer == 'maybe' || newAnswer == 'yes') {
                    this.config.myTempVoteStack++;
                }
            } else {
                console.info('same answer as before')
            }

        }
        this.el.nativeElement.blur();
    }

}
<div class="choicebox selection-{{choice.answer}}" >
    <!-- add .choicebox--active to most voted -->
    <button
        *ngIf='showChangeChoicebutton'
        class='btn btn--primary'
        (click)=' choice.simpleAnswer = !choice.simpleAnswer' >
        <i class='fa fa-gears' ></i >
    </button >

    <div class="choicebox__subject" >
        <div class='columns' >
            <div class='column' >
                <div
                    class="text title clickable"
                    (click)="setAnswserTo('yes')" >
                    {{choice.text}}
                </div > <!-- TEXT CASE --><!--
        <p class="choicebox__txt">
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Nulla nobis nam culpa !
        </p>
        --><!-- TEXT CASE -->

                        <!-- IMG CASE -->
                <img
                    *ngIf='choice.url'
                    class="choicebox__img"
                    [src]="choice.url"
                    alt="{{choice.url}}"
                >
                        <!-- IMG CASE -->

                        <!-- DATE CASE  -->
                <div
                    class="dates"
                    *ngIf="pollIsSpecialDate" >
                    <div class="choicebox__date" >
                        {{choice.date.date | date:'EEE'}} <span
                        class="choicebox__day" >{{choice.date.date | date:'dd'}}</span > {{choice.date.date | date:'LLL'}}
                    </div >
                    <div class="choicebox__hour" >
                        {{choice.date.date | date:'H:m'}}
                    </div >
                </div >
                        <!-- DATE CASE -->
            </div >
            <div class='column' >
                <div class="choicebox__actions" >
                    <!-- show only the yes check if the config is set to simpleAnswer -->
                    <!-- add .choicebox__btn--active to selected <button> -->
                    <span class="simple-answer" >

        <button
            class="choicebox__btn choicebox__btn--yes"
            type="button"
            [ngClass]="{'choicebox__btn--active': choice.answer === 'yes'}"
            (click)="setAnswserTo('yes')" >
            <img
                src="../../../assets/img/check.svg"
                alt="" >
        </button >
        </span >
                    <span
                        class="complex-answers"
                        *ngIf="!simpleAnswer" >
            <button
                class="choicebox__btn choicebox__btn--maybe"
                type="button"
                [ngClass]="{'choicebox__btn--active': choice.answer === 'maybe'}"
                (click)="setAnswserTo('maybe')" >
            <img
                src="../../../assets/img/check-2.svg"
                alt="" >
        </button >
        <button
            class="choicebox__btn choicebox__btn--no"
            type="button"
            [ngClass]="{'choicebox__btn--active': choice.answer === 'no'}"
            (click)="setAnswserTo('no')"
        >
            <img
                src="../../../assets/img/croix.svg"
                alt="" >
        </button >
        </span >

                </div >
            </div >
            <div class='column' >
                <div class="choicebox__count" >

                    <div
                        class='no-votes'
                        *ngIf='! poll.choices_count.counts[choice.id] ' >
                        aucun vote
                    </div >
                    <button
                        type="button"
                        aria-describedby="choicebox-tooltip"
                        class="choicebox__votes"
                        *ngIf="poll.choices_count && choice && poll.choices_count.counts[choice.id]" >
                        <div class="choicebox__vote" >
                            {{poll.choices_count.counts[choice.id].yes.count}}
                            <img
                                width="20px"
                                height="21px"
                                src="../../../assets/img/votant-sur.svg"
                                alt="" >
                        </div >
                        <div class="choicebox__vote" >
                            {{poll.choices_count.counts[choice.id].maybe.count}}
                            <img
                                width="22px"
                                height="24px"
                                src="../../../assets/img/votant-pas-sur.svg"
                                alt="" >
                        </div >
                        <div
                            class="choicebox__tooltip"
                            id="choicebox-tooltip" >
                            <div class="choicebox__tooltiplist" >
                                <div class="choicebox__tooltipttl" >
                                    <img
                                        width="20px"
                                        height="21px"
                                        src="../../../assets/img/votant-sur.svg"
                                        alt="" >
                                    {{poll.choices_count.counts[choice.id].yes.count}} "Oui"
                                </div >
                                <!--                    liste des gens qui ont répondu oui-->
                                <ul >
                                    <li *ngFor='let pseudo of choices_count.counts[choice.id].yes.people ' >{{pseudo}}</li >
                                </ul >
                            </div >
                            <div
                                class="choicebox__tooltiplist"
                                *ngIf='!simpleAnswer' >
                                <div class="choicebox__tooltipttl" >
                                    <img
                                        width="22px"
                                        height="24px"
                                        src="../../../assets/img/votant-pas-sur.svg"
                                        alt="" >
                                    {{poll.choices_count.counts[choice.id].maybe.count}} "Peut-être"
                                </div >
                                <ul >
                                    <li *ngFor='let pseudo of choices_count.counts[choice.id].maybe.people ' >{{pseudo}}</li >
                                </ul >
                            </div >
                            <div
                                class="choicebox__tooltiplist"
                                *ngIf='!simpleAnswer' >
                                <div class="choicebox__tooltipttl" >
                                    <i class='fa fa-times' ></i >
                                    {{poll.choices_count.counts[choice.id].no.count}} "Non"
                                </div >
                                <ul >
                                    <li *ngFor='let pseudo of choices_count.counts[choice.id].no.people ' >{{pseudo}}</li >
                                </ul >
                            </div >
                        </div >
                    </button >
                    <div class="choicebox__countxt" >
                        Choix ayant reçu le plus de votes
                    </div >
                </div >
            </div >
        </div >

    </div >

</div >

./voting-choice.component.scss

// ---------------------------------------------------------
// -- VOTE CHOICE COMPONENT
// ---------------------------------------------------------

// -- IMPORTS
// ----------------------------

@import "../../../../assets/scss/variables";


// -- VARIABLES
// ----------------------------

$box-padding: 2rem;
$box-border-width: .6rem;
$btn-size: 5rem;
$btn-margin-x: 1rem;
$btn-margin-y: 1.5rem;
$btn-wrap-size: calc(2 * #{$btn-size} + 4 * #{$btn-margin-x});
$img-maxheight: 12rem;
$breakpoint-responsive: 640px; // à définir


// -- GLOBAL
// ----------------------------

.choicebox {
    position: relative;
    min-width: 32rem;
    min-height: 16rem;
    display: block;
    padding: $box-padding $box-padding $box-padding calc(#{$box-padding} - #{$box-border-width});
    border-left: $box-border-width solid transparent;
    background-color: $white;
    box-shadow: 0 0 .6rem 0 rgba($black, .2);

    &--active {
        padding-left: $box-padding;
        border-left-color: $primary_color;
    }

    &.selection-yes {
        font-weight: 700;
        background: #e9bdeb;
    }
}

.choicebox__subject {
    margin-bottom: 3rem;
    padding-right: $btn-wrap-size;
    @media (min-width: $breakpoint-responsive) {
        margin-bottom: 0;
        padding-right: 0;
    }
}


// -- DATE
// ----------------------------

.choicebox__date {
    font-size: 1.8rem;
    margin-bottom: .5rem;
    white-space: nowrap;
    text-transform: capitalize;

    @media (min-width: $breakpoint-responsive) {
        margin-bottom: 0;
    }
}

.choicebox__day {
    font-size: 2.4rem;
    font-weight: bold;
}


// -- IMG
// ----------------------------

.choicebox__img {
    max-width: 100%;
    max-height: $img-maxheight;
}


// -- TXT
// ----------------------------

.choicebox__txt {
    margin: 0;
    font-size: 1.8rem;
    min-width: 10em;
}


// -- VOTE BTNS
// ----------------------------

.choicebox__actions {
    position: absolute;
    z-index: 1;

    max-width: $btn-wrap-size;
    top: 50%;
    right: $box-padding;

    @media (min-width: $breakpoint-responsive) {
        position: static;
        max-width: none;
        transform: none;
        margin: 0 1.5rem;
    }
}

.choicebox__btn {
    width: $btn-size;
    height: $btn-size;
    align-items: center;
    justify-content: center;
    margin: $btn-margin-y $btn-margin-x;
    border: .3rem solid #ccc9c9;
    background-color: transparent;
    border-radius: 50%;
    cursor: pointer;
    float: left;

    &--maybe {
        position: relative;
        top: calc((#{$btn-size} + 2 * #{$btn-margin-y}) / 2);
        @media (min-width: $breakpoint-responsive) {
            top: auto;
            left: auto;
        }
    }

    &--active {
        border-color: #bf83c2;
    }

    @media (min-width: $breakpoint-responsive) {
        margin-top: 0;
        margin-bottom: 0;
    }

}


// -- VOTE COUNT
// ----------------------------

.choicebox__count {
    position: relative;
    padding-right: $btn-wrap-size;
    @media (min-width: $breakpoint-responsive) {
        text-align: right;
        padding-right: 0;
    }
}

.choicebox__votes {
    border: 0;
    padding: 0;
    line-height: normal;
    background-color: transparent;
    @media (min-width: $breakpoint-responsive) {
        padding: 1.5rem;
    }
}

.choicebox__vote {
    display: inline-block;
    vertical-align: middle;

    & + .choicebox__vote {
        margin-left: 1.5rem;
    }
}

.choicebox__countxt {
    display: none;
    margin-top: .5rem;

    .choicebox--active & {
        display: block;
        @media (min-width: $breakpoint-responsive) {
            display: none;
        }
    }
}


// -- TOOLTIP
// ----------------------------

.choicebox__tooltip {
    display: none;
    @media (min-width: $breakpoint-responsive) {
        position: absolute;
        min-width: 18rem;
        font-weight: normal;
        top: 5rem;
        left: 50%;
        z-index: 1;
        padding: 2rem;
        border: .1rem solid rgba($black, .1);
        background-color: $white;
        text-align: left;
        transform: translateX(-50%);
        &::after,
        &::before {
            position: absolute;
            width: 0;
            height: 0;
            bottom: 100%;
            left: 50%;
            content: " ";
            pointer-events: none;
            border: solid transparent;
        }
        &::after {
            margin-left: -1.5rem;
            border-width: 1.5rem;
            border-color: rgba($white, 0);
            border-bottom-color: #fff;
        }
        &::before {
            margin-left: -1.6rem;
            border-width: 1.6rem;
            border-color: rgba($black, 0);
            border-bottom-color: rgba($black, .1);
        }
        ul {
            margin: 0;
            padding: 0;
            list-style: none;
        }
    }
}

.choicebox__tooltiplist {
    & + .choicebox__tooltiplist {
        padding-left: 3rem;
    }

    ul {
        max-height: 11rem;
        overflow: auto;
    }
}

.choicebox__tooltipttl {
    @media (min-width: $breakpoint-responsive) {
        margin-bottom: 1rem;
        font-size: 1.6rem;
        font-weight: bold;
        white-space: nowrap;
        img {
            margin-right: .5rem;
            vertical-align: sub;
        }
        & ~ .choicebox__tooltipttl {
            margin-top: 3rem;
        }
    }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""