load datatables afte save. minor fixes

This commit is contained in:
annampak 2017-10-27 19:38:31 +03:00
parent 294e113a05
commit bed9322767
5 changed files with 92 additions and 22 deletions

View File

@ -9,6 +9,8 @@ import { DataTable, DataTableTranslations, DataTableResource } from 'angular-4-d
import { DropdownField } from '../../app/form/fields/dropdown/field-dropdown';
import { Param } from '../entities/model/param';
declare var $ :any;
@Component({
selector: 'datasets-table',
templateUrl: 'dataset.html',
@ -39,7 +41,7 @@ export class DatasetsComponent implements OnInit{
@Input() dmpIdforDatasets: string;
dataset:any;
@ViewChild(DataTable) projectsTable;
//@ViewChild(DataTable) projectsTable;
dataSetValue:boolean
@Input()
@ -74,7 +76,7 @@ export class DatasetsComponent implements OnInit{
}
ngOnInit() {
ngOnInit() {debugger;
//this.projects = this.serverService.getDummyProjects();
this.datasets = [];
console.log(this.dmpIdforDatasets);
@ -115,7 +117,7 @@ export class DatasetsComponent implements OnInit{
reloadDatasets(params) {
this.datasetResource = new DataTableResource(this.datasets);
this.datasetResource.query(params).then(projects => this.datasets = projects);
this.datasetResource.query(params).then(datasets => this.datasets = datasets);
}
afterLoad(){
@ -133,8 +135,29 @@ SaveNewDataset(){debugger;
this.serverService.createDatasetForDmp(this.dataset).subscribe(
response=>{
console.log(response);
}
)
$("#newDatasetModal").modal("hide");
this.serverService.getDatasetForDmp({"id":this.dmpIdforDatasets}).subscribe(
response => {
console.log("response");
console.log(response);
this.datasets = [];
response.forEach(resp => {
let dt = new Dataset();
dt.id = resp.id;
dt.name = resp.label;
dt.uriDataset = resp.uri;
this.datasets.push(dt);
var params = {limit:8,offset:0, sortAsc:false}
this.afterLoad();
this.datasetResource.query(params).then(datasets => this.datasets = datasets);
});
}
);
}
// special params:
@ -146,6 +169,26 @@ SaveNewDataset(){debugger;
paginationRange: 'Result range'
};
getDatasetForDmpMethod(dmpid){
this.serverService.getDatasetForDmp({"id":dmpid}).subscribe(
response => {
console.log("response");
console.log(response);
this.datasets = [];
response.forEach(resp => {
let dt = new Dataset();
dt.id = resp.id;
dt.name = resp.label;
dt.uriDataset = resp.uri;
this.datasets.push(dt);
var params = {limit:8,offset:0, sortAsc:false}
this.afterLoad();
this.datasetResource.query(params).then(datasets => this.datasets = datasets);
});
}
);
}
}

View File

@ -1,4 +1,4 @@
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import {GoogleSignInSuccess} from 'angular-google-signin';
import { Router, ActivatedRoute } from '@angular/router';
import { ServerService } from '../../app/services/server.service';
@ -12,6 +12,7 @@ import { ModalComponent } from '../modal/modal.component';
import { HttpErrorResponse } from '@angular/common/http';
import { FormGroup, FormControl } from '@angular/forms'; //na dw an xreiazontai
import { NgForm } from '@angular/forms';
import { DatasetsComponent } from '../datasets/dataset.component';
declare var $ :any;
@ -31,8 +32,10 @@ export class DmpComponent implements OnInit{
@Input() dataSetVisibe:boolean;
@Input() projects: Project[];
@ViewChild(DataTable) dmpsTable;
@ViewChild(DataTable) datasetsTable;
@ViewChild(DatasetsComponent) datasetsComponent:DatasetsComponent;
@ViewChild('isignOutBtn') isignOutBtn;
constructor(
@ -42,6 +45,7 @@ export class DmpComponent implements OnInit{
this.projectsDropDown = new DropdownField();
this.projectsDropDown.options = [];
this.projects = [];
this.dataSetVisibe = false;
this.dmp = {
label: '',
abbreviation:'',
@ -119,10 +123,10 @@ filterGrid() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("projects-grid");
table = document.getElementById("dmps-grid");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[3];
td = tr[i].getElementsByTagName("td")[4];
if (td) {
if (td.innerText.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
@ -146,8 +150,27 @@ SaveNewDmp(){
response =>{
console.log("response");
console.log(response);
this.dmps = [];
this.serverService.getDmpOfUser().subscribe(
response => {
response.forEach(resp => {
let dmp = new Dmp();
dmp.id = resp.id;
dmp.label = resp.label;
dmp.version = resp.version;
dmp.dataset = resp.dataset;
dmp.projectLabel = resp.project.label;
this.dmps.push(dmp);
var params = {limit:8,offset:0, sortAsc:false}
this.afterLoad();
this.dmpResource.query(params).then(dmps => this.dmps = dmps);
}
);
});
}
);
$("#newDmpModal").modal("hide");
}
// special params:
@ -163,16 +186,20 @@ signOut() {
    this.serverService.logOut();
}
selectDmp(rowEvent){
selectDmp(rowEvent){debugger;
this.dmpIdforDatasets = rowEvent.row.item.id;
this.dataSetVisibe = true;
if(this.dataSetVisibe == false)
this.dataSetVisibe = true;
else
this.datasetsComponent.getDatasetForDmpMethod(rowEvent.row.item.id);
}
editRow(dmp){
this.dmp.label = this.dmp.label;
this.dmp.abbreviation = this.dmp.abbreviation;
this.dmp.uri = this.dmp.uri;
this.dmp.id = this.dmp.id;
editRow(item){debugger;
this.dmp.label = item.label;
this.dmp.abbreviation = item.abbreviation;
this.dmp.uri = item.uri;
this.dmp.id = item.id;
this.dmp.project = item.project;
$("#newDmpModal").modal("show");
}

View File

@ -7,7 +7,7 @@
</div>
<data-table id="dmps-grid" headerTitle="My Dmps" [items]="dmps" [itemCount]="dmpCount" (reload)="reloadDmps($event)"
[limit]="8" [sortBy]="'rating'" [sortAsc]="false" [selectColumn]="true" [multiSelect]="false" [substituteRows]="false"
[expandableRows]="true" [translations]="translations" [indexColumnHeader]="'#'" [selectOnRowClick]="true" (rowClick)="selectDmp($event)">
[translations]="translations" [indexColumnHeader]="'#'" [selectOnRowClick]="true" (rowClick)="selectDmp($event)">
<data-table-column [property]="'label'" [header]="'Label'" [sortable]="true">
</data-table-column>
@ -112,7 +112,7 @@
<!-- <modal *ngIf="item && show" [(show)]="show" [item]="item" [(dataSetVisibe)]="dataSetVisibe"></modal> -->
<!--DATASET TABLE-->
<datasets-table *ngIf="dataSetVisibe" [dmpIdforDatasets]= "dmpIdforDatasets"></datasets-table>
<datasets-table *ngIf="dataSetVisibe" [dmpIdforDatasets]= "dmpIdforDatasets" [(dataSetVisibe)]="dataSetVisibe"></datasets-table>
<a href="#" (click)="signOut();" #isignOutBtn >Sign out</a>
<router-outlet></router-outlet>

View File

@ -113,7 +113,7 @@ export class ServerService {
return this.restBase.post("/dmp/getdatasets", data);
}
public createDatasetForDmp(data:any){debugger;
public createDatasetForDmp(data:any){
return this.restBase.post("dataset/create", data);
}

View File

@ -4,12 +4,12 @@ import { Component } from '@angular/core';
selector: 'my-app',
template: `
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link" routerLink="dmps" routerLinkActive="active">My Dmps</a>
</li>
<li class="nav-item">
<a class="nav-link active" routerLink="projects" routerLinkActive="active">Projects</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink="dmps" routerLinkActive="active">My Dmps</a>
</li>
</ul>
<router-outlet></router-outlet>