Commit 11f7574f authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

added suffix details (needs work)

parent 2fa98641
......@@ -28,6 +28,8 @@ import { HeaderComponent } from './navigation/header/header.component';
import { SidenavListComponent } from './navigation/sidenav-list/sidenav-list.component';
import { MainListComponent } from './components/main-list/main-list.component';
import { MainDetailsComponent } from './components/main-details/main-details.component';
import { SuffixListComponent } from './components/suffix-list/suffix-list.component';
import { SuffixDetailsComponent } from './components/suffix-details/suffix-details.component';
......@@ -46,6 +48,8 @@ import { MainDetailsComponent } from './components/main-details/main-details.com
SidenavListComponent,
MainListComponent,
MainDetailsComponent,
SuffixListComponent,
SuffixDetailsComponent,
],
imports: [
BrowserModule,
......
<app-prefix-list></app-prefix-list>
<app-main-list></app-main-list>
<app-suffix-list></app-suffix-list>
<div>
<div *ngIf="currentboilerplate.id" class="edit-form">
<h4>Boilerplate</h4>
......@@ -14,7 +15,7 @@
name="title"
/>
</div>
<div style="display: flex; flex-grow: grow">
<div style="display: flex; flex-grow: grow; margin-top: 50px;">
<form class="form-group form-inline ">
<mat-checkbox class="example-full-width"
[(ngModel)]="currentboilerplate.has_prefix"
......@@ -22,9 +23,12 @@
>Prefix
</mat-checkbox>
</form>
<div *ngIf="this.currentboilerplate.has_prefix">
<app-prefix-details></app-prefix-details>
</div>
</div>
<div style="display: flex; flex-grow: grow">
<mat-divider></mat-divider>
<div style="display: flex; flex-grow: grow; margin-top: 50px;">
<form class="form-group form-inline ">
<mat-checkbox class="example-full-width"
[(ngModel)]="currentboilerplate.has_main"
......@@ -32,22 +36,27 @@
>Main
</mat-checkbox>
</form>
<div *ngIf="this.currentboilerplate.has_main">
<app-main-details></app-main-details>
</div>
</div>
<div class="form-group">
<label for="has_suffix">Suffix</label>
<input
type="checkbox"
class="form-control"
id="has_suffix"
[(ngModel)]="currentboilerplate.has_suffix"
name="has_suffix"
/>
<mat-divider></mat-divider>
<div style="display: flex; flex-grow: grow; margin-top: 50px;">
<form class="form-group form-inline ">
<mat-checkbox class="example-full-width"
[(ngModel)]="this.currentboilerplate.has_suffix"
name="has_suffix"
>Suffix
</mat-checkbox>
</form>
<div *ngIf="this.currentboilerplate.has_suffix">
<app-suffix-details></app-suffix-details>
</div>
</div>
</form>
<button class="badge badge-danger mr-2" (click)="deleteBoilerplate()">
Delete
Delete Boilerplate
</button>
<button
......@@ -55,7 +64,7 @@
class="badge badge-success mb-2"
(click)="updateBoilerplate()"
>
Update
Update Boilerplate
</button>
<p>{{ message }}</p>
</div>
......
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Boilerplate } from 'src/app/models/boilerplate.model';
import { BoilerplateService } from 'src/app/services/boilerplate.service';
@Component({
selector: 'app-boilerplate-details',
templateUrl: './boilerplate-details.component.html',
......@@ -33,7 +35,7 @@ export class BoilerplateDetailsComponent implements OnInit {
.subscribe(
data => {
this.currentboilerplate = data;
//console.log(data);
console.log(data);
},
error => {
console.log(error);
......@@ -53,15 +55,16 @@ export class BoilerplateDetailsComponent implements OnInit {
}
deleteBoilerplate(): void {
this.boilerplateService.delete(this.currentboilerplate.id)
.subscribe(
response => {
console.log(response);
this.router.navigate(['/boilerplates']);
},
error => {
console.log(error);
});
if(confirm("Αre you sure you want to delete this Boilerplate?")) {
this.boilerplateService.delete(this.currentboilerplate.id)
.subscribe(
response => {
console.log(response);
this.router.navigate(['/boilerplates']);
},
error => {
console.log(error);
});
}
}
}
......@@ -10,7 +10,7 @@
[formControl]="subjectsControl"
[matAutocomplete]="automainsub"
>
<mat-autocomplete autoActiveFirstOption #automainsub="matAutocomplete">
<mat-autocomplete autoActiveFirstOption #automainsub="matAutocomplete">
<mat-option *ngFor="let option of subjectsfilteredOptions | async" [value]="option">
{{option}}
</mat-option>
......@@ -114,6 +114,14 @@
</form>
</div>
<!--NUmber Value-->
<div class="col" >
<form class="form-group form-inline">
<mat-form-field class="example-full-width">
<mat-label>Numerical Value</mat-label>
<input type="number" matInput value=0 [(ngModel)]="currentmain.numerical" name="numerical">
</mat-form-field>
</form>
</div>
<div class="col">
<form class="form-group form-inline">
<mat-form-field class="example-full-width">
......
......@@ -60,7 +60,7 @@ export class MainDetailsComponent implements OnInit {
shall: "",
verb: "",
quantifier: "",
numerical: "",
numerical: 0,
mumerical_units: "",
flow_function_interface_item_system_state_stateset: "",
statevalue_system_connection_stateset: "",
......@@ -132,7 +132,7 @@ export class MainDetailsComponent implements OnInit {
.subscribe(
data => {
this.currentmain = data;
console.log(data)
//console.log(data)
this.subjectsControl.setValue(this.currentmain.sys_fun_inter);
this.stateitemControl.setValue(this.currentmain.state_item_before_verb);
this.statevalueControl.setValue(this.currentmain.statevalue_before_verb);
......
......@@ -31,9 +31,8 @@ export class MainListComponent implements OnInit {
data => {
MainDetailsComponent.id.length =0;
this.mains = data;
console.log(data);
for (var val of data) {
this.mainDetails.getMain(id, val.id);
//this.mainDetails.getMain(id, val.id);
MainDetailsComponent.id.push(val.id);
}
},
......
<div class="form-row">
<div class="col">
<form class="form-group form-inline">
<mat-form-field class="example-full-width">
<mat-label>Suffix</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="suffixControl"
[matAutocomplete]="autosuffix"
>
<mat-autocomplete autoActiveFirstOption #autosuffix="matAutocomplete">
<mat-option *ngFor="let option of suffixfilteredOptions | async" [value]="option">
{{option}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
</div>
<div class="col" >
<form class="form-group form-inline">
<mat-form-field class="example-full-width">
<mat-label>Numerical Value</mat-label>
<input type="number" matInput value=0 [(ngModel)]="currentsuffix.numerical" name="numerical">
</mat-form-field>
</form>
</div>
<div class="col">
<form class="form-group form-inline">
<mat-form-field class="example-full-width">
<mat-label>Unit</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="mumerical_unitsControl"
[matAutocomplete]="automumerical_units"
>
<mat-autocomplete autoActiveFirstOption #automumerical_units="matAutocomplete">
<mat-option *ngFor="let option of mumerical_unitsfilteredOptions | async" [value]="option">
{{option}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
</div>
<div class="col">
<form class="form-group form-inline">
<mat-form-field class="example-full-width">
<mat-label>Unit</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="flowControl"
[matAutocomplete]="autoflow"
>
<mat-autocomplete autoActiveFirstOption #autoflow="matAutocomplete">
<mat-option *ngFor="let option of flowfilteredOptions | async" [value]="option">
{{option}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
</div>
<div class="col">
<button
type="submit"
class="badge badge-success mb-2"
(click)="updateSuffix()"
>
Update Suffix
</button>
</div>
</div>
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SuffixDetailsComponent } from './suffix-details.component';
describe('SuffixDetailsComponent', () => {
let component: SuffixDetailsComponent;
let fixture: ComponentFixture<SuffixDetailsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SuffixDetailsComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(SuffixDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Suffix } from 'src/app/models/suffix.model';
import { SuffixService } from 'src/app/services/suffix.service';
import {FormControl} from '@angular/forms';
import {Observable} from 'rxjs';
import {map, startWith} from 'rxjs/operators';
import { NotifierService } from "angular-notifier";
@Component({
selector: 'app-suffix-details',
templateUrl: './suffix-details.component.html',
styleUrls: ['./suffix-details.component.scss']
})
export class SuffixDetailsComponent implements OnInit {
suffixControl = new FormControl();
suffix:string[] = [];
suffixfilteredOptions: Observable<string[]>;
mumerical_unitsControl = new FormControl();
mumerical_units:string[] = [];
mumerical_unitsfilteredOptions: Observable<string[]>;
flowControl = new FormControl();
flow:string[] = [];
flowfilteredOptions: Observable<string[]>;
public static id: any [] = [];
private readonly notifier: NotifierService;
currentsuffix: Suffix = {
s_choices: "",
numerical: 0,
mumerical_units: "",
flow: "",
};
message = '';
constructor(
private suffixService: SuffixService,
private route: ActivatedRoute,
private router: Router,
notifierService: NotifierService) {
this.notifier = notifierService;
this.suffixfilteredOptions = this.suffixControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.suffix, value))
);
this.mumerical_unitsfilteredOptions = this.mumerical_unitsControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.mumerical_units, value))
);
this.flowfilteredOptions = this.flowControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.flow, value))
);
}
ngOnInit(): void {
this.getchoices();
for (let i=0; i<SuffixDetailsComponent.id.length; i++)
{
this.getSuffix(this.route.snapshot.params.id, SuffixDetailsComponent.id[i]);
};
}
private _filter(data:string[], value: string): string[] {
const filterValue = value.toLowerCase();
return data.filter(option => option.toLowerCase().indexOf(filterValue) === 0);
}
getSuffix(main: any, id: string): void {
//PrefixDetailsComponent.id = id;
this.suffixService.get(main, id)
.subscribe(
data => {
this.currentsuffix = data;
//console.log(data)
this.suffixControl.setValue(this.currentsuffix.s_choices);
this.mumerical_unitsControl.setValue(this.currentsuffix.mumerical_units);
this.flowControl.setValue(this.currentsuffix.flow);
},
error => {
console.log(error);
});
}
updateSuffix(): void {
this.currentsuffix.s_choices = this.suffixControl.value;
this.currentsuffix.mumerical_units = this.mumerical_unitsControl.value;
this.currentsuffix.flow = this.flowControl.value;
for (let i=0; i<SuffixDetailsComponent.id.length; i++){
this.suffixService.update(this.route.snapshot.params.id, SuffixDetailsComponent.id[i], this.currentsuffix)
.subscribe(
response => {
this.notifier.notify("success",JSON.stringify("Suffix updated"));
this.message = response.message;
},
error => {
console.log(error);
this.notifier.notify("warning",(JSON.stringify(error["error"])));
});}
}
getchoices(): void{
this.suffixService.getsuffix()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
this.suffix.push(data[x][1]);}
},
error => {
console.log(error);
});
this.suffixService.getnumunits()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
this.mumerical_units.push(data[x][1]);}
},
error => {
console.log(error);
});
this.suffixService.getflow()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
this.flow.push(data[x][1]);}
},
error => {
console.log(error);
});
}
}
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SuffixListComponent } from './suffix-list.component';
describe('SuffixListComponent', () => {
let component: SuffixListComponent;
let fixture: ComponentFixture<SuffixListComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SuffixListComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(SuffixListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Suffix } from 'src/app/models/suffix.model';
import { SuffixService } from 'src/app/services/suffix.service';
import { SuffixDetailsComponent} from 'src/app/components/suffix-details/suffix-details.component';
import { PrefixDetailsComponent } from '../prefix-details/prefix-details.component';
@Component({
selector: 'app-suffix-list',
providers: [SuffixDetailsComponent],
templateUrl: './suffix-list.component.html',
styleUrls: ['./suffix-list.component.scss']
})
export class SuffixListComponent implements OnInit {
suffixs?:Suffix[];
constructor(
private suffixService: SuffixService,
private suffixDetails: SuffixDetailsComponent,
private route: ActivatedRoute,
private router: Router) { }
ngOnInit(): void {
this.getAllSuffix(this.route.snapshot.params.id);
}
getAllSuffix(id: string): void {
this.suffixService.getAll(id)
.subscribe(
data => {
SuffixDetailsComponent.id.length =0;
this.suffixs = data;
for (var val of data) {
//this.mainDetails.getMain(id, val.id);
SuffixDetailsComponent.id.push(val.id);
}
},
error => {
console.log(error);
});
}
}
......@@ -8,7 +8,7 @@ export class Main {
shall?: string;
verb?: string;
quantifier?: string;
numerical?: string;
numerical?: any;
mumerical_units?: string;
flow_function_interface_item_system_state_stateset?: string;
statevalue_system_connection_stateset?: string;
......
import { Suffix } from './suffix.model';
describe('Suffix', () => {
it('should create an instance', () => {
expect(new Suffix()).toBeTruthy();
});
});
export class Suffix {
id?:any
boilerplate_of_suffix?:any;
suffix_owner?:any;
s_choices?: string;
numerical?: any;
mumerical_units?:string;
flow?: string;
suffix_choices?: string;
}
import { TestBed } from '@angular/core/testing';
import { SuffixService } from './suffix.service';
describe('SuffixService', () => {
let service: SuffixService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(SuffixService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Suffix } from '../models/suffix.model';
const baseUrl = 'http://155.207.131.19:8000/api-auth/boilerplates/';
const Url = '/suffix/';
@Injectable({
providedIn: 'root'
})
export class SuffixService {
constructor(private http: HttpClient) { }
getAll(boilerplate: any): Observable<Suffix[]> {
return this.http.get<Suffix[]>(`${baseUrl}${boilerplate}${Url}`);
}
get(boilerplate: any, id: any): Observable<Suffix> {
return this.http.get(`${baseUrl}${boilerplate}${Url}${id}`);
}
create(boilerplate: any, data: any): Observable<any> {
return this.http.post(`${baseUrl}${boilerplate}${Url}`, data);
}
update(boilerplate: any, id: any, data: any): Observable<any> {
return this.http.put(`${baseUrl}${boilerplate}${Url}${id}/`, data);
}
delete(boilerplate: any, id: any): Observable<any> {
return this.http.delete(`${baseUrl}${boilerplate}${Url}${baseUrl}${id}`);
}
getsuffix(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/suffix/choices/suffix/`);
}
getnumunits(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/suffix/choices/numunits/`);
}
getflow(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/suffix/choices/flow/`);
}
}
......@@ -19,8 +19,9 @@ SUFFIX_CHOICES = (("",""), ('S1', 'S1: <numerical-affirmative> j <closed-interva
NUMERICAL_AFFIRMATIVE_CHOICES = (("more than", "MORE THAN"), ("less than", "LESS THAN"), ("exactly","EXACTLY"),
("at least", "AT LEAST"), ("at most", "AT MOST"))
NUMBER_UNITS_CHOICES = (("",""), ("meters","METERS"), ("kilometers","KILOMETERS"), ("volt","VOLT"))
TIME_UNITS_CHOICES = (("",""), ("seconds","SECONDS"), ("minutes","MINUTES"), ("milliseconds","MILLISECONDS"))
TIME_UNITS_CHOICES = (("seconds","SECONDS"), ("minutes","MINUTES"), ("milliseconds","MILLISECONDS"))
FLOW_CHOICES = get_instances("SAO#Flow")
# FLOW returns ()
S2_CHOICES = (("before","BEFORE"), ("after","AFTER"))
S3_CHOICES = (("every","EVERY"), ("for a period of","FOR A PERIOD OF"), ("within", "WITHIN"), ("for at least", "FOR AT LEAST"))
S4_CHOICES = (("at the beginning","AT THE BEGINNING"), ("at the end","AT THE END"))
......@@ -51,8 +52,8 @@ class Suffix(models.Model):
s_choices = models.CharField(choices=S_CHOICES, max_length=100, blank=True)
#if S1
numerical = models.IntegerField(blank=True, null=True)
mumerical_units = models.CharField(choices=NUMBER_UNITS_CHOICES, max_length=100, blank=True)
time_units = models.CharField(choices=TIME_UNITS_CHOICES, max_length=100, blank=True)
mumerical_units = models.CharField(choices=NUMBER_UNITS_CHOICES + TIME_UNITS_CHOICES, max_length=100, blank=True)
#time_units = models.CharField(choices=TIME_UNITS_CHOICES, max_length=100, blank=True)
#if S2/S3
flow = models.CharField(choices=FLOW_CHOICES, max_length=100, blank=True)
#find suffix
......
......@@ -43,7 +43,6 @@ urlpatterns = [
#SUFFIX CHOICES DATA
path('suffix/choices/suffix/', suffix_req_views.SuffixChoicesViewSet.as_view(), name='suffixsuffix'),
path('suffix/choices/numunits/', suffix_req_views.NumChoicesViewSet.as_view(), name='suffixnum'),
path('suffix/choices/timeunits/', suffix_req_views.TimeChoicesViewSet.as_view(), name='suffixtime'),
path('suffix/choices/flow/', suffix_req_views.FlowChoicesViewSet.as_view(), name='suffixflow'),
......
......@@ -77,14 +77,7 @@ class SuffixChoicesViewSet(APIView):
class NumChoicesViewSet(APIView):
def get(self, request):
response = Response(NUMBER_UNITS_CHOICES)
return response
class TimeChoicesViewSet(APIView):
def get(self, request):
response = Response(TIME_UNITS_CHOICES)
response = Response(NUMBER_UNITS_CHOICES+TIME_UNITS_CHOICES)
return response
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment