Guest User

Untitled

a guest
Jun 17th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.63 KB | None | 0 0
  1. import { Component, OnInit} from '@angular/core';
  2. import {HttpClient} from '@angular/common/http';
  3. import { Router } from '@angular/router';
  4. import { DataService } from "../data.service";
  5. import { AppComponent } from "../app.component";
  6. import { FormGroup, FormBuilder, Validators, AbstractControl, ValidatorFn, FormArray } from '@angular/forms';
  7. import * as $ from 'jquery';
  8.  
  9.  
  10. @Component({
  11. selector: 'app-additionalform',
  12. templateUrl: './additionalForm.component.html',
  13. styleUrls: ['./form.component.css']
  14. })
  15.  
  16. export class AdditionalFormComponent implements OnInit {
  17.  
  18. firstForm: any = [];
  19. additionalFormGroup: FormGroup;
  20. skillsArray = [];
  21.  
  22. constructor(private httpClient: HttpClient, private router: Router, private userinformation: DataService, private fb: FormBuilder) {
  23.  
  24. }
  25.  
  26. get experienceSummary(): FormArray {
  27. return <FormArray>this.additionalFormGroup.get('experienceSummary');
  28. }
  29.  
  30. get proffesionalExperience(): FormArray {
  31. return <FormArray>this.additionalFormGroup.get('proffesionalExperience');
  32. }
  33.  
  34. get educationSummary(): FormArray {
  35. return <FormArray>this.additionalFormGroup.get('educationSummary');
  36. }
  37.  
  38. get userSkillsRating(): FormArray {
  39. return <FormArray>this.additionalFormGroup.get('userSkillsRating');
  40. }
  41.  
  42. loadingJquery() {
  43. $('#overlay').css('visibility', 'visible');
  44. setTimeout(() => {
  45. $('#overlay').css('visibility', 'hidden');
  46. }, 2000);
  47. }
  48.  
  49. addEducationalSummary(): void {
  50. this.educationSummary.push(this.buildEducationSummary());
  51. }
  52.  
  53. buildEducationSummary(): FormGroup {
  54. return this.fb.group({
  55. school: '',
  56. course: '',
  57. schoolFromDate: '',
  58. schoolToDate: ''
  59. });
  60. }
  61.  
  62. addExperienceSummary(): void {
  63. this.experienceSummary.push(this.buildExperienceSummaryGroup());
  64. }
  65.  
  66. buildExperienceSummaryGroup(): FormGroup {
  67. return this.fb.group({
  68. userExperience: ''
  69. });
  70. }
  71.  
  72. removeButton(formArray: FormArray, arrayIndex: number): void {
  73. formArray.removeAt(arrayIndex);
  74. }
  75.  
  76. addProfessionalExperience(): void {
  77. this.proffesionalExperience.push(this.buildProfessionalExperience());
  78. }
  79.  
  80. buildProfessionalExperience(): FormGroup {
  81. return this.fb.group({
  82. company: '',
  83. position: '',
  84. fromDate: '',
  85. toDate: '',
  86. jobDescription: ''
  87. });
  88. }
  89.  
  90. addSkills(skillsName: string): void {
  91. // console.log("this is the skill name");
  92. // console.log(skillsName);
  93. this.userSkillsRating.push(this.buildSkillsRating(skillsName));
  94. }
  95.  
  96. buildSkillsRating(buildSkillName: string): FormGroup {
  97. return this.fb.group({
  98. userSkillName: '',
  99. userSkillLevel: '',
  100. userSkillYear: ''
  101. });
  102. }
  103.  
  104. populateSkillName(): void {
  105. this.firstForm = JSON.parse(localStorage.getItem('firstForm'));
  106. this.firstForm.userSkills.map(data => this.addSkills(String(data.skillName)));
  107. }
  108.  
  109. ngOnInit() {
  110. this.loadingJquery();
  111.  
  112. this.additionalFormGroup = this.fb.group({
  113. experienceSummary: this.fb.array([ this.buildExperienceSummaryGroup() ], Validators.required),
  114. proffesionalExperience: this.fb.array([ this.buildProfessionalExperience() ], Validators.required),
  115. educationSummary: this.fb.array([ this.buildEducationSummary() ], Validators.required),
  116. userSkillsRating: this.fb.array([ this.populateSkillName() ], Validators.required)
  117. });
  118. }
  119.  
  120.  
  121.  
  122. }
  123.  
  124. <div class="container">
  125. <div class="row justify-content-md-center">
  126. <div class="col col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 ">
  127.  
  128. <div align="center" class="header ">
  129. <h3 class="title">Application Form</h3>
  130. </div>
  131.  
  132. <div class="content div-shadow">
  133.  
  134. <form
  135. [formGroup]="additionalFormGroup">
  136. <div class="row">
  137. <div class="col-md-12">
  138. <div class="form-group">
  139. <div class="col col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 " style="margin-bottom: 10px;">
  140. <h5>Additional Form (<span>required</span>) :</h5>
  141. </div>
  142. <div>
  143. <hr>
  144. <h5 class="formGroupLabel">Experience Summary</h5>
  145.  
  146. <button class="btn btn-info" type="button" style="margin-left: 40px;" (click)="addExperienceSummary()">Add</button>
  147. </div>
  148. <div class="experienceSummaryFormGroup" formArrayName="experienceSummary" *ngFor="let experience of experienceSummary.controls; let i=index">
  149. <div [formGroupName]="i">
  150. <div class="card">
  151. <div class="card-body">
  152. <button type="button" style="margin-top: 0px;" class="btn btn-danger" (click)="removeButton(experienceSummary, i)">Remove</button>
  153. <input type="text" class="form-control" id="{{ userExperience + i }}"
  154. placeholder="Write in a form of one sentence." formControlName="userExperience" style="margin-bottom: 5px;">
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. <hr>
  160. <h5 class="formGroupLabel">Professional Experience</h5>
  161.  
  162. <button type="button" class="btn btn-info" style="margin-left: 40px; color: white;" (click)="addProfessionalExperience()">Add</button>
  163.  
  164. <div class="professionalExperienceGroup" formArrayName="proffesionalExperience" *ngFor="let profExperience of proffesionalExperience.controls; let w=index">
  165. <div [formGroupName]="w">
  166. <div class="col-md-12">
  167.  
  168. <div class="card" style="margin-bottom: 5px;">
  169. <div class="card-body">
  170. <button type="button" class="btn btn-danger" (click)="removeButton(proffesionalExperience, w)">Remove</button>
  171. <input type="text" class="form-control" style="margin-bottom: 5px;" id="{{ company + w }}" placeholder="Company" formControlName="company">
  172. <input type="text" class="form-control" style="margin-bottom: 5px;" id="{{ position + w }}" placeholder="Position" formControlName="position">
  173. <div class="row">
  174. <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 ">
  175. <div class="form-group">
  176. <input type="text" class="form-control" style="margin-bottom: 5px;" id="{{ fromDate + w }}" placeholder="From" formControlName="fromDate">
  177. </div>
  178. </div>
  179. <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 ">
  180. <div class="form-group">
  181. <input type="text" class="form-control" style="margin-bottom: 5px;" id="{{ toDate + w }}" placeholder="To" formControlName="toDate">
  182. </div>
  183. </div>
  184. </div>
  185. <textarea id="{{ jobDescription + w }}" placeholder="Job Description" class="form-control" formControlName="jobDescription" cols="30" rows="10"></textarea>
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. </div>
  191. <hr>
  192. <h5 class="formGroupLabel">Education</h5>
  193.  
  194. <button type="button" class="btn btn-info" style="margin-left: 40px; color: white;" (click)="addEducationalSummary()">Add</button>
  195.  
  196. <div class="professionalExperienceGroup" formArrayName="educationSummary" *ngFor="let education of educationSummary.controls; let e=index">
  197. <div [formGroupName]="e">
  198. <div class="col-md-12">
  199.  
  200. <div class="card" style="margin-bottom: 5px;">
  201. <div class="card-body">
  202. <table class="table table-borderless">
  203. <tbody>
  204. <tr>
  205. <td>
  206. <button type="button" class="btn btn-danger" style="margin-top: 0px;" (click)="removeButton(educationSummary, e)">Remove</button>
  207. </td>
  208. <td>
  209. <input type="text" class="form-control" style="margin-bottom: 5px;" id="{{ school + e }}" placeholder="School" formControlName="school">
  210. </td>
  211. <td>
  212. <input type="text" class="form-control" style="margin-bottom: 5px;" id="{{ course + e }}" placeholder="Course" formControlName="course">
  213. </td>
  214. <td>
  215. <input type="text" class="form-control" style="margin-bottom: 5px;" id="{{ schoolFromDate + e }}" placeholder="From" formControlName="schoolFromDate">
  216. </td>
  217. <td>
  218. <input type="text" class="form-control" style="margin-bottom: 5px;" id="{{ schoolToDate + e }}" placeholder="To" formControlName="schoolToDate">
  219. </td>
  220. </tr>
  221. </tbody>
  222. </table>
  223. </div>
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228.  
  229. <hr>
  230.  
  231. <h5 class="formGroupLabel">Rate Skills(required): </h5>
  232. <div class="col-md-12">
  233. <div class="card" style="margin-bottom: 5px;">
  234. <div class="card-body">
  235. <table class="table table-borderless">
  236. <tbody>
  237. <tr formArrayName="userSkillsRating" *ngFor="let skill of userSkillsRating.controls; let r=index">
  238. <div [formGroupName]="r">
  239. <td>
  240. {{ userSkillName }}
  241. </td>
  242. <td>
  243. <div class="form-group">
  244. <label for="{{ userSkillLevel + r }}">Example select</label>
  245. <select class="form-control" id="{{ userSkillLevel + r }}" formControlName="userSkillLevel">
  246. <option disabled selected="true">Skill Rating</option>
  247. <option value="beginner">Beginner</option>
  248. <option value="intermediate">Intermediate</option>
  249. <option value="advance">Advance</option>
  250. </select>
  251. </div>
  252. </td>
  253. <td>
  254. <label for="{{ userSkillYear + r }}">Years of experience</label>
  255. <input type="text" class="form-control" id="{{ userSkillYear + r }}" placeholder="Specify years of experience" formControlName="userSkillYear">
  256. </td>
  257. </div>
  258. </tr>
  259. </tbody>
  260. </table>
  261. </div>
  262. </div>
  263. </div>
  264.  
  265.  
  266. </div>
  267. </div>
  268. </div>
  269. <button class="btn btn-secondary btn-lg btn-block background-primary" type="submit">Next</button>
  270. </form>
  271. </div>
  272. </div>
  273. </div>
  274.  
  275.  
  276. <div id="overlay" align="center">
  277. <div class="loader"></div>
  278. </div>
  279.  
  280.  
  281. </div>
  282.  
  283. get userSkillsRating(): FormArray {
  284. return <FormArray>this.additionalFormGroup.get('userSkillsRating');
  285. }
  286.  
  287. addSkills(skillsName: string): void {
  288. // console.log("this is the skill name");
  289. // console.log(skillsName);
  290. this.userSkillsRating.push(this.buildSkillsRating(skillsName));
  291. }
  292.  
  293. buildSkillsRating(buildSkillName: string): FormGroup {
  294. return this.fb.group({
  295. userSkillName: '',
  296. userSkillLevel: '',
  297. userSkillYear: ''
  298. });
  299. }
  300.  
  301. populateSkillName(): void {
  302. this.firstForm = JSON.parse(localStorage.getItem('firstForm'));
Add Comment
Please, Sign In to add comment