Skip to content

Commit

Permalink
Merge pull request #64 from feup-infolab/lazaroDevelop
Browse files Browse the repository at this point in the history
Lazaro develop
  • Loading branch information
lazarocosta committed Apr 13, 2020
2 parents 0091692 + 1748c5d commit 928a034
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 188 deletions.
2 changes: 1 addition & 1 deletion frontend/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<app-example></app-example>
<router-outlet></router-outlet>
19 changes: 17 additions & 2 deletions frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,30 @@ import { FlexLayoutModule } from '@angular/flex-layout';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {ComboBoxComponent} from './combo-box/combo-box.component';
import { RouterModule, Routes } from '@angular/router';
import { EditEntityComponent } from './components/edit-entity.component';
import {MatIconModule} from "@angular/material/icon";
import {MatButtonModule} from '@angular/material';

const appRoutes: Routes = [
{ path: '', component: ExampleComponent },
{ path: ':uid', component: EditEntityComponent },

];


@NgModule({
declarations: [
AppComponent,
ExampleComponent,
ComboBoxComponent,
ComboBoxComponent
EditEntityComponent
],
imports: [
RouterModule.forRoot(
appRoutes,
{enableTracing: true} // <-- debugging purposes only
),
BrowserModule,
HttpClientModule,
MaterialDesignFrameworkModule,
Expand All @@ -29,7 +43,8 @@ import {MatButtonModule} from '@angular/material';
Bootstrap4FrameworkModule,
NoopAnimationsModule,
FlexLayoutModule,
MatButtonModule
MatButtonModule,
MatIconModule
],
providers: [MyServiceService],
bootstrap: [ AppComponent ],
Expand Down
Empty file.
33 changes: 33 additions & 0 deletions frontend/src/app/components/edit-entity.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

<div *ngIf="load" style="margin: 35px">
<json-schema-form
*ngIf="load"
[form]= "form"
[options]='jsonFormOptions'
[framework]="'bootstrap-4'"
(onSubmit)="onSubmit($event)"
(formSchema)="showFormSchemaFn($event)"
(formLayout)="showFormLayoutFn($event)"
(isValid)="isValid($event)">
</json-schema-form>

<div class="example-button-row">
<button mat-raised-button color="primary" (click)="goBack()">Go back</button>
</div>
</div>




<!--
<json-schema-form
loadExternalAssets="true"
[schema]="schema"
[(data)]='data'
[layout]='layout'
[options]="jsonFormOptions"
[framework]="'material-design'">
(onChanges)="onChanges($event)"
(onSubmit)="onSubmit($event)"
(validationErrors)="validationErrors($event)">
</json-schema-form>-->
25 changes: 25 additions & 0 deletions frontend/src/app/components/edit-entity.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { EditEntityComponent } from './edit-entity.component';

describe('EditEntityComponent', () => {
let component: EditEntityComponent;
let fixture: ComponentFixture<EditEntityComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditEntityComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(EditEntityComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
204 changes: 204 additions & 0 deletions frontend/src/app/components/edit-entity.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import { Component, OnInit } from '@angular/core';
import {MyServiceService} from "../service/my-service.service";
import {ActivatedRoute} from "@angular/router";
import { Location } from '@angular/common';

@Component({
selector: 'app-edit-entity',
templateUrl: './edit-entity.component.html',
styleUrls: ['./edit-entity.component.css']
})
export class EditEntityComponent implements OnInit {

constructor(
private location: Location,
private route: ActivatedRoute,
private service: MyServiceService) {
}
uid = '';
name = 'Angular 7';
jsonFormOptions = {
loadExternalAssets: true,
};
schema = {};
data = {};
submittedFormData;
load = false;
form = {
schema: {},
data: {},
layout: []
};

onEnter(uid: string) {
//this.uid = uid;
// this.form.data = {};
// this.form.layout = [];
// this.form.schema = {};
//this.getSchemaNode(this.uid);
}
goBack() {
this.location.back();
}
ngOnInit() {
this.route.paramMap.subscribe(params => {
this.uid = params.get('uid');
console.log(this.uid);
this.load = false;
this.getSchemaNode(this.uid);
});
}

getDataNode(uid) {
this.service.getDataNode(uid)
.subscribe(result => {
this.form.data = result;
console.log(result);
this.load = true;
});
}

getSchemaNode(uid) {
this.service.getSchemaNode(uid)
.subscribe(returnedSchema => {
this.form.layout = [];
console.log(returnedSchema);
this.form.schema = this.refactorSchema(returnedSchema);
this.form.layout = ['*'];
// const button1 = {
// type: 'submit',
// title: 'Submit',
// onClick(evt) {
// sen
// evt.preventDefault();
// alert('Thank you!');
// }
// this.getDataNode(this.uid);
this.load = true;
});
}

refactorSchema(jsonSchema) {
const ref = jsonSchema.$ref;
const path = ref.split('/');
const schemaName = path[2];
const properties = {};
properties[this.uid] = {
$ref: ref,
title: 'Editing'
};
jsonSchema.properties = properties;
jsonSchema.desc = "Description";

delete jsonSchema.$ref;
const schemaEntity = jsonSchema.definitions[schemaName];

delete schemaEntity.properties.uid;
jsonSchema.type = 'object';
return jsonSchema;

}

sendNode(data) {
this.service.sendNode(data)
.subscribe(result => {
this.form.data = result;
console.log(result);
});
}

onSubmit(a: any) {
console.log(a);
this.sendNode(a);
}

showFormSchemaFn($event) {
// console.log($event); it shows schema of node
}

showFormLayoutFn($event) {
console.log($event);
}

isValid($event) {
// console.log('isvalid ' + $event);
}

yourValidationErrorsFn($event) {
console.log('error' + $event);

}
}


// inline ref schema
// const schema3 = {
// $schema: 'http://json-schema.org/draft-07/schema#',
// type: 'object',
// properties: {
// bb2ca7ccfab44ee49c4594adfde91734: {
// $ref: '#/definitions/E52_Time_SpanSchema',
// title: 'Editing E52_Time_Span <a href=\"/bb2ca7ccfab44ee49c4594adfde91734\">teste</a>'
// }
// },
//
// definitions: {
// DataObjectSchema: {
// additionalProperties: false,
// properties: {
// name: {
// title: 'name',
// type: 'string'
// },
// uid: {
// title: 'uid',
// type: 'string'
// }
// },
// required: ['name'],
// type: 'object'
// },
// E52_Time_SpanSchema: {
// additionalProperties: false,
// properties: {
// date: {
// format: 'date',
// title: 'date',
// type: 'string'
// },
// has_value: {
// items: {
// $ref: '#/definitions/DataObjectSchema',
// type: 'object'
// },
// type: 'array'
// },
// uid: {
// title: 'uid',
// type: 'string'
// },
// name: {
// title: 'name',
// type: 'string'
// }
// },
// required: ['date', 'name'],
// type: 'object'
// }
// }
// };

// data
// {
// 'fruits': [ 'apple' ],
// 'vegetables': [
// {
// 'veggieName': 'potato',
// 'veggieLike': true
// },
// {
// 'veggieName': 'broccoli',
// 'veggieLike': false
// }
// ]
// }
33 changes: 3 additions & 30 deletions frontend/src/app/components/example.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
</thead>
<tbody>
<tr *ngFor="let item of searchResultArray; let i = index">
<td>{{ item.uid }}</td>
<td><nav>
<a routerLink={{item.uid}}>{{item.uid}}</a>
</nav></td>
<td>{{ item.name }}</td>
<td><ul>
<li *ngFor="let label of item.labels">
Expand All @@ -35,35 +37,6 @@
</tr>
</tbody>
</table>
</div>

<div style="margin: 35px;"><p>Insert your UID </p>
<input style="width: 300px" #box (keyup.enter)="onEnter(box.value)">
</div>

<div *ngIf="load" style="margin: 35px">
<json-schema-form
*ngIf="load"
[form]= "form"
[options]='jsonFormOptions'
[framework]="'bootstrap-4'"
(onSubmit)="onSubmit($event)"
(formSchema)="showFormSchemaFn($event)"
(formLayout)="showFormLayoutFn($event)"
(isValid)="isValid($event)">
</json-schema-form>
</div>


<!--
<json-schema-form
loadExternalAssets="true"
[schema]="schema"
[(data)]='data'
[layout]='layout'
[options]="jsonFormOptions"
[framework]="'material-design'">
(onChanges)="onChanges($event)"
(onSubmit)="onSubmit($event)"
(validationErrors)="validationErrors($event)">
</json-schema-form>-->
Loading

0 comments on commit 928a034

Please sign in to comment.