Commit 2fa98641 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

angular main update

parent b5b3130b
......@@ -26,6 +26,8 @@ import { FlexLayoutModule } from '@angular/flex-layout';
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';
......@@ -42,6 +44,8 @@ import { SidenavListComponent } from './navigation/sidenav-list/sidenav-list.com
PrefixListComponent,
HeaderComponent,
SidenavListComponent,
MainListComponent,
MainDetailsComponent,
],
imports: [
BrowserModule,
......
<app-prefix-list></app-prefix-list>
<app-main-list></app-main-list>
<div>
<div *ngIf="currentboilerplate.id" class="edit-form">
<h4>Boilerplate</h4>
......@@ -23,15 +24,15 @@
</form>
<app-prefix-details></app-prefix-details>
</div>
<div class="form-group">
<label for="has_main">Main</label>
<input
type="checkbox"
class="form-control"
id="has_main"
<div style="display: flex; flex-grow: grow">
<form class="form-group form-inline ">
<mat-checkbox class="example-full-width"
[(ngModel)]="currentboilerplate.has_main"
name="has_main"
/>
name="has_prefix"
>Main
</mat-checkbox>
</form>
<app-main-details></app-main-details>
</div>
<div class="form-group">
<label for="has_suffix">Suffix</label>
......
<div class="form-row">
<div class="col">
<form class="form-group form-inline">
<mat-form-field class="example-full-width">
<mat-label>Subject</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="subjectsControl"
[matAutocomplete]="automainsub"
>
<mat-autocomplete autoActiveFirstOption #automainsub="matAutocomplete">
<mat-option *ngFor="let option of subjectsfilteredOptions | 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>State or Item</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="stateitemControl"
[matAutocomplete]="autostateitem"
>
<mat-autocomplete autoActiveFirstOption #autostateitem="matAutocomplete">
<mat-option *ngFor="let option of stateitemfilteredOptions | 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>State Value</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="statevalueControl"
[matAutocomplete]="autostatevalue"
>
<mat-autocomplete autoActiveFirstOption #autostatevalue="matAutocomplete">
<mat-option *ngFor="let option of statevaluefilteredOptions | 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>Shall/shall not</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="shallControl"
[matAutocomplete]="autoshall"
>
<mat-autocomplete autoActiveFirstOption #autoshall ="matAutocomplete">
<mat-option *ngFor="let option of shallfilteredOptions | 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>Verb</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="verbControl"
[matAutocomplete]="autoverb"
>
<mat-autocomplete autoActiveFirstOption #autoverb ="matAutocomplete">
<mat-option *ngFor="let option of verbfilteredOptions | 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>Quantifier</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="quantifierControl"
[matAutocomplete]="autoquantifier"
>
<mat-autocomplete autoActiveFirstOption #autoquantifier ="matAutocomplete">
<mat-option *ngFor="let option of quantifierfilteredOptions | async" [value]="option">
{{option}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
</div>
<!--NUmber Value-->
<div class="col">
<form class="form-group form-inline">
<mat-form-field class="example-full-width">
<mat-label>Number Unit</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="numunitControl"
[matAutocomplete]="autonumunit"
>
<mat-autocomplete autoActiveFirstOption #autonumunit ="matAutocomplete">
<mat-option *ngFor="let option of numunitfilteredOptions | 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>Object</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="fifuintsysstatsetControl"
[matAutocomplete]="autofifuintsysstatset"
>
<mat-autocomplete autoActiveFirstOption #autofifuintsysstatset ="matAutocomplete">
<mat-option *ngFor="let option of fifuintsysstatsetfilteredOptions | 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>Connection</mat-label>
<input type="text"
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="stsysconsetControl"
[matAutocomplete]="autostsysconset"
>
<mat-autocomplete autoActiveFirstOption #autostsysconset ="matAutocomplete">
<mat-option *ngFor="let option of stsysconsetfilteredOptions | 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)="updateMain()"
>
Update Main
</button>
</div>
</div>
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MainDetailsComponent } from './main-details.component';
describe('MainDetailsComponent', () => {
let component: MainDetailsComponent;
let fixture: ComponentFixture<MainDetailsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ MainDetailsComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(MainDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Main } from 'src/app/models/main.model';
import { MainService } from 'src/app/services/main.service';
import {FormControl} from '@angular/forms';
import {Observable} from 'rxjs';
import {map, startWith} from 'rxjs/operators';
import { NotifierService } from "angular-notifier";
@Component({
selector: 'app-main-details',
templateUrl: './main-details.component.html',
styleUrls: ['./main-details.component.scss']
})
export class MainDetailsComponent implements OnInit {
subjectsControl = new FormControl();
subjects:string[] = [];
subjectsfilteredOptions: Observable<string[]>;
stateitemControl = new FormControl();
stateitem:string[] = [];
stateitemfilteredOptions: Observable<string[]>;
statevalueControl = new FormControl();
statevalue:string[] = [];
statevaluefilteredOptions: Observable<string[]>;
shallControl = new FormControl();
shall:string[] = [];
shallfilteredOptions: Observable<string[]>;
verbControl = new FormControl();
verb:string[] = [];
verbfilteredOptions: Observable<string[]>;
quantifierControl = new FormControl();
quantifier:string[] = [];
quantifierfilteredOptions: Observable<string[]>;
numunitControl = new FormControl();
numunit:string[] = [];
numunitfilteredOptions: Observable<string[]>;
fifuintsysstatsetControl = new FormControl();
fifuintsysstatset:string[] = [];
fifuintsysstatsetfilteredOptions: Observable<string[]>;
stsysconsetControl = new FormControl();
stsysconset:string[] = [];
stsysconsetfilteredOptions: Observable<string[]>;
public static id: any [] = [];
private readonly notifier: NotifierService;
currentmain: Main = {
sys_fun_inter: "",
state_item_before_verb: "",
statevalue_before_verb: "",
shall: "",
verb: "",
quantifier: "",
numerical: "",
mumerical_units: "",
flow_function_interface_item_system_state_stateset: "",
statevalue_system_connection_stateset: "",
};
message = '';
constructor(
private mainService: MainService,
private route: ActivatedRoute,
private router: Router,
notifierService: NotifierService) {
this.notifier = notifierService;
this.subjectsfilteredOptions = this.subjectsControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.subjects, value))
);
this.stateitemfilteredOptions = this.stateitemControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.stateitem, value))
);
this.statevaluefilteredOptions = this.statevalueControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.statevalue, value))
);
this.shallfilteredOptions = this.shallControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.shall, value))
);
this.verbfilteredOptions = this.verbControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.verb, value))
);
this.quantifierfilteredOptions = this.quantifierControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.quantifier, value))
);
this.numunitfilteredOptions = this.numunitControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.numunit, value))
);
this.fifuintsysstatsetfilteredOptions = this.fifuintsysstatsetControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.fifuintsysstatset, value))
);
this.stsysconsetfilteredOptions = this.stsysconsetControl.valueChanges.pipe(
startWith(""),
map(value => this._filter(this.stsysconset, value))
);
}
ngOnInit(): void {
this.getchoices();
for (let i=0; i<MainDetailsComponent.id.length; i++)
{
this.getMain(this.route.snapshot.params.id, MainDetailsComponent.id[i]);
};
}
private _filter(data:string[], value: string): string[] {
const filterValue = value.toLowerCase();
return data.filter(option => option.toLowerCase().indexOf(filterValue) === 0);
}
getMain(main: any, id: string): void {
//PrefixDetailsComponent.id = id;
this.mainService.get(main, id)
.subscribe(
data => {
this.currentmain = 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);
this.shallControl.setValue(this.currentmain.shall);
this.verbControl.setValue(this.currentmain.verb);
this.quantifierControl.setValue(this.currentmain.quantifier);
// num
this.numunitControl.setValue(this.currentmain.mumerical_units);
this.fifuintsysstatsetControl.setValue(this.currentmain.flow_function_interface_item_system_state_stateset);
this.stsysconsetControl.setValue(this.currentmain.statevalue_system_connection_stateset);
},
error => {
console.log(error);
});
}
updateMain(): void {
this.currentmain.sys_fun_inter = this.subjectsControl.value;
this.currentmain.state_item_before_verb = this.stateitemControl.value;
this.currentmain.statevalue_before_verb = this.statevalueControl.value;
this.currentmain.shall = this.shallControl.value;
this.currentmain.verb = this.verbControl.value;
this.currentmain.quantifier = this.quantifierControl.value;
//num
this.currentmain.mumerical_units = this.numunitControl.value;
this.currentmain.flow_function_interface_item_system_state_stateset = this.fifuintsysstatsetControl.value;
this.currentmain.statevalue_system_connection_stateset = this.stsysconsetControl.value;
for (let i=0; i<MainDetailsComponent.id.length; i++){
this.mainService.update(this.route.snapshot.params.id, MainDetailsComponent.id[i], this.currentmain)
.subscribe(
response => {
this.notifier.notify("success",JSON.stringify("Prefix updated"));
this.message = response.message;
},
error => {
console.log(error);
this.notifier.notify("warning",(JSON.stringify(error["error"])));
});}
}
getchoices(): void{
this.mainService.getsubject()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
this.subjects.push(data[x][1]);}
},
error => {
console.log(error);
});
this.mainService.getstateitem()
.subscribe(
data => {
//no data from State and Item
console.log(data);
for (let x=0; x < data.length; x++ ){
this.stateitem.push(data[x][1]);}
},
error => {
console.log(error);
});
this.mainService.getstatevalue()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
this.statevalue.push(data[x][1]);}
},
error => {
console.log(error);
});
this.mainService.getshall()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
this.shall.push(data[x][1]);}
},
error => {
console.log(error);
});
this.mainService.getverb()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
this.verb.push(data[x][1]);}
},
error => {
console.log(error);
});
this.mainService.getquantifier()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
this.quantifier.push(data[x][1]);}
},
error => {
console.log(error);
});
//num
this.mainService.getnumunit()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
this.numunit.push(data[x][1]);}
},
error => {
console.log(error);
});
this.mainService.getfifuintsysstatset()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
this.fifuintsysstatset.push(data[x][1]);}
},
error => {
console.log(error);
});
this.mainService.getstsysconset()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
this.stsysconset.push(data[x][1]);}
},
error => {
console.log(error);
});
}
}
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MainListComponent } from './main-list.component';
describe('MainListComponent', () => {
let component: MainListComponent;
let fixture: ComponentFixture<MainListComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ MainListComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(MainListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Main } from 'src/app/models/main.model';
import { MainService } from 'src/app/services/main.service';
import { MainDetailsComponent} from 'src/app/components/main-details/main-details.component';
@Component({
selector: 'app-main-list',
providers: [MainDetailsComponent],
templateUrl: './main-list.component.html',
styleUrls: ['./main-list.component.scss']
})
export class MainListComponent implements OnInit {
mains?: Main[];
constructor(
private mainService: MainService,
private mainDetails: MainDetailsComponent,
private route: ActivatedRoute,
private router: Router) { }
ngOnInit(): void {
this.getAllMain(this.route.snapshot.params.id);
}
getAllMain(id: string): void {
this.mainService.getAll(id)
.subscribe(
data => {
MainDetailsComponent.id.length =0;
this.mains = data;
console.log(data);
for (var val of data) {
this.mainDetails.getMain(id, val.id);
MainDetailsComponent.id.push(val.id);
}
},
error => {
console.log(error);
});
}
}
......@@ -38,7 +38,6 @@ export class PrefixDetailsComponent implements OnInit {
public static id: any [] = [];
private readonly notifier: NotifierService;
disable = true;
//for the moment only one prefix can showed/updates
currentprefix: Prefix = {
......@@ -103,9 +102,6 @@ export class PrefixDetailsComponent implements OnInit {
this.verbsControl.setValue(this.currentprefix.state_or_verb);
this.objectsControl.setValue(this.currentprefix.item_function_flow_statevalue);
this.logic_conControl.setValue(this.currentprefix.logic_connective);
},
error => {
console.log(error);
......
import { Main } from './main.model';
describe('Main', () => {
it('should create an instance', () => {
expect(new Main()).toBeTruthy();
});
});
export class Main {
id?:any;
boilerplate_of_main?:any;
main_owner?:any;
sys_fun_inter?: string;
state_item_before_verb?: string;
statevalue_before_verb?:string;
shall?: string;
verb?: string;
quantifier?: string;
numerical?: string;
mumerical_units?: string;
flow_function_interface_item_system_state_stateset?: string;
statevalue_system_connection_stateset?: string;
main_choices?: string;
}
import { TestBed } from '@angular/core/testing';
import { MainService } from './main.service';
describe('MainService', () => {
let service: MainService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(MainService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Main } from '../models/main.model';
const baseUrl = 'http://155.207.131.19:8000/api-auth/boilerplates/';
const Url = '/main/';
@Injectable({
providedIn: 'root'
})
export class MainService {
constructor(private http: HttpClient) { }
getAll(boilerplate: any): Observable<Main[]> {
return this.http.get<Main[]>(`${baseUrl}${boilerplate}${Url}`);
}
get(boilerplate: any, id: any): Observable<Main> {
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}`);
}
getsubject(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/main/choices/subject/`);
}
getstateitem(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/main/choices/stateitem/`);
}
getstatevalue(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/main/choices/statevalue/`);
}
getshall(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/main/choices/shall/`);
}
getverb(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/main/choices/verb/`);
}
getquantifier(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/main/choices/quantifier/`);
}
getnumunit(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/main/choices/numunit/`);
}
getfifuintsysstatset(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/main/choices/fifuintsysstatset/`);
}
getstsysconset(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/main/choices/stsysconset/`);
}
}
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Prefix } from '../models/prefix.model';
......
......@@ -31,13 +31,14 @@ MAIN_CHOICES = ( ("",""), ("M1", "M1 : system/function shall [not] set [<quant
#to be updated with domains from DSO
SYSTEM_CHOICES = get_instances("SAO#System") #+get_i_instances("SAO#System")
FUNCTION_CHOICES = get_instances("SAO#Function")
SHALL_CHOICES = ( ("shall", "SHALL"), ("shall not", "SHALL NOT"))
SHALL_CHOICES = ( ("shall", "shall"), ("shall not", "shall not"))
QUANTIFIER_CHOICES = ( ("none","NONE"), ("all", "ALL"), ("only", "ONLY"),
("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"))
ITEM_CHOICES = get_instances("SAO#Item")
#NO ITEM returned
STATE_VALUE_CHOICES =get_i_instances("SAO#StateValue")
#print(STATE_VALUE_CHOICES)
STATE_CHOICES = get_instances("SAO#State")
......
......@@ -16,7 +16,7 @@ from rest_framework.views import APIView
from reqman.apps.reqtool.models.main_req import SYSTEM_CHOICES, FUNCTION_CHOICES, INTERFACE_CHOICES, STATE_CHOICES, ITEM_CHOICES
from reqman.apps.reqtool.models.main_req import STATE_VALUE_CHOICES, SHALL_CHOICES, VERB_CHOICES, QUANTIFIER_CHOICES, NUMBER_UNITS_CHOICES
from reqman.apps.reqtool.models.main_req import FLOW_CHOICES, CONNECTION_CHOICES
from reqman.apps.reqtool.models.main_req import FLOW_CHOICES, CONNECTION_CHOICES, STATE_SET_CHOICES
class MainListAPIView(ListAPIView):
"""
......@@ -85,6 +85,7 @@ class StatItemChoicesViewSet(APIView):
class StatevalueChoicesViewSet(APIView):
def get(self, request):
print(STATE_VALUE_CHOICES)
response = Response(STATE_VALUE_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