Skip to content

Commit

Permalink
Truyền dữ liệu khi mở form
Browse files Browse the repository at this point in the history
  • Loading branch information
anhducc13 committed Apr 5, 2019
1 parent 2ac62d3 commit 5822676
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 1 deletion.
96 changes: 95 additions & 1 deletion Management/src/app/exams/form/form.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit, EventEmitter, Output, Input} from '@angular/core';
import {Component, OnInit, EventEmitter, Output, Input, ViewChild, ElementRef} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {showAlert, SwalConfirm} from '../../shared/helper/notification';
import {ExamsService} from '../../shared/services/exams.service';
Expand All @@ -23,7 +23,101 @@ export class FormComponent implements OnInit {
private router: Router,
public ngProgress: NgProgress) {
}
@ViewChild('clearfileinputThumb') clearfileinputThumb: ElementRef;
listAnswer: any[] = [];
@Input() set seletedExam(seletedExam: IExam) {
if (seletedExam) {
this.currentExam = seletedExam;

if (this.clearfileinputThumb) {
this.clearfileinputThumb.nativeElement.click();
}
this.simpleSlider = this.currentExam.answers.length;
}
}

ckeConfig: any;
selectedThumb: File = null;
selectedExamPdf: File = null;
formExam: FormGroup;
statuses: any[] = [
{value: 'active', viewValue: 'active'},
{value: 'inactive', viewValue: 'inactive'},
];
specials: any[] = [
{value: 'active', viewValue: 'Top Post'},
{value: 'inactive', viewValue: 'Normal'},
];
levels: any[] = [
{value: 'dễ', viewValue: 'dễ'},
{value: 'trung bình', viewValue: 'trung bình'},
{value: 'khó', viewValue: 'khó'},
];
rates: any[] = [
{value: 1, viewValue: '1 Star'},
{value: 2, viewValue: '2 Star'},
{value: 3, viewValue: '3 Star'},
{value: 4, viewValue: '4 Star'},
{value: 5, viewValue: '5 Star'},
];
subjects: ISubject[] = [];
simpleSlider: any = 0;
isOnlineExam = false;
@Input('userLogin') userLogin: any;

currentExam: IExam;

ngOnInit(): void {
this.ckeConfig = ckeConfig;
this.getSubjects();
}

/*--------------------------------------------------------------
| Get subjects status: string, sort_field: string, sort_type: string, keyword: string
----------------------------------------------------------------*/
getSubjects() {
/*-------------------------------
| Todo: Get subject
---------------------------------*/
this._subjectService.getItems('all', 'name', 'asc', '')
.subscribe(
data => {
this.subjects = data;
},
error => this.reloadPageIfError(),
() => {
});
}

/*--------------------------------------------------------------
| isFieldValid(form: FormGroup, field: string) touched && !valid
----------------------------------------------------------------*/
isFieldValid(form: FormGroup, field: string) {
return !form.get(field).valid && form.get(field).touched;
}

/*--------------------------------------------------------------
| displayFieldCss(form: FormGroup, field: string)
----------------------------------------------------------------*/
displayFieldCss(form: FormGroup, field: string, autoField: boolean = false) {
return {
'has-error': this.isFieldValid(form, field),
'has-feedback': this.isFieldValid(form, field),
};
}

reloadPageIfError() {
SwalConfirm('Click Ok to reload the page', () => {
this.router.routeReuseStrategy.shouldReuseRoute = function () {
return false;
};
const currentUrl = this.router.url + '?';
this.router.navigateByUrl(currentUrl)
.then(() => {
this.router.navigated = false;
this.router.navigate([this.router.url]);
});
}, 'Server Error !', '500px', 'warning');
}

}
35 changes: 35 additions & 0 deletions Management/src/app/exams/list/list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,39 @@ export class ListComponent implements OnInit {
item.selected = this.selectAll;
});
}

@Output() sendExam = new EventEmitter<IExam>();
openForm(id) {
let exam: IExam = {
name: null,
status: null,
special: null,
ordering: null,
content: null,
thumb: null,
exam_pdf: null,
slug: null,
level: null,
rates: null,
price: null,
onlineExam: null,
timeStart: null,
answers: [],
time: null,
subject: {
id: null,
name: null
},
number_questions: null
};
this.allItems.forEach((value, index) => {
if (value._id === id) {
exam = value;
return;
}
});
// Create copy object exam
const copyExam = Object.assign({}, exam);
this.sendExam.emit(copyExam);
}
}

0 comments on commit 5822676

Please sign in to comment.