Guest User

Untitled

a guest
Oct 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. <div>
  2. <form>
  3. <div class="form-group">
  4. <label for="LogLocation-input">Select Your Location </label>
  5. <select type="text" id="LogLocation" name="LogLocation-input" [(ngModel)]="teacherLocInput" (ngModelChange)="basedOnLoc($event)" class="form-control">
  6. <option *ngFor="let loc of teacherLocationsData" [value]="loc.location">
  7. {{ loc.location }}
  8. </option>
  9. </select>
  10. </div>
  11.  
  12. <div class="form-group">
  13. <label for="TeacherName-input">Enter Teacher Name </label>
  14. <select type="text" id="TeacherName" name="TeacherName-input" [(ngModel)]="loggingInfo.ClassTimesTeacherName" class="form-control">
  15. <option *ngFor="let nam of filteredTeacherNames">
  16. {{ nam.name }}
  17. </option>
  18. </select>
  19. </div>
  20.  
  21.  
  22. <button type="button" class="btn btn-primary" (click)="addOrUpdateLoggingRecord($event);">Save</button>
  23.  
  24. <h2 *ngIf="!loggingInfo || loggingInfo.id === undefined">Add record</h2>
  25.  
  26. <h2 *ngIf="loggingInfo && loggingInfo.id !== undefined">Update record (ID: )</h2>
  27.  
  28. </form>
  29. </div>
  30.  
  31. import { Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
  32. import { TimeService } from '../time.service';
  33.  
  34.  
  35. @Component({
  36. selector: 'app-update',
  37. templateUrl: './update.component.html',
  38. styleUrls: ['./update.component.css']
  39. })
  40. export class UpdateComponent implements OnInit {
  41. @Output() loggingCreated = new EventEmitter<any>();
  42. @Input() loggingInfo: any;
  43. public buttonText = 'Save';
  44. public teacherLocationsData: Array<any>;
  45. public teacherNameData: Array<any>;
  46. public filteredTeacherNames: Array<any>;
  47.  
  48. private _teacherLocInput: string;
  49. get teacherLocInput(): string {
  50. return this._teacherLocInput;
  51. }
  52. set teacherLocInput(value: string) {
  53. this._teacherLocInput = value;
  54. this.filteredTeacherNames = this.filterTeachers(value);
  55. }
  56.  
  57. filterTeachers(teacherLocInput: string) {
  58. return this.teacherNameData.filter(teacher => teacher.location === this.teacherLocInput);
  59. }
  60.  
  61.  
  62. constructor(private timeService: TimeService) {
  63. this.clearAllInfo();
  64. timeService.getTeacherLocation().subscribe((importLocations: any) => this.teacherLocationsData = importLocations);
  65. }
  66.  
  67. ngOnInit() {
  68. // not sure if needed
  69. this.teacherNameData;
  70.  
  71. }
  72.  
  73. basedOnLoc(val:any) {
  74. // not sure if this is calling API
  75. this.customFunction(val);
  76. }
  77.  
  78. // gets called on the change event of location selected
  79. customFunction(val:any) {
  80. this.teacherLocInput = val;
  81. this.timeService.getTeacherName().subscribe((importTeacherName: any) => this.teacherNameData = importTeacherName);
  82. }
  83.  
  84.  
  85.  
  86. private clearAllInfo = function() {
  87. // Create an empty logging object
  88. this.loggingInfo = {
  89. id: undefined,
  90. date: '',
  91. ClassTimesStudentID: '',
  92. ClassTimesStudentName:'',
  93. ClassTimesSubjects: '',
  94. ClassTimesLogLocation: '',
  95. ClassTimesTeacherID: '',
  96. ClassTimesTeacherName: '',
  97. ClassTimesLogOff: '',
  98. timeInSeconds: 0,
  99. distanceInMeters: 0
  100. };
  101. };
  102.  
  103. public addOrUpdateLoggingRecord = function(event) {
  104. this.loggingCreated.emit(this.loggingInfo);
  105. this.clearAllInfo();
  106. console.log(this.LoggingIfo);
  107. };
  108.  
  109.  
  110. }
Add Comment
Please, Sign In to add comment