Skip to content

Commit

Permalink
Fresh updates
Browse files Browse the repository at this point in the history
  • Loading branch information
RbkGh committed Feb 26, 2017
1 parent 869c456 commit 5e73a11
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 26 deletions.
18 changes: 18 additions & 0 deletions src/app/components/main-content/subject/subject.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@
</div>
</div>

<div class="panel-title text-capitalize text-blue">Is Subject A Practical Subject?(for example A subject done at the workshop or kitchen)</div>
<div class="row form-group m-b-40" id="isSubjectAPracticalSubjectId">
<div class="m-t-10 col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="radio radio-primary has-feedback">
<input type="radio" id="isSubjectAPracticalSubjectTrueId" formControlName="isSubjectAPracticalSubject" value=true
name="isSubjectAPracticalSubject" required checked>
<label for="isSubjectAPracticalSubjectTrueId">YES</label>
</div>
</div>
<div class="m-t-10 col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="radio radio-primary">
<input type="radio" id="isSubjectAPracticalSubjectFalseId" formControlName="isSubjectAPracticalSubject" name="isSubjectAPracticalSubject"
required value=false>
<label for="isSubjectAPracticalSubjectFalseId">NO</label>
</div>
</div>
</div>

<div class="panel-title text-capitalize text-blue">Choose Type of Subject</div>
<div class="row form-group m-b-40" id="subjectTypeId">
<div class="m-t-10 col-lg-6 col-md-6 col-sm-12 col-xs-12">
Expand Down
89 changes: 63 additions & 26 deletions src/app/components/main-content/subject/subject.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class SubjectComponent implements OnInit {
updateSubjectForm: FormGroup;

subjects: Array<SubjectEntity>;
currentSubjectBeforeUpdateModalInitiation:SubjectEntity;
currentSubjectBeforeUpdateModalInitiation: SubjectEntity;

isSubjectsListEmpty: boolean = false;
formIsValid: boolean = false;
Expand Down Expand Up @@ -121,6 +121,8 @@ export class SubjectComponent implements OnInit {
],
'subjectYearGroupList3': ['',
],
'isSubjectAPracticalSubject': [
Validators.required],
'subjectType': [
Validators.required]
},
Expand Down Expand Up @@ -176,11 +178,11 @@ export class SubjectComponent implements OnInit {
Validators.required],
'subjectCodeUpdate': [subject.subjectCode,
Validators.required],
'subjectYearGroupList1Update': [subjectYearGroupList1UpdateValue||false,
'subjectYearGroupList1Update': [subjectYearGroupList1UpdateValue || false,
],
'subjectYearGroupList2Update': [subjectYearGroupList2UpdateValue||false,
'subjectYearGroupList2Update': [subjectYearGroupList2UpdateValue || false,
],
'subjectYearGroupList3Update': [subjectYearGroupList3UpdateValue||false,
'subjectYearGroupList3Update': [subjectYearGroupList3UpdateValue || false,
],
'subjectTypeUpdate': [subject.subjectType,
Validators.required]
Expand Down Expand Up @@ -240,13 +242,14 @@ export class SubjectComponent implements OnInit {

};

formErrorsGetter():Array<Map<string,string>>{
formErrorsGetter(): Array<Map<string,string>> {
let formErrorsArray = new Array<Map<string,string>>();
let map = new Map<string,string>();
map.set('subjectFullName','');
map.set('subjectFullName', '');
formErrorsArray.push(map);
return formErrorsArray;
}

validationMessages = {
'subjectFullName': {
'required': 'Subject Full name is required.'
Expand Down Expand Up @@ -325,10 +328,11 @@ export class SubjectComponent implements OnInit {
addSubjectForm.value.subjectCode,
yearGroupsArray,
addSubjectForm.value.subjectType,
addSubjectForm.value.isSubjectAPracticalSubject,
null);
}

private prepareSubjectJsonToUpdate(updateSubjectForm: AbstractControl): SubjectEntity {
private prepareSubjectJsonToUpdate(updateSubjectForm: AbstractControl, currentSubjectObject: SubjectEntity): SubjectEntity {

console.log(updateSubjectForm);
let yearGroupsArray: Array<number> = new Array<number>();
Expand All @@ -348,30 +352,63 @@ export class SubjectComponent implements OnInit {
updateSubjectForm.value.subjectCodeUpdate,
yearGroupsArray,
updateSubjectForm.value.subjectTypeUpdate,
currentSubjectObject.isSubjectAPracticalSubject,
null);
}

CORE_SUBJECT_NOTATION: string = "CORE";
ELECTIVE_SUBJECT_NOTATION: string = "ELECTIVE";

isSubjectOkToBeSubmitted(subjectJsonObject: SubjectEntity): Map<boolean,string> {
let booleanStringRequest: Map<boolean,string> = new Map();
let isSubjectAPracticalSubject:boolean = subjectJsonObject.isSubjectAPracticalSubject;
let subjectTypeOfSubjectObject:string = subjectJsonObject.subjectType;
console.log("isSubjectAPracticalSubjectObject= "+isSubjectAPracticalSubject+", subjectTypeOfSubjectObject="+subjectTypeOfSubjectObject);
console.log("compring isSubjectAPracticalSubject === true response ===>"+(isSubjectAPracticalSubject === true));
if (isSubjectAPracticalSubject){
console.log("its a practical subject,check if type is elective")
console.log("subjectTypeOfSubjectObject ="+subjectTypeOfSubjectObject+" compared string="+this.ELECTIVE_SUBJECT_NOTATION);
if(subjectTypeOfSubjectObject === this.ELECTIVE_SUBJECT_NOTATION) {
booleanStringRequest.set(true, "Everything ok");
console.log(subjectTypeOfSubjectObject+" is the same as "+this.ELECTIVE_SUBJECT_NOTATION);
}else {
booleanStringRequest.set(false, "If Subject is a practical subject,it cannot be a core subject at the same time.");
}
} else {
booleanStringRequest.set(true,"Everything ok paaaa");
}
console.log("response =>",booleanStringRequest);
return booleanStringRequest;
}

public addSubject(addSubjectForm: AbstractControl): void {
this.accessingService = true;

let subjectJsonObject = this.prepareSubjectJson(addSubjectForm);
this.subjectService.createSubject(subjectJsonObject).subscribe(
(response: TutorResponsePayload) => {
this.accessingService = false;
console.info("response status = " + response.status);
if (response.status === 0) {
this.modalAddSubject.dismiss();
this.ngOnInit();
swal("Success", "Subject Added Successfully", "success");
} else {
swal("Error", response.message, "error");
let isSubjectOkToBeSubmittedMap: Map<boolean,string> = this.isSubjectOkToBeSubmitted(subjectJsonObject);
if (isSubjectOkToBeSubmittedMap.has(false)) {
console.info("message == " + isSubjectOkToBeSubmittedMap.get(false));
swal("Error", isSubjectOkToBeSubmittedMap.get(false), "error");
return;
} else {
this.accessingService = true;
this.subjectService.createSubject(subjectJsonObject).subscribe(
(response: TutorResponsePayload) => {
this.accessingService = false;
console.info("response status = " + response.status);
if (response.status === 0) {
this.modalAddSubject.dismiss();
this.ngOnInit();
swal("Success", "Subject Added Successfully", "success");
} else {
swal("Error", response.message, "error");
}
},
(error: any) => {
swal("Error", "Something went wrong,Try Again", "error");
console.log(error);
}
},
(error: any) => {
swal("Error", "Something went wrong,Try Again", "error");
console.log(error);
}
);
);
}
}

public openUpdateSubjectModal(subject: SubjectEntity): void {
Expand All @@ -382,7 +419,7 @@ export class SubjectComponent implements OnInit {

updateSubject(updateSubjectForm: FormGroup): void {
console.log(updateSubjectForm);
let subjectId:string = this.currentSubjectBeforeUpdateModalInitiation.id;
let subjectId: string = this.currentSubjectBeforeUpdateModalInitiation.id;
swal({
title: "Are you sure?",
text: "This will update information for this Subject !!",
Expand All @@ -401,7 +438,7 @@ export class SubjectComponent implements OnInit {
* always use arrow functions otherwise this collides with typescript's this,hence leading to undefined.
*/

this.subjectService.updateSubject(subjectId, this.prepareSubjectJsonToUpdate(updateSubjectForm)).subscribe(
this.subjectService.updateSubject(subjectId, this.prepareSubjectJsonToUpdate(updateSubjectForm, this.currentSubjectBeforeUpdateModalInitiation)).subscribe(
(response: SubjectResponsePayload) => {
if (response.status === 0) {
this.modalUpdateSubject.dismiss();
Expand Down
1 change: 1 addition & 0 deletions src/app/models/subject-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export class SubjectEntity {
public subjectCode:string,
public subjectYearGroupList:Array<number>,
public subjectType:string,
public isSubjectAPracticalSubject:boolean,
public allSubjectYearGroupsAllocated:boolean){}
}

0 comments on commit 5e73a11

Please sign in to comment.