From 6db96397ea4fc7735f4a921cd8a9a912dafa2221 Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Sat, 17 Oct 2020 11:12:53 +0200 Subject: [PATCH 1/7] hop --- src/app/app.component.ts | 25 +++++++------- .../components/header/header.component.html | 2 +- src/app/core/services/poll.service.ts | 9 +++-- .../administration-routing.module.ts | 6 +++- .../administration.component.html | 4 ++- .../administration.component.ts | 2 ++ .../administration/administration.module.ts | 3 +- .../naming/naming.component.html | 1 + .../naming/naming.component.scss | 0 .../naming/naming.component.spec.ts | 24 +++++++++++++ .../administration/naming/naming.component.ts | 12 +++++++ .../stepper/stepper.component.html | 34 +++++++++---------- src/environments/environment.ts | 2 +- 13 files changed, 86 insertions(+), 38 deletions(-) create mode 100644 src/app/features/administration/naming/naming.component.html create mode 100644 src/app/features/administration/naming/naming.component.scss create mode 100644 src/app/features/administration/naming/naming.component.spec.ts create mode 100644 src/app/features/administration/naming/naming.component.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 5a8dcc6c..3c89ed13 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,12 +1,12 @@ -import {Component, OnDestroy, OnInit} from '@angular/core'; -import {Title} from '@angular/platform-browser'; -import {Subscription} from 'rxjs'; +import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Title } from '@angular/platform-browser'; +import { Subscription } from 'rxjs'; -import {environment} from '../environments/environment'; -import {Theme} from './core/enums/theme.enum'; -import {LanguageService} from './core/services/language.service'; -import {ThemeService} from './core/services/theme.service'; -import {MockingService} from './core/services/mocking.service'; +import { environment } from '../environments/environment'; +import { Theme } from './core/enums/theme.enum'; +import { LanguageService } from './core/services/language.service'; +import { ThemeService } from './core/services/theme.service'; +import { MockingService } from './core/services/mocking.service'; @Component({ selector: 'app-root', @@ -23,16 +23,15 @@ export class AppComponent implements OnInit, OnDestroy { constructor( private titleService: Title, private themeService: ThemeService, - private languageService: LanguageService, - private mockingService: MockingService - ) { - } + private languageService: LanguageService + ) // private mockingService: MockingService + {} ngOnInit(): void { if (!environment.production) { this.appTitle += ' [DEV]'; // TODO: to be removed - this.mockingService.init(); + // this.mockingService.init(); } this.titleService.setTitle(this.appTitle); this.languageService.configureAndInitTranslations(); diff --git a/src/app/core/components/header/header.component.html b/src/app/core/components/header/header.component.html index fae62667..6eb8b36d 100644 --- a/src/app/core/components/header/header.component.html +++ b/src/app/core/components/header/header.component.html @@ -28,7 +28,7 @@ diff --git a/src/app/features/administration/form/form.component.scss b/src/app/features/administration/form/form.component.scss new file mode 100644 index 00000000..83c66da9 --- /dev/null +++ b/src/app/features/administration/form/form.component.scss @@ -0,0 +1,7 @@ +:host { + input, + textarea { + padding: 0.5em; + border: solid #eee; + } +} diff --git a/src/app/features/administration/form/form.component.spec.ts b/src/app/features/administration/form/form.component.spec.ts new file mode 100644 index 00000000..62a17377 --- /dev/null +++ b/src/app/features/administration/form/form.component.spec.ts @@ -0,0 +1,24 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { FormComponent } from './form.component'; + +describe('FormComponent', () => { + let component: FormComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [FormComponent], + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(FormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/features/administration/form/form.component.ts b/src/app/features/administration/form/form.component.ts new file mode 100644 index 00000000..8ea81d61 --- /dev/null +++ b/src/app/features/administration/form/form.component.ts @@ -0,0 +1,69 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { Poll } from '../../../core/models/poll.model'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { UuidService } from '../../../core/services/uuid.service'; +import { DateService } from '../../../core/services/date.service'; +import { ApiService } from '../../../core/services/api.service'; + +@Component({ + selector: 'app-admin-form', + templateUrl: './form.component.html', + styleUrls: ['./form.component.scss'], +}) +export class FormComponent implements OnInit { + @Input() + public poll?: Poll; + public pollFormGroup: FormGroup; + public configurationFormGroup: FormGroup; + public longFormVersionEnabled = true; + + public urlPrefix: string = window.location.origin + '/participation/'; + + constructor(private fb: FormBuilder, private uuidService: UuidService, private apiService: ApiService) {} + + ngOnInit(): void { + this.pollFormGroup = this.fb.group({ + title: [this.poll ? this.poll.title : '', [Validators.required]], + slug: [this.poll ? this.poll.slug : this.uuidService.getUUID(), [Validators.required]], + description: [this.poll ? this.poll.description : ''], + }); + + this.configurationFormGroup = this.fb.group({ + isAboutDate: [this.poll ? this.poll.configuration.isAboutDate : false, [Validators.required]], + isProtectedByPassword: [ + this.poll ? this.poll.configuration.isProtectedByPassword : false, + [Validators.required], + ], + isOwnerNotifiedByEmailOnNewVote: [ + this.poll ? this.poll.configuration.isOwnerNotifiedByEmailOnNewVote : false, + [Validators.required], + ], + isOwnerNotifiedByEmailOnNewComment: [ + this.poll ? this.poll.configuration.isOwnerNotifiedByEmailOnNewComment : false, + [Validators.required], + ], + isMaybeAnswerAvailable: [ + this.poll ? this.poll.configuration.isMaybeAnswerAvailable : false, + [Validators.required], + ], + areResultsPublic: [this.poll ? this.poll.configuration.areResultsPublic : true, [Validators.required]], + expiracyNumberOfDays: [ + this.poll ? DateService.diffInDays(new Date(), this.poll.configuration.expires) : 60, + [Validators.required], + ], + }); + } + + public createPoll(): void { + if (this.pollFormGroup.valid && this.configurationFormGroup.valid) { + console.log('Le sondage est correctement rempli, prêt à enregistrer.'); + // TODO : save the poll + this.apiService.createPoll(this.poll); + } + } + public updateSlug() { + let newValueFormatted = 'TODO'; + } + // this.pollFormGroup.setValue({'slug' : newValueFormatted); + // } +} diff --git a/src/app/features/administration/stepper/stepper.component.html b/src/app/features/administration/stepper/stepper.component.html index 3ee2864e..268af8f0 100644 --- a/src/app/features/administration/stepper/stepper.component.html +++ b/src/app/features/administration/stepper/stepper.component.html @@ -4,7 +4,7 @@ Informations du sondage Titre - + +

Choix de réponses

+
+			choicesFormArray :
+				{{ choicesFormArray | json }}
+