From 7400b4f216051d8b982f157eb2ed941f192bb85e Mon Sep 17 00:00:00 2001 From: dineshkumarkannan Date: Mon, 1 Oct 2018 18:09:13 +0530 Subject: [PATCH] template questions details master added : kdk --- ng6-seed/package.json | 2 + ng6-seed/src/app/app.routing.ts | 3 + .../src/app/shared/menu-items/menu-items.ts | 8 + .../template/questions/add/add.component.html | 77 ++++++ .../template/questions/add/add.component.scss | 3 + .../questions/add/add.component.spec.ts | 25 ++ .../template/questions/add/add.component.ts | 155 ++++++++++++ .../questions/edit/edit.component.html | 86 +++++++ .../questions/edit/edit.component.scss | 3 + .../questions/edit/edit.component.spec.ts | 25 ++ .../template/questions/edit/edit.component.ts | 191 +++++++++++++++ .../questions/list/list.component.html | 134 +++++++++++ .../questions/list/list.component.scss | 46 ++++ .../questions/list/list.component.spec.ts | 25 ++ .../template/questions/list/list.component.ts | 119 ++++++++++ .../template/questions/questions.module.ts | 109 +++++++++ .../template/questions/questions.routing.ts | 19 ++ .../service/masters/masters.service.spec.ts | 15 ++ .../service/masters/masters.service.ts | 223 ++++++++++++++++++ .../questions/questions.service.spec.ts | 12 + .../service/questions/questions.service.ts | 70 ++++++ ng6-seed/src/app/template/template.module.ts | 54 +++++ ng6-seed/src/app/template/template.routing.ts | 11 + ng6-seed/src/assets/styles/app.scss | 3 + package-lock.json | 3 + 25 files changed, 1421 insertions(+) create mode 100644 ng6-seed/src/app/template/questions/add/add.component.html create mode 100644 ng6-seed/src/app/template/questions/add/add.component.scss create mode 100644 ng6-seed/src/app/template/questions/add/add.component.spec.ts create mode 100644 ng6-seed/src/app/template/questions/add/add.component.ts create mode 100644 ng6-seed/src/app/template/questions/edit/edit.component.html create mode 100644 ng6-seed/src/app/template/questions/edit/edit.component.scss create mode 100644 ng6-seed/src/app/template/questions/edit/edit.component.spec.ts create mode 100644 ng6-seed/src/app/template/questions/edit/edit.component.ts create mode 100644 ng6-seed/src/app/template/questions/list/list.component.html create mode 100644 ng6-seed/src/app/template/questions/list/list.component.scss create mode 100644 ng6-seed/src/app/template/questions/list/list.component.spec.ts create mode 100644 ng6-seed/src/app/template/questions/list/list.component.ts create mode 100644 ng6-seed/src/app/template/questions/questions.module.ts create mode 100644 ng6-seed/src/app/template/questions/questions.routing.ts create mode 100644 ng6-seed/src/app/template/service/masters/masters.service.spec.ts create mode 100644 ng6-seed/src/app/template/service/masters/masters.service.ts create mode 100644 ng6-seed/src/app/template/service/questions/questions.service.spec.ts create mode 100644 ng6-seed/src/app/template/service/questions/questions.service.ts create mode 100644 ng6-seed/src/app/template/template.module.ts create mode 100644 ng6-seed/src/app/template/template.routing.ts create mode 100644 package-lock.json diff --git a/ng6-seed/package.json b/ng6-seed/package.json index 7dca4c1b4..299250298 100644 --- a/ng6-seed/package.json +++ b/ng6-seed/package.json @@ -31,6 +31,7 @@ "@swimlane/ngx-datatable": "11.1.5", "amazon-cognito-identity-js": "^2.0.27", "angular-calendar": "0.23.3", + "angular-notifier": "^4.1.1", "angular-sortablejs": "^2.0.6", "angular-tree-component": "6.1.0", "chart.js": "2.6.0", @@ -47,6 +48,7 @@ "ng2-charts": "1.6.0", "ng2-dragula": "1.3.1", "ng2-file-upload": "1.2.1", + "ng2-toastr": "^4.1.2", "ng2-validation": "4.2.0", "ngx-color-picker": "^4.0.3", "ngx-mat-select-search": "^1.3.1", diff --git a/ng6-seed/src/app/app.routing.ts b/ng6-seed/src/app/app.routing.ts index a4d27b61d..deeef0a53 100644 --- a/ng6-seed/src/app/app.routing.ts +++ b/ng6-seed/src/app/app.routing.ts @@ -22,6 +22,9 @@ export const AppRoutes: Routes = [{ ,{ path:'pdtrigger', loadChildren:'./pd-triger/pd-triger.module#PdTrigerModule' + },{ + path:'template', + loadChildren:'./template/template.module#TemplateModule' } ] }, { diff --git a/ng6-seed/src/app/shared/menu-items/menu-items.ts b/ng6-seed/src/app/shared/menu-items/menu-items.ts index ebc3fe320..ea4fde87b 100644 --- a/ng6-seed/src/app/shared/menu-items/menu-items.ts +++ b/ng6-seed/src/app/shared/menu-items/menu-items.ts @@ -44,6 +44,14 @@ const MENUITEMS : Menu[] = [ // children:[ // {state:'pdtriggerlist',name:'Pd Trigger Listing'} // ] + },{ + state: 'template', + name: 'Template', + type: 'sub', + icon: 'art_track', + children: [ + {state: 'questions', name: 'Questions'} + ] }, { state: 'authentication', diff --git a/ng6-seed/src/app/template/questions/add/add.component.html b/ng6-seed/src/app/template/questions/add/add.component.html new file mode 100644 index 000000000..48a04cea6 --- /dev/null +++ b/ng6-seed/src/app/template/questions/add/add.component.html @@ -0,0 +1,77 @@ +
+ +
+

{{pageTitle}}

+
+
+ +
+
+
+ +
+ + + {{ ct.categroy_name }} + + You must Select Category. + +
+
+ + + You must Include Question. + +
+
+ + + You must Include Description. + +
+
+ + + {{ ans.answer_type_name }} + + You must Select Answer Type. + +
+
+
+
+
+
+
+ + + + + +
+
+ + + +
+
+
+
+ + +
+
+ + +
+ + +
+ +
+
+
\ No newline at end of file diff --git a/ng6-seed/src/app/template/questions/add/add.component.scss b/ng6-seed/src/app/template/questions/add/add.component.scss new file mode 100644 index 000000000..6e263adae --- /dev/null +++ b/ng6-seed/src/app/template/questions/add/add.component.scss @@ -0,0 +1,3 @@ +.example-full-width{ + width: 100%; +} \ No newline at end of file diff --git a/ng6-seed/src/app/template/questions/add/add.component.spec.ts b/ng6-seed/src/app/template/questions/add/add.component.spec.ts new file mode 100644 index 000000000..fdcddf4c8 --- /dev/null +++ b/ng6-seed/src/app/template/questions/add/add.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AddComponent } from './add.component'; + +describe('AddComponent', () => { + let component: AddComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ AddComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AddComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/template/questions/add/add.component.ts b/ng6-seed/src/app/template/questions/add/add.component.ts new file mode 100644 index 000000000..60ccf36f4 --- /dev/null +++ b/ng6-seed/src/app/template/questions/add/add.component.ts @@ -0,0 +1,155 @@ +/** Common Imports */ +import { + Component, + OnInit, + Inject +} from '@angular/core'; + +import { + FormBuilder, + FormGroup, + Validators, + FormArray, +} from '@angular/forms'; + +import { + MatDialog, + MatDialogRef, + MAT_DIALOG_DATA +} from '@angular/material'; +/** Service */ +import { MastersService } from './../../service/masters/masters.service'; +import { QuestionsService } from './../../service/questions/questions.service'; + +@Component({ + selector: 'app-add', + templateUrl: './add.component.html', + styleUrls: ['./add.component.scss'] +}) +export class AddComponent implements OnInit { + + public pageTitle : string = "Add Question Details"; + public _addQuesFrom: FormGroup; + public submitted = false; + public categories: any = []; + public questionsOptions: any = []; + errorMessage: string; + + constructor(private _formBuilder: FormBuilder, + private dialogRef: MatDialogRef, + private masterService: MastersService, + private questionsService: QuestionsService) { } + + + ngOnInit() { + /** Questions Form Datas*/ + this._addQuesFrom = this._formBuilder.group({ + question: [null, Validators.compose([Validators.required])], + description: [null, Validators.compose([Validators.required])], + fk_question_catagory: [null, Validators.compose([Validators.required])], + fk_question_answertype: [null, Validators.compose([Validators.required])], + answers: this._formBuilder.array([ + this.initAnswers(), + ]) + }); + // OnInit Load Category and Question Type Masters + this.getCategoryListMaster(); + this.getQuestionOptionsMaster(); + + // /** For SelectDrop Datas*/ + // this._mastersService.getAllMasterData('CITY') + // .subscribe( + // data => { + + // if (data.status == 200) { + // this.citydatas = data.records; + // this.citydatas = this.citydatas.filter(city=>city.isactive == 1 ); + // } + + // }, error => this.errorMessage = error); + + } + + // convenience getter for easy access to form fields + get f() { return this._addQuesFrom.controls; } + + // Dynamic Form field creation Functionality : START ===> + initAnswers() { + return this._formBuilder.group({ + answer: ['', Validators.compose([Validators.required])] + }); + } + addLanguage(e) { + const control = this._addQuesFrom.controls['answers']; + control.push(this.initAnswers()); + } + removeLanguage(i: number) { + const control = this._addQuesFrom.controls['answers']; + control.removeAt(i); + } + + // END ===> + + getCategoryListMaster() { + this.masterService.getAllMasterData('QUESTIONCATEGORY').subscribe( + data => { + this.categories = data.records.filter(category => category.isactive == 1); + }, + error => { + this.errorMessage = "No Category Record Found."; + } + ) + } + getQuestionOptionsMaster() { + this.masterService.getAllMasterData('QUESTIONANSWERTYPE').subscribe( + data => { + this.questionsOptions = data.records; + }, + error => { + this.errorMessage = "No Answer Type Record Found."; + } + ) + } + + /** For Popup Close Button */ + onNoClick(): void { + this.dialogRef.close(); + } + + /** To Save/Edited Popup Data */ + onSubmit() { + this.submitted = true; + // stop here if form is invalid + if (this._addQuesFrom.invalid) { + this.errorMessage = "Please Fill All Mandate Fields."; + return; + } else { + var answerFormValues = this._addQuesFrom.value; + + //To Remove The "Null" With Key also + Object.keys(answerFormValues).forEach((key) => (answerFormValues[key] == null) && delete answerFormValues[key]); + + //Add BRANCH data with help Service File + this.questionsService.addQuestionMasterDetails(answerFormValues).subscribe( + dataresult => { + if (dataresult.status == 200) { + console.log(dataresult); + alert("sample alert for Saving"); + } + else { + this.errorMessage = "Some Thing Wents Wrong Try Again !"; + } + } , error => { + this.errorMessage = "Some Thing Wents Wrong Try Again !"; + this.dialogRef.close(); + }); + //After Saving the BRANCH data then popup close + // this.dialogRef.close(); + } + } + + /** To Reset Popup Data */ + onReset() { + this._addQuesFrom.reset(); + } +} diff --git a/ng6-seed/src/app/template/questions/edit/edit.component.html b/ng6-seed/src/app/template/questions/edit/edit.component.html new file mode 100644 index 000000000..6ee59cc58 --- /dev/null +++ b/ng6-seed/src/app/template/questions/edit/edit.component.html @@ -0,0 +1,86 @@ +
+ +
+

{{pageTitle}}

+
+
+ +
+
+ +
+ +
+ + + {{ ct.categroy_name }} + + You must Select Category. + +
+
+ + + You must Include Question. + +
+
+ + + You must Include Description. + +
+
+ + + {{ ans.answer_type_name }} + + You must Select Answer Type. + +
+
+
+
+
+
+
+ + + + + +
+
+ + + + +
+
+
+
+ + +
+
+
+ Active/InActive +
+ + +
+ + +
+ +
+
+
+ + \ No newline at end of file diff --git a/ng6-seed/src/app/template/questions/edit/edit.component.scss b/ng6-seed/src/app/template/questions/edit/edit.component.scss new file mode 100644 index 000000000..6e263adae --- /dev/null +++ b/ng6-seed/src/app/template/questions/edit/edit.component.scss @@ -0,0 +1,3 @@ +.example-full-width{ + width: 100%; +} \ No newline at end of file diff --git a/ng6-seed/src/app/template/questions/edit/edit.component.spec.ts b/ng6-seed/src/app/template/questions/edit/edit.component.spec.ts new file mode 100644 index 000000000..34ef921a1 --- /dev/null +++ b/ng6-seed/src/app/template/questions/edit/edit.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EditComponent } from './edit.component'; + +describe('EditComponent', () => { + let component: EditComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ EditComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EditComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/template/questions/edit/edit.component.ts b/ng6-seed/src/app/template/questions/edit/edit.component.ts new file mode 100644 index 000000000..726bb8e56 --- /dev/null +++ b/ng6-seed/src/app/template/questions/edit/edit.component.ts @@ -0,0 +1,191 @@ +/** Common Imports */ +import { + Component, + OnInit, + Inject +} from '@angular/core'; + +import { + FormBuilder, + FormGroup, + Validators, + FormArray, +} from '@angular/forms'; + +import { NotifierService } from 'angular-notifier'; + +import { + MatDialog, + MatDialogRef, + MAT_DIALOG_DATA +} from '@angular/material'; +/** Service */ +import { MastersService } from './../../service/masters/masters.service'; +import { QuestionsService } from './../../service/questions/questions.service'; + +@Component({ + selector: 'app-edit', + templateUrl: './edit.component.html', + styleUrls: ['./edit.component.scss'] +}) +export class EditComponent implements OnInit { + + + public pageTitle : string = "Edit Question Details"; + public _addQuesFrom: FormGroup; + public submitted = false; + public categories: any = []; + public questionsOptions: any = []; + errorMessage: string; + + + /** + * Notifier service + */ + private notifier: NotifierService; + + constructor( + notifier: NotifierService, + private _formBuilder: FormBuilder, + private dialogRef: MatDialogRef, + private masterService: MastersService, + private questionsService: QuestionsService, + @Inject(MAT_DIALOG_DATA) public data: any) { + this.notifier = notifier; + } + + ngOnInit() { + this.loadFormData(); + if (this.data["0"].length > 0) { + for (let val of this.data["0"]) { + // alert(JSON.stringify(val)); + let vals = val; + this.addLanguage(vals['answer'], vals['question_answer_id'], vals['isactive'], null); + } + } + + // OnInit Load Category and Question Type Masters + this.getCategoryListMaster(); + this.getQuestionOptionsMaster(); + } + + loadAnsData(){ + if (this.data["0"].length > 0) { + for (let val of this.data["0"]) { + // alert(JSON.stringify(val)); + let vals = val; + this.addLanguage(vals['answer'], vals['question_answer_id'], vals['isactive'], null); + } + } + } + + loadFormData() { + /** Questions Form Datas*/ + this._addQuesFrom = this._formBuilder.group({ + question_id: [this.data.question_id], + question: [this.data.question, Validators.compose([Validators.required])], + description: [this.data.description, Validators.compose([Validators.required])], + fk_question_catagory: [this.data.fk_question_catagory, Validators.compose([Validators.required])], + fk_question_answertype: [this.data.fk_question_answertype, Validators.compose([Validators.required])], + isactive:[this.data.isactive], + answers: this._formBuilder.array([ + // this.initAnswers(null, null), + ]) + }); + } + + get f_ans() { return this._addQuesFrom.get('answers'); } + + // convenience getter for easy access to form fields + get f() { return this._addQuesFrom.controls; } + + // Dynamic Form field creation Functionality : START ===> + initAnswers(ans, fk_id, isAct) { + isAct = isAct == null ? 1 : isAct; + return this._formBuilder.group({ + answer: [ans, Validators.compose([Validators.required])], + question_answer_id: [fk_id], + isactive: [isAct] + }); + } + addLanguage(ans, fk_id, isAct, e) { + const control = this._addQuesFrom.controls['answers']; + control.push(this.initAnswers(ans, fk_id, isAct)); + } + removeLanguage(i: number) { + const control = this._addQuesFrom.controls['answers']; + control.removeAt(i); + } + + // END ===> + + getCategoryListMaster() { + this.masterService.getAllMasterData('QUESTIONCATEGORY').subscribe( + data => { + this.categories = data.records.filter(category => category.isactive == 1); + }, + error => { + this.errorMessage = "No Category Record Found."; + } + ) + } + getQuestionOptionsMaster() { + this.masterService.getAllMasterData('QUESTIONANSWERTYPE').subscribe( + data => { + this.questionsOptions = data.records; + }, + error => { + this.errorMessage = "No Answer Type Record Found."; + } + ) + } + + /** For Popup Close Button */ + onNoClick(): void { + this.dialogRef.close(); + } + + /** To Save/Edited Popup Data */ + onSubmit() { + this.submitted = true; + // stop here if form is invalid + if (this._addQuesFrom.invalid) { + this.errorMessage = "Please Fill All Mandate Fields."; + return; + } else { + var answerFormValues = this._addQuesFrom.value; + + //To Remove The "Null" With Key also + Object.keys(answerFormValues).forEach((key) => (answerFormValues[key] == null) && delete answerFormValues[key]); + + //Add BRANCH data with help Service File + this.questionsService.updateQuestionMasterDetails(answerFormValues).subscribe( + dataresult => { + if (dataresult.status == 200) { + console.log(dataresult); + this.notifier.notify( 'success', 'Your Changes Updated!' ); + this.dialogRef.close(); + // this.notifierService('success', 'You are awesome! I mean it!'); + // alert("sample alert for Saving"); + } + else { + this.notifier.notify( 'warning', 'Something Wents Wrong Try Again !' ); + this.errorMessage = "Something Wents Wrong Try Again !"; + } + }, error => { + this.errorMessage = "Some Thing Wents Wrong Try Again !"; + this.dialogRef.close(); + }); + //After Saving the BRANCH data then popup close + // this.dialogRef.close(); + } + } + + /** To Reset Popup Data */ + onReset() { + // this._addQuesFrom.reset(); + this.loadFormData(); + this.loadAnsData(); + } + +} diff --git a/ng6-seed/src/app/template/questions/list/list.component.html b/ng6-seed/src/app/template/questions/list/list.component.html new file mode 100644 index 000000000..0ee433bb7 --- /dev/null +++ b/ng6-seed/src/app/template/questions/list/list.component.html @@ -0,0 +1,134 @@ +
+ + + +
+
Questions Master
+
List of Questions
+
+
+
+
+ + + + + + {{cat.categroy_name}} + + + + +
+
+
+ +
+
+ +
+ + +
+ +
+ +
+ +
+
+ {{ product.categroy_name }} +
+
+
{{ product.question }} +
+
+
+
+
+ + + + +
+
+ +
+
+
+ + + + + + + +
+
+ + + + \ No newline at end of file diff --git a/ng6-seed/src/app/template/questions/list/list.component.scss b/ng6-seed/src/app/template/questions/list/list.component.scss new file mode 100644 index 000000000..67712370e --- /dev/null +++ b/ng6-seed/src/app/template/questions/list/list.component.scss @@ -0,0 +1,46 @@ +// mat table css + +.example-container { + display: flex; + flex-direction: column; + min-width: 300px; +} + +.example-header { + min-height: 64px; + padding: 8px 24px 0; +} + +.mat-form-field { + font-size: 14px; +// width: 100%; +} + +.mat-table { + overflow: auto; + max-height: 500px; +} + +.text-line-limit { + text-overflow: ellipsis; + overflow: hidden; + // white-space: nowrap; + display: -webkit-box; + line-height: 16px; /* fallback */ + max-height: 32px; /* fallback */ + -webkit-line-clamp: 2; /* number of lines to show */ + -webkit-box-orient: vertical; + + // text-overflow: ellipsis; + // overflow: hidden; + // width: 160px; + // height: 1.2em; + // white-space: nowrap; +} + +.category-label { + padding: 2px 6px; + background: #629cff; + color: #fff; + box-shadow: 0 2px 3px #c8bbbb; +} diff --git a/ng6-seed/src/app/template/questions/list/list.component.spec.ts b/ng6-seed/src/app/template/questions/list/list.component.spec.ts new file mode 100644 index 000000000..beacd156f --- /dev/null +++ b/ng6-seed/src/app/template/questions/list/list.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ListComponent } from './list.component'; + +describe('ListComponent', () => { + let component: ListComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ListComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ListComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/template/questions/list/list.component.ts b/ng6-seed/src/app/template/questions/list/list.component.ts new file mode 100644 index 000000000..c670fd325 --- /dev/null +++ b/ng6-seed/src/app/template/questions/list/list.component.ts @@ -0,0 +1,119 @@ +import { Component, ViewChild, OnInit } from '@angular/core'; +import { MatPaginator, MatSort, MatTableDataSource, MatDialog, PageEvent} from '@angular/material'; +import { FormGroup, FormControl } from '@angular/forms'; +import { DataSource } from '@angular/cdk/table'; +import { Observable } from 'rxjs/Observable'; +import { QuestionsService } from './../../service/questions/questions.service'; +import { MastersService } from './../../service/masters/masters.service'; +/** Dialog Component */ +import { AddComponent } from './../add/add.component'; +import { EditComponent } from './../edit/edit.component'; + +@Component({ + selector: 'app-list', + templateUrl: './list.component.html', + styleUrls: ['./list.component.scss'] +}) +export class ListComponent implements OnInit { + + public productList: any[] = []; + public paginationList: any[] = []; + public categories: any = []; + public search_cid :any = null; + + public filterFormCtrl : FormControl = new FormControl(); + /** control for the MatSelect filter keyword */ + // public masterFilterCtrl: FormControl = new FormControl(); + + length = 50; + pageIndex = 0; + pageSize = 10; + + pageEvent: PageEvent; + + questionListData = null; + public dataLength: number; + public dataSource = new MatTableDataSource(); + displayedColumns = ['categroy_name', 'question', 'actions']; + + @ViewChild(MatPaginator) paginator: MatPaginator; + @ViewChild(MatSort) sort: MatSort; + + constructor(private dialog: MatDialog, + private questionsService: QuestionsService, + private masterService: MastersService) { + this.getQuestionsMasters(); + } + + getQuestionsMasters(){ + this.search_cid = this.filterFormCtrl.value; + console.log(this.filterFormCtrl); + this.questionsService.getQuestionMasterDetails(this.search_cid).subscribe( + data => { + this.productList = data.records; + this.questionListData = data.records; + // alert(this.userData); + this.dataLength = data.records.length; + this.dataSource.data = this.questionListData; + } + ) + } + + ngOnInit() { + this.getCategorMaster(); + } + + getCategorMaster() { + this.masterService.getAllMasterData('QUESTIONCATEGORY').subscribe( + data => { + this.categories = data.records.filter(category => category.isactive == 1); + }, + error => { + // this.errorMessage = "No Category Record Found."; + } + ) + } + + ngAfterViewInit() { + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + } + + applyFilter(filterValue: string) { + filterValue = filterValue.trim(); // Remove whitespace + filterValue = filterValue.toLowerCase(); // Datasource defaults to lowercase matches + this.dataSource.filter = filterValue; + } + + // add questions popup model call + addNewQuestion() { + const dialogRef = this.dialog.open(AddComponent, { + data: {} + }); + + dialogRef.afterClosed() + .subscribe(dataresult => { + this.getQuestionsMasters(); + // this.getBranch(); + // this.isPopupOpened = false; + }); + } + + editQuestion(rowDetails: any){ + const dialogRef = this.dialog.open(EditComponent, { + data: rowDetails + }); + + dialogRef.afterClosed() + .subscribe(dataresult => { + this.getQuestionsMasters(); + // this.getBranch(); + // this.isPopupOpened = false; + }); + } + + pageChange(e) { + console.log(e); + } + +} diff --git a/ng6-seed/src/app/template/questions/questions.module.ts b/ng6-seed/src/app/template/questions/questions.module.ts new file mode 100644 index 000000000..0c8a20bd5 --- /dev/null +++ b/ng6-seed/src/app/template/questions/questions.module.ts @@ -0,0 +1,109 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +import { NotifierModule, NotifierOptions } from 'angular-notifier'; +import { FlexLayoutModule } from '@angular/flex-layout'; +import { + MatCardModule, + MatIconModule, + MatInputModule, + MatRadioModule, + MatButtonModule,MatTableModule,MatPaginatorModule, + MatProgressBarModule,MatDialogModule, MatSortModule, + MatToolbarModule,MatSelectModule, + MatListModule, MatMenuModule, + MatCheckboxModule +} from '@angular/material'; +import {MatSlideToggleModule} from '@angular/material/slide-toggle'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { RouterModule } from '@angular/router'; + +// Questions Routing import +import { QuestionsRouting } from './questions.routing'; +// Questions List +import { ListComponent } from './list/list.component'; + +import { QuestionsService } from './../service/questions/questions.service'; +import { AddComponent } from './add/add.component'; +import { EditComponent } from './edit/edit.component'; +/* +* Question Master Module details +*/ + + +/** + * Custom angular notifier options + */ +const customNotifierOptions: NotifierOptions = { + position: { + horizontal: { + position: 'right', + distance: 12 + }, + vertical: { + position: 'top', + distance: 12, + gap: 10 + } + }, + theme: 'material', + behaviour: { + autoHide: 5000, + onClick: 'hide', + onMouseover: 'pauseAutoHide', + showDismissButton: true, + stacking: 4 + }, + animations: { + enabled: true, + show: { + preset: 'slide', + speed: 300, + easing: 'ease' + }, + hide: { + preset: 'fade', + speed: 300, + easing: 'ease', + offset: 50 + }, + shift: { + speed: 300, + easing: 'ease' + }, + overlap: 150 + } +}; + +@NgModule({ + imports: [ + CommonModule, + NotifierModule.withConfig(customNotifierOptions), + FlexLayoutModule, + MatCardModule, + MatIconModule, + MatInputModule, + MatRadioModule, + MatButtonModule,MatTableModule,MatPaginatorModule, + MatProgressBarModule,MatDialogModule, MatSortModule, + MatToolbarModule,MatSelectModule,MatListModule, MatMenuModule, + MatSlideToggleModule, + MatCheckboxModule, + FormsModule, + ReactiveFormsModule, + QuestionsRouting + ], + declarations: [ + ListComponent, + AddComponent, + EditComponent + ], + entryComponents: [ + AddComponent, + EditComponent + ], + providers: [ + QuestionsService + ] +}) +export class QuestionsModule { } diff --git a/ng6-seed/src/app/template/questions/questions.routing.ts b/ng6-seed/src/app/template/questions/questions.routing.ts new file mode 100644 index 000000000..0f07ea048 --- /dev/null +++ b/ng6-seed/src/app/template/questions/questions.routing.ts @@ -0,0 +1,19 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; +// Questions List +import { ListComponent } from './list/list.component'; +/* +* Question Master Router Module details +*/ +const routes: Routes = [ + { + path: '', + component: ListComponent + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) +export class QuestionsRouting {} diff --git a/ng6-seed/src/app/template/service/masters/masters.service.spec.ts b/ng6-seed/src/app/template/service/masters/masters.service.spec.ts new file mode 100644 index 000000000..2550bd5a4 --- /dev/null +++ b/ng6-seed/src/app/template/service/masters/masters.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { MastersService } from './masters.service'; + +describe('MastersService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [MastersService] + }); + }); + + it('should be created', inject([MastersService], (service: MastersService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/ng6-seed/src/app/template/service/masters/masters.service.ts b/ng6-seed/src/app/template/service/masters/masters.service.ts new file mode 100644 index 000000000..0448504d2 --- /dev/null +++ b/ng6-seed/src/app/template/service/masters/masters.service.ts @@ -0,0 +1,223 @@ +/** Common Import Section */ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs';//for Datatables +import { HttpClient } from '@angular/common/http'; +import { catchError } from 'rxjs/operators'; +import { of } from 'rxjs'; + +/** Imported Service Files Are., */ +import { AwsService } from '../../../AwsService/aws.service'; +//import { environment } from 'environments/environment'; + + +/** Consant Value For Created Date And Updated Date */ +const currentdate = new Date().toJSON().slice(0,19).replace('T',' '); + +/** Master Interface */ +export interface Master { + master_id:number; + master_name:string; + constant_name:string; +} + +@Injectable() + +export class MastersService { + + + private apiUrl = "http://ssa.sineedge.com/sparqapi/api/"; + + + constructor(private _http: HttpClient, + private _aws:AwsService) { } + + //headers:any = this._shared.headercofig(''); + + /** + * TO Add Master Datas using API Call + * 1st argument is "Records": any - Set of Data To Adding to database + * 2nd argument is "MasterName" :string - Table Name To Store the Records + */ + addMasterDetails(Records: any,MasterName:string): Observable { + Records.fk_createdby = this._aws.getlocale();//to get user id for who is created the Record + if(MasterName == 'COMPANY'){ + Records.company_master_createdon = currentdate;//to get Current date and Time for when the Record is created + } + else{ + Records.createdon = currentdate;//to get Current date and Time for when the Record is created + } + var ArrayData = { "master_name":MasterName, + "records": Records } + +// var data = this._http.post(this.apiUrl+'saveMaster',ArrayData); +// console.log('from service',data); + +return this._http.post(this.apiUrl+"saveMaster", ArrayData) +.pipe( + catchError(this.handleError('role', [])) + ) + + // return data; + } + + /** + * TO Edit Master Datas using API Call + * 1st argument is "Records": any - Set of Updated Data + * 2nd argument is "MasterName" :string - Table Name + */ + editMasterDetails(Records: any,MasterName:string): Observable { + + Records.fk_updatedby = this._aws.getlocale();//to get user id for who is update the record + Records.updatedon = currentdate;//to get Current date and Time for when the Record is updated + + var ArrayData = { "master_name":MasterName, + "records": Records } + + var data = this._http.post(this.apiUrl+'saveMaster',ArrayData); + + return data; + + } + + + /** + * TO Inactive the Master Datas using API Call + * Note : Which means To delete The records + * 1st argument is "PrimaryKeyWithValue" : any - Primarykey and its value + * 2nd argument is "MasterName" :string - Table Name + */ + deleteMasterDetails(PrimaryKeyWithValue:any,MasterName:string): Observable { + + //This "otherDatas" Array is common Argument For All Master + let otherDatas:any = {isactive:0, + fk_updatedby:this._aws.getlocale(), + updatedon:currentdate} + + //This "dataWithPrimaryKey" Array is Mergeing The 'PrimaryKeyWithValue' argument with otherDatas + let dataWithPrimaryKey = Object.assign(otherDatas,PrimaryKeyWithValue); + + var ArrayData = { "master_name":MasterName, + "records":JSON.parse(JSON.stringify(dataWithPrimaryKey)) + } + + return this._http.post(this.apiUrl+'saveMaster',ArrayData).pipe( + catchError(this.handleError('role', [])) + ); + // alert(data); + // return data; + } + + /** + * TO Get the Master Datas using API Call + * 1st argument is "TableName" :string - Table Name + */ + getAllMasterData(TableName:string): Observable { + return this._http.post(this.apiUrl+"getListOfMaster", { "master_name":TableName }) + .pipe( + catchError(this.handleError('role', [])) + ) + } + + /** + * TO get Branch Data For Listing Screen + */ + getAllBranch(): Observable { + return this._http.get(this.apiUrl+'getListOfBranches') + .pipe( + catchError(this.handleError('role', [])) + ) + + } + + + + /** + * TO get Subproduct Data For Listing Screen + */ + getAllSubProduct(): Observable { + + return this._http.get(this.apiUrl+'getListOfSubProduct') + .pipe( + catchError(this.handleError('role', [])) + ) + + } + + + /** + * TO get State Data For Listing Screen + */ + getAllState(): Observable { + + return this._http.get(this.apiUrl+'getListOfState') + .pipe( + catchError(this.handleError('role', [])) + ) + + + } + + /** + * TO get Company Data For Listing Screen + */ + getAllCompany(): Observable { + + return this._http.get(this.apiUrl+'getListOfCompany') + .pipe( + catchError(this.handleError('role', [])) + ) + + } + + /** + * TO get City Data For Listing Screen + */ + getAllCity(): Observable { + + return this._http.get(this.apiUrl+'getListOfCity') + .pipe( + catchError(this.handleError('role', [])) + ) + +} + + + /** Get All EntityType Data using API call With master Keyword */ + // getAllEntityType(): Observable { + // var EntityTypeArr = { + // "master_name":"ENTITYTYPE", + // } + // return this._http.post(this.apiUrl+'getListOfMaster',EntityTypeArr,{headers:this.headers}) + // .pipe( + // catchError(this.handleError('role', [])) + // ) + // } + + + + /** + * Seperated Records from the res + * argument 'res' : Response + */ + private extractData(res : Response) { + + let Response = res['_body']; + Response = JSON.parse(Response); + + return Response['dataStatus'] === true + ? Response['records'] + : []; + + } + + /** + * TO Handle The Error + */ + private handleError(operation = 'operation', result?: T) { + + return (error: any): Observable => { + return of(result as T); + }; +} +addCompanyDetails +} \ No newline at end of file diff --git a/ng6-seed/src/app/template/service/questions/questions.service.spec.ts b/ng6-seed/src/app/template/service/questions/questions.service.spec.ts new file mode 100644 index 000000000..831ec17b2 --- /dev/null +++ b/ng6-seed/src/app/template/service/questions/questions.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { QuestionsService } from './questions.service'; + +describe('QuestionsService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: QuestionsService = TestBed.get(QuestionsService); + expect(service).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/template/service/questions/questions.service.ts b/ng6-seed/src/app/template/service/questions/questions.service.ts new file mode 100644 index 000000000..1b532635c --- /dev/null +++ b/ng6-seed/src/app/template/service/questions/questions.service.ts @@ -0,0 +1,70 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpParams } from '@angular/common/http'; +import { Observable } from 'rxjs/Observable'; +import { catchError } from 'rxjs/operators'; +import { of } from 'rxjs'; +import 'rxjs/add/operator/map'; + +/** Imported Service Files Are., */ +import { AwsService } from '../../../AwsService/aws.service'; +/** Consant Value For Created Date And Updated Date */ +const currentdate = new Date().toJSON().slice(0, 19).replace('T', ' '); + + +@Injectable({ + providedIn: 'root' +}) + +/* +* Add , Edit, List, Delete Question Master API service End-point Call Functionality +* Kdk +*/ +export class QuestionsService { + private apiUrl = "http://ssa.sineedge.com/sparqapi/api/"; + private serviceUrl = 'https://jsonplaceholder.typicode.com/users'; + + constructor(private _http: HttpClient, + private _aws: AwsService) { } + + getUser(): Observable { + return this._http.get(this.serviceUrl); + } + + // get questions master details list + getQuestionMasterDetails(cid: any): Observable { + // Add safe, URL encoded search parameter if there is a search term + const options = cid ? + { params: new HttpParams().set('cid', cid) } : {}; + return this._http.get(this.apiUrl + "listAllQuestions/get", options); + } + + // add question master + addQuestionMasterDetails(Records: any): Observable { + Records.fk_createdby = this._aws.getlocale();//to get user id for who is created the Record + Records.createdon = currentdate;//to get Current date and Time for when the Record is created + return this._http.post(this.apiUrl + "saveNewQuestion", { 'records': Records}) + .pipe( + catchError(this.handleError('role', [])) + ) + } + + updateQuestionMasterDetails(Records: any): Observable { + Records.fk_updatedby = this._aws.getlocale();//to get user id for who is created the Record + Records.updatedon = currentdate;//to get Current date and Time for when the Record is created + return this._http.post(this.apiUrl + "saveExistQuestion", { 'records': Records}) + .pipe( + catchError(this.handleError('role', [])) + ) + } + + /** + * TO Handle The Error + */ + private handleError(operation = 'operation', result?: T) { + + return (error: any): Observable => { + return of(result as T); + }; + } + +} diff --git a/ng6-seed/src/app/template/template.module.ts b/ng6-seed/src/app/template/template.module.ts new file mode 100644 index 000000000..452fcd0cc --- /dev/null +++ b/ng6-seed/src/app/template/template.module.ts @@ -0,0 +1,54 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +import { + MatCardModule, + MatIconModule, + MatInputModule, + MatRadioModule, + MatButtonModule,MatTableModule,MatPaginatorModule, + MatProgressBarModule,MatDialogModule, MatSortModule, + MatToolbarModule,MatSelectModule } from '@angular/material'; +import {MatSlideToggleModule} from '@angular/material/slide-toggle'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload'; +import { TreeModule } from 'angular-tree-component'; +import { NgxDatatableModule } from '@swimlane/ngx-datatable'; +import { FlexLayoutModule } from '@angular/flex-layout'; + +import { DemoMaterialModule } from '../shared/demo.module'; +// import { NgxMatSelectSearchModule } from 'ngx-mat-select-search'; +import 'hammerjs'; +import { RouterModule } from '@angular/router'; + + +import { QuestionsModule } from './questions/questions.module'; +/** Template Routes */ +import { TemplateRoutes } from './template.routing'; + +/** Master Service */ +import { MastersService } from './service/masters/masters.service'; + + +// import { HttpClientModule } from '@angular/common/http'; +@NgModule({ + imports: [ + CommonModule, + RouterModule.forChild(TemplateRoutes), + QuestionsModule, + MatCardModule, + MatIconModule, + MatInputModule, + MatRadioModule, + MatButtonModule,MatTableModule,MatPaginatorModule, + MatProgressBarModule,MatDialogModule, MatSortModule, + MatToolbarModule,MatSelectModule, + FormsModule,ReactiveFormsModule, + // HttpClientModule, + ], + + providers:[ + MastersService + ] +}) +export class TemplateModule { } diff --git a/ng6-seed/src/app/template/template.routing.ts b/ng6-seed/src/app/template/template.routing.ts new file mode 100644 index 000000000..0aee5b6fd --- /dev/null +++ b/ng6-seed/src/app/template/template.routing.ts @@ -0,0 +1,11 @@ +import { Routes } from '@angular/router'; +import { QuestionsModule } from './questions/questions.module'; + +export const TemplateRoutes: Routes = [{ + path: '', + children:[{ + path:'questions', + loadChildren:'./questions/questions.module#QuestionsModule' + } +] +}] diff --git a/ng6-seed/src/assets/styles/app.scss b/ng6-seed/src/assets/styles/app.scss index d966db745..a5b6d83cc 100644 --- a/ng6-seed/src/assets/styles/app.scss +++ b/ng6-seed/src/assets/styles/app.scss @@ -45,3 +45,6 @@ Author: TrendSetter Themes @import "scss/material"; @import "scss/utilities/utilities"; + +/* Add application styles & imports to this file! */ +@import "~angular-notifier/styles"; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..48e341a09 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +}