Skip to content

Instantly share code, notes, and snippets.

View chasebaker21's full-sized avatar
🤓

chasebaker21 chasebaker21

🤓
View GitHub Profile
// creates controls inside each day of week
initDayTaskInfo(day: DayInfoProject, date: Date) {
let dayTask = this.fb.group({
comments: new FormControl(day.comments),
day: new FormControl(date),
hours: new FormControl(day.hours, (Validators.min(0), Validators.max(24))),
open: new FormControl(day.open),
tasks: this.initTaskInfo(day.tasks)
})
// creates controls for each day of week in hoursHashMap form group
initHoursHashMap(data: HoursHashMap) {
return this.fb.group({
Sunday: this.initDayTaskInfo(data.Sunday, this.sunday),
Monday: this.initDayTaskInfo(data.Monday, this.monday),
Tuesday: this.initDayTaskInfo(data.Tuesday, this.tuesday),
Wednesday: this.initDayTaskInfo(data.Wednesday, this.wednesday),
Thursday: this.initDayTaskInfo(data.Thursday, this.thursday),
Friday: this.initDayTaskInfo(data.Friday, this.friday),
addProjects() {
this.projectTimesheet.forEach(d => {
let group;
group = this.fb.group({
clientId: d.clientId,
clientName: d.clientName,
endDate: d.endDate,
hoursHashMap: this.initHoursHashMap(d.hoursHashMap),
projectCode: d.projectCode,
projectDesc: d.projectDesc,
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { FormGroup, FormBuilder, FormArray, FormControl, Validators } from '@angular/forms';
@Component({
selector: 'app-project-timesheet',
templateUrl: './project-timesheet.component.html',
styleUrls: ['./project-timesheet.component.scss']
})
<app-project-timesheet (project)="getProjectForm($event)"></app-project-timesheet>
<app-admin-timesheet (admin)="getAdminForm($event)"></app-admin-timesheet>
// gets form data for adminTime from child component admin timesheet
getAdminForm(adminFormData: FormGroup) {
this.adminForm = adminFormData.get('adminTime').value;
this.timesheetForm.get('adminTime').patchValue(this.adminForm);
}
// get form data for projectTime from child component project timesheet
getProjectForm(projectFormData: FormGroup) {
this.projectForm = projectFormData.get('projectTime').value;
patchValues(timesheetData: any) {
this.timesheetForm.get('comments').patchValue(timesheetData.comments);
this.timesheetForm.get('projectTime').patchValue(timesheetData.projectTime);
this.timesheetForm.get('adminTime').patchValue(timesheetData.adminTime);
}
initDataSource(data: any) {
this.adminTimesheet = data.adminTime;
this.projectTimesheet = data.projectTime;
this.patchValues(data);
}
createTimesheetForm() {
this.timesheetForm = this.fb.group({
comments: new FormControl(null),
projectTime: new FormControl(null), // project timesheet component
adminTime: new FormControl(null), // admin timesheet component
})
}
export class TimesheetSubmitComponent implements OnInit {
adminTimesheet = [];
projectTimesheet = [];
timesheetForm: FormGroup;
adminForm: FormGroup;
projectForm: FormGroup;