import {Component, OnInit} from '@angular/core'; import {BaseComponent} from '../base-page/base.component'; import {ConfigService} from '../../config.service'; @Component({ selector: 'framadate-visibility', templateUrl: './visibility.component.html', styleUrls: ['./visibility.component.scss'] }) export class VisibilityComponent extends BaseComponent implements OnInit { showCustomPassword = false; constructor(public config: ConfigService) { super(config); } ngOnInit() { this.config.customUrl = this.makeUuid(); this.config.expirationDate = (this.addDaysToDate(this.config.expiracyDateDefaultInDays, new Date())).toISOString().substring(0, 10); } /** * generate unique id to have a default url for future poll */ makeUuid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } /** * add some days to a date, to compute intervals * @param days * @param date */ addDaysToDate(days: number, date: Date) { date = new Date(date.valueOf()); date.setDate(date.getDate() + days); return date; }; }