links in Toc

This commit is contained in:
annampak 2017-11-02 16:46:43 +02:00
parent 7e19087bb6
commit fdf54f77e8
8 changed files with 103 additions and 45 deletions

View File

@ -12,6 +12,7 @@ export class GroupBase<T>{
section:string;
style:string;
class: string;
page: number;
constructor(options: {
value?: T,
@ -24,7 +25,8 @@ export class GroupBase<T>{
controlType?: string
section?: string,
style?:string
class?:string
class?:string,
page?:number
} = {}) {
this.value = options.value;
this.key = options.key || '';
@ -37,5 +39,6 @@ export class GroupBase<T>{
this.section = options.section || '';
this.style = options.style || '';
this.class = options.class || '';
this.page = options.page || 1;
}
}

View File

@ -44,7 +44,7 @@
</div>
<div class="panel-body" id="collapse-panel" class="panel-collapse">
<div *ngIf="dataModel.groups.length">
<toc [dataModel]="dataModel"></toc>
<toc [dataModel]="dataModel" (setPage)="setPage(page)"></toc>
</div>
</div>
</div>

View File

@ -74,9 +74,8 @@ export class DynamicFormComponent implements OnInit {
this.id = params.id;
this.datasetId = params.datasetId;
//this.datasetProperties = params.datasetProperties
});
this.serverService.getDatasetProfileByID(this.id).subscribe(
});
this.serverService.getDatasetProfileByID(this.id).subscribe(
response => {
@ -100,7 +99,7 @@ export class DynamicFormComponent implements OnInit {
this.dataModel = new DataModel();
this.dataModel = this.dataModelService.getDataModel(data);
this.dataModel = this.dataModelService.getDataModel(data);debugger;
this.form = this.qcs.toFormGroup(this.dataModel.fields, this.dataModel.groups);
@ -148,10 +147,9 @@ export class DynamicFormComponent implements OnInit {
}
);
this.serverService.getDatasetByID(this.datasetId).subscribe(
(data) => {
var flatList;
if(data.properties){
console.log("Found already submitted form, loading that one!");
@ -160,12 +158,16 @@ export class DynamicFormComponent implements OnInit {
let formValues = JSON.parse(data.properties);
var flatList = flatten(formValues);
flatList = flatten(formValues);
this.patchForm(flatList);
}
//η κληση για το dataset profile pou htan prin pio panw anexarthth
//end- klhsh gia to dataset profiel
},
(err) => {
@ -244,14 +246,15 @@ export class DynamicFormComponent implements OnInit {
if (page < 1 || page > this.pagination.totalPages) {
return;
}
var pagesize = 3;
// get pagination object from service
this.pagination = this.pagerService.getPagination(this.dataModel.groups.length, page);
this.pagination = this.pagerService.getPagination(this.dataModel.groups,this.dataModel.groups.length, page, pagesize);
// get current page of items
this.dataModel.sections.forEach(section => {
if(section.groupFields.length > 0){
section.groupFields = this.dataModel.groups.slice(this.pagination.startIndex, this.pagination.endIndex + 1);
section.groupFields = this.dataModel.groups.slice(this.pagination.startIndex, this.pagination.endIndex + 1);
}
});
//this.dataModel.groups = this.dataModel.groups.slice(this.pager.startIndex, this.pager.endIndex + 1);

View File

@ -43,7 +43,7 @@ export class DynamicFormFieldComponent {
public ngOnInit() { //dropdown lists take only one of the available sources
for (var i = 0, len = this.dataModel.groups.length; i < len; i++) {
let dropdownField: any;
dropdownField = this.dataModel.groups[i].groupFields.find(x => x.controlType == "dropdown");
dropdownField = this.dataModel.groups[i].groupFields.find(x => x.controlType == "dropdown");
if (dropdownField != undefined) {
if (dropdownField.attributes.sources != undefined)
dropdownField.options = dropdownField.attributes.sources[0].params;

View File

@ -5,7 +5,7 @@
<div *ngFor="let group of dataModel.groups"> <!-- All contents in the first page -->
<ul>
<li>
<a (click)='scrollToElemID(group.key)'>{{group.title}}</a>
<a (click)='scrollToElemID(group.key, group.page)'>{{group.title}} {{group.page}}</a>
<ul *ngFor="let field of group.groupFields">
<li *ngIf="field.visible == 'true'">
<a (click)='scrollToElemID(field.key)'>{{field.label}}</a>

View File

@ -1,4 +1,4 @@
import { Component, OnInit, Input } from '@angular/core';
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { DataModel } from '../../entities/DataModel';
//import * as $ from '../../../../node_modules/jquery/dist/jquery'
@ -15,6 +15,9 @@ export class TocComponent implements OnInit{
@Input() dataModel: DataModel;
private headers = new Array();
@Output()
setPage:EventEmitter<string> = new EventEmitter();
ngOnInit(){
var len = this.dataModel.groups.length; // I don't use headers , I use datamodel.groupfields
for (var i=0; i<len; i++){
@ -23,8 +26,9 @@ export class TocComponent implements OnInit{
}
scrollToElemID(elemID){
scrollToElemID(elemID, page){
console.log("going to id:"+elemID)
this.setPage.emit(page);
scroll("#"+elemID);
}

View File

@ -224,42 +224,78 @@ export class dataModelBuilder {
if (attr.sources) {
newAttribute.sources.push(attr.sources.source);
for (var i = 0; i < attr.sources.source.length; i++) {
if (attr.sources.source[i].url !== undefined) {
if (attr.sources.source.length != undefined) {
for (var i = 0; i < attr.sources.source.length; i++) {
if (attr.sources.source[i].url !== undefined) {
fields.find(x => x.key == newAttribute.id).url.url = attr.sources.source[i].url._value;
fields.find(x => x.key == newAttribute.id).url.url = attr.sources.source[i].url._value;
this.restBase.proxy_get(attr.sources.source[i].url._value).subscribe((data) => {
console.log(data);
newAttribute.sources.forEach(src => {
src.params = new Array();
data.data.forEach(data => {
let prm = new Param();
prm.key = data.id;
prm.value = data.attributes.name;
src.params.push(prm);
this.restBase.proxy_get(attr.sources.source[i].url._value).subscribe((data) => {
console.log(data);
newAttribute.sources.forEach(src => {
src.params = new Array();
data.data.forEach(data => {
let prm = new Param();
prm.key = data.id;
prm.value = data.attributes.name;
src.params.push(prm);
});
});
});
break;
} else {
newAttribute.sources.forEach(src => {
});
break;
} else {
newAttribute.sources.forEach(src => {
src.params = new Array();
for (var i = 0, len = attr.sources.source[i].value.length; i < len; i++) {
let prm = new Param();
prm.key = attr.sources.source[i].value[i]._value;
prm.value = attr.sources.source[i].value[i]._label;
src.params.push(prm);
}
src.params = new Array();
for (var i = 0, len = attr.sources.source[i].value.length; i < len; i++) {
let prm = new Param();
prm.key = attr.sources.source[i].value[i]._value;
prm.value = attr.sources.source[i].value[i]._label;
src.params.push(prm);
}
});
});
}
}
}
if (attr.sources.source.url !== undefined) {
fields.find(x => x.key == newAttribute.id).url.url = attr.sources.source.url._value;
this.restBase.proxy_get(attr.sources.source.url._value).subscribe((data) => {
console.log(data);
newAttribute.sources.forEach(src => {
src.params = new Array();
data.data.forEach(data => {
let prm = new Param();
prm.key = data.id;
prm.value = data.attributes.name;
src.params.push(prm);
});
});
});
} else {
newAttribute.sources.forEach(src => {
src.params = new Array();
for (var i = 0, len = attr.sources.source.value.length; i < len; i++) {
let prm = new Param();
prm.key = attr.sources.source.value[i]._value;
prm.value = attr.sources.source.value[i]._label;
src.params.push(prm);
}
});
}
}

View File

@ -1,8 +1,20 @@
export class PaginationService {
getPagination(totalGroups: number, currentPage: number = 1, pageSize: number = 3) {
getPagination(groups, totalGroups: number, currentPage: number = 1, pageSize: number = 3) {
// calculate total pages
let totalPages = Math.ceil(totalGroups / pageSize);
//each group get the number of its page for toc linking
for (var x = 0; x < totalPages ; x++) {debugger;
for (var i = 0; i < pageSize; i++) {
if (x==0)
groups[i].page = x+1;
else
groups[i+pageSize].page = x+1;
};
}
let startPage: number, endPage: number;
if (totalPages <= 10) {
// less than 10 total pages so show all
@ -28,8 +40,8 @@ export class PaginationService {
// create an array of pages to ng-repeat in the pagination control
let pages = [];
for (var i = 1; i <endPage + 1; i++)
pages.push(i);
for (var i = 1; i < endPage + 1; i++)
pages.push(i);
// return object with all pagination properties required by the view
return {