Toc navigate to the same page, pagination cursor
This commit is contained in:
parent
996491cebe
commit
bb98e7cfcf
|
@ -17,7 +17,9 @@ const appRoutes: Routes = [
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
RouterModule.forRoot(
|
RouterModule.forRoot(
|
||||||
appRoutes)
|
appRoutes
|
||||||
|
// { enableTracing: true } // <-- debugging purposes only
|
||||||
|
)
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
RouterModule
|
RouterModule
|
||||||
|
|
|
@ -48,24 +48,22 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<p>Angular 2 - Pagination Example with logic like Google</p>
|
|
||||||
|
|
||||||
<!-- pagination -->
|
<!-- pagination -->
|
||||||
<ul *ngIf="pagination.pages && pagination.pages.length" class="pagination">
|
<ul *ngIf="pagination.pages && pagination.pages.length" class="pagination">
|
||||||
<li [ngClass]="{disabled:pagination.currentPage === 1}">
|
<li [ngClass]="{disabled:pagination.currentPage === 1}">
|
||||||
<a (click)="setPage(1)">First</a>
|
<a (click)="setPage(1)" class="cursor-link" >First</a>
|
||||||
</li>
|
</li>
|
||||||
<li [ngClass]="{disabled:pagination.currentPage === 1}">
|
<li [ngClass]="{disabled:pagination.currentPage === 1}">
|
||||||
<a (click)="setPage(pagination.currentPage - 1)">Previous</a>
|
<a (click)="setPage(pagination.currentPage - 1)" class="cursor-link">Previous</a>
|
||||||
</li>
|
</li>
|
||||||
<li *ngFor="let page of pagination.pages" [ngClass]="{active:pagination.currentPage === page}">
|
<li *ngFor="let page of pagination.pages" [ngClass]="{active:pagination.currentPage === page}">
|
||||||
<a (click)="setPage(page)">{{page}}</a>
|
<a (click)="setPage(page)" class="cursor-link">{{page}}</a>
|
||||||
</li>
|
</li>
|
||||||
<li [ngClass]="{disabled:pagination.currentPage === pagination.totalPages}">
|
<li [ngClass]="{disabled:pagination.currentPage === pagination.totalPages}">
|
||||||
<a (click)="setPage(pagination.currentPage + 1)">Next</a>
|
<a (click)="setPage(pagination.currentPage + 1)" class="cursor-link">Next</a>
|
||||||
</li>
|
</li>
|
||||||
<li [ngClass]="{disabled:pagination.currentPage === pagination.totalPages}">
|
<li [ngClass]="{disabled:pagination.currentPage === pagination.totalPages}">
|
||||||
<a (click)="setPage(pagination.totalPages)">Last</a>
|
<a (click)="setPage(pagination.totalPages)" class="cursor-link">Last</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -23,10 +23,11 @@ export class DynamicFormComponent implements OnInit {
|
||||||
form: FormGroup;
|
form: FormGroup;
|
||||||
payLoad = '';
|
payLoad = '';
|
||||||
@Input() dirtyValues: number = 0;
|
@Input() dirtyValues: number = 0;
|
||||||
|
|
||||||
// pagination object
|
// pagination object
|
||||||
@Input() pagination: any = {};
|
@Input() pagination: any = {};
|
||||||
|
|
||||||
|
private fragment: string;
|
||||||
|
|
||||||
constructor(private qcs: FieldControlService, private serverService: ServerService, private dataModelService: dataModelBuilder, private router: Router,
|
constructor(private qcs: FieldControlService, private serverService: ServerService, private dataModelService: dataModelBuilder, private router: Router,
|
||||||
private route: ActivatedRoute, private pagerService: PaginationService) {
|
private route: ActivatedRoute, private pagerService: PaginationService) {
|
||||||
this.form = this.qcs.toFormGroup(new Array(), new Array());
|
this.form = this.qcs.toFormGroup(new Array(), new Array());
|
||||||
|
@ -40,6 +41,8 @@ export class DynamicFormComponent implements OnInit {
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
||||||
|
this.route.fragment.subscribe(fragment => { this.fragment = fragment; }); //navigate to certain section of the page
|
||||||
|
|
||||||
console.log("DynamicFormComponent.ngOnInit() -- RUNNIGN");
|
console.log("DynamicFormComponent.ngOnInit() -- RUNNIGN");
|
||||||
let id = this.route.snapshot.paramMap.get('id'); //get the project id
|
let id = this.route.snapshot.paramMap.get('id'); //get the project id
|
||||||
|
|
||||||
|
@ -96,6 +99,12 @@ export class DynamicFormComponent implements OnInit {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngAfterViewChecked(): void { //navigate to certain section of the page
|
||||||
|
try {
|
||||||
|
document.querySelector('#' + this.fragment).scrollIntoView();
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
this.payLoad = JSON.stringify(this.form.value);
|
this.payLoad = JSON.stringify(this.form.value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
|
|
||||||
<div *ngSwitchCase="'radiobox'">
|
<div *ngSwitchCase="'radiobox'">
|
||||||
<ng-container *ngFor="let answrBase of field.answers">
|
<ng-container *ngFor="let answrBase of field.answers">
|
||||||
<div style="display: inline-block;margin-right:10px;">
|
<div style="display: inline-block;margin-right:10px;" [id]="field.key">
|
||||||
<label for="{{answrBase.id}}" style="padding: 8px 10px; padding-right:5px;">{{answrBase.answer}}</label>
|
<label for="{{answrBase.id}}" style="padding: 8px 10px; padding-right:5px;">{{answrBase.answer}}</label>
|
||||||
<input type="radio" [formControlName]="field.key" [id]= "answrBase.id" [value]= "answrBase" [(ngModel)]="field.value" (change) = "toggleVisibility($event, field)" [required]="field.required"/>
|
<input type="radio" [formControlName]="field.key" [id]= "answrBase.id" [value]= "answrBase" [(ngModel)]="field.value" (change) = "toggleVisibility($event, field)" [required]="field.required"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { DataModel } from '../../entities/DataModel';
|
import { DataModel } from '../../entities/DataModel';
|
||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
import { FormGroup, ValidatorFn, AbstractControl, Validators } from '@angular/forms';
|
import { FormGroup, ValidatorFn, AbstractControl, Validators } from '@angular/forms';
|
||||||
|
import { ActivatedRoute} from '@angular/router';
|
||||||
|
|
||||||
import { FieldBase } from './field-base';
|
import { FieldBase } from './field-base';
|
||||||
import { GroupBase } from '../../form/dynamic-form-group/group-base';
|
import { GroupBase } from '../../form/dynamic-form-group/group-base';
|
||||||
|
@ -18,6 +19,10 @@ export class DynamicFormFieldComponent {
|
||||||
@Input() field: FieldBase<any>;
|
@Input() field: FieldBase<any>;
|
||||||
@Input() form: FormGroup;
|
@Input() form: FormGroup;
|
||||||
|
|
||||||
|
private fragment: string;
|
||||||
|
|
||||||
|
constructor (private route: ActivatedRoute){}
|
||||||
|
|
||||||
get isValid() {
|
get isValid() {
|
||||||
return this.form.controls[this.field.key].valid;
|
return this.form.controls[this.field.key].valid;
|
||||||
}
|
}
|
||||||
|
@ -41,8 +46,15 @@ export class DynamicFormFieldComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.route.fragment.subscribe(fragment => { this.fragment = fragment; }); //navigate to certain section of the page
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngAfterViewChecked(): void { //navigate to certain section of the page
|
||||||
|
try {
|
||||||
|
document.querySelector('#' + this.fragment).scrollIntoView();
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
ruleVisibleMethod(field, rule, dataModel) { //visibility rule -- checks if target field is visible
|
ruleVisibleMethod(field, rule, dataModel) { //visibility rule -- checks if target field is visible
|
||||||
dataModel.fields.forEach(fld => {
|
dataModel.fields.forEach(fld => {
|
||||||
if (fld.label == rule._target && fld.visible == true)
|
if (fld.label == rule._target && fld.visible == true)
|
||||||
|
|
|
@ -2,11 +2,28 @@
|
||||||
<nav id="toc" data-toggle="toc">
|
<nav id="toc" data-toggle="toc">
|
||||||
<ul class="nav flex-column">
|
<ul class="nav flex-column">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<div *ngFor="let group of dataModel.groups">
|
<div *ngFor="let section of dataModel.sections">
|
||||||
|
<div *ngFor="let group of section.groupFields">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a class="nav-link" href="#{{group.key}}">{{group.title}}</a>
|
<li><a class="nav-link" [routerLink]="['.']" fragment="{{group.key}}">{{group.title}}</a>
|
||||||
<ul *ngFor="let field of group.groupFields">
|
<ul *ngFor="let field of group.groupFields">
|
||||||
<li *ngIf= "field.visible == 'true'" >
|
<li *ngIf="field.visible == 'true'">
|
||||||
|
<a class="nav-link" [routerLink]="['.']" fragment="{{field.key}}">{{field.label}}</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!-- <div *ngFor="let group of dataModel.groups">
|
||||||
|
<ul>
|
||||||
|
<li><a class="nav-link" [routerLink]="['.']" fragment="{{group.key}}">{{group.title}}</a>
|
||||||
|
<ul *ngFor="let field of group.groupFields">
|
||||||
|
<li *ngIf="field.visible == 'true'">
|
||||||
<a class="nav-link" href="#field.key">{{field.label}}</a>
|
<a class="nav-link" href="#field.key">{{field.label}}</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -15,7 +32,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div> -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -66,3 +66,7 @@ body {
|
||||||
border: 2px solid #A11515;
|
border: 2px solid #A11515;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cursor-link{
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue