Commit b0331218 authored by Thodoris Nestoridis's avatar Thodoris Nestoridis

prefix get data from api-group (change dynamical)

parent fe2267a1
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -72,7 +72,7 @@
<ng-container matColumnDef="action">
<th mat-header-cell *matHeaderCellDef> Action </th>
<td mat-cell *matCellDef="let element" class="action-link">
<a class="btn btn-info" routerLink="details/{{element.id}}">Edit</a>
<a class="btn btn-info" routerLink="details/{{element.boilerplate_data_id}}">Edit</a>
</td>
</ng-container>
......
......@@ -236,7 +236,6 @@ export class MainDetailsComponent implements OnInit {
.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);
......
......@@ -42,6 +42,7 @@ export class PrefixDetailsComponent implements OnInit {
//for the moment only one prefix can showed/updates
currentprefix: Prefix = {
prefix_group: "",
prefix: "",
system_fun_item: "",
state_or_verb: "",
......@@ -78,7 +79,7 @@ export class PrefixDetailsComponent implements OnInit {
}
ngOnInit(): void {
this.getchoices();
this.getchoices(this.route.snapshot.params.gb);
this.getAllPrefix(this.route.snapshot.params.id);
}
......@@ -120,7 +121,7 @@ export class PrefixDetailsComponent implements OnInit {
.subscribe(
data => {
this.currentprefix = data;
//console.log(data)
console.log(data)
this.simpleprefixControl.setValue(this.currentprefix.prefix);
this.subjectsControl.setValue(this.currentprefix.system_fun_item);
this.verbsControl.setValue(this.currentprefix.state_or_verb);
......@@ -151,54 +152,55 @@ export class PrefixDetailsComponent implements OnInit {
}
getchoices(): void{
this.prefixService.getsimpleprefix()
getchoices(prefix_group: any): void{
this.prefixService.getsimpleprefix(prefix_group)
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
if(this.simpleprefix.indexOf(data[x][1]) == -1) {
this.simpleprefix.push(data[x][1]);}}
//this.simpleprefix = data;
},
error => {
console.log(error);
});
this.prefixService.getlogcon()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
if(this.logic_con.indexOf(data[x][1]) == -1) {
this.logic_con.push(data[x][1]);}}
},
error => {
console.log(error);
});
this.prefixService.getverb()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
if(this.verbs.indexOf(data[x][1]) == -1) {
this.verbs.push(data[x][1]);}}
},
error => {
console.log(error);
});
this.prefixService.getsubject()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
if(this.subjects.indexOf(data[x][1]) == -1) {
this.subjects.push(data[x][1]);}}
},
error => {
console.log(error);
});
this.prefixService.getoobject()
.subscribe(
data => {
for (let x=0; x < data.length; x++ ){
if(this.objects.indexOf(data[x][1]) == -1) {
this.objects.push(data[x][1]);}}
//get prefix (if, as soon as) etc
let strIntoObj = JSON.parse(data[0].prefix_choices)
for (let x=0; x <strIntoObj.length; x++ ){
if(this.simpleprefix.indexOf(strIntoObj[x][1]) == -1) {
this.simpleprefix.push(strIntoObj[x][1]);}}
//get logic connective
let strlogic_con = JSON.parse(data[0].prefix_logcon_choices)
for (let x=0; x <strlogic_con.length; x++ ){
if(this.logic_con.indexOf(strlogic_con[x][1]) == -1) {
this.logic_con.push(strlogic_con[x][1]);}}
//get prefix verbs
let strprverb_con = JSON.parse(data[0].prefix_verb_choices)
for (let x=0; x < strprverb_con.length; x++ ){
if(this.verbs.indexOf(strprverb_con[x][1]) == -1) {
this.verbs.push(strprverb_con[x][1]);}}
//get prefix subjects
let strprsub = JSON.parse(data[0].system_choices)
for (let x=0; x < strprsub.length; x++ ){
if(this.subjects.indexOf(strprsub[x][1]) == -1) {
this.subjects.push(strprsub[x][1]);}}
let strprsub2 = JSON.parse(data[0].function_choices)
for (let x=0; x < strprsub2.length; x++ ){
if(this.subjects.indexOf(strprsub2[x][1]) == -1) {
this.subjects.push(strprsub2[x][1]);}}
let strprsub3 = JSON.parse(data[0].item_choices)
for (let x=0; x < strprsub3.length; x++ ){
if(this.subjects.indexOf(strprsub3[x][1]) == -1) {
this.subjects.push(strprsub3[x][1]);}}
//get prefix objects
let strprobj = JSON.parse(data[0].item_choices)
for (let x=0; x < strprobj.length; x++ ){
if(this.objects.indexOf(strprobj[x][1]) == -1) {
this.objects.push(strprobj[x][1]);}}
let strprobj2 = JSON.parse(data[0].function_choices)
for (let x=0; x < strprobj2.length; x++ ){
if(this.objects.indexOf(strprobj2[x][1]) == -1) {
this.objects.push(strprobj2[x][1]);}}
let strprobj3 = JSON.parse(data[0].state_value_choices)
for (let x=0; x < strprobj3.length; x++ ){
if(this.objects.indexOf(strprobj3[x][1]) == -1) {
this.objects.push(strprobj3[x][1]);}}
let strprobj4 = JSON.parse(data[0].flow_choices)
for (let x=0; x < strprobj4.length; x++ ){
if(this.objects.indexOf(strprobj4[x][1]) == -1) {
this.objects.push(strprobj4[x][1]);}}
},
error => {
console.log(error);
......
......@@ -4,6 +4,7 @@ import { Observable } from 'rxjs';
import { Prefix } from '../models/prefix.model';
const baseUrl = 'http://155.207.131.19:8000/api-auth/groupboilerplates/0/boilerplates/';
const baseUrl2 = 'http://155.207.131.19:8000/api-auth/groupboilerplates/';
const Url = '/prefix/';
@Injectable({
......@@ -33,8 +34,8 @@ export class PrefixService {
return this.http.delete(`${baseUrl}${boilerplate}${Url}${baseUrl}${id}`);
}
getsimpleprefix(): Observable<any> {
return this.http.get(`http://155.207.131.19:8000/api-auth/prefix/choices/simpleprefix/`);
getsimpleprefix(gb: any): Observable<any> {
return this.http.get(`${baseUrl2}${gb}${Url}`+`choices/simpleprefix/`);
}
getlogcon(): Observable<any> {
......
# Generated by Django 2.1.3 on 2018-11-07 09:13
import uuid
from django.db import migrations, models
from django.utils import timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0009_alter_user_last_name_max_length'),
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='created')),
('updated', models.DateTimeField(auto_now=True, verbose_name='updated')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('email', models.EmailField(max_length=254, unique=True, verbose_name='Email')),
('first_name', models.CharField(blank=True, max_length=30, null=True, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=30, null=True, verbose_name='last name')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=timezone.now, verbose_name='date joined')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'ordering': ('first_name', 'last_name'),
},
),
]
# Generated by Django 2.2.4 on 2020-12-16 10:56
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('account', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='user',
name='date_joined',
field=models.DateTimeField(default=django.utils.timezone.now),
),
]
# Generated by Django 2.2.4 on 2021-01-04 08:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('account', '0002_auto_20201216_1056'),
]
operations = [
migrations.AlterField(
model_name='user',
name='email',
field=models.EmailField(max_length=254, unique=True, verbose_name='email'),
),
]
from django.db import models
from jsonfield import JSONField
#from django.contrib.postgres.fields import ArrayField
#from reqman.apps.common.models import CoreModel
from reqman.apps.account.models import User
from reqman.apps.reqtool.models.main_req import create_main, ITEM_CHOICES, STATE_VALUE_CHOICES, STATE_CHOICES, SYSTEM_CHOICES, FUNCTION_CHOICES, FLOW_CHOICES
from reqman.apps.reqtool.models.suffix_req import create_suffix
from reqman.apps.reqtool.models.main_req import * # create_main, ITEM_CHOICES, STATE_VALUE_CHOICES, STATE_CHOICES, SYSTEM_CHOICES, FUNCTION_CHOICES, FLOW_CHOICES
from reqman.apps.reqtool.models.suffix_req import * #create_suffix
from reqman.apps.reqtool.rest_api.services.parse_ontologies import *
from pygments.formatters.html import HtmlFormatter
......@@ -69,9 +71,23 @@ def create_extra_prefix(instance, now_prefix):
prefix.save()
def create_infer_result(instance):
def create_infer_result_and_classes_instances(instance):
infer = InferenceResults(owner_infer= instance.boilerplate_owner, infer_group_of_boilerplate = instance)
infer.save()
a = (("If", "If"), ("Unless", "Unless"),("As soon as", "As soon as"), ("As long as", "As long as"), ("Once", "Once"))
jsonObj = json.dumps(a)
classes_inctances = BoilerplateGroupClassesInstances ( classes_instances_owner= instance.boilerplate_owner, classes_instances_group_of_boilerplate = instance,
prefix_choices = jsonObj, prefix_logcon_choices =json.dumps(LOGIC_CONNECTIVE), prefix_verb_choices =json.dumps(STATE_CHOICES + VERB_CHOICES_PREFIX),
main_class_choices =json.dumps(MAIN_CHOICES), system_choices = json.dumps(SYSTEM_CHOICES), function_choices =json.dumps(FUNCTION_CHOICES),
quantifier_choices=json.dumps(QUANTIFIER_CHOICES), number_unit_choices=json.dumps(NUMBER_UNITS_CHOICES), item_choices=json.dumps(ITEM_CHOICES),
inteface_choices=json.dumps(INTERFACE_CHOICES), connection_choices=json.dumps(CONNECTION_CHOICES), flow_choices=json.dumps(FLOW_CHOICES),
state_choices=json.dumps(STATE_CHOICES),state_set_choices=json.dumps(STATE_SET_CHOICES), state_value_choices=json.dumps(STATE_VALUE_CHOICES),
main_verb_choices=json.dumps(VERB_CHOICES), numerical_affirmative_choices=json.dumps(NUMERICAL_AFFIRMATIVE_CHOICES),
suffix_choices=json.dumps(S_CHOICES) )
classes_inctances.save()
class BoilerplateGroup(models.Model):
......@@ -81,7 +97,7 @@ class BoilerplateGroup(models.Model):
def save(self, **kwargs):
super(BoilerplateGroup, self).save(**kwargs)
create_infer_result(self)
create_infer_result_and_classes_instances(self)
class Boilerplate(models.Model):
......@@ -202,3 +218,42 @@ class InferenceResults(models.Model):
class Meta:
ordering = ['owner_infer']
import collections
class BoilerplateGroupClassesInstances(models.Model):
classes_instances_group_of_boilerplate = models.ForeignKey(BoilerplateGroup, related_name='classes_instances_owner_of_boilerplate', on_delete=models.CASCADE)
classes_instances_owner = models.ForeignKey(User, related_name='classes_instances_owner', on_delete=models.CASCADE)
ontology_file = models.CharField(default="", max_length=100, blank=True)
prefix_choices = JSONField()
prefix_logcon_choices = JSONField()
prefix_verb_choices = JSONField()
main_class_choices =JSONField()
system_choices=JSONField()
function_choices = JSONField()
quantifier_choices = JSONField()
item_choices = JSONField()
inteface_choices = JSONField()
connection_choices = JSONField()
flow_choices = JSONField()
state_choices =JSONField()
state_set_choices = JSONField()
state_value_choices = JSONField()
main_verb_choices = JSONField()
numerical_affirmative_choices = JSONField()
number_unit_choices =JSONField()
suffix_choices = JSONField()
import json
def get_prefix_choices():
#Must read this info from the Ontology
a = (("If", "If"), ("Unless", "Unless"),("As soon as", "As soon as"), ("As long as", "As long as"), ("Once", "Once"))
jsonObj = json.dumps(a)
print(jsonObj)
return jsonObj
from rest_framework import serializers
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateData, BoilerplateGroup, InferenceResults
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateData, BoilerplateGroup, InferenceResults, BoilerplateGroupClassesInstances
class BoilerplateSerializer(serializers.ModelSerializer):
......@@ -36,3 +36,11 @@ class BoilerplateGroupSerializer(serializers.ModelSerializer):
class Meta:
model = BoilerplateGroup
fields = ('id', 'boilerplate_owner', 'title_bgroup', 'description')
class BoilerplateGroupClassesInstancesSerializer(serializers.ModelSerializer):
classes_instances_owner = serializers.ReadOnlyField(source='owner.username')
prefix_choices = serializers.JSONField()
class Meta:
model = BoilerplateGroupClassesInstances
fields = '__all__'
......@@ -30,7 +30,7 @@ urlpatterns = [
path('groupboilerplates/<int:groupboil>/boilerplates/<int:boilerplate>/suffix/<int:pk>/', suffix_req_views.SuffixDetailsAPIView.as_view(), name='api-suffix-details'),
#PREFIX CHOICES DATA
path('prefix/choices/simpleprefix/', requirements_views.PrefixChoicesViewSet.as_view(), name='simpleprefixchoices'),
path('groupboilerplates/<int:groupboil>/prefix/choices/simpleprefix/', requirements_views.PrefixChoicesViewSet.as_view(), name='simpleprefixchoices'),
path('prefix/choices/logicalconnectivity/', requirements_views.LogConChoicesViewSet.as_view(), name='logicalconnectivitychoices'),
path('prefix/choices/verbprefix/', requirements_views.VerbChoicesViewSet.as_view(), name='verbprefixchoices'),
path('prefix/choices/sysfunitem/', requirements_views.FunItemSysChoicesViewSet.as_view(), name='sysfunitem'),
......
......@@ -8,9 +8,9 @@ from rest_framework.parsers import JSONParser
from reqman.apps.reqtool.models.requirements import Prefix, Boilerplate, BoilerplateGroup, PREFIX_CHOICES, LOGIC_CONNECTIVE
from reqman.apps.reqtool.models.requirements import VERB_CHOICES_PREFIX, ITEM_CHOICES, SYSTEM_CHOICES, FUNCTION_CHOICES, STATE_CHOICES
from reqman.apps.reqtool.models.requirements import ITEM_CHOICES, FLOW_CHOICES, FUNCTION_CHOICES, STATE_VALUE_CHOICES
from reqman.apps.reqtool.models.requirements import BoilerplateData, InferenceResults
from reqman.apps.reqtool.models.requirements import BoilerplateData, InferenceResults, BoilerplateGroupClassesInstances
from reqman.apps.reqtool.rest_api.serializers.requirements import BoilerplateSerializer, PrefixSerializer, BoilerplateDataSerializer, BoilerplateGroupSerializer, InferSerializer
from reqman.apps.reqtool.rest_api.serializers.requirements import BoilerplateSerializer, PrefixSerializer, BoilerplateDataSerializer, BoilerplateGroupSerializer, InferSerializer, BoilerplateGroupClassesInstancesSerializer
from reqman.apps.permissions import IsOwnerOrReadOnly
from reqman.apps.reqtool.models.main_req import Main
......@@ -278,11 +278,23 @@ class InferDetailsAPIView(RetrieveUpdateDestroyAPIView):
def getsuffixdata(self, pr):
return (Suffix.objects.filter(boilerplate_of_suffix = pr))
class PrefixChoicesViewSet(APIView):
#class PrefixChoicesViewSet(APIView):#
#def get(self, request):
# response = Response(PREFIX_CHOICES)
# return response
class PrefixChoicesViewSet(ListAPIView):
"""
API view to retrieve, update or delete post
"""
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
serializer_class = BoilerplateGroupClassesInstancesSerializer
def get_queryset(self):
group_pk = self.kwargs['groupboil']
queryset_cl= BoilerplateGroupClassesInstances.objects.filter(classes_instances_group_of_boilerplate = group_pk)
return queryset_cl
def get(self, request):
response = Response(PREFIX_CHOICES)
return response
class LogConChoicesViewSet(APIView):
......
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