Skip to content

Instantly share code, notes, and snippets.

@aarivalagan
Created August 12, 2018 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarivalagan/a9c1d22c1d6056da624f0968fb6cd59c to your computer and use it in GitHub Desktop.
Save aarivalagan/a9c1d22c1d6056da624f0968fb6cd59c to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
import { Router } from '@angular/router';
import { FormControl, FormGroup, FormBuilder, Validators, FormArray } from '@angular/forms';
import { TrainData } from '../Train/trainin.class';
import { QData } from '../Train/trainin.class';
import { DData } from '../Train/trainin.class';
import { VDataService } from '../Services/videoData.service';
@Component({
templateUrl: './ad.component.html'
})
export class AdComponent {
vForm: FormGroup;
Q_Form: FormGroup;
D_Form: FormGroup;
items: AngularFireList<TrainData[]>;
item: TrainData = new TrainData();
test: TrainData[] = [];
items1: AngularFireList<QData[]>;
item1: QData = new QData();
test1: QData[] = [];
items2: AngularFireList<DData[]>;
item2: DData = new DData();
test2: DData[] = [];
fileToUpload: File = null;
fileUploadService;;
constructor(private db: AngularFireDatabase, private router: Router, private fb: FormBuilder, private dataService: VDataService) {
this.createForm();
this.QForm();
this.DForm();
this.items = this.db.list('/newCour');
this.items1 = this.db.list('/newCour1');
this.items2 = this.db.list('/newCour2');
}
createForm() {
this.vForm = this.fb.group({
name: ['', Validators.required],
URL: ['', Validators.required],
em: ['', Validators.required],
q1: ['', Validators.required],
Opa: ['', Validators.required],
Opb: ['', Validators.required],
Opc: ['', Validators.required],
Opd: ['', Validators.required],
an1: ['', Validators.required],
Com: false,
isActive: true,
isQCom: false,
Score: 0,
file: ['', Validators.required]
});
}
QForm() {
this.Quiz_Form = this.fb.group({
cour_name: ['', Validators.required],
q_name: ['', Validators.required],
q1: ['', Validators.required],
Opa: ['', Validators.required],
Opb: ['', Validators.required],
Opc: ['', Validators.required],
Opd: ['', Validators.required],
an1: ['', Validators.required],
isQCompleted: false,
Score: 0,
});
}
DForm() {
this.D_Form = this.fb.group({
cour_name: ['', Validators.required],
file: ['', Validators.required]
});
}
publish() {
alert('Pusblished');
this.item.key = this.vForm.value.name;
this.item.an1 = this.vForm.value.an1;
this.item.Com = this.vForm.value.Com;
this.item.isActive = true;
this.item.isQCom = false;
this.item.Score = 0;
this.item.name = this.vForm.value.name;
this.item.URL = this.vForm.value.URL;
this.item.em = this.vForm.value.em;
this.item.Opa = this.vForm.value.Opa;
this.item.Opb = this.vForm.value.Optb;
this.item.Opc = this.vForm.value.Optc;
this.item.Opd = this.vForm.value.Optd;
this.item.q1 = this.vForm.value.q1;
this.item.file = this.vForm.value.file;
this.test.push(this.item);
this.db.list(`/newCourse/`).push(this.vForm.value);
console.log(this.vForm.value.name);
}
publishQ() {
alert('Pusblished');
this.item1.key = this.Q_Form.value.name;
this.item1.answer1 = this.Q_Form.value.an1;
// this.item.isActive = true;
this.item1.isQCom = false;
this.item1.Score = 0;
this.item1.cour_name = this.Q_Form.value.name;
this.item1.q_name = this.Q_Form.value.q_name;
this.item1.Opa = this.Q_Form.value.Opta;
this.item1.Opb = this.Q_Form.value.Optb;
this.item1.Opc = this.Q_Form.value.Optc;
this.item1.Opd = this.Q_Form.value.Optd;
this.item1.q1 = this.Q_Form.value.q1;
this.test1.push(this.item1);
this.db.list(`/newCourse1/`).push(this.Q_Form.value);
console.log(this.Q_Form.value.name);
}
publishD() {
alert('Pusblished');
this.item.key = this.D_Form.value.name;
this.item.file = this.D_Form.value.file;
this.test2.push(this.item);
// this.items.push(this.test);
this.db.list(`/newCour2/`).push(this.D_Form.value);
console.log(this.D_Form.value.name);
}
uploadFile(event) {
let files = event.target.files;
if (files.length > 0) {
console.log(this.vForm.value.file); // You will see the file
this.dataService.uploadFile(this.vForm.value.file);
}
}
handleFileInput(files: FileList) {
this.fileToUpload = files.item(0);
}
uploadFileToActivity() {
this.fileUploadService.postFile(this.fileToUpload).subscribe(data => {
// do something, if upload success
}, error => {
console.log(error);
});
}
UploadQuiz() {
this.QuizForm();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment